37 #include <linux/slab.h>
51 #define NFSDDBG_FACILITY NFSDDBG_PROC
57 #define all_ones {{~0,~0},~0}
69 static u64 current_sessionid = 1;
71 #define ZERO_STATEID(stateid) (!memcmp((stateid), &zero_stateid, sizeof(stateid_t)))
72 #define ONE_STATEID(stateid) (!memcmp((stateid), &one_stateid, sizeof(stateid_t)))
73 #define CURRENT_STATEID(stateid) (!memcmp((stateid), ¤tstateid, sizeof(stateid_t)))
102 static void free_session(
struct kref *);
105 static void nfsd4_put_session_locked(
struct nfsd4_session *ses)
107 kref_put(&ses->
se_ref, free_session);
122 opaque_hashval(
const void *
ptr,
int nbytes)
124 unsigned char *cptr = (
unsigned char *) ptr;
136 static void nfsd4_free_file(
struct nfs4_file *
f)
146 spin_unlock(&recall_lock);
158 static int num_delegations;
166 #define OWNER_HASH_BITS 8
167 #define OWNER_HASH_SIZE (1 << OWNER_HASH_BITS)
168 #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
170 static unsigned int ownerstr_hashval(
u32 clientid,
struct xdr_netobj *ownername)
174 ret = opaque_hashval(ownername->data, ownername->len);
182 #define FILE_HASH_BITS 8
183 #define FILE_HASH_SIZE (1 << FILE_HASH_BITS)
185 static unsigned int file_hashval(
struct inode *
ino)
193 static void __nfs4_file_get_access(
struct nfs4_file *
fp,
int oflag)
199 static void nfs4_file_get_access(
struct nfs4_file *fp,
int oflag)
202 __nfs4_file_get_access(fp,
O_RDONLY);
203 __nfs4_file_get_access(fp,
O_WRONLY);
205 __nfs4_file_get_access(fp, oflag);
208 static void nfs4_file_put_fd(
struct nfs4_file *fp,
int oflag)
216 static void __nfs4_file_put_access(
struct nfs4_file *fp,
int oflag)
219 nfs4_file_put_fd(fp, oflag);
227 nfs4_file_put_fd(fp,
O_RDWR);
231 static void nfs4_file_put_access(
struct nfs4_file *fp,
int oflag)
234 __nfs4_file_put_access(fp,
O_RDONLY);
235 __nfs4_file_put_access(fp,
O_WRONLY);
237 __nfs4_file_put_access(fp, oflag);
240 static inline int get_new_stid(
struct nfs4_stid *stid)
242 static int min_stateid = 0;
265 min_stateid = new_stid+1;
279 new_id = get_new_stid(stid);
302 return openlockstateid(nfs4_alloc_stid(clp, stateid_slab));
311 dprintk(
"NFSD alloc_init_deleg\n");
321 if (num_delegations > max_delegations)
323 dp = delegstateid(nfs4_alloc_stid(clp, deleg_slab));
332 dp->
dl_stid.sc_stateid.si_generation = 1;
351 dprintk(
"NFSD: freeing dp %p\n",dp);
358 static void nfs4_put_deleg_lease(
struct nfs4_file *fp)
381 spin_lock(&recall_lock);
384 spin_unlock(&recall_lock);
385 nfs4_put_deleg_lease(dp->
dl_file);
397 #define CLIENT_HASH_BITS 4
398 #define CLIENT_HASH_SIZE (1 << CLIENT_HASH_BITS)
399 #define CLIENT_HASH_MASK (CLIENT_HASH_SIZE - 1)
401 static unsigned int clientid_hashval(
u32 id)
406 static unsigned int clientstr_hashval(
const char *
name)
428 static int reclaim_str_hashtbl_size = 0;
455 bmap_to_share_mode(
unsigned long bmap) {
459 for (i = 1; i < 4; i++) {
468 unsigned int access, deny;
519 static int nfs4_access_to_omode(
u32 access)
526 case NFS4_SHARE_ACCESS_BOTH:
538 for (i = 1; i < 4; i++) {
539 if (test_access(i, stp))
540 nfs4_file_put_access(stp->
st_file,
541 nfs4_access_to_omode(i));
542 clear_access(i, stp);
554 release_all_access(stp);
568 unhash_generic_stateid(stp);
570 file = find_any_file(stp->
st_file);
573 close_generic_stateid(stp);
574 free_generic_stateid(stp);
584 while (!list_empty(&lo->
lo_owner.so_stateids)) {
587 release_lock_stateid(stp);
593 unhash_lockowner(lo);
605 release_lockowner(lo);
611 unhash_generic_stateid(stp);
612 release_stateid_lockowners(stp);
613 close_generic_stateid(stp);
618 unhash_open_stateid(stp);
620 free_generic_stateid(stp);
629 while (!list_empty(&oo->
oo_owner.so_stateids)) {
632 release_open_stateid(stp);
636 static void release_last_closed_stateid(
struct nfs4_openowner *oo)
642 free_generic_stateid(s);
649 unhash_openowner(oo);
651 release_last_closed_stateid(oo);
655 #define SESSION_HASH_SIZE 512
671 dprintk(
"%s: %u:%u:%u:%u\n", fn, ptr[0], ptr[1], ptr[2], ptr[3]);
689 sid->
sequence = current_sessionid++;
705 #define NFSD_MIN_HDR_SEQ_SZ (24 + 12 + 44)
725 static int nfsd4_sanitize_slot_size(
u32 size)
738 static int nfsd4_get_drc_mem(
int slotsize,
u32 num)
747 num =
min_t(
int, num, avail / slotsize);
754 static void nfsd4_put_drc_mem(
int slotsize,
int num)
761 static struct nfsd4_session *__alloc_session(
int slotsize,
int numslots)
770 new = kzalloc(
sizeof(*
new) + mem,
GFP_KERNEL);
774 for (i = 0; i < numslots; i++) {
777 if (!new->se_slots[i])
783 kfree(new->se_slots[i]);
792 new->maxreqs = numslots;
845 __nfsd4_hash_conn(conn, ses);
849 static int nfsd4_register_conn(
struct nfsd4_conn *conn)
859 nfsd4_hash_conn(conn, ses);
860 ret = nfsd4_register_conn(conn);
876 return alloc_conn(rqstp, dir);
902 free_session_slots(ses);
906 static void free_session(
struct kref *
kref)
912 nfsd4_del_conns(ses);
918 spin_lock(&client_lock);
919 nfsd4_put_session_locked(ses);
920 spin_unlock(&client_lock);
926 int numslots, slotsize;
935 numslots = nfsd4_get_drc_mem(slotsize, fchan->
maxreqs);
939 new = __alloc_session(slotsize, numslots);
941 nfsd4_put_drc_mem(slotsize, fchan->
maxreqs);
944 init_forechannel_attrs(&new->se_fchannel, fchan, numslots, slotsize);
952 new->se_client = clp;
955 INIT_LIST_HEAD(&new->se_conns);
957 new->se_cb_seq_nr = 1;
958 new->se_flags = cses->
flags;
960 kref_init(&new->se_ref);
961 idx = hash_sessionid(&new->se_sessionid);
962 spin_lock(&client_lock);
963 list_add(&new->se_hash, &sessionid_hashtbl[idx]);
967 spin_unlock(&client_lock);
979 clp->
cl_cb_conn.cb_addrlen = svc_addr_len(sa);
991 dump_sessionid(__func__, sessionid);
992 idx = hash_sessionid(sessionid);
1001 dprintk(
"%s: session not found\n", __func__);
1019 if (is_client_expired(clp)) {
1021 printk(
"%s: client (clientid %08x/%08x) already expired\n",
1028 dprintk(
"renewing client (clientid %08x/%08x)\n",
1031 list_move_tail(&clp->
cl_lru, &client_lru);
1038 spin_lock(&client_lock);
1039 renew_client_locked(clp);
1040 spin_unlock(&client_lock);
1049 dprintk(
"NFSD stale clientid (%08x/%08x) boot_time %08lx\n",
1084 nfsd4_put_session_locked(ses);
1098 if (is_client_expired(clp)) {
1102 renew_client_locked(clp);
1103 spin_unlock(&client_lock);
1112 mark_client_expired(clp);
1117 spin_unlock(&clp->cl_lock);
1127 INIT_LIST_HEAD(&reaplist);
1128 spin_lock(&recall_lock);
1129 while (!list_empty(&clp->cl_delegations)) {
1134 spin_unlock(&recall_lock);
1135 while (!list_empty(&reaplist)) {
1137 unhash_delegation(dp);
1139 while (!list_empty(&clp->cl_openowners)) {
1141 release_openowner(oo);
1144 if (clp->cl_cb_conn.cb_xprt)
1148 spin_lock(&client_lock);
1149 unhash_client_locked(clp);
1152 spin_unlock(&client_lock);
1155 static void expire_client(
struct nfs4_client *clp)
1158 destroy_client(clp);
1173 static int copy_cred(
struct svc_cred *
target,
struct svc_cred *
source)
1175 if (source->cr_principal) {
1176 target->cr_principal =
1178 if (target->cr_principal ==
NULL)
1181 target->cr_principal =
NULL;
1182 target->cr_flavor = source->cr_flavor;
1183 target->cr_uid = source->cr_uid;
1184 target->cr_gid = source->cr_gid;
1185 target->cr_group_info = source->cr_group_info;
1186 get_group_info(target->cr_group_info);
1190 static int same_name(
const char *n1,
const char *n2)
1228 static bool is_gss_cred(
struct svc_cred *
cr)
1231 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR);
1236 same_creds(
struct svc_cred *
cr1,
struct svc_cred *
cr2)
1238 if ((is_gss_cred(cr1) != is_gss_cred(cr2))
1239 || (cr1->cr_uid != cr2->cr_uid)
1240 || (cr1->cr_gid != cr2->cr_gid)
1241 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info))
1243 if (cr1->cr_principal == cr2->cr_principal)
1245 if (!cr1->cr_principal || !cr2->cr_principal)
1247 return 0 ==
strcmp(cr1->cr_principal, cr2->cr_principal);
1252 static u32 current_clientid = 1;
1278 s = find_stateid(cl, t);
1286 static struct nfs4_client *create_client(
struct xdr_netobj name,
char *recdir,
1293 clp = alloc_client(name);
1300 spin_lock(&client_lock);
1302 spin_unlock(&client_lock);
1313 INIT_LIST_HEAD(&clp->
cl_lru);
1320 copy_verf(clp, verf);
1328 add_to_unconfirmed(
struct nfs4_client *clp,
unsigned int strhashval)
1330 unsigned int idhashval;
1332 list_add(&clp->
cl_strhash, &unconf_str_hashtbl[strhashval]);
1334 list_add(&clp->
cl_idhash, &unconf_id_hashtbl[idhashval]);
1342 unsigned int strhashval;
1344 dprintk(
"NFSD: move_to_confirm nfs4_client %p\n", clp);
1345 list_move(&clp->
cl_idhash, &conf_id_hashtbl[idhashval]);
1346 strhashval = clientstr_hashval(clp->
cl_recdir);
1347 list_move(&clp->
cl_strhash, &conf_str_hashtbl[strhashval]);
1352 find_confirmed_client(
clientid_t *clid,
bool sessions)
1355 unsigned int idhashval = clientid_hashval(clid->
cl_id);
1369 find_unconfirmed_client(
clientid_t *clid,
bool sessions)
1372 unsigned int idhashval = clientid_hashval(clid->
cl_id);
1384 static bool clp_used_exchangeid(
struct nfs4_client *clp)
1390 find_confirmed_client_by_str(
const char *dname,
unsigned int hashval)
1402 find_unconfirmed_client_by_str(
const char *dname,
unsigned int hashval)
1417 struct sockaddr *sa = svc_addr(rqstp);
1418 u32 scopeid = rpc_get_scope_id(sa);
1419 unsigned short expected_family;
1450 "will not receive delegations\n",
1465 dprintk(
"--> %s slot %p\n", __func__, slot);
1471 if (nfsd4_not_cached(resp)) {
1476 base = (
char *)resp->
cstate.datap -
1477 (
char *)resp->
xbuf->head[0].iov_base;
1480 WARN(
"%s: sessions DRC could not cache compound\n", __func__);
1522 dprintk(
"--> %s slot %p\n", __func__, slot);
1525 status = nfsd4_enc_sequence_replay(resp->
rqstp->rq_argp, resp);
1552 clid->
flags =
new->cl_exchange_flags;
1555 static bool client_has_state(
struct nfs4_client *clp)
1575 unsigned int strhashval;
1579 struct sockaddr *sa = svc_addr(rqstp);
1582 rpc_ntop(sa, addr_str,
sizeof(addr_str));
1583 dprintk(
"%s rqstp=%p exid=%p clname.len=%u clname.data=%p "
1584 "ip_addr=%s flags %x, spa_how %d\n",
1585 __func__, rqstp, exid, exid->
clname.len, exid->
clname.data,
1608 strhashval = clientstr_hashval(dname);
1612 conf = find_confirmed_client_by_str(dname, strhashval);
1615 bool verfs_match = same_verf(&verf, &conf->
cl_verifier);
1618 if (!clp_used_exchangeid(conf)) {
1636 if (client_has_state(conf)) {
1640 expire_client(conf);
1657 unconf = find_unconfirmed_client_by_str(dname, strhashval);
1659 expire_client(unconf);
1663 new = create_client(exid->
clname, dname, rqstp, &verf);
1668 new->cl_minorversion = 1;
1671 add_to_unconfirmed(
new, strhashval);
1676 exid->
seqid =
new->cl_cs_slot.sl_seqid + 1;
1677 nfsd4_set_ex_flags(
new, exid);
1679 dprintk(
"nfsd4_exchange_id seqid %d flags %x\n",
1680 new->cl_cs_slot.sl_seqid, new->cl_exchange_flags);
1689 check_slot_seqid(
u32 seqid,
u32 slot_seqid,
int slot_inuse)
1691 dprintk(
"%s enter. seqid %d slot_seqid %d\n", __func__, seqid,
1696 if (seqid == slot_seqid)
1702 if (
likely(seqid == slot_seqid + 1))
1704 if (seqid == slot_seqid)
1730 #define NFSD_MIN_REQ_HDR_SEQ_SZ ((\
1734 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
1736 4 ) * sizeof(__be32))
1738 #define NFSD_MIN_RESP_HDR_SEQ_SZ ((\
1743 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
1745 5 ) * sizeof(__be32))
1758 struct sockaddr *sa = svc_addr(rqstp);
1773 conn = alloc_conn_from_crses(rqstp, cr_ses);
1775 goto out_free_session;
1778 unconf = find_unconfirmed_client(&cr_ses->
clientid,
true);
1779 conf = find_confirmed_client(&cr_ses->
clientid,
true);
1783 status = check_slot_seqid(cr_ses->
seqid, cs_slot->
sl_seqid, 0);
1785 status = nfsd4_replay_create_session(cr_ses, cs_slot);
1791 }
else if (unconf) {
1800 status = check_slot_seqid(cr_ses->
seqid, cs_slot->
sl_seqid, 0);
1806 hash = clientstr_hashval(unconf->
cl_recdir);
1807 old = find_confirmed_client_by_str(unconf->
cl_recdir, hash);
1810 move_to_confirmed(unconf);
1823 init_session(rqstp,
new, conf, cr_ses);
1824 nfsd4_init_conn(rqstp, conn,
new);
1834 nfsd4_cache_create_session(cr_ses, cs_slot, status);
1842 __free_session(
new);
1846 static bool nfsd4_last_compound_op(
struct svc_rqst *rqstp)
1854 static __be32 nfsd4_map_bcts_dir(
u32 *dir)
1875 if (!nfsd4_last_compound_op(rqstp))
1877 spin_lock(&client_lock);
1882 nfsd4_get_session(cstate->
session);
1885 spin_unlock(&client_lock);
1889 status = nfsd4_map_bcts_dir(&bcts->
dir);
1892 conn = alloc_conn(rqstp, bcts->
dir);
1895 nfsd4_init_conn(rqstp, conn, cstate->
session);
1922 if (!nfsd4_last_compound_op(r))
1925 dump_sessionid(__func__, &sessionid->
sessionid);
1926 spin_lock(&client_lock);
1927 ses = find_in_sessionid_hashtbl(&sessionid->
sessionid);
1929 spin_unlock(&client_lock);
1933 unhash_session(ses);
1934 spin_unlock(&client_lock);
1940 spin_lock(&client_lock);
1941 nfsd4_del_conns(ses);
1942 nfsd4_put_session_locked(ses);
1943 spin_unlock(&client_lock);
1969 c = __nfsd4_find_conn(new->cn_xprt, ses);
1975 __nfsd4_hash_conn(
new, ses);
1977 ret = nfsd4_register_conn(
new);
1980 nfsd4_conn_lost(&new->cn_xpt_user);
1991 static bool nfsd4_request_too_big(
struct svc_rqst *rqstp,
1994 struct xdr_buf *
xb = &rqstp->
rq_arg;
2010 if (resp->
opcnt != 1)
2021 spin_lock(&client_lock);
2023 session = find_in_sessionid_hashtbl(&seq->
sessionid);
2028 if (nfsd4_session_too_many_ops(rqstp, session))
2032 if (nfsd4_request_too_big(rqstp, session))
2064 nfsd4_sequence_check_conn(conn, session);
2083 nfsd4_get_session(cstate->
session);
2097 spin_unlock(&client_lock);
2109 unconf = find_unconfirmed_client(&dc->
clientid,
true);
2110 conf = find_confirmed_client(&dc->
clientid,
true);
2115 if (!is_client_expired(conf) && client_has_state(conf)) {
2157 &cstate->
session->se_client->cl_flags))
2161 if (is_client_expired(cstate->
session->se_client))
2182 struct xdr_netobj clname = setclid->
se_name;
2184 unsigned int strhashval;
2193 strhashval = clientstr_hashval(dname);
2197 conf = find_confirmed_client_by_str(dname, strhashval);
2201 if (clp_used_exchangeid(conf))
2207 dprintk(
"NFSD: setclientid: string in use by client "
2208 "at %s\n", addr_str);
2212 unconf = find_unconfirmed_client_by_str(dname, strhashval);
2214 expire_client(unconf);
2216 new = create_client(clname, dname, rqstp, &clverifier);
2219 if (conf && same_verf(&conf->
cl_verifier, &clverifier))
2221 copy_clid(
new, conf);
2224 new->cl_minorversion = 0;
2225 gen_callback(
new, setclid, rqstp);
2226 add_to_unconfirmed(
new, strhashval);
2248 if (STALE_CLIENTID(clid, nn))
2252 conf = find_confirmed_client(clid,
false);
2253 unconf = find_unconfirmed_client(clid,
false);
2266 if (!unconf || !same_verf(&confirm, &unconf->
cl_confirm)) {
2267 if (conf && !unconf)
2277 expire_client(unconf);
2281 conf = find_confirmed_client_by_str(unconf->
cl_recdir, hash);
2283 expire_client(conf);
2284 move_to_confirmed(unconf);
2292 static struct nfs4_file *nfsd4_alloc_file(
void)
2300 unsigned int hashval = file_hashval(ino);
2311 spin_lock(&recall_lock);
2312 list_add(&fp->
fi_hash, &file_hashtbl[hashval]);
2313 spin_unlock(&recall_lock);
2328 nfsd4_free_slab(&openowner_slab);
2329 nfsd4_free_slab(&lockowner_slab);
2330 nfsd4_free_slab(&file_slab);
2331 nfsd4_free_slab(&stateid_slab);
2332 nfsd4_free_slab(&deleg_slab);
2340 if (openowner_slab ==
NULL)
2344 if (lockowner_slab ==
NULL)
2348 if (file_slab ==
NULL)
2352 if (stateid_slab ==
NULL)
2356 if (deleg_slab ==
NULL)
2361 dprintk(
"nfsd4: out of memory while initializing nfsv4\n");
2407 list_add(&oo->
oo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
2412 alloc_init_open_stateowner(
unsigned int strhashval,
struct nfs4_client *clp,
struct nfsd4_open *open) {
2415 oo = alloc_stateowner(openowner_slab, &open->
op_owner, clp);
2424 hash_openowner(oo, clp, strhashval);
2449 dprintk(
"NFSD: move_to_close_lru nfs4_openowner %p\n", oo);
2459 return (sop->
so_owner.len == owner->len) &&
2465 find_openstateowner_str(
unsigned int hashval,
struct nfsd4_open *open,
bool sessions)
2479 renew_client(oo->
oo_owner.so_client);
2490 unsigned int hashval = file_hashval(ino);
2493 spin_lock(&recall_lock);
2497 spin_unlock(&recall_lock);
2501 spin_unlock(&recall_lock);
2510 nfs4_share_conflict(
struct svc_fh *current_fh,
unsigned int deny_type)
2517 dprintk(
"NFSD: nfs4_share_conflict\n");
2519 fp = find_file(ino);
2525 if (test_deny(deny_type, stp) ||
2553 static void nfsd_break_deleg_cb(
struct file_lock *
fl)
2568 spin_lock(&recall_lock);
2571 nfsd_break_one_deleg(dp);
2572 spin_unlock(&recall_lock);
2585 .lm_break = nfsd_break_deleg_cb,
2586 .lm_change = nfsd_change_deleg_cb,
2591 if (nfsd4_has_session(cstate))
2606 unsigned int strhashval;
2617 open->
op_file = nfsd4_alloc_file();
2621 strhashval = ownerstr_hashval(clientid->
cl_id, &open->
op_owner);
2622 oo = find_openstateowner_str(strhashval, open, cstate->
minorversion);
2625 clp = find_confirmed_client(clientid, cstate->
minorversion);
2633 release_openowner(oo);
2643 oo = alloc_init_open_stateowner(strhashval, clp, open);
2648 open->
op_stp = nfs4_alloc_stateid(clp);
2663 static int share_access_to_flags(
u32 share_access)
2675 return delegstateid(ret);
2678 static bool nfsd4_is_deleg_cur(
struct nfsd4_open *open)
2695 status = nfs4_check_delegmode(*dp, flags);
2699 if (!nfsd4_is_deleg_cur(open))
2721 if (!test_share(local, open))
2727 static inline int nfs4_access_to_access(
u32 nfs4_access)
2745 if (!fp->
fi_fds[oflag]) {
2751 nfs4_file_get_access(fp, oflag);
2778 new_access = !test_access(op_share_access, stp);
2780 status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open);
2784 status = nfsd4_truncate(rqstp, cur_fh, open);
2787 int oflag = nfs4_access_to_omode(op_share_access);
2788 nfs4_file_put_access(fp, oflag);
2793 set_access(op_share_access, stp);
2801 nfs4_set_claim_prev(
struct nfsd4_open *open,
bool has_session)
2807 static bool nfsd4_cb_channel_good(
struct nfs4_client *clp)
2827 fl->
fl_lmops = &nfsd_lease_mng_ops;
2842 fl = nfs4_alloc_init_lease(dp, flag);
2865 return nfs4_setlease(dp, flag);
2866 spin_lock(&recall_lock);
2868 spin_unlock(&recall_lock);
2873 spin_unlock(&recall_lock);
2878 static void nfsd4_open_deleg_none_ext(
struct nfsd4_open *open,
int status)
2903 nfs4_open_delegation(
struct net *
net,
struct svc_fh *fh,
2909 int status = 0, flag = 0;
2911 cb_up = nfsd4_cb_channel_good(oo->
oo_owner.so_client);
2938 dp = alloc_init_deleg(oo->
oo_owner.so_client, stp, fh, flag);
2941 status = nfs4_set_delegation(dp, flag);
2954 dprintk(
"NFSD: WARNING: refusing delegation reclaim\n");
2958 nfsd4_open_deleg_none_ext(open, status);
2968 static void nfsd4_deleg_xgrade_none_ext(
struct nfsd4_open *open,
3005 fp = find_file(ino);
3007 if ((status = nfs4_check_open(fp, open, &stp)))
3009 status = nfs4_check_deleg(cl, fp, open, &dp);
3014 if (nfsd4_is_deleg_cur(open))
3019 nfsd4_init_file(fp, ino);
3028 status = nfs4_upgrade_open(rqstp, fp, current_fh, stp, open);
3032 status = nfs4_get_vfs_file(rqstp, fp, current_fh, open);
3035 status = nfsd4_truncate(rqstp, current_fh, open);
3040 init_open_stateid(stp, fp, open);
3042 update_stateid(&stp->
st_stid.sc_stateid);
3045 if (nfsd4_has_session(&resp->
cstate)) {
3059 nfs4_open_delegation(
SVC_NET(rqstp), current_fh, open, stp);
3069 nfsd4_deleg_xgrade_none_ext(open, dp);
3074 nfs4_set_claim_prev(open, nfsd4_has_session(&resp->
cstate));
3080 !nfsd4_has_session(&resp->
cstate))
3091 if (!list_empty(&oo->
oo_owner.so_stateids))
3095 release_openowner(oo);
3102 nfsd4_free_file(open->
op_file);
3104 free_generic_stateid(open->
op_stp);
3116 dprintk(
"process_renew(%08x/%08x): starting\n",
3119 if (STALE_CLIENTID(clid, nn))
3121 clp = find_confirmed_client(clid, cstate->
minorversion);
3125 dprintk(
"nfsd4_renew: clientid not found!\n");
3139 nfsd4_end_grace(
struct net *net)
3147 dprintk(
"NFSD: end of grace period\n");
3160 nfs4_laundromat(
void)
3172 dprintk(
"NFSD: laundromat service - starting\n");
3174 INIT_LIST_HEAD(&reaplist);
3175 spin_lock(&client_lock);
3180 if (clientid_val > t)
3185 dprintk(
"NFSD: client in use (clientid %08x)\n",
3189 unhash_client_locked(clp);
3190 list_add(&clp->
cl_lru, &reaplist);
3192 spin_unlock(&client_lock);
3195 dprintk(
"NFSD: purging unused client (clientid %08x)\n",
3199 spin_lock(&recall_lock);
3210 spin_unlock(&recall_lock);
3213 unhash_delegation(dp);
3224 release_openowner(oo);
3226 if (clientid_val < NFSD_LAUNDROMAT_MINTIMEOUT)
3227 clientid_val = NFSD_LAUNDROMAT_MINTIMEOUT;
3229 return clientid_val;
3233 static void laundromat_main(
struct work_struct *);
3241 t = nfs4_laundromat();
3242 dprintk(
"NFSD: laundromat_main - sleeping for %ld seconds\n", t);
3266 return test_access(NFS4_SHARE_ACCESS_READ, stp) ||
3286 if ((flags & WR_STATE) && !access_permit_write(stp))
3288 if ((flags &
RD_STATE) && !access_permit_read(stp))
3296 check_special_stateids(
struct net *net,
svc_fh *current_fh,
stateid_t *stateid,
int flags)
3304 }
else if (flags & WR_STATE)
3305 return nfs4_share_conflict(current_fh,
3308 return nfs4_share_conflict(current_fh,
3317 grace_disallows_io(
struct net *net,
struct inode *
inode)
3341 if (stateid_generation_after(in, ref))
3370 "with incorrect client ID\n", addr_str);
3373 s = find_stateid(cl, stateid);
3376 status = check_stateid_generation(stateid, &s->
sc_stateid, 1);
3381 ols = openlockstateid(s);
3388 static __be32 nfsd4_lookup_stateid(
stateid_t *stateid,
unsigned char typemask,
struct nfs4_stid **s,
bool sessions)
3395 if (STALE_STATEID(stateid, nn))
3400 *s = find_stateid_by_type(cl, stateid, typemask);
3412 stateid_t *stateid,
int flags,
struct file **filpp)
3424 if (grace_disallows_io(net, ino))
3428 return check_special_stateids(net, current_fh, stateid, flags);
3433 status = check_stateid_generation(stateid, &s->
sc_stateid, nfsd4_has_session(cstate));
3438 dp = delegstateid(s);
3439 status = nfs4_check_delegmode(dp, flags);
3443 *filpp = dp->
dl_file->fi_deleg_file;
3449 stp = openlockstateid(s);
3450 status = nfs4_check_fh(current_fh, stp);
3456 status = nfs4_check_openmode(stp, flags);
3460 if (flags & RD_STATE)
3463 *filpp = find_writeable_file(stp->
st_file);
3479 release_lock_stateid(stp);
3512 s = find_stateid(cl, stateid);
3521 ret = check_stateid_generation(stateid, &s->
sc_stateid, 1);
3525 ret = nfsd4_free_lock_stateid(openlockstateid(s));
3550 status = nfsd4_check_seqid(cstate, sop, seqid);
3559 status = check_stateid_generation(stateid, &stp->
st_stid.sc_stateid, nfsd4_has_session(cstate));
3562 return nfs4_check_fh(current_fh, stp);
3580 status = nfsd4_lookup_stateid(stateid, typemask, &s, cstate->
minorversion);
3583 *stpp = openlockstateid(s);
3586 return nfs4_seqid_op_checks(cstate, stateid, seqid, *stpp);
3594 status = nfs4_preprocess_seqid_op(cstate, seqid, stateid,
3598 oo = openowner((*stpp)->st_stateowner);
3612 dprintk(
"NFSD: nfsd4_open_confirm on file %.*s\n",
3613 (
int)cstate->
current_fh.fh_dentry->d_name.len,
3622 status = nfs4_preprocess_seqid_op(cstate,
3632 update_stateid(&stp->
st_stid.sc_stateid);
3645 static inline void nfs4_stateid_downgrade_bit(
struct nfs4_ol_stateid *stp,
u32 access)
3647 if (!test_access(access, stp))
3649 nfs4_file_put_access(stp->
st_file, nfs4_access_to_omode(access));
3650 clear_access(access, stp);
3653 static inline void nfs4_stateid_downgrade(
struct nfs4_ol_stateid *stp,
u32 to_access)
3655 switch (to_access) {
3656 case NFS4_SHARE_ACCESS_READ:
3661 nfs4_stateid_downgrade_bit(stp, NFS4_SHARE_ACCESS_READ);
3672 reset_union_bmap_deny(
unsigned long deny,
struct nfs4_ol_stateid *stp)
3675 for (i = 0; i < 4; i++) {
3676 if ((i & deny) != i)
3689 dprintk(
"NFSD: nfsd4_open_downgrade on file %.*s\n",
3690 (
int)cstate->
current_fh.fh_dentry->d_name.len,
3695 dprintk(
"NFSD: %s: od_deleg_want=0x%x ignored\n", __func__,
3699 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->
od_seqid,
3705 dprintk(
"NFSD: access not a subset current bitmap: 0x%lx, input access=%08x\n",
3710 dprintk(
"NFSD:deny not a subset current bitmap: 0x%lx, input deny=%08x\n",
3718 update_stateid(&stp->
st_stid.sc_stateid);
3744 release_last_closed_stateid(oo);
3749 unhash_open_stateid(s);
3764 dprintk(
"NFSD: nfsd4_close on file %.*s\n",
3765 (
int)cstate->
current_fh.fh_dentry->d_name.len,
3769 status = nfs4_preprocess_seqid_op(cstate, close->
cl_seqid,
3777 update_stateid(&stp->
st_stid.sc_stateid);
3780 nfsd4_close_open_stateid(stp);
3781 release_last_closed_stateid(oo);
3784 if (list_empty(&oo->
oo_owner.so_stateids)) {
3786 release_openowner(oo);
3793 if (list_empty(&oo->
oo_owner.so_stateids))
3794 move_to_close_lru(oo);
3815 inode = cstate->
current_fh.fh_dentry->d_inode;
3821 dp = delegstateid(s);
3822 status = check_stateid_generation(stateid, &dp->
dl_stid.sc_stateid, nfsd4_has_session(cstate));
3826 unhash_delegation(dp);
3834 #define LOFF_OVERFLOW(start, len) ((u64)(len) > ~(u64)(start))
3836 #define LOCKOWNER_INO_HASH_BITS 8
3837 #define LOCKOWNER_INO_HASH_SIZE (1 << LOCKOWNER_INO_HASH_BITS)
3838 #define LOCKOWNER_INO_HASH_MASK (LOCKOWNER_INO_HASH_SIZE - 1)
3860 static unsigned int lockowner_ino_hashval(
struct inode *
inode,
u32 cl_id,
struct xdr_netobj *ownername)
3862 return (file_hashval(inode) + cl_id
3863 + opaque_hashval(ownername->data, ownername->len))
3878 nfs4_transform_lock_offset(
struct file_lock *lock)
3896 if (fl->
fl_lmops == &nfsd_posix_mng_ops) {
3921 static bool same_lockowner_ino(
struct nfs4_lockowner *lo,
struct inode *inode,
clientid_t *clid,
struct xdr_netobj *owner)
3925 if (!same_owner_str(&lo->
lo_owner, owner, clid))
3933 find_lockowner_str(
struct inode *inode,
clientid_t *clid,
3934 struct xdr_netobj *owner)
3936 unsigned int hashval = lockowner_ino_hashval(inode, clid->
cl_id, owner);
3940 if (same_lockowner_ino(lo, inode, clid, owner))
3948 struct inode *inode = open_stp->
st_file->fi_inode;
3949 unsigned int inohash = lockowner_ino_hashval(inode,
3952 list_add(&lo->
lo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
3969 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp);
3972 INIT_LIST_HEAD(&lo->
lo_owner.so_stateids);
3976 lo->
lo_owner.so_seqid = lock->lk_new_lock_seqid + 1;
3977 hash_lockowner(lo, strhashval, clp, open_stp);
3987 stp = nfs4_alloc_stateid(clp);
4012 int oflag = nfs4_access_to_omode(access);
4014 if (test_access(access, lock_stp))
4016 nfs4_file_get_access(fp, oflag);
4017 set_access(access, lock_stp);
4026 unsigned int strhashval;
4038 &lock->
v.
new.owner);
4039 lo = alloc_init_lock_stateowner(strhashval, cl, ost, lock);
4042 *lst = alloc_init_lock_stateid(lo, fi, ost);
4044 release_lockowner(lo);
4061 struct file *filp =
NULL;
4063 struct file_lock *conflock =
NULL;
4070 dprintk(
"NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
4079 dprintk(
"NFSD: nfsd4_lock: permission denied!\n");
4088 if (nfsd4_has_session(cstate))
4091 &cstate->
session->se_client->cl_clientid,
4095 if (STALE_CLIENTID(&lock->lk_new_clientid, nn))
4099 status = nfs4_preprocess_confirmed_seqid_op(cstate,
4100 lock->lk_new_open_seqid,
4101 &lock->lk_new_open_stateid,
4107 if (!same_clid(&open_sop->
oo_owner.so_client->cl_clientid,
4108 &lock->
v.
new.clientid))
4110 status = lookup_or_create_lock_state(cstate, open_stp, lock,
4111 &lock_stp, &new_state);
4113 status = nfs4_preprocess_seqid_op(cstate,
4114 lock->lk_old_lock_seqid,
4115 &lock->lk_old_lock_stateid,
4121 lkflg = setlkflg(lock->
lk_type);
4122 status = nfs4_check_openmode(lock_stp, lkflg);
4135 dprintk(
"NFSD: %s: unable to allocate lock!\n", __func__);
4146 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ);
4151 filp = find_writeable_file(lock_stp->
st_file);
4168 file_lock->
fl_lmops = &nfsd_posix_mng_ops;
4171 nfs4_transform_lock_offset(file_lock);
4175 dprintk(
"NFSD: %s: unable to allocate lock!\n", __func__);
4183 update_stateid(&lock_stp->
st_stid.sc_stateid);
4184 memcpy(&lock->lk_resp_stateid, &lock_stp->
st_stid.sc_stateid,
4190 dprintk(
"NFSD: nfsd4_lock: conflicting lock found!\n");
4191 nfs4_set_lock_denied(conflock, &lock->lk_denied);
4197 dprintk(
"NFSD: nfsd4_lock: vfs_lock_file() failed! status %d\n",err);
4202 if (status && new_state)
4203 release_lockowner(lock_sop);
4237 struct inode *
inode;
4252 if (!nfsd4_has_session(cstate) && STALE_CLIENTID(&lockt->
lt_clientid, nn))
4258 inode = cstate->
current_fh.fh_dentry->d_inode;
4261 dprintk(
"NFSD: %s: unable to allocate lock!\n", __func__);
4276 dprintk(
"NFSD: nfs4_lockt: bad lock type!\n");
4290 nfs4_transform_lock_offset(file_lock);
4292 status = nfsd_test_lock(rqstp, &cstate->
current_fh, file_lock);
4298 nfs4_set_lock_denied(file_lock, &lockt->
lt_denied);
4312 struct file *filp =
NULL;
4317 dprintk(
"NFSD: nfsd4_locku: start=%Ld length=%Ld\n",
4326 status = nfs4_preprocess_seqid_op(cstate, locku->
lu_seqid,
4330 filp = find_any_file(stp->
st_file);
4337 dprintk(
"NFSD: %s: unable to allocate lock!\n", __func__);
4347 file_lock->
fl_lmops = &nfsd_posix_mng_ops;
4352 nfs4_transform_lock_offset(file_lock);
4359 dprintk(
"NFSD: nfs4_locku: vfs_lock_file failed!\n");
4365 update_stateid(&stp->
st_stid.sc_stateid);
4389 struct inode *inode = filp->
fi_inode;
4394 if ((*flpp)->fl_owner == (
fl_owner_t)lowner) {
4413 struct xdr_netobj *owner = &rlockowner->
rl_owner;
4415 unsigned int hashval = ownerstr_hashval(clid->
cl_id, owner);
4419 dprintk(
"nfsd4_release_lockowner clientid: (%08x/%08x):\n",
4425 if (STALE_CLIENTID(clid, nn))
4431 INIT_LIST_HEAD(&matches);
4436 if (!same_owner_str(sop, owner, clid))
4440 lo = lockowner(sop);
4441 if (check_for_locks(stp->
st_file, lo))
4443 list_add(&lo->
lo_list, &matches);
4450 while (!list_empty(&matches)) {
4456 release_lockowner(lo);
4472 unsigned int strhashval = clientstr_hashval(name);
4475 clp = find_confirmed_client_by_str(name, strhashval);
4487 unsigned int strhashval;
4491 crp = alloc_reclaim();
4494 strhashval = clientstr_hashval(name);
4496 list_add(&crp->
cr_strhash, &reclaim_str_hashtbl[strhashval]);
4498 reclaim_str_hashtbl_size++;
4509 while (!list_empty(&reclaim_str_hashtbl[i])) {
4510 crp =
list_entry(reclaim_str_hashtbl[i].next,
4514 reclaim_str_hashtbl_size--;
4517 BUG_ON(reclaim_str_hashtbl_size);
4525 unsigned int strhashval;
4528 dprintk(
"NFSD: nfs4_find_reclaim_client for %.*s with recdir %s\n",
4533 strhashval = clientstr_hashval(clp->
cl_recdir);
4551 clp = find_confirmed_client(clid, sessions);
4558 #ifdef CONFIG_NFSD_FAULT_INJECTION
4560 void nfsd_forget_clients(
u64 num)
4578 release_lockowner(lockowner(sop));
4583 release_openowner(openowner(sop));
4586 static int nfsd_release_n_owners(
u64 num,
bool is_open_owner,
4604 void nfsd_forget_locks(
u64 num)
4609 count = nfsd_release_n_owners(num,
false, release_lockowner_sop);
4615 void nfsd_forget_openowners(
u64 num)
4620 count = nfsd_release_n_owners(num,
true, release_openowner_sop);
4645 void nfsd_forget_delegations(
u64 num)
4651 spin_lock(&recall_lock);
4652 count = nfsd_process_n_delegations(num, &victims);
4653 spin_unlock(&recall_lock);
4657 unhash_delegation(dp);
4663 void nfsd_recall_delegations(
u64 num)
4669 spin_lock(&recall_lock);
4670 count = nfsd_process_n_delegations(num, &victims);
4673 nfsd_break_one_deleg(dp);
4675 spin_unlock(&recall_lock);
4690 INIT_LIST_HEAD(&conf_id_hashtbl[i]);
4691 INIT_LIST_HEAD(&conf_str_hashtbl[i]);
4692 INIT_LIST_HEAD(&unconf_str_hashtbl[i]);
4693 INIT_LIST_HEAD(&unconf_id_hashtbl[i]);
4694 INIT_LIST_HEAD(&reclaim_str_hashtbl[i]);
4697 INIT_LIST_HEAD(&sessionid_hashtbl[i]);
4699 INIT_LIST_HEAD(&file_hashtbl[i]);
4702 INIT_LIST_HEAD(&ownerstr_hashtbl[i]);
4705 INIT_LIST_HEAD(&lockowner_ino_hashtbl[i]);
4706 INIT_LIST_HEAD(&close_lru);
4707 INIT_LIST_HEAD(&client_lru);
4708 INIT_LIST_HEAD(&del_recall_lru);
4709 reclaim_str_hashtbl_size = 0;
4722 set_max_delegations(
void)
4762 if (laundry_wq ==
NULL) {
4768 goto out_free_laundry;
4770 set_max_delegations();
4781 __nfs4_state_shutdown(
void)
4789 while (!list_empty(&conf_id_hashtbl[i])) {
4791 destroy_client(clp);
4793 while (!list_empty(&unconf_str_hashtbl[i])) {
4795 destroy_client(clp);
4798 INIT_LIST_HEAD(&reaplist);
4799 spin_lock(&recall_lock);
4804 spin_unlock(&recall_lock);
4807 unhash_delegation(dp);
4824 __nfs4_state_shutdown();
4875 put_stateid(cstate, &lock->lk_resp_stateid);