linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@gmail.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: fstests <fstests@vger.kernel.org>,
	kernel-team@fb.com, linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/3] fsstress: add the ability to create snapshots
Date: Tue, 17 Dec 2019 16:06:38 +0000	[thread overview]
Message-ID: <CAL3q7H4t_L3JrmP1NNf8VTb+UApbLWC8f69UzsMen1hGzXzb=A@mail.gmail.com> (raw)
In-Reply-To: <20191114155836.3528-3-josef@toxicpanda.com>

On Thu, Nov 14, 2019 at 3:59 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> Snapshots are just fancy subvolumes, add this ability so we can stress
> snapshot creation.  We get the deletion with SUBVOL_DELETE.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Looks good, and it works on my test boxes.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

> ---
>  ltp/fsstress.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>
> diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> index e0636a12..f7f5f1dc 100644
> --- a/ltp/fsstress.c
> +++ b/ltp/fsstress.c
> @@ -129,6 +129,7 @@ typedef enum {
>         OP_SETATTR,
>         OP_SETFATTR,
>         OP_SETXATTR,
> +       OP_SNAPSHOT,
>         OP_SPLICE,
>         OP_STAT,
>         OP_SUBVOL_CREATE,
> @@ -255,6 +256,7 @@ void        rmdir_f(int, long);
>  void   setattr_f(int, long);
>  void   setfattr_f(int, long);
>  void   setxattr_f(int, long);
> +void   snapshot_f(int, long);
>  void   splice_f(int, long);
>  void   stat_f(int, long);
>  void   subvol_create_f(int, long);
> @@ -322,6 +324,7 @@ opdesc_t    ops[] = {
>         { OP_SETFATTR, "setfattr", setfattr_f, 2, 1 },
>         /* set project id (XFS_IOC_FSSETXATTR ioctl) */
>         { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
> +       { OP_SNAPSHOT, "snapshot", snapshot_f, 1, 1 },
>         { OP_SPLICE, "splice", splice_f, 1, 1 },
>         { OP_STAT, "stat", stat_f, 1, 0 },
>         { OP_SUBVOL_CREATE, "subvol_create", subvol_create_f, 1, 1},
> @@ -1903,6 +1906,7 @@ zero_freq(void)
>  #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
>
>  opty_t btrfs_ops[] = {
> +       OP_SNAPSHOT,
>         OP_SUBVOL_CREATE,
>         OP_SUBVOL_DELETE,
>  };
> @@ -4703,6 +4707,55 @@ out:
>         free_pathname(&f);
>  }
>
> +void
> +snapshot_f(int opno, long r)
> +{
> +#ifdef HAVE_BTRFSUTIL_H
> +       enum btrfs_util_error   e;
> +       pathname_t              f;
> +       pathname_t              newf;
> +       fent_t                  *fep;
> +       int                     id;
> +       int                     parid;
> +       int                     v;
> +       int                     v1;
> +       int                     err;
> +
> +       init_pathname(&f);
> +       if (!get_fname(FT_SUBVOLm, r, &f, NULL, &fep, &v)) {
> +               if (v)
> +                       printf("%d/%d: snapshot - no subvolume\n", procid,
> +                              opno);
> +               free_pathname(&f);
> +               return;
> +       }
> +       init_pathname(&newf);
> +       parid = fep->id;
> +       err = generate_fname(fep, FT_SUBVOL, &newf, &id, &v1);
> +       v |= v1;
> +       if (!err) {
> +               if (v) {
> +                       (void)fent_to_name(&f, fep);
> +                       printf("%d/%d: snapshot - no filename from %s\n",
> +                              procid, opno, f.path);
> +               }
> +               free_pathname(&f);
> +               return;
> +       }
> +       e = btrfs_util_create_snapshot(f.path, newf.path, 0, NULL, NULL);
> +       if (e == BTRFS_UTIL_OK)
> +               add_to_flist(FT_SUBVOL, id, parid, 0);
> +       if (v) {
> +               printf("%d/%d: snapshot %s->%s %d(%s)\n", procid, opno,
> +                      f.path, newf.path, e, btrfs_util_strerror(e));
> +               printf("%d/%d: snapshot add id=%d,parent=%d\n", procid, opno,
> +                      id, parid);
> +       }
> +       free_pathname(&newf);
> +       free_pathname(&f);
> +#endif
> +}
> +
>  void
>  stat_f(int opno, long r)
>  {
> --
> 2.21.0
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

  reply	other threads:[~2019-12-17 16:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 15:58 [PATCH 0/3] fsstress: add support for btrfs subvol and snapshot ops Josef Bacik
2019-11-14 15:58 ` [PATCH 1/3] fsstress: add the ability to create/delete subvolumes Josef Bacik
2019-11-14 18:14   ` [PATCH][v2] " Josef Bacik
2019-12-17 15:55     ` Filipe Manana
2019-11-14 15:58 ` [PATCH 2/3] fsstress: add the ability to create snapshots Josef Bacik
2019-12-17 16:06   ` Filipe Manana [this message]
2019-11-14 15:58 ` [PATCH 3/3] fsstress: allow operations to use either a directory or subvol Josef Bacik
2019-12-17 16:10   ` Filipe Manana

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='CAL3q7H4t_L3JrmP1NNf8VTb+UApbLWC8f69UzsMen1hGzXzb=A@mail.gmail.com' \
    --to=fdmanana@gmail.com \
    --cc=fstests@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@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).