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) 2014, Intel Corporation.
27 * Author: Joshua Walgenbach <jjw@iu.edu>
29 #include <linux/module.h>
30 #include <linux/sort.h>
31 #include <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 /* Highest numerical lu_nodemap.nm_id defined */
48 static atomic_t nodemap_highest_id;
50 /* Simple flag to determine if nodemaps are active */
54 * pointer to default nodemap kept to keep from
55 * lookup it up in the hash since it is needed
58 static struct lu_nodemap *default_nodemap;
61 * Lock required to access the range tree.
63 rwlock_t nm_range_tree_lock;
66 * Hash keyed on nodemap name containing all
69 static struct cfs_hash *nodemap_hash;
74 * \param nodemap nodemap to destroy
76 static void nodemap_destroy(struct lu_nodemap *nodemap)
78 struct lu_nid_range *range;
79 struct lu_nid_range *range_temp;
81 write_lock(&nm_range_tree_lock);
82 list_for_each_entry_safe(range, range_temp, &nodemap->nm_ranges,
86 write_unlock(&nm_range_tree_lock);
88 write_lock(&nodemap->nm_idmap_lock);
89 idmap_delete_tree(nodemap);
90 write_unlock(&nodemap->nm_idmap_lock);
91 nm_member_reclassify_nodemap(nodemap);
92 if (!cfs_hash_is_empty(nodemap->nm_member_hash))
93 CWARN("nodemap_destroy failed to reclassify all members\n");
95 nm_member_delete_hash(nodemap);
97 OBD_FREE_PTR(nodemap);
101 * Functions used for the cfs_hash
103 static void nodemap_getref(struct lu_nodemap *nodemap)
105 atomic_inc(&nodemap->nm_refcount);
108 void nodemap_putref(struct lu_nodemap *nodemap)
110 LASSERT(nodemap != NULL);
111 LASSERT(atomic_read(&nodemap->nm_refcount) > 0);
113 if (atomic_dec_and_test(&nodemap->nm_refcount))
114 nodemap_destroy(nodemap);
117 static __u32 nodemap_hashfn(struct cfs_hash *hash_body,
118 const void *key, unsigned mask)
120 return cfs_hash_djb2_hash(key, strlen(key), mask);
123 static void *nodemap_hs_key(struct hlist_node *hnode)
125 struct lu_nodemap *nodemap;
127 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
129 return nodemap->nm_name;
132 static int nodemap_hs_keycmp(const void *key,
133 struct hlist_node *compared_hnode)
137 nodemap_name = nodemap_hs_key(compared_hnode);
139 return !strcmp(key, nodemap_name);
142 static void *nodemap_hs_hashobject(struct hlist_node *hnode)
144 return hlist_entry(hnode, struct lu_nodemap, nm_hash);
147 static void nodemap_hs_get(struct cfs_hash *hs, struct hlist_node *hnode)
149 struct lu_nodemap *nodemap;
151 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
152 nodemap_getref(nodemap);
155 static void nodemap_hs_put_locked(struct cfs_hash *hs,
156 struct hlist_node *hnode)
158 struct lu_nodemap *nodemap;
160 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
161 nodemap_putref(nodemap);
164 static struct cfs_hash_ops nodemap_hash_operations = {
165 .hs_hash = nodemap_hashfn,
166 .hs_key = nodemap_hs_key,
167 .hs_keycmp = nodemap_hs_keycmp,
168 .hs_object = nodemap_hs_hashobject,
169 .hs_get = nodemap_hs_get,
170 .hs_put_locked = nodemap_hs_put_locked,
173 /* end of cfs_hash functions */
176 * Helper iterator to clean up nodemap on module exit.
178 * \param hs hash structure
179 * \param bd bucket descriptor
180 * \param hnode hash node
181 * \param data not used here
183 static int nodemap_cleanup_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
184 struct hlist_node *hnode, void *data)
186 struct lu_nodemap *nodemap;
188 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
189 nodemap_putref(nodemap);
195 * Walk the nodemap_hash and remove all nodemaps.
197 void nodemap_cleanup_all(void)
199 cfs_hash_for_each_safe(nodemap_hash, nodemap_cleanup_iter_cb, NULL);
200 cfs_hash_putref(nodemap_hash);
204 * Initialize nodemap_hash
207 * \retval -ENOMEM cannot create hash
209 static int nodemap_init_hash(void)
211 nodemap_hash = cfs_hash_create("NODEMAP", HASH_NODEMAP_CUR_BITS,
212 HASH_NODEMAP_MAX_BITS,
213 HASH_NODEMAP_BKT_BITS, 0,
216 &nodemap_hash_operations,
219 if (nodemap_hash == NULL) {
220 CERROR("cannot create nodemap_hash table\n");
228 * Check for valid nodemap name
230 * \param name nodemap name
232 * \retval false invalid
234 static bool nodemap_name_is_valid(const char *name)
236 if (strlen(name) > LUSTRE_NODEMAP_NAME_LENGTH ||
240 for (; *name != '\0'; name++) {
241 if (!isalnum(*name) && *name != '_')
251 * Look nodemap up in the nodemap hash
253 * \param name name of nodemap
254 * \param nodemap found nodemap or NULL
255 * \retval lu_nodemap named nodemap
256 * \retval NULL nodemap doesn't exist
258 static int nodemap_lookup(const char *name, struct lu_nodemap **nodemap)
264 if (!nodemap_name_is_valid(name))
265 GOTO(out, rc = -EINVAL);
267 *nodemap = cfs_hash_lookup(nodemap_hash, name);
268 if (*nodemap == NULL)
276 * classify the nid into the proper nodemap
278 * \param nid nid to classify
279 * \retval nodemap nodemap containing the nid
280 * \retval default_nodemap default nodemap
282 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
284 struct lu_nid_range *range;
286 range = range_search(nid);
288 return range->rn_nodemap;
290 return default_nodemap;
292 EXPORT_SYMBOL(nodemap_classify_nid);
295 * simple check for default nodemap
297 static bool is_default_nodemap(const struct lu_nodemap *nodemap)
299 return nodemap->nm_id == 0;
303 * parse a nodemap range string into two nids
305 * \param range_str string to parse
306 * \param range[2] array of two nids
307 * \reyval 0 on success
309 int nodemap_parse_range(const char *range_str, lnet_nid_t range[2])
311 char buf[LNET_NIDSTR_SIZE * 2 + 2];
317 snprintf(buf, sizeof(buf), "%s", range_str);
319 start_nidstr = strsep(&ptr, ":");
320 end_nidstr = strsep(&ptr, ":");
322 if (start_nidstr == NULL || end_nidstr == NULL)
323 GOTO(out, rc = -EINVAL);
325 range[0] = libcfs_str2nid(start_nidstr);
326 range[1] = libcfs_str2nid(end_nidstr);
332 EXPORT_SYMBOL(nodemap_parse_range);
335 * parse a string containing an id map of form "client_id:filesystem_id"
336 * into an array of __u32 * for use in mapping functions
338 * \param idmap_str map string
339 * \param idmap array[2] of __u32
341 * \retval 0 on success
342 * \retval -EINVAL if idmap cannot be parsed
344 int nodemap_parse_idmap(char *idmap_str, __u32 idmap[2])
347 long unsigned int idmap_buf;
350 if (idmap_str == NULL)
353 sep = strchr(idmap_str, ':');
359 rc = kstrtoul(idmap_str, 10, &idmap_buf);
362 idmap[0] = idmap_buf;
364 rc = kstrtoul(sep, 10, &idmap_buf);
367 idmap[1] = idmap_buf;
371 EXPORT_SYMBOL(nodemap_parse_idmap);
374 * add a member to a nodemap
376 * \param nid nid to add to the members
377 * \param exp obd_export structure for the connection
378 * that is being added
379 * \retval -EINVAL export is NULL
380 * \retval -EEXIST export is already member of a nodemap
382 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp)
384 struct lu_nodemap *nodemap;
387 read_lock(&nm_range_tree_lock);
388 nodemap = nodemap_classify_nid(nid);
389 rc = nm_member_add(nodemap, exp);
390 read_unlock(&nm_range_tree_lock);
393 EXPORT_SYMBOL(nodemap_add_member);
396 * delete a member from a nodemap
398 * \param exp export to remove from a nodemap
400 void nodemap_del_member(struct obd_export *exp)
402 struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap;
405 nm_member_del(nodemap, exp);
407 EXPORT_SYMBOL(nodemap_del_member);
410 * add an idmap to the proper nodemap trees
412 * \param name name of nodemap
413 * \param id_type NODEMAP_UID or NODEMAP_GID
414 * \param map array[2] __u32 containing the map values
415 * map[0] is client id
416 * map[1] is the filesystem id
418 * \retval 0 on success
420 int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type,
423 struct lu_nodemap *nodemap = NULL;
424 struct lu_idmap *idmap;
427 rc = nodemap_lookup(name, &nodemap);
428 if (nodemap == NULL || is_default_nodemap(nodemap))
429 GOTO(out, rc = -EINVAL);
431 idmap = idmap_create(map[0], map[1]);
433 GOTO(out_putref, rc = -ENOMEM);
435 write_lock(&nodemap->nm_idmap_lock);
436 idmap_insert(id_type, idmap, nodemap);
437 write_unlock(&nodemap->nm_idmap_lock);
438 nm_member_revoke_locks(nodemap);
441 nodemap_putref(nodemap);
445 EXPORT_SYMBOL(nodemap_add_idmap);
448 * delete idmap from proper nodemap tree
450 * \param name name of nodemap
451 * \param id_type NODEMAP_UID or NODEMAP_GID
452 * \param map array[2] __u32 containing the mapA values
453 * map[0] is client id
454 * map[1] is the filesystem id
456 * \retval 0 on success
458 int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type,
461 struct lu_nodemap *nodemap = NULL;
462 struct lu_idmap *idmap = NULL;
465 rc = nodemap_lookup(name, &nodemap);
466 if (nodemap == NULL || is_default_nodemap(nodemap))
467 GOTO(out, rc = -EINVAL);
469 write_lock(&nodemap->nm_idmap_lock);
470 idmap = idmap_search(nodemap, NODEMAP_CLIENT_TO_FS, id_type,
473 write_unlock(&nodemap->nm_idmap_lock);
474 GOTO(out_putref, rc = -EINVAL);
477 idmap_delete(id_type, idmap, nodemap);
478 write_unlock(&nodemap->nm_idmap_lock);
479 nm_member_revoke_locks(nodemap);
482 nodemap_putref(nodemap);
486 EXPORT_SYMBOL(nodemap_del_idmap);
489 * mapping function for nodemap idmaps
491 * \param nodemap lu_nodemap structure defining nodemap
492 * \param node_type NODEMAP_UID or NODEMAP_GID
493 * \param tree_type NODEMAP_CLIENT_TO_FS or
494 * NODEMAP_FS_TO_CLIENT
495 * \param id id to map
497 * \retval mapped id according to the rules below.
499 * if the nodemap_active is false, just return the passed id without mapping
501 * if the id to be looked up is 0, check that root access is allowed and if it
502 * is, return 0. Otherwise, return the squash uid or gid.
504 * if the nodemap is configured to trusted the ids from the client system, just
505 * return the passwd id without mapping.
507 * if by this point, we haven't returned and the nodemap in question is the
508 * default nodemap, return the squash uid or gid.
510 * after these checks, search the proper tree for the mapping, and if found
511 * return the mapped value, otherwise return the squash uid or gid.
513 __u32 nodemap_map_id(struct lu_nodemap *nodemap,
514 enum nodemap_id_type id_type,
515 enum nodemap_tree_type tree_type, __u32 id)
517 struct lu_idmap *idmap = NULL;
523 if (unlikely(nodemap == NULL))
527 if (nodemap->nmf_allow_root_access)
533 if (nodemap->nmf_trust_client_ids)
536 if (is_default_nodemap(nodemap))
539 read_lock(&nodemap->nm_idmap_lock);
540 idmap = idmap_search(nodemap, tree_type, id_type, id);
542 read_unlock(&nodemap->nm_idmap_lock);
546 if (tree_type == NODEMAP_FS_TO_CLIENT)
547 found_id = idmap->id_client;
549 found_id = idmap->id_fs;
550 read_unlock(&nodemap->nm_idmap_lock);
554 if (id_type == NODEMAP_UID)
555 return nodemap->nm_squash_uid;
557 return nodemap->nm_squash_gid;
561 EXPORT_SYMBOL(nodemap_map_id);
564 * Map posix ACL entries according to the nodemap membership. Removes any
567 * \param lu_nodemap nodemap
568 * \param buf buffer containing xattr encoded ACLs
569 * \param size size of ACLs in bytes
570 * \param tree_type direction of mapping
571 * \retval size new size of ACLs in bytes
572 * \retval -EINVAL bad \a size param, see posix_acl_xattr_count()
574 ssize_t nodemap_map_acl(struct lu_nodemap *nodemap, void *buf, size_t size,
575 enum nodemap_tree_type tree_type)
577 posix_acl_xattr_header *header = buf;
578 posix_acl_xattr_entry *entry = &header->a_entries[0];
579 posix_acl_xattr_entry *new_entry = entry;
580 posix_acl_xattr_entry *end;
586 if (unlikely(nodemap == NULL))
589 count = posix_acl_xattr_count(size);
595 for (end = entry + count; entry != end; entry++) {
596 __u16 tag = le16_to_cpu(entry->e_tag);
597 __u32 id = le32_to_cpu(entry->e_id);
601 id = nodemap_map_id(nodemap, NODEMAP_UID,
603 if (id == nodemap->nm_squash_uid)
605 entry->e_id = cpu_to_le32(id);
608 id = nodemap_map_id(nodemap, NODEMAP_GID,
610 if (id == nodemap->nm_squash_gid)
612 entry->e_id = cpu_to_le32(id);
616 /* if we skip an ACL, copy the following ones over it */
617 if (new_entry != entry)
623 return (void *)new_entry - (void *)header;
625 EXPORT_SYMBOL(nodemap_map_acl);
628 * add nid range to nodemap
629 * \param name nodemap name
630 * \param range_st string containing nid range
631 * \retval 0 on success
633 * add an range to the global range tree and attached the
634 * range to the named nodemap.
636 int nodemap_add_range(const char *name, const lnet_nid_t nid[2])
638 struct lu_nodemap *nodemap = NULL;
639 struct lu_nid_range *range;
642 rc = nodemap_lookup(name, &nodemap);
643 if (nodemap == NULL || is_default_nodemap(nodemap))
644 GOTO(out, rc = -EINVAL);
646 range = range_create(nid[0], nid[1], nodemap);
648 GOTO(out_putref, rc = -ENOMEM);
650 write_lock(&nm_range_tree_lock);
651 rc = range_insert(range);
653 CERROR("cannot insert nodemap range into '%s': rc = %d\n",
654 nodemap->nm_name, rc);
655 write_unlock(&nm_range_tree_lock);
656 list_del(&range->rn_list);
657 range_destroy(range);
658 GOTO(out_putref, rc = -ENOMEM);
661 list_add(&range->rn_list, &nodemap->nm_ranges);
662 write_unlock(&nm_range_tree_lock);
664 nm_member_reclassify_nodemap(default_nodemap);
665 nm_member_revoke_locks(default_nodemap);
666 nm_member_revoke_locks(nodemap);
669 nodemap_putref(nodemap);
673 EXPORT_SYMBOL(nodemap_add_range);
677 * \param name nodemap name
678 * \param range_str string containing range
679 * \retval 0 on success
681 * Delete range from global range tree, and remove it
682 * from the list in the associated nodemap.
684 int nodemap_del_range(const char *name, const lnet_nid_t nid[2])
686 struct lu_nodemap *nodemap;
687 struct lu_nid_range *range;
690 rc = nodemap_lookup(name, &nodemap);
691 if (nodemap == NULL || is_default_nodemap(nodemap))
692 GOTO(out, rc = -EINVAL);
694 write_lock(&nm_range_tree_lock);
695 range = range_find(nid[0], nid[1]);
697 write_unlock(&nm_range_tree_lock);
698 GOTO(out_putref, rc = -EINVAL);
702 write_unlock(&nm_range_tree_lock);
703 nm_member_reclassify_nodemap(nodemap);
704 nm_member_revoke_locks(default_nodemap);
705 nm_member_revoke_locks(nodemap);
708 nodemap_putref(nodemap);
712 EXPORT_SYMBOL(nodemap_del_range);
715 * Nodemap constructor
717 * Creates an lu_nodemap structure and assigns sane default
718 * member values. If this is the default nodemap, the defaults
719 * are the most restictive in xterms of mapping behavior. Otherwise
720 * the default flags should be inherited from the default nodemap.
721 * The adds nodemap to nodemap_hash.
723 * \param name name of nodemap
724 * \param is_default true if default nodemap
726 * \retval -EINVAL invalid nodemap name
727 * \retval -EEXIST nodemap already exists
728 * \retval -ENOMEM cannot allocate memory for nodemap
730 static int nodemap_create(const char *name, bool is_default)
732 struct lu_nodemap *nodemap = NULL;
735 if (!nodemap_name_is_valid(name))
736 GOTO(out, rc = -EINVAL);
738 OBD_ALLOC_PTR(nodemap);
739 if (nodemap == NULL) {
740 CERROR("cannot allocate memory (%zu bytes)"
741 "for nodemap '%s'\n", sizeof(*nodemap),
743 GOTO(out, rc = -ENOMEM);
747 * take an extra reference to prevent nodemap from being destroyed
748 * while its being created.
750 atomic_set(&nodemap->nm_refcount, 2);
751 snprintf(nodemap->nm_name, sizeof(nodemap->nm_name), "%s", name);
752 rc = cfs_hash_add_unique(nodemap_hash, name, &nodemap->nm_hash);
754 OBD_FREE_PTR(nodemap);
755 GOTO(out, rc = -EEXIST);
759 rc = nm_member_init_hash(nodemap);
761 OBD_FREE_PTR(nodemap);
765 INIT_LIST_HEAD(&nodemap->nm_ranges);
767 rwlock_init(&nodemap->nm_idmap_lock);
768 nodemap->nm_fs_to_client_uidmap = RB_ROOT;
769 nodemap->nm_client_to_fs_uidmap = RB_ROOT;
770 nodemap->nm_fs_to_client_gidmap = RB_ROOT;
771 nodemap->nm_client_to_fs_gidmap = RB_ROOT;
774 nodemap->nm_id = LUSTRE_NODEMAP_DEFAULT_ID;
775 nodemap->nmf_trust_client_ids = 0;
776 nodemap->nmf_allow_root_access = 0;
777 nodemap->nmf_block_lookups = 0;
779 nodemap->nm_squash_uid = NODEMAP_NOBODY_UID;
780 nodemap->nm_squash_gid = NODEMAP_NOBODY_GID;
782 lprocfs_nodemap_register(name, is_default, nodemap);
784 default_nodemap = nodemap;
786 nodemap->nm_id = atomic_inc_return(&nodemap_highest_id);
787 nodemap->nmf_trust_client_ids =
788 default_nodemap->nmf_trust_client_ids;
789 nodemap->nmf_allow_root_access =
790 default_nodemap->nmf_allow_root_access;
791 nodemap->nmf_block_lookups =
792 default_nodemap->nmf_block_lookups;
794 nodemap->nm_squash_uid = default_nodemap->nm_squash_uid;
795 nodemap->nm_squash_gid = default_nodemap->nm_squash_gid;
797 lprocfs_nodemap_register(name, is_default, nodemap);
801 nodemap_putref(nodemap);
805 CERROR("cannot add nodemap: '%s': rc = %d\n", name, rc);
806 nodemap_destroy(nodemap);
813 * update flag to turn on or off nodemap functions
814 * \param name nodemap name
815 * \param admin_string string containing updated value
816 * \retval 0 on success
818 * Update admin flag to turn on or off nodemap functions.
820 int nodemap_set_allow_root(const char *name, bool allow_root)
822 struct lu_nodemap *nodemap = NULL;
825 rc = nodemap_lookup(name, &nodemap);
827 GOTO(out, rc = -ENOENT);
829 nodemap->nmf_allow_root_access = allow_root;
830 nm_member_revoke_locks(nodemap);
831 nodemap_putref(nodemap);
835 EXPORT_SYMBOL(nodemap_set_allow_root);
838 * updated trust_client_ids flag for nodemap
840 * \param name nodemap name
841 * \param trust_string new value for trust flag
842 * \retval 0 on success
844 * Update the trust_client_ids flag for a nodemap.
846 int nodemap_set_trust_client_ids(const char *name, bool trust_client_ids)
848 struct lu_nodemap *nodemap = NULL;
851 rc = nodemap_lookup(name, &nodemap);
853 GOTO(out, rc = -ENOENT);
855 nodemap->nmf_trust_client_ids = trust_client_ids;
856 nm_member_revoke_locks(nodemap);
857 nodemap_putref(nodemap);
861 EXPORT_SYMBOL(nodemap_set_trust_client_ids);
864 * update the squash_uid for a nodemap
866 * \param name nodemap name
867 * \param uid_string string containing new squash_uid value
868 * \retval 0 on success
870 * Update the squash_uid for a nodemap. The squash_uid is the uid
871 * that the all client uids are mapped to if nodemap is active,
872 * the trust_client_ids flag is not set, and the uid is not in
875 int nodemap_set_squash_uid(const char *name, uid_t uid)
877 struct lu_nodemap *nodemap = NULL;
880 rc = nodemap_lookup(name, &nodemap);
882 GOTO(out, rc = -ENOENT);
884 nodemap->nm_squash_uid = uid;
885 nm_member_revoke_locks(nodemap);
886 nodemap_putref(nodemap);
890 EXPORT_SYMBOL(nodemap_set_squash_uid);
893 * Update the squash_gid for a nodemap.
895 * \param name nodemap name
896 * \param gid_string string containing new squash_gid value
897 * \retval 0 on success
899 * Update the squash_gid for a nodemap. The squash_uid is the gid
900 * that the all client gids are mapped to if nodemap is active,
901 * the trust_client_ids flag is not set, and the gid is not in
904 int nodemap_set_squash_gid(const char *name, gid_t gid)
906 struct lu_nodemap *nodemap = NULL;
909 rc = nodemap_lookup(name, &nodemap);
911 GOTO(out, rc = -ENOENT);
913 nodemap->nm_squash_gid = gid;
914 nm_member_revoke_locks(nodemap);
915 nodemap_putref(nodemap);
919 EXPORT_SYMBOL(nodemap_set_squash_gid);
922 * Returns true if this nodemap has root user access. Always returns true if
923 * nodemaps are not active.
925 * \param nodemap nodemap to check access for
927 bool nodemap_can_setquota(const struct lu_nodemap *nodemap)
929 return !nodemap_active || nodemap->nmf_allow_root_access;
931 EXPORT_SYMBOL(nodemap_can_setquota);
936 * \param name name of nodemap
938 * \retval -EINVAL invalid nodemap name
939 * \retval -EEXIST nodemap already exists
940 * \retval -ENOMEM cannot allocate memory for nodemap
942 int nodemap_add(const char *nodemap_name)
944 return nodemap_create(nodemap_name, 0);
946 EXPORT_SYMBOL(nodemap_add);
951 * \param name name of nodemmap
953 * \retval -EINVAL invalid input
954 * \retval -ENOENT no existing nodemap
956 int nodemap_del(const char *nodemap_name)
958 struct lu_nodemap *nodemap;
961 if (strcmp(nodemap_name, DEFAULT_NODEMAP) == 0)
962 GOTO(out, rc = -EINVAL);
964 nodemap = cfs_hash_del_key(nodemap_hash, nodemap_name);
966 GOTO(out, rc = -ENOENT);
969 * remove procfs here in case nodemap_create called with same name
970 * before nodemap_destory is run.
972 lprocfs_remove(&nodemap->nm_proc_entry);
973 nodemap_putref(nodemap);
977 EXPORT_SYMBOL(nodemap_del);
980 * activate nodemap functions
982 * \param value 1 for on, 0 for off
984 void nodemap_activate(const bool value)
986 nodemap_active = value;
987 nm_member_revoke_all();
989 EXPORT_SYMBOL(nodemap_activate);
992 * Cleanup nodemap module on exit
994 void nodemap_mod_exit(void)
996 nodemap_cleanup_all();
997 lprocfs_remove(&proc_lustre_nodemap_root);
1001 * Initialize the nodemap module
1003 int nodemap_mod_init(void)
1007 rc = nodemap_init_hash();
1011 rwlock_init(&nm_range_tree_lock);
1012 nodemap_procfs_init();
1013 rc = nodemap_create(DEFAULT_NODEMAP, 1);
1022 static int nm_member_revoke_all_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1023 struct hlist_node *hnode, void *data)
1025 struct lu_nodemap *nodemap;
1027 nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
1028 nm_member_revoke_locks(nodemap);
1033 * Revoke locks for all nodemaps.
1035 void nm_member_revoke_all()
1037 cfs_hash_for_each_safe(nodemap_hash, nm_member_revoke_all_cb, NULL);