From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org,
Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: Re: [PATCH 4/4] btrfs-progs: Enqueue command if it can't be performed immediately
Date: Wed, 2 Sep 2020 15:45:16 -0500 [thread overview]
Message-ID: <20200902204516.poralnz3skht5myn@fiona> (raw)
In-Reply-To: <20200902141117.GK28318@twin.jikos.cz>
On 16:11 02/09, David Sterba wrote:
> On Tue, Aug 25, 2020 at 10:03:38AM -0500, Goldwyn Rodrigues wrote:
> > From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> >
> > Wait for the current exclusive operation to finish before issuing the
> > command ioctl, so we have a better chance of success.
> >
> > Q: The resize argument parsing is hackish. Is there a better way to do
> > this?
>
> You mean parsing in kernel? Progs pass the 1st non-option parameter
> without changes, so if you add a new option, the -- separator needs to
> be used to make sure the relative size update (eg. -1G) is properly
> recognized. This is built in already and should not require anything
> special on the option parsing side.
Particularly the example you mention, -1G. You answered it as well :)
>
> > --- a/cmds/device.c
> > +++ b/cmds/device.c
> > @@ -49,6 +49,7 @@ static const char * const cmd_device_add_usage[] = {
> > "",
> > "-K|--nodiscard do not perform whole device TRIM on devices that report such capability",
> > "-f|--force force overwrite existing filesystem on the disk",
> > + "-q|--enqueue enqueue if an exclusive operation is running",
>
> Short for -q should not be used due to confusion with --quiet. Also I
> think that --enqueue is not a common action that would need a short
> option, the long option is always safe.
Yes, and --quit as well. However, just --enqueue is fine.
>
> > --- a/common/sysfs.c
> > +++ b/common/sysfs.c
> > @@ -50,3 +50,29 @@ int get_exclusive_operation(int mp_fd, char *val)
> > val[n - 1] = '\0';
> > return n;
> > }
> > +
> > +int sysfs_wait(int fd, int seconds)
> > +{
> > + fd_set fds;
> > + struct timeval tv;
> > +
> > + FD_ZERO(&fds);
> > + FD_SET(fd, &fds);
> > +
> > + tv.tv_sec = seconds;
> > + tv.tv_usec = 0;
> > +
> > + return select(fd+1, NULL, NULL, &fds, &tv);
>
> With the short sleep times, do we need to wait using select? Yes this
> would return once the notification event is sent but as the sleep time
> is 1 second, it could simply be sleep(1) unconditionally.
Yes, the kernel provides the sysfs notification. We could sys_wait() for
longer (with a higher wait parameter) and yet the function would return
the moment the kernel notifies the change. I know we are not using it
now, but it is better to use robust interfaces when a event notification
is provided by the kernel.
>
> > +}
> > +
> > +void wait_for_exclusive_operation(int dirfd)
> > +{
> > + char exop[BTRFS_SYSFS_EXOP_SIZE];
> > + int fd;
> > +
> > + fd = sysfs_open(dirfd, "exclusive_operation");
> > + while ((sysfs_get_str_fd(fd, exop, BTRFS_SYSFS_EXOP_SIZE) > 0) &&
> > + strncmp(exop, "none", 4))
> > + sysfs_wait(fd, 1);
> > + close(fd);
> > +}
> > diff --git a/common/utils.h b/common/utils.h
> > index be8aab58..f141edb6 100644
> > --- a/common/utils.h
> > +++ b/common/utils.h
> > @@ -155,5 +155,6 @@ int btrfs_warn_multiple_profiles(int fd);
> >
> > #define BTRFS_SYSFS_EXOP_SIZE 16
> > int get_exclusive_operation(int fd, char *val);
> > +void wait_for_exclusive_operation(int fd);
> >
> > #endif
> > --
> > 2.26.2
--
Goldwyn
next prev parent reply other threads:[~2020-09-02 20:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-25 15:02 [PATCH v3 0/2] btrfs: Enumerate and export exclusive operations Goldwyn Rodrigues
2020-08-25 15:02 ` [PATCH 1/2] btrfs: enumerate the type of exclusive operation in progress Goldwyn Rodrigues
2020-09-02 13:42 ` David Sterba
2020-08-25 15:02 ` [PATCH 2/2] btrfs: export currently executing exclusive operation via sysfs Goldwyn Rodrigues
2020-08-25 15:03 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Goldwyn Rodrigues
2020-08-25 15:03 ` [PATCH 2/4] btrfs-progs: add sysfs file reading functions Goldwyn Rodrigues
2020-08-25 15:03 ` [PATCH 3/4] btrfs-progs: Check for exclusive operation before issuing ioctl Goldwyn Rodrigues
2020-08-25 15:03 ` [PATCH 4/4] btrfs-progs: Enqueue command if it can't be performed immediately Goldwyn Rodrigues
2020-09-02 14:11 ` David Sterba
2020-09-02 20:45 ` Goldwyn Rodrigues [this message]
2020-09-02 20:11 ` [PATCH v3 0/2] btrfs: Enumerate and export exclusive operations David Sterba
-- strict thread matches above, loose matches on Subject: below --
2020-08-03 20:29 [PATCH v2 0/3] " Goldwyn Rodrigues
2020-08-03 20:30 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Goldwyn Rodrigues
2020-08-03 20:30 ` [PATCH 4/4] btrfs-progs: Enqueue command if it can't be performed immediately Goldwyn Rodrigues
2020-07-27 22:04 [PATCH 0/3] btrfs: Enumerate and export exclusive operations Goldwyn Rodrigues
2020-07-27 22:08 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Goldwyn Rodrigues
2020-07-27 22:08 ` [PATCH 4/4] btrfs-progs: Enqueue command if it can't be performed immediately Goldwyn Rodrigues
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=20200902204516.poralnz3skht5myn@fiona \
--to=rgoldwyn@suse.de \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=rgoldwyn@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox