NFSD: Replace boolean fields in struct nfsd4_copy

[ Upstream commit 1913cdf56cb5bfbc8170873728d13598cbecda23 ]

Clean up: saves 8 bytes, and we can replace check_and_set_stop_copy()
with an atomic bitop.

[ cel: adjusted to apply to v5.10.y ]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Chuck Lever
2022-07-27 14:40:41 -04:00
committed by Greg Kroah-Hartman
parent 627b896c52
commit ac774e1eeb
3 changed files with 52 additions and 42 deletions

View File

@@ -1295,23 +1295,9 @@ static void nfs4_put_copy(struct nfsd4_copy *copy)
kfree(copy); kfree(copy);
} }
static bool
check_and_set_stop_copy(struct nfsd4_copy *copy)
{
bool value;
spin_lock(&copy->cp_clp->async_lock);
value = copy->stopped;
if (!copy->stopped)
copy->stopped = true;
spin_unlock(&copy->cp_clp->async_lock);
return value;
}
static void nfsd4_stop_copy(struct nfsd4_copy *copy) static void nfsd4_stop_copy(struct nfsd4_copy *copy)
{ {
/* only 1 thread should stop the copy */ if (!test_and_set_bit(NFSD4_COPY_F_STOPPED, &copy->cp_flags))
if (!check_and_set_stop_copy(copy))
kthread_stop(copy->copy_task); kthread_stop(copy->copy_task);
nfs4_put_copy(copy); nfs4_put_copy(copy);
} }
@@ -1668,8 +1654,9 @@ static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
{ {
copy->cp_res.wr_stable_how = copy->cp_res.wr_stable_how =
copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE; test_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags) ?
copy->cp_synchronous = sync; NFS_FILE_SYNC : NFS_UNSTABLE;
nfsd4_copy_set_sync(copy, sync);
gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net); gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
} }
@@ -1698,16 +1685,16 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
copy->cp_res.wr_bytes_written += bytes_copied; copy->cp_res.wr_bytes_written += bytes_copied;
src_pos += bytes_copied; src_pos += bytes_copied;
dst_pos += bytes_copied; dst_pos += bytes_copied;
} while (bytes_total > 0 && !copy->cp_synchronous); } while (bytes_total > 0 && nfsd4_copy_is_async(copy));
/* for a non-zero asynchronous copy do a commit of data */ /* for a non-zero asynchronous copy do a commit of data */
if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) { if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) {
since = READ_ONCE(dst->f_wb_err); since = READ_ONCE(dst->f_wb_err);
status = vfs_fsync_range(dst, copy->cp_dst_pos, status = vfs_fsync_range(dst, copy->cp_dst_pos,
copy->cp_res.wr_bytes_written, 0); copy->cp_res.wr_bytes_written, 0);
if (!status) if (!status)
status = filemap_check_wb_err(dst->f_mapping, since); status = filemap_check_wb_err(dst->f_mapping, since);
if (!status) if (!status)
copy->committed = true; set_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags);
} }
return bytes_copied; return bytes_copied;
} }
@@ -1728,7 +1715,7 @@ static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
status = nfs_ok; status = nfs_ok;
} }
if (!copy->cp_intra) /* Inter server SSC */ if (nfsd4_ssc_is_inter(copy))
nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src, nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->nf_src,
copy->nf_dst); copy->nf_dst);
else else
@@ -1742,13 +1729,13 @@ static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
dst->cp_src_pos = src->cp_src_pos; dst->cp_src_pos = src->cp_src_pos;
dst->cp_dst_pos = src->cp_dst_pos; dst->cp_dst_pos = src->cp_dst_pos;
dst->cp_count = src->cp_count; dst->cp_count = src->cp_count;
dst->cp_synchronous = src->cp_synchronous; dst->cp_flags = src->cp_flags;
memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res)); memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
memcpy(&dst->fh, &src->fh, sizeof(src->fh)); memcpy(&dst->fh, &src->fh, sizeof(src->fh));
dst->cp_clp = src->cp_clp; dst->cp_clp = src->cp_clp;
dst->nf_dst = nfsd_file_get(src->nf_dst); dst->nf_dst = nfsd_file_get(src->nf_dst);
dst->cp_intra = src->cp_intra; /* for inter, nf_src doesn't exist yet */
if (src->cp_intra) /* for inter, file_src doesn't exist yet */ if (!nfsd4_ssc_is_inter(src))
dst->nf_src = nfsd_file_get(src->nf_src); dst->nf_src = nfsd_file_get(src->nf_src);
memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
@@ -1762,7 +1749,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
{ {
nfs4_free_copy_state(copy); nfs4_free_copy_state(copy);
nfsd_file_put(copy->nf_dst); nfsd_file_put(copy->nf_dst);
if (copy->cp_intra) if (!nfsd4_ssc_is_inter(copy))
nfsd_file_put(copy->nf_src); nfsd_file_put(copy->nf_src);
spin_lock(&copy->cp_clp->async_lock); spin_lock(&copy->cp_clp->async_lock);
list_del(&copy->copies); list_del(&copy->copies);
@@ -1775,7 +1762,7 @@ static int nfsd4_do_async_copy(void *data)
struct nfsd4_copy *copy = (struct nfsd4_copy *)data; struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
struct nfsd4_copy *cb_copy; struct nfsd4_copy *cb_copy;
if (!copy->cp_intra) { /* Inter server SSC */ if (nfsd4_ssc_is_inter(copy)) {
copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL);
if (!copy->nf_src) { if (!copy->nf_src) {
copy->nfserr = nfserr_serverfault; copy->nfserr = nfserr_serverfault;
@@ -1807,7 +1794,7 @@ do_callback:
&copy->fh, copy->cp_count, copy->nfserr); &copy->fh, copy->cp_count, copy->nfserr);
nfsd4_run_cb(&cb_copy->cp_cb); nfsd4_run_cb(&cb_copy->cp_cb);
out: out:
if (!copy->cp_intra) if (nfsd4_ssc_is_inter(copy))
kfree(copy->nf_src); kfree(copy->nf_src);
cleanup_async_copy(copy); cleanup_async_copy(copy);
return 0; return 0;
@@ -1821,8 +1808,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
__be32 status; __be32 status;
struct nfsd4_copy *async_copy = NULL; struct nfsd4_copy *async_copy = NULL;
if (!copy->cp_intra) { /* Inter server SSC */ if (nfsd4_ssc_is_inter(copy)) {
if (!inter_copy_offload_enable || copy->cp_synchronous) { if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) {
status = nfserr_notsupp; status = nfserr_notsupp;
goto out; goto out;
} }
@@ -1839,7 +1826,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
copy->cp_clp = cstate->clp; copy->cp_clp = cstate->clp;
memcpy(&copy->fh, &cstate->current_fh.fh_handle, memcpy(&copy->fh, &cstate->current_fh.fh_handle,
sizeof(struct knfsd_fh)); sizeof(struct knfsd_fh));
if (!copy->cp_synchronous) { if (nfsd4_copy_is_async(copy)) {
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
status = nfserrno(-ENOMEM); status = nfserrno(-ENOMEM);
@@ -2605,7 +2592,7 @@ check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
return; return;
} }
putfh = (struct nfsd4_putfh *)&saved_op->u; putfh = (struct nfsd4_putfh *)&saved_op->u;
if (!copy->cp_intra) if (nfsd4_ssc_is_inter(copy))
putfh->no_verify = true; putfh->no_verify = true;
} }
} }

