From: Fabian Frederick <fabf@skynet.be>
To: Zach Brown <zab@zabbo.net>
Cc: Josef Bacik <jbacik@fb.com>,
linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org,
Chris Mason <clm@fb.com>
Subject: Re: [PATCH 1/1] Btrfs: fix sparse warning
Date: Sat, 2 Aug 2014 14:24:49 +0200 [thread overview]
Message-ID: <20140802142449.15f4cfc2c2821e90e04e175e@skynet.be> (raw)
In-Reply-To: <20140717190152.GB24196@lenny.home.zabbo.net>
On Thu, 17 Jul 2014 12:01:52 -0700
Zach Brown <zab@zabbo.net> wrote:
> > > > @@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf,
> > > > u32 len, loff_t *off)
> > >
> > > Though this probably wants to be rewritten in terms of kernel_write().
> > > That'd give an opportunity to get rid of the sctx->send_off and have it
> > > use f_pos in the filp.
> >
> > Do you mean directly call kernel_write from send_cmd/send_header ?
> > I guess that loop around vfs_write in write_buf is there for something ...
>
> write_buf() could still exist to iterate over the buffer in the case of
> partial writes but it doesn't need to muck around with set_fs() and
> forcing casts.
>
> - z
Hello Zach,
Here's an untested patch which
-removes send_off and set_fs
-calls kernel_write with ppos 0
but I don't know if something like adding filp->f_pos = pos
at the end of write_buf would be enough to replace send_off ...
Regards,
Fabian
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 6528aa6..a144b4e 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -83,7 +83,6 @@ struct clone_root {
struct send_ctx {
struct file *send_filp;
- loff_t send_off;
char *send_buf;
u32 send_size;
u32 send_max_size;
@@ -505,35 +504,28 @@ static struct btrfs_path *alloc_path_for_send(void)
return path;
}
-static int write_buf(struct file *filp, const void *buf, u32 len, loff_t *off)
+static int write_buf(struct file *filp, const void *buf, u32 len)
{
int ret;
mm_segment_t old_fs;
u32 pos = 0;
- old_fs = get_fs();
- set_fs(KERNEL_DS);
-
while (pos < len) {
- ret = vfs_write(filp, (char *)buf + pos, len - pos, off);
+ ret = kernel_write(filp, (char *)buf + pos, len - pos, 0);
/* TODO handle that correctly */
/*if (ret == -ERESTARTSYS) {
continue;
}*/
if (ret < 0)
- goto out;
+ return ret;
if (ret == 0) {
ret = -EIO;
- goto out;
+ return ret;
}
pos += ret;
}
- ret = 0;
-
-out:
- set_fs(old_fs);
- return ret;
+ return 0;
}
static int tlv_put(struct send_ctx *sctx, u16 attr, const void *data, int len)
@@ -639,8 +631,7 @@ static int send_header(struct send_ctx *sctx)
strcpy(hdr.magic, BTRFS_SEND_STREAM_MAGIC);
hdr.version = cpu_to_le32(BTRFS_SEND_STREAM_VERSION);
- return write_buf(sctx->send_filp, &hdr, sizeof(hdr),
- &sctx->send_off);
+ return write_buf(sctx->send_filp, &hdr, sizeof(hdr));
}
/*
@@ -675,8 +666,7 @@ static int send_cmd(struct send_ctx *sctx)
crc = btrfs_crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size);
hdr->crc = cpu_to_le32(crc);
- ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size,
- &sctx->send_off);
+ ret = write_buf(sctx->send_filp, sctx->send_buf);
sctx->total_send_size += sctx->send_size;
sctx->cmd_send_size[le16_to_cpu(hdr->cmd)] += sctx->send_size;
next prev parent reply other threads:[~2014-08-02 12:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 19:17 [PATCH 1/1] Btrfs: fix sparse warning Fabian Frederick
2014-07-16 17:20 ` Zach Brown
2014-07-17 18:37 ` Fabian Frederick
2014-07-17 19:01 ` Zach Brown
2014-08-02 12:24 ` Fabian Frederick [this message]
2014-08-04 18:31 ` Zach Brown
2014-08-05 9:20 ` Fabian Frederick
2014-08-05 21:32 ` Zach Brown
2014-08-18 16:53 ` Fabian Frederick
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=20140802142449.15f4cfc2c2821e90e04e175e@skynet.be \
--to=fabf@skynet.be \
--cc=clm@fb.com \
--cc=jbacik@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zab@zabbo.net \
/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).