linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andreas Dilger <adilger@dilger.ca>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Christoph Hellwig <hch@lst.de>,
	"Darrick J . Wong" <djwong@kernel.org>,
	Dave Kleikamp <shaggy@kernel.org>,
	David Sterba <dsterba@suse.com>, Jaegeuk Kim <jaegeuk@kernel.org>,
	Joel Becker <jlbec@evilplan.org>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	Mike Marshall <hubcap@omnibond.com>,
	Richard Weinberger <richard@nod.at>,
	Ryusuke Konishi <konishi.ryusuke@gmail.com>,
	"Theodore Ts'o" <tytso@mit.edu>, Tyler Hicks <code@tyhicks.com>
Subject: Re: [PATCH 01/18] vfs: add miscattr ops
Date: Wed, 3 Feb 2021 16:21:51 +0100	[thread overview]
Message-ID: <CAOssrKesMbzG9bX5HiDvCJTpdrCkvP7cg5nsZHCy4_QkJNEVZg@mail.gmail.com> (raw)
In-Reply-To: <20210203150448.GD7094@quack2.suse.cz>

On Wed, Feb 3, 2021 at 4:05 PM Jan Kara <jack@suse.cz> wrote:

[...]
> > +/**
> > + * miscattr_fill_xflags - initialize miscattr with xflags
> > + * @ma:              miscattr pointer
> > + * @xflags:  FS_XFLAG_* flags
> > + *
> > + * Set ->fsx_xflags, ->xattr_valid and ->flags (translated xflags).  All
> > + * other fields are zeroed.
> > + */
> > +void miscattr_fill_xflags(struct miscattr *ma, u32 xflags)
>
> Maybe call this miscattr_fill_from_xflags() and the next function
> miscattr_fill_from_flags()? At least to me it would be clearer when I want
> to use which function just by looking at the name...

Yes, more clarity for the cost of a longer name.  I'm not sure...

[...]
> > +/**
> > + * vfs_miscattr_get - retrieve miscellaneous inode attributes
> > + * @dentry:  the object to retrieve from
> > + * @ma:              miscattr pointer
> > + *
> > + * Call i_op->miscattr_get() callback, if exists.
> > + *
> > + * Returns 0 on success, or a negative error on failure.
> > + */
> > +int vfs_miscattr_get(struct dentry *dentry, struct miscattr *ma)
> > +{
> > +     struct inode *inode = d_inode(dentry);
> > +
> > +     if (d_is_special(dentry))
> > +             return -ENOTTY;
> > +
> > +     if (!inode->i_op->miscattr_get)
> > +             return -ENOIOCTLCMD;
> > +
> > +     memset(ma, 0, sizeof(*ma));
>
> So here we clear whole 'ma' but callers already set e.g. xattr_valid field
> and cleared the 'ma' as well which just looks silly...

Well spotted.   Fixed.

[...]
> > +/**
> > + * vfs_miscattr_set - change miscellaneous inode attributes
> > + * @dentry:  the object to change
> > + * @ma:              miscattr pointer
> > + *
> > + * After verifying permissions, call i_op->miscattr_set() callback, if
> > + * exists.
> > + *
> > + * Verifying attributes involves retrieving current attributes with
> > + * i_op->miscattr_get(), this also allows initilaizing attributes that have
> > + * not been set by the caller to current values.  Inode lock is held
> > + * thoughout to prevent racing with another instance.
> > + *
> > + * Returns 0 on success, or a negative error on failure.
> > + */
> > +int vfs_miscattr_set(struct dentry *dentry, struct miscattr *ma)
> > +{
> > +     struct inode *inode = d_inode(dentry);
> > +     struct miscattr old_ma = {};
> > +     int err;
> > +
> > +     if (d_is_special(dentry))
> > +             return -ENOTTY;
> > +
> > +     if (!inode->i_op->miscattr_set)
> > +             return -ENOIOCTLCMD;
> > +
> > +     if (!inode_owner_or_capable(inode))
> > +             return -EPERM;
> > +
> > +     inode_lock(inode);
> > +     err = vfs_miscattr_get(dentry, &old_ma);
> > +     if (!err) {
> > +             /* initialize missing bits from old_ma */
> > +             if (ma->flags_valid) {
> > +                     ma->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON;
> > +                     ma->fsx_extsize = old_ma.fsx_extsize;
> > +                     ma->fsx_nextents = old_ma.fsx_nextents;
> > +                     ma->fsx_projid = old_ma.fsx_projid;
> > +                     ma->fsx_cowextsize = old_ma.fsx_cowextsize;
> > +             } else {
> > +                     ma->flags |= old_ma.flags & ~FS_COMMON_FL;
> > +             }
> > +             err = miscattr_set_prepare(inode, &old_ma, ma);
> > +             if (!err)
> > +                     err = inode->i_op->miscattr_set(dentry, ma);
>
> So I somewhat wonder here - not all filesystems support all the xflags or
> other extended attributes. Currently these would be just silently ignored
> AFAICT. Which seems a bit dangerous to me - most notably because it makes
> future extensions of these filesystems difficult. So how are we going to go
> about this? Is every filesystem supposed to check what it supports and
> refuse other stuff (but currently e.g. your ext2 conversion patch doesn't do
> that AFAICT)? Shouldn't we make things easier for filesystems to provide a
> bitmask of changing fields (instead of flags / xflags bools) so that they
> can refuse unsupported stuff with a single mask check?

Ah, ext2 one is missing miscattr_has_xattr() check and doesn't use the
miscattr_fill_flags() helper.  It was one of the earlier fs I
converted, and the API wasn't so refined then.  Fixed.

Will review all conversions too for this type of omission.

Creating a  mask instead of bool makes sense, I'll look into this.

> To make things more complex, ext2/4 has traditionally silently cleared
> unknown flags for setflags but not for setxflags. Unlike e.g. XFS which
> refuses unknown flags.

Right. Not sure if this can be fixed.  Documenting rules and
exceptions should be a first step.

Thanks,
Miklos


  reply	other threads:[~2021-02-03 15:24 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 12:40 [PATCH 00/18] new API for FS_IOC_[GS]ETFLAGS/FS_IOC_FS[GS]ETXATTR Miklos Szeredi
2021-02-03 12:40 ` [PATCH 01/18] vfs: add miscattr ops Miklos Szeredi
2021-02-03 15:04   ` Jan Kara
2021-02-03 15:21     ` Miklos Szeredi [this message]
2021-03-23  0:23   ` Eric Biggers
2021-03-25 14:52     ` Miklos Szeredi
2021-03-25 15:17       ` Al Viro
2021-02-03 12:40 ` [PATCH 02/18] ecryptfs: stack " Miklos Szeredi
2021-02-03 12:40 ` [PATCH 03/18] ovl: stack miscattr Miklos Szeredi
2021-02-04 23:42   ` Vivek Goyal
2021-02-05 15:25     ` Miklos Szeredi
2021-02-05 15:28       ` Miklos Szeredi
2021-02-03 12:40 ` [PATCH 04/18] btrfs: convert to miscattr Miklos Szeredi
2021-02-03 12:40 ` [PATCH 05/18] ext2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 06/18] ext4: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 07/18] f2fs: " Miklos Szeredi
2021-03-23  0:28   ` Eric Biggers
2021-02-03 12:41 ` [PATCH 08/18] gfs2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 09/18] orangefs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 10/18] xfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 11/18] efivars: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 12/18] hfsplus: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 13/18] jfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 14/18] nilfs2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 15/18] ocfs2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 16/18] reiserfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 17/18] ubifs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 18/18] vfs: remove unused ioctl helpers Miklos Szeredi
2021-02-03 13:05 ` [PATCH 00/18] new API for FS_IOC_[GS]ETFLAGS/FS_IOC_FS[GS]ETXATTR Matthew Wilcox
2021-02-03 13:13   ` Miklos Szeredi
2021-02-03 13:58     ` Matthew Wilcox
2021-02-03 14:13       ` Miklos Szeredi
2021-02-03 14:28         ` Matthew Wilcox
2021-02-03 14:38           ` Miklos Szeredi
2021-02-03 14:56             ` Matthew Wilcox
2021-02-03 15:03               ` Miklos Szeredi
2021-02-08  2:00                 ` Dave Chinner
2021-02-08  8:25                   ` Miklos Szeredi
2021-02-08 14:02                     ` Matthew Wilcox
2021-02-08 14:52                       ` Miklos Szeredi

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=CAOssrKesMbzG9bX5HiDvCJTpdrCkvP7cg5nsZHCy4_QkJNEVZg@mail.gmail.com \
    --to=mszeredi@redhat.com \
    --cc=adilger@dilger.ca \
    --cc=agruenba@redhat.com \
    --cc=code@tyhicks.com \
    --cc=djwong@kernel.org \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=hubcap@omnibond.com \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=jlbec@evilplan.org \
    --cc=konishi.ryusuke@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    --cc=richard@nod.at \
    --cc=shaggy@kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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).