View File

@@ -1896,8 +1896,8 @@ static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp,
static __be32 static __be32
nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
{ {
u32 consecutive, i, count, sync;
struct nl4_server *ns_dummy; struct nl4_server *ns_dummy;
u32 consecutive, i, count;
__be32 status; __be32 status;
status = nfsd4_decode_stateid4(argp, &copy->cp_src_stateid); status = nfsd4_decode_stateid4(argp, &copy->cp_src_stateid);
@@ -1915,17 +1915,17 @@ nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
/* ca_consecutive: we always do consecutive copies */ /* ca_consecutive: we always do consecutive copies */
if (xdr_stream_decode_u32(argp->xdr, &consecutive) < 0) if (xdr_stream_decode_u32(argp->xdr, &consecutive) < 0)
return nfserr_bad_xdr; return nfserr_bad_xdr;
if (xdr_stream_decode_u32(argp->xdr, &copy->cp_synchronous) < 0) if (xdr_stream_decode_bool(argp->xdr, &sync) < 0)
return nfserr_bad_xdr; return nfserr_bad_xdr;
nfsd4_copy_set_sync(copy, sync);
if (xdr_stream_decode_u32(argp->xdr, &count) < 0) if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
return nfserr_bad_xdr; return nfserr_bad_xdr;
copy->cp_src = svcxdr_tmpalloc(argp, sizeof(*copy->cp_src)); copy->cp_src = svcxdr_tmpalloc(argp, sizeof(*copy->cp_src));
if (copy->cp_src == NULL) if (copy->cp_src == NULL)
return nfserr_jukebox; return nfserr_jukebox;
copy->cp_intra = false;
if (count == 0) { /* intra-server copy */ if (count == 0) { /* intra-server copy */
copy->cp_intra = true; __set_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
return nfs_ok; return nfs_ok;
} }
@@ -4712,13 +4712,13 @@ nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
__be32 *p; __be32 *p;
nfserr = nfsd42_encode_write_res(resp, &copy->cp_res, nfserr = nfsd42_encode_write_res(resp, &copy->cp_res,
!!copy->cp_synchronous); nfsd4_copy_is_sync(copy));
if (nfserr) if (nfserr)
return nfserr; return nfserr;
p = xdr_reserve_space(resp->xdr, 4 + 4); p = xdr_reserve_space(resp->xdr, 4 + 4);
*p++ = xdr_one; /* cr_consecutive */ *p++ = xdr_one; /* cr_consecutive */
*p++ = cpu_to_be32(copy->cp_synchronous); *p = nfsd4_copy_is_sync(copy) ? xdr_one : xdr_zero;
return 0; return 0;
} }

