ovl: restructure dentry revalidation
authorMiklos Szeredi <mszeredi@redhat.com>
Tue, 17 Mar 2020 14:04:22 +0000 (15:04 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 17 Mar 2020 14:04:22 +0000 (15:04 +0100)
Use a common loop for plain and weak revalidation.  This will aid doing
revalidation on upper layer.

This patch doesn't change behavior.

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

index 4db51c7..a05bf11 100644 (file)
@@ -113,47 +113,48 @@ bug:
        return dentry;
 }
 
-static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
+static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
 {
-       struct ovl_entry *oe = dentry->d_fsdata;
-       unsigned int i;
        int ret = 1;
 
-       for (i = 0; i < oe->numlower; i++) {
-               struct dentry *d = oe->lowerstack[i].dentry;
-
-               if (d->d_flags & DCACHE_OP_REVALIDATE) {
-                       ret = d->d_op->d_revalidate(d, flags);
-                       if (ret < 0)
-                               return ret;
-                       if (!ret) {
-                               if (!(flags & LOOKUP_RCU))
-                                       d_invalidate(d);
-                               return -ESTALE;
-                       }
+       if (weak) {
+               if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE)
+                       ret =  d->d_op->d_weak_revalidate(d, flags);
+       } else if (d->d_flags & DCACHE_OP_REVALIDATE) {
+               ret = d->d_op->d_revalidate(d, flags);
+               if (!ret) {
+                       if (!(flags & LOOKUP_RCU))
+                               d_invalidate(d);
+                       ret = -ESTALE;
                }
        }
-       return 1;
+       return ret;
 }
 
-static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
+static int ovl_dentry_revalidate_common(struct dentry *dentry,
+                                       unsigned int flags, bool weak)
 {
        struct ovl_entry *oe = dentry->d_fsdata;
        unsigned int i;
        int ret = 1;
 
-       for (i = 0; i < oe->numlower; i++) {
-               struct dentry *d = oe->lowerstack[i].dentry;
-
-               if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) {
-                       ret = d->d_op->d_weak_revalidate(d, flags);
-                       if (ret <= 0)
-                               break;
-               }
+       for (i = 0; ret > 0 && i < oe->numlower; i++) {
+               ret = ovl_revalidate_real(oe->lowerstack[i].dentry, flags,
+                                         weak);
        }
        return ret;
 }
 
+static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
+{
+       return ovl_dentry_revalidate_common(dentry, flags, false);
+}
+
+static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
+{
+       return ovl_dentry_revalidate_common(dentry, flags, true);
+}
+
 static const struct dentry_operations ovl_dentry_operations = {
        .d_release = ovl_dentry_release,
        .d_real = ovl_d_real,