From: Omar Sandoval <osandov@osandov.com>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com,
linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-api@vger.kernel.org
Subject: Re: [PATCH v10 09/14] btrfs: add BTRFS_IOC_ENCODED_WRITE
Date: Fri, 20 Aug 2021 10:59:56 -0700 [thread overview]
Message-ID: <YR/tnL4EcO++1uWb@relinquished.localdomain> (raw)
In-Reply-To: <bb47ef73-0f9c-55b2-c916-5774a3fe5278@suse.com>
On Fri, Aug 20, 2021 at 04:44:26PM +0300, Nikolay Borisov wrote:
>
>
> On 18.08.21 г. 0:06, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> >
> > The implementation resembles direct I/O: we have to flush any ordered
> > extents, invalidate the page cache, and do the io tree/delalloc/extent
> > map/ordered extent dance. From there, we can reuse the compression code
> > with a minor modification to distinguish the write from writeback. This
> > also creates inline extents when possible.
> >
> > Signed-off-by: Omar Sandoval <osandov@fb.com>
>
> <snip>
>
> > * Add an entry indicating a block group or device which is pinned by a
> > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> > index 7a0a9c752624..13a0a65c6a43 100644
> > --- a/fs/btrfs/ioctl.c
> > +++ b/fs/btrfs/ioctl.c
> > @@ -103,6 +103,8 @@ struct btrfs_ioctl_encoded_io_args_32 {
> >
> > #define BTRFS_IOC_ENCODED_READ_32 _IOR(BTRFS_IOCTL_MAGIC, 64, \
> > struct btrfs_ioctl_encoded_io_args_32)
> > +#define BTRFS_IOC_ENCODED_WRITE_32 _IOW(BTRFS_IOCTL_MAGIC, 64, \
> > + struct btrfs_ioctl_encoded_io_args_32)
> > #endif
> >
> > /* Mask out flags that are inappropriate for the given type of inode. */
> > @@ -4992,6 +4994,102 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp,
> > return ret;
> > }
> >
> > +static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp,
> > + bool compat)
> > +{
> > + struct btrfs_ioctl_encoded_io_args args;
> > + struct iovec iovstack[UIO_FASTIOV];
> > + struct iovec *iov = iovstack;
> > + struct iov_iter iter;
> > + loff_t pos;
> > + struct kiocb kiocb;
> > + ssize_t ret;
> > +
> > + if (!capable(CAP_SYS_ADMIN)) {
> > + ret = -EPERM;
> > + goto out_acct;
> > + }
> > +
> > + if (!(file->f_mode & FMODE_WRITE)) {
> > + ret = -EBADF;
> > + goto out_acct;
> > + }
> > +
> > + if (compat) {
> > +#if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
> > + struct btrfs_ioctl_encoded_io_args_32 args32;
> > +
> > + if (copy_from_user(&args32, argp, sizeof(args32))) {
> > + ret = -EFAULT;
> > + goto out_acct;
> > + }
> > + args.iov = compat_ptr(args32.iov);
> > + args.iovcnt = args.iovcnt;
> > + memcpy(&args.offset, &args32.offset,
> > + sizeof(args) -
> > + offsetof(struct btrfs_ioctl_encoded_io_args, offset));
> > +#else
> > + return -ENOTTY;
> > +#endif
> > + } else {
> > + if (copy_from_user(&args, argp, sizeof(args))) {
> > + ret = -EFAULT;
> > + goto out_acct;
> > + }
> > + }
> > +
> > + ret = -EINVAL;
> > + if (args.flags != 0)
> > + goto out_acct;
> > + if (memchr_inv(args.reserved, 0, sizeof(args.reserved)))
> > + goto out_acct;
> > + if (args.compression == BTRFS_ENCODED_IO_COMPRESSION_NONE &&
> > + args.encryption == BTRFS_ENCODED_IO_ENCRYPTION_NONE)
>
> Do you intend on supporting encrypted data writeout in the future, given
> that in btrfs_do_encoded_write EINVAL is returned if the data to be
> written is encrypted? If not then this check could be moved earlier to
> fail fast.
We probably want to support it at some point in the future, yes.
> > @@ -5138,9 +5236,13 @@ long btrfs_ioctl(struct file *file, unsigned int
> > return fsverity_ioctl_measure(file, argp);
> > case BTRFS_IOC_ENCODED_READ:
> > return btrfs_ioctl_encoded_read(file, argp, false);
> > + case BTRFS_IOC_ENCODED_WRITE:
> > + return btrfs_ioctl_encoded_write(file, argp, false);
> > #if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
> > case BTRFS_IOC_ENCODED_READ_32:
> > return btrfs_ioctl_encoded_read(file, argp, true);
> > + case BTRFS_IOC_ENCODED_WRITE_32:
> > + return btrfs_ioctl_encoded_write(file, argp, true);
> > #endif
> > }
> >
> > diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> > index 550c34fa0e6d..180f302dee93 100644
> > --- a/fs/btrfs/ordered-data.c
> > +++ b/fs/btrfs/ordered-data.c
> > @@ -521,9 +521,15 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode,
> > spin_lock(&btrfs_inode->lock);
> > btrfs_mod_outstanding_extents(btrfs_inode, -1);
> > spin_unlock(&btrfs_inode->lock);
> > - if (root != fs_info->tree_root)
> > - btrfs_delalloc_release_metadata(btrfs_inode, entry->num_bytes,
> > - false);
> > + if (root != fs_info->tree_root) {
> > + u64 release;
> > +
> > + if (test_bit(BTRFS_ORDERED_ENCODED, &entry->flags))
> > + release = entry->disk_num_bytes;
> > + else
> > + release = entry->num_bytes;
> > + btrfs_delalloc_release_metadata(btrfs_inode, release, false);
> > + }
> >
> > percpu_counter_add_batch(&fs_info->ordered_bytes, -entry->num_bytes,
> > fs_info->delalloc_batch);
> > diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
> > index 0feb0c29839e..04588ccad34c 100644
> > --- a/fs/btrfs/ordered-data.h
> > +++ b/fs/btrfs/ordered-data.h
> > @@ -74,6 +74,8 @@ enum {
> > BTRFS_ORDERED_LOGGED_CSUM,
> > /* We wait for this extent to complete in the current transaction */
> > BTRFS_ORDERED_PENDING,
> > + /* RWF_ENCODED I/O */
>
> nit: RWF_ENCODED is no longer, we simply have ioctl-based encoded io. So
> this needs to be renamed to avoid confusion for people not necessarily
> faimilar with the development history of the feature.
Good catch, thanks.
next prev parent reply other threads:[~2021-08-20 18:00 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 21:06 [PATCH v10 00/14] btrfs: add ioctls and send/receive support for reading/writing compressed data Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 01/14] fs: export rw_verify_area() Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 02/14] fs: export variant of generic_write_checks without iov_iter Omar Sandoval
2021-08-20 7:59 ` Nikolay Borisov
2021-08-20 17:31 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 03/14] btrfs: don't advance offset for compressed bios in btrfs_csum_one_bio() Omar Sandoval
2021-08-20 8:08 ` Nikolay Borisov
2021-08-20 17:37 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 04/14] btrfs: add ram_bytes and offset to btrfs_ordered_extent Omar Sandoval
2021-08-20 8:34 ` Nikolay Borisov
2021-08-20 17:43 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 05/14] btrfs: support different disk extent size for delalloc Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 06/14] btrfs: optionally extend i_size in cow_file_range_inline() Omar Sandoval
2021-08-20 8:51 ` Nikolay Borisov
2021-08-20 9:13 ` Qu Wenruo
2021-08-20 18:11 ` Omar Sandoval
2021-08-21 1:11 ` Qu Wenruo
2021-08-23 18:16 ` Omar Sandoval
2021-08-23 23:32 ` Qu Wenruo
2021-08-23 23:46 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 07/14] btrfs: add definitions + documentation for encoded I/O ioctls Omar Sandoval
2021-08-20 8:56 ` Nikolay Borisov
2021-08-20 17:48 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 08/14] btrfs: add BTRFS_IOC_ENCODED_READ Omar Sandoval
2021-08-20 12:30 ` Nikolay Borisov
2021-08-20 17:58 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 09/14] btrfs: add BTRFS_IOC_ENCODED_WRITE Omar Sandoval
2021-08-20 13:44 ` Nikolay Borisov
2021-08-20 17:59 ` Omar Sandoval [this message]
2021-08-17 21:06 ` [PATCH v10 10/14] btrfs: add send stream v2 definitions Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 11/14] btrfs: send: write larger chunks when using stream v2 Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 12/14] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 13/14] btrfs: send: send compressed extents with encoded writes Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 14/14] btrfs: send: enable support for stream v2 and compressed writes Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 01/10] btrfs-progs: receive: support v2 send stream larger tlv_len Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 02/10] btrfs-progs: receive: dynamically allocate sctx->read_buf Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 03/10] btrfs-progs: receive: support v2 send stream DATA tlv format Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 04/10] btrfs-progs: receive: add send stream v2 cmds and attrs to send.h Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 05/10] btrfs-progs: receive: process encoded_write commands Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 06/10] btrfs-progs: receive: encoded_write fallback to explicit decode and write Omar Sandoval
2021-08-18 18:07 ` Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 07/10] btrfs-progs: receive: process fallocate commands Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 08/10] btrfs-progs: receive: process setflags ioctl commands Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 09/10] btrfs-progs: send: stream v2 ioctl flags Omar Sandoval
2021-08-17 21:06 ` [PATCH v10 10/10] btrfs-progs: receive: add tests for basic encoded_write send/receive Omar Sandoval
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=YR/tnL4EcO++1uWb@relinquished.localdomain \
--to=osandov@osandov.com \
--cc=kernel-team@fb.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=torvalds@linux-foundation.org \
--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).