Linux NFS development
 help / color / mirror / Atom feed
* misc blocklayout updates
@ 2015-08-17 16:40 Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 1/5] pnfs/blocklayout: calculate layoutupdate size correctly Christoph Hellwig
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:40 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

A couple small bugfixes, and one patch that consolidates block layout XDR
related defines in nfs4.h instead of duplicating them in the client
and server.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] pnfs/blocklayout: calculate layoutupdate size correctly
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
@ 2015-08-17 16:40 ` Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 2/5] pnfs/blocklayout: set up layoutupdate_pages properly Christoph Hellwig
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:40 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

We need to include the first u32 for the number of entries.  Add a helper
for the calculation instead of opencoding it so that it's in one place.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/extent_tree.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_tree.c
index 31d0b5e..7536036 100644
--- a/fs/nfs/blocklayout/extent_tree.c
+++ b/fs/nfs/blocklayout/extent_tree.c
@@ -462,6 +462,12 @@ out:
 	return err;
 }
 
+static size_t ext_tree_layoutupdate_size(size_t count)
+{
+	return sizeof(__be32) /* number of entries */ +
+		BL_EXTENT_SIZE * count;
+}
+
 static void ext_tree_free_commitdata(struct nfs4_layoutcommit_args *arg,
 		size_t buffer_size)
 {
@@ -489,7 +495,7 @@ static int ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
 			continue;
 
 		(*count)++;
-		if (*count * BL_EXTENT_SIZE > buffer_size) {
+		if (ext_tree_layoutupdate_size(*count) > buffer_size) {
 			/* keep counting.. */
 			ret = -ENOSPC;
 			continue;
@@ -530,7 +536,7 @@ retry:
 	if (unlikely(ret)) {
 		ext_tree_free_commitdata(arg, buffer_size);
 
-		buffer_size = sizeof(__be32) + BL_EXTENT_SIZE * count;
+		buffer_size = ext_tree_layoutupdate_size(count);
 		count = 0;
 
 		arg->layoutupdate_pages =
@@ -549,7 +555,7 @@ retry:
 	}
 
 	*start_p = cpu_to_be32(count);
-	arg->layoutupdate_len = sizeof(__be32) + BL_EXTENT_SIZE * count;
+	arg->layoutupdate_len = ext_tree_layoutupdate_size(count);
 
 	if (unlikely(arg->layoutupdate_pages != &arg->layoutupdate_page)) {
 		__be32 *p = start_p;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] pnfs/blocklayout: set up layoutupdate_pages properly
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 1/5] pnfs/blocklayout: calculate layoutupdate size correctly Christoph Hellwig
@ 2015-08-17 16:40 ` Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 3/5] pnfs/blocklayout: reject too long signatures Christoph Hellwig
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:40 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

