Skip to content

Commit 1913cdf

Browse files
committed
NFSD: Replace boolean fields in struct nfsd4_copy
Clean up: saves 8 bytes, and we can replace check_and_set_stop_copy() with an atomic bitop. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 8ea6e2c commit 1913cdf

File tree

3 files changed

+53
-43
lines changed

3 files changed

+53
-43
lines changed

fs/nfsd/nfs4proc.c

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,23 +1293,9 @@ static void nfs4_put_copy(struct nfsd4_copy *copy)
12931293
kfree(copy);
12941294
}
12951295

1296-
static bool
1297-
check_and_set_stop_copy(struct nfsd4_copy *copy)
1298-
{
1299-
bool value;
1300-
1301-
spin_lock(&copy->cp_clp->async_lock);
1302-
value = copy->stopped;
1303-
if (!copy->stopped)
1304-
copy->stopped = true;
1305-
spin_unlock(&copy->cp_clp->async_lock);
1306-
return value;
1307-
}
1308-
13091296
static void nfsd4_stop_copy(struct nfsd4_copy *copy)
13101297
{
1311-
/* only 1 thread should stop the copy */
1312-
if (!check_and_set_stop_copy(copy))
1298+
if (!test_and_set_bit(NFSD4_COPY_F_STOPPED, &copy->cp_flags))
13131299
kthread_stop(copy->copy_task);
13141300
nfs4_put_copy(copy);
13151301
}
@@ -1678,8 +1664,9 @@ static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
16781664
static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
16791665
{
16801666
copy->cp_res.wr_stable_how =
1681-
copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE;
1682-
copy->cp_synchronous = sync;
1667+
test_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags) ?
1668+
NFS_FILE_SYNC : NFS_UNSTABLE;
1669+
nfsd4_copy_set_sync(copy, sync);
16831670
gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
16841671
}
16851672

@@ -1708,16 +1695,16 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
17081695
copy->cp_res.wr_bytes_written += bytes_copied;
17091696
src_pos += bytes_copied;
17101697
dst_pos += bytes_copied;
1711-
} while (bytes_total > 0 && !copy->cp_synchronous);
1698+
} while (bytes_total > 0 && nfsd4_copy_is_async(copy));
17121699
/* for a non-zero asynchronous copy do a commit of data */
1713-
if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) {
1700+
if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) {
17141701
since = READ_ONCE(dst->f_wb_err);
17151702
status = vfs_fsync_range(dst, copy->cp_dst_pos,
17161703
copy->cp_res.wr_bytes_written, 0);
17171704
if (!status)
17181705
status = filemap_check_wb_err(dst->f_mapping, since);
17191706
if (!status)
1720-
copy->committed = true;
1707+
set_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags);
17211708
}
17221709
return bytes_copied;
17231710
}
@@ -1738,7 +1725,7 @@ static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
17381725
status = nfs_ok;
17391726
}
17401727

1741-
if (!copy->cp_intra) /* Inter server SSC */
1728+
if (nfsd4_ssc_is_inter(copy))
17421729
nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
17431730
copy->nf_dst);
17441731
else
@@ -1752,13 +1739,13 @@ static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
17521739
dst->cp_src_pos = src->cp_src_pos;
17531740
dst->cp_dst_pos = src->cp_dst_pos;
17541741
dst->cp_count = src->cp_count;
1755-
dst->cp_synchronous = src->cp_synchronous;
1742+
dst->cp_flags = src->cp_flags;
17561743
memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
17571744
memcpy(&dst->fh, &src->fh, sizeof(src->fh));
17581745
dst->cp_clp = src->cp_clp;
17591746
dst->nf_dst = nfsd_file_get(src->nf_dst);
1760-
dst->cp_intra = src->cp_intra;
1761-
if (src->cp_intra) /* for inter, file_src doesn't exist yet */
1747+
/* for inter, nf_src doesn't exist yet */
1748+
if (!nfsd4_ssc_is_inter(src))
17621749
dst->nf_src = nfsd_file_get(src->nf_src);
17631750

