Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@gmail.com>
To: Omar Sandoval <osandov@osandov.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 1/9] btrfs: send: get rid of i_size logic in send_write()
Date: Fri, 21 Aug 2020 18:26:50 +0100 [thread overview]
Message-ID: <CAL3q7H70xhsW5pK5pzu2mUfmcUhzRUoWd5RTFMEX_-ut5HALpQ@mail.gmail.com> (raw)
In-Reply-To: <16f28691ff66e8aeb280532cc146c8ee49d6cda4.1597994106.git.osandov@osandov.com>
On Fri, Aug 21, 2020 at 8:42 AM Omar Sandoval <osandov@osandov.com> wrote:
>
> From: Omar Sandoval <osandov@fb.com>
>
> send_write()/fill_read_buf() have some logic for avoiding reading past
> i_size. However, everywhere that we call
> send_write()/send_extent_data(), we've already clamped the length down
> to i_size. Get rid of the i_size handling, which simplifies the next
> change.
>
> Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good, and it passed some long duration tests with both full and
incremental sends here (with and without compression, no-holes, etc).
Thanks.
> ---
> fs/btrfs/send.c | 37 ++++++++++---------------------------
> 1 file changed, 10 insertions(+), 27 deletions(-)
>
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 7c7c09fc65e8..8af5e867e4ca 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -4794,7 +4794,7 @@ static int process_all_new_xattrs(struct send_ctx *sctx)
> return ret;
> }
>
> -static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> +static int fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> {
> struct btrfs_root *root = sctx->send_root;
> struct btrfs_fs_info *fs_info = root->fs_info;
> @@ -4804,21 +4804,13 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> pgoff_t index = offset >> PAGE_SHIFT;
> pgoff_t last_index;
> unsigned pg_offset = offset_in_page(offset);
> - ssize_t ret = 0;
> + int ret = 0;
> + size_t read = 0;
>
> inode = btrfs_iget(fs_info->sb, sctx->cur_ino, root);
> if (IS_ERR(inode))
> return PTR_ERR(inode);
>
> - if (offset + len > i_size_read(inode)) {
> - if (offset > i_size_read(inode))
> - len = 0;
> - else
> - len = offset - i_size_read(inode);
> - }
> - if (len == 0)
> - goto out;
> -
> last_index = (offset + len - 1) >> PAGE_SHIFT;
>
> /* initial readahead */
> @@ -4859,16 +4851,15 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> }
>
> addr = kmap(page);
> - memcpy(sctx->read_buf + ret, addr + pg_offset, cur_len);
> + memcpy(sctx->read_buf + read, addr + pg_offset, cur_len);
> kunmap(page);
> unlock_page(page);
> put_page(page);
> index++;
> pg_offset = 0;
> len -= cur_len;
> - ret += cur_len;
> + read += cur_len;
> }
> -out:
> iput(inode);
> return ret;
> }
> @@ -4882,7 +4873,6 @@ static int send_write(struct send_ctx *sctx, u64 offset, u32 len)
> struct btrfs_fs_info *fs_info = sctx->send_root->fs_info;
> int ret = 0;
> struct fs_path *p;
> - ssize_t num_read = 0;
>
> p = fs_path_alloc();
> if (!p)
> @@ -4890,12 +4880,9 @@ static int send_write(struct send_ctx *sctx, u64 offset, u32 len)
>
> btrfs_debug(fs_info, "send_write offset=%llu, len=%d", offset, len);
>
> - num_read = fill_read_buf(sctx, offset, len);
> - if (num_read <= 0) {
> - if (num_read < 0)
> - ret = num_read;
> + ret = fill_read_buf(sctx, offset, len);
> + if (ret < 0)
> goto out;
> - }
>
> ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE);
> if (ret < 0)
> @@ -4907,16 +4894,14 @@ static int send_write(struct send_ctx *sctx, u64 offset, u32 len)
>
> TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p);
> TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset);
> - TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, num_read);
> + TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, len);
>
> ret = send_cmd(sctx);
>
> tlv_put_failure:
> out:
> fs_path_free(p);
> - if (ret < 0)
> - return ret;
> - return num_read;
> + return ret;
> }
>
> /*
> @@ -5095,9 +5080,7 @@ static int send_extent_data(struct send_ctx *sctx,
> ret = send_write(sctx, offset + sent, size);
> if (ret < 0)
> return ret;
> - if (!ret)
> - break;
> - sent += ret;
> + sent += size;
> }
> return 0;
> }
> --
> 2.28.0
>
--
Filipe David Manana,
“Whether you think you can, or you think you can't — you're right.”
next prev parent reply other threads:[~2020-08-21 17:27 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-21 7:39 [PATCH 0/9] btrfs: implement send/receive of compressed extents without decompressing Omar Sandoval
2020-08-21 7:39 ` [PATCH 1/9] btrfs: send: get rid of i_size logic in send_write() Omar Sandoval
2020-08-21 17:26 ` Filipe Manana [this message]
2020-08-24 17:39 ` Josef Bacik
2020-08-21 7:39 ` [PATCH 2/9] btrfs: send: avoid copying file data Omar Sandoval
2020-08-21 17:29 ` Filipe Manana
2020-08-24 21:34 ` Omar Sandoval
2020-08-24 17:47 ` Josef Bacik
2020-09-11 14:13 ` David Sterba
2020-09-14 22:04 ` Omar Sandoval
2020-09-15 8:14 ` David Sterba
2020-08-21 7:39 ` [PATCH 3/9] btrfs: send: use btrfs_file_extent_end() in send_write_or_clone() Omar Sandoval
2020-08-21 17:30 ` Filipe Manana
2020-08-21 7:39 ` [PATCH 4/9] btrfs: add send_stream_version attribute to sysfs Omar Sandoval
2020-08-21 7:39 ` [PATCH 5/9] btrfs: add send stream v2 definitions Omar Sandoval
2020-08-24 17:49 ` Josef Bacik
2020-08-21 7:39 ` [PATCH 6/9] btrfs: send: write larger chunks when using stream v2 Omar Sandoval
2020-08-24 17:57 ` Josef Bacik
2020-08-21 7:39 ` [PATCH 7/9] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Omar Sandoval
2020-08-21 7:39 ` [PATCH 8/9] btrfs: send: send compressed extents with encoded writes Omar Sandoval
2020-08-24 17:32 ` Josef Bacik
2020-08-24 17:52 ` Omar Sandoval
2020-08-21 7:39 ` [PATCH 9/9] btrfs: send: enable support for stream v2 and compressed writes Omar Sandoval
2020-08-21 7:40 ` [PATCH 01/11] btrfs-progs: receive: support v2 send stream larger tlv_len Omar Sandoval
2020-08-21 7:40 ` [PATCH 02/11] btrfs-progs: receive: dynamically allocate sctx->read_buf Omar Sandoval
2020-08-21 7:40 ` [PATCH 03/11] btrfs-progs: receive: support v2 send stream DATA tlv format Omar Sandoval
2020-08-21 7:40 ` [PATCH 04/11] btrfs-progs: receive: add send stream v2 cmds and attrs to send.h Omar Sandoval
2020-08-21 7:40 ` [PATCH 05/11] btrfs-progs: receive: add stub implementation for pwritev2 Omar Sandoval
2020-08-21 7:40 ` [PATCH 06/11] btrfs-progs: receive: process encoded_write commands Omar Sandoval
2020-08-21 7:40 ` [PATCH 07/11] btrfs-progs: receive: encoded_write fallback to explicit decode and write Omar Sandoval
2020-08-21 7:40 ` [PATCH 08/11] btrfs-progs: receive: process fallocate commands Omar Sandoval
2020-08-21 7:40 ` [PATCH 09/11] btrfs-progs: receive: process setflags ioctl commands Omar Sandoval
2020-08-21 7:40 ` [PATCH 10/11] btrfs-progs: send: stream v2 ioctl flags Omar Sandoval
2020-08-21 7:40 ` [PATCH 11/11] btrfs-progs: receive: add tests for basic encoded_write send/receive Omar Sandoval
2020-08-24 19:57 ` [PATCH 0/9] btrfs: implement send/receive of compressed extents without decompressing David Sterba
2020-08-24 22:16 ` Omar Sandoval
2020-09-10 11:28 ` David Sterba
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=CAL3q7H70xhsW5pK5pzu2mUfmcUhzRUoWd5RTFMEX_-ut5HALpQ@mail.gmail.com \
--to=fdmanana@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=osandov@osandov.com \
--subject='Re: [PATCH 1/9] btrfs: send: get rid of i_size logic in send_write()' \
/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
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).