NFSD: Impl multiple extents in block/scsi layoutget
Subsystems (3)
PATCH 1/1 NFSD: Impl multiple extents in block/scsi layoutget
This patch allows the pNFS server to respond with multiple extents in a layoutget request. As a result, the number of layoutget requests is significantly reduced for various file access patterns, including random and parallel writes, avoiding unnecessary load to the server. On the client side, this improves the performance of writing large files and allows requesting layouts with minimum length greater than PAGE_SIZE.
---
Checked with smatch, tested on pNFS block volume setup.
fs/nfsd/blocklayout.c | 167 +++++++++++++++++++++++++++++---------- fs/nfsd/blocklayoutxdr.c | 36 ++++++--- fs/nfsd/blocklayoutxdr.h | 5 ++ 3 files changed, 157 insertions(+), 51 deletions(-)
fs/nfsd/blocklayout.c +125 -42
@@ -17,48 +17,39 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_map_extent - get extent that covers the start of segment +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout subrange requested by the client +* @minlength: layout min length requested by the client +* @bex: output block extent structure +* +* Get an extent from the file system that starts at @seg->offset or below, +* but may be shorter than @seg->length. +* +* Return values: +* %nfs_ok: Success, @bex is initialized and valid +* %nfserr_layoutunavailable: Failed to get extent for requested @seg +* OS errors converted to NFS errors +*/ static __be32 -nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, -const struct svc_fh *fhp,struct nfsd4_layoutget *args) +nfsd4_block_map_extent (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_extent *bex) { -struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb; -u32 block_size =i_blocksize (inode); -struct pnfs_block_extent *bex;struct iomap iomap;u32 device_generation =0 ;int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } - -/* -* Some clients barf on non-zero block numbers for NONE or INVALID -* layouts, so make sure to zero the whole structure. -*/ - error = -ENOMEM ; - bex =kzalloc (sizeof (*bex),GFP_KERNEL ); -if (!bex) - goto out_error; - args->lg_content = bex; - error = sb->s_export_op->map_blocks (inode, seg->offset, seg->length, &iomap, seg->iomode !=IOMODE_READ , &device_generation);if (error) {if (error == -ENXIO ) - goto out_layoutunavailable; - goto out_error; - } - -if (iomap.length < args->lg_minlength) { -dprintk ("pnfsd: extent smaller than minlength\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; +return nfserrno (error); }switch (iomap.type) {
@@ -74,9 +65,9 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,/* * Crack monkey special case from section 2.3.1. */ -if (args->lg_minlength ==0 ) { +if (minlength ==0 ) {dprintk ("pnfsd: no soup for you!\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } bex->es =PNFS_BLOCK_INVALID_DATA ;
@@ -93,27 +84,119 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,case IOMAP_DELALLOC :default :WARN (1 ,"pnfsd: filesystem returned %d extent\n" , iomap.type); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } error =nfsd4_set_deviceid (&bex->vol_id, fhp, device_generation);if (error) - goto out_error; +return nfserrno (error); + bex->foff = iomap.offset; bex->len = iomap.length; +return nfs_ok; +} - seg->offset = iomap.offset; - seg->length = iomap.length; +/** +* nfsd4_block_map_segment - get extent array for the requested layout +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout range requested by the client +* @minlength: layout min length requested by the client +* @bl: output array of block extents +* +* Get an array of consecutive block extents that span the requested +* layout range. The resulting range may be shorter than requested if +* all preallocated block extents are used. +* +* Return values: +* %nfs_ok: Success, @bl initialized and valid +* %nfserr_layoutunavailable: Failed to get extents for requested @seg +* OS errors converted to NFS errors +*/ +static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl) +{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr; -dprintk ("GET: 0x%llx:0x%llx %d\n" , bex->foff, bex->len, bex->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +struct pnfs_block_extent *extent = bl->extents + i; +u64 extent_len; + + nfserr =nfsd4_block_map_extent (inode, fhp, &subseg, + minlength, extent); +if (nfserr != nfs_ok) +return nfserr; + + extent_len = extent->len - (subseg.offset - extent->foff); +if (extent_len >= subseg.length) { + bl->nr_extents = i +1 ; +return nfs_ok; + } + + subseg.offset = extent->foff + extent->len; + subseg.length -= extent_len; + } + +return nfs_ok; +} + +static __be32 +nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) +{ +struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ; +u32 block_size =i_blocksize (inode); +__be32 nfserr; + +if (locks_in_grace (SVC_NET (rqstp))) +return nfserr_grace; + + nfserr = nfserr_layoutunavailable; +if (seg->offset & (block_size -1 )) { +dprintk ("pnfsd: I/O misaligned\n" ); + goto out_error; + } + +/* +* Some clients barf on non-zero block numbers for NONE or INVALID +* layouts, so make sure to zero the whole structure. +*/ + nfserr =nfserrno (-ENOMEM ); + bl =kzalloc (struct_size (bl, extents, nr_extents_max),GFP_KERNEL ); +if (!bl) + goto out_error; + bl->nr_extents = nr_extents_max; + args->lg_content = bl; + + nfserr =nfsd4_block_map_segment (inode, fhp, seg, + args->lg_minlength, bl); +if (nfserr != nfs_ok) + goto out_error; + first_bex = bl->extents; + last_bex = bl->extents + bl->nr_extents -1 ; + + nfserr = nfserr_layoutunavailable; + seg_length = last_bex->foff + last_bex->len - seg->offset; +if (seg_length < args->lg_minlength) { +dprintk ("pnfsd: extent smaller than minlength\n" ); + goto out_error; + } + + seg->offset = first_bex->foff; + seg->length = last_bex->foff - first_bex->foff + last_bex->len; +return nfs_ok; out_error: seg->length =0 ; -return nfserrno (error); -out_layoutunavailable: - seg->length =0 ; -return nfserr_layoutunavailable; +return nfserr; } static __be32
fs/nfsd/blocklayoutxdr.c +27 -9
@@ -14,12 +14,25 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_encode_layoutget - encode block/scsi layout extent array +* @xdr: stream for data encoding +* @lgp: layoutget content, actually an array of extents to encode +* +* This function encodes the opaque loc_body field in the layoutget response. +* Since the pnfs_block_layout4 and pnfs_scsi_layout4 structures on the wire +* are the same, this function is used by both layout drivers. +* +* Return values: +* %nfs_ok: Success, all extents encoded into @xdr +* %nfserr_toosmall: Not enough space in @xdr to encode all the data +*/ __be32 nfsd4_block_encode_layoutget (struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp) { -const struct pnfs_block_extent *b = lgp->lg_content; -int len =sizeof (__be32) +5 *sizeof (__be64) +sizeof (__be32); +const struct pnfs_block_layout *bl = lgp->lg_content; +u32 i, len =sizeof (__be32) + bl->nr_extents *PNFS_BLOCK_EXTENT_SIZE ;__be32 *p; p =xdr_reserve_space (xdr,sizeof (__be32) + len);
@@ -27,14 +40,19 @@ nfsd4_block_encode_layoutget(struct xdr_stream *xdr,return nfserr_toosmall; *p++ =cpu_to_be32 (len); - *p++ =cpu_to_be32 (1 );/* we always return a single extent */ + *p++ =cpu_to_be32 (bl->nr_extents); - p =svcxdr_encode_deviceid4 (p, &b->vol_id); - p =xdr_encode_hyper (p, b->foff); - p =xdr_encode_hyper (p, b->len); - p =xdr_encode_hyper (p, b->soff); - *p++ =cpu_to_be32 (b->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +const struct pnfs_block_extent *bex = bl->extents + i; + + p =svcxdr_encode_deviceid4 (p, &bex->vol_id); + p =xdr_encode_hyper (p, bex->foff); + p =xdr_encode_hyper (p, bex->len); + p =xdr_encode_hyper (p, bex->soff); + *p++ =cpu_to_be32 (bex->es); + } + +return nfs_ok; } static int
fs/nfsd/blocklayoutxdr.h +5 -0
@@ -21,6 +21,11 @@ struct pnfs_block_range {u64 len; }; +struct pnfs_block_layout { +u32 nr_extents; + struct pnfs_block_extent extents[] __counted_by(nr_extents); +}; +/* * Random upper cap for the uuid length to avoid unbounded allocation. * Not actually limited by the protocol.
Signature · 1 line
2.43.0
Quoted 298 lines · Sergey Bashirov
This patch allows the pNFS server to respond with multiple extents in a layoutget request. As a result, the number of layoutget requests is significantly reduced for various file access patterns, including random and parallel writes, avoiding unnecessary load to the server. On the client side, this improves the performance of writing large files and allows requesting layouts with minimum length greater than
PAGE_SIZE.Signed-off-by Sergey Bashirov <[email protected]>---
Checked with smatch, tested on pNFS block volume setup.fs/nfsd/blocklayout.c | 167 +++++++++++++++++++++++++++++---------- fs/nfsd/blocklayoutxdr.c | 36 ++++++--- fs/nfsd/blocklayoutxdr.h | 5 ++ 3 files changed, 157 insertions(+), 51 deletions(-)fs/nfsd/blocklayout.c +125
-42@@ -17,48 +17,39 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_map_extent - get extent that covers the start of segment +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout subrange requested by the client +* @minlength: layout min length requested by the client +* @bex: output block extent structure +* +* Get an extent from the file system that starts at @seg->offset or below, +* but may be shorter than @seg->length. +* +* Return values: +* %nfs_ok: Success, @bex is initialized and valid +* %nfserr_layoutunavailable: Failed to get extent for requested @seg +* OS errors converted to NFS errors +*/ static __be32 -nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, -const struct svc_fh *fhp,struct nfsd4_layoutget *args) +nfsd4_block_map_extent (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_extent *bex) { -struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb; -u32 block_size =i_blocksize (inode); -struct pnfs_block_extent *bex;struct iomap iomap;u32 device_generation =0 ;int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } - -/* -* Some clients barf on non-zero block numbers for NONE or INVALID -* layouts, so make sure to zero the whole structure. -*/ - error = -ENOMEM ; - bex =kzalloc (sizeof (*bex),GFP_KERNEL ); -if (!bex) - goto out_error; - args->lg_content = bex; - error = sb->s_export_op->map_blocks (inode, seg->offset, seg->length, &iomap, seg->iomode !=IOMODE_READ , &device_generation);if (error) {if (error == -ENXIO ) - goto out_layoutunavailable; - goto out_error; - } - -if (iomap.length < args->lg_minlength) { -dprintk ("pnfsd: extent smaller than minlength\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; +return nfserrno (error); }switch (iomap.type) {@@ -74,9 +65,9 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,/* * Crack monkey special case from section 2.3.1. */ -if (args->lg_minlength ==0 ) { +if (minlength ==0 ) {dprintk ("pnfsd: no soup for you!\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } bex->es =PNFS_BLOCK_INVALID_DATA ;@@ -93,27 +84,119 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,case IOMAP_DELALLOC :default :WARN (1 ,"pnfsd: filesystem returned %d extent\n" , iomap.type); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } error =nfsd4_set_deviceid (&bex->vol_id, fhp, device_generation);if (error) - goto out_error; +return nfserrno (error); + bex->foff = iomap.offset; bex->len = iomap.length; +return nfs_ok; +} - seg->offset = iomap.offset; - seg->length = iomap.length; +/** +* nfsd4_block_map_segment - get extent array for the requested layout +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout range requested by the client +* @minlength: layout min length requested by the client +* @bl: output array of block extents +* +* Get an array of consecutive block extents that span the requested +* layout range. The resulting range may be shorter than requested if +* all preallocated block extents are used. +* +* Return values: +* %nfs_ok: Success, @bl initialized and valid +* %nfserr_layoutunavailable: Failed to get extents for requested @seg +* OS errors converted to NFS errors +*/ +static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl) +{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr; -dprintk ("GET: 0x%llx:0x%llx %d\n" , bex->foff, bex->len, bex->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +struct pnfs_block_extent *extent = bl->extents + i; +u64 extent_len; + + nfserr =nfsd4_block_map_extent (inode, fhp, &subseg, + minlength, extent); +if (nfserr != nfs_ok) +return nfserr; + + extent_len = extent->len - (subseg.offset - extent->foff); +if (extent_len >= subseg.length) { + bl->nr_extents = i +1 ; +return nfs_ok; + } + + subseg.offset = extent->foff + extent->len; + subseg.length -= extent_len; + } + +return nfs_ok; +} + +static __be32 +nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) +{ +struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ; +u32 block_size =i_blocksize (inode); +__be32 nfserr; + +if (locks_in_grace (SVC_NET (rqstp))) +return nfserr_grace; + + nfserr = nfserr_layoutunavailable; +if (seg->offset & (block_size -1 )) { +dprintk ("pnfsd: I/O misaligned\n" ); + goto out_error; + } + +/* +* Some clients barf on non-zero block numbers for NONE or INVALID +* layouts, so make sure to zero the whole structure. +*/ + nfserr =nfserrno (-ENOMEM ); + bl =kzalloc (struct_size (bl, extents, nr_extents_max),GFP_KERNEL ); +if (!bl) + goto out_error; + bl->nr_extents = nr_extents_max; + args->lg_content = bl; + + nfserr =nfsd4_block_map_segment (inode, fhp, seg, + args->lg_minlength, bl); +if (nfserr != nfs_ok) + goto out_error; + first_bex = bl->extents; + last_bex = bl->extents + bl->nr_extents -1 ; + + nfserr = nfserr_layoutunavailable; + seg_length = last_bex->foff + last_bex->len - seg->offset; +if (seg_length < args->lg_minlength) { +dprintk ("pnfsd: extent smaller than minlength\n" ); + goto out_error; + } + + seg->offset = first_bex->foff; + seg->length = last_bex->foff - first_bex->foff + last_bex->len; +return nfs_ok; out_error: seg->length =0 ; -return nfserrno (error); -out_layoutunavailable: - seg->length =0 ; -return nfserr_layoutunavailable; +return nfserr; } static __be32fs/nfsd/blocklayoutxdr.c +27
-9@@ -14,12 +14,25 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_encode_layoutget - encode block/scsi layout extent array +* @xdr: stream for data encoding +* @lgp: layoutget content, actually an array of extents to encode +* +* This function encodes the opaque loc_body field in the layoutget response. +* Since the pnfs_block_layout4 and pnfs_scsi_layout4 structures on the wire +* are the same, this function is used by both layout drivers. +* +* Return values: +* %nfs_ok: Success, all extents encoded into @xdr +* %nfserr_toosmall: Not enough space in @xdr to encode all the data +*/ __be32 nfsd4_block_encode_layoutget (struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp) { -const struct pnfs_block_extent *b = lgp->lg_content; -int len =sizeof (__be32) +5 *sizeof (__be64) +sizeof (__be32); +const struct pnfs_block_layout *bl = lgp->lg_content; +u32 i, len =sizeof (__be32) + bl->nr_extents *PNFS_BLOCK_EXTENT_SIZE ;__be32 *p; p =xdr_reserve_space (xdr,sizeof (__be32) + len);@@ -27,14 +40,19 @@ nfsd4_block_encode_layoutget(struct xdr_stream *xdr,return nfserr_toosmall; *p++ =cpu_to_be32 (len); - *p++ =cpu_to_be32 (1 );/* we always return a single extent */ + *p++ =cpu_to_be32 (bl->nr_extents); - p =svcxdr_encode_deviceid4 (p, &b->vol_id); - p =xdr_encode_hyper (p, b->foff); - p =xdr_encode_hyper (p, b->len); - p =xdr_encode_hyper (p, b->soff); - *p++ =cpu_to_be32 (b->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +const struct pnfs_block_extent *bex = bl->extents + i; + + p =svcxdr_encode_deviceid4 (p, &bex->vol_id); + p =xdr_encode_hyper (p, bex->foff); + p =xdr_encode_hyper (p, bex->len); + p =xdr_encode_hyper (p, bex->soff); + *p++ =cpu_to_be32 (bex->es); + } + +return nfs_ok; } static intfs/nfsd/blocklayoutxdr.h +0
-0@@ -21,6 +21,11 @@ struct pnfs_block_range {u64 len;
fs/nfsd/blocklayoutxdr.h struct pnfs_block_range { · line 31
Quoted 10 lines
fs/nfsd/blocklayoutxdr.h +5
-0}; +struct pnfs_block_layout { +u32 nr_extents; + struct pnfs_block_extent extents[] __counted_by(nr_extents); +}; +/* * Random upper cap for the uuid length to avoid unbounded allocation. * Not actually limited by the protocol.
Dai, Christoph - please review and/or test.
Signature · 1 line
Chuck Lever
Dai Ngo
reviewerQuoted 301 lines · Chuck Lever
Quoted 300 lines · Sergey Bashirov
This patch allows the pNFS server to respond with multiple extents in a layoutget request. As a result, the number of layoutget requests is significantly reduced for various file access patterns, including random and parallel writes, avoiding unnecessary load to the server. On the client side, this improves the performance of writing large files and allows requesting layouts with minimum length greater than
PAGE_SIZE.Signed-off-by Sergey Bashirov <[email protected]>---
Checked with smatch, tested on pNFS block volume setup.fs/nfsd/blocklayout.c | 167 +++++++++++++++++++++++++++++---------- fs/nfsd/blocklayoutxdr.c | 36 ++++++--- fs/nfsd/blocklayoutxdr.h | 5 ++ 3 files changed, 157 insertions(+), 51 deletions(-)fs/nfsd/blocklayout.c +125
-42@@ -17,48 +17,39 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_map_extent - get extent that covers the start of segment +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout subrange requested by the client +* @minlength: layout min length requested by the client +* @bex: output block extent structure +* +* Get an extent from the file system that starts at @seg->offset or below, +* but may be shorter than @seg->length. +* +* Return values: +* %nfs_ok: Success, @bex is initialized and valid +* %nfserr_layoutunavailable: Failed to get extent for requested @seg +* OS errors converted to NFS errors +*/ static __be32 -nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, -const struct svc_fh *fhp,struct nfsd4_layoutget *args) +nfsd4_block_map_extent (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_extent *bex) { -struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb; -u32 block_size =i_blocksize (inode); -struct pnfs_block_extent *bex;struct iomap iomap;u32 device_generation =0 ;int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } - -/* -* Some clients barf on non-zero block numbers for NONE or INVALID -* layouts, so make sure to zero the whole structure. -*/ - error = -ENOMEM ; - bex =kzalloc (sizeof (*bex),GFP_KERNEL ); -if (!bex) - goto out_error; - args->lg_content = bex; - error = sb->s_export_op->map_blocks (inode, seg->offset, seg->length, &iomap, seg->iomode !=IOMODE_READ , &device_generation);if (error) {if (error == -ENXIO ) - goto out_layoutunavailable; - goto out_error; - } - -if (iomap.length < args->lg_minlength) { -dprintk ("pnfsd: extent smaller than minlength\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; +return nfserrno (error); }switch (iomap.type) {@@ -74,9 +65,9 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,/* * Crack monkey special case from section 2.3.1. */ -if (args->lg_minlength ==0 ) { +if (minlength ==0 ) {dprintk ("pnfsd: no soup for you!\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } bex->es =PNFS_BLOCK_INVALID_DATA ;@@ -93,27 +84,119 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,case IOMAP_DELALLOC :default :WARN (1 ,"pnfsd: filesystem returned %d extent\n" , iomap.type); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } error =nfsd4_set_deviceid (&bex->vol_id, fhp, device_generation);if (error) - goto out_error; +return nfserrno (error); + bex->foff = iomap.offset; bex->len = iomap.length; +return nfs_ok; +} - seg->offset = iomap.offset; - seg->length = iomap.length; +/** +* nfsd4_block_map_segment - get extent array for the requested layout +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout range requested by the client +* @minlength: layout min length requested by the client +* @bl: output array of block extents +* +* Get an array of consecutive block extents that span the requested +* layout range. The resulting range may be shorter than requested if +* all preallocated block extents are used. +* +* Return values: +* %nfs_ok: Success, @bl initialized and valid +* %nfserr_layoutunavailable: Failed to get extents for requested @seg +* OS errors converted to NFS errors +*/ +static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl) +{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr; -dprintk ("GET: 0x%llx:0x%llx %d\n" , bex->foff, bex->len, bex->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +struct pnfs_block_extent *extent = bl->extents + i; +u64 extent_len; + + nfserr =nfsd4_block_map_extent (inode, fhp, &subseg, + minlength, extent); +if (nfserr != nfs_ok) +return nfserr; + + extent_len = extent->len - (subseg.offset - extent->foff); +if (extent_len >= subseg.length) { + bl->nr_extents = i +1 ; +return nfs_ok; + } + + subseg.offset = extent->foff + extent->len; + subseg.length -= extent_len; + } + +return nfs_ok; +} + +static __be32 +nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) +{ +struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ; +u32 block_size =i_blocksize (inode); +__be32 nfserr; + +if (locks_in_grace (SVC_NET (rqstp))) +return nfserr_grace; + + nfserr = nfserr_layoutunavailable; +if (seg->offset & (block_size -1 )) { +dprintk ("pnfsd: I/O misaligned\n" ); + goto out_error; + } + +/* +* Some clients barf on non-zero block numbers for NONE or INVALID +* layouts, so make sure to zero the whole structure. +*/ + nfserr =nfserrno (-ENOMEM ); + bl =kzalloc (struct_size (bl, extents, nr_extents_max),GFP_KERNEL ); +if (!bl) + goto out_error; + bl->nr_extents = nr_extents_max; + args->lg_content = bl; + + nfserr =nfsd4_block_map_segment (inode, fhp, seg, + args->lg_minlength, bl); +if (nfserr != nfs_ok) + goto out_error; + first_bex = bl->extents; + last_bex = bl->extents + bl->nr_extents -1 ; + + nfserr = nfserr_layoutunavailable; + seg_length = last_bex->foff + last_bex->len - seg->offset; +if (seg_length < args->lg_minlength) { +dprintk ("pnfsd: extent smaller than minlength\n" ); + goto out_error; + } + + seg->offset = first_bex->foff; + seg->length = last_bex->foff - first_bex->foff + last_bex->len; +return nfs_ok; out_error: seg->length =0 ; -return nfserrno (error); -out_layoutunavailable: - seg->length =0 ; -return nfserr_layoutunavailable; +return nfserr; } static __be32fs/nfsd/blocklayoutxdr.c +27
-9@@ -14,12 +14,25 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_encode_layoutget - encode block/scsi layout extent array +* @xdr: stream for data encoding +* @lgp: layoutget content, actually an array of extents to encode +* +* This function encodes the opaque loc_body field in the layoutget response. +* Since the pnfs_block_layout4 and pnfs_scsi_layout4 structures on the wire +* are the same, this function is used by both layout drivers. +* +* Return values: +* %nfs_ok: Success, all extents encoded into @xdr +* %nfserr_toosmall: Not enough space in @xdr to encode all the data +*/ __be32 nfsd4_block_encode_layoutget (struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp) { -const struct pnfs_block_extent *b = lgp->lg_content; -int len =sizeof (__be32) +5 *sizeof (__be64) +sizeof (__be32); +const struct pnfs_block_layout *bl = lgp->lg_content; +u32 i, len =sizeof (__be32) + bl->nr_extents *PNFS_BLOCK_EXTENT_SIZE ;__be32 *p; p =xdr_reserve_space (xdr,sizeof (__be32) + len);@@ -27,14 +40,19 @@ nfsd4_block_encode_layoutget(struct xdr_stream *xdr,return nfserr_toosmall; *p++ =cpu_to_be32 (len); - *p++ =cpu_to_be32 (1 );/* we always return a single extent */ + *p++ =cpu_to_be32 (bl->nr_extents); - p =svcxdr_encode_deviceid4 (p, &b->vol_id); - p =xdr_encode_hyper (p, b->foff); - p =xdr_encode_hyper (p, b->len); - p =xdr_encode_hyper (p, b->soff); - *p++ =cpu_to_be32 (b->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +const struct pnfs_block_extent *bex = bl->extents + i; + + p =svcxdr_encode_deviceid4 (p, &bex->vol_id); + p =xdr_encode_hyper (p, bex->foff); + p =xdr_encode_hyper (p, bex->len); + p =xdr_encode_hyper (p, bex->soff); + *p++ =cpu_to_be32 (bex->es); + } + +return nfs_ok; } static intfs/nfsd/blocklayoutxdr.h +0
-0@@ -21,6 +21,11 @@ struct pnfs_block_range {u64 len; };
Quoted 9 lines
fs/nfsd/blocklayoutxdr.h struct pnfs_block_range { · line 31
Quoted 8 lines
fs/nfsd/blocklayoutxdr.h +5
-0+struct pnfs_block_layout { +u32 nr_extents; + struct pnfs_block_extent extents[] __counted_by(nr_extents); +}; +/* * Random upper cap for the uuid length to avoid unbounded allocation. * Not actually limited by the protocol. Dai, Christoph - please review and/or test.
LGTM.
Tested with SCSI layout and verified with multi-extent IO Read and Write.
-Dai
Quoted 2 lines
Quoted 298 lines · Sergey Bashirov
This patch allows the pNFS server to respond with multiple extents in a layoutget request. As a result, the number of layoutget requests is significantly reduced for various file access patterns, including random and parallel writes, avoiding unnecessary load to the server. On the client side, this improves the performance of writing large files and allows requesting layouts with minimum length greater than
PAGE_SIZE.Signed-off-by Sergey Bashirov <[email protected]>---
Checked with smatch, tested on pNFS block volume setup.fs/nfsd/blocklayout.c | 167 +++++++++++++++++++++++++++++---------- fs/nfsd/blocklayoutxdr.c | 36 ++++++--- fs/nfsd/blocklayoutxdr.h | 5 ++ 3 files changed, 157 insertions(+), 51 deletions(-)fs/nfsd/blocklayout.c +125
-42@@ -17,48 +17,39 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_map_extent - get extent that covers the start of segment +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout subrange requested by the client +* @minlength: layout min length requested by the client +* @bex: output block extent structure +* +* Get an extent from the file system that starts at @seg->offset or below, +* but may be shorter than @seg->length. +* +* Return values: +* %nfs_ok: Success, @bex is initialized and valid +* %nfserr_layoutunavailable: Failed to get extent for requested @seg +* OS errors converted to NFS errors +*/ static __be32 -nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, -const struct svc_fh *fhp,struct nfsd4_layoutget *args) +nfsd4_block_map_extent (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_extent *bex) { -struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb; -u32 block_size =i_blocksize (inode); -struct pnfs_block_extent *bex;struct iomap iomap;u32 device_generation =0 ;int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } - -/* -* Some clients barf on non-zero block numbers for NONE or INVALID -* layouts, so make sure to zero the whole structure. -*/ - error = -ENOMEM ; - bex =kzalloc (sizeof (*bex),GFP_KERNEL ); -if (!bex) - goto out_error; - args->lg_content = bex; - error = sb->s_export_op->map_blocks (inode, seg->offset, seg->length, &iomap, seg->iomode !=IOMODE_READ , &device_generation);if (error) {if (error == -ENXIO ) - goto out_layoutunavailable; - goto out_error; - } - -if (iomap.length < args->lg_minlength) { -dprintk ("pnfsd: extent smaller than minlength\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; +return nfserrno (error); }switch (iomap.type) {@@ -74,9 +65,9 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,/* * Crack monkey special case from section 2.3.1. */ -if (args->lg_minlength ==0 ) { +if (minlength ==0 ) {dprintk ("pnfsd: no soup for you!\n" ); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } bex->es =PNFS_BLOCK_INVALID_DATA ;@@ -93,27 +84,119 @@ nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,case IOMAP_DELALLOC :default :WARN (1 ,"pnfsd: filesystem returned %d extent\n" , iomap.type); - goto out_layoutunavailable; +return nfserr_layoutunavailable; } error =nfsd4_set_deviceid (&bex->vol_id, fhp, device_generation);if (error) - goto out_error; +return nfserrno (error); + bex->foff = iomap.offset; bex->len = iomap.length; +return nfs_ok; +} - seg->offset = iomap.offset; - seg->length = iomap.length; +/** +* nfsd4_block_map_segment - get extent array for the requested layout +* @inode: inode of the file requested by the client +* @fhp: handle of the file requested by the client +* @seg: layout range requested by the client +* @minlength: layout min length requested by the client +* @bl: output array of block extents +* +* Get an array of consecutive block extents that span the requested +* layout range. The resulting range may be shorter than requested if +* all preallocated block extents are used. +* +* Return values: +* %nfs_ok: Success, @bl initialized and valid +* %nfserr_layoutunavailable: Failed to get extents for requested @seg +* OS errors converted to NFS errors +*/ +static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl) +{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr; -dprintk ("GET: 0x%llx:0x%llx %d\n" , bex->foff, bex->len, bex->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +struct pnfs_block_extent *extent = bl->extents + i; +u64 extent_len; + + nfserr =nfsd4_block_map_extent (inode, fhp, &subseg, + minlength, extent); +if (nfserr != nfs_ok) +return nfserr; + + extent_len = extent->len - (subseg.offset - extent->foff); +if (extent_len >= subseg.length) { + bl->nr_extents = i +1 ; +return nfs_ok; + } + + subseg.offset = extent->foff + extent->len; + subseg.length -= extent_len; + } + +return nfs_ok; +} + +static __be32 +nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) +{ +struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ; +u32 block_size =i_blocksize (inode); +__be32 nfserr; + +if (locks_in_grace (SVC_NET (rqstp))) +return nfserr_grace; + + nfserr = nfserr_layoutunavailable; +if (seg->offset & (block_size -1 )) { +dprintk ("pnfsd: I/O misaligned\n" ); + goto out_error; + } + +/* +* Some clients barf on non-zero block numbers for NONE or INVALID +* layouts, so make sure to zero the whole structure. +*/ + nfserr =nfserrno (-ENOMEM ); + bl =kzalloc (struct_size (bl, extents, nr_extents_max),GFP_KERNEL ); +if (!bl) + goto out_error; + bl->nr_extents = nr_extents_max; + args->lg_content = bl; + + nfserr =nfsd4_block_map_segment (inode, fhp, seg, + args->lg_minlength, bl); +if (nfserr != nfs_ok) + goto out_error; + first_bex = bl->extents; + last_bex = bl->extents + bl->nr_extents -1 ; + + nfserr = nfserr_layoutunavailable; + seg_length = last_bex->foff + last_bex->len - seg->offset; +if (seg_length < args->lg_minlength) { +dprintk ("pnfsd: extent smaller than minlength\n" ); + goto out_error; + } + + seg->offset = first_bex->foff; + seg->length = last_bex->foff - first_bex->foff + last_bex->len; +return nfs_ok; out_error: seg->length =0 ; -return nfserrno (error); -out_layoutunavailable: - seg->length =0 ; -return nfserr_layoutunavailable; +return nfserr; } static __be32fs/nfsd/blocklayoutxdr.c +27
-9@@ -14,12 +14,25 @@#define NFSDDBG_FACILITY NFSDDBG_PNFS +/** +* nfsd4_block_encode_layoutget - encode block/scsi layout extent array +* @xdr: stream for data encoding +* @lgp: layoutget content, actually an array of extents to encode +* +* This function encodes the opaque loc_body field in the layoutget response. +* Since the pnfs_block_layout4 and pnfs_scsi_layout4 structures on the wire +* are the same, this function is used by both layout drivers. +* +* Return values: +* %nfs_ok: Success, all extents encoded into @xdr +* %nfserr_toosmall: Not enough space in @xdr to encode all the data +*/ __be32 nfsd4_block_encode_layoutget (struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp) { -const struct pnfs_block_extent *b = lgp->lg_content; -int len =sizeof (__be32) +5 *sizeof (__be64) +sizeof (__be32); +const struct pnfs_block_layout *bl = lgp->lg_content; +u32 i, len =sizeof (__be32) + bl->nr_extents *PNFS_BLOCK_EXTENT_SIZE ;__be32 *p; p =xdr_reserve_space (xdr,sizeof (__be32) + len);@@ -27,14 +40,19 @@ nfsd4_block_encode_layoutget(struct xdr_stream *xdr,return nfserr_toosmall; *p++ =cpu_to_be32 (len); - *p++ =cpu_to_be32 (1 );/* we always return a single extent */ + *p++ =cpu_to_be32 (bl->nr_extents); - p =svcxdr_encode_deviceid4 (p, &b->vol_id); - p =xdr_encode_hyper (p, b->foff); - p =xdr_encode_hyper (p, b->len); - p =xdr_encode_hyper (p, b->soff); - *p++ =cpu_to_be32 (b->es); -return 0 ; +for (i =0 ; i < bl->nr_extents; i++) { +const struct pnfs_block_extent *bex = bl->extents + i; + + p =svcxdr_encode_deviceid4 (p, &bex->vol_id); + p =xdr_encode_hyper (p, bex->foff); + p =xdr_encode_hyper (p, bex->len); + p =xdr_encode_hyper (p, bex->soff); + *p++ =cpu_to_be32 (bex->es); + } + +return nfs_ok; } static intfs/nfsd/blocklayoutxdr.h +0
-0@@ -21,6 +21,11 @@ struct pnfs_block_range {u64 len;
fs/nfsd/blocklayoutxdr.h struct pnfs_block_range { · line 31
Quoted 10 lines
fs/nfsd/blocklayoutxdr.h +5
-0}; +struct pnfs_block_layout { +u32 nr_extents; + struct pnfs_block_extent extents[] __counted_by(nr_extents); +}; +/* * Random upper cap for the uuid length to avoid unbounded allocation. * Not actually limited by the protocol.
-Dai
The subject line is odd. What is impl supposed to mean?
I'd say something like:
nfsd/blocklayout: support multiple extent per LAYOUTGET
Quoted 1 line · Sergey Bashirov
This patch allows the pNFS server to respond with multiple extents
This patch is redundant and should generally be avoided in commit log.
Quoted 3 lines
Signed-off-by Sergey Bashirov <[email protected]>---
Checked with smatch, tested on pNFS block volume setup.
Any chance we could get testing for this added to pynfs?
Also what is this patch against? If fails to apply to linux-next for me.
Quoted 12 lines
+/**
+ *nfsd4_block_map_extent- get extent that covers the start of segment
+ * @inode: inode of the file requested by the client
+ * @fhp: handle of the file requested by the client
+ * @seg: layout subrange requested by the client
+ * @minlength: layout min length requested by the client
+ * @bex: output block extent structure
+ *
+ * Get an extent from the file system that starts at @seg->offset or below,
+ * but may be shorter than @seg->length.
+ *
+ * Return values:
Quoted 4 lines
+ * %nfs_ok: Success, @bex is initialized and valid + * %nfserr_layoutunavailable: Failed to get extent for requested @seg + * OS errors converted to NFS errors+ */
I'm not sure how Chuck handles this, but kerneldoc comments for static functions and thus not as public documentation can be really annoying due to the verbose formatting of the paramters. I'd generally avoid them and instead of have short comments explaining the interesting bits about the calling convention and/or functionality.
Quoted 7 lines
fs/nfsd/blocklayout.c +3
-0+nfsd4_block_map_extent(struct inode *inode, const struct svc_fh *fhp, + const struct nfsd4_layout_seg *seg, u64 minlength, + struct pnfs_block_extent *bex) { struct super_block *sb = inode->i_sb;struct iomap iomap;u32 device_generation =0 ;
fs/nfsd/blocklayout.c line 39
Quoted 10 lines
fs/nfsd/blocklayout.c +0
-8int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } -
There is a lot of code movement here mixed with functional changes, which makes it very hard to follow. Any chance you could first split the functions, then introduce the new pnfs_block_layout structure and only then actually add multiple extents per layoutget? That'll make it a lot easier there are no unintended changes.
fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 119
Quoted 7 lines
+ * %nfserr_layoutunavailable: Failed to get extents for requested @seg
+ * OS errors converted to NFS errors
+ */fs/nfsd/blocklayout.c +4
-0+static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl)
I struggle to see what the point of the nfsd4_block_map_segment helpers is, as it seems to add no real value while making the code harder to follow.
fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 123
Quoted 4 lines
fs/nfsd/blocklayout.c +4
-0+{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr;
Nit: nfserr can be local in the loop.
The subextent handling confuses me a bit - there is no such thing as a subsegment in NFS. I'd pass a never changing end of layout, a moving offset, and a constant iomode directly, which should simply the code quite a bit, i.e. something like:
u64 map_start = seg->offset;
u64 seg_end = seg->offset + seg->len;
for (..) {
nfserr = nfsd4_block_map_extent(inode, fhp, ...
map_start, &end);
if (end > seg_end) {
bl->nr_extents = i + 1;
break;
}
map_start = end;
}fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 155
Quoted 8 lines
fs/nfsd/blocklayout.c +8
-0+nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, + const struct svc_fh *fhp, struct nfsd4_layoutget *args) +{ + struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ;
Where is that -1 coming from? Or the magic PAGE_SIZE?
Quoted 10 lines · Christoph Hellwig
The subject line is odd. What is impl supposed to mean?
I'd say something like:
nfsd/blocklayout: support multiple extent per LAYOUTGET
Quoted 1 line · Sergey Bashirov
This patch allows the pNFS server to respond with multiple extents
This patch is redundant and should generally be avoided in commit log.
To put this another way, the patch description should explain "why" you want this change -- what's the benefit going to be. And maybe a little "how" it is done, if that isn't obvious from the diff.
Quoted 26 lines
Quoted 3 lines
Signed-off-by Sergey Bashirov <[email protected]>---
Checked with smatch, tested on pNFS block volume setup.Any chance we could get testing for this added to pynfs?
Also what is this patch against? If fails to apply to linux-next for me.
Quoted 12 lines
+/**
+ *nfsd4_block_map_extent- get extent that covers the start of segment
+ * @inode: inode of the file requested by the client
+ * @fhp: handle of the file requested by the client
+ * @seg: layout subrange requested by the client
+ * @minlength: layout min length requested by the client
+ * @bex: output block extent structure
+ *
+ * Get an extent from the file system that starts at @seg->offset or below,
+ * but may be shorter than @seg->length.
+ *
+ * Return values:Quoted 4 lines
+ * %nfs_ok: Success, @bex is initialized and valid + * %nfserr_layoutunavailable: Failed to get extent for requested @seg + * OS errors converted to NFS errors+ */
Quoted 5 lines
I'm not sure how Chuck handles this, but kerneldoc comments for static functions and thus not as public documentation can be really annoying due to the verbose formatting of the paramters. I'd generally avoid them and instead of have short comments explaining the interesting bits about the calling convention and/or functionality.
For NFSD, the tradition is to avoid kdoc comments for static functions unless they are the target of a virtual function call.
Static functions otherwise can have big comments. Just not kdoc style.
Quoted 75 lines
Quoted 7 lines
fs/nfsd/blocklayout.c +3
-0+nfsd4_block_map_extent(struct inode *inode, const struct svc_fh *fhp, + const struct nfsd4_layout_seg *seg, u64 minlength, + struct pnfs_block_extent *bex) { struct super_block *sb = inode->i_sb;struct iomap iomap;u32 device_generation =0 ;fs/nfsd/blocklayout.c line 39
Quoted 10 lines
fs/nfsd/blocklayout.c +0
-8int error; -if (locks_in_grace (SVC_NET (rqstp))) -return nfserr_grace; - -if (seg->offset & (block_size -1 )) { -dprintk ("pnfsd: I/O misaligned\n" ); - goto out_layoutunavailable; - } -There is a lot of code movement here mixed with functional changes, which makes it very hard to follow. Any chance you could first split the functions, then introduce the new
pnfs_block_layoutstructure and only then actually add multiple extents per layoutget? That'll make it a lot easier there are no unintended changes.fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 119
Quoted 7 lines
+ * %nfserr_layoutunavailable: Failed to get extents for requested @seg
+ * OS errors converted to NFS errors
+ */fs/nfsd/blocklayout.c +4
-0+static __be32 +nfsd4_block_map_segment (struct inode *inode,const struct svc_fh *fhp, +const struct nfsd4_layout_seg *seg,u64 minlength, +struct pnfs_block_layout *bl)I struggle to see what the point of the
nfsd4_block_map_segmenthelpers is, as it seems to add no real value while making the code harder to follow.fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 123
Quoted 4 lines
fs/nfsd/blocklayout.c +4
-0+{ +struct nfsd4_layout_seg subseg = *seg; +u32 i; +__be32 nfserr;Nit: nfserr can be local in the loop.
The subextent handling confuses me a bit - there is no such thing as a subsegment in NFS. I'd pass a never changing end of layout, a moving offset, and a constant iomode directly, which should simply the code quite a bit, i.e. something like:
u64 map_start = seg->offset; u64 seg_end = seg->offset + seg->len; for (..) { nfserr = nfsd4_block_map_extent(inode, fhp, ... map_start, &end); if (end > seg_end) { bl->nr_extents = i + 1; break; } map_start = end; }fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 155
Quoted 8 lines
fs/nfsd/blocklayout.c +8
-0+nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, + const struct svc_fh *fhp, struct nfsd4_layoutget *args) +{ + struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ;Where is that -1 coming from? Or the magic
PAGE_SIZE?
Signature · 1 line
Chuck Lever
Quoted 5 lines · Christoph Hellwig
The subject line is odd. What is impl supposed to mean?
I'd say something like:
nfsd/blocklayout: support multiple extent per LAYOUTGET
Impl is short for implement. But let's rephrase that if it looks odd.
Quoted 4 lines · Sergey Bashirov
Quoted 1 line
Checked with smatch, tested on pNFS block volume setup.
Any chance we could get testing for this added to pynfs?
Thanks for pointing out pynfs! I'm not familiar with it yet, but adding tests is a good idea. Will take a look on it.
Quoted 2 lines
Also what is this patch against? If fails to apply to linux-next for me.
At the time of submission, the patch was made on top of nfsd-testing.
Quoted 5 lines
There is a lot of code movement here mixed with functional changes, which makes it very hard to follow. Any chance you could first split the functions, then introduce the new
pnfs_block_layoutstructure and only then actually add multiple extents per layoutget? That'll make it a lot easier there are no unintended changes.
Agree. I will try to refactor or split the patch to reduce unnecessary code movement produced by diff tool.
Quoted 3 lines
I struggle to see what the point of the
nfsd4_block_map_segmenthelpers is, as it seems to add no real value while making the code harder to follow
The main idea of nfsd4_block_map_segment is to logically separate work with XFS, handling single extent, from the loop through the pnfs_block_layout structure across all extents. If we combine nfsd4_block_map_segment and nfsd4_block_map_extent, the switch statement will end up inside the for loop, which will result in a large code movement in diff due to the right shifts and line breaks.
Quoted 4 lines
The subextent handling confuses me a bit - there is no such thing as a subsegment in NFS. I'd pass a never changing end of layout, a moving offset, and a constant iomode directly, which should simply the code quite a bit, i.e. something like:
You are right, subsegment here simply means a smaller portion of the original requested segment and is not related to NFS structures or specification. Actually, I first made a version with three separate arguments. But then reworked it to reduce the number of arguments in the nfsd4_block_map_extent function. I am ok with any option, let's pass three variables without using structure.
Quoted 10 lines
fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, · line 155
Quoted 8 lines
fs/nfsd/blocklayout.c +8
-0+nfsd4_block_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode, + const struct svc_fh *fhp, struct nfsd4_layoutget *args) +{ + struct nfsd4_layout_seg *seg = &args->lg_seg; +u64 seg_length; +struct pnfs_block_extent *first_bex, *last_bex; +struct pnfs_block_layout *bl; +u32 nr_extents_max =PAGE_SIZE /sizeof (bl->extents[0 ]) -1 ;Where is that -1 coming from? Or the magic
PAGE_SIZE?
PAGE_SIZE is the maximum possible size of the pnfs_block_layout structure in the server's memory that we would like to have. And -1 ensures that the nr_extents field will also fit in it
if PAGE_SIZE % sizeof(struct pnfs_block_extent) == 0.
Yes, it would be nice to add a comment in the code, or even better, an inline function that calculates the number of extents in a given memory limit for the pnfs_block_layout structure.
I will prepare new patch(es).
--
Sergey Bashirov