40 #include <linux/errno.h>
41 #include <linux/string.h>
44 #include <linux/slab.h>
46 #include <linux/nfs.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs_fs.h>
53 #include <linux/module.h>
54 #include <linux/nfs_idmap.h>
56 #include <linux/xattr.h>
57 #include <linux/utsname.h>
68 #define NFSDBG_FACILITY NFSDBG_PROC
70 #define NFS4_POLL_RETRY_MIN (HZ/10)
71 #define NFS4_POLL_RETRY_MAX (15*HZ)
73 #define NFS4_MAX_LOOP_ON_RECOVER (10)
79 static int nfs4_async_handle_error(
struct rpc_task *,
const struct nfs_server *,
struct nfs4_state *);
80 static void nfs_fixup_referral_attributes(
struct nfs_fattr *fattr);
83 static int nfs4_do_setattr(
struct inode *
inode,
struct rpc_cred *
cred,
85 struct nfs4_state *
state);
86 #ifdef CONFIG_NFS_V4_1
91 static int nfs4_map_errors(
int err)
110 dprintk(
"%s could not handle NFSv4 error %d\n",
137 static const u32 nfs4_pnfs_open_bitmap[3] = {
155 static const u32 nfs4_open_noattr_bitmap[3] = {
205 struct nfs4_readdir_arg *readdir)
209 BUG_ON(readdir->count < 80);
212 memcpy(&readdir->verifier, verifier,
sizeof(readdir->verifier));
217 memset(&readdir->verifier, 0,
sizeof(readdir->verifier));
240 p = xdr_encode_hyper(p, NFS_FILEID(dentry->
d_inode));
252 p = xdr_encode_hyper(p, NFS_FILEID(dentry->
d_parent->d_inode));
254 readdir->pgbase = (
char *)p - (
char *)
start;
255 readdir->count -= readdir->pgbase;
259 static int nfs4_wait_clnt_recover(
struct nfs_client *clp)
265 res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
275 static int nfs4_delay(
struct rpc_clnt *clnt,
long *timeout)
286 if (fatal_signal_pending(
current))
295 static int nfs4_handle_exception(
struct nfs_server *server,
int errorcode,
struct nfs4_exception *
exception)
298 struct nfs4_state *
state = exception->state;
302 exception->retry = 0;
309 exception->retry = 1;
315 goto wait_on_recovery;
323 goto wait_on_recovery;
330 goto wait_on_recovery;
331 #if defined(CONFIG_NFS_V4_1)
339 dprintk(
"%s ERROR: %d Reset session\n", __func__,
341 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
342 goto wait_on_recovery;
345 if (exception->timeout >
HZ) {
355 ret = nfs4_delay(server->
client, &exception->timeout);
360 exception->retry = 1;
367 exception->retry = 1;
369 "does not accept raw "
371 "Reenabling the idmapper.\n",
376 return nfs4_map_errors(ret);
378 ret = nfs4_wait_clnt_recover(clp);
380 exception->retry = 1;
387 spin_lock(&clp->cl_lock);
390 spin_unlock(&clp->cl_lock);
393 static void renew_lease(
const struct nfs_server *server,
unsigned long timestamp)
395 do_renew_lease(server->
nfs_client, timestamp);
398 #if defined(CONFIG_NFS_V4_1)
416 nfs4_free_slot(
struct nfs4_slot_table *tbl,
u32 slotid)
423 if (slotid == tbl->highest_used_slotid) {
425 if (slotid < tbl->max_slots)
426 tbl->highest_used_slotid = slotid;
430 dprintk(
"%s: slotid %u highest_used_slotid %d\n", __func__,
431 slotid, tbl->highest_used_slotid);
443 static void nfs4_check_drain_fc_complete(
struct nfs4_session *ses)
445 if (!
test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
447 nfs4_set_task_privileged,
NULL);
451 if (ses->fc_slot_table.highest_used_slotid !=
NFS4_NO_SLOT)
454 dprintk(
"%s COMPLETE: Session Fore Channel Drained\n", __func__);
455 complete(&ses->fc_slot_table.complete);
461 void nfs4_check_drain_bc_complete(
struct nfs4_session *ses)
463 if (!
test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
466 dprintk(
"%s COMPLETE: Session Back Channel Drained\n", __func__);
467 complete(&ses->bc_slot_table.complete);
472 struct nfs4_slot_table *tbl;
478 dprintk(
"%s: No slot\n", __func__);
482 spin_lock(&tbl->slot_tbl_lock);
483 nfs4_free_slot(tbl, res->
sr_slot - tbl->slots);
484 nfs4_check_drain_fc_complete(res->
sr_session);
485 spin_unlock(&tbl->slot_tbl_lock);
514 do_renew_lease(clp, timestamp);
524 dprintk(
"%s: slot=%td seq=%d: Operation in progress\n",
536 nfs41_sequence_free_slot(res);
545 static int nfs4_sequence_done(
struct rpc_task *task,
550 return nfs41_sequence_done(task, res);
564 nfs4_find_slot(
struct nfs4_slot_table *tbl)
569 dprintk(
"--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
570 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
573 if (slotid >= tbl->max_slots)
576 if (slotid > tbl->highest_used_slotid ||
578 tbl->highest_used_slotid = slotid;
581 dprintk(
"<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
582 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
597 int nfs41_setup_sequence(
struct nfs4_session *session,
603 struct nfs4_slot_table *tbl;
611 tbl = &session->fc_slot_table;
613 spin_lock(&tbl->slot_tbl_lock);
614 if (
test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
618 spin_unlock(&tbl->slot_tbl_lock);
619 dprintk(
"%s session is draining\n", __func__);
626 spin_unlock(&tbl->slot_tbl_lock);
627 dprintk(
"%s enforce FIFO order\n", __func__);
631 slotid = nfs4_find_slot(tbl);
634 spin_unlock(&tbl->slot_tbl_lock);
635 dprintk(
"<-- %s: no free slots\n", __func__);
638 spin_unlock(&tbl->slot_tbl_lock);
641 slot = tbl->slots + slotid;
645 dprintk(
"<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->
seq_nr);
660 int nfs4_setup_sequence(
const struct nfs_server *server,
665 struct nfs4_session *session = nfs4_get_session(server);
671 dprintk(
"--> %s clp %p session %p sr_slot %td\n",
672 __func__, session->clp, session, res->
sr_slot ?
673 res->
sr_slot - session->fc_slot_table.slots : -1);
675 ret = nfs41_setup_sequence(session, args, res, task);
677 dprintk(
"<-- %s status=%d\n", __func__, ret);
681 struct nfs41_call_sync_data {
687 static void nfs41_call_sync_prepare(
struct rpc_task *task,
void *calldata)
689 struct nfs41_call_sync_data *
data = calldata;
691 dprintk(
"--> %s data->seq_server %p\n", __func__, data->seq_server);
693 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
694 data->seq_res, task))
699 static void nfs41_call_priv_sync_prepare(
struct rpc_task *task,
void *calldata)
702 nfs41_call_sync_prepare(task, calldata);
705 static void nfs41_call_sync_done(
struct rpc_task *task,
void *calldata)
707 struct nfs41_call_sync_data *data = calldata;
709 nfs41_sequence_done(task, data->seq_res);
712 static const struct rpc_call_ops nfs41_call_sync_ops = {
714 .rpc_call_done = nfs41_call_sync_done,
717 static const struct rpc_call_ops nfs41_call_priv_sync_ops = {
719 .rpc_call_done = nfs41_call_sync_done,
722 static int nfs4_call_sync_sequence(
struct rpc_clnt *clnt,
731 struct nfs41_call_sync_data data = {
732 .seq_server = server,
739 .callback_ops = &nfs41_call_sync_ops,
740 .callback_data = &data
762 nfs41_init_sequence(args, res, cache_reply);
763 return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0);
773 static int nfs4_sequence_done(
struct rpc_task *task,
787 nfs41_init_sequence(args, res, cache_reply);
792 int nfs4_call_sync(
struct rpc_clnt *clnt,
799 return server->
nfs_client->cl_mvops->call_sync(clnt, server, msg,
800 args, res, cache_reply);
803 static void update_changeattr(
struct inode *dir,
struct nfs4_change_info *cinfo)
812 spin_unlock(&dir->
i_lock);
847 static struct nfs4_opendata *nfs4_opendata_alloc(
struct dentry *dentry,
853 struct inode *dir = parent->
d_inode;
857 p = kzalloc(
sizeof(*p), gfp_mask);
868 p->
o_arg.fh = NFS_FH(dir);
880 p->
o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
881 p->
o_arg.id.uniquifier = sp->so_seqid.owner_id;
883 p->
o_arg.server = server;
884 p->
o_arg.bitmask = server->attr_bitmask;
885 p->
o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
896 sizeof(p->
o_arg.u.verifier.data));
901 nfs4_init_opendata_res(p);
911 static void nfs4_opendata_free(
struct kref *
kref)
931 kref_put(&p->
kref, nfs4_opendata_free);
934 static int nfs4_wait_for_completion_rpc_task(
struct rpc_task *task)
938 ret = rpc_wait_for_completion_task(task);
942 static int can_open_cached(
struct nfs4_state *state,
fmode_t mode,
int open_mode)
946 if (open_mode & (O_EXCL|
O_TRUNC))
950 ret |=
test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
951 && state->n_rdonly != 0;
954 ret |=
test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
955 && state->n_wronly != 0;
958 ret |=
test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
959 && state->n_rdwr != 0;
965 static int can_open_delegated(
struct nfs_delegation *delegation,
fmode_t fmode)
967 if (delegation ==
NULL)
969 if ((delegation->type & fmode) != fmode)
971 if (
test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
977 static void update_open_stateflags(
struct nfs4_state *state,
fmode_t fmode)
992 static void nfs_set_open_stateid_locked(
struct nfs4_state *state,
nfs4_stateid *stateid,
fmode_t fmode)
994 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
995 nfs4_stateid_copy(&state->stateid, stateid);
996 nfs4_stateid_copy(&state->open_stateid, stateid);
999 set_bit(NFS_O_RDONLY_STATE, &state->flags);
1002 set_bit(NFS_O_WRONLY_STATE, &state->flags);
1005 set_bit(NFS_O_RDWR_STATE, &state->flags);
1009 static void nfs_set_open_stateid(
struct nfs4_state *state,
nfs4_stateid *stateid,
fmode_t fmode)
1011 write_seqlock(&state->seqlock);
1012 nfs_set_open_stateid_locked(state, stateid, fmode);
1013 write_sequnlock(&state->seqlock);
1022 write_seqlock(&state->seqlock);
1023 if (deleg_stateid !=
NULL) {
1024 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1025 set_bit(NFS_DELEGATED_STATE, &state->flags);
1027 if (open_stateid !=
NULL)
1028 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1029 write_sequnlock(&state->seqlock);
1030 spin_lock(&state->owner->so_lock);
1031 update_open_stateflags(state, fmode);
1032 spin_unlock(&state->owner->so_lock);
1037 struct nfs_inode *nfsi = NFS_I(state->inode);
1038 struct nfs_delegation *deleg_cur;
1045 if (deleg_cur ==
NULL)
1048 spin_lock(&deleg_cur->lock);
1049 if (nfsi->delegation != deleg_cur ||
1050 (deleg_cur->type & fmode) != fmode)
1051 goto no_delegation_unlock;
1053 if (delegation ==
NULL)
1054 delegation = &deleg_cur->stateid;
1055 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1056 goto no_delegation_unlock;
1059 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1061 no_delegation_unlock:
1062 spin_unlock(&deleg_cur->lock);
1066 if (!ret && open_stateid !=
NULL) {
1067 __update_open_stateid(state, open_stateid,
NULL, fmode);
1075 static void nfs4_return_incompatible_delegation(
struct inode *inode,
fmode_t fmode)
1077 struct nfs_delegation *delegation;
1081 if (delegation ==
NULL || (delegation->type & fmode) == fmode) {
1089 static struct nfs4_state *nfs4_try_open_cached(
struct nfs4_opendata *opendata)
1091 struct nfs4_state *state = opendata->
state;
1092 struct nfs_inode *nfsi = NFS_I(state->inode);
1093 struct nfs_delegation *delegation;
1094 int open_mode = opendata->
o_arg.open_flags & (O_EXCL|
O_TRUNC);
1100 if (can_open_cached(state, fmode, open_mode)) {
1101 spin_lock(&state->owner->so_lock);
1102 if (can_open_cached(state, fmode, open_mode)) {
1103 update_open_stateflags(state, fmode);
1104 spin_unlock(&state->owner->so_lock);
1105 goto out_return_state;
1107 spin_unlock(&state->owner->so_lock);
1111 if (!can_open_delegated(delegation, fmode)) {
1116 nfs4_stateid_copy(&stateid, &delegation->stateid);
1118 ret =
nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1124 if (update_open_stateid(state,
NULL, &stateid, fmode))
1125 goto out_return_state;
1128 return ERR_PTR(ret);
1135 nfs4_opendata_check_deleg(
struct nfs4_opendata *data,
struct nfs4_state *state)
1137 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
1138 struct nfs_delegation *delegation;
1139 int delegation_flags = 0;
1144 delegation_flags = delegation->flags;
1148 "returning a delegation for "
1149 "OPEN(CLAIM_DELEGATE_CUR)\n",
1151 }
else if ((delegation_flags & 1
UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1153 data->
owner->so_cred,
1157 data->
owner->so_cred,
1165 static struct nfs4_state *
1166 _nfs4_opendata_reclaim_to_nfs4_state(
struct nfs4_opendata *data)
1168 struct inode *inode = data->
state->inode;
1169 struct nfs4_state *state = data->
state;
1192 if (data->
o_res.delegation_type != 0)
1193 nfs4_opendata_check_deleg(data, state);
1194 update_open_stateid(state, &data->
o_res.stateid,
NULL,
1199 return ERR_PTR(ret);
1203 static struct nfs4_state *
1206 struct inode *
inode;
1207 struct nfs4_state *state =
NULL;
1211 state = nfs4_try_open_cached(data);
1219 ret = PTR_ERR(inode);
1226 if (data->
o_res.delegation_type != 0)
1227 nfs4_opendata_check_deleg(data, state);
1228 update_open_stateid(state, &data->
o_res.stateid,
NULL,
1236 return ERR_PTR(ret);
1239 static struct nfs4_state *
1243 return _nfs4_opendata_reclaim_to_nfs4_state(data);
1244 return _nfs4_opendata_to_nfs4_state(data);
1247 static struct nfs_open_context *nfs4_state_find_open_context(
struct nfs4_state *state)
1249 struct nfs_inode *nfsi = NFS_I(state->inode);
1252 spin_lock(&state->inode->i_lock);
1254 if (ctx->
state != state)
1257 spin_unlock(&state->inode->i_lock);
1260 spin_unlock(&state->inode->i_lock);
1269 if (opendata ==
NULL)
1276 static int nfs4_open_recover_helper(
struct nfs4_opendata *opendata,
fmode_t fmode,
struct nfs4_state **res)
1278 struct nfs4_state *newstate;
1281 opendata->
o_arg.open_flags = 0;
1282 opendata->
o_arg.fmode = fmode;
1285 nfs4_init_opendata_res(opendata);
1286 ret = _nfs4_recover_proc_open(opendata);
1289 newstate = nfs4_opendata_to_nfs4_state(opendata);
1290 if (IS_ERR(newstate))
1291 return PTR_ERR(newstate);
1297 static int nfs4_open_recover(
struct nfs4_opendata *opendata,
struct nfs4_state *state)
1299 struct nfs4_state *newstate;
1303 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1305 if (state->n_rdwr != 0) {
1306 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1310 if (newstate != state)
1313 if (state->n_wronly != 0) {
1314 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1315 ret = nfs4_open_recover_helper(opendata,
FMODE_WRITE, &newstate);
1318 if (newstate != state)
1321 if (state->n_rdonly != 0) {
1322 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1323 ret = nfs4_open_recover_helper(opendata,
FMODE_READ, &newstate);
1326 if (newstate != state)
1333 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1334 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1335 write_seqlock(&state->seqlock);
1336 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1337 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1338 write_sequnlock(&state->seqlock);
1347 static int _nfs4_do_open_reclaim(
struct nfs_open_context *ctx,
struct nfs4_state *state)
1349 struct nfs_delegation *delegation;
1354 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1355 if (IS_ERR(opendata))
1356 return PTR_ERR(opendata);
1358 opendata->
o_arg.fh = NFS_FH(state->inode);
1361 if (delegation !=
NULL &&
test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1362 delegation_type = delegation->type;
1364 opendata->
o_arg.u.delegation_type = delegation_type;
1365 status = nfs4_open_recover(opendata, state);
1366 nfs4_opendata_put(opendata);
1370 static int nfs4_do_open_reclaim(
struct nfs_open_context *ctx,
struct nfs4_state *state)
1372 struct nfs_server *server = NFS_SERVER(state->inode);
1373 struct nfs4_exception exception = { };
1376 err = _nfs4_do_open_reclaim(ctx, state);
1379 nfs4_handle_exception(server, err, &exception);
1380 }
while (exception.retry);
1384 static int nfs4_open_reclaim(
struct nfs4_state_owner *sp,
struct nfs4_state *state)
1389 ctx = nfs4_state_find_open_context(state);
1391 return PTR_ERR(ctx);
1392 ret = nfs4_do_open_reclaim(ctx, state);
1402 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1403 if (IS_ERR(opendata))
1404 return PTR_ERR(opendata);
1406 nfs4_stateid_copy(&opendata->
o_arg.u.delegation, stateid);
1407 ret = nfs4_open_recover(opendata, state);
1408 nfs4_opendata_put(opendata);
1414 struct nfs4_exception exception = { };
1415 struct nfs_server *server = NFS_SERVER(state->inode);
1418 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1429 nfs4_schedule_session_recovery(server->
nfs_client->cl_session, err);
1459 err = nfs4_handle_exception(server, err, &exception);
1460 }
while (exception.retry);
1465 static void nfs4_open_confirm_done(
struct rpc_task *task,
void *calldata)
1471 nfs4_stateid_copy(&data->
o_res.stateid, &data->
c_res.stateid);
1472 nfs_confirm_seqid(&data->
owner->so_seqid, 0);
1478 static void nfs4_open_confirm_release(
void *calldata)
1481 struct nfs4_state *state =
NULL;
1489 state = nfs4_opendata_to_nfs4_state(data);
1493 nfs4_opendata_put(data);
1496 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1497 .rpc_call_done = nfs4_open_confirm_done,
1498 .rpc_release = nfs4_open_confirm_release,
1504 static int _nfs4_proc_open_confirm(
struct nfs4_opendata *data)
1510 .rpc_argp = &data->
c_arg,
1511 .rpc_resp = &data->
c_res,
1512 .rpc_cred = data->
owner->so_cred,
1516 .rpc_message = &
msg,
1517 .callback_ops = &nfs4_open_confirm_ops,
1518 .callback_data =
data,
1524 kref_get(&data->
kref);
1530 return PTR_ERR(task);
1531 status = nfs4_wait_for_completion_rpc_task(task);
1541 static void nfs4_open_prepare(
struct rpc_task *task,
void *calldata)
1544 struct nfs4_state_owner *sp = data->
owner;
1553 struct nfs_delegation *delegation;
1555 if (can_open_cached(data->
state, data->
o_arg.fmode, data->
o_arg.open_flags))
1560 can_open_delegated(delegation, data->
o_arg.fmode))
1561 goto unlock_no_action;
1565 data->
o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1568 data->
o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1569 nfs_copy_fh(&data->
o_res.fh, data->
o_arg.fh);
1572 if (nfs4_setup_sequence(data->
o_arg.server,
1573 &data->
o_arg.seq_args,
1574 &data->
o_res.seq_res,
1587 static void nfs4_recover_open_prepare(
struct rpc_task *task,
void *calldata)
1590 nfs4_open_prepare(task, calldata);
1593 static void nfs4_open_done(
struct rpc_task *task,
void *calldata)
1599 if (!nfs4_sequence_done(task, &data->
o_res.seq_res))
1619 nfs_confirm_seqid(&data->
owner->so_seqid, 0);
1624 static void nfs4_open_release(
void *calldata)
1627 struct nfs4_state *state =
NULL;
1638 state = nfs4_opendata_to_nfs4_state(data);
1642 nfs4_opendata_put(data);
1646 .rpc_call_prepare = nfs4_open_prepare,
1647 .rpc_call_done = nfs4_open_done,
1648 .rpc_release = nfs4_open_release,
1651 static const struct rpc_call_ops nfs4_recover_open_ops = {
1652 .rpc_call_prepare = nfs4_recover_open_prepare,
1653 .rpc_call_done = nfs4_open_done,
1654 .rpc_release = nfs4_open_release,
1657 static int nfs4_run_open_task(
struct nfs4_opendata *data,
int isrecover)
1659 struct inode *dir = data->
dir->d_inode;
1668 .rpc_cred = data->
owner->so_cred,
1672 .rpc_message = &
msg,
1673 .callback_ops = &nfs4_open_ops,
1674 .callback_data =
data,
1681 kref_get(&data->
kref);
1689 return PTR_ERR(task);
1690 status = nfs4_wait_for_completion_rpc_task(task);
1701 static int _nfs4_recover_proc_open(
struct nfs4_opendata *data)
1703 struct inode *dir = data->
dir->d_inode;
1707 status = nfs4_run_open_task(data, 1);
1708 if (status != 0 || !data->
rpc_done)
1714 status = _nfs4_proc_open_confirm(data);
1722 static int nfs4_opendata_access(
struct rpc_cred *
cred,
1724 struct nfs4_state *state,
fmode_t fmode)
1731 if (opendata->
o_res.access_supported == 0)
1760 struct inode *dir = data->
dir->d_inode;
1766 status = nfs4_run_open_task(data, 0);
1779 update_changeattr(dir, &o_res->
cinfo);
1783 status = _nfs4_proc_open_confirm(data);
1788 _nfs4_proc_getattr(server, &o_res->
fh, o_res->
f_attr);
1792 static int nfs4_client_recover_expired_lease(
struct nfs_client *clp)
1798 ret = nfs4_wait_clnt_recover(clp);
1801 if (!
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1802 !
test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1810 static int nfs4_recover_expired_lease(
struct nfs_server *server)
1812 return nfs4_client_recover_expired_lease(server->
nfs_client);
1820 static int _nfs4_open_expired(
struct nfs_open_context *ctx,
struct nfs4_state *state)
1825 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1826 if (IS_ERR(opendata))
1827 return PTR_ERR(opendata);
1828 ret = nfs4_open_recover(opendata, state);
1831 nfs4_opendata_put(opendata);
1835 static int nfs4_do_open_expired(
struct nfs_open_context *ctx,
struct nfs4_state *state)
1837 struct nfs_server *server = NFS_SERVER(state->inode);
1838 struct nfs4_exception exception = { };
1842 err = _nfs4_open_expired(ctx, state);
1848 nfs4_handle_exception(server, err, &exception);
1851 }
while (exception.retry);
1856 static int nfs4_open_expired(
struct nfs4_state_owner *sp,
struct nfs4_state *state)
1861 ctx = nfs4_state_find_open_context(state);
1863 return PTR_ERR(ctx);
1864 ret = nfs4_do_open_expired(ctx, state);
1869 #if defined(CONFIG_NFS_V4_1)
1870 static void nfs41_clear_delegation_stateid(
struct nfs4_state *state)
1872 struct nfs_server *server = NFS_SERVER(state->inode);
1877 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1880 status = nfs41_test_stateid(server, stateid);
1885 nfs41_free_stateid(server, stateid);
1888 write_seqlock(&state->seqlock);
1889 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1890 write_sequnlock(&state->seqlock);
1891 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1903 static int nfs41_check_open_stateid(
struct nfs4_state *state)
1905 struct nfs_server *server = NFS_SERVER(state->inode);
1910 if ((
test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
1911 (
test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
1912 (
test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
1915 status = nfs41_test_stateid(server, stateid);
1920 nfs41_free_stateid(server, stateid);
1922 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1923 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1924 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1929 static int nfs41_open_expired(
struct nfs4_state_owner *sp,
struct nfs4_state *state)
1933 nfs41_clear_delegation_stateid(state);
1934 status = nfs41_check_open_stateid(state);
1936 status = nfs4_open_expired(sp, state);
1946 static inline void nfs4_exclusive_attrset(
struct nfs4_opendata *opendata,
struct iattr *sattr)
1960 static int _nfs4_do_open(
struct inode *dir,
1961 struct dentry *dentry,
1964 struct iattr *sattr,
1965 struct rpc_cred *cred,
1966 struct nfs4_state **res,
1969 struct nfs4_state_owner *
sp;
1970 struct nfs4_state *state =
NULL;
1979 dprintk(
"nfs4_do_open: nfs4_get_state_owner failed!\n");
1982 status = nfs4_recover_expired_lease(server);
1984 goto err_put_state_owner;
1986 nfs4_return_incompatible_delegation(dentry->
d_inode, fmode);
1988 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
GFP_KERNEL);
1989 if (opendata ==
NULL)
1990 goto err_put_state_owner;
1994 if (!opendata->
f_attr.mdsthreshold)
1995 goto err_opendata_put;
1996 opendata->
o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
2001 status = _nfs4_proc_open(opendata);
2003 goto err_opendata_put;
2005 state = nfs4_opendata_to_nfs4_state(opendata);
2006 status = PTR_ERR(state);
2008 goto err_opendata_put;
2010 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
2012 status = nfs4_opendata_access(cred, opendata, state, fmode);
2014 goto err_opendata_put;
2016 if (opendata->
o_arg.open_flags & O_EXCL) {
2017 nfs4_exclusive_attrset(opendata, sattr);
2020 status = nfs4_do_setattr(state->inode, cred,
2021 opendata->
o_res.f_attr, sattr,
2028 if (pnfs_use_threshold(ctx_th, opendata->
f_attr.mdsthreshold, server))
2029 *ctx_th = opendata->
f_attr.mdsthreshold;
2034 nfs4_opendata_put(opendata);
2040 nfs4_opendata_put(opendata);
2041 err_put_state_owner:
2049 static struct nfs4_state *nfs4_do_open(
struct inode *dir,
2050 struct dentry *dentry,
2053 struct iattr *sattr,
2054 struct rpc_cred *cred,
2057 struct nfs4_exception exception = { };
2058 struct nfs4_state *
res;
2063 status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred,
2080 " returned a bad sequence-id error!\n",
2082 exception.retry = 1;
2092 exception.retry = 1;
2097 exception.retry = 1;
2100 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
2101 status, &exception));
2102 }
while (exception.retry);
2106 static int _nfs4_do_setattr(
struct inode *inode,
struct rpc_cred *cred,
2108 struct nfs4_state *state)
2110 struct nfs_server *server = NFS_SERVER(inode);
2112 .fh = NFS_FH(inode),
2115 .bitmask = server->attr_bitmask,
2127 unsigned long timestamp =
jiffies;
2132 if (state !=
NULL) {
2146 if (status == 0 && state !=
NULL)
2147 renew_lease(server, timestamp);
2151 static int nfs4_do_setattr(
struct inode *inode,
struct rpc_cred *cred,
2153 struct nfs4_state *state)
2155 struct nfs_server *server = NFS_SERVER(inode);
2156 struct nfs4_exception exception = {
2162 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
2172 err = nfs4_handle_exception(server, err, &exception);
2173 }
while (exception.retry);
2189 static void nfs4_free_closedata(
void *data)
2192 struct nfs4_state_owner *sp = calldata->
state->owner;
2204 static void nfs4_close_clear_stateid_flags(
struct nfs4_state *state,
2207 spin_lock(&state->owner->so_lock);
2208 if (!(fmode & FMODE_READ))
2209 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2211 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2212 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2213 spin_unlock(&state->owner->so_lock);
2216 static void nfs4_close_done(
struct rpc_task *task,
void *data)
2219 struct nfs4_state *state = calldata->
state;
2222 dprintk(
"%s: begin!\n", __func__);
2223 if (!nfs4_sequence_done(task, &calldata->
res.seq_res))
2233 nfs_set_open_stateid(state, &calldata->
res.stateid, 0);
2234 renew_lease(server, calldata->
timestamp);
2235 nfs4_close_clear_stateid_flags(state,
2236 calldata->
arg.fmode);
2242 if (calldata->
arg.fmode == 0)
2245 if (nfs4_async_handle_error(task, server, state) == -
EAGAIN)
2253 static void nfs4_close_prepare(
struct rpc_task *task,
void *data)
2256 struct nfs4_state *state = calldata->
state;
2257 struct inode *inode = calldata->
inode;
2260 dprintk(
"%s: begin!\n", __func__);
2266 spin_lock(&state->owner->so_lock);
2268 if (state->n_rdwr == 0) {
2269 if (state->n_rdonly == 0) {
2270 call_close |=
test_bit(NFS_O_RDONLY_STATE, &state->flags);
2271 call_close |=
test_bit(NFS_O_RDWR_STATE, &state->flags);
2272 calldata->
arg.fmode &= ~FMODE_READ;
2274 if (state->n_wronly == 0) {
2275 call_close |=
test_bit(NFS_O_WRONLY_STATE, &state->flags);
2276 call_close |=
test_bit(NFS_O_RDWR_STATE, &state->flags);
2280 spin_unlock(&state->owner->so_lock);
2288 if (calldata->
arg.fmode == 0) {
2290 if (calldata->
roc &&
2297 if (nfs4_setup_sequence(NFS_SERVER(inode),
2298 &calldata->
arg.seq_args,
2299 &calldata->
res.seq_res,
2305 dprintk(
"%s: done!\n", __func__);
2309 .rpc_call_prepare = nfs4_close_prepare,
2310 .rpc_call_done = nfs4_close_done,
2311 .rpc_release = nfs4_free_closedata,
2327 struct nfs_server *server = NFS_SERVER(state->inode);
2329 struct nfs4_state_owner *sp = state->owner;
2333 .rpc_cred = state->owner->so_cred,
2337 .rpc_message = &
msg,
2338 .callback_ops = &nfs4_close_ops,
2344 calldata = kzalloc(
sizeof(*calldata), gfp_mask);
2345 if (calldata ==
NULL)
2347 nfs41_init_sequence(&calldata->
arg.seq_args, &calldata->
res.seq_res, 1);
2348 calldata->
inode = state->inode;
2350 calldata->
arg.fh = NFS_FH(state->inode);
2351 calldata->
arg.stateid = &state->open_stateid;
2354 if (calldata->
arg.seqid ==
NULL)
2355 goto out_free_calldata;
2356 calldata->
arg.fmode = 0;
2357 calldata->
arg.bitmask = server->cache_consistency_bitmask;
2358 calldata->
res.fattr = &calldata->
fattr;
2359 calldata->
res.seqid = calldata->
arg.seqid;
2360 calldata->
res.server = server;
2369 return PTR_ERR(task);
2372 status = rpc_wait_for_completion_task(task);
2383 static struct inode *
2386 struct nfs4_state *
state;
2389 state = nfs4_do_open(dir, ctx->
dentry, ctx->
mode, open_flags, attr,
2392 return ERR_CAST(state);
2394 return igrab(state->inode);
2407 static int _nfs4_server_capabilities(
struct nfs_server *server,
struct nfs_fh *fhandle)
2409 struct nfs4_server_caps_arg args = {
2412 struct nfs4_server_caps_res res = {};
2420 status = nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
2422 memcpy(server->attr_bitmask, res.attr_bitmask,
sizeof(server->attr_bitmask));
2430 if (res.has_links != 0)
2432 if (res.has_symlinks != 0)
2451 memcpy(server->cache_consistency_bitmask, res.attr_bitmask,
sizeof(server->cache_consistency_bitmask));
2454 server->acl_bitmask = res.acl_bitmask;
2455 server->fh_expire_type = res.fh_expire_type;
2463 struct nfs4_exception exception = { };
2466 err = nfs4_handle_exception(server,
2467 _nfs4_server_capabilities(server, fhandle),
2469 }
while (exception.retry);
2473 static int _nfs4_lookup_root(
struct nfs_server *server,
struct nfs_fh *fhandle,
2476 struct nfs4_lookup_root_arg args = {
2479 struct nfs4_lookup_res res = {
2481 .fattr = info->
fattr,
2491 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
2494 static int nfs4_lookup_root(
struct nfs_server *server,
struct nfs_fh *fhandle,
2497 struct nfs4_exception exception = { };
2500 err = _nfs4_lookup_root(server, fhandle, info);
2506 err = nfs4_handle_exception(server, err, &exception);
2508 }
while (exception.retry);
2513 static int nfs4_lookup_root_sec(
struct nfs_server *server,
struct nfs_fh *fhandle,
2514 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2516 struct rpc_auth *
auth;
2524 ret = nfs4_lookup_root(server, fhandle, info);
2529 static int nfs4_find_root_sec(
struct nfs_server *server,
struct nfs_fh *fhandle,
2532 int i,
len, status = 0;
2538 for (i = 0; i < len; i++) {
2541 if (flav_array[i] == RPC_AUTH_UNIX)
2544 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2568 int status = nfs4_lookup_root(server, fhandle, info);
2578 status = nfs4_do_fsinfo(server, fhandle, info);
2579 return nfs4_map_errors(status);
2582 static int nfs4_proc_get_root(
struct nfs_server *server,
struct nfs_fh *mntfh,
2590 dprintk(
"nfs4_get_root: getcaps error = %d\n", -error);
2594 error = nfs4_proc_getattr(server, mntfh, fattr);
2596 dprintk(
"nfs4_get_root: getattr error = %d\n", -error);
2601 !nfs_fsid_equal(&server->
fsid, &fattr->
fsid))
2612 static int nfs4_get_referral(
struct rpc_clnt *
client,
struct inode *dir,
2618 struct nfs4_fs_locations *locations =
NULL;
2624 if (locations ==
NULL)
2631 if (nfs_fsid_equal(&NFS_SERVER(dir)->
fsid, &locations->fattr.fsid)) {
2632 dprintk(
"%s: server did not return a different fsid for"
2633 " a referral at %s\n", __func__, name->
name);
2638 nfs_fixup_referral_attributes(&locations->fattr);
2652 struct nfs4_getattr_arg args = {
2654 .bitmask = server->attr_bitmask,
2656 struct nfs4_getattr_res res = {
2667 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
2672 struct nfs4_exception exception = { };
2675 err = nfs4_handle_exception(server,
2676 _nfs4_proc_getattr(server, fhandle, fattr),
2678 }
while (exception.retry);
2700 nfs4_proc_setattr(
struct dentry *dentry,
struct nfs_fattr *fattr,
2701 struct iattr *sattr)
2703 struct inode *inode = dentry->
d_inode;
2704 struct rpc_cred *cred =
NULL;
2705 struct nfs4_state *state =
NULL;
2708 if (pnfs_ld_layoutret_on_setattr(inode))
2709 pnfs_return_layout(inode);
2725 ctx = nfs_file_open_context(sattr->
ia_file);
2732 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2738 static int _nfs4_proc_lookup(
struct rpc_clnt *clnt,
struct inode *dir,
2739 const struct qstr *name,
struct nfs_fh *fhandle,
2744 struct nfs4_lookup_arg args = {
2745 .bitmask = server->attr_bitmask,
2746 .dir_fh = NFS_FH(dir),
2749 struct nfs4_lookup_res res = {
2763 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2764 dprintk(
"NFS reply lookup: %d\n", status);
2768 static void nfs_fixup_secinfo_attributes(
struct nfs_fattr *fattr)
2776 static int nfs4_proc_lookup_common(
struct rpc_clnt **clnt,
struct inode *dir,
2780 struct nfs4_exception exception = { };
2784 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2790 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2794 if (client != *clnt)
2799 return PTR_ERR(client);
2801 exception.retry = 1;
2804 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2806 }
while (exception.retry);
2811 else if (client != *clnt)
2817 static int nfs4_proc_lookup(
struct inode *dir,
struct qstr *name,
2821 struct rpc_clnt *client = NFS_CLIENT(dir);
2823 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2824 if (client != NFS_CLIENT(dir)) {
2826 nfs_fixup_secinfo_attributes(fattr);
2838 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2841 return ERR_PTR(status);
2848 struct nfs_server *server = NFS_SERVER(inode);
2849 struct nfs4_accessargs args = {
2850 .fh = NFS_FH(inode),
2851 .bitmask = server->cache_consistency_bitmask,
2853 struct nfs4_accessres res = {
2860 .rpc_cred = entry->
cred,
2862 int mode = entry->
mask;
2876 if (mode & MAY_WRITE)
2883 if (res.fattr ==
NULL)
2886 status = nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
2891 nfs_free_fattr(res.fattr);
2895 static int nfs4_proc_access(
struct inode *inode,
struct nfs_access_entry *entry)
2897 struct nfs4_exception exception = { };
2900 err = nfs4_handle_exception(NFS_SERVER(inode),
2901 _nfs4_proc_access(inode, entry),
2903 }
while (exception.retry);
2929 static int _nfs4_proc_readlink(
struct inode *inode,
struct page *page,
2930 unsigned int pgbase,
unsigned int pglen)
2932 struct nfs4_readlink args = {
2933 .fh = NFS_FH(inode),
2938 struct nfs4_readlink_res res;
2945 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2948 static int nfs4_proc_readlink(
struct inode *inode,
struct page *page,
2949 unsigned int pgbase,
unsigned int pglen)
2951 struct nfs4_exception exception = { };
2954 err = nfs4_handle_exception(NFS_SERVER(inode),
2955 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2957 }
while (exception.retry);
2965 nfs4_proc_create(
struct inode *dir,
struct dentry *dentry,
struct iattr *sattr,
2969 struct nfs4_state *
state;
2974 return PTR_ERR(ctx);
2977 state = nfs4_do_open(dir, dentry, ctx->
mode,
2978 flags, sattr, ctx->
cred,
2981 if (IS_ERR(state)) {
2982 status = PTR_ERR(state);
2985 d_add(dentry,
igrab(state->inode));
2986 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2993 static int _nfs4_proc_remove(
struct inode *dir,
struct qstr *name)
3012 update_changeattr(dir, &res.
cinfo);
3016 static int nfs4_proc_remove(
struct inode *dir,
struct qstr *name)
3018 struct nfs4_exception exception = { };
3021 err = nfs4_handle_exception(NFS_SERVER(dir),
3022 _nfs4_proc_remove(dir, name),
3024 }
while (exception.retry);
3028 static void nfs4_proc_unlink_setup(
struct rpc_message *msg,
struct inode *dir)
3041 if (nfs4_setup_sequence(NFS_SERVER(data->
dir),
3042 &data->
args.seq_args,
3049 static int nfs4_proc_unlink_done(
struct rpc_task *task,
struct inode *dir)
3053 if (!nfs4_sequence_done(task, &res->
seq_res))
3057 update_changeattr(dir, &res->
cinfo);
3061 static void nfs4_proc_rename_setup(
struct rpc_message *msg,
struct inode *dir)
3074 if (nfs4_setup_sequence(NFS_SERVER(data->
old_dir),
3075 &data->
args.seq_args,
3082 static int nfs4_proc_rename_done(
struct rpc_task *task,
struct inode *old_dir,
3083 struct inode *new_dir)
3087 if (!nfs4_sequence_done(task, &res->
seq_res))
3092 update_changeattr(old_dir, &res->
old_cinfo);
3093 update_changeattr(new_dir, &res->
new_cinfo);
3097 static int _nfs4_proc_rename(
struct inode *old_dir,
struct qstr *old_name,
3098 struct inode *new_dir,
struct qstr *new_name)
3100 struct nfs_server *server = NFS_SERVER(old_dir);
3102 .old_dir = NFS_FH(old_dir),
3103 .new_dir = NFS_FH(new_dir),
3119 update_changeattr(old_dir, &res.
old_cinfo);
3120 update_changeattr(new_dir, &res.
new_cinfo);
3125 static int nfs4_proc_rename(
struct inode *old_dir,
struct qstr *old_name,
3126 struct inode *new_dir,
struct qstr *new_name)
3128 struct nfs4_exception exception = { };
3131 err = nfs4_handle_exception(NFS_SERVER(old_dir),
3132 _nfs4_proc_rename(old_dir, old_name,
3135 }
while (exception.retry);
3139 static int _nfs4_proc_link(
struct inode *inode,
struct inode *dir,
struct qstr *name)
3141 struct nfs_server *server = NFS_SERVER(inode);
3142 struct nfs4_link_arg arg = {
3143 .fh = NFS_FH(inode),
3144 .dir_fh = NFS_FH(dir),
3146 .bitmask = server->attr_bitmask,
3148 struct nfs4_link_res res = {
3159 if (res.fattr ==
NULL)
3162 status = nfs4_call_sync(server->
client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3164 update_changeattr(dir, &res.cinfo);
3168 nfs_free_fattr(res.fattr);
3172 static int nfs4_proc_link(
struct inode *inode,
struct inode *dir,
struct qstr *name)
3174 struct nfs4_exception exception = { };
3177 err = nfs4_handle_exception(NFS_SERVER(inode),
3178 _nfs4_proc_link(inode, dir, name),
3180 }
while (exception.retry);
3186 struct nfs4_create_arg arg;
3187 struct nfs4_create_res res;
3192 static struct nfs4_createdata *nfs4_alloc_createdata(
struct inode *dir,
3202 data->
msg.rpc_argp = &data->
arg;
3203 data->
msg.rpc_resp = &data->
res;
3204 data->
arg.dir_fh = NFS_FH(dir);
3205 data->
arg.server = server;
3207 data->
arg.attrs = sattr;
3208 data->
arg.ftype = ftype;
3209 data->
arg.bitmask = server->attr_bitmask;
3210 data->
res.server = server;
3211 data->
res.fh = &data->
fh;
3218 static int nfs4_do_create(
struct inode *dir,
struct dentry *dentry,
struct nfs4_createdata *data)
3220 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->
msg,
3221 &data->
arg.seq_args, &data->
res.seq_res, 1);
3223 update_changeattr(dir, &data->
res.dir_cinfo);
3234 static int _nfs4_proc_symlink(
struct inode *dir,
struct dentry *dentry,
3235 struct page *page,
unsigned int len,
struct iattr *sattr)
3244 data = nfs4_alloc_createdata(dir, &dentry->
d_name, sattr,
NF4LNK);
3249 data->
arg.u.symlink.pages = &
page;
3250 data->
arg.u.symlink.len = len;
3252 status = nfs4_do_create(dir, dentry, data);
3254 nfs4_free_createdata(data);
3259 static int nfs4_proc_symlink(
struct inode *dir,
struct dentry *dentry,
3260 struct page *page,
unsigned int len,
struct iattr *sattr)
3262 struct nfs4_exception exception = { };
3265 err = nfs4_handle_exception(NFS_SERVER(dir),
3266 _nfs4_proc_symlink(dir, dentry, page,
3269 }
while (exception.retry);
3273 static int _nfs4_proc_mkdir(
struct inode *dir,
struct dentry *dentry,
3274 struct iattr *sattr)
3279 data = nfs4_alloc_createdata(dir, &dentry->
d_name, sattr,
NF4DIR);
3283 status = nfs4_do_create(dir, dentry, data);
3285 nfs4_free_createdata(data);
3290 static int nfs4_proc_mkdir(
struct inode *dir,
struct dentry *dentry,
3291 struct iattr *sattr)
3293 struct nfs4_exception exception = { };
3298 err = nfs4_handle_exception(NFS_SERVER(dir),
3299 _nfs4_proc_mkdir(dir, dentry, sattr),
3301 }
while (exception.retry);
3305 static int _nfs4_proc_readdir(
struct dentry *dentry,
struct rpc_cred *cred,
3306 u64 cookie,
struct page **
pages,
unsigned int count,
int plus)
3308 struct inode *dir = dentry->
d_inode;
3309 struct nfs4_readdir_arg args = {
3314 .bitmask = NFS_SERVER(dentry->
d_inode)->attr_bitmask,
3317 struct nfs4_readdir_res res;
3326 dprintk(
"%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3329 (
unsigned long long)cookie);
3330 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3331 res.pgbase = args.pgbase;
3332 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3335 status += args.pgbase;
3340 dprintk(
"%s: returns %d\n", __func__, status);
3344 static int nfs4_proc_readdir(
struct dentry *dentry,
struct rpc_cred *cred,
3345 u64 cookie,
struct page **pages,
unsigned int count,
int plus)
3347 struct nfs4_exception exception = { };
3350 err = nfs4_handle_exception(NFS_SERVER(dentry->
d_inode),
3351 _nfs4_proc_readdir(dentry, cred, cookie,
3352 pages, count, plus),
3354 }
while (exception.retry);
3358 static int _nfs4_proc_mknod(
struct inode *dir,
struct dentry *dentry,
3368 data = nfs4_alloc_createdata(dir, &dentry->
d_name, sattr,
NF4SOCK);
3376 data->
arg.u.device.specdata1 =
MAJOR(rdev);
3377 data->
arg.u.device.specdata2 =
MINOR(rdev);
3381 data->
arg.u.device.specdata1 =
MAJOR(rdev);
3382 data->
arg.u.device.specdata2 =
MINOR(rdev);
3385 status = nfs4_do_create(dir, dentry, data);
3387 nfs4_free_createdata(data);
3392 static int nfs4_proc_mknod(
struct inode *dir,
struct dentry *dentry,
3395 struct nfs4_exception exception = { };
3400 err = nfs4_handle_exception(NFS_SERVER(dir),
3401 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3403 }
while (exception.retry);
3407 static int _nfs4_proc_statfs(
struct nfs_server *server,
struct nfs_fh *fhandle,
3410 struct nfs4_statfs_arg args = {
3412 .bitmask = server->attr_bitmask,
3414 struct nfs4_statfs_res res = {
3424 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
3429 struct nfs4_exception exception = { };
3432 err = nfs4_handle_exception(server,
3433 _nfs4_proc_statfs(server, fhandle, fsstat),
3435 }
while (exception.retry);
3439 static int _nfs4_do_fsinfo(
struct nfs_server *server,
struct nfs_fh *fhandle,
3442 struct nfs4_fsinfo_arg args = {
3444 .bitmask = server->attr_bitmask,
3446 struct nfs4_fsinfo_res res = {
3455 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
3460 struct nfs4_exception exception = { };
3464 err = nfs4_handle_exception(server,
3465 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3467 }
while (exception.retry);
3476 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3486 static int _nfs4_proc_pathconf(
struct nfs_server *server,
struct nfs_fh *fhandle,
3489 struct nfs4_pathconf_arg args = {
3491 .bitmask = server->attr_bitmask,
3493 struct nfs4_pathconf_res res = {
3494 .pathconf = pathconf,
3503 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3504 memset(pathconf, 0,
sizeof(*pathconf));
3509 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
3512 static int nfs4_proc_pathconf(
struct nfs_server *server,
struct nfs_fh *fhandle,
3515 struct nfs4_exception exception = { };
3519 err = nfs4_handle_exception(server,
3520 _nfs4_proc_pathconf(server, fhandle, pathconf),
3522 }
while (exception.retry);
3535 if (nfs4_async_handle_error(task, server, data->
args.context->state) == -
EAGAIN) {
3549 dprintk(
"--> %s\n", __func__);
3551 if (!nfs4_sequence_done(task, &data->
res.seq_res))
3555 nfs4_read_done_cb(task, data);
3563 nfs41_init_sequence(&data->
args.seq_args, &data->
res.seq_res, 0);
3568 if (nfs4_setup_sequence(NFS_SERVER(data->
header->inode),
3569 &data->
args.seq_args,
3578 struct inode *inode = data->
header->inode;
3580 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->
args.context->state) == -
EAGAIN) {
3585 renew_lease(NFS_SERVER(inode), data->
timestamp);
3593 if (!nfs4_sequence_done(task, &data->
res.seq_res))
3596 nfs4_write_done_cb(task, data);
3600 bool nfs4_write_need_cache_consistency_data(
const struct nfs_write_data *data)
3617 if (!nfs4_write_need_cache_consistency_data(data)) {
3621 data->
args.bitmask = server->cache_consistency_bitmask;
3625 data->
res.server = server;
3629 nfs41_init_sequence(&data->
args.seq_args, &data->
res.seq_res, 1);
3634 if (nfs4_setup_sequence(NFS_SERVER(data->
header->inode),
3635 &data->
args.seq_args,
3644 if (nfs4_setup_sequence(NFS_SERVER(data->
inode),
3645 &data->
args.seq_args,
3654 struct inode *inode = data->
inode;
3656 if (nfs4_async_handle_error(task, NFS_SERVER(inode),
NULL) == -
EAGAIN) {
3665 if (!nfs4_sequence_done(task, &data->
res.seq_res))
3676 data->
res.server = server;
3678 nfs41_init_sequence(&data->
args.seq_args, &data->
res.seq_res, 1);
3690 static void nfs4_renew_release(
void *calldata)
3701 static void nfs4_renew_done(
struct rpc_task *task,
void *calldata)
3705 unsigned long timestamp = data->
timestamp;
3717 do_renew_lease(clp, timestamp);
3721 .rpc_call_done = nfs4_renew_done,
3722 .rpc_release = nfs4_renew_release,
3725 static int nfs4_proc_async_renew(
struct nfs_client *clp,
struct rpc_cred *cred,
unsigned renew_flags)
3734 if (renew_flags == 0)
3744 &nfs4_renew_ops, data);
3747 static int nfs4_proc_renew(
struct nfs_client *clp,
struct rpc_cred *cred)
3760 do_renew_lease(clp, now);
3764 static inline int nfs4_server_supports_acls(
struct nfs_server *server)
3775 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
3777 static int buf_to_pages_noslab(
const void *
buf,
size_t buflen,
3778 struct page **pages,
unsigned int *pgbase)
3780 struct page *newpage, **spages;
3789 if (newpage ==
NULL)
3796 }
while (buflen != 0);
3812 static void nfs4_set_cached_acl(
struct inode *inode,
struct nfs4_cached_acl *acl)
3816 spin_lock(&inode->
i_lock);
3817 kfree(nfsi->nfs4_acl);
3818 nfsi->nfs4_acl = acl;
3819 spin_unlock(&inode->
i_lock);
3822 static void nfs4_zap_acl_attr(
struct inode *inode)
3824 nfs4_set_cached_acl(inode,
NULL);
3827 static inline ssize_t nfs4_read_cached_acl(
struct inode *inode,
char *
buf,
size_t buflen)
3833 spin_lock(&inode->
i_lock);
3834 acl = nfsi->nfs4_acl;
3842 if (acl->
len > buflen)
3848 spin_unlock(&inode->
i_lock);
3852 static void nfs4_write_cached_acl(
struct inode *inode,
struct page **pages,
size_t pgbase,
size_t acl_len)
3855 size_t buflen =
sizeof(*acl) + acl_len;
3871 nfs4_set_cached_acl(inode, acl);
3884 static ssize_t __nfs4_get_acl_uncached(
struct inode *inode,
void *buf,
size_t buflen)
3888 .
fh = NFS_FH(inode),
3910 for (i = 0; i < npages; i++) {
3924 dprintk(
"%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3925 __func__, buf, buflen, npages, args.
acl_len);
3926 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
3945 for (i = 0; i < npages; i++)
3953 static ssize_t nfs4_get_acl_uncached(
struct inode *inode,
void *buf,
size_t buflen)
3955 struct nfs4_exception exception = { };
3958 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3961 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3962 }
while (exception.retry);
3966 static ssize_t nfs4_proc_get_acl(
struct inode *inode,
void *buf,
size_t buflen)
3968 struct nfs_server *server = NFS_SERVER(inode);
3971 if (!nfs4_server_supports_acls(server))
3978 ret = nfs4_read_cached_acl(inode, buf, buflen);
3983 return nfs4_get_acl_uncached(inode, buf, buflen);
3986 static int __nfs4_proc_set_acl(
struct inode *inode,
const void *buf,
size_t buflen)
3988 struct nfs_server *server = NFS_SERVER(inode);
3991 .
fh = NFS_FH(inode),
4004 if (!nfs4_server_supports_acls(server))
4025 spin_lock(&inode->
i_lock);
4027 spin_unlock(&inode->
i_lock);
4033 static int nfs4_proc_set_acl(
struct inode *inode,
const void *buf,
size_t buflen)
4035 struct nfs4_exception exception = { };
4038 err = nfs4_handle_exception(NFS_SERVER(inode),
4039 __nfs4_proc_set_acl(inode, buf, buflen),
4041 }
while (exception.retry);
4046 nfs4_async_handle_error(
struct rpc_task *task,
const struct nfs_server *server,
struct nfs4_state *state)
4063 goto wait_on_recovery;
4070 goto wait_on_recovery;
4071 #if defined(CONFIG_NFS_V4_1)
4079 dprintk(
"%s ERROR %d, Reset session\n", __func__,
4081 nfs4_schedule_session_recovery(clp->cl_session, task->
tk_status);
4101 if (
test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4107 static void nfs4_init_boot_verifier(
const struct nfs_client *clp,
4112 if (
test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4126 nfs4_init_nonuniform_client_string(
const struct nfs_client *clp,
4127 char *buf,
size_t len)
4132 result =
scnprintf(buf, len,
"Linux NFSv4.0 %s/%s %s",
4137 RPC_DISPLAY_PROTO));
4143 nfs4_init_uniform_client_string(
const struct nfs_client *clp,
4144 char *buf,
size_t len)
4148 if (nfs4_client_id_uniquifier[0] !=
'\0')
4149 nodename = nfs4_client_id_uniquifier;
4150 return scnprintf(buf, len,
"Linux NFSv%u.%u %s",
4166 unsigned short port,
struct rpc_cred *cred,
4167 struct nfs4_setclientid_res *res)
4170 struct nfs4_setclientid setclientid = {
4171 .sc_verifier = &sc_verifier,
4173 .sc_cb_ident = clp->cl_cb_ident,
4177 .rpc_argp = &setclientid,
4184 nfs4_init_boot_verifier(clp, &sc_verifier);
4186 setclientid.sc_name_len =
4187 nfs4_init_uniform_client_string(clp,
4188 setclientid.sc_name,
4189 sizeof(setclientid.sc_name));
4191 setclientid.sc_name_len =
4192 nfs4_init_nonuniform_client_string(clp,
4193 setclientid.sc_name,
4194 sizeof(setclientid.sc_name));
4197 setclientid.sc_netid_len =
scnprintf(setclientid.sc_netid,
4198 sizeof(setclientid.sc_netid),
4200 RPC_DISPLAY_NETID));
4202 setclientid.sc_uaddr_len =
scnprintf(setclientid.sc_uaddr,
4203 sizeof(setclientid.sc_uaddr),
"%s.%u.%u",
4204 clp->cl_ipaddr, port >> 8, port & 255);
4206 dprintk(
"NFS call setclientid auth=%s, '%.*s'\n",
4208 setclientid.sc_name_len, setclientid.sc_name);
4210 dprintk(
"NFS reply setclientid: %d\n", status);
4223 struct nfs4_setclientid_res *arg,
4230 .rpc_resp = &fsinfo,
4236 dprintk(
"NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4242 spin_lock(&clp->cl_lock);
4244 clp->cl_last_renewal = now;
4245 spin_unlock(&clp->cl_lock);
4247 dprintk(
"NFS reply setclientid_confirm: %d\n", status);
4261 static void nfs4_delegreturn_done(
struct rpc_task *task,
void *calldata)
4265 if (!nfs4_sequence_done(task, &data->
res.seq_res))
4275 if (nfs4_async_handle_error(task, data->
res.server,
NULL) ==
4284 static void nfs4_delegreturn_release(
void *calldata)
4289 #if defined(CONFIG_NFS_V4_1)
4290 static void nfs4_delegreturn_prepare(
struct rpc_task *task,
void *data)
4296 if (nfs4_setup_sequence(d_data->
res.server,
4297 &d_data->
args.seq_args,
4298 &d_data->
res.seq_res, task))
4304 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4305 #if defined(CONFIG_NFS_V4_1)
4306 .rpc_call_prepare = nfs4_delegreturn_prepare,
4308 .rpc_call_done = nfs4_delegreturn_done,
4309 .rpc_release = nfs4_delegreturn_release,
4312 static int _nfs4_proc_delegreturn(
struct inode *inode,
struct rpc_cred *cred,
const nfs4_stateid *stateid,
int issync)
4315 struct nfs_server *server = NFS_SERVER(inode);
4323 .rpc_message = &
msg,
4324 .callback_ops = &nfs4_delegreturn_ops,
4329 data = kzalloc(
sizeof(*data),
GFP_NOFS);
4332 nfs41_init_sequence(&data->
args.seq_args, &data->
res.seq_res, 1);
4333 data->
args.fhandle = &data->
fh;
4335 data->
args.bitmask = server->cache_consistency_bitmask;
4336 nfs_copy_fh(&data->
fh, NFS_FH(inode));
4337 nfs4_stateid_copy(&data->
stateid, stateid);
4339 data->
res.server = server;
4349 return PTR_ERR(task);
4352 status = nfs4_wait_for_completion_rpc_task(task);
4367 struct nfs_server *server = NFS_SERVER(inode);
4368 struct nfs4_exception exception = { };
4371 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4378 err = nfs4_handle_exception(server, err, &exception);
4379 }
while (exception.retry);
4383 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4384 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4389 static unsigned long
4390 nfs4_set_lock_task_retry(
unsigned long timeout)
4401 struct inode *inode = state->inode;
4402 struct nfs_server *server = NFS_SERVER(inode);
4405 .
fh = NFS_FH(inode),
4415 .rpc_cred = state->owner->so_cred,
4435 request->
fl_ops->fl_release_private(request);
4440 static int nfs4_proc_getlk(
struct nfs4_state *state,
int cmd,
struct file_lock *request)
4442 struct nfs4_exception exception = { };
4446 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4447 _nfs4_proc_getlk(state, cmd, request),
4449 }
while (exception.retry);
4482 struct nfs_seqid *
seqid)
4485 struct inode *inode = lsp->ls_state->inode;
4490 p->
arg.fh = NFS_FH(inode);
4494 p->
arg.stateid = &lsp->ls_stateid;
4500 p->
server = NFS_SERVER(inode);
4504 static void nfs4_locku_release_calldata(
void *data)
4513 static void nfs4_locku_done(
struct rpc_task *task,
void *data)
4517 if (!nfs4_sequence_done(task, &calldata->
res.seq_res))
4521 nfs4_stateid_copy(&calldata->
lsp->ls_stateid,
4522 &calldata->
res.stateid);
4537 static void nfs4_locku_prepare(
struct rpc_task *task,
void *data)
4543 if (
test_bit(NFS_LOCK_INITIALIZED, &calldata->
lsp->ls_flags) == 0) {
4549 if (nfs4_setup_sequence(calldata->
server,
4550 &calldata->
arg.seq_args,
4551 &calldata->
res.seq_res,
4559 .rpc_call_prepare = nfs4_locku_prepare,
4560 .rpc_call_done = nfs4_locku_done,
4561 .rpc_release = nfs4_locku_release_calldata,
4567 struct nfs_seqid *
seqid)
4572 .rpc_cred = ctx->
cred,
4575 .
rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4576 .rpc_message = &
msg,
4577 .callback_ops = &nfs4_locku_ops,
4587 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4593 nfs41_init_sequence(&data->
arg.seq_args, &data->
res.seq_res, 1);
4600 static int nfs4_proc_unlck(
struct nfs4_state *state,
int cmd,
struct file_lock *request)
4602 struct nfs_inode *nfsi = NFS_I(state->inode);
4603 struct nfs_seqid *
seqid;
4607 unsigned char fl_flags = request->
fl_flags;
4621 if (
test_bit(NFS_DELEGATED_STATE, &state->flags))
4628 task = nfs4_do_unlck(request, nfs_file_open_context(request->
fl_file), lsp, seqid);
4629 status = PTR_ERR(task);
4632 status = nfs4_wait_for_completion_rpc_task(task);
4656 struct inode *inode = lsp->ls_state->inode;
4657 struct nfs_server *server = NFS_SERVER(inode);
4659 p = kzalloc(
sizeof(*p), gfp_mask);
4663 p->
arg.fh = NFS_FH(inode);
4666 if (p->
arg.open_seqid ==
NULL)
4669 if (p->
arg.lock_seqid ==
NULL)
4670 goto out_free_seqid;
4671 p->
arg.lock_stateid = &lsp->ls_stateid;
4672 p->
arg.lock_owner.clientid = server->
nfs_client->cl_clientid;
4673 p->
arg.lock_owner.id = lsp->ls_seqid.owner_id;
4674 p->
arg.lock_owner.s_dev = server->
s_dev;
4675 p->
res.lock_seqid = p->
arg.lock_seqid;
4689 static void nfs4_lock_prepare(
struct rpc_task *task,
void *calldata)
4692 struct nfs4_state *state = data->
lsp->ls_state;
4694 dprintk(
"%s: begin!\n", __func__);
4698 if (!(data->
arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4700 goto out_release_lock_seqid;
4701 data->
arg.open_stateid = &state->stateid;
4702 data->
arg.new_lock_owner = 1;
4703 data->
res.open_seqid = data->
arg.open_seqid;
4705 data->
arg.new_lock_owner = 0;
4707 if (nfs4_setup_sequence(data->
server,
4708 &data->
arg.seq_args,
4715 out_release_lock_seqid:
4720 static void nfs4_recover_lock_prepare(
struct rpc_task *task,
void *calldata)
4723 nfs4_lock_prepare(task, calldata);
4726 static void nfs4_lock_done(
struct rpc_task *task,
void *calldata)
4730 dprintk(
"%s: begin!\n", __func__);
4732 if (!nfs4_sequence_done(task, &data->
res.seq_res))
4736 if (data->
arg.new_lock_owner != 0) {
4738 nfs_confirm_seqid(&data->
lsp->ls_seqid, 0);
4743 nfs4_stateid_copy(&data->
lsp->ls_stateid, &data->
res.stateid);
4744 set_bit(NFS_LOCK_INITIALIZED, &data->
lsp->ls_flags);
4745 renew_lease(NFS_SERVER(data->
ctx->dentry->d_inode), data->
timestamp);
4751 static void nfs4_lock_release(
void *calldata)
4755 dprintk(
"%s: begin!\n", __func__);
4759 task = nfs4_do_unlck(&data->
fl, data->
ctx, data->
lsp,
4760 data->
arg.lock_seqid);
4763 dprintk(
"%s: cancelling lock!\n", __func__);
4769 dprintk(
"%s: done!\n", __func__);
4773 .rpc_call_prepare = nfs4_lock_prepare,
4774 .rpc_call_done = nfs4_lock_done,
4775 .rpc_release = nfs4_lock_release,
4778 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4779 .rpc_call_prepare = nfs4_recover_lock_prepare,
4780 .rpc_call_done = nfs4_lock_done,
4781 .rpc_release = nfs4_lock_release,
4784 static void nfs4_handle_setlk_error(
struct nfs_server *server,
struct nfs4_lock_state *lsp,
int new_lock_owner,
int error)
4789 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4790 if (new_lock_owner != 0 ||
4791 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
4795 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4801 static int _nfs4_do_setlk(
struct nfs4_state *state,
int cmd,
struct file_lock *fl,
int recovery_type)
4807 .rpc_cred = state->owner->so_cred,
4811 .rpc_message = &
msg,
4812 .callback_ops = &nfs4_lock_ops,
4818 dprintk(
"%s: begin!\n", __func__);
4819 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->
fl_file),
4825 data->
arg.block = 1;
4826 if (recovery_type > NFS_LOCK_NEW) {
4827 if (recovery_type == NFS_LOCK_RECLAIM)
4828 data->
arg.reclaim = NFS_LOCK_RECLAIM;
4831 nfs41_init_sequence(&data->
arg.seq_args, &data->
res.seq_res, 1);
4837 return PTR_ERR(task);
4838 ret = nfs4_wait_for_completion_rpc_task(task);
4842 nfs4_handle_setlk_error(data->
server, data->
lsp,
4843 data->
arg.new_lock_owner, ret);
4847 dprintk(
"%s: done, ret = %d!\n", __func__, ret);
4851 static int nfs4_lock_reclaim(
struct nfs4_state *state,
struct file_lock *request)
4853 struct nfs_server *server = NFS_SERVER(state->inode);
4854 struct nfs4_exception exception = {
4855 .inode = state->inode,
4861 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4863 err = _nfs4_do_setlk(state,
F_SETLK, request, NFS_LOCK_RECLAIM);
4866 nfs4_handle_exception(server, err, &exception);
4867 }
while (exception.retry);
4871 static int nfs4_lock_expired(
struct nfs4_state *state,
struct file_lock *request)
4873 struct nfs_server *server = NFS_SERVER(state->inode);
4874 struct nfs4_exception exception = {
4875 .inode = state->inode,
4883 if (
test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4885 err = _nfs4_do_setlk(state,
F_SETLK, request, NFS_LOCK_EXPIRED);
4891 nfs4_handle_exception(server, err, &exception);
4894 }
while (exception.retry);
4899 #if defined(CONFIG_NFS_V4_1)
4908 static int nfs41_check_expired_locks(
struct nfs4_state *state)
4912 struct nfs_server *server = NFS_SERVER(state->inode);
4915 if (
test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
4916 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4921 nfs41_free_stateid(server,
4923 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
4932 static int nfs41_lock_expired(
struct nfs4_state *state,
struct file_lock *request)
4936 if (
test_bit(LK_STATE_IN_USE, &state->flags))
4937 status = nfs41_check_expired_locks(state);
4939 status = nfs4_lock_expired(state, request);
4944 static int _nfs4_proc_setlk(
struct nfs4_state *state,
int cmd,
struct file_lock *request)
4946 struct nfs_inode *nfsi = NFS_I(state->inode);
4947 unsigned char fl_flags = request->
fl_flags;
4951 !
test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4958 status = do_vfs_lock(request->
fl_file, request);
4962 if (
test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4966 status = do_vfs_lock(request->
fl_file, request);
4969 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4974 if (do_vfs_lock(request->
fl_file, request) < 0)
4976 "manager!\n", __func__);
4984 static int nfs4_proc_setlk(
struct nfs4_state *state,
int cmd,
struct file_lock *request)
4986 struct nfs4_exception exception = {
4988 .inode = state->inode,
4993 err = _nfs4_proc_setlk(state, cmd, request);
4996 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4998 }
while (exception.retry);
5003 nfs4_proc_lock(
struct file *filp,
int cmd,
struct file_lock *request)
5006 struct nfs4_state *
state;
5011 ctx = nfs_file_open_context(filp);
5019 return nfs4_proc_getlk(state,
F_GETLK, request);
5028 return nfs4_proc_unlck(state, cmd, request);
5040 if (!(filp->
f_mode & FMODE_READ))
5049 status = nfs4_proc_setlk(state, cmd, request);
5052 timeout = nfs4_set_lock_task_retry(timeout);
5056 }
while(status < 0);
5062 struct nfs_server *server = NFS_SERVER(state->inode);
5063 struct nfs4_exception exception = { };
5070 err = _nfs4_do_setlk(state,
F_SETLK, fl, NFS_LOCK_NEW);
5074 "%d.\n", __func__, err);
5089 nfs4_schedule_session_recovery(server->
nfs_client->cl_session, err);
5120 err = nfs4_handle_exception(server, err, &exception);
5121 }
while (exception.retry);
5132 static void nfs4_release_lockowner_release(
void *calldata)
5139 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5140 .rpc_release = nfs4_release_lockowner_release,
5145 struct nfs_server *server = lsp->ls_state->owner->so_server;
5151 if (server->
nfs_client->cl_mvops->minor_version != 0)
5158 data->
args.lock_owner.clientid = server->
nfs_client->cl_clientid;
5159 data->
args.lock_owner.id = lsp->ls_seqid.owner_id;
5160 data->
args.lock_owner.s_dev = server->
s_dev;
5166 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5168 static int nfs4_xattr_set_nfs4_acl(
struct dentry *dentry,
const char *
key,
5169 const void *buf,
size_t buflen,
5170 int flags,
int type)
5172 if (
strcmp(key,
"") != 0)
5175 return nfs4_proc_set_acl(dentry->
d_inode, buf, buflen);
5178 static int nfs4_xattr_get_nfs4_acl(
struct dentry *dentry,
const char *
key,
5179 void *buf,
size_t buflen,
int type)
5181 if (
strcmp(key,
"") != 0)
5184 return nfs4_proc_get_acl(dentry->
d_inode, buf, buflen);
5187 static size_t nfs4_xattr_list_nfs4_acl(
struct dentry *dentry,
char *
list,
5193 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->
d_inode)))
5196 if (list && len <= list_len)
5204 static void nfs_fixup_referral_attributes(
struct nfs_fattr *fattr)
5218 static int _nfs4_proc_fs_locations(
struct rpc_clnt *client,
struct inode *dir,
5219 const struct qstr *name,
5220 struct nfs4_fs_locations *fs_locations,
5227 struct nfs4_fs_locations_arg args = {
5228 .dir_fh = NFS_FH(dir),
5233 struct nfs4_fs_locations_res res = {
5234 .fs_locations = fs_locations,
5243 dprintk(
"%s: start\n", __func__);
5253 fs_locations->server = server;
5254 fs_locations->nlocations = 0;
5255 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5256 dprintk(
"%s: returned status = %d\n", __func__, status);
5261 const struct qstr *name,
5262 struct nfs4_fs_locations *fs_locations,
5265 struct nfs4_exception exception = { };
5268 err = nfs4_handle_exception(NFS_SERVER(dir),
5269 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5271 }
while (exception.retry);
5275 static int _nfs4_proc_secinfo(
struct inode *dir,
const struct qstr *name,
struct nfs4_secinfo_flavors *flavors)
5278 struct nfs4_secinfo_arg args = {
5279 .dir_fh = NFS_FH(dir),
5282 struct nfs4_secinfo_res res = {
5292 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
5293 dprintk(
"NFS reply secinfo: %d\n", status);
5298 struct nfs4_secinfo_flavors *flavors)
5300 struct nfs4_exception exception = { };
5303 err = nfs4_handle_exception(NFS_SERVER(dir),
5304 _nfs4_proc_secinfo(dir, name, flavors),
5306 }
while (exception.retry);
5310 #ifdef CONFIG_NFS_V4_1
5316 static int nfs4_check_cl_exchange_flags(
u32 flags)
5331 nfs41_same_server_scope(
struct nfs41_server_scope *
a,
5332 struct nfs41_server_scope *
b)
5334 if (a->server_scope_sz == b->server_scope_sz &&
5335 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5347 int nfs4_proc_bind_conn_to_session(
struct nfs_client *clp,
struct rpc_cred *cred)
5350 struct nfs41_bind_conn_to_session_res res;
5359 dprintk(
"--> %s\n", __func__);
5362 res.session = kzalloc(
sizeof(
struct nfs4_session),
GFP_NOFS);
5370 if (
memcmp(res.session->sess_id.data,
5372 dprintk(
"NFS: %s: Session ID mismatch\n", __func__);
5377 dprintk(
"NFS: %s: Unexpected direction from server\n",
5382 if (res.use_conn_in_rdma_mode) {
5383 dprintk(
"NFS: %s: Server returned RDMA mode = true\n",
5392 dprintk(
"<-- %s status= %d\n", __func__, status);
5409 struct nfs41_exchange_id_args args = {
5410 .verifier = &verifier,
5414 struct nfs41_exchange_id_res res = {
5425 nfs4_init_boot_verifier(clp, &verifier);
5426 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
5428 dprintk(
"NFS call exchange_id auth=%s, '%.*s'\n",
5430 args.id_len, args.id);
5432 res.server_owner = kzalloc(
sizeof(
struct nfs41_server_owner),
5439 res.server_scope = kzalloc(
sizeof(
struct nfs41_server_scope),
5443 goto out_server_owner;
5446 res.impl_id = kzalloc(
sizeof(
struct nfs41_impl_id),
GFP_NOFS);
5449 goto out_server_scope;
5454 status = nfs4_check_cl_exchange_flags(res.flags);
5457 clp->cl_clientid = res.clientid;
5460 clp->cl_seqid = res.seqid;
5462 kfree(clp->cl_serverowner);
5463 clp->cl_serverowner = res.server_owner;
5464 res.server_owner =
NULL;
5467 kfree(clp->cl_implid);
5468 clp->cl_implid = res.impl_id;
5470 if (clp->cl_serverscope !=
NULL &&
5471 !nfs41_same_server_scope(clp->cl_serverscope,
5472 res.server_scope)) {
5473 dprintk(
"%s: server_scope mismatch detected\n",
5475 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
5476 kfree(clp->cl_serverscope);
5477 clp->cl_serverscope =
NULL;
5480 if (clp->cl_serverscope ==
NULL) {
5481 clp->cl_serverscope = res.server_scope;
5488 kfree(res.server_owner);
5490 kfree(res.server_scope);
5492 if (clp->cl_implid !=
NULL)
5493 dprintk(
"NFS reply exchange_id: Server Implementation ID: "
5494 "domain: %s, name: %s, date: %llu,%u\n",
5495 clp->cl_implid->domain, clp->cl_implid->name,
5496 clp->cl_implid->date.seconds,
5497 clp->cl_implid->date.nseconds);
5498 dprintk(
"NFS reply exchange_id: %d\n", status);
5502 static int _nfs4_proc_destroy_clientid(
struct nfs_client *clp,
5514 dprintk(
"NFS: Got error %d from the server %s on "
5519 static int nfs4_proc_destroy_clientid(
struct nfs_client *clp,
5526 ret = _nfs4_proc_destroy_clientid(clp, cred);
5539 int nfs4_destroy_clientid(
struct nfs_client *clp)
5541 struct rpc_cred *cred;
5544 if (clp->cl_mvops->minor_version < 1)
5546 if (clp->cl_exchange_flags == 0)
5548 if (clp->cl_preserve_clid)
5550 cred = nfs4_get_exchange_id_cred(clp);
5551 ret = nfs4_proc_destroy_clientid(clp, cred);
5557 clp->cl_exchange_flags = 0;
5563 struct nfs4_get_lease_time_data {
5569 static void nfs4_get_lease_time_prepare(
struct rpc_task *task,
5573 struct nfs4_get_lease_time_data *data =
5574 (
struct nfs4_get_lease_time_data *)calldata;
5576 dprintk(
"--> %s\n", __func__);
5580 ret = nfs41_setup_sequence(data->clp->cl_session,
5581 &data->args->la_seq_args,
5582 &data->res->lr_seq_res, task);
5586 dprintk(
"<-- %s\n", __func__);
5593 static void nfs4_get_lease_time_done(
struct rpc_task *task,
void *calldata)
5595 struct nfs4_get_lease_time_data *data =
5596 (
struct nfs4_get_lease_time_data *)calldata;
5598 dprintk(
"--> %s\n", __func__);
5599 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
5612 dprintk(
"<-- %s\n", __func__);
5615 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
5617 .rpc_call_done = nfs4_get_lease_time_done,
5627 struct nfs4_get_lease_time_data data = {
5639 .rpc_message = &
msg,
5640 .callback_ops = &nfs4_get_lease_time_ops,
5641 .callback_data = &
data,
5646 nfs41_init_sequence(&args.la_seq_args, &res.
lr_seq_res, 0);
5647 dprintk(
"--> %s\n", __func__);
5651 status = PTR_ERR(task);
5656 dprintk(
"<-- %s return %d\n", __func__, status);
5663 return kcalloc(max_slots,
sizeof(
struct nfs4_slot), gfp_flags);
5666 static void nfs4_add_and_init_slots(
struct nfs4_slot_table *tbl,
5674 spin_lock(&tbl->slot_tbl_lock);
5678 tbl->max_slots = max_slots;
5681 for (i = 0; i < tbl->max_slots; i++)
5682 tbl->slots[i].seq_nr = ivalue;
5683 spin_unlock(&tbl->slot_tbl_lock);
5690 static int nfs4_realloc_slot_table(
struct nfs4_slot_table *tbl,
u32 max_reqs,
5696 dprintk(
"--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
5697 max_reqs, tbl->max_slots);
5700 if (max_reqs != tbl->max_slots) {
5701 new = nfs4_alloc_slots(max_reqs,
GFP_NOFS);
5707 nfs4_add_and_init_slots(tbl,
new, max_reqs, ivalue);
5708 dprintk(
"%s: tbl=%p slots=%p max_slots=%d\n", __func__,
5709 tbl, tbl->slots, tbl->max_slots);
5711 dprintk(
"<-- %s: return %d\n", __func__, ret);
5716 static void nfs4_destroy_slot_tables(
struct nfs4_session *session)
5718 if (session->fc_slot_table.slots !=
NULL) {
5719 kfree(session->fc_slot_table.slots);
5720 session->fc_slot_table.slots =
NULL;
5722 if (session->bc_slot_table.slots !=
NULL) {
5723 kfree(session->bc_slot_table.slots);
5724 session->bc_slot_table.slots =
NULL;
5732 static int nfs4_setup_session_slot_tables(
struct nfs4_session *ses)
5734 struct nfs4_slot_table *tbl;
5737 dprintk(
"--> %s\n", __func__);
5739 tbl = &ses->fc_slot_table;
5740 status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
5744 tbl = &ses->bc_slot_table;
5745 status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
5746 if (status && tbl->slots ==
NULL)
5749 nfs4_destroy_slot_tables(ses);
5753 struct nfs4_session *nfs4_alloc_session(
struct nfs_client *clp)
5755 struct nfs4_session *session;
5756 struct nfs4_slot_table *tbl;
5758 session = kzalloc(
sizeof(
struct nfs4_session),
GFP_NOFS);
5762 tbl = &session->fc_slot_table;
5766 init_completion(&tbl->complete);
5768 tbl = &session->bc_slot_table;
5772 init_completion(&tbl->complete);
5774 session->session_state = 1<<NFS4_SESSION_INITING;
5780 void nfs4_destroy_session(
struct nfs4_session *session)
5782 struct rpc_xprt *xprt;
5783 struct rpc_cred *cred;
5785 cred = nfs4_get_exchange_id_cred(session->clp);
5786 nfs4_proc_destroy_session(session, cred);
5793 dprintk(
"%s Destroy backchannel for xprt %p\n",
5796 nfs4_destroy_slot_tables(session);
5809 static void nfs4_init_channel_attrs(
struct nfs41_create_session_args *args)
5811 struct nfs4_session *session = args->client->cl_session;
5812 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
5813 mxresp_sz = session->fc_attrs.max_resp_sz;
5820 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5821 args->fc_attrs.max_resp_sz = mxresp_sz;
5823 args->fc_attrs.max_reqs = max_session_slots;
5825 dprintk(
"%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5826 "max_ops=%u max_reqs=%u\n",
5828 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5829 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5834 args->bc_attrs.max_resp_sz_cached = 0;
5836 args->bc_attrs.max_reqs = 1;
5838 dprintk(
"%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5839 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5841 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5842 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5843 args->bc_attrs.max_reqs);
5846 static int nfs4_verify_fore_channel_attrs(
struct nfs41_create_session_args *args,
struct nfs4_session *session)
5868 static int nfs4_verify_back_channel_attrs(
struct nfs41_create_session_args *args,
struct nfs4_session *session)
5887 static int nfs4_verify_channel_attrs(
struct nfs41_create_session_args *args,
5888 struct nfs4_session *session)
5892 ret = nfs4_verify_fore_channel_attrs(args, session);
5895 return nfs4_verify_back_channel_attrs(args, session);
5898 static int _nfs4_proc_create_session(
struct nfs_client *clp,
5899 struct rpc_cred *cred)
5901 struct nfs4_session *session = clp->cl_session;
5902 struct nfs41_create_session_args args = {
5906 struct nfs41_create_session_res res = {
5917 nfs4_init_channel_attrs(&args);
5924 status = nfs4_verify_channel_attrs(&args, session);
5942 struct nfs4_session *session = clp->cl_session;
5944 dprintk(
"--> %s clp=%p session=%p\n", __func__, clp, session);
5946 status = _nfs4_proc_create_session(clp, cred);
5951 status = nfs4_setup_session_slot_tables(session);
5952 dprintk(
"slot table setup returned %d\n", status);
5956 ptr = (
unsigned *)&session->sess_id.data[0];
5957 dprintk(
"%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5958 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5960 dprintk(
"<-- %s\n", __func__);
5968 int nfs4_proc_destroy_session(
struct nfs4_session *session,
5969 struct rpc_cred *cred)
5973 .rpc_argp = session,
5978 dprintk(
"--> nfs4_proc_destroy_session\n");
5987 dprintk(
"NFS: Got error %d from the server on DESTROY_SESSION. "
5988 "Session has been destroyed regardless...\n", status);
5990 dprintk(
"<-- nfs4_proc_destroy_session\n");
6001 static int nfs41_check_session_ready(
struct nfs_client *clp)
6006 ret = nfs4_client_recover_expired_lease(clp);
6016 int nfs4_init_session(
struct nfs_server *server)
6019 struct nfs4_session *session;
6020 unsigned int rsize, wsize;
6022 if (!nfs4_has_session(clp))
6025 session = clp->cl_session;
6026 spin_lock(&clp->cl_lock);
6029 rsize = server->
rsize;
6032 wsize = server->
wsize;
6036 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
6037 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
6039 spin_unlock(&clp->cl_lock);
6041 return nfs41_check_session_ready(clp);
6046 struct nfs4_session *session = clp->cl_session;
6049 spin_lock(&clp->cl_lock);
6055 clp->cl_lease_time = lease_time;
6056 clp->cl_last_renewal =
jiffies;
6058 spin_unlock(&clp->cl_lock);
6060 ret = nfs41_check_session_ready(clp);
6064 if (!is_ds_client(clp))
6074 struct nfs4_sequence_data {
6080 static void nfs41_sequence_release(
void *data)
6082 struct nfs4_sequence_data *calldata =
data;
6091 static int nfs41_sequence_handle_errors(
struct rpc_task *task,
struct nfs_client *clp)
6103 static void nfs41_sequence_call_done(
struct rpc_task *task,
void *data)
6105 struct nfs4_sequence_data *calldata =
data;
6108 if (!nfs41_sequence_done(task, task->
tk_msg.rpc_resp))
6116 if (nfs41_sequence_handle_errors(task, clp) == -
EAGAIN) {
6121 dprintk(
"%s rpc_cred %p\n", __func__, task->
tk_msg.rpc_cred);
6123 dprintk(
"<-- %s\n", __func__);
6126 static void nfs41_sequence_prepare(
struct rpc_task *task,
void *data)
6128 struct nfs4_sequence_data *calldata =
data;
6133 args = task->
tk_msg.rpc_argp;
6134 res = task->
tk_msg.rpc_resp;
6136 if (nfs41_setup_sequence(clp->cl_session, args, res, task))
6141 static const struct rpc_call_ops nfs41_sequence_ops = {
6143 .rpc_call_prepare = nfs41_sequence_prepare,
6144 .rpc_release = nfs41_sequence_release,
6147 static struct rpc_task *_nfs41_proc_sequence(
struct nfs_client *clp,
struct rpc_cred *cred)
6149 struct nfs4_sequence_data *calldata;
6156 .rpc_message = &
msg,
6157 .callback_ops = &nfs41_sequence_ops,
6162 return ERR_PTR(-
EIO);
6163 calldata = kzalloc(
sizeof(*calldata),
GFP_NOFS);
6164 if (calldata ==
NULL) {
6168 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
6171 calldata->clp = clp;
6177 static int nfs41_proc_async_sequence(
struct nfs_client *clp,
struct rpc_cred *cred,
unsigned renew_flags)
6182 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
6184 task = _nfs41_proc_sequence(clp, cred);
6186 ret = PTR_ERR(task);
6189 dprintk(
"<-- %s status=%d\n", __func__, ret);
6193 static int nfs4_proc_sequence(
struct nfs_client *clp,
struct rpc_cred *cred)
6198 task = _nfs41_proc_sequence(clp, cred);
6200 ret = PTR_ERR(task);
6203 ret = rpc_wait_for_completion_task(task);
6213 dprintk(
"<-- %s status=%d\n", __func__, ret);
6217 struct nfs4_reclaim_complete_data {
6219 struct nfs41_reclaim_complete_args arg;
6220 struct nfs41_reclaim_complete_res res;
6223 static void nfs4_reclaim_complete_prepare(
struct rpc_task *task,
void *data)
6225 struct nfs4_reclaim_complete_data *calldata =
data;
6228 if (nfs41_setup_sequence(calldata->clp->cl_session,
6229 &calldata->arg.seq_args,
6230 &calldata->res.seq_res, task))
6236 static int nfs41_reclaim_complete_handle_errors(
struct rpc_task *task,
struct nfs_client *clp)
6254 static void nfs4_reclaim_complete_done(
struct rpc_task *task,
void *data)
6256 struct nfs4_reclaim_complete_data *calldata =
data;
6260 dprintk(
"--> %s\n", __func__);
6261 if (!nfs41_sequence_done(task, res))
6264 if (nfs41_reclaim_complete_handle_errors(task, clp) == -
EAGAIN) {
6268 dprintk(
"<-- %s\n", __func__);
6271 static void nfs4_free_reclaim_complete_data(
void *data)
6273 struct nfs4_reclaim_complete_data *calldata =
data;
6278 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6280 .rpc_call_done = nfs4_reclaim_complete_done,
6281 .rpc_release = nfs4_free_reclaim_complete_data,
6287 static int nfs41_proc_reclaim_complete(
struct nfs_client *clp)
6289 struct nfs4_reclaim_complete_data *calldata;
6296 .rpc_message = &
msg,
6297 .callback_ops = &nfs4_reclaim_complete_call_ops,
6302 dprintk(
"--> %s\n", __func__);
6303 calldata = kzalloc(
sizeof(*calldata),
GFP_NOFS);
6304 if (calldata ==
NULL)
6306 calldata->clp = clp;
6307 calldata->arg.one_fs = 0;
6309 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6315 status = PTR_ERR(task);
6318 status = nfs4_wait_for_completion_rpc_task(task);
6324 dprintk(
"<-- %s status=%d\n", __func__, status);
6329 nfs4_layoutget_prepare(
struct rpc_task *task,
void *calldata)
6334 dprintk(
"--> %s\n", __func__);
6340 if (nfs4_setup_sequence(server, &lgp->
args.seq_args,
6341 &lgp->
res.seq_res, task))
6344 NFS_I(lgp->
args.inode)->layout,
6345 lgp->
args.ctx->state)) {
6352 static void nfs4_layoutget_done(
struct rpc_task *task,
void *calldata)
6355 struct inode *inode = lgp->
args.inode;
6356 struct nfs_server *server = NFS_SERVER(inode);
6357 struct pnfs_layout_hdr *
lo;
6358 struct nfs4_state *state =
NULL;
6360 dprintk(
"--> %s\n", __func__);
6362 if (!nfs4_sequence_done(task, &lgp->
res.seq_res))
6374 spin_lock(&inode->
i_lock);
6375 lo = NFS_I(inode)->layout;
6376 if (!lo || list_empty(&lo->plh_segs)) {
6377 spin_unlock(&inode->
i_lock);
6379 state = lgp->
args.ctx->state;
6384 spin_unlock(&inode->
i_lock);
6390 if (nfs4_async_handle_error(task, server, state) == -
EAGAIN)
6393 dprintk(
"<-- %s\n", __func__);
6396 static size_t max_response_pages(
struct nfs_server *server)
6398 u32 max_resp_sz = server->
nfs_client->cl_session->fc_attrs.max_resp_sz;
6399 return nfs_page_array_len(0, max_resp_sz);
6402 static void nfs4_free_pages(
struct page **pages,
size_t size)
6409 for (i = 0; i <
size; i++) {
6417 static struct page **nfs4_alloc_pages(
size_t size,
gfp_t gfp_flags)
6419 struct page **
pages;
6422 pages = kcalloc(size,
sizeof(
struct page *), gfp_flags);
6424 dprintk(
"%s: can't alloc array of %zu pages\n", __func__, size);
6428 for (i = 0; i <
size; i++) {
6431 dprintk(
"%s: failed to allocate page\n", __func__);
6432 nfs4_free_pages(pages, size);
6440 static void nfs4_layoutget_release(
void *calldata)
6444 size_t max_pages = max_response_pages(server);
6446 dprintk(
"--> %s\n", __func__);
6447 nfs4_free_pages(lgp->
args.layout.pages, max_pages);
6450 dprintk(
"<-- %s\n", __func__);
6453 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6455 .rpc_call_done = nfs4_layoutget_done,
6456 .rpc_release = nfs4_layoutget_release,
6463 size_t max_pages = max_response_pages(server);
6467 .rpc_argp = &lgp->
args,
6468 .rpc_resp = &lgp->
res,
6472 .rpc_message = &
msg,
6473 .callback_ops = &nfs4_layoutget_call_ops,
6474 .callback_data = lgp,
6480 dprintk(
"--> %s\n", __func__);
6482 lgp->
args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
6483 if (!lgp->
args.layout.pages) {
6484 nfs4_layoutget_release(lgp);
6489 lgp->
res.layoutp = &lgp->
args.layout;
6490 lgp->
res.seq_res.sr_slot =
NULL;
6491 nfs41_init_sequence(&lgp->
args.seq_args, &lgp->
res.seq_res, 0);
6494 return ERR_CAST(task);
6495 status = nfs4_wait_for_completion_rpc_task(task);
6501 dprintk(
"<-- %s status=%d\n", __func__, status);
6503 return ERR_PTR(status);
6508 nfs4_layoutreturn_prepare(
struct rpc_task *task,
void *calldata)
6512 dprintk(
"--> %s\n", __func__);
6513 if (nfs41_setup_sequence(lrp->
clp->cl_session, &lrp->
args.seq_args,
6514 &lrp->
res.seq_res, task))
6519 static void nfs4_layoutreturn_done(
struct rpc_task *task,
void *calldata)
6524 dprintk(
"--> %s\n", __func__);
6526 if (!nfs4_sequence_done(task, &lrp->
res.seq_res))
6529 server = NFS_SERVER(lrp->
args.inode);
6530 if (nfs4_async_handle_error(task, server,
NULL) == -
EAGAIN) {
6534 dprintk(
"<-- %s\n", __func__);
6537 static void nfs4_layoutreturn_release(
void *calldata)
6540 struct pnfs_layout_hdr *lo = lrp->
args.layout;
6542 dprintk(
"--> %s\n", __func__);
6543 spin_lock(&lo->plh_inode->i_lock);
6544 if (lrp->
res.lrs_present)
6546 lo->plh_block_lgets--;
6547 spin_unlock(&lo->plh_inode->i_lock);
6550 dprintk(
"<-- %s\n", __func__);
6553 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6555 .rpc_call_done = nfs4_layoutreturn_done,
6556 .rpc_release = nfs4_layoutreturn_release,
6564 .rpc_argp = &lrp->
args,
6565 .rpc_resp = &lrp->
res,
6569 .rpc_message = &
msg,
6570 .callback_ops = &nfs4_layoutreturn_call_ops,
6571 .callback_data = lrp,
6575 dprintk(
"--> %s\n", __func__);
6576 nfs41_init_sequence(&lrp->
args.seq_args, &lrp->
res.seq_res, 1);
6579 return PTR_ERR(task);
6581 dprintk(
"<-- %s status=%d\n", __func__, status);
6589 static int _nfs4_getdevicelist(
struct nfs_server *server,
6591 struct pnfs_devicelist *
devlist)
6595 .layoutclass = server->pnfs_curr_ld->id,
6607 dprintk(
"--> %s\n", __func__);
6608 status = nfs4_call_sync(server->
client, server, &msg, &args.
seq_args,
6610 dprintk(
"<-- %s status=%d\n", __func__, status);
6614 int nfs4_proc_getdevicelist(
struct nfs_server *server,
6616 struct pnfs_devicelist *
devlist)
6618 struct nfs4_exception exception = { };
6622 err = nfs4_handle_exception(server,
6623 _nfs4_getdevicelist(server, fh, devlist),
6625 }
while (exception.retry);
6627 dprintk(
"%s: err=%d, num_devs=%u\n", __func__,
6628 err, devlist->num_devs);
6635 _nfs4_proc_getdeviceinfo(
struct nfs_server *server,
struct pnfs_device *pdev)
6650 dprintk(
"--> %s\n", __func__);
6652 dprintk(
"<-- %s status=%d\n", __func__, status);
6657 int nfs4_proc_getdeviceinfo(
struct nfs_server *server,
struct pnfs_device *pdev)
6659 struct nfs4_exception exception = { };
6663 err = nfs4_handle_exception(server,
6664 _nfs4_proc_getdeviceinfo(server, pdev),
6666 }
while (exception.retry);
6671 static void nfs4_layoutcommit_prepare(
struct rpc_task *task,
void *calldata)
6676 if (nfs4_setup_sequence(server, &data->
args.seq_args,
6677 &data->
res.seq_res, task))
6683 nfs4_layoutcommit_done(
struct rpc_task *task,
void *calldata)
6688 if (!nfs4_sequence_done(task, &data->
res.seq_res))
6703 if (nfs4_async_handle_error(task, server,
NULL) == -
EAGAIN) {
6710 static void nfs4_layoutcommit_release(
void *calldata)
6714 unsigned long *bitlock = &NFS_I(data->
args.inode)->flags;
6733 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
6735 .rpc_call_done = nfs4_layoutcommit_done,
6736 .rpc_release = nfs4_layoutcommit_release,
6744 .rpc_argp = &data->
args,
6745 .rpc_resp = &data->
res,
6746 .rpc_cred = data->
cred,
6750 .rpc_client = NFS_CLIENT(data->
args.inode),
6751 .rpc_message = &
msg,
6752 .callback_ops = &nfs4_layoutcommit_ops,
6753 .callback_data =
data,
6759 dprintk(
"NFS: %4d initiating layoutcommit call. sync %d "
6760 "lbw: %llu inode %lu\n",
6761 data->
task.tk_pid, sync,
6762 data->
args.lastbytewritten,
6763 data->
args.inode->i_ino);
6765 nfs41_init_sequence(&data->
args.seq_args, &data->
res.seq_res, 1);
6768 return PTR_ERR(task);
6771 status = nfs4_wait_for_completion_rpc_task(task);
6776 dprintk(
"%s: status %d\n", __func__, status);
6782 _nfs41_proc_secinfo_no_name(
struct nfs_server *server,
struct nfs_fh *fhandle,
6783 struct nfs_fsinfo *info,
struct nfs4_secinfo_flavors *flavors)
6785 struct nfs41_secinfo_no_name_args args = {
6786 .style = SECINFO_STYLE_CURRENT_FH,
6788 struct nfs4_secinfo_res res = {
6796 return nfs4_call_sync(server->
client, server, &msg, &args.seq_args, &res.seq_res, 0);
6800 nfs41_proc_secinfo_no_name(
struct nfs_server *server,
struct nfs_fh *fhandle,
6801 struct nfs_fsinfo *info,
struct nfs4_secinfo_flavors *flavors)
6803 struct nfs4_exception exception = { };
6806 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6813 err = nfs4_handle_exception(server, err, &exception);
6815 }
while (exception.retry);
6826 rpc_authflavor_t flavor;
6827 struct nfs4_secinfo_flavors *flavors;
6836 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6843 err = nfs4_find_root_sec(server, fhandle, info);
6851 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
6864 struct nfs41_test_stateid_args args = {
6867 struct nfs41_test_stateid_res res;
6874 dprintk(
"NFS call test_stateid %p\n", stateid);
6875 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6876 status = nfs4_call_sync_sequence(server->
client, server, &msg, &args.seq_args, &res.seq_res, 1);
6878 dprintk(
"NFS reply test_stateid: failed, %d\n", status);
6881 dprintk(
"NFS reply test_stateid: succeeded, %d\n", -res.status);
6897 struct nfs4_exception exception = { };
6900 err = _nfs41_test_stateid(server, stateid);
6903 nfs4_handle_exception(server, err, &exception);
6904 }
while (exception.retry);
6910 struct nfs41_free_stateid_args args = {
6913 struct nfs41_free_stateid_res res;
6921 dprintk(
"NFS call free_stateid %p\n", stateid);
6922 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6923 status = nfs4_call_sync_sequence(server->
client, server, &msg,
6924 &args.seq_args, &res.seq_res, 1);
6925 dprintk(
"NFS reply free_stateid: %d\n", status);
6940 struct nfs4_exception exception = { };
6943 err = _nfs4_free_stateid(server, stateid);
6946 nfs4_handle_exception(server, err, &exception);
6947 }
while (exception.retry);
6970 return nfs4_stateid_match(s1, s2);
6974 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6975 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6976 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6977 .recover_open = nfs4_open_reclaim,
6978 .recover_lock = nfs4_lock_reclaim,
6984 #if defined(CONFIG_NFS_V4_1)
6985 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6986 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6987 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6988 .recover_open = nfs4_open_reclaim,
6989 .recover_lock = nfs4_lock_reclaim,
6990 .establish_clid = nfs41_init_clientid,
6991 .get_clid_cred = nfs4_get_exchange_id_cred,
6992 .reclaim_complete = nfs41_proc_reclaim_complete,
6993 .detect_trunking = nfs41_discover_server_trunking,
6997 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6998 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6999 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
7000 .recover_open = nfs4_open_expired,
7001 .recover_lock = nfs4_lock_expired,
7006 #if defined(CONFIG_NFS_V4_1)
7007 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
7008 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
7009 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
7010 .recover_open = nfs41_open_expired,
7011 .recover_lock = nfs41_lock_expired,
7012 .establish_clid = nfs41_init_clientid,
7013 .get_clid_cred = nfs4_get_exchange_id_cred,
7017 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
7018 .sched_state_renewal = nfs4_proc_async_renew,
7020 .renew_lease = nfs4_proc_renew,
7023 #if defined(CONFIG_NFS_V4_1)
7024 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
7025 .sched_state_renewal = nfs41_proc_async_sequence,
7027 .renew_lease = nfs4_proc_sequence,
7031 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
7034 .match_stateid = nfs4_match_stateid,
7035 .find_root_sec = nfs4_find_root_sec,
7036 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
7037 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
7038 .state_renewal_ops = &nfs40_state_renewal_ops,
7041 #if defined(CONFIG_NFS_V4_1)
7042 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
7045 .match_stateid = nfs41_match_stateid,
7046 .find_root_sec = nfs41_find_root_sec,
7047 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
7048 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
7049 .state_renewal_ops = &nfs41_state_renewal_ops,
7054 [0] = &nfs_v4_0_minor_ops,
7055 #if defined(CONFIG_NFS_V4_1)
7056 [1] = &nfs_v4_1_minor_ops,
7063 .atomic_open = nfs_atomic_open,
7092 .dentry_ops = &nfs4_dentry_operations,
7094 .file_inode_ops = &nfs4_file_inode_operations,
7096 .getroot = nfs4_proc_get_root,
7099 .getattr = nfs4_proc_getattr,
7100 .setattr = nfs4_proc_setattr,
7101 .lookup = nfs4_proc_lookup,
7102 .access = nfs4_proc_access,
7103 .readlink = nfs4_proc_readlink,
7104 .create = nfs4_proc_create,
7105 .remove = nfs4_proc_remove,
7106 .unlink_setup = nfs4_proc_unlink_setup,
7107 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
7108 .unlink_done = nfs4_proc_unlink_done,
7109 .rename = nfs4_proc_rename,
7110 .rename_setup = nfs4_proc_rename_setup,
7111 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
7112 .rename_done = nfs4_proc_rename_done,
7113 .link = nfs4_proc_link,
7114 .symlink = nfs4_proc_symlink,
7115 .mkdir = nfs4_proc_mkdir,
7116 .rmdir = nfs4_proc_remove,
7117 .readdir = nfs4_proc_readdir,
7118 .mknod = nfs4_proc_mknod,
7119 .statfs = nfs4_proc_statfs,
7120 .fsinfo = nfs4_proc_fsinfo,
7121 .pathconf = nfs4_proc_pathconf,
7124 .read_setup = nfs4_proc_read_setup,
7126 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
7127 .read_done = nfs4_read_done,
7128 .write_setup = nfs4_proc_write_setup,
7130 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
7131 .write_done = nfs4_write_done,
7132 .commit_setup = nfs4_proc_commit_setup,
7133 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
7134 .commit_done = nfs4_commit_done,
7135 .lock = nfs4_proc_lock,
7136 .clear_acl_cache = nfs4_zap_acl_attr,
7137 .close_context = nfs4_close_context,
7138 .open_context = nfs4_atomic_open,
7148 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
7150 .list = nfs4_xattr_list_nfs4_acl,
7151 .get = nfs4_xattr_get_nfs4_acl,
7152 .set = nfs4_xattr_set_nfs4_acl,
7156 &nfs4_xattr_nfs4_acl_handler,