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, 2015, 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 read_lock(&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 read_unlock(&nodemap->nm_idmap_lock);
94 nodemap_putref(nodemap);
99 * Attaches nodemap_idmap_show to proc file.
101 * \param inode inode of seq file in proc fs
102 * \param file seq file
105 static int nodemap_idmap_open(struct inode *inode, struct file *file)
107 return single_open(file, nodemap_idmap_show, PDE_DATA(inode));
111 * Reads and prints the NID ranges for the given nodemap.
113 * \param m seq file in proc fs
117 static int nodemap_ranges_show(struct seq_file *m, void *data)
119 struct lu_nodemap *nodemap;
120 struct lu_nid_range *range;
121 struct interval_node_extent ext;
122 char start_nidstr[LNET_NIDSTR_SIZE];
123 char end_nidstr[LNET_NIDSTR_SIZE];
127 mutex_lock(&active_config_lock);
128 nodemap = nodemap_lookup(m->private);
129 if (IS_ERR(nodemap)) {
130 mutex_unlock(&active_config_lock);
131 rc = PTR_ERR(nodemap);
132 CERROR("cannot find nodemap '%s': rc = %d\n",
133 (char *)m->private, rc);
137 seq_printf(m, "[\n");
138 down_read(&active_config->nmc_range_tree_lock);
139 list_for_each_entry(range, &nodemap->nm_ranges, rn_list) {
141 seq_printf(m, ",\n");
143 ext = range->rn_node.in_extent;
144 libcfs_nid2str_r(ext.start, start_nidstr, sizeof(start_nidstr));
145 libcfs_nid2str_r(ext.end, end_nidstr, sizeof(end_nidstr));
146 seq_printf(m, " { id: %u, start_nid: %s, end_nid: %s }",
147 range->rn_id, start_nidstr, end_nidstr);
149 up_read(&active_config->nmc_range_tree_lock);
150 mutex_unlock(&active_config_lock);
152 seq_printf(m, "]\n");
154 nodemap_putref(nodemap);
159 * Connects nodemap_idmap_show to proc file.
161 * \param inode inode of seq file in proc fs
162 * \param file seq file
165 static int nodemap_ranges_open(struct inode *inode, struct file *file)
167 return single_open(file, nodemap_ranges_show, PDE_DATA(inode));
171 * Reads and prints the fileset for the given nodemap.
173 * \param m seq file in proc fs
177 static int nodemap_fileset_seq_show(struct seq_file *m, void *data)
179 struct lu_nodemap *nodemap;
182 mutex_lock(&active_config_lock);
183 nodemap = nodemap_lookup(m->private);
184 mutex_unlock(&active_config_lock);
185 if (IS_ERR(nodemap)) {
186 rc = PTR_ERR(nodemap);
187 CERROR("cannot find nodemap '%s': rc = %d\n",
188 (char *)m->private, rc);
192 rc = seq_printf(m, "%s\n", nodemap->nm_fileset);
193 nodemap_putref(nodemap);
198 * Set a fileset on a nodemap.
200 * \param[in] file proc file
201 * \param[in] buffer string, "<fileset>"
202 * \param[in] count \a buffer length
203 * \param[in] off unused
204 * \retval \a count on success
205 * \retval negative number on error
208 nodemap_fileset_seq_write(struct file *file,
209 const char __user *buffer,
210 size_t count, loff_t *off)
212 struct seq_file *m = file->private_data;
216 rc = nodemap_set_fileset(m->private, buffer);
223 LPROC_SEQ_FOPS(nodemap_fileset);
226 * Reads and prints the exports attached to the given nodemap.
228 * \param m seq file in proc fs, stores nodemap
232 static int nodemap_exports_show(struct seq_file *m, void *data)
234 struct lu_nodemap *nodemap;
235 struct obd_export *exp;
236 char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
239 mutex_lock(&active_config_lock);
240 nodemap = nodemap_lookup(m->private);
241 mutex_unlock(&active_config_lock);
242 if (IS_ERR(nodemap)) {
243 rc = PTR_ERR(nodemap);
244 CERROR("cannot find nodemap '%s': rc = %d\n",
245 (char *)m->private, rc);
249 seq_printf(m, "[\n");
251 mutex_lock(&nodemap->nm_member_list_lock);
252 list_for_each_entry(exp, &nodemap->nm_member_list,
253 exp_target_data.ted_nodemap_member) {
254 if (exp->exp_connection != NULL)
255 libcfs_nid2str_r(exp->exp_connection->c_peer.nid,
256 nidstr, sizeof(nidstr));
258 seq_printf(m, " { nid: %s, uuid: %s },",
259 nidstr, exp->exp_client_uuid.uuid);
261 mutex_unlock(&nodemap->nm_member_list_lock);
264 seq_printf(m, "]\n");
266 nodemap_putref(nodemap);
271 * Attaches nodemap_idmap_show to proc file.
273 * \param inode inode of seq file in proc fs
274 * \param file seq file
277 static int nodemap_exports_open(struct inode *inode, struct file *file)
279 return single_open(file, nodemap_exports_show, PDE_DATA(inode));
283 * Reads and prints the active flag for the given nodemap.
285 * \param m seq file in proc fs
289 static int nodemap_active_seq_show(struct seq_file *m, void *data)
291 seq_printf(m, "%u\n", (unsigned int)nodemap_active);
296 * Activate/deactivate nodemap.
298 * \param[in] file proc file
299 * \param[in] buffer string, "1" or "0" to activate/deactivate nodemap
300 * \param[in] count \a buffer length
301 * \param[in] off unused
302 * \retval \a count on success
303 * \retval negative number on error
306 nodemap_active_seq_write(struct file *file, const char __user *buffer,
307 size_t count, loff_t *off)
309 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
310 long unsigned int active;
316 if (count >= sizeof(active_string))
319 if (copy_from_user(active_string, buffer, count))
322 active_string[count] = '\0';
323 rc = kstrtoul(active_string, 10, &active);
327 nodemap_activate(active);
331 LPROC_SEQ_FOPS(nodemap_active);
334 * Reads and prints the nodemap ID for the given nodemap.
336 * \param m seq file in proc fs
340 static int nodemap_id_seq_show(struct seq_file *m, void *data)
342 struct lu_nodemap *nodemap;
344 mutex_lock(&active_config_lock);
345 nodemap = nodemap_lookup(m->private);
346 mutex_unlock(&active_config_lock);
347 if (IS_ERR(nodemap)) {
348 int rc = PTR_ERR(nodemap);
349 CERROR("cannot find nodemap '%s': rc = %d\n",
350 (char *)m->private, rc);
354 seq_printf(m, "%u\n", nodemap->nm_id);
355 nodemap_putref(nodemap);
358 LPROC_SEQ_FOPS_RO(nodemap_id);
361 * Reads and prints the root squash UID for the given nodemap.
363 * \param m seq file in proc fs
367 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
369 struct lu_nodemap *nodemap;
371 mutex_lock(&active_config_lock);
372 nodemap = nodemap_lookup(m->private);
373 mutex_unlock(&active_config_lock);
374 if (IS_ERR(nodemap)) {
375 int rc = PTR_ERR(nodemap);
376 CERROR("cannot find nodemap '%s': rc = %d\n",
377 (char *)m->private, rc);
381 seq_printf(m, "%u\n", nodemap->nm_squash_uid);
382 nodemap_putref(nodemap);
387 * Reads and prints the root squash GID for the given nodemap.
389 * \param m seq file in proc fs
393 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
395 struct lu_nodemap *nodemap;
397 mutex_lock(&active_config_lock);
398 nodemap = nodemap_lookup(m->private);
399 mutex_unlock(&active_config_lock);
400 if (IS_ERR(nodemap)) {
401 int rc = PTR_ERR(nodemap);
402 CERROR("cannot find nodemap '%s': rc = %d\n",
403 (char *)m->private, rc);
407 seq_printf(m, "%u\n", nodemap->nm_squash_gid);
408 nodemap_putref(nodemap);
413 * Reads and prints the trusted flag for the given nodemap.
415 * \param m seq file in proc fs
419 static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
421 struct lu_nodemap *nodemap;
423 mutex_lock(&active_config_lock);
424 nodemap = nodemap_lookup(m->private);
425 mutex_unlock(&active_config_lock);
426 if (IS_ERR(nodemap)) {
427 int rc = PTR_ERR(nodemap);
429 CERROR("cannot find nodemap '%s': rc = %d\n",
430 (char *)m->private, rc);
434 seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
435 nodemap_putref(nodemap);
440 * Reads and prints the admin flag for the given nodemap.
442 * \param m seq file in proc fs
446 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
448 struct lu_nodemap *nodemap;
451 mutex_lock(&active_config_lock);
452 nodemap = nodemap_lookup(m->private);
453 mutex_unlock(&active_config_lock);
454 if (IS_ERR(nodemap)) {
455 rc = PTR_ERR(nodemap);
456 CERROR("cannot find nodemap '%s': rc = %d\n",
457 (char *)m->private, rc);
461 seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
462 nodemap_putref(nodemap);
466 #ifdef NODEMAP_PROC_DEBUG
468 * Helper functions to set nodemap flags.
470 * \param[in] buffer string, which is "1" or "0" to set/unset flag
471 * \param[in] count \a buffer length
472 * \param[out] flag_p where to store flag value
473 * \retval \a count on success
474 * \retval negative number on error
476 static int nodemap_proc_read_flag(const char __user *buffer,
477 unsigned long count, unsigned int *flag_p)
479 char scratch[NODEMAP_LPROC_FLAG_LEN + 1];
480 long unsigned int flag_buf;
486 if (count >= sizeof(scratch))
489 if (copy_from_user(scratch, buffer, count))
492 scratch[count] = '\0';
493 rc = kstrtoul(scratch, 10, &flag_buf);
503 * Set the squash UID.
505 * \param[in] file proc file
506 * \param[in] buffer string representing squash UID to set
507 * \param[in] count \a buffer length
508 * \param[in] off unused
509 * \retval \a count on success
510 * \retval negative number on error
513 nodemap_squash_uid_seq_write(struct file *file, const char __user *buffer,
514 size_t count, loff_t *off)
516 char squash[NODEMAP_LPROC_ID_LEN + 1];
517 struct seq_file *m = file->private_data;
518 long unsigned int squash_uid;
524 if (count >= sizeof(squash))
527 if (copy_from_user(squash, buffer, count))
530 squash[count] = '\0';
531 rc = kstrtoul(squash, 10, &squash_uid);
535 rc = nodemap_set_squash_uid(m->private, squash_uid);
543 * Set the squash GID.
545 * \param[in] file proc file
546 * \param[in] buffer string representing squash GID to set
547 * \param[in] count \a buffer length
548 * \param[in] off unused
549 * \retval \a count on success
550 * \retval negative number on error
553 nodemap_squash_gid_seq_write(struct file *file, const char __user *buffer,
554 size_t count, loff_t *off)
556 char squash[NODEMAP_LPROC_ID_LEN + 1];
557 struct seq_file *m = file->private_data;
558 long unsigned int squash_gid;
564 if (count >= sizeof(squash))
567 if (copy_from_user(squash, buffer, count))
570 squash[count] = '\0';
571 rc = kstrtoul(squash, 10, &squash_gid);
575 rc = nodemap_set_squash_gid(m->private, squash_gid);
583 * Set/unset the trusted flag.
585 * \param[in] file proc file
586 * \param[in] buffer string, "1" or "0"
587 * \param[in] count \a buffer length
588 * \param[in] off unused
589 * \retval \a count on success
590 * \retval negative number on error
593 nodemap_trusted_seq_write(struct file *file, const char __user *buffer,
594 size_t count, loff_t *off)
596 struct seq_file *m = file->private_data;
600 rc = nodemap_proc_read_flag(buffer, count, &flags);
604 rc = nodemap_set_trust_client_ids(m->private, flags);
612 * Set/unset the admin flag.
614 * \param[in] file proc file
615 * \param[in] buffer string, "1" or "0"
616 * \param[in] count \a buffer length
617 * \param[in] off unused
618 * \retval \a count on success
619 * \retval negative number on error
622 nodemap_admin_seq_write(struct file *file, const char __user *buffer,
623 size_t count, loff_t *off)
625 struct seq_file *m = file->private_data;
629 rc = nodemap_proc_read_flag(buffer, count, &flags);
633 rc = nodemap_set_allow_root(m->private, flags);
643 * \param[in] file proc file
644 * \param[in] buffer string, name of the nodemap to add
645 * \param[in] count \a buffer length
646 * \param[in] off unused
647 * \retval \a count on success
648 * \retval negative number on error
651 lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
652 size_t count, loff_t *off)
654 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
662 if (count >= sizeof(nodemap_name))
665 if (copy_from_user(nodemap_name, buffer, count))
668 nodemap_name[count] = '\0';
670 cpybuf = nodemap_name;
671 pos = strsep(&cpybuf, " \n");
675 rc = nodemap_add(nodemap_name);
681 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
686 * \param[in] file proc file
687 * \param[in] buffer string, name of the nodemap to delete
688 * \param[in] count \a buffer length
689 * \param[in] off unused
690 * \retval \a count on success
691 * \retval negative number on error
694 lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
695 size_t count, loff_t *off)
697 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
705 if (count >= sizeof(nodemap_name))
708 if (copy_from_user(nodemap_name, buffer, count))
711 nodemap_name[count] = '\0';
713 cpybuf = nodemap_name;
714 pos = strsep(&cpybuf, " \n");
718 rc = nodemap_del(nodemap_name);
725 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
728 * Helper function to parse a NID string.
730 * \param[in] rangestr string representation of NIDs, see libcfs_str2nid()
731 * \param[out] nids array of two nids
732 * \retval 0 on success
733 * \retval negative number on error
735 static int parse_nids(char *rangestr, lnet_nid_t nids[2])
737 struct list_head nidlist;
738 char nidstr[2][LNET_NIDSTR_SIZE];
739 char nidrange_str[2 * LNET_NIDSTR_SIZE + 2];
742 INIT_LIST_HEAD(&nidlist);
744 if (cfs_parse_nidlist(rangestr, strlen(rangestr),
748 if (!cfs_nidrange_is_contiguous(&nidlist))
751 cfs_nidrange_find_min_max(&nidlist, nidstr[0], nidstr[1],
753 snprintf(nidrange_str, sizeof(nidrange_str), "%s:%s",
754 nidstr[0], nidstr[1]);
756 rc = nodemap_parse_range(nidrange_str, nids);
760 cfs_free_nidlist(&nidlist);
766 * Add a NID range to nodemap.
768 * \param[in] file proc file
769 * \param[in] buffer string, "<nodemap name> <nid range>"
770 * \param[in] count \a buffer length
771 * \param[in] off unused
772 * \retval \a count on success
773 * \retval negative number on error
776 lprocfs_add_nodemap_range_seq_write(struct file *file,
777 const char __user *buffer,
778 size_t count, loff_t *off)
780 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
781 LNET_NIDSTR_SIZE * 2 + 2];
784 char *rangestr = NULL;
791 if (count >= sizeof(name_range))
792 GOTO(out, rc = -EINVAL);
794 if (copy_from_user(name_range, buffer, count))
795 GOTO(out, rc = -EFAULT);
797 name_range[count] = '\0';
800 name = strsep(&cpybuf, " ");
802 GOTO(out, rc = -EINVAL);
804 rangestr = strsep(&cpybuf, " \n");
805 if (rangestr == NULL)
806 GOTO(out, rc = -EINVAL);
808 rc = parse_nids(rangestr, nids);
812 rc = nodemap_add_range(name, nids);
814 GOTO(out, rc = -EINVAL);
822 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range);
825 * Delete a NID range from nodemap.
827 * \param[in] file proc file
828 * \param[in] buffer string, "<nodemap name> <nid range>"
829 * \param[in] count \a buffer length
830 * \param[in] off unused
831 * \retval \a count on success
832 * \retval negative number on error
835 lprocfs_del_nodemap_range_seq_write(struct file *file,
836 const char __user *buffer,
837 size_t count, loff_t *off)
839 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
840 LNET_NIDSTR_SIZE * 2 + 2];
843 char *rangestr = NULL;
850 if (count >= sizeof(name_range))
851 GOTO(out, rc = -EINVAL);
853 if (copy_from_user(name_range, buffer, count))
854 GOTO(out, rc = -EFAULT);
856 name_range[count] = '\0';
859 name = strsep(&cpybuf, " ");
861 GOTO(out, rc = -EINVAL);
863 rangestr = strsep(&cpybuf, " \n");
864 if (rangestr == NULL)
865 GOTO(out, rc = -EINVAL);
867 rc = parse_nids(rangestr, nids);
871 rc = nodemap_del_range(name, nids);
873 GOTO(out, rc = -EINVAL);
881 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range);
884 * Add an idmap to nodemap.
886 * \param[in] file proc file
887 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
888 * \param[in] count \a buffer length
889 * \param[in] off unused
890 * \retval \a count on success
891 * \retval negative number on error
894 lprocfs_add_nodemap_idmap_seq_write(struct file *file,
895 const char __user *buffer,
896 size_t count, loff_t *off)
898 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
901 char *idtypestr = NULL;
902 char *idmapstr = NULL;
909 if (count >= sizeof(name_idmapstr))
910 GOTO(out, rc = -EINVAL);
912 if (copy_from_user(name_idmapstr, buffer, count))
913 GOTO(out, rc = -EFAULT);
915 name_idmapstr[count] = '\0';
917 cpybuf = name_idmapstr;
918 name = strsep(&cpybuf, " ");
920 GOTO(out, rc = -EINVAL);
922 idtypestr = strsep(&cpybuf, " ");
923 if (idtypestr == NULL)
924 GOTO(out, rc = -EINVAL);
926 idmapstr = strsep(&cpybuf, " \n");
927 if (idmapstr == NULL)
928 GOTO(out, rc = -EINVAL);
930 rc = nodemap_parse_idmap(idmapstr, idmap);
932 GOTO(out, rc = -EINVAL);
934 if (strcmp(idtypestr, "uid") == 0)
935 rc = nodemap_add_idmap(name, NODEMAP_UID, idmap);
936 else if (strcmp(idtypestr, "gid") == 0)
937 rc = nodemap_add_idmap(name, NODEMAP_GID, idmap);
939 GOTO(out, rc = -EINVAL);
942 GOTO(out, rc = -EINVAL);
950 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap);
953 * Delete an idmap from nodemap.
955 * \param[in] file proc file
956 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
957 * \param[in] count \a buffer length
958 * \param[in] off unused
959 * \retval \a count on success
960 * \retval negative number on error
963 lprocfs_del_nodemap_idmap_seq_write(struct file *file,
964 const char __user *buffer,
965 size_t count, loff_t *off)
967 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
970 char *idtypestr = NULL;
971 char *idmapstr = NULL;
978 if (count >= sizeof(name_idmapstr))
979 GOTO(out, rc = -EINVAL);
981 if (copy_from_user(name_idmapstr, buffer, count))
982 GOTO(out, rc = -EFAULT);
984 name_idmapstr[count] = '\0';
986 cpybuf = name_idmapstr;
987 name = strsep(&cpybuf, " ");
989 GOTO(out, rc = -EINVAL);
991 idtypestr = strsep(&cpybuf, " ");
992 if (idtypestr == NULL)
993 GOTO(out, rc = -EINVAL);
995 idmapstr = strsep(&cpybuf, " \n");
996 if (idmapstr == NULL)
997 GOTO(out, rc = -EINVAL);
999 rc = nodemap_parse_idmap(idmapstr, idmap);
1001 GOTO(out, rc = -EINVAL);
1003 if (strcmp(idtypestr, "uid") == 0)
1004 rc = nodemap_del_idmap(name, NODEMAP_UID, idmap);
1005 else if (strcmp(idtypestr, "gid") == 0)
1006 rc = nodemap_del_idmap(name, NODEMAP_GID, idmap);
1008 GOTO(out, rc = -EINVAL);
1011 GOTO(out, rc = -EINVAL);
1019 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap);
1020 #endif /* NODEMAP_PROC_DEBUG */
1022 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
1025 .fops = &nodemap_active_fops,
1027 #ifdef NODEMAP_PROC_DEBUG
1029 .name = "add_nodemap",
1030 .fops = &nodemap_add_nodemap_fops,
1033 .name = "remove_nodemap",
1034 .fops = &nodemap_del_nodemap_fops,
1037 .name = "add_nodemap_range",
1038 .fops = &nodemap_add_nodemap_range_fops,
1041 .name = "del_nodemap_range",
1042 .fops = &nodemap_del_nodemap_range_fops,
1045 .name = "add_nodemap_idmap",
1046 .fops = &nodemap_add_nodemap_idmap_fops,
1049 .name = "del_nodemap_idmap",
1050 .fops = &nodemap_del_nodemap_idmap_fops,
1052 #endif /* NODEMAP_PROC_DEBUG */
1058 #ifdef NODEMAP_PROC_DEBUG
1059 LPROC_SEQ_FOPS(nodemap_trusted);
1060 LPROC_SEQ_FOPS(nodemap_admin);
1061 LPROC_SEQ_FOPS(nodemap_squash_uid);
1062 LPROC_SEQ_FOPS(nodemap_squash_gid);
1064 LPROC_SEQ_FOPS_RO(nodemap_trusted);
1065 LPROC_SEQ_FOPS_RO(nodemap_admin);
1066 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
1067 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
1070 const struct file_operations nodemap_ranges_fops = {
1071 .open = nodemap_ranges_open,
1073 .llseek = seq_lseek,
1074 .release = single_release
1077 const struct file_operations nodemap_idmap_fops = {
1078 .open = nodemap_idmap_open,
1080 .llseek = seq_lseek,
1081 .release = single_release
1084 const struct file_operations nodemap_exports_fops = {
1085 .open = nodemap_exports_open,
1087 .llseek = seq_lseek,
1088 .release = single_release
1091 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
1094 .fops = &nodemap_id_fops,
1097 .name = "trusted_nodemap",
1098 .fops = &nodemap_trusted_fops,
1101 .name = "admin_nodemap",
1102 .fops = &nodemap_admin_fops,
1105 .name = "squash_uid",
1106 .fops = &nodemap_squash_uid_fops,
1109 .name = "squash_gid",
1110 .fops = &nodemap_squash_gid_fops,
1114 .fops = &nodemap_ranges_fops,
1118 .fops = &nodemap_fileset_fops,
1122 .fops = &nodemap_exports_fops,
1126 .fops = &nodemap_idmap_fops,
1133 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
1136 .fops = &nodemap_id_fops,
1139 .name = "trusted_nodemap",
1140 .fops = &nodemap_trusted_fops,
1143 .name = "admin_nodemap",
1144 .fops = &nodemap_admin_fops,
1147 .name = "squash_uid",
1148 .fops = &nodemap_squash_uid_fops,
1151 .name = "squash_gid",
1152 .fops = &nodemap_squash_gid_fops,
1156 .fops = &nodemap_exports_fops,
1164 * Initialize the nodemap procfs directory.
1168 int nodemap_procfs_init(void)
1172 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
1174 lprocfs_nm_module_vars,
1176 if (IS_ERR(proc_lustre_nodemap_root)) {
1177 rc = PTR_ERR(proc_lustre_nodemap_root);
1178 CERROR("cannot create 'nodemap' directory: rc = %d\n",
1180 proc_lustre_nodemap_root = NULL;
1186 * Cleanup nodemap proc entry data structures.
1188 void nodemap_procfs_exit(void)
1190 struct nodemap_pde *nm_pde;
1191 struct nodemap_pde *tmp;
1193 lprocfs_remove(&proc_lustre_nodemap_root);
1194 list_for_each_entry_safe(nm_pde, tmp, &nodemap_pde_list,
1196 list_del(&nm_pde->npe_list_member);
1197 OBD_FREE_PTR(nm_pde);
1202 * Remove a nodemap's procfs entry and related data.
1204 void lprocfs_nodemap_remove(struct nodemap_pde *nm_pde)
1206 lprocfs_remove(&nm_pde->npe_proc_entry);
1207 list_del(&nm_pde->npe_list_member);
1208 OBD_FREE_PTR(nm_pde);
1212 * Register the proc directory for a nodemap
1214 * \param nodemap nodemap to make the proc dir for
1215 * \param is_default: 1 if default nodemap
1218 int lprocfs_nodemap_register(struct lu_nodemap *nodemap, bool is_default)
1220 struct nodemap_pde *nm_entry;
1223 OBD_ALLOC_PTR(nm_entry);
1224 if (nm_entry == NULL)
1225 GOTO(out, rc = -ENOMEM);
1227 nm_entry->npe_proc_entry = proc_mkdir(nodemap->nm_name,
1228 proc_lustre_nodemap_root);
1229 if (IS_ERR(nm_entry->npe_proc_entry))
1230 GOTO(out, rc = PTR_ERR(nm_entry->npe_proc_entry));
1232 snprintf(nm_entry->npe_name, sizeof(nm_entry->npe_name), "%s",
1235 /* Use the nodemap name as stored on the PDE as the private data. This
1236 * is so a nodemap struct can be replaced without updating the proc
1239 rc = lprocfs_add_vars(nm_entry->npe_proc_entry,
1240 (is_default ? lprocfs_default_nodemap_vars :
1241 lprocfs_nodemap_vars),
1242 nm_entry->npe_name);
1244 lprocfs_remove(&nm_entry->npe_proc_entry);
1246 list_add(&nm_entry->npe_list_member, &nodemap_pde_list);
1250 CERROR("cannot create 'nodemap/%s': rc = %d\n",
1251 nodemap->nm_name, rc);
1252 if (nm_entry != NULL) {
1253 OBD_FREE_PTR(nm_entry);
1258 nodemap->nm_pde_data = nm_entry;