Re: [PATCH 1/1] Btrfs: fix sparse warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 17 Jul 2014 12:01:52 -0700
Zach Brown <zab@xxxxxxxxx> 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;
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux