NFSD: Disallow layoutget during grace period
Subsystems (3)
PATCH v2 1/1 NFSD: Disallow layoutget during grace period
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
---
Changes in v2:
- Push down the check to layout driver level
fs/nfsd/blocklayout.c | 8 +++++++- fs/nfsd/flexfilelayout.c | 2 +- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/pnfs.h | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-)
fs/nfsd/blocklayout.c +7 -1
@@ -19,7 +19,7 @@static __be32 nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;
@@ -34,6 +34,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, goto out_layoutunavailable; } +if (in_grace) + goto out_grace; +/* * Some clients barf on non-zero block numbers for NONE or INVALID * layouts, so make sure to zero the whole structure.
@@ -111,6 +114,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, out_layoutunavailable: seg->length =0 ;return nfserr_layoutunavailable; +out_grace: + seg->length =0 ; +return nfserr_grace; } static __be32
fs/nfsd/flexfilelayout.c +1 -1
@@ -21,7 +21,7 @@static __be32 nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;
fs/nfsd/nfs4proc.c +2 -1
@@ -2435,6 +2435,7 @@ static __be32 nfsd4_layoutget(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { + struct net *net = SVC_NET(rqstp);struct nfsd4_layoutget *lgp = &u->layoutget;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops;
@@ -2498,7 +2499,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, goto out_put_stid; nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), - current_fh, lgp); + current_fh, lgp,locks_in_grace (net));if (nfserr) goto out_put_stid;
fs/nfsd/pnfs.h +1 -1
@@ -30,7 +30,7 @@ struct nfsd4_layout_ops { const struct nfsd4_getdeviceinfo *gdevp);__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +struct nfsd4_layoutget *lgp,bool in_grace);__be32 (*encode_layoutget)(struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp);
Signature · 1 line
2.43.0
Quoted 7 lines · Sergey Bashirov
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
Looks good:
Quoted 93 lines · Sergey Bashirov
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
Co-developed-by Konstantin Evtushenko <[email protected]>Signed-off-by Konstantin Evtushenko <[email protected]>Signed-off-by Sergey Bashirov <[email protected]>---
Changes in v2:
- Push down the check to layout driver levelfs/nfsd/blocklayout.c | 8 +++++++- fs/nfsd/flexfilelayout.c | 2 +- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/pnfs.h | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-)fs/nfsd/blocklayout.c +7
-1@@ -19,7 +19,7 @@static __be32 nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;@@ -34,6 +34,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, goto out_layoutunavailable; } +if (in_grace) + goto out_grace; +/* * Some clients barf on non-zero block numbers for NONE or INVALID * layouts, so make sure to zero the whole structure. @@ -111,6 +114,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, out_layoutunavailable: seg->length =0 ;return nfserr_layoutunavailable; +out_grace: + seg->length =0 ; +return nfserr_grace; } static __be32fs/nfsd/flexfilelayout.c +1
-1@@ -21,7 +21,7 @@static __be32 nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;fs/nfsd/nfs4proc.c +2
-1@@ -2435,6 +2435,7 @@ static __be32 nfsd4_layoutget(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { + struct net *net = SVC_NET(rqstp);struct nfsd4_layoutget *lgp = &u->layoutget;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops;@@ -2498,7 +2499,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, goto out_put_stid; nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), - current_fh, lgp); + current_fh, lgp,locks_in_grace (net));if (nfserr) goto out_put_stid;fs/nfsd/pnfs.h +0
-0
fs/nfsd/pnfs.h struct nfsd4_layout_ops { · line 36
Quoted 8 lines
fs/nfsd/pnfs.h +1
-1@@ -30,7 +30,7 @@ struct nfsd4_layout_ops { const struct nfsd4_getdeviceinfo *gdevp);__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +struct nfsd4_layoutget *lgp,bool in_grace);__be32 (*encode_layoutget)(struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp);
Quoted 35 lines · Sergey Bashirov
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
Co-developed-by Konstantin Evtushenko <[email protected]>Signed-off-by Konstantin Evtushenko <[email protected]>Signed-off-by Sergey Bashirov <[email protected]>---
Changes in v2:
- Push down the check to layout driver levelfs/nfsd/blocklayout.c | 8 +++++++- fs/nfsd/flexfilelayout.c | 2 +- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/pnfs.h | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-)fs/nfsd/blocklayout.c +1
-1@@ -19,7 +19,7 @@static __be32 nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;
fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, · line 38
Quoted 5 lines
fs/nfsd/blocklayout.c +2
-0@@ -34,6 +34,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, goto out_layoutunavailable; } +if (in_grace) + goto out_grace;
Taste/style nit:
I prefer that the controlling svc_rqst is passed to ->proc_layoutget, rather than passing a boolean. The ff layout can just ignore that new parameter, and the block layout can deref the network namespace and do the locks_in_grace check.
Quoted 61 lines
fs/nfsd/blocklayout.c +4
-0+/* * Some clients barf on non-zero block numbers for NONE or INVALID * layouts, so make sure to zero the whole structure. @@ -111,6 +114,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, out_layoutunavailable: seg->length =0 ;return nfserr_layoutunavailable; +out_grace: + seg->length =0 ; +return nfserr_grace; } static __be32fs/nfsd/flexfilelayout.c +1
-1@@ -21,7 +21,7 @@static __be32 nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;fs/nfsd/nfs4proc.c +2
-1@@ -2435,6 +2435,7 @@ static __be32 nfsd4_layoutget(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { + struct net *net = SVC_NET(rqstp);struct nfsd4_layoutget *lgp = &u->layoutget;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops;@@ -2498,7 +2499,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, goto out_put_stid; nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), - current_fh, lgp); + current_fh, lgp,locks_in_grace (net));if (nfserr) goto out_put_stid;fs/nfsd/pnfs.h +1
-1@@ -30,7 +30,7 @@ struct nfsd4_layout_ops { const struct nfsd4_getdeviceinfo *gdevp);__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +struct nfsd4_layoutget *lgp,bool in_grace);__be32 (*encode_layoutget)(struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp);
Signature · 1 line
Chuck Lever
Quoted 44 lines · Chuck Lever
Quoted 35 lines · Sergey Bashirov
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
Co-developed-by Konstantin Evtushenko <[email protected]>Signed-off-by Konstantin Evtushenko <[email protected]>Signed-off-by Sergey Bashirov <[email protected]>---
Changes in v2:
- Push down the check to layout driver levelfs/nfsd/blocklayout.c | 8 +++++++- fs/nfsd/flexfilelayout.c | 2 +- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/pnfs.h | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-)fs/nfsd/blocklayout.c +1
-1@@ -19,7 +19,7 @@static __be32 nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, · line 38
Quoted 5 lines
fs/nfsd/blocklayout.c +2
-0@@ -34,6 +34,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, goto out_layoutunavailable; } +if (in_grace) + goto out_grace;Taste/style nit:
Quoted 4 lines
I prefer that the controlling
svc_rqstis passed to ->proc_layoutget, rather than passing a boolean. The ff layout can just ignore that new parameter, and the block layout can deref the network namespace and do thelocks_in_gracecheck.
Never mind. I will take v2 as is and fix this up myself.
Quoted 63 lines
Quoted 61 lines
fs/nfsd/blocklayout.c +4
-0+/* * Some clients barf on non-zero block numbers for NONE or INVALID * layouts, so make sure to zero the whole structure. @@ -111,6 +114,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, out_layoutunavailable: seg->length =0 ;return nfserr_layoutunavailable; +out_grace: + seg->length =0 ; +return nfserr_grace; } static __be32fs/nfsd/flexfilelayout.c +1
-1@@ -21,7 +21,7 @@static __be32 nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;fs/nfsd/nfs4proc.c +2
-1@@ -2435,6 +2435,7 @@ static __be32 nfsd4_layoutget(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { + struct net *net = SVC_NET(rqstp);struct nfsd4_layoutget *lgp = &u->layoutget;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops;@@ -2498,7 +2499,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, goto out_put_stid; nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), - current_fh, lgp); + current_fh, lgp,locks_in_grace (net));if (nfserr) goto out_put_stid;fs/nfsd/pnfs.h +1
-1@@ -30,7 +30,7 @@ struct nfsd4_layout_ops { const struct nfsd4_getdeviceinfo *gdevp);__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +struct nfsd4_layoutget *lgp,bool in_grace);__be32 (*encode_layoutget)(struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp);
Signature · 1 line
Chuck Lever
Quoted 45 lines · Sergey Bashirov
When the block/scsi layout server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.
If multiple clients write data to the same file, rebooting the server during writing can result in the file corruption. Observed this behavior while testing pNFS block volume setup.
Co-developed-by Konstantin Evtushenko <[email protected]>Signed-off-by Konstantin Evtushenko <[email protected]>Signed-off-by Sergey Bashirov <[email protected]>---
Changes in v2:
- Push down the check to layout driver levelfs/nfsd/blocklayout.c | 8 +++++++- fs/nfsd/flexfilelayout.c | 2 +- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/pnfs.h | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-)fs/nfsd/blocklayout.c +4
-1@@ -19,7 +19,7 @@static __be32 nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;@@ -34,6 +34,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, goto out_layoutunavailable; } +if (in_grace) + goto out_grace; +/* * Some clients barf on non-zero block numbers for NONE or INVALID * layouts, so make sure to zero the whole structure.
fs/nfsd/blocklayout.c nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, · line 119
Quoted 6 lines
fs/nfsd/blocklayout.c +3
-0@@ -111,6 +114,9 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, out_layoutunavailable: seg->length =0 ;return nfserr_layoutunavailable; +out_grace: + seg->length =0 ; +return nfserr_grace;
Also setting the seg->length to zero is probably unnecessary:
union LAYOUTGET4res switch (nfsstat4 logr_status) { case NFS4_OK:
LAYOUTGET4resok logr_resok4;
case NFS4ERR_LAYOUTTRYLATER:
bool logr_will_signal_layout_avail;
default:
void;
};Is the segment length value used at all if ->proc_layoutget returns NFS4ERR_GRACE ?
Quoted 50 lines
fs/nfsd/blocklayout.c +0
-0} static __be32fs/nfsd/flexfilelayout.c +1
-1@@ -21,7 +21,7 @@static __be32 nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +struct nfsd4_layoutget *args,bool in_grace) {struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;fs/nfsd/nfs4proc.c +2
-1@@ -2435,6 +2435,7 @@ static __be32 nfsd4_layoutget(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { + struct net *net = SVC_NET(rqstp);struct nfsd4_layoutget *lgp = &u->layoutget;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops;@@ -2498,7 +2499,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, goto out_put_stid; nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), - current_fh, lgp); + current_fh, lgp,locks_in_grace (net));if (nfserr) goto out_put_stid;fs/nfsd/pnfs.h +1
-1@@ -30,7 +30,7 @@ struct nfsd4_layout_ops { const struct nfsd4_getdeviceinfo *gdevp);__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +struct nfsd4_layoutget *lgp,bool in_grace);__be32 (*encode_layoutget)(struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp);
Signature · 1 line
Chuck Lever