]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - fs/overlayfs/util.c
Merge tag 'vfs-6.9.uuid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[thirdparty/linux.git] / fs / overlayfs / util.c
index ed71480d8adbe0266697367ca9780a6f851e4f0a..d285d1d7baaddedf6fc938ac8aaf8dc35e74d7d7 100644 (file)
@@ -461,6 +461,33 @@ void ovl_dentry_set_opaque(struct dentry *dentry)
        ovl_dentry_set_flag(OVL_E_OPAQUE, dentry);
 }
 
+bool ovl_dentry_has_xwhiteouts(struct dentry *dentry)
+{
+       return ovl_dentry_test_flag(OVL_E_XWHITEOUTS, dentry);
+}
+
+void ovl_dentry_set_xwhiteouts(struct dentry *dentry)
+{
+       ovl_dentry_set_flag(OVL_E_XWHITEOUTS, dentry);
+}
+
+/*
+ * ovl_layer_set_xwhiteouts() is called before adding the overlay dir
+ * dentry to dcache, while readdir of that same directory happens after
+ * the overlay dir dentry is in dcache, so if some cpu observes that
+ * ovl_dentry_is_xwhiteouts(), it will also observe layer->has_xwhiteouts
+ * for the layers where xwhiteouts marker was found in that merge dir.
+ */
+void ovl_layer_set_xwhiteouts(struct ovl_fs *ofs,
+                             const struct ovl_layer *layer)
+{
+       if (layer->has_xwhiteouts)
+               return;
+
+       /* Write once to read-mostly layer properties */
+       ofs->layers[layer->idx].has_xwhiteouts = true;
+}
+
 /*
  * For hard links and decoded file handles, it's possible for ovl_dentry_upper()
  * to return positive, while there's no actual upper alias for the inode.
@@ -739,19 +766,6 @@ bool ovl_path_check_xwhiteout_xattr(struct ovl_fs *ofs, const struct path *path)
        return res >= 0;
 }
 
-bool ovl_path_check_xwhiteouts_xattr(struct ovl_fs *ofs, const struct path *path)
-{
-       struct dentry *dentry = path->dentry;
-       int res;
-
-       /* xattr.whiteouts must be a directory */
-       if (!d_is_dir(dentry))
-               return false;
-
-       res = ovl_path_getxattr(ofs, path, OVL_XATTR_XWHITEOUTS, NULL, 0);
-       return res >= 0;
-}
-
 /*
  * Load persistent uuid from xattr into s_uuid if found, or store a new
  * random generated value in s_uuid and in xattr.
@@ -815,20 +829,17 @@ fail:
        return false;
 }
 
-bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
-                              enum ovl_xattr ox)
+char ovl_get_dir_xattr_val(struct ovl_fs *ofs, const struct path *path,
+                          enum ovl_xattr ox)
 {
        int res;
        char val;
 
        if (!d_is_dir(path->dentry))
-               return false;
+               return 0;
 
        res = ovl_path_getxattr(ofs, path, ox, &val, 1);
-       if (res == 1 && val == 'y')
-               return true;
-
-       return false;
+       return res == 1 ? val : 0;
 }
 
 #define OVL_XATTR_OPAQUE_POSTFIX       "opaque"
@@ -841,7 +852,6 @@ bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
 #define OVL_XATTR_METACOPY_POSTFIX     "metacopy"
 #define OVL_XATTR_PROTATTR_POSTFIX     "protattr"
 #define OVL_XATTR_XWHITEOUT_POSTFIX    "whiteout"
-#define OVL_XATTR_XWHITEOUTS_POSTFIX   "whiteouts"
 
 #define OVL_XATTR_TAB_ENTRY(x) \
        [x] = { [false] = OVL_XATTR_TRUSTED_PREFIX x ## _POSTFIX, \
@@ -858,7 +868,6 @@ const char *const ovl_xattr_table[][2] = {
        OVL_XATTR_TAB_ENTRY(OVL_XATTR_METACOPY),
        OVL_XATTR_TAB_ENTRY(OVL_XATTR_PROTATTR),
        OVL_XATTR_TAB_ENTRY(OVL_XATTR_XWHITEOUT),
-       OVL_XATTR_TAB_ENTRY(OVL_XATTR_XWHITEOUTS),
 };
 
 int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry,