All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: "zhangyi (F)" <yi.zhang@huawei.com>
Cc: overlayfs <linux-unionfs@vger.kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>, Miao Xie <miaoxie@huawei.com>,
	yangerkun <yangerkun@huawei.com>
Subject: Re: [RFC PATCH v2 4/9] ovl: add helper funcs to set upper layer feature set
Date: Wed, 1 Aug 2018 11:51:26 +0300	[thread overview]
Message-ID: <CAOQ4uxg38tQN1g9oTeu6ZZ8SncUoQCoeZgFAZQ0ZL5UGsXktkA@mail.gmail.com> (raw)
In-Reply-To: <20180731093727.26855-5-yi.zhang@huawei.com>

On Tue, Jul 31, 2018 at 12:37 PM, zhangyi (F) <yi.zhang@huawei.com> wrote:
> overlayfs will want to add the upper layer's feature bitset if some
> overlay file system features were set. For example: redirect dir feature
> will be set when user rename a lower/merge dir if redirect dir feature
> is enabled. So add helper functions to set feature sets to the upper
> layer for future use.
>
> This patch introduce helper functions only, does not set any feature
> bits.
>
> Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
> ---
>  fs/overlayfs/feature.c   | 85 ++++++++++++++++++++++++++++++++++++++++++++++++
>  fs/overlayfs/overlayfs.h | 46 ++++++++++++++++++++++++++
>  fs/overlayfs/ovl_entry.h |  2 ++
>  fs/overlayfs/super.c     |  1 +
>  4 files changed, 134 insertions(+)
>
> diff --git a/fs/overlayfs/feature.c b/fs/overlayfs/feature.c
> index fac4d7544475..7c66e71bdd98 100644
> --- a/fs/overlayfs/feature.c
> +++ b/fs/overlayfs/feature.c
> @@ -10,6 +10,8 @@
>
>  #include <linux/fs.h>
>  #include <linux/xattr.h>
> +#include <linux/mount.h>
> +#include <linux/ratelimit.h>
>  #include "overlayfs.h"
>
>  /*
> @@ -63,6 +65,89 @@ static struct ovl_d_feature *ovl_get_feature(struct dentry *realroot)
>  }
>
>  /*
> + * Set overlay features to the upper root dir.
> + *
> + * @upper_layer: overlay upper layer information,
> + * @upper: upper root dentry.
> + *
> + * Return 0 if success, error number otherwise.
> + */
> +static int ovl_set_feature(struct ovl_layer *upper_layer,
> +                          struct dentry *upper)
> +{
> +       struct vfsmount *upper_mnt = upper_layer->mnt;
> +       struct ovl_d_feature odf = {};
> +       int err;
> +
> +       odf.magic = OVL_FEATURE_MAGIC;
> +       odf.compat = cpu_to_be64(upper_layer->compat);
> +       odf.ro_compat = cpu_to_be64(upper_layer->ro_compat);
> +       odf.incompat = cpu_to_be64(upper_layer->incompat);
> +
> +       err = mnt_want_write(upper_mnt);
> +       if (err)
> +               return err;
> +
> +       err = ovl_do_setxattr(upper, OVL_XATTR_FEATURE,
> +                             &odf, sizeof(odf), 0);
> +       if (err)
> +               pr_err_ratelimited("overlayfs: failed to set features (%i)\n", err);
> +
> +       mnt_drop_write(upper_mnt);
> +       return err;
> +}
> +
> +/*
> + * Add feature bit mask to the upper root dir.
> + *
> + * @ofs: overlay filesystem information
> + * @type: feature set type, compat, ro compat or incompat
> + * @mask: new features mask want to add
> + *
> + * Return 0 if success, error number otherwise.
> + */
> +int ovl_set_upper_feature(struct ovl_fs *ofs,
> +                         enum ovl_feature_type type,
> +                         u64 mask)
> +{
> +       struct ovl_layer *upper_layer = ofs->upper_layer;
> +       u64 *features;
> +       int err;
> +
> +       if (!upper_layer)
> +               return -EINVAL;
> +
> +       switch (type) {
> +       case OVL_FEATURE_COMPAT:
> +               features = &upper_layer->compat;
> +               break;
> +       case OVL_FEATURE_RO_COMPAT:
> +               features = &upper_layer->ro_compat;
> +               break;
> +       case OVL_FEATURE_INCOMPAT:
> +               features = &upper_layer->incompat;
> +               break;
> +       default:
> +               return -EINVAL;
> +       }
> +
> +       spin_lock(&upper_layer->lock);
> +       if ((*features) & mask) {
> +               spin_unlock(&upper_layer->lock);
> +               return 0;
> +       }
> +
> +       (*features) |= mask;
> +       spin_unlock(&upper_layer->lock);
> +

Seems like you can move the above test and set into
ovl_set_feature() and you can also use upperdir->d_lock
and don't need to introduce a new spinlock for this.

Thanks,
Amir.

  reply	other threads:[~2018-08-01  8:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31  9:37 [RFC PATCH v2 0/9] ovl: add feature set support zhangyi (F)
2018-07-31  9:37 ` [RFC PATCH v2 1/9] ovl: store ovl upper root path in ovl_fs zhangyi (F)
2018-08-01  6:48   ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 2/9] ovl: read feature set from each layer's root dir zhangyi (F)
2018-08-01  7:44   ` Amir Goldstein
2018-08-03 12:11     ` zhangyi (F)
2018-07-31  9:37 ` [RFC PATCH v2 3/9] ovl: check file system features can be mounted properly zhangyi (F)
2018-08-01  8:06   ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 4/9] ovl: add helper funcs to set upper layer feature set zhangyi (F)
2018-08-01  8:51   ` Amir Goldstein [this message]
2018-08-01 11:04     ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 5/9] ovl: add redirect dir feature when set redirect xattr to dir zhangyi (F)
2018-08-01 11:03   ` Amir Goldstein
2018-08-03 11:52     ` zhangyi (F)
2018-08-03 20:38       ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 6/9] ovl: add index feature if index dir exists zhangyi (F)
2018-08-01 11:15   ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 7/9] ovl: add nfs_export feature when nfs_export is enabled zhangyi (F)
2018-08-01 11:20   ` Amir Goldstein
2018-07-31  9:37 ` [RFC PATCH v2 8/9] ovl: force mount underlying layers which have feature sets zhangyi (F)
     [not found]   ` <CAOQ4uxgZcwxENyf5STfNgL6juLoHvOBnWkORpifp0pv04oi8Ww@mail.gmail.com>
2018-08-03 11:25     ` zhangyi (F)
     [not found]       ` <CAOQ4uxjxY1Urjy2fUEkV24ZfxbDjAu1vkJcERNc_7uZVmJ+2YA@mail.gmail.com>
2018-08-06  1:15         ` zhangyi (F)
2018-07-31  9:37 ` [RFC PATCH v2 9/9] ovl: check redirect_dir feature when detect redirect xattr on dir zhangyi (F)
2018-08-01 11:30   ` Amir Goldstein
2018-08-01 11:35     ` Amir Goldstein
2018-08-02 12:30       ` Vivek Goyal

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=CAOQ4uxg38tQN1g9oTeu6ZZ8SncUoQCoeZgFAZQ0ZL5UGsXktkA@mail.gmail.com \
    --to=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=miklos@szeredi.hu \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.