From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>, Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [RFC][PATCH 3/3] ovl: use persistent s_uuid with index=on
Date: Thu, 6 Jul 2023 10:19:59 +0300 [thread overview]
Message-ID: <CAOQ4uxgX0Tx07q2gAzsB2kPsUm+MjsYw9BG4W7-h8ODNnqH_1A@mail.gmail.com> (raw)
In-Reply-To: <20230425132223.2608226-4-amir73il@gmail.com>
On Tue, Apr 25, 2023 at 4:22 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> With index=on, overlayfs instances are non-migratable, meaning that
> the layers cannot be copied without breaking the index.
>
> So when indexdir exists, store a persistent uuid in xattr on the
> indexdir to give the overlayfs instance a persistent identifier.
>
> This also makes f_fsid persistent and more reliable for reporting
> fid info in fanotify events.
>
> With mount option uuid=nogen, a persistent uuid is not be initialized
> on indexdir, but if a persistent uuid already exists, it will be used.
>
This behavior (along with the grammatical mistakes) was changed in
https://github.com/amir73il/linux/commits/ovl_encode_fid
uuid=off or uuid=null both set ovl fsid to null regardless of persistent
uuid xattr.
Whether we need this backward compact option or not is to be determined.
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> fs/overlayfs/overlayfs.h | 3 +++
> fs/overlayfs/super.c | 7 +++++++
> fs/overlayfs/util.c | 41 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 51 insertions(+)
>
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index dcdb02d0ddf8..9927472a3aaa 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -36,6 +36,7 @@ enum ovl_xattr {
> OVL_XATTR_IMPURE,
> OVL_XATTR_NLINK,
> OVL_XATTR_UPPER,
> + OVL_XATTR_UUID,
> OVL_XATTR_METACOPY,
> OVL_XATTR_PROTATTR,
> };
> @@ -431,6 +432,8 @@ bool ovl_already_copied_up(struct dentry *dentry, int flags);
> bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
> enum ovl_xattr ox);
> bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, const struct path *path);
> +bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
> + struct dentry *upperdentry, bool set);
>
> static inline bool ovl_check_origin_xattr(struct ovl_fs *ofs,
> struct dentry *upperdentry)
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index ad2250f98b38..8364620e8722 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -1535,6 +1535,9 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
> if (err)
> pr_err("failed to verify index dir 'upper' xattr\n");
>
> + /* Best effort get or set persistent uuid */
> + ovl_init_uuid_xattr(sb, ofs, ofs->indexdir, true);
> +
> /* Cleanup bad/stale/orphan index entries */
> if (!err)
> err = ovl_indexdir_cleanup(ofs);
> @@ -2052,6 +2055,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
> ovl_uuid_str[ofs->config.uuid]);
> }
>
> + /*
> + * This uuid may be overridden by a persistent uuid stored in xattr on
> + * index dir and it may be persisted in xattr on first index=on mount.
> + */
> if (ovl_want_uuid_gen(ofs))
> uuid_gen(&sb->s_uuid);
>
> diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> index 923d66d131c1..8902db4b2975 100644
> --- a/fs/overlayfs/util.c
> +++ b/fs/overlayfs/util.c
> @@ -589,6 +589,45 @@ bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, const struct path *path)
> return false;
> }
>
> +/*
> + * Load persistent uuid from xattr into s_uuid if found, possibly overriding
> + * the random generated value in s_uuid.
> + * Otherwise, if @set is true and s_uuid contains a valid value, store this
> + * value in xattr.
> + */
> +bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
> + struct dentry *upperdentry, bool set)
> +{
> + struct path path = {
> + .dentry = upperdentry,
> + .mnt = ovl_upper_mnt(ofs),
> + };
> + uuid_t uuid;
> + int res;
> +
> + res = ovl_path_getxattr(ofs, &path, OVL_XATTR_UUID, uuid.b, UUID_SIZE);
> + if (res == UUID_SIZE) {
> + uuid_copy(&sb->s_uuid, &uuid);
> + return true;
> + }
> +
> + if (res == -ENODATA) {
> + if (!set || uuid_is_null(&sb->s_uuid))
> + return false;
> +
> + res = ovl_setxattr(ofs, upperdentry, OVL_XATTR_UUID,
> + sb->s_uuid.b, UUID_SIZE);
> + if (res == 0)
> + return true;
> + } else {
> + set = false;
> + }
> +
> + pr_warn("failed to %s uuid (%pd2, err=%i)\n",
> + set ? "set" : "get", upperdentry, res);
> + return false;
> +}
> +
> bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
> enum ovl_xattr ox)
> {
> @@ -611,6 +650,7 @@ bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
> #define OVL_XATTR_IMPURE_POSTFIX "impure"
> #define OVL_XATTR_NLINK_POSTFIX "nlink"
> #define OVL_XATTR_UPPER_POSTFIX "upper"
> +#define OVL_XATTR_UUID_POSTFIX "uuid"
> #define OVL_XATTR_METACOPY_POSTFIX "metacopy"
> #define OVL_XATTR_PROTATTR_POSTFIX "protattr"
>
> @@ -625,6 +665,7 @@ const char *const ovl_xattr_table[][2] = {
> OVL_XATTR_TAB_ENTRY(OVL_XATTR_IMPURE),
> OVL_XATTR_TAB_ENTRY(OVL_XATTR_NLINK),
> OVL_XATTR_TAB_ENTRY(OVL_XATTR_UPPER),
> + OVL_XATTR_TAB_ENTRY(OVL_XATTR_UUID),
> OVL_XATTR_TAB_ENTRY(OVL_XATTR_METACOPY),
> OVL_XATTR_TAB_ENTRY(OVL_XATTR_PROTATTR),
> };
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-07-06 7:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 13:22 [RFC][PATCH 0/3] Prepare for supporting more filesystems with fanotify Amir Goldstein
2023-04-25 13:22 ` [RFC][PATCH 1/3] ovl: support encoding non-decodeable file handles Amir Goldstein
2023-07-06 7:27 ` Amir Goldstein
2023-04-25 13:22 ` [RFC][PATCH 2/3] ovl: report a per-instance f_fsid by default Amir Goldstein
2023-04-25 13:22 ` [RFC][PATCH 3/3] ovl: use persistent s_uuid with index=on Amir Goldstein
2023-07-06 7:19 ` Amir Goldstein [this message]
2023-07-06 10:14 ` Amir Goldstein
2023-07-06 17:49 ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOQ4uxgX0Tx07q2gAzsB2kPsUm+MjsYw9BG4W7-h8ODNnqH_1A@mail.gmail.com \
--to=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).