4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (C) 2013, Trustees of Indiana University
25 * Copyright (c) 2017, Intel Corporation.
27 * Author: Joshua Walgenbach <jjw@iu.edu>
29 #include <linux/module.h>
30 #include <linux/sort.h>
31 #include <uapi/linux/lnet/nidstr.h>
32 #include <lustre_net.h>
33 #include <lustre_acl.h>
34 #include <lustre_eacl.h>
35 #include <obd_class.h>
36 #include "nodemap_internal.h"
38 #define HASH_NODEMAP_BKT_BITS 3
39 #define HASH_NODEMAP_CUR_BITS 3
40 #define HASH_NODEMAP_MAX_BITS 7
42 #define DEFAULT_NODEMAP "default"
44 /* nodemap proc root proc directory under fs/lustre */
45 struct proc_dir_entry *proc_lustre_nodemap_root;
47 /* Copy of config active flag to avoid locking in mapping functions */
50 /* Lock protecting the active config, useful primarily when proc and
51 * nodemap_hash might be replaced when loading a new config
52 * Any time the active config is referenced, the lock should be held.
54 DEFINE_MUTEX(active_config_lock);
55 struct nodemap_config *active_config;
60 * \param nodemap nodemap to destroy
62 static void nodemap_destroy(struct lu_nodemap *nodemap)
66 if (nodemap->nm_pde_data != NULL)
67 lprocfs_nodemap_remove(nodemap->nm_pde_data);
69 mutex_lock(&active_config_lock);
70 down_read(&active_config->nmc_range_tree_lock);
71 nm_member_reclassify_nodemap(nodemap);
72 up_read(&active_config->nmc_range_tree_lock);
74 down_write(&nodemap->nm_idmap_lock);
75 idmap_delete_tree(nodemap);
76 up_write(&nodemap->nm_idmap_lock);
78 mutex_unlock(&active_config_lock);
80 if (!list_empty(&nodemap->nm_member_list))
81 CWARN("nodemap_destroy failed to reclassify all members\n");
83 nm_member_delete_list(nodemap);
85 OBD_FREE_PTR(nodemap);
91 * Functions used for the cfs_hash
93 void nodemap_getref(struct lu_nodemap *nodemap)
95 atomic_inc(&nodemap->nm_refcount);
96 CDEBUG(D_INFO, "GETting nodemap %s(p=%p) : new refcount %d\n",
97 nodemap->nm_name, nodemap, atomic_read(&nodemap->nm_refcount));
101 * Destroy nodemap if last reference is put. Should be called outside
104 void nodemap_putref(struct lu_nodemap *nodemap)
109 LASSERT(atomic_read(&nodemap->nm_refcount) > 0);
111 CDEBUG(D_INFO, "PUTting nodemap %s(p=%p) : new refcount %d\n",
112 nodemap->nm_name, nodemap,
113 atomic_read(&nodemap->nm_refcount) - 1);
115 if (atomic_dec_and_test(&nodemap->nm_refcount))
116 nodemap_destroy(nodemap);
118 EXPORT_SYMBOL(nodemap_putref);
120 static __u32 nodemap_hashfn(struct cfs_hash *hash_body,
121 const void *key, unsigned mask)
123 return cfs_hash_djb2_hash(key, strlen(key), mask);
126 static void *nodemap_hs_key(struct hlist_node *hnode)
128 struct lu_nodemap *nodemap;
130 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
132 return nodemap->nm_name;
135 static int nodemap_hs_keycmp(const void *key,
136 struct hlist_node *compared_hnode)
140 nodemap_name = nodemap_hs_key(compared_hnode);
142 return !strcmp(key, nodemap_name);
145 static void *nodemap_hs_hashobject(struct hlist_node *hnode)
147 return hlist_entry(hnode, struct lu_nodemap, nm_hash);
150 static void nodemap_hs_get(struct cfs_hash *hs, struct hlist_node *hnode)
152 struct lu_nodemap *nodemap;
154 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
155 nodemap_getref(nodemap);
158 static void nodemap_hs_put_locked(struct cfs_hash *hs,
159 struct hlist_node *hnode)
161 struct lu_nodemap *nodemap;
163 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
164 nodemap_putref(nodemap);
167 static struct cfs_hash_ops nodemap_hash_operations = {
168 .hs_hash = nodemap_hashfn,
169 .hs_key = nodemap_hs_key,
170 .hs_keycmp = nodemap_hs_keycmp,
171 .hs_object = nodemap_hs_hashobject,
172 .hs_get = nodemap_hs_get,
173 .hs_put_locked = nodemap_hs_put_locked,
176 /* end of cfs_hash functions */
179 * Initialize nodemap_hash
182 * \retval -ENOMEM cannot create hash
184 static int nodemap_init_hash(struct nodemap_config *nmc)
186 nmc->nmc_nodemap_hash = cfs_hash_create("NODEMAP",
187 HASH_NODEMAP_CUR_BITS,
188 HASH_NODEMAP_MAX_BITS,
189 HASH_NODEMAP_BKT_BITS, 0,
192 &nodemap_hash_operations,
195 if (nmc->nmc_nodemap_hash == NULL) {
196 CERROR("cannot create nodemap_hash table\n");
204 * Check for valid nodemap name
206 * \param name nodemap name
208 * \retval false invalid
210 static bool nodemap_name_is_valid(const char *name)
212 if (strlen(name) > LUSTRE_NODEMAP_NAME_LENGTH ||
216 for (; *name != '\0'; name++) {
217 if (!isalnum(*name) && *name != '_')
227 * Look nodemap up in the active_config nodemap hash. Caller should hold the
228 * active_config_lock.
230 * \param name name of nodemap
231 * \retval nodemap pointer set to found nodemap
232 * \retval -EINVAL name is not valid
233 * \retval -ENOENT nodemap not found
235 struct lu_nodemap *nodemap_lookup(const char *name)
237 struct lu_nodemap *nodemap = NULL;
239 if (!nodemap_name_is_valid(name))
240 return ERR_PTR(-EINVAL);
242 nodemap = cfs_hash_lookup(active_config->nmc_nodemap_hash, name);
244 return ERR_PTR(-ENOENT);
250 * Classify the nid into the proper nodemap. Caller must hold active config and
251 * nm_range_tree_lock, and call nodemap_putref when done with nodemap.
253 * \param nid nid to classify
254 * \retval nodemap nodemap containing the nid
255 * \retval default_nodemap default nodemap
256 * \retval -EINVAL LO nid given without other local nid
258 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
260 struct lu_nid_range *range;
261 struct lu_nodemap *nodemap;
266 /* don't use 0@lo, use the first non-lo local NID instead */
267 if (nid == LNET_NID_LO_0) {
268 struct lnet_process_id id;
272 rc = LNetGetId(i++, &id);
274 RETURN(ERR_PTR(-EINVAL));
275 } while (id.nid == LNET_NID_LO_0);
278 CDEBUG(D_INFO, "found nid %s\n", libcfs_nid2str(nid));
281 range = range_search(&active_config->nmc_range_tree, nid);
283 nodemap = range->rn_nodemap;
285 nodemap = active_config->nmc_default_nodemap;
287 LASSERT(nodemap != NULL);
288 nodemap_getref(nodemap);
294 * simple check for default nodemap
296 static bool is_default_nodemap(const struct lu_nodemap *nodemap)
298 return nodemap->nm_id == 0;
302 * parse a nodemap range string into two nids
304 * \param range_str string to parse
305 * \param range[2] array of two nids
306 * \reyval 0 on success
308 int nodemap_parse_range(const char *range_str, lnet_nid_t range[2])
310 char buf[LNET_NIDSTR_SIZE * 2 + 2];
316 snprintf(buf, sizeof(buf), "%s", range_str);
318 start_nidstr = strsep(&ptr, ":");
319 end_nidstr = strsep(&ptr, ":");
321 if (start_nidstr == NULL || end_nidstr == NULL)
322 GOTO(out, rc = -EINVAL);
324 range[0] = libcfs_str2nid(start_nidstr);
325 range[1] = libcfs_str2nid(end_nidstr);
331 EXPORT_SYMBOL(nodemap_parse_range);
334 * parse a string containing an id map of form "client_id:filesystem_id"
335 * into an array of __u32 * for use in mapping functions
337 * \param idmap_str map string
338 * \param idmap array[2] of __u32
340 * \retval 0 on success
341 * \retval -EINVAL if idmap cannot be parsed
343 int nodemap_parse_idmap(char *idmap_str, __u32 idmap[2])
346 long unsigned int idmap_buf;
349 if (idmap_str == NULL)
352 sep = strchr(idmap_str, ':');
358 rc = kstrtoul(idmap_str, 10, &idmap_buf);
361 idmap[0] = idmap_buf;
363 rc = kstrtoul(sep, 10, &idmap_buf);
366 idmap[1] = idmap_buf;
370 EXPORT_SYMBOL(nodemap_parse_idmap);
373 * add a member to a nodemap
375 * \param nid nid to add to the members
376 * \param exp obd_export structure for the connection
377 * that is being added
378 * \retval -EINVAL export is NULL, or has invalid NID
379 * \retval -EEXIST export is already member of a nodemap
381 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp)
383 struct lu_nodemap *nodemap;
387 mutex_lock(&active_config_lock);
388 down_read(&active_config->nmc_range_tree_lock);
390 nodemap = nodemap_classify_nid(nid);
392 if (IS_ERR(nodemap)) {
393 CWARN("%s: error adding to nodemap, no valid NIDs found\n",
394 exp->exp_obd->obd_name);
397 rc = nm_member_add(nodemap, exp);
400 up_read(&active_config->nmc_range_tree_lock);
401 mutex_unlock(&active_config_lock);
403 if (!IS_ERR(nodemap))
404 nodemap_putref(nodemap);
408 EXPORT_SYMBOL(nodemap_add_member);
411 * delete a member from a nodemap
413 * \param exp export to remove from a nodemap
415 void nodemap_del_member(struct obd_export *exp)
417 struct lu_nodemap *nodemap;
421 /* using ac lock to prevent nodemap reclassification while deleting */
422 mutex_lock(&active_config_lock);
424 /* use of ted_nodemap is protected by active_config_lock. we take an
425 * extra reference to make sure nodemap isn't destroyed under
428 nodemap = exp->exp_target_data.ted_nodemap;
432 nodemap_getref(nodemap);
434 mutex_lock(&nodemap->nm_member_list_lock);
435 nm_member_del(nodemap, exp);
436 mutex_unlock(&nodemap->nm_member_list_lock);
439 mutex_unlock(&active_config_lock);
442 nodemap_putref(nodemap);
446 EXPORT_SYMBOL(nodemap_del_member);
449 * add an idmap to the proper nodemap trees
451 * \param nodemap nodemap to add idmap to
452 * \param id_type NODEMAP_UID or NODEMAP_GID
453 * \param map array[2] __u32 containing the map values
454 * map[0] is client id
455 * map[1] is the filesystem id
457 * \retval 0 on success
458 * \retval < 0 if error occurs
460 int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
461 enum nodemap_id_type id_type,
464 struct lu_idmap *idmap;
465 struct lu_idmap *temp;
468 idmap = idmap_create(map[0], map[1]);
470 GOTO(out, rc = -ENOMEM);
472 down_write(&nodemap->nm_idmap_lock);
473 temp = idmap_insert(id_type, idmap, nodemap);
474 /* If the new id_client or id_fs is matched, the old idmap and its
475 * index should be deleted according to its id_client before the new
476 * idmap is added again.
479 GOTO(out_insert, rc = PTR_ERR(temp));
483 del_map[0] = temp->id_client;
484 idmap_delete(id_type, temp, nodemap);
485 rc = nodemap_idx_idmap_del(nodemap, id_type, del_map);
486 /* In case there is any corrupted idmap */
487 if (!rc || unlikely(rc == -ENOENT)) {
488 temp = idmap_insert(id_type, idmap, nodemap);
500 up_write(&nodemap->nm_idmap_lock);
501 nm_member_revoke_locks(nodemap);
507 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
510 struct lu_nodemap *nodemap = NULL;
515 mutex_lock(&active_config_lock);
516 nodemap = nodemap_lookup(name);
517 if (IS_ERR(nodemap)) {
518 mutex_unlock(&active_config_lock);
519 GOTO(out, rc = PTR_ERR(nodemap));
522 if (is_default_nodemap(nodemap)) {
525 rc = nodemap_add_idmap_helper(nodemap, id_type, map);
527 rc = nodemap_idx_idmap_add(nodemap, id_type, map);
529 mutex_unlock(&active_config_lock);
530 nodemap_putref(nodemap);
535 EXPORT_SYMBOL(nodemap_add_idmap);
538 * delete idmap from proper nodemap tree
540 * \param name name of nodemap
541 * \param id_type NODEMAP_UID or NODEMAP_GID
542 * \param map array[2] __u32 containing the mapA values
543 * map[0] is client id
544 * map[1] is the filesystem id
546 * \retval 0 on success
548 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
551 struct lu_nodemap *nodemap = NULL;
552 struct lu_idmap *idmap = NULL;
557 mutex_lock(&active_config_lock);
558 nodemap = nodemap_lookup(name);
559 if (IS_ERR(nodemap)) {
560 mutex_unlock(&active_config_lock);
561 GOTO(out, rc = PTR_ERR(nodemap));
564 if (is_default_nodemap(nodemap))
565 GOTO(out_putref, rc = -EINVAL);
567 down_write(&nodemap->nm_idmap_lock);
568 idmap = idmap_search(nodemap, NODEMAP_CLIENT_TO_FS, id_type,
573 idmap_delete(id_type, idmap, nodemap);
574 rc = nodemap_idx_idmap_del(nodemap, id_type, map);
576 up_write(&nodemap->nm_idmap_lock);
579 mutex_unlock(&active_config_lock);
581 nm_member_revoke_locks(nodemap);
582 nodemap_putref(nodemap);
587 EXPORT_SYMBOL(nodemap_del_idmap);
590 * Get nodemap assigned to given export. Takes a reference on the nodemap.
592 * Note that this function may return either NULL, or an ERR_PTR()
593 * or a valid nodemap pointer. All of the functions accessing the
594 * returned nodemap can check IS_ERR(nodemap) to see if an error is
595 * returned. NULL is not considered an error, which is OK since this
596 * is a valid case if nodemap are not in use. All nodemap handling
597 * functions must check for nodemap == NULL and do nothing, and the
598 * nodemap returned from this function should not be dereferenced.
600 * \param export export to get nodemap for
602 * \retval pointer to nodemap on success
603 * \retval NULL nodemap subsystem disabled
604 * \retval -EACCES export does not have nodemap assigned
606 struct lu_nodemap *nodemap_get_from_exp(struct obd_export *exp)
608 struct lu_nodemap *nodemap;
615 spin_lock(&exp->exp_target_data.ted_nodemap_lock);
616 nodemap = exp->exp_target_data.ted_nodemap;
618 nodemap_getref(nodemap);
619 spin_unlock(&exp->exp_target_data.ted_nodemap_lock);
622 CDEBUG(D_INFO, "%s: nodemap null on export %s (at %s)\n",
623 exp->exp_obd->obd_name,
624 obd_uuid2str(&exp->exp_client_uuid),
625 obd_export_nid2str(exp));
626 RETURN(ERR_PTR(-EACCES));
631 EXPORT_SYMBOL(nodemap_get_from_exp);
634 * mapping function for nodemap idmaps
636 * \param nodemap lu_nodemap structure defining nodemap
637 * \param node_type NODEMAP_UID or NODEMAP_GID
638 * \param tree_type NODEMAP_CLIENT_TO_FS or
639 * NODEMAP_FS_TO_CLIENT
640 * \param id id to map
642 * \retval mapped id according to the rules below.
644 * if the nodemap_active is false, just return the passed id without mapping
646 * if the id to be looked up is 0, check that root access is allowed and if it
647 * is, return 0. Otherwise, return the squash uid or gid.
649 * if the nodemap is configured to trusted the ids from the client system, just
650 * return the passed id without mapping.
652 * if by this point, we haven't returned and the nodemap in question is the
653 * default nodemap, return the squash uid or gid.
655 * after these checks, search the proper tree for the mapping, and if found
656 * return the mapped value, otherwise return the squash uid or gid.
658 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
659 enum nodemap_id_type id_type,
660 enum nodemap_tree_type tree_type, __u32 id)
662 struct lu_idmap *idmap = NULL;
670 if (unlikely(nodemap == NULL))
673 if (nodemap->nmf_map_uid_only && id_type == NODEMAP_GID)
676 if (nodemap->nmf_map_gid_only && id_type == NODEMAP_UID)
680 if (nodemap->nmf_allow_root_access)
686 if (nodemap->nmf_trust_client_ids)
689 if (is_default_nodemap(nodemap))
692 down_read(&nodemap->nm_idmap_lock);
693 idmap = idmap_search(nodemap, tree_type, id_type, id);
695 up_read(&nodemap->nm_idmap_lock);
699 if (tree_type == NODEMAP_FS_TO_CLIENT)
700 found_id = idmap->id_client;
702 found_id = idmap->id_fs;
703 up_read(&nodemap->nm_idmap_lock);
707 if (id_type == NODEMAP_UID)
708 RETURN(nodemap->nm_squash_uid);
710 RETURN(nodemap->nm_squash_gid);
714 EXPORT_SYMBOL(nodemap_map_id);
717 * Map posix ACL entries according to the nodemap membership. Removes any
720 * \param lu_nodemap nodemap
721 * \param buf buffer containing xattr encoded ACLs
722 * \param size size of ACLs in bytes
723 * \param tree_type direction of mapping
724 * \retval size new size of ACLs in bytes
725 * \retval -EINVAL bad \a size param, see posix_acl_xattr_count()
727 ssize_t nodemap_map_acl(struct lu_nodemap *nodemap, void *buf, size_t size,
728 enum nodemap_tree_type tree_type)
730 posix_acl_xattr_header *header = buf;
731 posix_acl_xattr_entry *entry = GET_POSIX_ACL_XATTR_ENTRY(header);
732 posix_acl_xattr_entry *new_entry = entry;
733 posix_acl_xattr_entry *end;
741 if (unlikely(nodemap == NULL))
744 count = posix_acl_xattr_count(size);
750 for (end = entry + count; entry != end; entry++) {
751 __u16 tag = le16_to_cpu(entry->e_tag);
752 __u32 id = le32_to_cpu(entry->e_id);
756 id = nodemap_map_id(nodemap, NODEMAP_UID,
758 if (id == nodemap->nm_squash_uid)
760 entry->e_id = cpu_to_le32(id);
763 id = nodemap_map_id(nodemap, NODEMAP_GID,
765 if (id == nodemap->nm_squash_gid)
767 entry->e_id = cpu_to_le32(id);
771 /* if we skip an ACL, copy the following ones over it */
772 if (new_entry != entry)
778 RETURN((void *)new_entry - (void *)header);
780 EXPORT_SYMBOL(nodemap_map_acl);
783 * Add nid range to given nodemap
785 * \param config nodemap config to work on
786 * \param nodemap nodemap to add range to
787 * \param nid nid range to add
788 * \param range_id should be 0 unless loading from disk
793 int nodemap_add_range_helper(struct nodemap_config *config,
794 struct lu_nodemap *nodemap,
795 const lnet_nid_t nid[2],
796 unsigned int range_id)
798 struct lu_nid_range *range;
801 down_write(&config->nmc_range_tree_lock);
802 range = range_create(&config->nmc_range_tree, nid[0], nid[1],
805 up_write(&config->nmc_range_tree_lock);
806 GOTO(out, rc = -ENOMEM);
809 rc = range_insert(&config->nmc_range_tree, range);
811 CERROR("cannot insert nodemap range into '%s': rc = %d\n",
812 nodemap->nm_name, rc);
813 up_write(&config->nmc_range_tree_lock);
814 list_del(&range->rn_list);
815 range_destroy(range);
816 GOTO(out, rc = -ENOMEM);
819 list_add(&range->rn_list, &nodemap->nm_ranges);
821 /* nodemaps have no members if they aren't on the active config */
822 if (config == active_config)
823 nm_member_reclassify_nodemap(config->nmc_default_nodemap);
825 up_write(&config->nmc_range_tree_lock);
827 /* if range_id is non-zero, we are loading from disk */
829 rc = nodemap_idx_range_add(range, nid);
831 if (config == active_config) {
832 nm_member_revoke_locks(config->nmc_default_nodemap);
833 nm_member_revoke_locks(nodemap);
839 int nodemap_add_range(const char *name, const lnet_nid_t nid[2])
841 struct lu_nodemap *nodemap = NULL;
844 mutex_lock(&active_config_lock);
845 nodemap = nodemap_lookup(name);
846 if (IS_ERR(nodemap)) {
847 mutex_unlock(&active_config_lock);
848 GOTO(out, rc = PTR_ERR(nodemap));
851 if (is_default_nodemap(nodemap))
854 rc = nodemap_add_range_helper(active_config, nodemap, nid, 0);
855 mutex_unlock(&active_config_lock);
856 nodemap_putref(nodemap);
860 EXPORT_SYMBOL(nodemap_add_range);
864 * \param name nodemap name
865 * \param nid nid range
866 * \retval 0 on success
868 * Delete range from global range tree, and remove it
869 * from the list in the associated nodemap.
871 int nodemap_del_range(const char *name, const lnet_nid_t nid[2])
873 struct lu_nodemap *nodemap;
874 struct lu_nid_range *range;
877 mutex_lock(&active_config_lock);
878 nodemap = nodemap_lookup(name);
879 if (IS_ERR(nodemap)) {
880 mutex_unlock(&active_config_lock);
881 GOTO(out, rc = PTR_ERR(nodemap));
884 if (is_default_nodemap(nodemap))
885 GOTO(out_putref, rc = -EINVAL);
887 down_write(&active_config->nmc_range_tree_lock);
888 range = range_find(&active_config->nmc_range_tree, nid[0], nid[1]);
890 up_write(&active_config->nmc_range_tree_lock);
891 GOTO(out_putref, rc = -EINVAL);
893 if (range->rn_nodemap != nodemap) {
894 up_write(&active_config->nmc_range_tree_lock);
895 GOTO(out_putref, rc = -EINVAL);
897 rc = nodemap_idx_range_del(range);
898 range_delete(&active_config->nmc_range_tree, range);
899 nm_member_reclassify_nodemap(nodemap);
900 up_write(&active_config->nmc_range_tree_lock);
902 nm_member_revoke_locks(active_config->nmc_default_nodemap);
903 nm_member_revoke_locks(nodemap);
906 mutex_unlock(&active_config_lock);
907 nodemap_putref(nodemap);
911 EXPORT_SYMBOL(nodemap_del_range);
914 * set fileset on nodemap
915 * \param name nodemap to set fileset on
916 * \param fileset string containing fileset
917 * \retval 0 on success
919 * set a fileset on the named nodemap
921 static int nodemap_set_fileset_helper(struct nodemap_config *config,
922 struct lu_nodemap *nodemap,
927 /* Allow 'fileset=clear' in addition to 'fileset=""' to clear fileset
928 * because either command 'lctl set_param -P *.*.fileset=""' or
929 * 'lctl nodemap_set_fileset --fileset ""' can only work correctly
930 * on MGS, while on other servers, both commands will invoke upcall
931 * "/usr/sbin/lctl set_param nodemap.default.fileset=" by function
932 * process_param2_config(), which will cause "no value" error and
933 * won't clear fileset.
934 * 'fileset=""' is still kept for compatibility reason.
938 else if (fileset[0] == '\0' || strcmp(fileset, "clear") == 0)
939 nodemap->nm_fileset[0] = '\0';
940 else if (fileset[0] != '/')
942 else if (strlcpy(nodemap->nm_fileset, fileset,
943 sizeof(nodemap->nm_fileset)) >=
944 sizeof(nodemap->nm_fileset))
950 int nodemap_set_fileset(const char *name, const char *fileset)
952 struct lu_nodemap *nodemap = NULL;
955 mutex_lock(&active_config_lock);
956 nodemap = nodemap_lookup(name);
957 if (IS_ERR(nodemap)) {
958 mutex_unlock(&active_config_lock);
959 GOTO(out, rc = PTR_ERR(nodemap));
962 rc = nodemap_set_fileset_helper(active_config, nodemap, fileset);
963 mutex_unlock(&active_config_lock);
965 nodemap_putref(nodemap);
969 EXPORT_SYMBOL(nodemap_set_fileset);
972 * get fileset defined on nodemap
973 * \param nodemap nodemap to get fileset from
974 * \retval fileset name, or NULL if not defined or not activated
976 * get the fileset defined on the nodemap
978 char *nodemap_get_fileset(const struct lu_nodemap *nodemap)
983 return (char *)nodemap->nm_fileset;
985 EXPORT_SYMBOL(nodemap_get_fileset);
987 static int nodemap_validate_sepol(const char *sepol)
989 char buf[LUSTRE_NODEMAP_SEPOL_LENGTH + 1];
990 char *p = (char *)sepol;
992 char polname[NAME_MAX + 1] = "";
993 char hash[SELINUX_POLICY_HASH_LEN + 1] = "";
997 CLASSERT(sizeof(buf) == sizeof(((struct lu_nodemap *)0)->nm_sepol));
1002 /* we allow sepol = "" which means clear SELinux policy info */
1003 if (sepol[0] == '\0')
1006 /* make a copy of sepol, by replacing ':' with space
1007 * so that we can use sscanf over the string
1009 while (p-sepol < sizeof(buf)) {
1019 if (p-sepol == sizeof(buf))
1020 return -ENAMETOOLONG;
1022 if (sscanf(buf, "%1hhu %s %hu %s", &mode, polname, &ver, hash) != 4)
1025 if (mode != 0 && mode != 1)
1032 * set SELinux policy on nodemap
1033 * \param name nodemap to set SELinux policy info on
1034 * \param sepol string containing SELinux policy info
1035 * \retval 0 on success
1037 * set SELinux policy info on the named nodemap
1039 int nodemap_set_sepol(const char *name, const char *sepol)
1041 struct lu_nodemap *nodemap = NULL;
1044 rc = nodemap_validate_sepol(sepol);
1048 mutex_lock(&active_config_lock);
1049 nodemap = nodemap_lookup(name);
1050 if (IS_ERR(nodemap)) {
1051 mutex_unlock(&active_config_lock);
1052 GOTO(out, rc = PTR_ERR(nodemap));
1055 if (is_default_nodemap(nodemap)) {
1056 /* We do not want nodes in the default nodemap to have
1057 * SELinux restrictions. Sec admin should create dedicated
1058 * nodemap entries for this.
1060 GOTO(out_putref, rc = -EINVAL);
1063 /* truncation cannot happen, as string length was checked in
1064 * nodemap_validate_sepol()
1066 strlcpy(nodemap->nm_sepol, sepol, sizeof(nodemap->nm_sepol));
1069 mutex_unlock(&active_config_lock);
1070 nodemap_putref(nodemap);
1074 EXPORT_SYMBOL(nodemap_set_sepol);
1077 * get SELinux policy info defined on nodemap
1078 * \param nodemap nodemap to get SELinux policy info from
1079 * \retval SELinux policy info, or NULL if not defined or not activated
1081 * get the SELinux policy info defined on the nodemap
1083 const char *nodemap_get_sepol(const struct lu_nodemap *nodemap)
1085 if (is_default_nodemap(nodemap))
1088 return (char *)nodemap->nm_sepol;
1090 EXPORT_SYMBOL(nodemap_get_sepol);
1093 * Nodemap constructor
1095 * Creates an lu_nodemap structure and assigns sane default
1096 * member values. If this is the default nodemap, the defaults
1097 * are the most restrictive in terms of mapping behavior. Otherwise
1098 * the default flags should be inherited from the default nodemap.
1099 * The adds nodemap to nodemap_hash.
1101 * Requires that the caller take the active_config_lock
1103 * \param name name of nodemap
1104 * \param is_default true if default nodemap
1105 * \retval nodemap success
1106 * \retval -EINVAL invalid nodemap name
1107 * \retval -EEXIST nodemap already exists
1108 * \retval -ENOMEM cannot allocate memory for nodemap
1110 struct lu_nodemap *nodemap_create(const char *name,
1111 struct nodemap_config *config,
1114 struct lu_nodemap *nodemap = NULL;
1115 struct lu_nodemap *default_nodemap;
1116 struct cfs_hash *hash = config->nmc_nodemap_hash;
1120 default_nodemap = config->nmc_default_nodemap;
1122 if (!nodemap_name_is_valid(name))
1123 GOTO(out, rc = -EINVAL);
1126 CERROR("Config nodemap hash is NULL, unable to add %s\n", name);
1127 GOTO(out, rc = -EINVAL);
1130 OBD_ALLOC_PTR(nodemap);
1131 if (nodemap == NULL) {
1132 CERROR("cannot allocate memory (%zu bytes)"
1133 "for nodemap '%s'\n", sizeof(*nodemap),
1135 GOTO(out, rc = -ENOMEM);
1139 * take an extra reference to prevent nodemap from being destroyed
1140 * while it's being created.
1142 atomic_set(&nodemap->nm_refcount, 2);
1143 snprintf(nodemap->nm_name, sizeof(nodemap->nm_name), "%s", name);
1144 rc = cfs_hash_add_unique(hash, name, &nodemap->nm_hash);
1146 OBD_FREE_PTR(nodemap);
1147 GOTO(out, rc = -EEXIST);
1150 INIT_LIST_HEAD(&nodemap->nm_ranges);
1151 INIT_LIST_HEAD(&nodemap->nm_list);
1152 INIT_LIST_HEAD(&nodemap->nm_member_list);
1154 mutex_init(&nodemap->nm_member_list_lock);
1155 init_rwsem(&nodemap->nm_idmap_lock);
1156 nodemap->nm_fs_to_client_uidmap = RB_ROOT;
1157 nodemap->nm_client_to_fs_uidmap = RB_ROOT;
1158 nodemap->nm_fs_to_client_gidmap = RB_ROOT;
1159 nodemap->nm_client_to_fs_gidmap = RB_ROOT;
1162 nodemap->nm_id = LUSTRE_NODEMAP_DEFAULT_ID;
1163 config->nmc_default_nodemap = nodemap;
1165 config->nmc_nodemap_highest_id++;
1166 nodemap->nm_id = config->nmc_nodemap_highest_id;
1169 if (is_default || default_nodemap == NULL) {
1170 nodemap->nmf_trust_client_ids = 0;
1171 nodemap->nmf_allow_root_access = 0;
1172 nodemap->nmf_deny_unknown = 0;
1173 nodemap->nmf_map_uid_only = 0;
1174 nodemap->nmf_map_gid_only = 0;
1175 nodemap->nmf_enable_audit = 1;
1177 nodemap->nm_squash_uid = NODEMAP_NOBODY_UID;
1178 nodemap->nm_squash_gid = NODEMAP_NOBODY_GID;
1179 nodemap->nm_fileset[0] = '\0';
1180 nodemap->nm_sepol[0] = '\0';
1182 CWARN("adding nodemap '%s' to config without"
1183 " default nodemap\n", nodemap->nm_name);
1185 nodemap->nmf_trust_client_ids =
1186 default_nodemap->nmf_trust_client_ids;
1187 nodemap->nmf_allow_root_access =
1188 default_nodemap->nmf_allow_root_access;
1189 nodemap->nmf_deny_unknown =
1190 default_nodemap->nmf_deny_unknown;
1191 nodemap->nmf_map_uid_only =
1192 default_nodemap->nmf_map_uid_only;
1193 nodemap->nmf_map_gid_only =
1194 default_nodemap->nmf_map_gid_only;
1195 nodemap->nmf_enable_audit =
1196 default_nodemap->nmf_enable_audit;
1198 nodemap->nm_squash_uid = default_nodemap->nm_squash_uid;
1199 nodemap->nm_squash_gid = default_nodemap->nm_squash_gid;
1200 nodemap->nm_fileset[0] = '\0';
1201 nodemap->nm_sepol[0] = '\0';
1207 CERROR("cannot add nodemap: '%s': rc = %d\n", name, rc);
1208 RETURN(ERR_PTR(rc));
1212 * Set the nmf_deny_unknown flag to true or false.
1213 * \param name nodemap name
1214 * \param deny_unknown if true, squashed users will get EACCES
1215 * \retval 0 on success
1218 int nodemap_set_deny_unknown(const char *name, bool deny_unknown)
1220 struct lu_nodemap *nodemap = NULL;
1223 mutex_lock(&active_config_lock);
1224 nodemap = nodemap_lookup(name);
1225 mutex_unlock(&active_config_lock);
1226 if (IS_ERR(nodemap))
1227 GOTO(out, rc = PTR_ERR(nodemap));
1229 nodemap->nmf_deny_unknown = deny_unknown;
1230 rc = nodemap_idx_nodemap_update(nodemap);
1232 nm_member_revoke_locks(nodemap);
1233 nodemap_putref(nodemap);
1237 EXPORT_SYMBOL(nodemap_set_deny_unknown);
1240 * Set the nmf_allow_root_access flag to true or false.
1241 * \param name nodemap name
1242 * \param allow_root if true, nodemap will not squash the root user
1243 * \retval 0 on success
1246 int nodemap_set_allow_root(const char *name, bool allow_root)
1248 struct lu_nodemap *nodemap = NULL;
1251 mutex_lock(&active_config_lock);
1252 nodemap = nodemap_lookup(name);
1253 mutex_unlock(&active_config_lock);
1254 if (IS_ERR(nodemap))
1255 GOTO(out, rc = PTR_ERR(nodemap));
1257 nodemap->nmf_allow_root_access = allow_root;
1258 rc = nodemap_idx_nodemap_update(nodemap);
1260 nm_member_revoke_locks(nodemap);
1261 nodemap_putref(nodemap);
1265 EXPORT_SYMBOL(nodemap_set_allow_root);
1268 * Set the nmf_trust_client_ids flag to true or false.
1270 * \param name nodemap name
1271 * \param trust_client_ids if true, nodemap will not map its IDs
1272 * \retval 0 on success
1275 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids)
1277 struct lu_nodemap *nodemap = NULL;
1280 mutex_lock(&active_config_lock);
1281 nodemap = nodemap_lookup(name);
1282 mutex_unlock(&active_config_lock);
1283 if (IS_ERR(nodemap))
1284 GOTO(out, rc = PTR_ERR(nodemap));
1286 nodemap->nmf_trust_client_ids = trust_client_ids;
1287 rc = nodemap_idx_nodemap_update(nodemap);
1289 nm_member_revoke_locks(nodemap);
1290 nodemap_putref(nodemap);
1294 EXPORT_SYMBOL(nodemap_set_trust_client_ids);
1296 int nodemap_set_mapping_mode(const char *name, enum nodemap_mapping_modes mode)
1298 struct lu_nodemap *nodemap = NULL;
1301 mutex_lock(&active_config_lock);
1302 nodemap = nodemap_lookup(name);
1303 mutex_unlock(&active_config_lock);
1304 if (IS_ERR(nodemap))
1305 GOTO(out, rc = PTR_ERR(nodemap));
1308 case NODEMAP_MAP_BOTH:
1309 nodemap->nmf_map_uid_only = 0;
1310 nodemap->nmf_map_gid_only = 0;
1312 case NODEMAP_MAP_UID_ONLY:
1313 nodemap->nmf_map_uid_only = 1;
1314 nodemap->nmf_map_gid_only = 0;
1316 case NODEMAP_MAP_GID_ONLY:
1317 nodemap->nmf_map_uid_only = 0;
1318 nodemap->nmf_map_gid_only = 1;
1321 CWARN("cannot set unknown mapping mode, mode = %d\n", mode);
1323 rc = nodemap_idx_nodemap_update(nodemap);
1325 nm_member_revoke_locks(nodemap);
1326 nodemap_putref(nodemap);
1330 EXPORT_SYMBOL(nodemap_set_mapping_mode);
1333 * Update the squash_uid for a nodemap.
1335 * \param name nodemap name
1336 * \param uid the new uid to squash unknown users to
1337 * \retval 0 on success
1339 * Update the squash_uid for a nodemap. The squash_uid is the uid
1340 * that the all client uids are mapped to if nodemap is active,
1341 * the trust_client_ids flag is not set, and the uid is not in
1344 int nodemap_set_squash_uid(const char *name, uid_t uid)
1346 struct lu_nodemap *nodemap = NULL;
1349 mutex_lock(&active_config_lock);
1350 nodemap = nodemap_lookup(name);
1351 mutex_unlock(&active_config_lock);
1352 if (IS_ERR(nodemap))
1353 GOTO(out, rc = PTR_ERR(nodemap));
1355 nodemap->nm_squash_uid = uid;
1356 rc = nodemap_idx_nodemap_update(nodemap);
1358 nm_member_revoke_locks(nodemap);
1359 nodemap_putref(nodemap);
1363 EXPORT_SYMBOL(nodemap_set_squash_uid);
1366 * Update the squash_gid for a nodemap.
1368 * \param name nodemap name
1369 * \param gid the new gid to squash unknown gids to
1370 * \retval 0 on success
1372 * Update the squash_gid for a nodemap. The squash_uid is the gid
1373 * that the all client gids are mapped to if nodemap is active,
1374 * the trust_client_ids flag is not set, and the gid is not in
1377 int nodemap_set_squash_gid(const char *name, gid_t gid)
1379 struct lu_nodemap *nodemap = NULL;
1382 mutex_lock(&active_config_lock);
1383 nodemap = nodemap_lookup(name);
1384 mutex_unlock(&active_config_lock);
1385 if (IS_ERR(nodemap))
1386 GOTO(out, rc = PTR_ERR(nodemap));
1388 nodemap->nm_squash_gid = gid;
1389 rc = nodemap_idx_nodemap_update(nodemap);
1391 nm_member_revoke_locks(nodemap);
1392 nodemap_putref(nodemap);
1396 EXPORT_SYMBOL(nodemap_set_squash_gid);
1399 * Returns true if this nodemap has root user access. Always returns true if
1400 * nodemaps are not active.
1402 * \param nodemap nodemap to check access for
1404 bool nodemap_can_setquota(const struct lu_nodemap *nodemap)
1406 return !nodemap_active || (nodemap && nodemap->nmf_allow_root_access);
1408 EXPORT_SYMBOL(nodemap_can_setquota);
1411 * Set the nmf_enable_audit flag to true or false.
1412 * \param name nodemap name
1413 * \param audit_mode if true, allow audit
1414 * \retval 0 on success
1417 int nodemap_set_audit_mode(const char *name, bool enable_audit)
1419 struct lu_nodemap *nodemap = NULL;
1422 mutex_lock(&active_config_lock);
1423 nodemap = nodemap_lookup(name);
1424 mutex_unlock(&active_config_lock);
1425 if (IS_ERR(nodemap))
1426 GOTO(out, rc = PTR_ERR(nodemap));
1428 nodemap->nmf_enable_audit = enable_audit;
1429 rc = nodemap_idx_nodemap_update(nodemap);
1431 nm_member_revoke_locks(nodemap);
1432 nodemap_putref(nodemap);
1436 EXPORT_SYMBOL(nodemap_set_audit_mode);
1442 * \param name name of nodemap
1444 * \retval -EINVAL invalid nodemap name
1445 * \retval -EEXIST nodemap already exists
1446 * \retval -ENOMEM cannot allocate memory for nodemap
1448 int nodemap_add(const char *nodemap_name)
1450 struct lu_nodemap *nodemap;
1453 mutex_lock(&active_config_lock);
1454 nodemap = nodemap_create(nodemap_name, active_config, 0);
1455 if (IS_ERR(nodemap)) {
1456 mutex_unlock(&active_config_lock);
1457 return PTR_ERR(nodemap);
1460 rc = nodemap_idx_nodemap_add(nodemap);
1462 rc = lprocfs_nodemap_register(nodemap, 0);
1464 mutex_unlock(&active_config_lock);
1465 nodemap_putref(nodemap);
1469 EXPORT_SYMBOL(nodemap_add);
1474 * \param name name of nodemmap
1476 * \retval -EINVAL invalid input
1477 * \retval -ENOENT no existing nodemap
1479 int nodemap_del(const char *nodemap_name)
1481 struct lu_nodemap *nodemap;
1482 struct lu_nid_range *range;
1483 struct lu_nid_range *range_temp;
1487 if (strcmp(nodemap_name, DEFAULT_NODEMAP) == 0)
1490 mutex_lock(&active_config_lock);
1491 nodemap = cfs_hash_del_key(active_config->nmc_nodemap_hash,
1493 if (nodemap == NULL) {
1494 mutex_unlock(&active_config_lock);
1495 GOTO(out, rc = -ENOENT);
1498 /* erase nodemap from active ranges to prevent client assignment */
1499 down_write(&active_config->nmc_range_tree_lock);
1500 list_for_each_entry_safe(range, range_temp, &nodemap->nm_ranges,
1502 rc2 = nodemap_idx_range_del(range);
1506 range_delete(&active_config->nmc_range_tree, range);
1508 up_write(&active_config->nmc_range_tree_lock);
1510 rc2 = nodemap_idx_nodemap_del(nodemap);
1515 * remove procfs here in case nodemap_create called with same name
1516 * before nodemap_destroy is run.
1518 lprocfs_nodemap_remove(nodemap->nm_pde_data);
1519 nodemap->nm_pde_data = NULL;
1521 /* reclassify all member exports from nodemap, so they put their refs */
1522 down_read(&active_config->nmc_range_tree_lock);
1523 nm_member_reclassify_nodemap(nodemap);
1524 up_read(&active_config->nmc_range_tree_lock);
1526 if (!list_empty(&nodemap->nm_member_list))
1527 CWARN("nodemap_del failed to reclassify all members\n");
1529 mutex_unlock(&active_config_lock);
1531 nodemap_putref(nodemap);
1536 EXPORT_SYMBOL(nodemap_del);
1539 * activate nodemap functions
1541 * \param value 1 for on, 0 for off
1543 void nodemap_activate(const bool value)
1545 mutex_lock(&active_config_lock);
1546 active_config->nmc_nodemap_is_active = value;
1548 /* copy active value to global to avoid locking in map functions */
1549 nodemap_active = value;
1550 nodemap_idx_nodemap_activate(value);
1551 mutex_unlock(&active_config_lock);
1552 nm_member_revoke_all();
1554 EXPORT_SYMBOL(nodemap_activate);
1557 * Helper iterator to convert nodemap hash to list.
1559 * \param hs hash structure
1560 * \param bd bucket descriptor
1561 * \param hnode hash node
1562 * \param nodemap_list_head list head for list of nodemaps in hash
1564 static int nodemap_cleanup_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1565 struct hlist_node *hnode,
1566 void *nodemap_list_head)
1568 struct lu_nodemap *nodemap;
1570 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
1571 list_add(&nodemap->nm_list, nodemap_list_head);
1573 cfs_hash_bd_del_locked(hs, bd, hnode);
1578 struct nodemap_config *nodemap_config_alloc(void)
1580 struct nodemap_config *config;
1583 OBD_ALLOC_PTR(config);
1585 return ERR_PTR(-ENOMEM);
1587 rc = nodemap_init_hash(config);
1589 OBD_FREE_PTR(config);
1593 init_rwsem(&config->nmc_range_tree_lock);
1597 EXPORT_SYMBOL(nodemap_config_alloc);
1600 * Walk the nodemap_hash and remove all nodemaps.
1602 void nodemap_config_dealloc(struct nodemap_config *config)
1604 struct lu_nodemap *nodemap = NULL;
1605 struct lu_nodemap *nodemap_temp;
1606 struct lu_nid_range *range;
1607 struct lu_nid_range *range_temp;
1608 LIST_HEAD(nodemap_list_head);
1610 cfs_hash_for_each_safe(config->nmc_nodemap_hash,
1611 nodemap_cleanup_iter_cb, &nodemap_list_head);
1612 cfs_hash_putref(config->nmc_nodemap_hash);
1614 /* Because nodemap_destroy might sleep, we can't destroy them
1615 * in cfs_hash_for_each, so we build a list there and destroy here
1617 list_for_each_entry_safe(nodemap, nodemap_temp, &nodemap_list_head,
1619 mutex_lock(&active_config_lock);
1620 down_write(&config->nmc_range_tree_lock);
1622 /* move members to new config, requires ac lock */
1623 nm_member_reclassify_nodemap(nodemap);
1624 list_for_each_entry_safe(range, range_temp, &nodemap->nm_ranges,
1626 range_delete(&config->nmc_range_tree, range);
1627 up_write(&config->nmc_range_tree_lock);
1628 mutex_unlock(&active_config_lock);
1630 /* putref must be outside of ac lock if nm could be destroyed */
1631 nodemap_putref(nodemap);
1633 OBD_FREE_PTR(config);
1635 EXPORT_SYMBOL(nodemap_config_dealloc);
1638 * callback for cfs_hash_for_each_safe used to convert a nodemap hash to a
1639 * nodemap list, generally for locking purposes as a hash cb can't sleep.
1641 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1642 struct hlist_node *hnode,
1643 void *nodemap_list_head)
1645 struct lu_nodemap *nodemap;
1647 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
1648 list_add(&nodemap->nm_list, nodemap_list_head);
1652 void nodemap_config_set_active(struct nodemap_config *config)
1654 struct nodemap_config *old_config = active_config;
1655 struct lu_nodemap *nodemap;
1656 struct lu_nodemap *tmp;
1658 LIST_HEAD(nodemap_list_head);
1662 LASSERT(active_config != config);
1663 LASSERT(config->nmc_default_nodemap);
1665 mutex_lock(&active_config_lock);
1667 /* move proc entries from already existing nms, create for new nms */
1668 cfs_hash_for_each_safe(config->nmc_nodemap_hash,
1669 nm_hash_list_cb, &nodemap_list_head);
1670 list_for_each_entry_safe(nodemap, tmp, &nodemap_list_head, nm_list) {
1671 struct lu_nodemap *old_nm = NULL;
1673 if (active_config != NULL)
1674 old_nm = cfs_hash_lookup(
1675 active_config->nmc_nodemap_hash,
1677 if (old_nm != NULL) {
1678 nodemap->nm_pde_data = old_nm->nm_pde_data;
1679 old_nm->nm_pde_data = NULL;
1680 nodemap_putref(old_nm);
1682 bool is_def = (nodemap == config->nmc_default_nodemap);
1684 lprocfs_nodemap_register(nodemap, is_def);
1689 * We only need to revoke locks if old nodemap was active, and new
1690 * config is now nodemap inactive. nodemap_config_dealloc will
1691 * reclassify exports, triggering a lock revoke if and only if new
1692 * nodemap is active.
1694 revoke_locks = !config->nmc_nodemap_is_active && nodemap_active;
1696 /* if new config is inactive, deactivate live config before switching */
1697 if (!config->nmc_nodemap_is_active)
1698 nodemap_active = false;
1699 active_config = config;
1700 if (config->nmc_nodemap_is_active)
1701 nodemap_active = true;
1703 mutex_unlock(&active_config_lock);
1705 if (old_config != NULL)
1706 nodemap_config_dealloc(old_config);
1709 nm_member_revoke_all();
1715 * Cleanup nodemap module on exit
1717 void nodemap_mod_exit(void)
1719 nodemap_config_dealloc(active_config);
1720 nodemap_procfs_exit();
1724 * Initialize the nodemap module
1726 int nodemap_mod_init(void)
1728 struct nodemap_config *new_config;
1729 struct lu_nodemap *nodemap;
1732 rc = nodemap_procfs_init();
1736 new_config = nodemap_config_alloc();
1737 if (IS_ERR(new_config)) {
1738 nodemap_procfs_exit();
1739 GOTO(out, rc = PTR_ERR(new_config));
1742 nodemap = nodemap_create(DEFAULT_NODEMAP, new_config, 1);
1743 if (IS_ERR(nodemap)) {
1744 nodemap_config_dealloc(new_config);
1745 nodemap_procfs_exit();
1746 GOTO(out, rc = PTR_ERR(nodemap));
1749 nodemap_config_set_active(new_config);
1750 nodemap_putref(nodemap);
1757 * Revoke locks for all nodemaps.
1759 void nm_member_revoke_all(void)
1761 struct lu_nodemap *nodemap;
1762 struct lu_nodemap *tmp;
1763 LIST_HEAD(nodemap_list_head);
1765 mutex_lock(&active_config_lock);
1766 cfs_hash_for_each_safe(active_config->nmc_nodemap_hash,
1767 nm_hash_list_cb, &nodemap_list_head);
1769 /* revoke_locks sleeps, so can't call in cfs hash cb */
1770 list_for_each_entry_safe(nodemap, tmp, &nodemap_list_head, nm_list)
1771 nm_member_revoke_locks_always(nodemap);
1772 mutex_unlock(&active_config_lock);
1776 * Returns the nodemap classification for a given nid into an ioctl buffer.
1777 * Useful for testing the nodemap configuration to make sure it is working as
1780 * \param nid nid to classify
1781 * \param[out] name_buf buffer to write the nodemap name to
1782 * \param name_len length of buffer
1784 void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len)
1786 struct lu_nodemap *nodemap;
1788 mutex_lock(&active_config_lock);
1789 down_read(&active_config->nmc_range_tree_lock);
1790 nodemap = nodemap_classify_nid(nid);
1791 up_read(&active_config->nmc_range_tree_lock);
1792 mutex_unlock(&active_config_lock);
1794 if (IS_ERR(nodemap))
1797 strncpy(name_buf, nodemap->nm_name, name_len);
1799 name_buf[name_len - 1] = '\0';
1801 nodemap_putref(nodemap);
1803 EXPORT_SYMBOL(nodemap_test_nid);
1806 * Passes back the id mapping for a given nid/id pair. Useful for testing the
1807 * nodemap configuration to make sure it is working as expected.
1809 * \param nid nid to classify
1810 * \param idtype uid or gid
1811 * \param client_id id to map to fs
1812 * \param fs_id_buf pointer to save mapped fs_id to
1815 * \retval -EINVAL invalid NID
1817 int nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
1818 __u32 client_id, __u32 *fs_id)
1820 struct lu_nodemap *nodemap;
1822 mutex_lock(&active_config_lock);
1823 down_read(&active_config->nmc_range_tree_lock);
1824 nodemap = nodemap_classify_nid(nid);
1825 up_read(&active_config->nmc_range_tree_lock);
1826 mutex_unlock(&active_config_lock);
1828 if (IS_ERR(nodemap))
1829 return PTR_ERR(nodemap);
1831 *fs_id = nodemap_map_id(nodemap, idtype, NODEMAP_CLIENT_TO_FS,
1833 nodemap_putref(nodemap);
1837 EXPORT_SYMBOL(nodemap_test_id);