Skip to content

Commit a188620

Browse files
jtlaytonJ. Bruce Fields
authored andcommitted
nfsd: plumb in a CB_NOTIFY_LOCK operation
Add the encoding/decoding for CB_NOTIFY_LOCK operations. Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 1eca45f commit a188620

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,62 @@ static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp,
623623
}
624624
#endif /* CONFIG_NFSD_PNFS */
625625

626+
static void encode_stateowner(struct xdr_stream *xdr, struct nfs4_stateowner *so)
627+
{
628+
__be32 *p;
629+
630+
p = xdr_reserve_space(xdr, 8 + 4 + so->so_owner.len);
631+
p = xdr_encode_opaque_fixed(p, &so->so_client->cl_clientid, 8);
632+
xdr_encode_opaque(p, so->so_owner.data, so->so_owner.len);
633+
}
634+
635+
static void nfs4_xdr_enc_cb_notify_lock(struct rpc_rqst *req,
636+
struct xdr_stream *xdr,
637+
const struct nfsd4_callback *cb)
638+
{
639+
const struct nfsd4_blocked_lock *nbl =
640+
container_of(cb, struct nfsd4_blocked_lock, nbl_cb);
641+
struct nfs4_lockowner *lo = (struct nfs4_lockowner *)nbl->nbl_lock.fl_owner;
642+
struct nfs4_cb_compound_hdr hdr = {
643+
.ident = 0,
644+
.minorversion = cb->cb_clp->cl_minorversion,
645+
};
646+
647+
__be32 *p;
648+
649+
BUG_ON(hdr.minorversion == 0);
650+
651+
encode_cb_compound4args(xdr, &hdr);
652+
encode_cb_sequence4args(xdr, cb, &hdr);
653+
654+
p = xdr_reserve_space(xdr, 4);
655+
*p = cpu_to_be32(OP_CB_NOTIFY_LOCK);
656+
encode_nfs_fh4(xdr, &nbl->nbl_fh);
657+
encode_stateowner(xdr, &lo->lo_owner);
658+
hdr.nops++;
659+
660+
encode_cb_nops(&hdr);
661+
}
662+
663+
static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp,
664+
struct xdr_stream *xdr,
665+
struct nfsd4_callback *cb)
666+
{
667+
struct nfs4_cb_compound_hdr hdr;
668+
int status;
669+
670+
status = decode_cb_compound4res(xdr, &hdr);
671+
if (unlikely(status))
672+
return status;
673+
674+
if (cb) {
675+
status = decode_cb_sequence4res(xdr, cb);
676+
if (unlikely(status || cb->cb_seq_status))
677+
return status;
678+
}
679+
return decode_cb_op_status(xdr, OP_CB_NOTIFY_LOCK, &cb->cb_status);
680+
}
681+
626682
/*
627683
* RPC procedure tables
628684
*/
@@ -643,6 +699,7 @@ static struct rpc_procinfo nfs4_cb_procedures[] = {
643699
#ifdef CONFIG_NFSD_PNFS
644700
PROC(CB_LAYOUT, COMPOUND, cb_layout, cb_layout),
645701
#endif
702+
PROC(CB_NOTIFY_LOCK, COMPOUND, cb_notify_lock, cb_notify_lock),
646703
};
647704

648705
static struct rpc_version nfs_cb_version4 = {

fs/nfsd/state.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ enum nfsd4_cb_op {
571571
NFSPROC4_CLNT_CB_RECALL,
572572
NFSPROC4_CLNT_CB_LAYOUT,
573573
NFSPROC4_CLNT_CB_SEQUENCE,
574+
NFSPROC4_CLNT_CB_NOTIFY_LOCK,
574575
};
575576

576577
/* Returns true iff a is later than b: */
@@ -579,6 +580,12 @@ static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
579580
return (s32)(a->si_generation - b->si_generation) > 0;
580581
}
581582

583+
struct nfsd4_blocked_lock {
584+
struct file_lock nbl_lock;
585+
struct knfsd_fh nbl_fh;
586+
struct nfsd4_callback nbl_cb;
587+
};
588+
582589
struct nfsd4_compound_state;
583590
struct nfsd_net;
584591

fs/nfsd/xdr4cb.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@
2828
#define NFS4_dec_cb_layout_sz (cb_compound_dec_hdr_sz + \
2929
cb_sequence_dec_sz + \
3030
op_dec_sz)
31+
32+
#define NFS4_enc_cb_notify_lock_sz (cb_compound_enc_hdr_sz + \
33+
cb_sequence_enc_sz + \
34+
2 + 1 + \
35+
XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
36+
enc_nfs4_fh_sz)
37+
#define NFS4_dec_cb_notify_lock_sz (cb_compound_dec_hdr_sz + \
38+
cb_sequence_dec_sz + \
39+
op_dec_sz)

0 commit comments

Comments
 (0)