17641751
memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
@@ -1772,7 +1759,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
17721759
{
17731760
nfs4_free_copy_state(copy);
17741761
nfsd_file_put(copy->nf_dst);
1775-
if (copy->cp_intra)
1762+
if (!nfsd4_ssc_is_inter(copy))
17761763
nfsd_file_put(copy->nf_src);
17771764
spin_lock(&copy->cp_clp->async_lock);
17781765
list_del(&copy->copies);
@@ -1785,7 +1772,7 @@ static int nfsd4_do_async_copy(void *data)
17851772
struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
17861773
struct nfsd4_copy *cb_copy;
17871774

1788-
if (!copy->cp_intra) { /* Inter server SSC */
1775+
if (nfsd4_ssc_is_inter(copy)) {
17891776
copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
17901777
if (!copy->nf_src) {
17911778
copy->nfserr = nfserr_serverfault;
@@ -1817,7 +1804,7 @@ static int nfsd4_do_async_copy(void *data)
18171804
&copy->fh, copy->cp_count, copy->nfserr);
18181805
nfsd4_run_cb(&cb_copy->cp_cb);
18191806
out:
1820-
if (!copy->cp_intra)
1807+
if (nfsd4_ssc_is_inter(copy))
18211808
kfree(copy->nf_src);
18221809
cleanup_async_copy(copy);
18231810
return 0;
@@ -1831,8 +1818,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
18311818
__be32 status;
18321819
struct nfsd4_copy *async_copy = NULL;
18331820

1834-
if (!copy->cp_intra) { /* Inter server SSC */
1835-
if (!inter_copy_offload_enable || copy->cp_synchronous) {
1821+
if (nfsd4_ssc_is_inter(copy)) {
1822+
if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) {
18361823
status = nfserr_notsupp;
18371824
goto out;
18381825
}
@@ -1849,7 +1836,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
18491836
copy->cp_clp = cstate->clp;
18501837
memcpy(&copy->fh, &cstate->current_fh.fh_handle,
18511838
sizeof(struct knfsd_fh));
1852-
if (!copy->cp_synchronous) {
1839+
if (nfsd4_copy_is_async(copy)) {
18531840
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
18541841

18551842
status = nfserrno(-ENOMEM);
@@ -1884,7 +1871,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
18841871
if (async_copy)
18851872
cleanup_async_copy(async_copy);
18861873
status = nfserrno(-ENOMEM);
1887-
if (!copy->cp_intra)
1874+
if (nfsd4_ssc_is_inter(copy))
18881875
nfsd4_interssc_disconnect(copy->ss_mnt);
18891876
goto out;
18901877
}
@@ -2613,7 +2600,7 @@ check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
26132600
return;
26142601
}
26152602
putfh = (struct nfsd4_putfh *)&saved_op->u;
2616-
if (!copy->cp_intra)
2603+
if (nfsd4_ssc_is_inter(copy))
26172604
putfh->no_verify = true;
26182605
}
26192606
}

fs/nfsd/nfs4xdr.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,8 @@ static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp,
18961896
static __be32
18971897
nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
18981898
{
1899+
u32 consecutive, i, count, sync;
18991900
struct nl4_server *ns_dummy;
1900-
u32 consecutive, i, count;
19011901
__be32 status;
19021902

19031903
status = nfsd4_decode_stateid4(argp, &copy->cp_src_stateid);
@@ -1915,17 +1915,17 @@ nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
19151915
/* ca_consecutive: we always do consecutive copies */
19161916
if (xdr_stream_decode_u32(argp->xdr, &consecutive) < 0)
19171917
return nfserr_bad_xdr;
1918-
if (xdr_stream_decode_u32(argp->xdr, &copy->cp_synchronous) < 0)
1918+
if (xdr_stream_decode_bool(argp->xdr, &sync) < 0)
19191919
return nfserr_bad_xdr;
1920+
nfsd4_copy_set_sync(copy, sync);
19201921

19211922
if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
19221923
return nfserr_bad_xdr;
19231924
copy->cp_src = svcxdr_tmpalloc(argp, sizeof(*copy->cp_src));
19241925
if (copy->cp_src == NULL)
19251926
return nfserr_jukebox;
1926-
copy->cp_intra = false;
19271927
if (count == 0) { /* intra-server copy */
1928-
copy->cp_intra = true;
1928+
__set_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
19291929
return nfs_ok;
19301930
}
19311931

@@ -4704,13 +4704,13 @@ nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
47044704
__be32 *p;
47054705

47064706
nfserr = nfsd42_encode_write_res(resp, &copy->cp_res,
4707-
!!copy->cp_synchronous);
4707+
nfsd4_copy_is_sync(copy));
47084708
if (nfserr)
47094709
return nfserr;
47104710

47114711
p = xdr_reserve_space(resp->xdr, 4 + 4);
47124712
*p++ = xdr_one; /* cr_consecutive */
4713-
*p++ = cpu_to_be32(copy->cp_synchronous);
4713+
*p = nfsd4_copy_is_sync(copy) ? xdr_one : xdr_zero;
47144714
return 0;
47154715
}
47164716

fs/nfsd/xdr4.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,12 @@ struct nfsd4_copy {
541541
u64 cp_dst_pos;
542542
u64 cp_count;
543543
struct nl4_server *cp_src;
544-
bool cp_intra;
545544

546-
/* both */
547-
u32 cp_synchronous;
545+
unsigned long cp_flags;
546+
#define NFSD4_COPY_F_STOPPED (0)
547+
#define NFSD4_COPY_F_INTRA (1)
548+
#define NFSD4_COPY_F_SYNCHRONOUS (2)
549+
#define NFSD4_COPY_F_COMMITTED (3)
548550

549551
/* response */
550552
struct nfsd42_write_res cp_res;
@@ -564,14 +566,35 @@ struct nfsd4_copy {
564566
struct list_head copies;
565567
struct task_struct *copy_task;
566568
refcount_t refcount;
567-
bool stopped;
568569

569570
struct vfsmount *ss_mnt;
570571
struct nfs_fh c_fh;
571572
nfs4_stateid stateid;
572-
bool committed;
573573
};
574574

575+
static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync)
576+
{
577+
if (sync)
578+
set_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
579+
else
580+
clear_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
581+
}
582+
583+
static inline bool nfsd4_copy_is_sync(const struct nfsd4_copy *copy)
584+
{
585+
return test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
586+
}
587+
588+
static inline bool nfsd4_copy_is_async(const struct nfsd4_copy *copy)
589+
{
590+
return !test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
591+
}
592+
593+
static inline bool nfsd4_ssc_is_inter(const struct nfsd4_copy *copy)
594+
{
595+
return !test_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
596+
}
597+
575598
struct nfsd4_seek {
576599
/* request */
577600
stateid_t seek_stateid;

0 commit comments

Comments
 (0)