View File

@@ -541,10 +541,12 @@ struct nfsd4_copy {
u64 cp_dst_pos; u64 cp_dst_pos;
u64 cp_count; u64 cp_count;
struct nl4_server *cp_src; struct nl4_server *cp_src;
bool cp_intra;
/* both */ unsigned long cp_flags;
u32 cp_synchronous; #define NFSD4_COPY_F_STOPPED (0)
#define NFSD4_COPY_F_INTRA (1)
#define NFSD4_COPY_F_SYNCHRONOUS (2)
#define NFSD4_COPY_F_COMMITTED (3)
/* response */ /* response */
struct nfsd42_write_res cp_res; struct nfsd42_write_res cp_res;
@@ -564,14 +566,35 @@ struct nfsd4_copy {
struct list_head copies; struct list_head copies;
struct task_struct *copy_task; struct task_struct *copy_task;
refcount_t refcount; refcount_t refcount;
bool stopped;
struct vfsmount *ss_mnt; struct vfsmount *ss_mnt;
struct nfs_fh c_fh; struct nfs_fh c_fh;
nfs4_stateid stateid; nfs4_stateid stateid;
bool committed;
}; };
static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync)
{
if (sync)
set_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
else
clear_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
}
static inline bool nfsd4_copy_is_sync(const struct nfsd4_copy *copy)
{
return test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
}
static inline bool nfsd4_copy_is_async(const struct nfsd4_copy *copy)
{
return !test_bit(NFSD4_COPY_F_SYNCHRONOUS, &copy->cp_flags);
}
static inline bool nfsd4_ssc_is_inter(const struct nfsd4_copy *copy)
{
return !test_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
}
struct nfsd4_seek { struct nfsd4_seek {
/* request */ /* request */
stateid_t seek_stateid; stateid_t seek_stateid;