We need to replace the __be32 with a void pointer to do proper arithmentics
on the virtual addresses so that we can get the right page pointers.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/extent_tree.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_tree.c
index 7536036..a11b759 100644
--- a/fs/nfs/blocklayout/extent_tree.c
+++ b/fs/nfs/blocklayout/extent_tree.c
@@ -558,14 +558,11 @@ retry:
 	arg->layoutupdate_len = ext_tree_layoutupdate_size(count);
 
 	if (unlikely(arg->layoutupdate_pages != &arg->layoutupdate_page)) {
-		__be32 *p = start_p;
+		void *p = start_p, *end = p + arg->layoutupdate_len;
 		int i = 0;
 
-		for (p = start_p;
-		     p < start_p + arg->layoutupdate_len;
-		     p += PAGE_SIZE) {
+		for ( ; p < end; p += PAGE_SIZE)
 			arg->layoutupdate_pages[i++] = vmalloc_to_page(p);
-		}
 	}
 
 	dprintk("%s found %zu ranges\n", __func__, count);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] pnfs/blocklayout: reject too long signatures
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 1/5] pnfs/blocklayout: calculate layoutupdate size correctly Christoph Hellwig
  2015-08-17 16:40 ` [PATCH 2/5] pnfs/blocklayout: set up layoutupdate_pages properly Christoph Hellwig
@ 2015-08-17 16:40 ` Christoph Hellwig
  2015-08-17 16:41 ` [PATCH 4/5] pnfs/blocklayout: pass proper file mode to blkdev_get/put Christoph Hellwig
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:40 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

Instead of overwriting kernel memory reject too long signatures.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/dev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index e535599..d76993a 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -65,6 +65,11 @@ nfs4_block_decode_volume(struct xdr_stream *xdr, struct pnfs_block_volume *b)
 				return -EIO;
 			p = xdr_decode_hyper(p, &b->simple.sigs[i].offset);
 			b->simple.sigs[i].sig_len = be32_to_cpup(p++);
+			if (b->simple.sigs[i].sig_len > PNFS_BLOCK_UUID_LEN) {
+				pr_info("signature too long: %d\n",
+					b->simple.sigs[i].sig_len);
+				return -EIO;
+			}
 
 			p = xdr_inline_decode(xdr, b->simple.sigs[i].sig_len);
 			if (!p)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] pnfs/blocklayout: pass proper file mode to blkdev_get/put
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
                   ` (2 preceding siblings ...)
  2015-08-17 16:40 ` [PATCH 3/5] pnfs/blocklayout: reject too long signatures Christoph Hellwig
@ 2015-08-17 16:41 ` Christoph Hellwig
  2015-08-17 16:41 ` [PATCH 5/5] pnfs: move common blocklayout XDR defintions to nfs4.h Christoph Hellwig
  2015-08-21  7:04 ` misc blocklayout updates Christoph Hellwig
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:41 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

We generally want to read and write to a block device that's used by
the pNFS block layout client (and even if it's read only the server
has no way of telling us).  Add FMODE_WRITE to the mode argument
so that we don't incorrectly tell the block driver that we want a
read-only open.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index d76993a..a861bbd 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -22,7 +22,7 @@ bl_free_device(struct pnfs_block_dev *dev)
 		kfree(dev->children);
 	} else {
 		if (dev->bdev)
-			blkdev_put(dev->bdev, FMODE_READ);
+			blkdev_put(dev->bdev, FMODE_READ | FMODE_WRITE);
 	}
 }
 
@@ -200,7 +200,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
 	if (!dev)
 		return -EIO;
 
-	d->bdev = blkdev_get_by_dev(dev, FMODE_READ, NULL);
+	d->bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_WRITE, NULL);
 	if (IS_ERR(d->bdev)) {
 		printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
 			MAJOR(dev), MINOR(dev), PTR_ERR(d->bdev));
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] pnfs: move common blocklayout XDR defintions to nfs4.h
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
                   ` (3 preceding siblings ...)
  2015-08-17 16:41 ` [PATCH 4/5] pnfs/blocklayout: pass proper file mode to blkdev_get/put Christoph Hellwig
@ 2015-08-17 16:41 ` Christoph Hellwig
  2015-08-21  7:04 ` misc blocklayout updates Christoph Hellwig
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-17 16:41 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/blocklayout/blocklayout.h | 19 +------------------
 fs/nfs/blocklayout/extent_tree.c |  2 +-
 fs/nfsd/blocklayoutxdr.c         |  2 +-
 fs/nfsd/blocklayoutxdr.h         | 15 ---------------
 include/linux/nfs4.h             | 18 ++++++++++++++++++
 5 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h
index 92dca9e..c556640 100644
--- a/fs/nfs/blocklayout/blocklayout.h
+++ b/fs/nfs/blocklayout/blocklayout.h
@@ -46,13 +46,6 @@
 
 struct pnfs_block_dev;
 
-enum pnfs_block_volume_type {
-	PNFS_BLOCK_VOLUME_SIMPLE	= 0,
-	PNFS_BLOCK_VOLUME_SLICE		= 1,
-	PNFS_BLOCK_VOLUME_CONCAT	= 2,
-	PNFS_BLOCK_VOLUME_STRIPE	= 3,
-};
-
 #define PNFS_BLOCK_MAX_UUIDS	4
 #define PNFS_BLOCK_MAX_DEVICES	64
 
@@ -117,13 +110,6 @@ struct pnfs_block_dev {
 			struct pnfs_block_dev_map *map);
 };
 
