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 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;
220 if (count > PATH_MAX)
223 OBD_ALLOC(nm_fileset, count);
224 if (nm_fileset == NULL)
227 if (copy_from_user(nm_fileset, buffer, count))
228 GOTO(out, rc = -EFAULT);
230 rc = nodemap_set_fileset(m->private, nm_fileset);
232 GOTO(out, rc = -EINVAL);
236 OBD_FREE(nm_fileset, count);
240 LPROC_SEQ_FOPS(nodemap_fileset);
243 * Reads and prints the exports attached to the given nodemap.
245 * \param m seq file in proc fs, stores nodemap
249 static int nodemap_exports_show(struct seq_file *m, void *data)
251 struct lu_nodemap *nodemap;
252 struct obd_export *exp;
253 char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
256 mutex_lock(&active_config_lock);
257 nodemap = nodemap_lookup(m->private);
258 mutex_unlock(&active_config_lock);
259 if (IS_ERR(nodemap)) {
260 rc = PTR_ERR(nodemap);
261 CERROR("cannot find nodemap '%s': rc = %d\n",
262 (char *)m->private, rc);
266 seq_printf(m, "[\n");
268 mutex_lock(&nodemap->nm_member_list_lock);
269 list_for_each_entry(exp, &nodemap->nm_member_list,
270 exp_target_data.ted_nodemap_member) {
271 if (exp->exp_connection != NULL)
272 libcfs_nid2str_r(exp->exp_connection->c_peer.nid,
273 nidstr, sizeof(nidstr));
275 seq_printf(m, " { nid: %s, uuid: %s },",
276 nidstr, exp->exp_client_uuid.uuid);
278 mutex_unlock(&nodemap->nm_member_list_lock);
281 seq_printf(m, "]\n");
283 nodemap_putref(nodemap);
288 * Attaches nodemap_idmap_show to proc file.
290 * \param inode inode of seq file in proc fs
291 * \param file seq file
294 static int nodemap_exports_open(struct inode *inode, struct file *file)
296 return single_open(file, nodemap_exports_show, PDE_DATA(inode));
300 * Reads and prints the active flag for the given nodemap.
302 * \param m seq file in proc fs
306 static int nodemap_active_seq_show(struct seq_file *m, void *data)
308 seq_printf(m, "%u\n", (unsigned int)nodemap_active);
313 * Activate/deactivate nodemap.
315 * \param[in] file proc file
316 * \param[in] buffer string, "1" or "0" to activate/deactivate nodemap
317 * \param[in] count \a buffer length
318 * \param[in] off unused
319 * \retval \a count on success
320 * \retval negative number on error
323 nodemap_active_seq_write(struct file *file, const char __user *buffer,
324 size_t count, loff_t *off)
326 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
327 long unsigned int active;
333 if (count >= sizeof(active_string))
336 if (copy_from_user(active_string, buffer, count))
339 active_string[count] = '\0';
340 rc = kstrtoul(active_string, 10, &active);
344 nodemap_activate(active);
348 LPROC_SEQ_FOPS(nodemap_active);
351 * Reads and prints the nodemap ID for the given nodemap.
353 * \param m seq file in proc fs
357 static int nodemap_id_seq_show(struct seq_file *m, void *data)
359 struct lu_nodemap *nodemap;
361 mutex_lock(&active_config_lock);
362 nodemap = nodemap_lookup(m->private);
363 mutex_unlock(&active_config_lock);
364 if (IS_ERR(nodemap)) {
365 int rc = PTR_ERR(nodemap);
366 CERROR("cannot find nodemap '%s': rc = %d\n",
367 (char *)m->private, rc);
371 seq_printf(m, "%u\n", nodemap->nm_id);
372 nodemap_putref(nodemap);
375 LPROC_SEQ_FOPS_RO(nodemap_id);
378 * Reads and prints the root squash UID for the given nodemap.
380 * \param m seq file in proc fs
384 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
386 struct lu_nodemap *nodemap;
388 mutex_lock(&active_config_lock);
389 nodemap = nodemap_lookup(m->private);
390 mutex_unlock(&active_config_lock);
391 if (IS_ERR(nodemap)) {
392 int rc = PTR_ERR(nodemap);
393 CERROR("cannot find nodemap '%s': rc = %d\n",
394 (char *)m->private, rc);
398 seq_printf(m, "%u\n", nodemap->nm_squash_uid);
399 nodemap_putref(nodemap);
404 * Reads and prints the root squash GID for the given nodemap.
406 * \param m seq file in proc fs
410 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
412 struct lu_nodemap *nodemap;
414 mutex_lock(&active_config_lock);
415 nodemap = nodemap_lookup(m->private);
416 mutex_unlock(&active_config_lock);
417 if (IS_ERR(nodemap)) {
418 int rc = PTR_ERR(nodemap);
419 CERROR("cannot find nodemap '%s': rc = %d\n",
420 (char *)m->private, rc);
424 seq_printf(m, "%u\n", nodemap->nm_squash_gid);
425 nodemap_putref(nodemap);
430 * Reads and prints the trusted flag for the given nodemap.
432 * \param m seq file in proc fs
436 static int nodemap_trusted_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);
446 CERROR("cannot find nodemap '%s': rc = %d\n",
447 (char *)m->private, rc);
451 seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
452 nodemap_putref(nodemap);
457 * Reads and prints the admin flag for the given nodemap.
459 * \param m seq file in proc fs
463 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
465 struct lu_nodemap *nodemap;
468 mutex_lock(&active_config_lock);
469 nodemap = nodemap_lookup(m->private);
470 mutex_unlock(&active_config_lock);
471 if (IS_ERR(nodemap)) {
472 rc = PTR_ERR(nodemap);
473 CERROR("cannot find nodemap '%s': rc = %d\n",
474 (char *)m->private, rc);
478 seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
479 nodemap_putref(nodemap);
484 * Reads and prints the deny_unknown flag for the given nodemap.
486 * \param m seq file in proc fs
490 static int nodemap_deny_unknown_seq_show(struct seq_file *m, void *data)
492 struct lu_nodemap *nodemap;
495 mutex_lock(&active_config_lock);
496 nodemap = nodemap_lookup(m->private);
497 mutex_unlock(&active_config_lock);
498 if (IS_ERR(nodemap)) {
499 rc = PTR_ERR(nodemap);
500 CERROR("cannot find nodemap '%s': rc = %d\n",
501 (char *)m->private, rc);
505 seq_printf(m, "%d\n", (int)nodemap->nmf_deny_unknown);
506 nodemap_putref(nodemap);
510 #ifdef NODEMAP_PROC_DEBUG
512 * Helper functions to set nodemap flags.
514 * \param[in] buffer string, which is "1" or "0" to set/unset flag
515 * \param[in] count \a buffer length
516 * \param[out] flag_p where to store flag value
517 * \retval \a count on success
518 * \retval negative number on error
520 static int nodemap_proc_read_flag(const char __user *buffer,
521 unsigned long count, unsigned int *flag_p)
523 char scratch[NODEMAP_LPROC_FLAG_LEN + 1];
524 long unsigned int flag_buf;
530 if (count >= sizeof(scratch))
533 if (copy_from_user(scratch, buffer, count))
536 scratch[count] = '\0';
537 rc = kstrtoul(scratch, 10, &flag_buf);
547 * Set the squash UID.
549 * \param[in] file proc file
550 * \param[in] buffer string representing squash UID to set
551 * \param[in] count \a buffer length
552 * \param[in] off unused
553 * \retval \a count on success
554 * \retval negative number on error
557 nodemap_squash_uid_seq_write(struct file *file, const char __user *buffer,
558 size_t count, loff_t *off)
560 char squash[NODEMAP_LPROC_ID_LEN + 1];
561 struct seq_file *m = file->private_data;
562 long unsigned int squash_uid;
568 if (count >= sizeof(squash))
571 if (copy_from_user(squash, buffer, count))
574 squash[count] = '\0';
575 rc = kstrtoul(squash, 10, &squash_uid);
579 rc = nodemap_set_squash_uid(m->private, squash_uid);
587 * Set the squash GID.
589 * \param[in] file proc file
590 * \param[in] buffer string representing squash GID to set
591 * \param[in] count \a buffer length
592 * \param[in] off unused
593 * \retval \a count on success
594 * \retval negative number on error
597 nodemap_squash_gid_seq_write(struct file *file, const char __user *buffer,
598 size_t count, loff_t *off)
600 char squash[NODEMAP_LPROC_ID_LEN + 1];
601 struct seq_file *m = file->private_data;
602 long unsigned int squash_gid;
608 if (count >= sizeof(squash))
611 if (copy_from_user(squash, buffer, count))
614 squash[count] = '\0';
615 rc = kstrtoul(squash, 10, &squash_gid);
619 rc = nodemap_set_squash_gid(m->private, squash_gid);
627 * Set/unset the trusted flag.
629 * \param[in] file proc file
630 * \param[in] buffer string, "1" or "0"
631 * \param[in] count \a buffer length
632 * \param[in] off unused
633 * \retval \a count on success
634 * \retval negative number on error
637 nodemap_trusted_seq_write(struct file *file, const char __user *buffer,
638 size_t count, loff_t *off)
640 struct seq_file *m = file->private_data;
644 rc = nodemap_proc_read_flag(buffer, count, &flags);
648 rc = nodemap_set_trust_client_ids(m->private, flags);
656 * Set/unset the admin flag.
658 * \param[in] file proc file
659 * \param[in] buffer string, "1" or "0"
660 * \param[in] count \a buffer length
661 * \param[in] off unused
662 * \retval \a count on success
663 * \retval negative number on error
666 nodemap_admin_seq_write(struct file *file, const char __user *buffer,
667 size_t count, loff_t *off)
669 struct seq_file *m = file->private_data;
673 rc = nodemap_proc_read_flag(buffer, count, &flags);
677 rc = nodemap_set_allow_root(m->private, flags);
687 * \param[in] file proc file
688 * \param[in] buffer string, name of the nodemap to add
689 * \param[in] count \a buffer length
690 * \param[in] off unused
691 * \retval \a count on success
692 * \retval negative number on error
695 lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
696 size_t count, loff_t *off)
698 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
706 if (count >= sizeof(nodemap_name))
709 if (copy_from_user(nodemap_name, buffer, count))
712 nodemap_name[count] = '\0';
714 cpybuf = nodemap_name;
715 pos = strsep(&cpybuf, " \n");
719 rc = nodemap_add(nodemap_name);
725 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
730 * \param[in] file proc file
731 * \param[in] buffer string, name of the nodemap to delete
732 * \param[in] count \a buffer length
733 * \param[in] off unused
734 * \retval \a count on success
735 * \retval negative number on error
738 lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
739 size_t count, loff_t *off)
741 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
749 if (count >= sizeof(nodemap_name))
752 if (copy_from_user(nodemap_name, buffer, count))
755 nodemap_name[count] = '\0';
757 cpybuf = nodemap_name;
758 pos = strsep(&cpybuf, " \n");
762 rc = nodemap_del(nodemap_name);
769 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
772 * Helper function to parse a NID string.
774 * \param[in] rangestr string representation of NIDs, see libcfs_str2nid()
775 * \param[out] nids array of two nids
776 * \retval 0 on success
777 * \retval negative number on error
779 static int parse_nids(char *rangestr, lnet_nid_t nids[2])
781 struct list_head nidlist;
782 char nidstr[2][LNET_NIDSTR_SIZE];
783 char nidrange_str[2 * LNET_NIDSTR_SIZE + 2];
786 INIT_LIST_HEAD(&nidlist);
788 if (cfs_parse_nidlist(rangestr, strlen(rangestr),
792 if (!cfs_nidrange_is_contiguous(&nidlist))
795 cfs_nidrange_find_min_max(&nidlist, nidstr[0], nidstr[1],
797 snprintf(nidrange_str, sizeof(nidrange_str), "%s:%s",
798 nidstr[0], nidstr[1]);
800 rc = nodemap_parse_range(nidrange_str, nids);
804 cfs_free_nidlist(&nidlist);
810 * Add a NID range to nodemap.
812 * \param[in] file proc file
813 * \param[in] buffer string, "<nodemap name> <nid range>"
814 * \param[in] count \a buffer length
815 * \param[in] off unused
816 * \retval \a count on success
817 * \retval negative number on error
820 lprocfs_add_nodemap_range_seq_write(struct file *file,
821 const char __user *buffer,
822 size_t count, loff_t *off)
824 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
825 LNET_NIDSTR_SIZE * 2 + 2];
828 char *rangestr = NULL;
835 if (count >= sizeof(name_range))
836 GOTO(out, rc = -EINVAL);
838 if (copy_from_user(name_range, buffer, count))
839 GOTO(out, rc = -EFAULT);
841 name_range[count] = '\0';
844 name = strsep(&cpybuf, " ");
846 GOTO(out, rc = -EINVAL);
848 rangestr = strsep(&cpybuf, " \n");
849 if (rangestr == NULL)
850 GOTO(out, rc = -EINVAL);
852 rc = parse_nids(rangestr, nids);
856 rc = nodemap_add_range(name, nids);
858 GOTO(out, rc = -EINVAL);
866 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range);
869 * Delete a NID range from nodemap.
871 * \param[in] file proc file
872 * \param[in] buffer string, "<nodemap name> <nid range>"
873 * \param[in] count \a buffer length
874 * \param[in] off unused
875 * \retval \a count on success
876 * \retval negative number on error
879 lprocfs_del_nodemap_range_seq_write(struct file *file,
880 const char __user *buffer,
881 size_t count, loff_t *off)
883 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
884 LNET_NIDSTR_SIZE * 2 + 2];
887 char *rangestr = NULL;
894 if (count >= sizeof(name_range))
895 GOTO(out, rc = -EINVAL);
897 if (copy_from_user(name_range, buffer, count))
898 GOTO(out, rc = -EFAULT);
900 name_range[count] = '\0';
903 name = strsep(&cpybuf, " ");
905 GOTO(out, rc = -EINVAL);
907 rangestr = strsep(&cpybuf, " \n");
908 if (rangestr == NULL)
909 GOTO(out, rc = -EINVAL);
911 rc = parse_nids(rangestr, nids);
915 rc = nodemap_del_range(name, nids);
917 GOTO(out, rc = -EINVAL);
925 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range);
928 * Add an idmap to nodemap.
930 * \param[in] file proc file
931 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
932 * \param[in] count \a buffer length
933 * \param[in] off unused
934 * \retval \a count on success
935 * \retval negative number on error
938 lprocfs_add_nodemap_idmap_seq_write(struct file *file,
939 const char __user *buffer,
940 size_t count, loff_t *off)
942 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
945 char *idtypestr = NULL;
946 char *idmapstr = NULL;
953 if (count >= sizeof(name_idmapstr))
954 GOTO(out, rc = -EINVAL);
956 if (copy_from_user(name_idmapstr, buffer, count))
957 GOTO(out, rc = -EFAULT);
959 name_idmapstr[count] = '\0';
961 cpybuf = name_idmapstr;
962 name = strsep(&cpybuf, " ");
964 GOTO(out, rc = -EINVAL);
966 idtypestr = strsep(&cpybuf, " ");
967 if (idtypestr == NULL)
968 GOTO(out, rc = -EINVAL);
970 idmapstr = strsep(&cpybuf, " \n");
971 if (idmapstr == NULL)
972 GOTO(out, rc = -EINVAL);
974 rc = nodemap_parse_idmap(idmapstr, idmap);
976 GOTO(out, rc = -EINVAL);
978 if (strcmp(idtypestr, "uid") == 0)
979 rc = nodemap_add_idmap(name, NODEMAP_UID, idmap);
980 else if (strcmp(idtypestr, "gid") == 0)
981 rc = nodemap_add_idmap(name, NODEMAP_GID, idmap);
983 GOTO(out, rc = -EINVAL);
986 GOTO(out, rc = -EINVAL);
994 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap);
997 * Delete an idmap from nodemap.
999 * \param[in] file proc file
1000 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
1001 * \param[in] count \a buffer length
1002 * \param[in] off unused
1003 * \retval \a count on success
1004 * \retval negative number on error
1007 lprocfs_del_nodemap_idmap_seq_write(struct file *file,
1008 const char __user *buffer,
1009 size_t count, loff_t *off)
1011 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
1012 char *cpybuf = NULL;
1014 char *idtypestr = NULL;
1015 char *idmapstr = NULL;
1022 if (count >= sizeof(name_idmapstr))
1023 GOTO(out, rc = -EINVAL);
1025 if (copy_from_user(name_idmapstr, buffer, count))
1026 GOTO(out, rc = -EFAULT);
1028 name_idmapstr[count] = '\0';
1030 cpybuf = name_idmapstr;
1031 name = strsep(&cpybuf, " ");
1033 GOTO(out, rc = -EINVAL);
1035 idtypestr = strsep(&cpybuf, " ");
1036 if (idtypestr == NULL)
1037 GOTO(out, rc = -EINVAL);
1039 idmapstr = strsep(&cpybuf, " \n");
1040 if (idmapstr == NULL)
1041 GOTO(out, rc = -EINVAL);
1043 rc = nodemap_parse_idmap(idmapstr, idmap);
1045 GOTO(out, rc = -EINVAL);
1047 if (strcmp(idtypestr, "uid") == 0)
1048 rc = nodemap_del_idmap(name, NODEMAP_UID, idmap);
1049 else if (strcmp(idtypestr, "gid") == 0)
1050 rc = nodemap_del_idmap(name, NODEMAP_GID, idmap);
1052 GOTO(out, rc = -EINVAL);
1055 GOTO(out, rc = -EINVAL);
1063 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap);
1064 #endif /* NODEMAP_PROC_DEBUG */
1066 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
1069 .fops = &nodemap_active_fops,
1071 #ifdef NODEMAP_PROC_DEBUG
1073 .name = "add_nodemap",
1074 .fops = &nodemap_add_nodemap_fops,
1077 .name = "remove_nodemap",
1078 .fops = &nodemap_del_nodemap_fops,
1081 .name = "add_nodemap_range",
1082 .fops = &nodemap_add_nodemap_range_fops,
1085 .name = "del_nodemap_range",
1086 .fops = &nodemap_del_nodemap_range_fops,
1089 .name = "add_nodemap_idmap",
1090 .fops = &nodemap_add_nodemap_idmap_fops,
1093 .name = "del_nodemap_idmap",
1094 .fops = &nodemap_del_nodemap_idmap_fops,
1096 #endif /* NODEMAP_PROC_DEBUG */
1102 #ifdef NODEMAP_PROC_DEBUG
1103 LPROC_SEQ_FOPS(nodemap_trusted);
1104 LPROC_SEQ_FOPS(nodemap_admin);
1105 LPROC_SEQ_FOPS(nodemap_squash_uid);
1106 LPROC_SEQ_FOPS(nodemap_squash_gid);
1108 LPROC_SEQ_FOPS_RO(nodemap_trusted);
1109 LPROC_SEQ_FOPS_RO(nodemap_admin);
1110 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
1111 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
1114 LPROC_SEQ_FOPS_RO(nodemap_deny_unknown);
1116 const struct file_operations nodemap_ranges_fops = {
1117 .open = nodemap_ranges_open,
1119 .llseek = seq_lseek,
1120 .release = single_release
1123 const struct file_operations nodemap_idmap_fops = {
1124 .open = nodemap_idmap_open,
1126 .llseek = seq_lseek,
1127 .release = single_release
1130 const struct file_operations nodemap_exports_fops = {
1131 .open = nodemap_exports_open,
1133 .llseek = seq_lseek,
1134 .release = single_release
1137 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
1140 .fops = &nodemap_id_fops,
1143 .name = "trusted_nodemap",
1144 .fops = &nodemap_trusted_fops,
1147 .name = "admin_nodemap",
1148 .fops = &nodemap_admin_fops,
1151 .name = "deny_unknown",
1152 .fops = &nodemap_deny_unknown_fops,
1155 .name = "squash_uid",
1156 .fops = &nodemap_squash_uid_fops,
1159 .name = "squash_gid",
1160 .fops = &nodemap_squash_gid_fops,
1164 .fops = &nodemap_ranges_fops,
1168 .fops = &nodemap_fileset_fops,
1172 .fops = &nodemap_exports_fops,
1176 .fops = &nodemap_idmap_fops,
1183 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
1186 .fops = &nodemap_id_fops,
1189 .name = "trusted_nodemap",
1190 .fops = &nodemap_trusted_fops,
1193 .name = "admin_nodemap",
1194 .fops = &nodemap_admin_fops,
1197 .name = "squash_uid",
1198 .fops = &nodemap_squash_uid_fops,
1201 .name = "squash_gid",
1202 .fops = &nodemap_squash_gid_fops,
1206 .fops = &nodemap_exports_fops,
1214 * Initialize the nodemap procfs directory.
1218 int nodemap_procfs_init(void)
1222 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
1224 lprocfs_nm_module_vars,
1226 if (IS_ERR(proc_lustre_nodemap_root)) {
1227 rc = PTR_ERR(proc_lustre_nodemap_root);
1228 CERROR("cannot create 'nodemap' directory: rc = %d\n",
1230 proc_lustre_nodemap_root = NULL;
1236 * Cleanup nodemap proc entry data structures.
1238 void nodemap_procfs_exit(void)
1240 struct nodemap_pde *nm_pde;
1241 struct nodemap_pde *tmp;
1243 lprocfs_remove(&proc_lustre_nodemap_root);
1244 list_for_each_entry_safe(nm_pde, tmp, &nodemap_pde_list,
1246 list_del(&nm_pde->npe_list_member);
1247 OBD_FREE_PTR(nm_pde);
1252 * Remove a nodemap's procfs entry and related data.
1254 void lprocfs_nodemap_remove(struct nodemap_pde *nm_pde)
1256 lprocfs_remove(&nm_pde->npe_proc_entry);
1257 list_del(&nm_pde->npe_list_member);
1258 OBD_FREE_PTR(nm_pde);
1262 * Register the proc directory for a nodemap
1264 * \param nodemap nodemap to make the proc dir for
1265 * \param is_default: 1 if default nodemap
1268 int lprocfs_nodemap_register(struct lu_nodemap *nodemap, bool is_default)
1270 struct nodemap_pde *nm_entry;
1273 OBD_ALLOC_PTR(nm_entry);
1274 if (nm_entry == NULL)
1275 GOTO(out, rc = -ENOMEM);
1277 nm_entry->npe_proc_entry = proc_mkdir(nodemap->nm_name,
1278 proc_lustre_nodemap_root);
1279 if (IS_ERR(nm_entry->npe_proc_entry))
1280 GOTO(out, rc = PTR_ERR(nm_entry->npe_proc_entry));
1282 snprintf(nm_entry->npe_name, sizeof(nm_entry->npe_name), "%s",
1285 /* Use the nodemap name as stored on the PDE as the private data. This
1286 * is so a nodemap struct can be replaced without updating the proc
1289 rc = lprocfs_add_vars(nm_entry->npe_proc_entry,
1290 (is_default ? lprocfs_default_nodemap_vars :
1291 lprocfs_nodemap_vars),
1292 nm_entry->npe_name);
1294 lprocfs_remove(&nm_entry->npe_proc_entry);
1296 list_add(&nm_entry->npe_list_member, &nodemap_pde_list);
1300 CERROR("cannot create 'nodemap/%s': rc = %d\n",
1301 nodemap->nm_name, rc);
1302 if (nm_entry != NULL) {
1303 OBD_FREE_PTR(nm_entry);
1308 nodemap->nm_pde_data = nm_entry;