]> Pileus Git - ~andy/linux/blobdiff - fs/nilfs2/super.c
nilfs2: implement calculation of free inodes count
[~andy/linux] / fs / nilfs2 / super.c
index c7d1f9f18b094fb1f281fb0dfcb6b53328dc72fe..7d257e78fbad197701f8ea2a25ba12c7494d85b3 100644 (file)
@@ -609,6 +609,7 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        unsigned long overhead;
        unsigned long nrsvblocks;
        sector_t nfreeblocks;
+       u64 nmaxinodes, nfreeinodes;
        int err;
 
        /*
@@ -633,14 +634,34 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        if (unlikely(err))
                return err;
 
+       err = nilfs_ifile_count_free_inodes(root->ifile,
+                                           &nmaxinodes, &nfreeinodes);
+       if (unlikely(err)) {
+               printk(KERN_WARNING
+                       "NILFS warning: fail to count free inodes: err %d.\n",
+                       err);
+               if (err == -ERANGE) {
+                       /*
+                        * If nilfs_palloc_count_max_entries() returns
+                        * -ERANGE error code then we simply treat
+                        * curent inodes count as maximum possible and
+                        * zero as free inodes value.
+                        */
+                       nmaxinodes = atomic_read(&root->inodes_count);
+                       nfreeinodes = 0;
+                       err = 0;
+               } else
+                       return err;
+       }
+
        buf->f_type = NILFS_SUPER_MAGIC;
        buf->f_bsize = sb->s_blocksize;
        buf->f_blocks = blocks - overhead;
        buf->f_bfree = nfreeblocks;
        buf->f_bavail = (buf->f_bfree >= nrsvblocks) ?
                (buf->f_bfree - nrsvblocks) : 0;
-       buf->f_files = atomic_read(&root->inodes_count);
-       buf->f_ffree = 0; /* nilfs_count_free_inodes(sb); */
+       buf->f_files = nmaxinodes;
+       buf->f_ffree = nfreeinodes;
        buf->f_namelen = NILFS_NAME_LEN;
        buf->f_fsid.val[0] = (u32)id;
        buf->f_fsid.val[1] = (u32)(id >> 32);