Skip to contentSkip to conversation

drop sysfs inode number functionality?

DISCUSSION Adam J. Richter 3 participants 3 messages Dec 12, 2004 – Dec 13, 2004 VFS

lore
Share & tools
lore
#0 lore raw

There are some further reductions in sysfs memory consumption
that I would like to make which would be easier if sysfs would make no attempt to avoid duplicate inode numbers.

Currently, the readdir routine in sysfs generates a new inode
number for any node that does not at that moment have a struct dentry. Repeated calls to readdir will return different inode numbers, but it is very rare that reading information about two different nodes will return the same inode number.

If a struct dentry exists (normally because someone has a file
descriptor open on the node), then readdir and stat will always consistently return the same inode number for the same node. To accomplish this, sysfs_readdir currently reads sysfs_dirent.s_dentry. I want to eliminate sysfs_dirent.s_dentry for non-directories and eliminate the sysfs_dirent structures for attributes that are part of an attribute_group directory.

The approach which would involve the smallest implementation
would be just to return zero or some other constant for the inode number in all cases. My inclination is to try this first, and then switch to another approach if it causes problems.

A second approach would be to find some unique memory address
to cast to the inode number (the address of the sysfs_dirent perhaps, or even different addresses for different types of sysfs nodes). This is a slight problem for members of attribute groups, since there is no unique address (the struct attribute may be pointed to by many instances of the same type of kobject), but I could use addresses of bytes within the sysfs_dirent structure as unique addresses as long as their are fewer than about 28 attributes, and I could even allocate extra bytes on the struct sysfs_dirent to guarantee enough unique addresses in cases where a group has more than 28 attributes.

A third approach would be actually to allocate inode numbers
or ranges of them, and store them in struct sysfs_dirent. This would increasee memory consumption, and if it is necessary to worry about the index wrapping around and potentially being duplicated, then the implementation will be slightly more involved.

My inclination is to try to make sysfs always return 0 or
something similar as the inode number. Comments?

                    __     ______________ 

Adam J. Richter \ /
[email protected] | g g d r a s i l

#1 lore raw

All other issues aside, inode number 0 is special cased by glibc and all your files with inode number 0 are invisible to "ls". In ntfs the $MFT system file has inode number 0 and if you do "ls" it does not appear. But if you do "ls \$MFT" it does appear and if you do "stat \$MFT" it also returns the correct information. So if you return inode 0 for all things sysfs the whole sysfs tree would be invisible which is probably not what you want...

Best regards,

Anton

Quoted 46 lines · Adam J. Richter

There are some further reductions in sysfs memory consumption
that I would like to make which would be easier if sysfs would make no attempt to avoid duplicate inode numbers.

Currently, the readdir routine in sysfs generates a new inode
number for any node that does not at that moment have a struct dentry. Repeated calls to readdir will return different inode numbers, but it is very rare that reading information about two different nodes will return the same inode number.

If a struct dentry exists (normally because someone has a file
descriptor open on the node), then readdir and stat will always consistently return the same inode number for the same node. To accomplish this, sysfs_readdir currently reads sysfs_dirent.s_dentry. I want to eliminate sysfs_dirent.s_dentry for non-directories and eliminate the sysfs_dirent structures for attributes that are part of an attribute_group directory.

The approach which would involve the smallest implementation
would be just to return zero or some other constant for the inode number in all cases. My inclination is to try this first, and then switch to another approach if it causes problems.

A second approach would be to find some unique memory address
to cast to the inode number (the address of the sysfs_dirent perhaps, or even different addresses for different types of sysfs nodes). This is a slight problem for members of attribute groups, since there is no unique address (the struct attribute may be pointed to by many instances of the same type of kobject), but I could use addresses of bytes within the sysfs_dirent structure as unique addresses as long as their are fewer than about 28 attributes, and I could even allocate extra bytes on the struct sysfs_dirent to guarantee enough unique addresses in cases where a group has more than 28 attributes.

A third approach would be actually to allocate inode numbers
or ranges of them, and store them in struct sysfs_dirent. This would increasee memory consumption, and if it is necessary to worry about the index wrapping around and potentially being duplicated, then the implementation will be slightly more involved.

My inclination is to try to make sysfs always return 0 or
something similar as the inode number. Comments?

                    __     ______________ 

Adam J. Richter \ /
[email protected] | g g d r a s i l

Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
#2 lore raw
In reply to Adam J. Richter
Quoted 3 lines · Adam J. Richter

There are some further reductions in sysfs memory consumption
that I would like to make which would be easier if sysfs would make no attempt to avoid duplicate inode numbers.

It would be a Good Thing for sysfs to be exportable as a network filesystem. Remote debugging, that kind of thing. NFS, at least, blow up and goes boom if files have non-unique inode numbers. So I'd be disappointed if sysfs stopped having unique inode numbers for files.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain