ovl: simplify empty checking
authorMiklos Szeredi <mszeredi@redhat.com>
Fri, 29 Jul 2016 10:05:25 +0000 (12:05 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Fri, 29 Jul 2016 10:05:25 +0000 (12:05 +0200)
The empty checking logic is duplicated in ovl_check_empty_and_clear() and
ovl_remove_and_whiteout(), except the condition for clearing whiteouts is
different:

ovl_check_empty_and_clear() checked for being upper

ovl_remove_and_whiteout() checked for merge OR lower

Move the intersection of those checks (upper AND merge) into
ovl_check_empty_and_clear() and simplify ovl_remove_and_whiteout().

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/dir.c

index ddda948109d391a050c9e2171a85e6fb32f95720..12bcd07b9e32c516f89605a7247da493d3ccedad 100644 (file)
@@ -307,23 +307,29 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry)
 {
        int err;
        struct dentry *ret = NULL;
+       enum ovl_path_type type = ovl_path_type(dentry);
        LIST_HEAD(list);
 
        err = ovl_check_empty_dir(dentry, &list);
-       if (err)
+       if (err) {
                ret = ERR_PTR(err);
-       else {
-               /*
-                * If no upperdentry then skip clearing whiteouts.
-                *
-                * Can race with copy-up, since we don't hold the upperdir
-                * mutex.  Doesn't matter, since copy-up can't create a
-                * non-empty directory from an empty one.
-                */
-               if (ovl_dentry_upper(dentry))
-                       ret = ovl_clear_empty(dentry, &list);
+               goto out_free;
        }
 
+       /*
+        * When removing an empty opaque directory, then it makes no sense to
+        * replace it with an exact replica of itself.
+        *
+        * If no upperdentry then skip clearing whiteouts.
+        *
+        * Can race with copy-up, since we don't hold the upperdir mutex.
+        * Doesn't matter, since copy-up can't create a non-empty directory
+        * from an empty one.
+        */
+       if (OVL_TYPE_UPPER(type) && OVL_TYPE_MERGE(type))
+               ret = ovl_clear_empty(dentry, &list);
+
+out_free:
        ovl_cache_free(&list);
 
        return ret;
@@ -551,24 +557,10 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
                return -EROFS;
 
        if (is_dir) {
-               if (OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) {
-                       opaquedir = ovl_check_empty_and_clear(dentry);
-                       err = PTR_ERR(opaquedir);
-                       if (IS_ERR(opaquedir))
-                               goto out;
-               } else {
-                       LIST_HEAD(list);
-
-                       /*
-                        * When removing an empty opaque directory, then it
-                        * makes no sense to replace it with an exact replica of
-                        * itself.  But emptiness still needs to be checked.
-                        */
-                       err = ovl_check_empty_dir(dentry, &list);
-                       ovl_cache_free(&list);
-                       if (err)
-                               goto out;
-               }
+               opaquedir = ovl_check_empty_and_clear(dentry);
+               err = PTR_ERR(opaquedir);
+               if (IS_ERR(opaquedir))
+                       goto out;
        }
 
        err = ovl_lock_rename_workdir(workdir, upperdir);