-enum exstate4 {
-	PNFS_BLOCK_READWRITE_DATA	= 0,
-	PNFS_BLOCK_READ_DATA		= 1,
-	PNFS_BLOCK_INVALID_DATA		= 2, /* mapped, but data is invalid */
-	PNFS_BLOCK_NONE_DATA		= 3  /* unmapped, it's a hole */
-};
-
 /* sector_t fields are all in 512-byte sectors */
 struct pnfs_block_extent {
 	union {
@@ -134,15 +120,12 @@ struct pnfs_block_extent {
 	sector_t	be_f_offset;	/* the starting offset in the file */
 	sector_t	be_length;	/* the size of the extent */
 	sector_t	be_v_offset;	/* the starting offset in the volume */
-	enum exstate4	be_state;	/* the state of this extent */
+	enum pnfs_block_extent_state be_state;	/* the state of this extent */
 #define EXTENT_WRITTEN		1
 #define EXTENT_COMMITTING	2
 	unsigned int	be_tag;
 };
 
-/* on the wire size of the extent */
-#define BL_EXTENT_SIZE	(7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
-
 struct pnfs_block_layout {
 	struct pnfs_layout_hdr	bl_layout;
 	struct rb_root		bl_ext_rw;
diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_tree.c
index a11b759..c59a59c 100644
--- a/fs/nfs/blocklayout/extent_tree.c
+++ b/fs/nfs/blocklayout/extent_tree.c
@@ -465,7 +465,7 @@ out:
 static size_t ext_tree_layoutupdate_size(size_t count)
 {
 	return sizeof(__be32) /* number of entries */ +
-		BL_EXTENT_SIZE * count;
+		PNFS_BLOCK_EXTENT_SIZE * count;
 }
 
 static void ext_tree_free_commitdata(struct nfs4_layoutcommit_args *arg,
diff --git a/fs/nfsd/blocklayoutxdr.c b/fs/nfsd/blocklayoutxdr.c
index 9aa2796..6d834dc 100644
--- a/fs/nfsd/blocklayoutxdr.c
+++ b/fs/nfsd/blocklayoutxdr.c
@@ -101,7 +101,7 @@ nfsd4_block_decode_layoutupdate(__be32 *p, u32 len, struct iomap **iomapp,
 	}
 
 	nr_iomaps = be32_to_cpup(p++);
-	expected = sizeof(__be32) + nr_iomaps * NFS4_BLOCK_EXTENT_SIZE;
+	expected = sizeof(__be32) + nr_iomaps * PNFS_BLOCK_EXTENT_SIZE;
 	if (len != expected) {
 		dprintk("%s: extent array size mismatch: %u/%u\n",
 			__func__, len, expected);
diff --git a/fs/nfsd/blocklayoutxdr.h b/fs/nfsd/blocklayoutxdr.h
index fdc7903..6de925f 100644
--- a/fs/nfsd/blocklayoutxdr.h
+++ b/fs/nfsd/blocklayoutxdr.h
@@ -7,13 +7,6 @@
 struct iomap;
 struct xdr_stream;
 
-enum pnfs_block_extent_state {
-	PNFS_BLOCK_READWRITE_DATA	= 0,
-	PNFS_BLOCK_READ_DATA		= 1,
-	PNFS_BLOCK_INVALID_DATA		= 2,
-	PNFS_BLOCK_NONE_DATA		= 3,
-};
-
 struct pnfs_block_extent {
 	struct nfsd4_deviceid		vol_id;
 	u64				foff;
@@ -21,14 +14,6 @@ struct pnfs_block_extent {
 	u64				soff;
 	enum pnfs_block_extent_state	es;
 };
-#define NFS4_BLOCK_EXTENT_SIZE		44
-
-enum pnfs_block_volume_type {
-	PNFS_BLOCK_VOLUME_SIMPLE	= 0,
-	PNFS_BLOCK_VOLUME_SLICE		= 1,
-	PNFS_BLOCK_VOLUME_CONCAT	= 2,
-	PNFS_BLOCK_VOLUME_STRIPE	= 3,
-};
 
 /*
  * Random upper cap for the uuid length to avoid unbounded allocation.
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index b8e72aa..00121f2 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -547,6 +547,24 @@ enum pnfs_notify_deviceid_type4 {
 	NOTIFY_DEVICEID4_DELETE = 1 << 2,
 };
 
+enum pnfs_block_volume_type {
+	PNFS_BLOCK_VOLUME_SIMPLE	= 0,
+	PNFS_BLOCK_VOLUME_SLICE		= 1,
+	PNFS_BLOCK_VOLUME_CONCAT	= 2,
+	PNFS_BLOCK_VOLUME_STRIPE	= 3,
+};
+
+enum pnfs_block_extent_state {
+	PNFS_BLOCK_READWRITE_DATA	= 0,
+	PNFS_BLOCK_READ_DATA		= 1,
+	PNFS_BLOCK_INVALID_DATA		= 2,
+	PNFS_BLOCK_NONE_DATA		= 3,
+};
+
+/* on the wire size of a block layout extent */
+#define PNFS_BLOCK_EXTENT_SIZE \
+	(7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
+
 #define NFL4_UFLG_MASK			0x0000003F
 #define NFL4_UFLG_DENSE			0x00000001
 #define NFL4_UFLG_COMMIT_THRU_MDS	0x00000002
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: misc blocklayout updates
  2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
                   ` (4 preceding siblings ...)
  2015-08-17 16:41 ` [PATCH 5/5] pnfs: move common blocklayout XDR defintions to nfs4.h Christoph Hellwig
@ 2015-08-21  7:04 ` Christoph Hellwig
  2015-08-21  7:11   ` Trond Myklebust
  5 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-21  7:04 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

Any chance you could look over them?  There's been a steady trickle
of more recently posted patches to your tree and the merge window is
about to end, so I'll ping unusually early.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: misc blocklayout updates
  2015-08-21  7:04 ` misc blocklayout updates Christoph Hellwig
@ 2015-08-21  7:11   ` Trond Myklebust
  2015-08-21  7:15     ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Trond Myklebust @ 2015-08-21  7:11 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Linux NFS Mailing List

On Fri, Aug 21, 2015 at 12:04 AM, Christoph Hellwig <hch@lst.de> wrote:
> Any chance you could look over them?  There's been a steady trickle
> of more recently posted patches to your tree and the merge window is
> about to end, so I'll ping unusually early.

I thought i merged those into the linux-next+testing branches 2-3 days
ago. Are they missing?

Cheers
  Trond

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: misc blocklayout updates
  2015-08-21  7:11   ` Trond Myklebust
@ 2015-08-21  7:15     ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2015-08-21  7:15 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: Linux NFS Mailing List

On Fri, Aug 21, 2015 at 12:11:55AM -0700, Trond Myklebust wrote:
> On Fri, Aug 21, 2015 at 12:04 AM, Christoph Hellwig <hch@lst.de> wrote:
> > Any chance you could look over them?  There's been a steady trickle
> > of more recently posted patches to your tree and the merge window is
> > about to end, so I'll ping unusually early.
> 
> I thought i merged those into the linux-next+testing branches 2-3 days
> ago. Are they missing?

Oops, sorry.  The are there, but you rebased other patches that were
in earlier on top.  Sorry for not looking close enough!

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-08-21  7:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-17 16:40 misc blocklayout updates Christoph Hellwig
2015-08-17 16:40 ` [PATCH 1/5] pnfs/blocklayout: calculate layoutupdate size correctly Christoph Hellwig
2015-08-17 16:40 ` [PATCH 2/5] pnfs/blocklayout: set up layoutupdate_pages properly Christoph Hellwig
2015-08-17 16:40 ` [PATCH 3/5] pnfs/blocklayout: reject too long signatures Christoph Hellwig
2015-08-17 16:41 ` [PATCH 4/5] pnfs/blocklayout: pass proper file mode to blkdev_get/put Christoph Hellwig
2015-08-17 16:41 ` [PATCH 5/5] pnfs: move common blocklayout XDR defintions to nfs4.h Christoph Hellwig
2015-08-21  7:04 ` misc blocklayout updates Christoph Hellwig
2015-08-21  7:11   ` Trond Myklebust
2015-08-21  7:15     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox