aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2012-03-04 18:13:56 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-03-06 10:32:46 -0500
commitf597c53790f662662281b82b7692a22d2a4d4afa (patch)
tree3567e1c7e232973fee14b7ddffa3545cd88392d0 /fs/nfs
parent1e3987c3052a48fbfc8f5d30214c825eff41192d (diff)
NFSv4: Add helpers for basic copying of stateids
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/delegation.c14
-rw-r--r--fs/nfs/nfs4_fs.h10
-rw-r--r--fs/nfs/nfs4proc.c34
-rw-r--r--fs/nfs/nfs4state.c6
-rw-r--r--fs/nfs/pnfs.c10
5 files changed, 38 insertions, 36 deletions
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index c7249e26e2e9..87f7544f3dce 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -105,7 +105,7 @@ again:
105 continue; 105 continue;
106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
107 continue; 107 continue;
108 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0) 108 if (!nfs4_stateid_match(&state->stateid, stateid))
109 continue; 109 continue;
110 get_nfs_open_context(ctx); 110 get_nfs_open_context(ctx);
111 spin_unlock(&inode->i_lock); 111 spin_unlock(&inode->i_lock);
@@ -139,8 +139,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
139 if (delegation != NULL) { 139 if (delegation != NULL) {
140 spin_lock(&delegation->lock); 140 spin_lock(&delegation->lock);
141 if (delegation->inode != NULL) { 141 if (delegation->inode != NULL) {
142 memcpy(delegation->stateid.data, res->delegation.data, 142 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
143 sizeof(delegation->stateid.data));
144 delegation->type = res->delegation_type; 143 delegation->type = res->delegation_type;
145 delegation->maxsize = res->maxsize; 144 delegation->maxsize = res->maxsize;
146 oldcred = delegation->cred; 145 oldcred = delegation->cred;
@@ -236,8 +235,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
236 delegation = kmalloc(sizeof(*delegation), GFP_NOFS); 235 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
237 if (delegation == NULL) 236 if (delegation == NULL)
238 return -ENOMEM; 237 return -ENOMEM;
239 memcpy(delegation->stateid.data, res->delegation.data, 238 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
240 sizeof(delegation->stateid.data));
241 delegation->type = res->delegation_type; 239 delegation->type = res->delegation_type;
242 delegation->maxsize = res->maxsize; 240 delegation->maxsize = res->maxsize;
243 delegation->change_attr = inode->i_version; 241 delegation->change_attr = inode->i_version;
@@ -250,8 +248,8 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
250 old_delegation = rcu_dereference_protected(nfsi->delegation, 248 old_delegation = rcu_dereference_protected(nfsi->delegation,
251 lockdep_is_held(&clp->cl_lock)); 249 lockdep_is_held(&clp->cl_lock));
252 if (old_delegation != NULL) { 250 if (old_delegation != NULL) {
253 if (memcmp(&delegation->stateid, &old_delegation->stateid, 251 if (nfs4_stateid_match(&delegation->stateid,
254 sizeof(old_delegation->stateid)) == 0 && 252 &old_delegation->stateid) &&
255 delegation->type == old_delegation->type) { 253 delegation->type == old_delegation->type) {
256 goto out; 254 goto out;
257 } 255 }
@@ -708,7 +706,7 @@ int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
708 rcu_read_lock(); 706 rcu_read_lock();
709 delegation = rcu_dereference(nfsi->delegation); 707 delegation = rcu_dereference(nfsi->delegation);
710 if (delegation != NULL) { 708 if (delegation != NULL) {
711 memcpy(dst->data, delegation->stateid.data, sizeof(dst->data)); 709 nfs4_stateid_copy(dst, &delegation->stateid);
712 ret = 1; 710 ret = 1;
713 } 711 }
714 rcu_read_unlock(); 712 rcu_read_unlock();
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 308d2f999c3d..1c54ef3146d4 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -349,6 +349,16 @@ struct nfs4_mount_data;
349extern struct svc_version nfs4_callback_version1; 349extern struct svc_version nfs4_callback_version1;
350extern struct svc_version nfs4_callback_version4; 350extern struct svc_version nfs4_callback_version4;
351 351
352static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
353{
354 memcpy(dst->data, src->data, sizeof(dst->data));
355}
356
357static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
358{
359 return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
360}
361
352#else 362#else
353 363
354#define nfs4_close_state(a, b) do { } while (0) 364#define nfs4_close_state(a, b) do { } while (0)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index f181c70ea933..ce0ad81dd466 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -941,8 +941,8 @@ static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
941static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) 941static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
942{ 942{
943 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 943 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
944 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); 944 nfs4_stateid_copy(&state->stateid, stateid);
945 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); 945 nfs4_stateid_copy(&state->open_stateid, stateid);
946 switch (fmode) { 946 switch (fmode) {
947 case FMODE_READ: 947 case FMODE_READ:
948 set_bit(NFS_O_RDONLY_STATE, &state->flags); 948 set_bit(NFS_O_RDONLY_STATE, &state->flags);
@@ -970,7 +970,7 @@ static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_s
970 */ 970 */
971 write_seqlock(&state->seqlock); 971 write_seqlock(&state->seqlock);
972 if (deleg_stateid != NULL) { 972 if (deleg_stateid != NULL) {
973 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); 973 nfs4_stateid_copy(&state->stateid, deleg_stateid);
974 set_bit(NFS_DELEGATED_STATE, &state->flags); 974 set_bit(NFS_DELEGATED_STATE, &state->flags);
975 } 975 }
976 if (open_stateid != NULL) 976 if (open_stateid != NULL)
@@ -1001,7 +1001,7 @@ static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stat
1001 1001
1002 if (delegation == NULL) 1002 if (delegation == NULL)
1003 delegation = &deleg_cur->stateid; 1003 delegation = &deleg_cur->stateid;
1004 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) 1004 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1005 goto no_delegation_unlock; 1005 goto no_delegation_unlock;
1006 1006
1007 nfs_mark_delegation_referenced(deleg_cur); 1007 nfs_mark_delegation_referenced(deleg_cur);
@@ -1062,7 +1062,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1062 break; 1062 break;
1063 } 1063 }
1064 /* Save the delegation */ 1064 /* Save the delegation */
1065 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); 1065 nfs4_stateid_copy(&stateid, &delegation->stateid);
1066 rcu_read_unlock(); 1066 rcu_read_unlock();
1067 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); 1067 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1068 if (ret != 0) 1068 if (ret != 0)
@@ -1225,10 +1225,10 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1225 * Check if we need to update the current stateid. 1225 * Check if we need to update the current stateid.
1226 */ 1226 */
1227 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && 1227 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1228 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { 1228 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1229 write_seqlock(&state->seqlock); 1229 write_seqlock(&state->seqlock);
1230 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 1230 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1231 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); 1231 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1232 write_sequnlock(&state->seqlock); 1232 write_sequnlock(&state->seqlock);
1233 } 1233 }
1234 return 0; 1234 return 0;
@@ -1297,8 +1297,7 @@ static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs
1297 if (IS_ERR(opendata)) 1297 if (IS_ERR(opendata))
1298 return PTR_ERR(opendata); 1298 return PTR_ERR(opendata);
1299 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; 1299 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1300 memcpy(opendata->o_arg.u.delegation.data, stateid->data, 1300 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1301 sizeof(opendata->o_arg.u.delegation.data));
1302 ret = nfs4_open_recover(opendata, state); 1301 ret = nfs4_open_recover(opendata, state);
1303 nfs4_opendata_put(opendata); 1302 nfs4_opendata_put(opendata);
1304 return ret; 1303 return ret;
@@ -1363,8 +1362,7 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1363 1362
1364 data->rpc_status = task->tk_status; 1363 data->rpc_status = task->tk_status;
1365 if (data->rpc_status == 0) { 1364 if (data->rpc_status == 0) {
1366 memcpy(data->o_res.stateid.data, data->c_res.stateid.data, 1365 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1367 sizeof(data->o_res.stateid.data));
1368 nfs_confirm_seqid(&data->owner->so_seqid, 0); 1366 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1369 renew_lease(data->o_res.server, data->timestamp); 1367 renew_lease(data->o_res.server, data->timestamp);
1370 data->rpc_done = 1; 1368 data->rpc_done = 1;
@@ -1924,7 +1922,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1924 } else if (state != NULL) { 1922 } else if (state != NULL) {
1925 nfs4_select_rw_stateid(&arg.stateid, state, current->files, current->tgid); 1923 nfs4_select_rw_stateid(&arg.stateid, state, current->files, current->tgid);
1926 } else 1924 } else
1927 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); 1925 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
1928 1926
1929 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 1927 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
1930 if (status == 0 && state != NULL) 1928 if (status == 0 && state != NULL)
@@ -3989,7 +3987,7 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
3989 data->args.stateid = &data->stateid; 3987 data->args.stateid = &data->stateid;
3990 data->args.bitmask = server->attr_bitmask; 3988 data->args.bitmask = server->attr_bitmask;
3991 nfs_copy_fh(&data->fh, NFS_FH(inode)); 3989 nfs_copy_fh(&data->fh, NFS_FH(inode));
3992 memcpy(&data->stateid, stateid, sizeof(data->stateid)); 3990 nfs4_stateid_copy(&data->stateid, stateid);
3993 data->res.fattr = &data->fattr; 3991 data->res.fattr = &data->fattr;
3994 data->res.server = server; 3992 data->res.server = server;
3995 nfs_fattr_init(data->res.fattr); 3993 nfs_fattr_init(data->res.fattr);
@@ -4172,9 +4170,8 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
4172 return; 4170 return;
4173 switch (task->tk_status) { 4171 switch (task->tk_status) {
4174 case 0: 4172 case 0:
4175 memcpy(calldata->lsp->ls_stateid.data, 4173 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4176 calldata->res.stateid.data, 4174 &calldata->res.stateid);
4177 sizeof(calldata->lsp->ls_stateid.data));
4178 renew_lease(calldata->server, calldata->timestamp); 4175 renew_lease(calldata->server, calldata->timestamp);
4179 break; 4176 break;
4180 case -NFS4ERR_BAD_STATEID: 4177 case -NFS4ERR_BAD_STATEID:
@@ -4387,8 +4384,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4387 goto out; 4384 goto out;
4388 } 4385 }
4389 if (data->rpc_status == 0) { 4386 if (data->rpc_status == 0) {
4390 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, 4387 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4391 sizeof(data->lsp->ls_stateid.data));
4392 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; 4388 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4393 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); 4389 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4394 } 4390 }
@@ -6292,7 +6288,7 @@ static bool nfs41_match_stateid(const nfs4_stateid *s1,
6292static bool nfs4_match_stateid(const nfs4_stateid *s1, 6288static bool nfs4_match_stateid(const nfs4_stateid *s1,
6293 const nfs4_stateid *s2) 6289 const nfs4_stateid *s2)
6294{ 6290{
6295 return memcmp(s1->data, s2->data, sizeof(s1->data)) == 0; 6291 return nfs4_stateid_match(s1, s2);
6296} 6292}
6297 6293
6298 6294
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 6ba82271c868..55c8a81cd6fb 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -895,7 +895,7 @@ void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owne
895 895
896 do { 896 do {
897 seq = read_seqbegin(&state->seqlock); 897 seq = read_seqbegin(&state->seqlock);
898 memcpy(dst, &state->stateid, sizeof(*dst)); 898 nfs4_stateid_copy(dst, &state->stateid);
899 } while (read_seqretry(&state->seqlock, seq)); 899 } while (read_seqretry(&state->seqlock, seq));
900 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) 900 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
901 return; 901 return;
@@ -903,7 +903,7 @@ void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owne
903 spin_lock(&state->state_lock); 903 spin_lock(&state->state_lock);
904 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE); 904 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
905 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) 905 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
906 memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); 906 nfs4_stateid_copy(dst, &lsp->ls_stateid);
907 spin_unlock(&state->state_lock); 907 spin_unlock(&state->state_lock);
908 nfs4_put_lock_state(lsp); 908 nfs4_put_lock_state(lsp);
909} 909}
@@ -1126,7 +1126,7 @@ void nfs_inode_find_state_and_recover(struct inode *inode,
1126 continue; 1126 continue;
1127 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 1127 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
1128 continue; 1128 continue;
1129 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0) 1129 if (!nfs4_stateid_match(&state->stateid, stateid))
1130 continue; 1130 continue;
1131 nfs4_state_mark_reclaim_nograce(clp, state); 1131 nfs4_state_mark_reclaim_nograce(clp, state);
1132 found = true; 1132 found = true;
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 402efc2f5b70..c190e9c2e3d2 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -499,7 +499,7 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
499 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid); 499 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
500 newseq = be32_to_cpu(new->stateid.seqid); 500 newseq = be32_to_cpu(new->stateid.seqid);
501 if ((int)(newseq - oldseq) > 0) { 501 if ((int)(newseq - oldseq) > 0) {
502 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid)); 502 nfs4_stateid_copy(&lo->plh_stateid, new);
503 if (update_barrier) { 503 if (update_barrier) {
504 u32 new_barrier = be32_to_cpu(new->stateid.seqid); 504 u32 new_barrier = be32_to_cpu(new->stateid.seqid);
505 505
@@ -549,11 +549,10 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
549 549
550 do { 550 do {
551 seq = read_seqbegin(&open_state->seqlock); 551 seq = read_seqbegin(&open_state->seqlock);
552 memcpy(dst->data, open_state->stateid.data, 552 nfs4_stateid_copy(dst, &open_state->stateid);
553 sizeof(open_state->stateid.data));
554 } while (read_seqretry(&open_state->seqlock, seq)); 553 } while (read_seqretry(&open_state->seqlock, seq));
555 } else 554 } else
556 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data)); 555 nfs4_stateid_copy(dst, &lo->plh_stateid);
557 spin_unlock(&lo->plh_inode->i_lock); 556 spin_unlock(&lo->plh_inode->i_lock);
558 dprintk("<-- %s\n", __func__); 557 dprintk("<-- %s\n", __func__);
559 return status; 558 return status;
@@ -1527,8 +1526,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
1527 end_pos = nfsi->layout->plh_lwb; 1526 end_pos = nfsi->layout->plh_lwb;
1528 nfsi->layout->plh_lwb = 0; 1527 nfsi->layout->plh_lwb = 0;
1529 1528
1530 memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data, 1529 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
1531 sizeof(nfsi->layout->plh_stateid.data));
1532 spin_unlock(&inode->i_lock); 1530 spin_unlock(&inode->i_lock);
1533 1531
1534 data->args.inode = inode; 1532 data->args.inode = inode;