diff mbox

[7/9] pnfs/blocklayout: implement the return_range method

Message ID 1410362617-28018-8-git-send-email-hch@lst.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christoph Hellwig Sept. 10, 2014, 3:23 p.m. UTC
This allows removing extents from the extent tree especially on truncate
operations, and thus fixing reads from truncated and re-extended that
previously returned stale data.

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

Comments

Peng Tao Sept. 11, 2014, 2:16 p.m. UTC | #1
On Wed, Sep 10, 2014 at 11:23 PM, Christoph Hellwig <hch@lst.de> wrote:
> This allows removing extents from the extent tree especially on truncate
> operations, and thus fixing reads from truncated and re-extended that
> previously returned stale data.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/nfs/blocklayout/blocklayout.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
> index 42b6f9c..a7524c4 100644
> --- a/fs/nfs/blocklayout/blocklayout.c
> +++ b/fs/nfs/blocklayout/blocklayout.c
> @@ -470,6 +470,35 @@ static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo,
>  }
>
>  static void
> +bl_return_range(struct pnfs_layout_hdr *lo,
> +               struct pnfs_layout_range *range)
> +{
> +       struct pnfs_block_layout *bl = BLK_LO2EXT(lo);
> +       sector_t offset = range->offset >> SECTOR_SHIFT, end;
> +       int err;
> +
> +       if (range->offset % 8) {
why arbitrary block size? You should be able to use the blocksize
returned by server, right?

btw, did you test your patchset with smaller block size such as 2K/1K?
Did it work?

> +               dprintk("%s: offset %lld not block size aligned\n",
> +                       __func__, range->offset);
> +               return;
> +       }
> +
> +       if (range->length != NFS4_MAX_UINT64) {
> +               if (range->length % 8) {
ditto here.

Cheers,
Tao
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Sept. 11, 2014, 3:24 p.m. UTC | #2
On Thu, Sep 11, 2014 at 10:16:56PM +0800, Peng Tao wrote:
> > diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
> > index 42b6f9c..a7524c4 100644
> > --- a/fs/nfs/blocklayout/blocklayout.c
> > +++ b/fs/nfs/blocklayout/blocklayout.c
> > @@ -470,6 +470,35 @@ static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo,
> >  }
> >
> >  static void
> > +bl_return_range(struct pnfs_layout_hdr *lo,
> > +               struct pnfs_layout_range *range)
> > +{
> > +       struct pnfs_block_layout *bl = BLK_LO2EXT(lo);
> > +       sector_t offset = range->offset >> SECTOR_SHIFT, end;
> > +       int err;
> > +
> > +       if (range->offset % 8) {
> why arbitrary block size? You should be able to use the blocksize
> returned by server, right?

I need to look into it.  Right now the client has all extents properly
aligned, and allowing a smaller size here would change that.  Give me
some time to test it and get back to you.

> 
> btw, did you test your patchset with smaller block size such as 2K/1K?
> Did it work?

I did test a very early version but haven't redone the tests.  It worked
fine because even although the server supported smaller blocks the client
now never asks for anything not aligned to 4k!

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 42b6f9c..a7524c4 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -470,6 +470,35 @@  static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo,
 }
 
 static void
+bl_return_range(struct pnfs_layout_hdr *lo,
+		struct pnfs_layout_range *range)
+{
+	struct pnfs_block_layout *bl = BLK_LO2EXT(lo);
+	sector_t offset = range->offset >> SECTOR_SHIFT, end;
+	int err;
+
+	if (range->offset % 8) {
+		dprintk("%s: offset %lld not block size aligned\n",
+			__func__, range->offset);
+		return;
+	}
+
+	if (range->length != NFS4_MAX_UINT64) {
+		if (range->length % 8) {
+			dprintk("%s: length %lld not block size aligned\n",
+				__func__, range->length);
+			return;
+		}
+
+		end = offset + (range->length >> SECTOR_SHIFT);
+	} else {
+		end = round_down(NFS4_MAX_UINT64, PAGE_SIZE);
+	}
+
+	err = ext_tree_remove(bl, range->iomode & IOMODE_RW, offset, end);
+}
+
+static void
 bl_encode_layoutcommit(struct pnfs_layout_hdr *lo, struct xdr_stream *xdr,
 		       const struct nfs4_layoutcommit_args *arg)
 {
@@ -777,6 +806,7 @@  static struct pnfs_layoutdriver_type blocklayout_type = {
 	.free_layout_hdr		= bl_free_layout_hdr,
 	.alloc_lseg			= bl_alloc_lseg,
 	.free_lseg			= bl_free_lseg,
+	.return_range			= bl_return_range,
 	.encode_layoutcommit		= bl_encode_layoutcommit,
 	.cleanup_layoutcommit		= bl_cleanup_layoutcommit,
 	.set_layoutdriver		= bl_set_layoutdriver,