OSDN Git Service

ovl: Initialize ovl_inode->redirect in ovl_get_inode()
authorVivek Goyal <vgoyal@redhat.com>
Fri, 11 May 2018 15:49:27 +0000 (11:49 -0400)
committerMiklos Szeredi <mszeredi@redhat.com>
Fri, 20 Jul 2018 07:56:05 +0000 (09:56 +0200)
ovl_inode->redirect is an inode property and should be initialized in
ovl_get_inode() only when we are adding a new inode to cache.  If inode is
already in cache, it is already initialized and we should not be touching
ovl_inode->redirect field.

As of now this is not a problem as redirects are used only for directories
which don't share inode.  But soon I want to use redirects for regular
files also and there it can become an issue.

Hence, move ->redirect initialization in ovl_get_inode().

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/inode.c
fs/overlayfs/namei.c
fs/overlayfs/overlayfs.h

index 28ee802..4833545 100644 (file)
@@ -844,6 +844,7 @@ struct inode *ovl_get_inode(struct super_block *sb,
                        }
 
                        dput(upperdentry);
+                       kfree(oip->redirect);
                        goto out;
                }
 
@@ -867,6 +868,8 @@ struct inode *ovl_get_inode(struct super_block *sb,
        if (oip->index)
                ovl_set_flag(OVL_INDEX, inode);
 
+       OVL_I(inode)->redirect = oip->redirect;
+
        /* Check for non-merge dir that may have whiteouts */
        if (is_dir) {
                if (((upperdentry && lowerdentry) || oip->numlower > 1) ||
index c993dd8..ebc377b 100644 (file)
@@ -1009,19 +1009,13 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                        .lowerpath = stack,
                        .index = index,
                        .numlower = ctr,
+                       .redirect = upperredirect,
                };
 
                inode = ovl_get_inode(dentry->d_sb, &oip);
                err = PTR_ERR(inode);
                if (IS_ERR(inode))
                        goto out_free_oe;
-
-               /*
-                * NB: handle redirected hard links when non-dir redirects
-                * become possible
-                */
-               WARN_ON(OVL_I(inode)->redirect);
-               OVL_I(inode)->redirect = upperredirect;
        }
 
        revert_creds(old_cred);
index 16d439e..69010e3 100644 (file)
@@ -335,6 +335,7 @@ struct ovl_inode_params {
        struct ovl_path *lowerpath;
        struct dentry *index;
        unsigned int numlower;
+       char *redirect;
 };
 struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
 struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,