]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ubifs: Correctly evict xattr inodes
authorRichard Weinberger <richard@nod.at>
Tue, 16 May 2017 22:20:27 +0000 (00:20 +0200)
committerRichard Weinberger <richard@nod.at>
Fri, 14 Jul 2017 20:49:04 +0000 (22:49 +0200)
UBIFS handles extended attributes just like files, as consequence of
that, they also have inodes.
Therefore UBIFS does all the inode machinery also for xattrs. Since new
inodes have i_nlink of 1, a file or xattr inode will be evicted
if i_nlink goes down to 0 after an unlink. UBIFS assumes this model also
for xattrs, which is not correct.
One can create a file "foo" with xattr "user.test". By reading
"user.test" an inode will be created, and by deleting "user.test" it
will get evicted later. The assumption breaks if the file "foo", which
hosts the xattrs, will be removed. VFS nor UBIFS does not remove each
xattr via ubifs_xattr_remove(), it just removes the host inode from
the TNC and all underlying xattr nodes too and the inode will remain
in the cache and wastes memory.

To solve this problem, remove xattr inodes from the VFS inode cache in
ubifs_xattr_remove() to make sure that they get evicted.

Fixes: 1e51764a3c2ac05a ("UBIFS: add new flash file system")
Cc: <stable@vger.kernel.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/tnc.c
fs/ubifs/ubifs.h
fs/ubifs/xattr.c

index 709aa098dd46e48e34a9627cd0af85d136737fab..96374a39ffbae346a3dba8112c57a4a87eb91df7 100644 (file)
@@ -2802,6 +2802,8 @@ int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum)
                dbg_tnc("xent '%s', ino %lu", xent->name,
                        (unsigned long)xattr_inum);
 
+               ubifs_evict_xattr_inode(c, xattr_inum);
+
                fname_name(&nm) = xent->name;
                fname_len(&nm) = le16_to_cpu(xent->nlen);
                err = ubifs_tnc_remove_nm(c, &key1, &nm);
index aa530e82e9a8adc0bc2fd9c2d2d1a960cd49c151..998fb6eea5ac0f39a81a3f3f166be5698c5abca0 100644 (file)
@@ -1756,6 +1756,7 @@ int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
                    size_t size, int flags);
 ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
                        size_t size);
+void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
 
 #ifdef CONFIG_UBIFS_FS_SECURITY
 extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
index 6c9e62c2ef559b2d6b3d3383436775795e927375..98f11257d66c09cc9311192d247c23c19b2f07c4 100644 (file)
@@ -513,6 +513,28 @@ out_cancel:
        return err;
 }
 
+/**
+ * ubifs_evict_xattr_inode - Evict an xattr inode.
+ * @c: UBIFS file-system description object
+ * @xattr_inum: xattr inode number
+ *
+ * When an inode that hosts xattrs is being removed we have to make sure
+ * that cached inodes of the xattrs also get removed from the inode cache
+ * otherwise we'd waste memory. This function looks up an inode from the
+ * inode cache and clears the link counter such that iput() will evict
+ * the inode.
+ */
+void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum)
+{
+       struct inode *inode;
+
+       inode = ilookup(c->vfs_sb, xattr_inum);
+       if (inode) {
+               clear_nlink(inode);
+               iput(inode);
+       }
+}
+
 static int ubifs_xattr_remove(struct inode *host, const char *name)
 {
        struct inode *inode;