Skip to content

Commit a11ada9

Browse files
committed
NFSD: Move copy offload callback arguments into a separate structure
Refactor so that CB_OFFLOAD arguments can be passed without allocating a whole struct nfsd4_copy object. On my system (x86_64) this removes another 96 bytes from struct nfsd4_copy. Signed-off-by: Chuck Lever <[email protected]>
1 parent e72f9bc commit a11ada9

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp,
679679
* case NFS4_OK:
680680
* write_response4 coa_resok4;
681681
* default:
682-
* length4 coa_bytes_copied;
682+
* length4 coa_bytes_copied;
683683
* };
684684
* struct CB_OFFLOAD4args {
685685
* nfs_fh4 coa_fh;
@@ -688,40 +688,39 @@ static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp,
688688
* };
689689
*/
690690
static void encode_offload_info4(struct xdr_stream *xdr,
691-
__be32 nfserr,
692-
const struct nfsd4_copy *cp)
691+
const struct nfsd4_cb_offload *cbo)
693692
{
694693
__be32 *p;
695694

696695
p = xdr_reserve_space(xdr, 4);
697-
*p++ = nfserr;
698-
if (!nfserr) {
696+
*p = cbo->co_nfserr;
697+
switch (cbo->co_nfserr) {
698+
case nfs_ok:
699699
p = xdr_reserve_space(xdr, 4 + 8 + 4 + NFS4_VERIFIER_SIZE);
700700
p = xdr_encode_empty_array(p);
701-
p = xdr_encode_hyper(p, cp->cp_res.wr_bytes_written);
702-
*p++ = cpu_to_be32(cp->cp_res.wr_stable_how);
703-
p = xdr_encode_opaque_fixed(p, cp->cp_res.wr_verifier.data,
701+
p = xdr_encode_hyper(p, cbo->co_res.wr_bytes_written);
702+
*p++ = cpu_to_be32(cbo->co_res.wr_stable_how);
703+
p = xdr_encode_opaque_fixed(p, cbo->co_res.wr_verifier.data,
704704
NFS4_VERIFIER_SIZE);
705-
} else {
705+
break;
706+
default:
706707
p = xdr_reserve_space(xdr, 8);
707708
/* We always return success if bytes were written */
708709
p = xdr_encode_hyper(p, 0);
709710
}
710711
}
711712

712713
static void encode_cb_offload4args(struct xdr_stream *xdr,
713-
__be32 nfserr,
714-
const struct knfsd_fh *fh,
715-
const struct nfsd4_copy *cp,
714+
const struct nfsd4_cb_offload *cbo,
716715
struct nfs4_cb_compound_hdr *hdr)
717716
{
718717
__be32 *p;
719718

720719
p = xdr_reserve_space(xdr, 4);
721-
*p++ = cpu_to_be32(OP_CB_OFFLOAD);
722-
encode_nfs_fh4(xdr, fh);
723-
encode_stateid4(xdr, &cp->cp_res.cb_stateid);
724-
encode_offload_info4(xdr, nfserr, cp);
720+
*p = cpu_to_be32(OP_CB_OFFLOAD);
721+
encode_nfs_fh4(xdr, &cbo->co_fh);
722+
encode_stateid4(xdr, &cbo->co_res.cb_stateid);
723+
encode_offload_info4(xdr, cbo);
725724

726725
hdr->nops++;
727726
}
@@ -731,16 +730,16 @@ static void nfs4_xdr_enc_cb_offload(struct rpc_rqst *req,
731730
const void *data)
732731
{
733732
const struct nfsd4_callback *cb = data;
734-
const struct nfsd4_copy *cp =
735-
container_of(cb, struct nfsd4_copy, cp_cb);
733+
const struct nfsd4_cb_offload *cbo =
734+
container_of(cb, struct nfsd4_cb_offload, co_cb);
736735
struct nfs4_cb_compound_hdr hdr = {
737736
.ident = 0,
738737
.minorversion = cb->cb_clp->cl_minorversion,
739738
};
740739

741740
encode_cb_compound4args(xdr, &hdr);
742741
encode_cb_sequence4args(xdr, cb, &hdr);
743-
encode_cb_offload4args(xdr, cp->nfserr, &cp->fh, cp, &hdr);
742+
encode_cb_offload4args(xdr, cbo, &hdr);
744743
encode_cb_nops(&hdr);
745744
}
746745

fs/nfsd/nfs4proc.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,10 @@ nfsd4_cleanup_intra_ssc(struct nfsd_file *src, struct nfsd_file *dst)
16451645

16461646
static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
16471647
{
1648-
struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
1648+
struct nfsd4_cb_offload *cbo =
1649+
container_of(cb, struct nfsd4_cb_offload, co_cb);
16491650

1650-
nfs4_put_copy(copy);
1651+
kfree(cbo);
16511652
}
16521653

16531654
static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
@@ -1763,25 +1764,23 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
17631764
nfs4_put_copy(copy);
17641765
}
17651766

1766-
static void nfsd4_send_cb_offload(struct nfsd4_copy *copy)
1767+
static void nfsd4_send_cb_offload(struct nfsd4_copy *copy, __be32 nfserr)
17671768
{
1768-
struct nfsd4_copy *cb_copy;
1769+
struct nfsd4_cb_offload *cbo;
17691770

1770-
cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
1771-
if (!cb_copy)
1771+
cbo = kzalloc(sizeof(*cbo), GFP_KERNEL);
1772+
if (!cbo)
17721773
return;
17731774

1774-
refcount_set(&cb_copy->refcount, 1);
1775-
memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
1776-
cb_copy->cp_clp = copy->cp_clp;
1777-
cb_copy->nfserr = copy->nfserr;
1778-
memcpy(&cb_copy->fh, &copy->fh, sizeof(copy->fh));
1775+
memcpy(&cbo->co_res, &copy->cp_res, sizeof(copy->cp_res));
1776+
memcpy(&cbo->co_fh, &copy->fh, sizeof(copy->fh));
1777+
cbo->co_nfserr = nfserr;
17791778

1780-
nfsd4_init_cb(&cb_copy->cp_cb, cb_copy->cp_clp,
1781-
&nfsd4_cb_offload_ops, NFSPROC4_CLNT_CB_OFFLOAD);
1782-
trace_nfsd_cb_offload(copy->cp_clp, &copy->cp_res.cb_stateid,
1783-
&copy->fh, copy->cp_count, copy->nfserr);
1784-
nfsd4_run_cb(&cb_copy->cp_cb);
1779+
nfsd4_init_cb(&cbo->co_cb, copy->cp_clp, &nfsd4_cb_offload_ops,
1780+
NFSPROC4_CLNT_CB_OFFLOAD);
1781+
trace_nfsd_cb_offload(copy->cp_clp, &cbo->co_res.cb_stateid,
1782+
&cbo->co_fh, copy->cp_count, nfserr);
1783+
nfsd4_run_cb(&cbo->co_cb);
17851784
}
17861785

17871786
/**
@@ -1794,28 +1793,29 @@ static void nfsd4_send_cb_offload(struct nfsd4_copy *copy)
17941793
static int nfsd4_do_async_copy(void *data)
17951794
{
17961795
struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
1796+
__be32 nfserr;
17971797

17981798
if (nfsd4_ssc_is_inter(copy)) {
17991799
struct file *filp;
18001800

18011801
filp = nfs42_ssc_open(copy->ss_mnt, &copy->c_fh,
18021802
&copy->stateid);
18031803
if (IS_ERR(filp)) {
1804-
copy->nfserr = nfserr_offload_denied;
1804+
nfserr = nfserr_offload_denied;
18051805
nfsd4_interssc_disconnect(copy->ss_mnt);
18061806
goto do_callback;
18071807
}
1808-
copy->nfserr = nfsd4_do_copy(copy, filp,
1809-
copy->nf_dst->nf_file, false);
1808+
nfserr = nfsd4_do_copy(copy, filp, copy->nf_dst->nf_file,
1809+
false);
18101810
nfsd4_cleanup_inter_ssc(copy->ss_mnt, filp, copy->nf_dst);
18111811
} else {
1812-
copy->nfserr = nfsd4_do_copy(copy, copy->nf_src->nf_file,
1813-
copy->nf_dst->nf_file, false);
1812+
nfserr = nfsd4_do_copy(copy, copy->nf_src->nf_file,
1813+
copy->nf_dst->nf_file, false);
18141814
nfsd4_cleanup_intra_ssc(copy->nf_src, copy->nf_dst);
18151815
}
18161816

18171817
do_callback:
1818-
nfsd4_send_cb_offload(copy);
1818+
nfsd4_send_cb_offload(copy, nfserr);
18191819
cleanup_async_copy(copy);
18201820
return 0;
18211821
}

fs/nfsd/xdr4.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ struct nfsd42_write_res {
533533
stateid_t cb_stateid;
534534
};
535535

536+
struct nfsd4_cb_offload {
537+
struct nfsd4_callback co_cb;
538+
struct nfsd42_write_res co_res;
539+
__be32 co_nfserr;
540+
struct knfsd_fh co_fh;
541+
};
542+
536543
struct nfsd4_copy {
537544
/* request */
538545
stateid_t cp_src_stateid;
@@ -550,10 +557,6 @@ struct nfsd4_copy {
550557

551558
/* response */
552559
struct nfsd42_write_res cp_res;
553-
554-
/* for cb_offload */
555-
struct nfsd4_callback cp_cb;
556-
__be32 nfserr;
557560
struct knfsd_fh fh;
558561

559562
struct nfs4_client *cp_clp;

0 commit comments

Comments
 (0)