lkml.org 
[lkml]   [2010]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 3/7] sysfs: Keep an nlink count on sysfs directories.
    From
    Date
    "Serge E. Hallyn" <serue@us.ibm.com> writes:

    > Quoting Eric W. Biederman (ebiederm@xmission.com):
    >> From: Eric W. Biederman <ebiederm@aristanetworks.com>
    >>
    >> On large directories sysfs_count_nlinks can be a significant
    >> bottleneck, so keep a count in sysfs_dirent. If we exceed
    >> the maximum number of directory entries we can store return
    >> nlink of 1. An nlink of 1 matches what reiserfs does in
    >> this case, and it let's find and similar utlities know that
    >> we have a the directory nlink can not be used for optimization
    >> purposes.
    >>
    >> Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
    >> ---
    >> fs/sysfs/dir.c | 20 ++++++++++++++++++++
    >> fs/sysfs/inode.c | 15 +--------------
    >> fs/sysfs/mount.c | 1 +
    >> fs/sysfs/sysfs.h | 1 +
    >> 4 files changed, 23 insertions(+), 14 deletions(-)
    >>
    >> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
    >> index 5c4703d..1c364be 100644
    >> --- a/fs/sysfs/dir.c
    >> +++ b/fs/sysfs/dir.c
    >> @@ -359,6 +359,7 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
    >> sd->s_name = name;
    >> sd->s_mode = mode;
    >> sd->s_flags = type;
    >> + sd->s_nlink = type == SYSFS_DIR? 2:1;
    >>
    >> return sd;
    >>
    >> @@ -392,6 +393,23 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
    >> mutex_lock(&sysfs_mutex);
    >> }
    >>
    >> +static void sysfs_dir_inc_nlink(struct sysfs_dirent *sd)
    >> +{
    >> + /* If we overflow force nlink to be 1 */
    >> + if (sd->s_nlink > 1) {
    >> + sd->s_nlink++;
    >> + if (sd->s_nlink == 0)
    >> + sd->s_nlink = 1;
    >> + }
    >> +}
    >
    > Now, the original code only ups nlink on parent if child is a dir.
    > IIUC your code will now inc nlink for files as well. Is any userspace
    > going to be confused by that?

    Good point. nlink should only be upped for directories.

    Eric


    \
     
     \ /
      Last update: 2010-01-12 09:33    [W:0.026 / U:0.972 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site