[Libsysio-commit] HEAD: libsysio/src inode.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-15 18:01:02
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv9577/src Modified Files: inode.c Log Message: Eliminated the i-node number field from the inode structure. We already carry the file identifier so it was redundant. Problematic too, in that it can be 32 or 64 bits in size. This forced _sysio_i_new() and _sysio_i_find() to change -- They no longer take the i-node number as an argument. Updated the driver calls to reflect the new usage. The i-node cache is now indexed by hashing the file identifier as opposed to just using the, no longer maintained, i-node number. This caused _sysio_i_find to become 2+ percent more expensive to use. Acceptable for me. Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -b -B -p -r1.10 -r1.11 --- inode.c 8 Sep 2003 15:43:21 -0000 1.10 +++ inode.c 15 Oct 2003 18:00:57 -0000 1.11 @@ -171,6 +171,23 @@ i_reclaim() max_inodes += t; } +static unsigned +hash(struct file_identifier *fid) +{ + size_t n; + void *p; + unsigned hkey; + + n = fid->fid_len; + p = fid->fid_data; + hkey = 0; + do { + hkey <<= 1; + hkey += *(unsigned char *)p++; + } while (--n); + return hkey; +} + /* * Allocate and initialize a new i-node. Returned i-node is referenced. * @@ -179,7 +196,6 @@ i_reclaim() */ struct inode * _sysio_i_new(struct filesys *fs, - ino_t inum, struct file_identifier *fid, mode_t type, dev_t rdev, @@ -217,10 +233,10 @@ _sysio_i_new(struct filesys *fs, ino->i_ops.inop_datasync = o->inop_datasync; ino->i_ops.inop_ioctl = o->inop_ioctl; } - I_INIT(ino, fs, inum, type, rdev, &ino->i_ops, fid, immunity, private); + I_INIT(ino, fs, type, rdev, &ino->i_ops, fid, immunity, private); ino->i_ref = 1; TAILQ_INSERT_TAIL(&_sysio_inodes, ino, i_nodes); - head = &fs->fs_itbl[inum % FS_ITBLSIZ]; + head = &fs->fs_itbl[hash(fid) % FS_ITBLSIZ]; LIST_INSERT_HEAD(head, ino, i_link); n_inodes++; @@ -234,18 +250,17 @@ _sysio_i_new(struct filesys *fs, * and identifier. */ struct inode * -_sysio_i_find(struct filesys *fs, ino_t inum, struct file_identifier *fid) +_sysio_i_find(struct filesys *fs, struct file_identifier *fid) { struct inode *ino; struct itable_entry *head; - head = &fs->fs_itbl[inum % FS_ITBLSIZ]; + head = &fs->fs_itbl[hash(fid) % FS_ITBLSIZ]; /* * Look for existing. */ for (ino = head->lh_first; ino; ino = ino->i_link.le_next) - if (ino->i_num == inum && - ino->i_fid->fid_len == fid->fid_len && + if (ino->i_fid->fid_len == fid->fid_len && memcmp(ino->i_fid->fid_data, fid->fid_data, fid->fid_len) == 0) { |