Lines Matching +full:fails +full:- +full:without +full:- +full:test +full:- +full:cd

1 // SPDX-License-Identifier: GPL-2.0
32 * One maps client+vfsmnt+dentry to export options - the export map
33 * The other maps client+filehandle-fragment to export options. - the expkey map
41 #define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
47 if (test_bit(CACHE_VALID, &key->h.flags) && in expkey_put()
48 !test_bit(CACHE_NEGATIVE, &key->h.flags)) in expkey_put()
49 path_put(&key->ek_path); in expkey_put()
50 auth_domain_put(key->ek_client); in expkey_put()
54 static int expkey_upcall(struct cache_detail *cd, struct cache_head *h) in expkey_upcall() argument
56 return sunrpc_cache_pipe_upcall(cd, h); in expkey_upcall()
59 static void expkey_request(struct cache_detail *cd, in expkey_request() argument
67 qword_add(bpp, blen, ek->ek_client->name); in expkey_request()
68 snprintf(type, 5, "%d", ek->ek_fsidtype); in expkey_request()
70 qword_addhex(bpp, blen, (char*)ek->ek_fsid, key_len(ek->ek_fsidtype)); in expkey_request()
71 (*bpp)[-1] = '\n'; in expkey_request()
74 static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
76 static struct svc_expkey *svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *);
78 static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) in expkey_parse() argument
90 if (mesg[mlen - 1] != '\n') in expkey_parse()
91 return -EINVAL; in expkey_parse()
92 mesg[mlen-1] = 0; in expkey_parse()
95 err = -ENOMEM; in expkey_parse()
99 err = -EINVAL; in expkey_parse()
103 err = -ENOENT; in expkey_parse()
109 err = -EINVAL; in expkey_parse()
134 ek = svc_expkey_lookup(cd, &key); in expkey_parse()
135 err = -ENOMEM; in expkey_parse()
140 err = -EINVAL; in expkey_parse()
148 ek = svc_expkey_update(cd, &key, ek); in expkey_parse()
152 err = -ENOMEM; in expkey_parse()
160 ek = svc_expkey_update(cd, &key, ek); in expkey_parse()
164 err = -ENOMEM; in expkey_parse()
170 cache_put(&ek->h, cd); in expkey_parse()
178 struct cache_detail *cd, in expkey_show() argument
189 seq_printf(m, "%s %d 0x", ek->ek_client->name, in expkey_show()
190 ek->ek_fsidtype); in expkey_show()
191 for (i=0; i < key_len(ek->ek_fsidtype)/4; i++) in expkey_show()
192 seq_printf(m, "%08x", ek->ek_fsid[i]); in expkey_show()
193 if (test_bit(CACHE_VALID, &h->flags) && in expkey_show()
194 !test_bit(CACHE_NEGATIVE, &h->flags)) { in expkey_show()
196 seq_path(m, &ek->ek_path, "\\ \t\n"); in expkey_show()
207 if (orig->ek_fsidtype != new->ek_fsidtype || in expkey_match()
208 orig->ek_client != new->ek_client || in expkey_match()
209 memcmp(orig->ek_fsid, new->ek_fsid, key_len(orig->ek_fsidtype)) != 0) in expkey_match()
220 kref_get(&item->ek_client->ref); in expkey_init()
221 new->ek_client = item->ek_client; in expkey_init()
222 new->ek_fsidtype = item->ek_fsidtype; in expkey_init()
224 memcpy(new->ek_fsid, item->ek_fsid, sizeof(new->ek_fsid)); in expkey_init()
233 new->ek_path = item->ek_path; in expkey_update()
234 path_get(&item->ek_path); in expkey_update()
241 return &i->h; in expkey_alloc()
253 nfsd_file_cache_purge(current->nsproxy->net_ns); in expkey_flush()
276 int hash = item->ek_fsidtype; in svc_expkey_hash()
277 char * cp = (char*)item->ek_fsid; in svc_expkey_hash()
278 int len = key_len(item->ek_fsidtype); in svc_expkey_hash()
281 hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS); in svc_expkey_hash()
287 svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *item) in svc_expkey_lookup() argument
292 ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash); in svc_expkey_lookup()
300 svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new, in svc_expkey_update() argument
306 ch = sunrpc_cache_update(cd, &new->h, &old->h, hash); in svc_expkey_update()
319 struct nfsd4_fs_location *locations = fsloc->locations; in nfsd4_fslocs_free()
325 for (i = 0; i < fsloc->locations_count; i++) { in nfsd4_fslocs_free()
331 fsloc->locations = NULL; in nfsd4_fslocs_free()
337 path_put(&exp->ex_path); in svc_export_put()
338 auth_domain_put(exp->ex_client); in svc_export_put()
339 nfsd4_fslocs_free(&exp->ex_fslocs); in svc_export_put()
340 kfree(exp->ex_uuid); in svc_export_put()
344 static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h) in svc_export_upcall() argument
346 return sunrpc_cache_pipe_upcall(cd, h); in svc_export_upcall()
349 static void svc_export_request(struct cache_detail *cd, in svc_export_request() argument
357 qword_add(bpp, blen, exp->ex_client->name); in svc_export_request()
358 pth = d_path(&exp->ex_path, *bpp, *blen); in svc_export_request()
365 (*bpp)[-1] = '\n'; in svc_export_request()
379 if (!S_ISDIR(inode->i_mode) && in check_export()
380 !S_ISLNK(inode->i_mode) && in check_export()
381 !S_ISREG(inode->i_mode)) in check_export()
382 return -ENOTDIR; in check_export()
394 * or an FSID number (so NFSEXP_FSID or ->uuid is needed). in check_export()
398 if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) && in check_export()
401 dprintk("exp_export: export of non-dev fs without fsid\n"); in check_export()
402 return -EINVAL; in check_export()
405 if (!inode->i_sb->s_export_op || in check_export()
406 !inode->i_sb->s_export_op->fh_to_dentry) { in check_export()
408 return -EINVAL; in check_export()
424 if (fsloc->locations) in fsloc_parse()
425 return -EINVAL; in fsloc_parse()
428 err = get_uint(mesg, &fsloc->locations_count); in fsloc_parse()
431 if (fsloc->locations_count > MAX_FS_LOCATIONS) in fsloc_parse()
432 return -EINVAL; in fsloc_parse()
433 if (fsloc->locations_count == 0) in fsloc_parse()
436 fsloc->locations = kcalloc(fsloc->locations_count, in fsloc_parse()
439 if (!fsloc->locations) in fsloc_parse()
440 return -ENOMEM; in fsloc_parse()
441 for (i=0; i < fsloc->locations_count; i++) { in fsloc_parse()
443 err = -EINVAL; in fsloc_parse()
447 err = -ENOMEM; in fsloc_parse()
448 fsloc->locations[i].hosts = kstrdup(buf, GFP_KERNEL); in fsloc_parse()
449 if (!fsloc->locations[i].hosts) in fsloc_parse()
451 err = -EINVAL; in fsloc_parse()
456 err = -ENOMEM; in fsloc_parse()
457 fsloc->locations[i].path = kstrdup(buf, GFP_KERNEL); in fsloc_parse()
458 if (!fsloc->locations[i].path) in fsloc_parse()
465 err = -EINVAL; in fsloc_parse()
468 fsloc->migrated = migrated; in fsloc_parse()
482 if (exp->ex_nflavors) in secinfo_parse()
483 return -EINVAL; in secinfo_parse()
489 return -EINVAL; in secinfo_parse()
491 for (f = exp->ex_flavors; f < exp->ex_flavors + listsize; f++) { in secinfo_parse()
492 err = get_uint(mesg, &f->pseudoflavor); in secinfo_parse()
498 * problem at export time instead of when a client fails in secinfo_parse()
501 err = get_uint(mesg, &f->flags); in secinfo_parse()
505 if (~NFSEXP_SECINFO_FLAGS & (f->flags ^ exp->ex_flags)) in secinfo_parse()
506 return -EINVAL; in secinfo_parse()
508 exp->ex_nflavors = listsize; in secinfo_parse()
526 return -EINVAL; in nfsd_uuid_parse()
531 return -EINVAL; in nfsd_uuid_parse()
535 return -ENOMEM; in nfsd_uuid_parse()
540 static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) in svc_export_parse() argument
550 if (mesg[mlen-1] != '\n') in svc_export_parse()
551 return -EINVAL; in svc_export_parse()
552 mesg[mlen-1] = 0; in svc_export_parse()
556 return -ENOMEM; in svc_export_parse()
559 err = -EINVAL; in svc_export_parse()
564 err = -ENOENT; in svc_export_parse()
570 err = -EINVAL; in svc_export_parse()
579 exp.cd = cd; in svc_export_parse()
583 err = -EINVAL; in svc_export_parse()
590 if (err == -ENOENT) { in svc_export_parse()
625 * following. Newer user-space can try to set in svc_export_parse()
646 * invalid (-1) uid & gid on the "dummy" export which it in svc_export_parse()
647 * uses to test export support. To make sure exportfs in svc_export_parse()
651 err = -EINVAL; in svc_export_parse()
663 err = -ENOMEM; in svc_export_parse()
672 err = -ENOMEM; in svc_export_parse()
690 struct cache_detail *cd, in svc_export_show() argument
700 seq_path(m, &exp->ex_path, " \t\n\\"); in svc_export_show()
702 seq_escape(m, exp->ex_client->name, " \t\n\\"); in svc_export_show()
704 if (test_bit(CACHE_VALID, &h->flags) && in svc_export_show()
705 !test_bit(CACHE_NEGATIVE, &h->flags)) { in svc_export_show()
706 exp_flags(m, exp->ex_flags, exp->ex_fsid, in svc_export_show()
707 exp->ex_anon_uid, exp->ex_anon_gid, &exp->ex_fslocs); in svc_export_show()
708 if (exp->ex_uuid) { in svc_export_show()
714 seq_printf(m, "%02x", exp->ex_uuid[i]); in svc_export_show()
726 return orig->ex_client == new->ex_client && in svc_export_match()
727 path_equal(&orig->ex_path, &new->ex_path); in svc_export_match()
735 kref_get(&item->ex_client->ref); in svc_export_init()
736 new->ex_client = item->ex_client; in svc_export_init()
737 new->ex_path = item->ex_path; in svc_export_init()
738 path_get(&item->ex_path); in svc_export_init()
739 new->ex_fslocs.locations = NULL; in svc_export_init()
740 new->ex_fslocs.locations_count = 0; in svc_export_init()
741 new->ex_fslocs.migrated = 0; in svc_export_init()
742 new->ex_layout_types = 0; in svc_export_init()
743 new->ex_uuid = NULL; in svc_export_init()
744 new->cd = item->cd; in svc_export_init()
753 new->ex_flags = item->ex_flags; in export_update()
754 new->ex_anon_uid = item->ex_anon_uid; in export_update()
755 new->ex_anon_gid = item->ex_anon_gid; in export_update()
756 new->ex_fsid = item->ex_fsid; in export_update()
757 new->ex_devid_map = item->ex_devid_map; in export_update()
758 item->ex_devid_map = NULL; in export_update()
759 new->ex_uuid = item->ex_uuid; in export_update()
760 item->ex_uuid = NULL; in export_update()
761 new->ex_fslocs.locations = item->ex_fslocs.locations; in export_update()
762 item->ex_fslocs.locations = NULL; in export_update()
763 new->ex_fslocs.locations_count = item->ex_fslocs.locations_count; in export_update()
764 item->ex_fslocs.locations_count = 0; in export_update()
765 new->ex_fslocs.migrated = item->ex_fslocs.migrated; in export_update()
766 item->ex_fslocs.migrated = 0; in export_update()
767 new->ex_layout_types = item->ex_layout_types; in export_update()
768 new->ex_nflavors = item->ex_nflavors; in export_update()
770 new->ex_flavors[i] = item->ex_flavors[i]; in export_update()
778 return &i->h; in svc_export_alloc()
803 hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS); in svc_export_hash()
804 hash ^= hash_ptr(exp->ex_path.dentry, EXPORT_HASHBITS); in svc_export_hash()
805 hash ^= hash_ptr(exp->ex_path.mnt, EXPORT_HASHBITS); in svc_export_hash()
815 ch = sunrpc_cache_lookup_rcu(exp->cd, &exp->h, hash); in svc_export_lookup()
828 ch = sunrpc_cache_update(old->cd, &new->h, &old->h, hash); in svc_export_update()
837 exp_find_key(struct cache_detail *cd, struct auth_domain *clp, int fsid_type, in exp_find_key() argument
844 return ERR_PTR(-ENOENT); in exp_find_key()
850 ek = svc_expkey_lookup(cd, &key); in exp_find_key()
852 return ERR_PTR(-ENOMEM); in exp_find_key()
853 err = cache_check(cd, &ek->h, reqp); in exp_find_key()
862 exp_get_by_name(struct cache_detail *cd, struct auth_domain *clp, in exp_get_by_name() argument
869 return ERR_PTR(-ENOENT); in exp_get_by_name()
873 key.cd = cd; in exp_get_by_name()
877 return ERR_PTR(-ENOMEM); in exp_get_by_name()
878 err = cache_check(cd, &exp->h, reqp); in exp_get_by_name()
890 exp_parent(struct cache_detail *cd, struct auth_domain *clp, struct path *path) in exp_parent() argument
892 struct dentry *saved = dget(path->dentry); in exp_parent()
893 struct svc_export *exp = exp_get_by_name(cd, clp, path, NULL); in exp_parent()
895 while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) { in exp_parent()
896 struct dentry *parent = dget_parent(path->dentry); in exp_parent()
897 dput(path->dentry); in exp_parent()
898 path->dentry = parent; in exp_parent()
899 exp = exp_get_by_name(cd, clp, path, NULL); in exp_parent()
901 dput(path->dentry); in exp_parent()
902 path->dentry = saved; in exp_parent()
923 struct cache_detail *cd = nn->svc_export_cache; in exp_rootfh() local
925 err = -EPERM; in exp_rootfh()
926 /* NB: we probably ought to check that it's NUL-terminated */ in exp_rootfh()
934 name, path.dentry, clp->name, in exp_rootfh()
935 inode->i_sb->s_id, inode->i_ino); in exp_rootfh()
936 exp = exp_parent(cd, clp, &path); in exp_rootfh()
947 err = -EINVAL; in exp_rootfh()
958 static struct svc_export *exp_find(struct cache_detail *cd, in exp_find() argument
963 struct nfsd_net *nn = net_generic(cd->net, nfsd_net_id); in exp_find()
964 struct svc_expkey *ek = exp_find_key(nn->svc_expkey_cache, clp, fsid_type, fsidv, reqp); in exp_find()
968 exp = exp_get_by_name(cd, clp, &ek->ek_path, reqp); in exp_find()
969 cache_put(&ek->h, nn->svc_expkey_cache); in exp_find()
979 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors; in check_nfsd_access()
981 /* legacy gss-only clients are always OK: */ in check_nfsd_access()
982 if (exp->ex_client == rqstp->rq_gssclient) in check_nfsd_access()
984 /* ip-address based client; check sec= export option: */ in check_nfsd_access()
985 for (f = exp->ex_flavors; f < end; f++) { in check_nfsd_access()
986 if (f->pseudoflavor == rqstp->rq_cred.cr_flavor) in check_nfsd_access()
990 if (exp->ex_nflavors == 0) { in check_nfsd_access()
991 if (rqstp->rq_cred.cr_flavor == RPC_AUTH_NULL || in check_nfsd_access()
992 rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX) in check_nfsd_access()
1005 return rqstp->rq_vers < 4 ? nfserr_acces : nfserr_wrongsec; in check_nfsd_access()
1020 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); in rqst_exp_get_by_name()
1022 struct cache_detail *cd = nn->svc_export_cache; in rqst_exp_get_by_name() local
1024 if (rqstp->rq_client == NULL) in rqst_exp_get_by_name()
1028 exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle); in rqst_exp_get_by_name()
1029 if (PTR_ERR(exp) == -ENOENT) in rqst_exp_get_by_name()
1034 if (exp->ex_nflavors > 0) in rqst_exp_get_by_name()
1038 if (rqstp->rq_gssclient == NULL) in rqst_exp_get_by_name()
1040 gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle); in rqst_exp_get_by_name()
1041 if (PTR_ERR(gssexp) == -ENOENT) in rqst_exp_get_by_name()
1051 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); in rqst_exp_find()
1053 struct cache_detail *cd = nn->svc_export_cache; in rqst_exp_find() local
1055 if (rqstp->rq_client == NULL) in rqst_exp_find()
1059 exp = exp_find(cd, rqstp->rq_client, fsid_type, in rqst_exp_find()
1060 fsidv, &rqstp->rq_chandle); in rqst_exp_find()
1061 if (PTR_ERR(exp) == -ENOENT) in rqst_exp_find()
1066 if (exp->ex_nflavors > 0) in rqst_exp_find()
1070 if (rqstp->rq_gssclient == NULL) in rqst_exp_find()
1072 gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv, in rqst_exp_find()
1073 &rqstp->rq_chandle); in rqst_exp_find()
1074 if (PTR_ERR(gssexp) == -ENOENT) in rqst_exp_find()
1084 struct dentry *saved = dget(path->dentry); in rqst_exp_parent()
1087 while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) { in rqst_exp_parent()
1088 struct dentry *parent = dget_parent(path->dentry); in rqst_exp_parent()
1089 dput(path->dentry); in rqst_exp_parent()
1090 path->dentry = parent; in rqst_exp_parent()
1093 dput(path->dentry); in rqst_exp_parent()
1094 path->dentry = saved; in rqst_exp_parent()
1121 rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL); in exp_pseudoroot()
1152 for (flg = expflags; flg->flag; flg++) { in show_expflags()
1153 if (flg->flag & ~mask) in show_expflags()
1155 state = (flg->flag & flags) ? 0 : 1; in show_expflags()
1156 if (*flg->name[state]) in show_expflags()
1157 seq_printf(m, "%s%s", first++?",":"", flg->name[state]); in show_expflags()
1178 flags = (*fp)->flags; in show_secinfo_run()
1179 seq_printf(m, ",sec=%d", (*fp)->pseudoflavor); in show_secinfo_run()
1181 while (*fp != end && secinfo_flags_equal(flags, (*fp)->flags)) { in show_secinfo_run()
1182 seq_printf(m, ":%d", (*fp)->pseudoflavor); in show_secinfo_run()
1191 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors; in show_secinfo()
1194 if (exp->ex_nflavors == 0) in show_secinfo()
1196 f = exp->ex_flavors; in show_secinfo()
1198 if (!secinfo_flags_equal(flags, exp->ex_flags)) in show_secinfo()
1209 struct user_namespace *userns = m->file->f_cred->user_ns; in exp_flags()
1214 if (!uid_eq(anonu, make_kuid(userns, (uid_t)-2)) && in exp_flags()
1215 !uid_eq(anonu, make_kuid(userns, 0x10000-2))) in exp_flags()
1217 if (!gid_eq(anong, make_kgid(userns, (gid_t)-2)) && in exp_flags()
1218 !gid_eq(anong, make_kgid(userns, 0x10000-2))) in exp_flags()
1220 if (fsloc && fsloc->locations_count > 0) { in exp_flags()
1221 char *loctype = (fsloc->migrated) ? "refer" : "replicas"; in exp_flags()
1225 seq_escape(m, fsloc->locations[0].path, ",;@ \t\n\\"); in exp_flags()
1227 seq_escape(m, fsloc->locations[0].hosts, ",;@ \t\n\\"); in exp_flags()
1228 for (i = 1; i < fsloc->locations_count; i++) { in exp_flags()
1230 seq_escape(m, fsloc->locations[i].path, ",;@ \t\n\\"); in exp_flags()
1232 seq_escape(m, fsloc->locations[i].hosts, ",;@ \t\n\\"); in exp_flags()
1241 struct cache_detail *cd = m->private; in e_show() local
1250 if (cache_check(cd, &exp->h, NULL)) in e_show()
1253 return svc_export_show(m, cd, cp); in e_show()
1272 dprintk("nfsd: initializing export module (net: %x).\n", net->ns.inum); in nfsd_export_init()
1274 nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net); in nfsd_export_init()
1275 if (IS_ERR(nn->svc_export_cache)) in nfsd_export_init()
1276 return PTR_ERR(nn->svc_export_cache); in nfsd_export_init()
1277 rv = cache_register_net(nn->svc_export_cache, net); in nfsd_export_init()
1281 nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net); in nfsd_export_init()
1282 if (IS_ERR(nn->svc_expkey_cache)) { in nfsd_export_init()
1283 rv = PTR_ERR(nn->svc_expkey_cache); in nfsd_export_init()
1286 rv = cache_register_net(nn->svc_expkey_cache, net); in nfsd_export_init()
1292 cache_destroy_net(nn->svc_expkey_cache, net); in nfsd_export_init()
1294 cache_unregister_net(nn->svc_export_cache, net); in nfsd_export_init()
1296 cache_destroy_net(nn->svc_export_cache, net); in nfsd_export_init()
1301 * Flush exports table - called when last nfsd thread is killed
1308 cache_purge(nn->svc_expkey_cache); in nfsd_export_flush()
1309 cache_purge(nn->svc_export_cache); in nfsd_export_flush()
1320 dprintk("nfsd: shutting down export module (net: %x).\n", net->ns.inum); in nfsd_export_shutdown()
1322 cache_unregister_net(nn->svc_expkey_cache, net); in nfsd_export_shutdown()
1323 cache_unregister_net(nn->svc_export_cache, net); in nfsd_export_shutdown()
1324 cache_destroy_net(nn->svc_expkey_cache, net); in nfsd_export_shutdown()
1325 cache_destroy_net(nn->svc_export_cache, net); in nfsd_export_shutdown()
1328 dprintk("nfsd: export shutdown complete (net: %x).\n", net->ns.inum); in nfsd_export_shutdown()