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 "nodemap_internal.h"
39 static LIST_HEAD(nodemap_pde_list);
42 * Reads and prints the idmap for the given nodemap.
44 * \param m seq file in proc fs
48 static int nodemap_idmap_show(struct seq_file *m, void *data)
50 struct lu_nodemap *nodemap;
51 struct lu_idmap *idmap;
56 mutex_lock(&active_config_lock);
57 nodemap = nodemap_lookup(m->private);
58 mutex_unlock(&active_config_lock);
59 if (IS_ERR(nodemap)) {
60 rc = PTR_ERR(nodemap);
61 CERROR("cannot find nodemap '%s': rc = %d\n",
62 (char *)m->private, rc);
67 down_read(&nodemap->nm_idmap_lock);
68 for (node = rb_first(&nodemap->nm_client_to_fs_uidmap); node;
69 node = rb_next(node)) {
73 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
75 seq_printf(m, " { idtype: uid, client_id: %u, "
76 "fs_id: %u }", idmap->id_client,
79 for (node = rb_first(&nodemap->nm_client_to_fs_gidmap);
80 node; node = rb_next(node)) {
83 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
85 seq_printf(m, " { idtype: gid, client_id: %u, "
86 "fs_id: %u }", idmap->id_client,
89 for (node = rb_first(&nodemap->nm_client_to_fs_projidmap);
90 node; node = rb_next(node)) {
93 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
96 " { idtype: projid, client_id: %u, fs_id: %u }",
100 up_read(&nodemap->nm_idmap_lock);
102 seq_printf(m, "]\n");
104 nodemap_putref(nodemap);
109 * Attaches nodemap_idmap_show to proc file.
111 * \param inode inode of seq file in proc fs
112 * \param file seq file
115 static int nodemap_idmap_open(struct inode *inode, struct file *file)
117 return single_open(file, nodemap_idmap_show, pde_data(inode));
121 * Reads and prints the NID ranges for the given nodemap.
123 * \param m seq file in proc fs
127 static int nodemap_ranges_show(struct seq_file *m, void *data)
129 struct lu_nodemap *nodemap;
130 struct lu_nid_range *range;
131 char start_nidstr[LNET_NIDSTR_SIZE];
132 char end_nidstr[LNET_NIDSTR_SIZE];
136 mutex_lock(&active_config_lock);
137 nodemap = nodemap_lookup(m->private);
138 if (IS_ERR(nodemap)) {
139 mutex_unlock(&active_config_lock);
140 rc = PTR_ERR(nodemap);
141 CERROR("cannot find nodemap '%s': rc = %d\n",
142 (char *)m->private, rc);
146 seq_printf(m, "[\n");
147 down_read(&active_config->nmc_range_tree_lock);
148 list_for_each_entry(range, &nodemap->nm_ranges, rn_list) {
150 seq_printf(m, ",\n");
152 libcfs_nidstr_r(&range->rn_start, start_nidstr, sizeof(start_nidstr));
153 libcfs_nidstr_r(&range->rn_end, end_nidstr, sizeof(end_nidstr));
154 seq_printf(m, " { id: %u, start_nid: %s, end_nid: %s }",
155 range->rn_id, start_nidstr, end_nidstr);
157 up_read(&active_config->nmc_range_tree_lock);
158 mutex_unlock(&active_config_lock);
160 seq_printf(m, "]\n");
162 nodemap_putref(nodemap);
167 * Connects nodemap_idmap_show to proc file.
169 * \param inode inode of seq file in proc fs
170 * \param file seq file
173 static int nodemap_ranges_open(struct inode *inode, struct file *file)
175 return single_open(file, nodemap_ranges_show, pde_data(inode));
179 * Reads and prints the fileset for the given nodemap.
181 * \param m seq file in proc fs
185 static int nodemap_fileset_seq_show(struct seq_file *m, void *data)
187 struct lu_nodemap *nodemap;
190 mutex_lock(&active_config_lock);
191 nodemap = nodemap_lookup(m->private);
192 mutex_unlock(&active_config_lock);
193 if (IS_ERR(nodemap)) {
194 rc = PTR_ERR(nodemap);
195 CERROR("cannot find nodemap '%s': rc = %d\n",
196 (char *)m->private, rc);
200 seq_printf(m, "%s\n", nodemap->nm_fileset);
201 nodemap_putref(nodemap);
206 * Set a fileset on a nodemap.
208 * \param[in] file proc file
209 * \param[in] buffer string, "<fileset>"
210 * \param[in] count \a buffer length
211 * \param[in] off unused
212 * \retval \a count on success
213 * \retval negative number on error
216 nodemap_fileset_seq_write(struct file *file,
217 const char __user *buffer,
218 size_t count, loff_t *off)
220 struct seq_file *m = file->private_data;
228 if (count > PATH_MAX)
231 OBD_ALLOC(nm_fileset, count + 1);
232 /* OBD_ALLOC zero-fills the buffer */
233 if (nm_fileset == NULL)
236 if (copy_from_user(nm_fileset, buffer, count))
237 GOTO(out, rc = -EFAULT);
239 rc = nodemap_set_fileset(m->private, nm_fileset);
241 GOTO(out, rc = -EINVAL);
245 OBD_FREE(nm_fileset, count + 1);
249 LPROC_SEQ_FOPS(nodemap_fileset);
252 * Reads and prints the SELinux policy info for the given nodemap.
254 * \param m seq file in proc fs
258 static int nodemap_sepol_seq_show(struct seq_file *m, void *data)
260 struct lu_nodemap *nodemap;
263 mutex_lock(&active_config_lock);
264 nodemap = nodemap_lookup(m->private);
265 mutex_unlock(&active_config_lock);
266 if (IS_ERR(nodemap)) {
267 rc = PTR_ERR(nodemap);
268 CERROR("cannot find nodemap '%s': rc = %d\n",
269 (char *)m->private, rc);
273 seq_printf(m, "%s\n", nodemap_get_sepol(nodemap));
274 nodemap_putref(nodemap);
279 * Set SELinux policy info on a nodemap.
281 * \param[in] file proc file
282 * \param[in] buffer string, "<sepol>"
283 * \param[in] count \a buffer length
284 * \param[in] off unused
285 * \retval \a count on success
286 * \retval negative number on error
289 nodemap_sepol_seq_write(struct file *file,
290 const char __user *buffer,
291 size_t count, loff_t *off)
293 struct seq_file *m = file->private_data;
294 char sepol[LUSTRE_NODEMAP_SEPOL_LENGTH + 1];
297 BUILD_BUG_ON(sizeof(sepol) !=
298 sizeof(((struct lu_nodemap *)0)->nm_sepol));
301 if (count >= sizeof(sepol))
302 GOTO(out, rc = -ENAMETOOLONG);
304 if (copy_from_user(sepol, buffer, count))
305 GOTO(out, rc = -EFAULT);
309 rc = nodemap_set_sepol(m->private, sepol);
318 LPROC_SEQ_FOPS(nodemap_sepol);
321 * Reads and prints the exports attached to the given nodemap.
323 * \param m seq file in proc fs, stores nodemap
327 static int nodemap_exports_show(struct seq_file *m, void *data)
329 struct lu_nodemap *nodemap;
330 struct obd_export *exp;
331 char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
334 mutex_lock(&active_config_lock);
335 nodemap = nodemap_lookup(m->private);
336 mutex_unlock(&active_config_lock);
337 if (IS_ERR(nodemap)) {
338 rc = PTR_ERR(nodemap);
339 CERROR("cannot find nodemap '%s': rc = %d\n",
340 (char *)m->private, rc);
344 seq_printf(m, "[\n");
346 mutex_lock(&nodemap->nm_member_list_lock);
347 list_for_each_entry(exp, &nodemap->nm_member_list,
348 exp_target_data.ted_nodemap_member) {
349 if (exp->exp_connection != NULL)
350 libcfs_nidstr_r(&exp->exp_connection->c_peer.nid,
351 nidstr, sizeof(nidstr));
353 seq_printf(m, " { nid: %s, uuid: %s },",
354 nidstr, exp->exp_client_uuid.uuid);
356 mutex_unlock(&nodemap->nm_member_list_lock);
359 seq_printf(m, "]\n");
361 nodemap_putref(nodemap);
366 * Attaches nodemap_idmap_show to proc file.
368 * \param inode inode of seq file in proc fs
369 * \param file seq file
372 static int nodemap_exports_open(struct inode *inode, struct file *file)
374 return single_open(file, nodemap_exports_show, pde_data(inode));
378 * Reads and prints the active flag for the given nodemap.
380 * \param m seq file in proc fs
384 static int nodemap_active_seq_show(struct seq_file *m, void *data)
386 seq_printf(m, "%u\n", (unsigned int)nodemap_active);
391 * Activate/deactivate nodemap.
393 * \param[in] file proc file
394 * \param[in] buffer string, "1" or "0" to activate/deactivate nodemap
395 * \param[in] count \a buffer length
396 * \param[in] off unused
397 * \retval \a count on success
398 * \retval negative number on error
401 nodemap_active_seq_write(struct file *file, const char __user *buffer,
402 size_t count, loff_t *off)
404 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
405 long unsigned int active;
411 if (count >= sizeof(active_string))
414 if (copy_from_user(active_string, buffer, count))
417 active_string[count] = '\0';
418 rc = kstrtoul(active_string, 10, &active);
422 nodemap_activate(active);
426 LPROC_SEQ_FOPS(nodemap_active);
429 * Reads and prints the nodemap ID for the given nodemap.
431 * \param m seq file in proc fs
435 static int nodemap_id_seq_show(struct seq_file *m, void *data)
437 struct lu_nodemap *nodemap;
439 mutex_lock(&active_config_lock);
440 nodemap = nodemap_lookup(m->private);
441 mutex_unlock(&active_config_lock);
442 if (IS_ERR(nodemap)) {
443 int rc = PTR_ERR(nodemap);
444 CERROR("cannot find nodemap '%s': rc = %d\n",
445 (char *)m->private, rc);
449 seq_printf(m, "%u\n", nodemap->nm_id);
450 nodemap_putref(nodemap);
453 LPROC_SEQ_FOPS_RO(nodemap_id);
456 * Reads and prints the root squash UID for the given nodemap.
458 * \param m seq file in proc fs
462 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
464 struct lu_nodemap *nodemap;
466 mutex_lock(&active_config_lock);
467 nodemap = nodemap_lookup(m->private);
468 mutex_unlock(&active_config_lock);
469 if (IS_ERR(nodemap)) {
470 int rc = PTR_ERR(nodemap);
471 CERROR("cannot find nodemap '%s': rc = %d\n",
472 (char *)m->private, rc);
476 seq_printf(m, "%u\n", nodemap->nm_squash_uid);
477 nodemap_putref(nodemap);
482 * Reads and prints the root squash GID for the given nodemap.
484 * \param m seq file in proc fs
488 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
490 struct lu_nodemap *nodemap;
492 mutex_lock(&active_config_lock);
493 nodemap = nodemap_lookup(m->private);
494 mutex_unlock(&active_config_lock);
495 if (IS_ERR(nodemap)) {
496 int rc = PTR_ERR(nodemap);
497 CERROR("cannot find nodemap '%s': rc = %d\n",
498 (char *)m->private, rc);
502 seq_printf(m, "%u\n", nodemap->nm_squash_gid);
503 nodemap_putref(nodemap);
508 * Reads and prints the squash PROJID for the given nodemap.
510 * \param m seq file in proc fs
514 static int nodemap_squash_projid_seq_show(struct seq_file *m, void *data)
516 struct lu_nodemap *nodemap;
518 mutex_lock(&active_config_lock);
519 nodemap = nodemap_lookup(m->private);
520 mutex_unlock(&active_config_lock);
521 if (IS_ERR(nodemap)) {
522 int rc = PTR_ERR(nodemap);
524 CERROR("cannot find nodemap '%s': rc = %d\n",
525 (char *)m->private, rc);
529 seq_printf(m, "%u\n", nodemap->nm_squash_projid);
530 nodemap_putref(nodemap);
535 * Reads and prints the trusted flag for the given nodemap.
537 * \param m seq file in proc fs
541 static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
543 struct lu_nodemap *nodemap;
545 mutex_lock(&active_config_lock);
546 nodemap = nodemap_lookup(m->private);
547 mutex_unlock(&active_config_lock);
548 if (IS_ERR(nodemap)) {
549 int rc = PTR_ERR(nodemap);
551 CERROR("cannot find nodemap '%s': rc = %d\n",
552 (char *)m->private, rc);
556 seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
557 nodemap_putref(nodemap);
562 * Reads and prints the admin flag for the given nodemap.
564 * \param m seq file in proc fs
568 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
570 struct lu_nodemap *nodemap;
573 mutex_lock(&active_config_lock);
574 nodemap = nodemap_lookup(m->private);
575 mutex_unlock(&active_config_lock);
576 if (IS_ERR(nodemap)) {
577 rc = PTR_ERR(nodemap);
578 CERROR("cannot find nodemap '%s': rc = %d\n",
579 (char *)m->private, rc);
583 seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
584 nodemap_putref(nodemap);
589 * Reads and prints the mapping mode for the given nodemap.
591 * \param m seq file in proc fs
595 static int nodemap_map_mode_seq_show(struct seq_file *m, void *data)
597 struct lu_nodemap *nodemap;
598 bool need_sep = false;
601 mutex_lock(&active_config_lock);
602 nodemap = nodemap_lookup(m->private);
603 mutex_unlock(&active_config_lock);
604 if (IS_ERR(nodemap)) {
605 rc = PTR_ERR(nodemap);
606 CERROR("cannot find nodemap '%s': rc = %d\n",
607 (char *)m->private, rc);
611 if (nodemap->nmf_map_mode == NODEMAP_MAP_ALL) {
612 seq_puts(m, "all\n");
614 if (nodemap->nmf_map_mode & NODEMAP_MAP_UID) {
618 if (nodemap->nmf_map_mode & NODEMAP_MAP_GID) {
619 seq_puts(m, need_sep ? ",gid" : "gid");
622 if (nodemap->nmf_map_mode & NODEMAP_MAP_PROJID)
623 seq_puts(m, need_sep ? ",projid" : "projid");
627 nodemap_putref(nodemap);
632 * Reads and prints the rbac for the given nodemap.
634 * \param m seq file in proc fs
638 static int nodemap_rbac_seq_show(struct seq_file *m, void *data)
640 struct lu_nodemap *nodemap;
644 mutex_lock(&active_config_lock);
645 nodemap = nodemap_lookup(m->private);
646 mutex_unlock(&active_config_lock);
647 if (IS_ERR(nodemap)) {
648 rc = PTR_ERR(nodemap);
649 CERROR("cannot find nodemap '%s': rc = %d\n",
650 (char *)m->private, rc);
654 if (nodemap->nmf_rbac == NODEMAP_RBAC_ALL) {
655 for (i = 0; i < ARRAY_SIZE(nodemap_rbac_names); i++)
656 seq_printf(m, "%s%s", i == 0 ? "" : ",",
657 nodemap_rbac_names[i].nrn_name);
659 } else if (nodemap->nmf_rbac == NODEMAP_RBAC_NONE) {
660 seq_puts(m, "none\n");
662 for (i = 0; i < ARRAY_SIZE(nodemap_rbac_names); i++) {
663 if (nodemap->nmf_rbac &
664 nodemap_rbac_names[i].nrn_mode) {
665 seq_printf(m, "%s%s", sep,
666 nodemap_rbac_names[i].nrn_name);
673 nodemap_putref(nodemap);
678 * Reads and prints the deny_unknown flag for the given nodemap.
680 * \param m seq file in proc fs
684 static int nodemap_deny_unknown_seq_show(struct seq_file *m, void *data)
686 struct lu_nodemap *nodemap;
689 mutex_lock(&active_config_lock);
690 nodemap = nodemap_lookup(m->private);
691 mutex_unlock(&active_config_lock);
692 if (IS_ERR(nodemap)) {
693 rc = PTR_ERR(nodemap);
694 CERROR("cannot find nodemap '%s': rc = %d\n",
695 (char *)m->private, rc);
699 seq_printf(m, "%d\n", (int)nodemap->nmf_deny_unknown);
700 nodemap_putref(nodemap);
705 * Reads and prints the audit_mode flag for the given nodemap.
707 * \param m seq file in proc fs
711 static int nodemap_audit_mode_seq_show(struct seq_file *m, void *data)
713 struct lu_nodemap *nodemap;
716 mutex_lock(&active_config_lock);
717 nodemap = nodemap_lookup(m->private);
718 mutex_unlock(&active_config_lock);
719 if (IS_ERR(nodemap)) {
720 rc = PTR_ERR(nodemap);
721 CERROR("cannot find nodemap '%s': rc = %d\n",
722 (char *)m->private, rc);
726 seq_printf(m, "%d\n", (int)nodemap->nmf_enable_audit);
727 nodemap_putref(nodemap);
732 * Reads and prints the forbid_encryption flag for the given nodemap.
734 * \param m seq file in proc fs
738 static int nodemap_forbid_encryption_seq_show(struct seq_file *m, void *data)
740 struct lu_nodemap *nodemap;
743 mutex_lock(&active_config_lock);
744 nodemap = nodemap_lookup(m->private);
745 mutex_unlock(&active_config_lock);
746 if (IS_ERR(nodemap)) {
747 rc = PTR_ERR(nodemap);
748 CERROR("cannot find nodemap '%s': rc = %d\n",
749 (char *)m->private, rc);
753 seq_printf(m, "%d\n", (int)nodemap->nmf_forbid_encryption);
754 nodemap_putref(nodemap);
759 * Reads and prints the readonly_mount flag for the given nodemap.
761 * \param m seq file in proc fs
765 static int nodemap_readonly_mount_seq_show(struct seq_file *m, void *data)
767 struct lu_nodemap *nodemap;
770 mutex_lock(&active_config_lock);
771 nodemap = nodemap_lookup(m->private);
772 mutex_unlock(&active_config_lock);
773 if (IS_ERR(nodemap)) {
774 rc = PTR_ERR(nodemap);
775 CERROR("cannot find nodemap '%s': rc = %d\n",
776 (char *)m->private, rc);
780 seq_printf(m, "%d\n", (int)nodemap->nmf_readonly_mount);
781 nodemap_putref(nodemap);
785 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
788 .fops = &nodemap_active_fops,
795 LPROC_SEQ_FOPS_RO(nodemap_trusted);
796 LPROC_SEQ_FOPS_RO(nodemap_admin);
797 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
798 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
799 LPROC_SEQ_FOPS_RO(nodemap_squash_projid);
801 LPROC_SEQ_FOPS_RO(nodemap_deny_unknown);
802 LPROC_SEQ_FOPS_RO(nodemap_map_mode);
803 LPROC_SEQ_FOPS_RO(nodemap_rbac);
804 LPROC_SEQ_FOPS_RO(nodemap_audit_mode);
805 LPROC_SEQ_FOPS_RO(nodemap_forbid_encryption);
806 LPROC_SEQ_FOPS_RO(nodemap_readonly_mount);
808 static const struct proc_ops nodemap_ranges_fops = {
809 .proc_open = nodemap_ranges_open,
810 .proc_read = seq_read,
811 .proc_lseek = seq_lseek,
812 .proc_release = single_release
815 static const struct proc_ops nodemap_idmap_fops = {
816 .proc_open = nodemap_idmap_open,
817 .proc_read = seq_read,
818 .proc_lseek = seq_lseek,
819 .proc_release = single_release
822 static const struct proc_ops nodemap_exports_fops = {
823 .proc_open = nodemap_exports_open,
824 .proc_read = seq_read,
825 .proc_lseek = seq_lseek,
826 .proc_release = single_release
829 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
830 /* in alphabetical order */
832 .name = "admin_nodemap",
833 .fops = &nodemap_admin_fops,
836 .name = "audit_mode",
837 .fops = &nodemap_audit_mode_fops,
840 .name = "deny_unknown",
841 .fops = &nodemap_deny_unknown_fops,
845 .fops = &nodemap_exports_fops,
849 .fops = &nodemap_fileset_fops,
852 .name = "forbid_encryption",
853 .fops = &nodemap_forbid_encryption_fops,
857 .fops = &nodemap_id_fops,
861 .fops = &nodemap_idmap_fops,
865 .fops = &nodemap_map_mode_fops,
869 .fops = &nodemap_ranges_fops,
873 .fops = &nodemap_rbac_fops,
876 .name = "readonly_mount",
877 .fops = &nodemap_readonly_mount_fops,
881 .fops = &nodemap_sepol_fops,
884 .name = "squash_gid",
885 .fops = &nodemap_squash_gid_fops,
888 .name = "squash_projid",
889 .fops = &nodemap_squash_projid_fops,
892 .name = "squash_uid",
893 .fops = &nodemap_squash_uid_fops,
896 .name = "trusted_nodemap",
897 .fops = &nodemap_trusted_fops,
904 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
905 /* in alphabetical order */
907 .name = "admin_nodemap",
908 .fops = &nodemap_admin_fops,
911 .name = "audit_mode",
912 .fops = &nodemap_audit_mode_fops,
915 .name = "deny_unknown",
916 .fops = &nodemap_deny_unknown_fops,
920 .fops = &nodemap_exports_fops,
924 .fops = &nodemap_fileset_fops,
927 .name = "forbid_encryption",
928 .fops = &nodemap_forbid_encryption_fops,
932 .fops = &nodemap_id_fops,
936 .fops = &nodemap_map_mode_fops,
939 .name = "readonly_mount",
940 .fops = &nodemap_readonly_mount_fops,
943 .name = "squash_gid",
944 .fops = &nodemap_squash_gid_fops,
947 .name = "squash_projid",
948 .fops = &nodemap_squash_projid_fops,
951 .name = "squash_uid",
952 .fops = &nodemap_squash_uid_fops,
955 .name = "trusted_nodemap",
956 .fops = &nodemap_trusted_fops,
964 * Initialize the nodemap procfs directory.
968 int nodemap_procfs_init(void)
972 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
974 lprocfs_nm_module_vars,
976 if (IS_ERR(proc_lustre_nodemap_root)) {
977 rc = PTR_ERR(proc_lustre_nodemap_root);
978 CERROR("cannot create 'nodemap' directory: rc = %d\n",
980 proc_lustre_nodemap_root = NULL;
986 * Cleanup nodemap proc entry data structures.
988 void nodemap_procfs_exit(void)
990 struct nodemap_pde *nm_pde;
991 struct nodemap_pde *tmp;
993 lprocfs_remove(&proc_lustre_nodemap_root);
994 list_for_each_entry_safe(nm_pde, tmp, &nodemap_pde_list,
996 list_del(&nm_pde->npe_list_member);
997 OBD_FREE_PTR(nm_pde);
1002 * Remove a nodemap's procfs entry and related data.
1004 void lprocfs_nodemap_remove(struct nodemap_pde *nm_pde)
1006 lprocfs_remove(&nm_pde->npe_proc_entry);
1007 list_del(&nm_pde->npe_list_member);
1008 OBD_FREE_PTR(nm_pde);
1012 * Register the proc directory for a nodemap
1014 * \param nodemap nodemap to make the proc dir for
1015 * \param is_default: 1 if default nodemap
1018 int lprocfs_nodemap_register(struct lu_nodemap *nodemap, bool is_default)
1020 struct nodemap_pde *nm_entry;
1023 OBD_ALLOC_PTR(nm_entry);
1024 if (nm_entry == NULL)
1025 GOTO(out, rc = -ENOMEM);
1027 nm_entry->npe_proc_entry = proc_mkdir(nodemap->nm_name,
1028 proc_lustre_nodemap_root);
1029 if (IS_ERR(nm_entry->npe_proc_entry))
1030 GOTO(out, rc = PTR_ERR(nm_entry->npe_proc_entry));
1032 snprintf(nm_entry->npe_name, sizeof(nm_entry->npe_name), "%s",
1035 /* Use the nodemap name as stored on the PDE as the private data. This
1036 * is so a nodemap struct can be replaced without updating the proc
1039 rc = lprocfs_add_vars(nm_entry->npe_proc_entry,
1040 (is_default ? lprocfs_default_nodemap_vars :
1041 lprocfs_nodemap_vars),
1042 nm_entry->npe_name);
1044 lprocfs_remove(&nm_entry->npe_proc_entry);
1046 list_add(&nm_entry->npe_list_member, &nodemap_pde_list);
1050 CERROR("cannot create 'nodemap/%s': rc = %d\n",
1051 nodemap->nm_name, rc);
1052 if (nm_entry != NULL) {
1053 OBD_FREE_PTR(nm_entry);
1058 nodemap->nm_pde_data = nm_entry;