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, 2017, Intel Corporation.
27 * Author: Joshua Walgenbach <jjw@iu.edu>
30 #define NODEMAP_LPROC_ID_LEN 16
31 #define NODEMAP_LPROC_FLAG_LEN 2
33 #include <lprocfs_status.h>
34 #include <lustre_net.h>
35 #include <lustre_export.h>
36 #include <obd_class.h>
37 #include <interval_tree.h>
38 #include "nodemap_internal.h"
40 static LIST_HEAD(nodemap_pde_list);
43 * Reads and prints the idmap for the given nodemap.
45 * \param m seq file in proc fs
49 static int nodemap_idmap_show(struct seq_file *m, void *data)
51 struct lu_nodemap *nodemap;
52 struct lu_idmap *idmap;
57 mutex_lock(&active_config_lock);
58 nodemap = nodemap_lookup(m->private);
59 mutex_unlock(&active_config_lock);
60 if (IS_ERR(nodemap)) {
61 rc = PTR_ERR(nodemap);
62 CERROR("cannot find nodemap '%s': rc = %d\n",
63 (char *)m->private, rc);
68 down_read(&nodemap->nm_idmap_lock);
69 for (node = rb_first(&nodemap->nm_client_to_fs_uidmap); node;
70 node = rb_next(node)) {
74 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
76 seq_printf(m, " { idtype: uid, client_id: %u, "
77 "fs_id: %u }", idmap->id_client,
80 for (node = rb_first(&nodemap->nm_client_to_fs_gidmap);
81 node; node = rb_next(node)) {
84 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
86 seq_printf(m, " { idtype: gid, client_id: %u, "
87 "fs_id: %u }", idmap->id_client,
90 for (node = rb_first(&nodemap->nm_client_to_fs_projidmap);
91 node; node = rb_next(node)) {
94 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
97 " { idtype: projid, client_id: %u, fs_id: %u }",
101 up_read(&nodemap->nm_idmap_lock);
103 seq_printf(m, "]\n");
105 nodemap_putref(nodemap);
110 * Attaches nodemap_idmap_show to proc file.
112 * \param inode inode of seq file in proc fs
113 * \param file seq file
116 static int nodemap_idmap_open(struct inode *inode, struct file *file)
118 return single_open(file, nodemap_idmap_show, pde_data(inode));
122 * Reads and prints the NID ranges for the given nodemap.
124 * \param m seq file in proc fs
128 static int nodemap_ranges_show(struct seq_file *m, void *data)
130 struct lu_nodemap *nodemap;
131 struct lu_nid_range *range;
132 char start_nidstr[LNET_NIDSTR_SIZE];
133 char end_nidstr[LNET_NIDSTR_SIZE];
137 mutex_lock(&active_config_lock);
138 nodemap = nodemap_lookup(m->private);
139 if (IS_ERR(nodemap)) {
140 mutex_unlock(&active_config_lock);
141 rc = PTR_ERR(nodemap);
142 CERROR("cannot find nodemap '%s': rc = %d\n",
143 (char *)m->private, rc);
147 seq_printf(m, "[\n");
148 down_read(&active_config->nmc_range_tree_lock);
149 list_for_each_entry(range, &nodemap->nm_ranges, rn_list) {
151 seq_printf(m, ",\n");
153 libcfs_nid2str_r(range->rn_start, start_nidstr, sizeof(start_nidstr));
154 libcfs_nid2str_r(range->rn_end, end_nidstr, sizeof(end_nidstr));
155 seq_printf(m, " { id: %u, start_nid: %s, end_nid: %s }",
156 range->rn_id, start_nidstr, end_nidstr);
158 up_read(&active_config->nmc_range_tree_lock);
159 mutex_unlock(&active_config_lock);
161 seq_printf(m, "]\n");
163 nodemap_putref(nodemap);
168 * Connects nodemap_idmap_show to proc file.
170 * \param inode inode of seq file in proc fs
171 * \param file seq file
174 static int nodemap_ranges_open(struct inode *inode, struct file *file)
176 return single_open(file, nodemap_ranges_show, pde_data(inode));
180 * Reads and prints the fileset for the given nodemap.
182 * \param m seq file in proc fs
186 static int nodemap_fileset_seq_show(struct seq_file *m, void *data)
188 struct lu_nodemap *nodemap;
191 mutex_lock(&active_config_lock);
192 nodemap = nodemap_lookup(m->private);
193 mutex_unlock(&active_config_lock);
194 if (IS_ERR(nodemap)) {
195 rc = PTR_ERR(nodemap);
196 CERROR("cannot find nodemap '%s': rc = %d\n",
197 (char *)m->private, rc);
201 seq_printf(m, "%s\n", nodemap->nm_fileset);
202 nodemap_putref(nodemap);
207 * Set a fileset on a nodemap.
209 * \param[in] file proc file
210 * \param[in] buffer string, "<fileset>"
211 * \param[in] count \a buffer length
212 * \param[in] off unused
213 * \retval \a count on success
214 * \retval negative number on error
217 nodemap_fileset_seq_write(struct file *file,
218 const char __user *buffer,
219 size_t count, loff_t *off)
221 struct seq_file *m = file->private_data;
229 if (count > PATH_MAX)
232 OBD_ALLOC(nm_fileset, count + 1);
233 /* OBD_ALLOC zero-fills the buffer */
234 if (nm_fileset == NULL)
237 if (copy_from_user(nm_fileset, buffer, count))
238 GOTO(out, rc = -EFAULT);
240 rc = nodemap_set_fileset(m->private, nm_fileset);
242 GOTO(out, rc = -EINVAL);
246 OBD_FREE(nm_fileset, count + 1);
250 LPROC_SEQ_FOPS(nodemap_fileset);
253 * Reads and prints the SELinux policy info for the given nodemap.
255 * \param m seq file in proc fs
259 static int nodemap_sepol_seq_show(struct seq_file *m, void *data)
261 struct lu_nodemap *nodemap;
264 mutex_lock(&active_config_lock);
265 nodemap = nodemap_lookup(m->private);
266 mutex_unlock(&active_config_lock);
267 if (IS_ERR(nodemap)) {
268 rc = PTR_ERR(nodemap);
269 CERROR("cannot find nodemap '%s': rc = %d\n",
270 (char *)m->private, rc);
274 seq_printf(m, "%s\n", nodemap_get_sepol(nodemap));
275 nodemap_putref(nodemap);
280 * Set SELinux policy info on a nodemap.
282 * \param[in] file proc file
283 * \param[in] buffer string, "<sepol>"
284 * \param[in] count \a buffer length
285 * \param[in] off unused
286 * \retval \a count on success
287 * \retval negative number on error
290 nodemap_sepol_seq_write(struct file *file,
291 const char __user *buffer,
292 size_t count, loff_t *off)
294 struct seq_file *m = file->private_data;
295 char sepol[LUSTRE_NODEMAP_SEPOL_LENGTH + 1];
298 BUILD_BUG_ON(sizeof(sepol) !=
299 sizeof(((struct lu_nodemap *)0)->nm_sepol));
302 if (count >= sizeof(sepol))
303 GOTO(out, rc = -ENAMETOOLONG);
305 if (copy_from_user(sepol, buffer, count))
306 GOTO(out, rc = -EFAULT);
310 rc = nodemap_set_sepol(m->private, sepol);
319 LPROC_SEQ_FOPS(nodemap_sepol);
322 * Reads and prints the exports attached to the given nodemap.
324 * \param m seq file in proc fs, stores nodemap
328 static int nodemap_exports_show(struct seq_file *m, void *data)
330 struct lu_nodemap *nodemap;
331 struct obd_export *exp;
332 char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
335 mutex_lock(&active_config_lock);
336 nodemap = nodemap_lookup(m->private);
337 mutex_unlock(&active_config_lock);
338 if (IS_ERR(nodemap)) {
339 rc = PTR_ERR(nodemap);
340 CERROR("cannot find nodemap '%s': rc = %d\n",
341 (char *)m->private, rc);
345 seq_printf(m, "[\n");
347 mutex_lock(&nodemap->nm_member_list_lock);
348 list_for_each_entry(exp, &nodemap->nm_member_list,
349 exp_target_data.ted_nodemap_member) {
350 if (exp->exp_connection != NULL)
351 libcfs_nidstr_r(&exp->exp_connection->c_peer.nid,
352 nidstr, sizeof(nidstr));
354 seq_printf(m, " { nid: %s, uuid: %s },",
355 nidstr, exp->exp_client_uuid.uuid);
357 mutex_unlock(&nodemap->nm_member_list_lock);
360 seq_printf(m, "]\n");
362 nodemap_putref(nodemap);
367 * Attaches nodemap_idmap_show to proc file.
369 * \param inode inode of seq file in proc fs
370 * \param file seq file
373 static int nodemap_exports_open(struct inode *inode, struct file *file)
375 return single_open(file, nodemap_exports_show, pde_data(inode));
379 * Reads and prints the active flag for the given nodemap.
381 * \param m seq file in proc fs
385 static int nodemap_active_seq_show(struct seq_file *m, void *data)
387 seq_printf(m, "%u\n", (unsigned int)nodemap_active);
392 * Activate/deactivate nodemap.
394 * \param[in] file proc file
395 * \param[in] buffer string, "1" or "0" to activate/deactivate nodemap
396 * \param[in] count \a buffer length
397 * \param[in] off unused
398 * \retval \a count on success
399 * \retval negative number on error
402 nodemap_active_seq_write(struct file *file, const char __user *buffer,
403 size_t count, loff_t *off)
405 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
406 long unsigned int active;
412 if (count >= sizeof(active_string))
415 if (copy_from_user(active_string, buffer, count))
418 active_string[count] = '\0';
419 rc = kstrtoul(active_string, 10, &active);
423 nodemap_activate(active);
427 LPROC_SEQ_FOPS(nodemap_active);
430 * Reads and prints the nodemap ID for the given nodemap.
432 * \param m seq file in proc fs
436 static int nodemap_id_seq_show(struct seq_file *m, void *data)
438 struct lu_nodemap *nodemap;
440 mutex_lock(&active_config_lock);
441 nodemap = nodemap_lookup(m->private);
442 mutex_unlock(&active_config_lock);
443 if (IS_ERR(nodemap)) {
444 int rc = PTR_ERR(nodemap);
445 CERROR("cannot find nodemap '%s': rc = %d\n",
446 (char *)m->private, rc);
450 seq_printf(m, "%u\n", nodemap->nm_id);
451 nodemap_putref(nodemap);
454 LPROC_SEQ_FOPS_RO(nodemap_id);
457 * Reads and prints the root squash UID for the given nodemap.
459 * \param m seq file in proc fs
463 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
465 struct lu_nodemap *nodemap;
467 mutex_lock(&active_config_lock);
468 nodemap = nodemap_lookup(m->private);
469 mutex_unlock(&active_config_lock);
470 if (IS_ERR(nodemap)) {
471 int rc = PTR_ERR(nodemap);
472 CERROR("cannot find nodemap '%s': rc = %d\n",
473 (char *)m->private, rc);
477 seq_printf(m, "%u\n", nodemap->nm_squash_uid);
478 nodemap_putref(nodemap);
483 * Reads and prints the root squash GID for the given nodemap.
485 * \param m seq file in proc fs
489 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
491 struct lu_nodemap *nodemap;
493 mutex_lock(&active_config_lock);
494 nodemap = nodemap_lookup(m->private);
495 mutex_unlock(&active_config_lock);
496 if (IS_ERR(nodemap)) {
497 int rc = PTR_ERR(nodemap);
498 CERROR("cannot find nodemap '%s': rc = %d\n",
499 (char *)m->private, rc);
503 seq_printf(m, "%u\n", nodemap->nm_squash_gid);
504 nodemap_putref(nodemap);
509 * Reads and prints the squash PROJID for the given nodemap.
511 * \param m seq file in proc fs
515 static int nodemap_squash_projid_seq_show(struct seq_file *m, void *data)
517 struct lu_nodemap *nodemap;
519 mutex_lock(&active_config_lock);
520 nodemap = nodemap_lookup(m->private);
521 mutex_unlock(&active_config_lock);
522 if (IS_ERR(nodemap)) {
523 int rc = PTR_ERR(nodemap);
525 CERROR("cannot find nodemap '%s': rc = %d\n",
526 (char *)m->private, rc);
530 seq_printf(m, "%u\n", nodemap->nm_squash_projid);
531 nodemap_putref(nodemap);
536 * Reads and prints the trusted flag for the given nodemap.
538 * \param m seq file in proc fs
542 static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
544 struct lu_nodemap *nodemap;
546 mutex_lock(&active_config_lock);
547 nodemap = nodemap_lookup(m->private);
548 mutex_unlock(&active_config_lock);
549 if (IS_ERR(nodemap)) {
550 int rc = PTR_ERR(nodemap);
552 CERROR("cannot find nodemap '%s': rc = %d\n",
553 (char *)m->private, rc);
557 seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
558 nodemap_putref(nodemap);
563 * Reads and prints the admin flag for the given nodemap.
565 * \param m seq file in proc fs
569 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
571 struct lu_nodemap *nodemap;
574 mutex_lock(&active_config_lock);
575 nodemap = nodemap_lookup(m->private);
576 mutex_unlock(&active_config_lock);
577 if (IS_ERR(nodemap)) {
578 rc = PTR_ERR(nodemap);
579 CERROR("cannot find nodemap '%s': rc = %d\n",
580 (char *)m->private, rc);
584 seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
585 nodemap_putref(nodemap);
590 * Reads and prints the mapping mode for the given nodemap.
592 * \param m seq file in proc fs
596 static int nodemap_map_mode_seq_show(struct seq_file *m, void *data)
598 struct lu_nodemap *nodemap;
599 bool need_sep = false;
602 mutex_lock(&active_config_lock);
603 nodemap = nodemap_lookup(m->private);
604 mutex_unlock(&active_config_lock);
605 if (IS_ERR(nodemap)) {
606 rc = PTR_ERR(nodemap);
607 CERROR("cannot find nodemap '%s': rc = %d\n",
608 (char *)m->private, rc);
612 if (nodemap->nmf_map_mode == NODEMAP_MAP_ALL) {
613 seq_puts(m, "all\n");
615 if (nodemap->nmf_map_mode & NODEMAP_MAP_UID) {
619 if (nodemap->nmf_map_mode & NODEMAP_MAP_GID) {
620 seq_puts(m, need_sep ? ",gid" : "gid");
623 if (nodemap->nmf_map_mode & NODEMAP_MAP_PROJID)
624 seq_puts(m, need_sep ? ",projid" : "projid");
628 nodemap_putref(nodemap);
633 * Reads and prints the rbac for the given nodemap.
635 * \param m seq file in proc fs
639 static int nodemap_rbac_seq_show(struct seq_file *m, void *data)
641 struct lu_nodemap *nodemap;
645 mutex_lock(&active_config_lock);
646 nodemap = nodemap_lookup(m->private);
647 mutex_unlock(&active_config_lock);
648 if (IS_ERR(nodemap)) {
649 rc = PTR_ERR(nodemap);
650 CERROR("cannot find nodemap '%s': rc = %d\n",
651 (char *)m->private, rc);
655 if (nodemap->nmf_rbac == NODEMAP_RBAC_ALL) {
656 for (i = 0; i < ARRAY_SIZE(nodemap_rbac_names); i++)
657 seq_printf(m, "%s%s", i == 0 ? "" : ",",
658 nodemap_rbac_names[i].nrn_name);
660 } else if (nodemap->nmf_rbac == NODEMAP_RBAC_NONE) {
661 seq_puts(m, "none\n");
663 for (i = 0; i < ARRAY_SIZE(nodemap_rbac_names); i++) {
664 if (nodemap->nmf_rbac &
665 nodemap_rbac_names[i].nrn_mode) {
666 seq_printf(m, "%s%s", sep,
667 nodemap_rbac_names[i].nrn_name);
674 nodemap_putref(nodemap);
679 * Reads and prints the deny_unknown flag for the given nodemap.
681 * \param m seq file in proc fs
685 static int nodemap_deny_unknown_seq_show(struct seq_file *m, void *data)
687 struct lu_nodemap *nodemap;
690 mutex_lock(&active_config_lock);
691 nodemap = nodemap_lookup(m->private);
692 mutex_unlock(&active_config_lock);
693 if (IS_ERR(nodemap)) {
694 rc = PTR_ERR(nodemap);
695 CERROR("cannot find nodemap '%s': rc = %d\n",
696 (char *)m->private, rc);
700 seq_printf(m, "%d\n", (int)nodemap->nmf_deny_unknown);
701 nodemap_putref(nodemap);
706 * Reads and prints the audit_mode flag for the given nodemap.
708 * \param m seq file in proc fs
712 static int nodemap_audit_mode_seq_show(struct seq_file *m, void *data)
714 struct lu_nodemap *nodemap;
717 mutex_lock(&active_config_lock);
718 nodemap = nodemap_lookup(m->private);
719 mutex_unlock(&active_config_lock);
720 if (IS_ERR(nodemap)) {
721 rc = PTR_ERR(nodemap);
722 CERROR("cannot find nodemap '%s': rc = %d\n",
723 (char *)m->private, rc);
727 seq_printf(m, "%d\n", (int)nodemap->nmf_enable_audit);
728 nodemap_putref(nodemap);
733 * Reads and prints the forbid_encryption flag for the given nodemap.
735 * \param m seq file in proc fs
739 static int nodemap_forbid_encryption_seq_show(struct seq_file *m, void *data)
741 struct lu_nodemap *nodemap;
744 mutex_lock(&active_config_lock);
745 nodemap = nodemap_lookup(m->private);
746 mutex_unlock(&active_config_lock);
747 if (IS_ERR(nodemap)) {
748 rc = PTR_ERR(nodemap);
749 CERROR("cannot find nodemap '%s': rc = %d\n",
750 (char *)m->private, rc);
754 seq_printf(m, "%d\n", (int)nodemap->nmf_forbid_encryption);
755 nodemap_putref(nodemap);
760 * Reads and prints the readonly_mount flag for the given nodemap.
762 * \param m seq file in proc fs
766 static int nodemap_readonly_mount_seq_show(struct seq_file *m, void *data)
768 struct lu_nodemap *nodemap;
771 mutex_lock(&active_config_lock);
772 nodemap = nodemap_lookup(m->private);
773 mutex_unlock(&active_config_lock);
774 if (IS_ERR(nodemap)) {
775 rc = PTR_ERR(nodemap);
776 CERROR("cannot find nodemap '%s': rc = %d\n",
777 (char *)m->private, rc);
781 seq_printf(m, "%d\n", (int)nodemap->nmf_readonly_mount);
782 nodemap_putref(nodemap);
786 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
789 .fops = &nodemap_active_fops,
796 LPROC_SEQ_FOPS_RO(nodemap_trusted);
797 LPROC_SEQ_FOPS_RO(nodemap_admin);
798 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
799 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
800 LPROC_SEQ_FOPS_RO(nodemap_squash_projid);
802 LPROC_SEQ_FOPS_RO(nodemap_deny_unknown);
803 LPROC_SEQ_FOPS_RO(nodemap_map_mode);
804 LPROC_SEQ_FOPS_RO(nodemap_rbac);
805 LPROC_SEQ_FOPS_RO(nodemap_audit_mode);
806 LPROC_SEQ_FOPS_RO(nodemap_forbid_encryption);
807 LPROC_SEQ_FOPS_RO(nodemap_readonly_mount);
809 static const struct proc_ops nodemap_ranges_fops = {
810 .proc_open = nodemap_ranges_open,
811 .proc_read = seq_read,
812 .proc_lseek = seq_lseek,
813 .proc_release = single_release
816 static const struct proc_ops nodemap_idmap_fops = {
817 .proc_open = nodemap_idmap_open,
818 .proc_read = seq_read,
819 .proc_lseek = seq_lseek,
820 .proc_release = single_release
823 static const struct proc_ops nodemap_exports_fops = {
824 .proc_open = nodemap_exports_open,
825 .proc_read = seq_read,
826 .proc_lseek = seq_lseek,
827 .proc_release = single_release
830 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
831 /* in alphabetical order */
833 .name = "admin_nodemap",
834 .fops = &nodemap_admin_fops,
837 .name = "audit_mode",
838 .fops = &nodemap_audit_mode_fops,
841 .name = "deny_unknown",
842 .fops = &nodemap_deny_unknown_fops,
846 .fops = &nodemap_exports_fops,
850 .fops = &nodemap_fileset_fops,
853 .name = "forbid_encryption",
854 .fops = &nodemap_forbid_encryption_fops,
858 .fops = &nodemap_id_fops,
862 .fops = &nodemap_idmap_fops,
866 .fops = &nodemap_map_mode_fops,
870 .fops = &nodemap_ranges_fops,
874 .fops = &nodemap_rbac_fops,
877 .name = "readonly_mount",
878 .fops = &nodemap_readonly_mount_fops,
882 .fops = &nodemap_sepol_fops,
885 .name = "squash_gid",
886 .fops = &nodemap_squash_gid_fops,
889 .name = "squash_projid",
890 .fops = &nodemap_squash_projid_fops,
893 .name = "squash_uid",
894 .fops = &nodemap_squash_uid_fops,
897 .name = "trusted_nodemap",
898 .fops = &nodemap_trusted_fops,
905 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
908 .fops = &nodemap_id_fops,
911 .name = "trusted_nodemap",
912 .fops = &nodemap_trusted_fops,
915 .name = "admin_nodemap",
916 .fops = &nodemap_admin_fops,
919 .name = "deny_unknown",
920 .fops = &nodemap_deny_unknown_fops,
923 .name = "squash_uid",
924 .fops = &nodemap_squash_uid_fops,
927 .name = "squash_gid",
928 .fops = &nodemap_squash_gid_fops,
931 .name = "squash_projid",
932 .fops = &nodemap_squash_projid_fops,
936 .fops = &nodemap_fileset_fops,
940 .fops = &nodemap_exports_fops,
943 .name = "audit_mode",
944 .fops = &nodemap_audit_mode_fops,
947 .name = "forbid_encryption",
948 .fops = &nodemap_forbid_encryption_fops,
951 .name = "readonly_mount",
952 .fops = &nodemap_readonly_mount_fops,
960 * Initialize the nodemap procfs directory.
964 int nodemap_procfs_init(void)
968 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
970 lprocfs_nm_module_vars,
972 if (IS_ERR(proc_lustre_nodemap_root)) {
973 rc = PTR_ERR(proc_lustre_nodemap_root);
974 CERROR("cannot create 'nodemap' directory: rc = %d\n",
976 proc_lustre_nodemap_root = NULL;
982 * Cleanup nodemap proc entry data structures.
984 void nodemap_procfs_exit(void)
986 struct nodemap_pde *nm_pde;
987 struct nodemap_pde *tmp;
989 lprocfs_remove(&proc_lustre_nodemap_root);
990 list_for_each_entry_safe(nm_pde, tmp, &nodemap_pde_list,
992 list_del(&nm_pde->npe_list_member);
993 OBD_FREE_PTR(nm_pde);
998 * Remove a nodemap's procfs entry and related data.
1000 void lprocfs_nodemap_remove(struct nodemap_pde *nm_pde)
1002 lprocfs_remove(&nm_pde->npe_proc_entry);
1003 list_del(&nm_pde->npe_list_member);
1004 OBD_FREE_PTR(nm_pde);
1008 * Register the proc directory for a nodemap
1010 * \param nodemap nodemap to make the proc dir for
1011 * \param is_default: 1 if default nodemap
1014 int lprocfs_nodemap_register(struct lu_nodemap *nodemap, bool is_default)
1016 struct nodemap_pde *nm_entry;
1019 OBD_ALLOC_PTR(nm_entry);
1020 if (nm_entry == NULL)
1021 GOTO(out, rc = -ENOMEM);
1023 nm_entry->npe_proc_entry = proc_mkdir(nodemap->nm_name,
1024 proc_lustre_nodemap_root);
1025 if (IS_ERR(nm_entry->npe_proc_entry))
1026 GOTO(out, rc = PTR_ERR(nm_entry->npe_proc_entry));
1028 snprintf(nm_entry->npe_name, sizeof(nm_entry->npe_name), "%s",
1031 /* Use the nodemap name as stored on the PDE as the private data. This
1032 * is so a nodemap struct can be replaced without updating the proc
1035 rc = lprocfs_add_vars(nm_entry->npe_proc_entry,
1036 (is_default ? lprocfs_default_nodemap_vars :
1037 lprocfs_nodemap_vars),
1038 nm_entry->npe_name);
1040 lprocfs_remove(&nm_entry->npe_proc_entry);
1042 list_add(&nm_entry->npe_list_member, &nodemap_pde_list);
1046 CERROR("cannot create 'nodemap/%s': rc = %d\n",
1047 nodemap->nm_name, rc);
1048 if (nm_entry != NULL) {
1049 OBD_FREE_PTR(nm_entry);
1054 nodemap->nm_pde_data = nm_entry;