* Added a name hash to pipefs; this should speedup the lookup when more pipes
are used at the same time. * Added a TODO item: pipefs entries aren't deleted yet after usage! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21108 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2006, Axel Dörfler, [email protected].
|
* Copyright 2003-2007, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,9 +25,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
// TODO: pipefs entries aren't deleted automatically after usage yet!
|
||||||
// ToDo: handles file names suboptimally - it has all file names
|
|
||||||
// in a singly linked list, no hash lookups or whatever.
|
|
||||||
|
|
||||||
//#define TRACE_PIPEFS
|
//#define TRACE_PIPEFS
|
||||||
#ifdef TRACE_PIPEFS
|
#ifdef TRACE_PIPEFS
|
||||||
@@ -108,7 +106,7 @@ class Volume {
|
|||||||
void Unlock();
|
void Unlock();
|
||||||
|
|
||||||
Inode *Lookup(vnode_id id);
|
Inode *Lookup(vnode_id id);
|
||||||
Inode *FindNode(const char *name);
|
Inode *Lookup(const char *name);
|
||||||
Inode *CreateNode(Inode *parent, const char *name, int32 type);
|
Inode *CreateNode(Inode *parent, const char *name, int32 type);
|
||||||
status_t DeleteNode(Inode *inode, bool forceDelete = false);
|
status_t DeleteNode(Inode *inode, bool forceDelete = false);
|
||||||
status_t RemoveNode(Inode *directory, const char *name);
|
status_t RemoveNode(Inode *directory, const char *name);
|
||||||
@@ -132,6 +130,7 @@ class Volume {
|
|||||||
Inode *fRootNode;
|
Inode *fRootNode;
|
||||||
vnode_id fNextNodeID;
|
vnode_id fNextNodeID;
|
||||||
hash_table *fNodeHash;
|
hash_table *fNodeHash;
|
||||||
|
hash_table *fNameHash;
|
||||||
|
|
||||||
// root directory contents - we don't support other directories
|
// root directory contents - we don't support other directories
|
||||||
Inode *fFirstEntry;
|
Inode *fFirstEntry;
|
||||||
@@ -182,6 +181,10 @@ class Inode {
|
|||||||
status_t Select(uint8 event, uint32 ref, selectsync *sync);
|
status_t Select(uint8 event, uint32 ref, selectsync *sync);
|
||||||
status_t Deselect(uint8 event, selectsync *sync);
|
status_t Deselect(uint8 event, selectsync *sync);
|
||||||
|
|
||||||
|
static int32 NameHashNextOffset();
|
||||||
|
static uint32 name_hash_func(void *_node, const void *_key, uint32 range);
|
||||||
|
static int name_compare_func(void *_node, const void *_key);
|
||||||
|
|
||||||
static int32 HashNextOffset();
|
static int32 HashNextOffset();
|
||||||
static uint32 hash_func(void *_node, const void *_key, uint32 range);
|
static uint32 hash_func(void *_node, const void *_key, uint32 range);
|
||||||
static int compare_func(void *_node, const void *_key);
|
static int compare_func(void *_node, const void *_key);
|
||||||
@@ -189,6 +192,7 @@ class Inode {
|
|||||||
private:
|
private:
|
||||||
Inode *fNext;
|
Inode *fNext;
|
||||||
Inode *fHashNext;
|
Inode *fHashNext;
|
||||||
|
Inode *fNameHashNext;
|
||||||
vnode_id fID;
|
vnode_id fID;
|
||||||
int32 fType;
|
int32 fType;
|
||||||
const char *fName;
|
const char *fName;
|
||||||
@@ -297,6 +301,7 @@ Volume::Volume(mount_id id)
|
|||||||
fRootNode(NULL),
|
fRootNode(NULL),
|
||||||
fNextNodeID(0),
|
fNextNodeID(0),
|
||||||
fNodeHash(NULL),
|
fNodeHash(NULL),
|
||||||
|
fNameHash(NULL),
|
||||||
fFirstEntry(NULL),
|
fFirstEntry(NULL),
|
||||||
fFirstDirCookie(NULL)
|
fFirstDirCookie(NULL)
|
||||||
{
|
{
|
||||||
@@ -308,6 +313,11 @@ Volume::Volume(mount_id id)
|
|||||||
if (fNodeHash == NULL)
|
if (fNodeHash == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fNameHash = hash_init(PIPEFS_HASH_SIZE, Inode::NameHashNextOffset(),
|
||||||
|
&Inode::name_compare_func, &Inode::name_hash_func);
|
||||||
|
if (fNameHash == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
// create the root vnode
|
// create the root vnode
|
||||||
fRootNode = CreateNode(NULL, "", S_IFDIR | 0777);
|
fRootNode = CreateNode(NULL, "", S_IFDIR | 0777);
|
||||||
if (fRootNode == NULL)
|
if (fRootNode == NULL)
|
||||||
@@ -321,6 +331,9 @@ Volume::~Volume()
|
|||||||
if (fRootNode)
|
if (fRootNode)
|
||||||
put_vnode(ID(), fRootNode->ID());
|
put_vnode(ID(), fRootNode->ID());
|
||||||
|
|
||||||
|
if (fNameHash != NULL)
|
||||||
|
hash_uninit(fNameHash);
|
||||||
|
|
||||||
if (fNodeHash != NULL) {
|
if (fNodeHash != NULL) {
|
||||||
// delete all of the inodes
|
// delete all of the inodes
|
||||||
struct hash_iterator i;
|
struct hash_iterator i;
|
||||||
@@ -380,6 +393,7 @@ Volume::CreateNode(Inode *parent, const char *name, int32 type)
|
|||||||
InsertNode(inode);
|
InsertNode(inode);
|
||||||
|
|
||||||
hash_insert(fNodeHash, inode);
|
hash_insert(fNodeHash, inode);
|
||||||
|
hash_insert(fNameHash, inode);
|
||||||
publish_vnode(ID(), inode->ID(), inode);
|
publish_vnode(ID(), inode->ID(), inode);
|
||||||
|
|
||||||
if (fRootNode != NULL)
|
if (fRootNode != NULL)
|
||||||
@@ -394,6 +408,7 @@ Volume::DeleteNode(Inode *inode, bool forceDelete)
|
|||||||
{
|
{
|
||||||
// remove it from the global hash table
|
// remove it from the global hash table
|
||||||
hash_remove(fNodeHash, inode);
|
hash_remove(fNodeHash, inode);
|
||||||
|
hash_remove(fNameHash, inode);
|
||||||
|
|
||||||
if (fRootNode != NULL)
|
if (fRootNode != NULL)
|
||||||
fRootNode->SetModificationTime(time(NULL));
|
fRootNode->SetModificationTime(time(NULL));
|
||||||
@@ -428,8 +443,7 @@ Volume::RemoveCookie(dir_cookie *cookie)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* makes sure none of the dircookies point to the vnode passed in */
|
/*! Makes sure none of the dircookies point to the vnode passed in */
|
||||||
|
|
||||||
void
|
void
|
||||||
Volume::UpdateDirCookies(Inode *inode)
|
Volume::UpdateDirCookies(Inode *inode)
|
||||||
{
|
{
|
||||||
@@ -450,17 +464,13 @@ Volume::Lookup(vnode_id id)
|
|||||||
|
|
||||||
|
|
||||||
Inode *
|
Inode *
|
||||||
Volume::FindNode(const char *name)
|
Volume::Lookup(const char *name)
|
||||||
{
|
{
|
||||||
if (!strcmp(name, ".")
|
if (!strcmp(name, ".")
|
||||||
|| !strcmp(name, ".."))
|
|| !strcmp(name, ".."))
|
||||||
return fRootNode;
|
return fRootNode;
|
||||||
|
|
||||||
for (Inode *inode = fFirstEntry; inode; inode = inode->Next()) {
|
return (Inode *)hash_lookup(fNameHash, name);
|
||||||
if (!strcmp(inode->Name(), name))
|
|
||||||
return inode;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,7 +514,7 @@ Volume::RemoveNode(Inode *directory, const char *name)
|
|||||||
|
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
|
|
||||||
Inode *inode = FindNode(name);
|
Inode *inode = Lookup(name);
|
||||||
if (inode == NULL)
|
if (inode == NULL)
|
||||||
status = B_ENTRY_NOT_FOUND;
|
status = B_ENTRY_NOT_FOUND;
|
||||||
else if (S_ISDIR(inode->Type()))
|
else if (S_ISDIR(inode->Type()))
|
||||||
@@ -842,6 +852,40 @@ Inode::compare_func(void *_node, const void *_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
Inode::NameHashNextOffset()
|
||||||
|
{
|
||||||
|
Inode *inode;
|
||||||
|
return (addr_t)&inode->fNameHashNext - (addr_t)inode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
Inode::name_hash_func(void *_node, const void *_key, uint32 range)
|
||||||
|
{
|
||||||
|
Inode *inode = (Inode *)_node;
|
||||||
|
const char *key = (const char *)_key;
|
||||||
|
|
||||||
|
if (inode != NULL)
|
||||||
|
return hash_hash_string(inode->Name()) % range;
|
||||||
|
|
||||||
|
return hash_hash_string(key) % range;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Inode::name_compare_func(void *_node, const void *_key)
|
||||||
|
{
|
||||||
|
Inode *inode = (Inode *)_node;
|
||||||
|
const char *key = (const char *)_key;
|
||||||
|
|
||||||
|
if (!strcmp(inode->Name(), key))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Inode::Select(uint8 event, uint32 ref, selectsync *sync)
|
Inode::Select(uint8 event, uint32 ref, selectsync *sync)
|
||||||
{
|
{
|
||||||
@@ -1053,7 +1097,7 @@ pipefs_lookup(fs_volume _volume, fs_vnode _dir, const char *name, vnode_id *_id,
|
|||||||
volume->Lock();
|
volume->Lock();
|
||||||
|
|
||||||
// look it up
|
// look it up
|
||||||
Inode *inode = volume->FindNode(name);
|
Inode *inode = volume->Lookup(name);
|
||||||
if (inode == NULL) {
|
if (inode == NULL) {
|
||||||
status = B_ENTRY_NOT_FOUND;
|
status = B_ENTRY_NOT_FOUND;
|
||||||
goto err;
|
goto err;
|
||||||
@@ -1171,7 +1215,7 @@ pipefs_create(fs_volume _volume, fs_vnode _dir, const char *name, int openMode,
|
|||||||
Inode *directory = (Inode *)_dir;
|
Inode *directory = (Inode *)_dir;
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
|
|
||||||
Inode *inode = volume->FindNode(name);
|
Inode *inode = volume->Lookup(name);
|
||||||
if (inode != NULL && (openMode & O_EXCL) != 0) {
|
if (inode != NULL && (openMode & O_EXCL) != 0) {
|
||||||
status = B_FILE_EXISTS;
|
status = B_FILE_EXISTS;
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
Reference in New Issue
Block a user