linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Chengguang Xu <cgxu519@mykernel.net>,
	overlayfs <linux-unionfs@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] ovl: consistent behavior for immutable/append-only inodes
Date: Fri, 18 Jun 2021 15:57:14 +0200	[thread overview]
Message-ID: <CAJfpegv9e1oTyu+9Z-TyZQmNG0NrJhokXd8UbaRNft3_bwBEjQ@mail.gmail.com> (raw)
In-Reply-To: <20210617152241.987010-4-amir73il@gmail.com>

On Thu, 17 Jun 2021 at 17:22, Amir Goldstein <amir73il@gmail.com> wrote:

> Instead, if any of the fileattr flags of interest exist on the lower
> inode, we store them in overlay.xflags xattr on the upper inode and we
> we read the flags from xattr on lookup and on fileattr_get().

Calling this xflags, especially near fileattr code, makes it easy to
confuse with fsx_xflags.   Can we find a more distinctive name?

> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> index aec353a2dc80..d66e51b9c347 100644
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -162,7 +162,8 @@ int ovl_getattr(struct user_namespace *mnt_userns, const struct path *path,
>         enum ovl_path_type type;
>         struct path realpath;
>         const struct cred *old_cred;
> -       bool is_dir = S_ISDIR(dentry->d_inode->i_mode);
> +       struct inode *inode = d_inode(dentry);
> +       bool is_dir = S_ISDIR(inode->i_mode);
>         int fsid = 0;
>         int err;
>         bool metacopy_blocks = false;
> @@ -175,6 +176,10 @@ int ovl_getattr(struct user_namespace *mnt_userns, const struct path *path,
>         if (err)
>                 goto out;
>
> +       /* Report immutable/append-only STATX flags */
> +       if (ovl_test_flag(OVL_XFLAGS, inode))
> +               ovl_fill_xflags(inode, stat, NULL);
> +

Filesystems are doing these transformations: (already down one from
before fileattr)

internal flags -> statx->attributes
internal flags -> inode->i_flags
internal flags <-> fa->flags or fa->fsx_xflags

To further improve this situation the statx filling could be moved to
generic code based on i_flags.  I'm not asking you to convert all
filesystems (though that would be nice), but adding the helpers and
using them here would be a good first step.

> @@ -639,6 +642,174 @@ int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry)
>         return err;
>  }
>
> +
> +/*
> + * Overlayfs stores immutable/append-only attributes in overlay.xflags xattr.
> + * If upper inode does have those fileattr flags set (i.e. from old kernel),
> + * overlayfs does not clear them on fileattr_get(), but it will clear them on
> + * fileattr_set().
> + */
> +#define OVL_XFLAG(c, x) \
> +       { c, S_ ## x, FS_ ## x ## _FL, FS_XFLAG_ ## x, STATX_ATTR_ ## x }
> +
> +struct ovl_xflag {
> +       char code;
> +       u32 i_flag;
> +       u32 fs_flag;
> +       u32 fsx_flag;
> +       u64 statx_attr;
> +} const ovl_xflags[] = {
> +       OVL_XFLAG('a', APPEND),
> +       OVL_XFLAG('i', IMMUTABLE),
> +};

This would be really nice for a dozen flags, but for two...

My guess is that many lines of code could be saved by un-generalizing this.

> +/* Set inode flags and xflags xattr from fileattr */
> +int ovl_set_xflags(struct inode *inode, struct dentry *upper,
> +                  struct fileattr *fa)
> +{
> +       struct ovl_fs *ofs = OVL_FS(inode->i_sb);
> +       char buf[OVL_XFLAGS_NUM];
> +       int len, err = 0;
> +
> +       BUILD_BUG_ON(OVL_XFLAGS_NUM >= OVL_XFLAGS_MAX);
> +       len = ovl_xflags_to_buf(inode, buf, OVL_XFLAGS_NUM, fa);
> +
> +       /*
> +        * Do not fail when upper doesn't support xattrs, but also do not
> +        * mask out the xattr xflags from real fileattr to continue
> +        * supporting fileattr_set() on fs without xattr support.
> +        * Remove xattr if it exist and all flags are cleared.
> +        */

Does this matter in practice?   I.e. is there any filesystem with
immutable/append attribute but not xattr that could be an upper layer?

If yes, then this could end up as a copy-up regression (failure to
copy up files having immutable/append).

Thanks,
Miklos

  reply	other threads:[~2021-06-18 13:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17 15:22 [PATCH v2 0/3] Overlayfs fileattr related fixes Amir Goldstein
2021-06-17 15:22 ` [PATCH v2 1/3] ovl: pass ovl_fs to ovl_check_setxattr() Amir Goldstein
2021-06-17 15:22 ` [PATCH v2 2/3] ovl: copy up sync/noatime fileattr flags Amir Goldstein
2021-06-17 15:22 ` [PATCH v2 3/3] ovl: consistent behavior for immutable/append-only inodes Amir Goldstein
2021-06-18 13:57   ` Miklos Szeredi [this message]
2021-06-18 15:54     ` 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=CAJfpegv9e1oTyu+9Z-TyZQmNG0NrJhokXd8UbaRNft3_bwBEjQ@mail.gmail.com \
    --to=miklos@szeredi.hu \
    --cc=amir73il@gmail.com \
    --cc=cgxu519@mykernel.net \
    --cc=linux-unionfs@vger.kernel.org \
    /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).