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 /* Turn on proc debug interface to allow OSS and
41 * MDS nodes to configure nodemap independently of
42 * MGS (since the nodemap distribution is not written
44 #define NODEMAP_PROC_DEBUG 1
46 static LIST_HEAD(nodemap_pde_list);
49 * Reads and prints the idmap for the given nodemap.
51 * \param m seq file in proc fs
55 static int nodemap_idmap_show(struct seq_file *m, void *data)
57 struct lu_nodemap *nodemap;
58 struct lu_idmap *idmap;
63 mutex_lock(&active_config_lock);
64 nodemap = nodemap_lookup(m->private);
65 mutex_unlock(&active_config_lock);
66 if (IS_ERR(nodemap)) {
67 rc = PTR_ERR(nodemap);
68 CERROR("cannot find nodemap '%s': rc = %d\n",
69 (char *)m->private, rc);
74 read_lock(&nodemap->nm_idmap_lock);
75 for (node = rb_first(&nodemap->nm_client_to_fs_uidmap); node;
76 node = rb_next(node)) {
80 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
82 seq_printf(m, " { idtype: uid, client_id: %u, "
83 "fs_id: %u }", idmap->id_client,
86 for (node = rb_first(&nodemap->nm_client_to_fs_gidmap);
87 node; node = rb_next(node)) {
90 idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
92 seq_printf(m, " { idtype: gid, client_id: %u, "
93 "fs_id: %u }", idmap->id_client,
96 read_unlock(&nodemap->nm_idmap_lock);
100 nodemap_putref(nodemap);
105 * Attaches nodemap_idmap_show to proc file.
107 * \param inode inode of seq file in proc fs
108 * \param file seq file
111 static int nodemap_idmap_open(struct inode *inode, struct file *file)
113 return single_open(file, nodemap_idmap_show, PDE_DATA(inode));
117 * Reads and prints the NID ranges for the given nodemap.
119 * \param m seq file in proc fs
123 static int nodemap_ranges_show(struct seq_file *m, void *data)
125 struct lu_nodemap *nodemap;
126 struct lu_nid_range *range;
127 struct interval_node_extent ext;
128 char start_nidstr[LNET_NIDSTR_SIZE];
129 char end_nidstr[LNET_NIDSTR_SIZE];
133 mutex_lock(&active_config_lock);
134 nodemap = nodemap_lookup(m->private);
135 if (IS_ERR(nodemap)) {
136 mutex_unlock(&active_config_lock);
137 rc = PTR_ERR(nodemap);
138 CERROR("cannot find nodemap '%s': rc = %d\n",
139 (char *)m->private, rc);
143 seq_printf(m, "[\n");
144 down_read(&active_config->nmc_range_tree_lock);
145 list_for_each_entry(range, &nodemap->nm_ranges, rn_list) {
147 seq_printf(m, ",\n");
149 ext = range->rn_node.in_extent;
150 libcfs_nid2str_r(ext.start, start_nidstr, sizeof(start_nidstr));
151 libcfs_nid2str_r(ext.end, end_nidstr, sizeof(end_nidstr));
152 seq_printf(m, " { id: %u, start_nid: %s, end_nid: %s }",
153 range->rn_id, start_nidstr, end_nidstr);
155 up_read(&active_config->nmc_range_tree_lock);
156 mutex_unlock(&active_config_lock);
158 seq_printf(m, "]\n");
160 nodemap_putref(nodemap);
165 * Connects nodemap_idmap_show to proc file.
167 * \param inode inode of seq file in proc fs
168 * \param file seq file
171 static int nodemap_ranges_open(struct inode *inode, struct file *file)
173 return single_open(file, nodemap_ranges_show, PDE_DATA(inode));
177 * Reads and prints the exports attached to the given nodemap.
179 * \param m seq file in proc fs, stores nodemap
183 static int nodemap_exports_show(struct seq_file *m, void *data)
185 struct lu_nodemap *nodemap;
186 struct obd_export *exp;
187 char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
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, "[\n");
202 mutex_lock(&nodemap->nm_member_list_lock);
203 list_for_each_entry(exp, &nodemap->nm_member_list,
204 exp_target_data.ted_nodemap_member) {
205 if (exp->exp_connection != NULL)
206 libcfs_nid2str_r(exp->exp_connection->c_peer.nid,
207 nidstr, sizeof(nidstr));
209 seq_printf(m, " { nid: %s, uuid: %s },",
210 nidstr, exp->exp_client_uuid.uuid);
212 mutex_unlock(&nodemap->nm_member_list_lock);
215 seq_printf(m, "]\n");
217 nodemap_putref(nodemap);
222 * Attaches nodemap_idmap_show to proc file.
224 * \param inode inode of seq file in proc fs
225 * \param file seq file
228 static int nodemap_exports_open(struct inode *inode, struct file *file)
230 return single_open(file, nodemap_exports_show, PDE_DATA(inode));
234 * Reads and prints the active flag for the given nodemap.
236 * \param m seq file in proc fs
240 static int nodemap_active_seq_show(struct seq_file *m, void *data)
242 seq_printf(m, "%u\n", (unsigned int)nodemap_active);
247 * Activate/deactivate nodemap.
249 * \param[in] file proc file
250 * \param[in] buffer string, "1" or "0" to activate/deactivate nodemap
251 * \param[in] count \a buffer length
252 * \param[in] off unused
253 * \retval \a count on success
254 * \retval negative number on error
257 nodemap_active_seq_write(struct file *file, const char __user *buffer,
258 size_t count, loff_t *off)
260 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
261 long unsigned int active;
267 if (count >= sizeof(active_string))
270 if (copy_from_user(active_string, buffer, count))
273 active_string[count] = '\0';
274 rc = kstrtoul(active_string, 10, &active);
278 nodemap_activate(active);
282 LPROC_SEQ_FOPS(nodemap_active);
285 * Reads and prints the nodemap ID for the given nodemap.
287 * \param m seq file in proc fs
291 static int nodemap_id_seq_show(struct seq_file *m, void *data)
293 struct lu_nodemap *nodemap;
295 mutex_lock(&active_config_lock);
296 nodemap = nodemap_lookup(m->private);
297 mutex_unlock(&active_config_lock);
298 if (IS_ERR(nodemap)) {
299 int rc = PTR_ERR(nodemap);
300 CERROR("cannot find nodemap '%s': rc = %d\n",
301 (char *)m->private, rc);
305 seq_printf(m, "%u\n", nodemap->nm_id);
306 nodemap_putref(nodemap);
309 LPROC_SEQ_FOPS_RO(nodemap_id);
312 * Reads and prints the root squash UID for the given nodemap.
314 * \param m seq file in proc fs
318 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
320 struct lu_nodemap *nodemap;
322 mutex_lock(&active_config_lock);
323 nodemap = nodemap_lookup(m->private);
324 mutex_unlock(&active_config_lock);
325 if (IS_ERR(nodemap)) {
326 int rc = PTR_ERR(nodemap);
327 CERROR("cannot find nodemap '%s': rc = %d\n",
328 (char *)m->private, rc);
332 seq_printf(m, "%u\n", nodemap->nm_squash_uid);
333 nodemap_putref(nodemap);
338 * Reads and prints the root squash GID for the given nodemap.
340 * \param m seq file in proc fs
344 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
346 struct lu_nodemap *nodemap;
348 mutex_lock(&active_config_lock);
349 nodemap = nodemap_lookup(m->private);
350 mutex_unlock(&active_config_lock);
351 if (IS_ERR(nodemap)) {
352 int rc = PTR_ERR(nodemap);
353 CERROR("cannot find nodemap '%s': rc = %d\n",
354 (char *)m->private, rc);
358 seq_printf(m, "%u\n", nodemap->nm_squash_gid);
359 nodemap_putref(nodemap);
364 * Reads and prints the trusted flag for the given nodemap.
366 * \param m seq file in proc fs
370 static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
372 struct lu_nodemap *nodemap;
374 mutex_lock(&active_config_lock);
375 nodemap = nodemap_lookup(m->private);
376 mutex_unlock(&active_config_lock);
377 if (IS_ERR(nodemap)) {
378 int rc = PTR_ERR(nodemap);
380 CERROR("cannot find nodemap '%s': rc = %d\n",
381 (char *)m->private, rc);
385 seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
386 nodemap_putref(nodemap);
391 * Reads and prints the admin flag for the given nodemap.
393 * \param m seq file in proc fs
397 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
399 struct lu_nodemap *nodemap;
402 mutex_lock(&active_config_lock);
403 nodemap = nodemap_lookup(m->private);
404 mutex_unlock(&active_config_lock);
405 if (IS_ERR(nodemap)) {
406 rc = PTR_ERR(nodemap);
407 CERROR("cannot find nodemap '%s': rc = %d\n",
408 (char *)m->private, rc);
412 seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
413 nodemap_putref(nodemap);
417 #ifdef NODEMAP_PROC_DEBUG
419 * Helper functions to set nodemap flags.
421 * \param[in] buffer string, which is "1" or "0" to set/unset flag
422 * \param[in] count \a buffer length
423 * \param[out] flag_p where to store flag value
424 * \retval \a count on success
425 * \retval negative number on error
427 static int nodemap_proc_read_flag(const char __user *buffer,
428 unsigned long count, unsigned int *flag_p)
430 char scratch[NODEMAP_LPROC_FLAG_LEN + 1];
431 long unsigned int flag_buf;
437 if (count >= sizeof(scratch))
440 if (copy_from_user(scratch, buffer, count))
443 scratch[count] = '\0';
444 rc = kstrtoul(scratch, 10, &flag_buf);
454 * Set the squash UID.
456 * \param[in] file proc file
457 * \param[in] buffer string representing squash UID to set
458 * \param[in] count \a buffer length
459 * \param[in] off unused
460 * \retval \a count on success
461 * \retval negative number on error
464 nodemap_squash_uid_seq_write(struct file *file, const char __user *buffer,
465 size_t count, loff_t *off)
467 char squash[NODEMAP_LPROC_ID_LEN + 1];
468 struct seq_file *m = file->private_data;
469 long unsigned int squash_uid;
475 if (count >= sizeof(squash))
478 if (copy_from_user(squash, buffer, count))
481 squash[count] = '\0';
482 rc = kstrtoul(squash, 10, &squash_uid);
486 rc = nodemap_set_squash_uid(m->private, squash_uid);
494 * Set the squash GID.
496 * \param[in] file proc file
497 * \param[in] buffer string representing squash GID to set
498 * \param[in] count \a buffer length
499 * \param[in] off unused
500 * \retval \a count on success
501 * \retval negative number on error
504 nodemap_squash_gid_seq_write(struct file *file, const char __user *buffer,
505 size_t count, loff_t *off)
507 char squash[NODEMAP_LPROC_ID_LEN + 1];
508 struct seq_file *m = file->private_data;
509 long unsigned int squash_gid;
515 if (count >= sizeof(squash))
518 if (copy_from_user(squash, buffer, count))
521 squash[count] = '\0';
522 rc = kstrtoul(squash, 10, &squash_gid);
526 rc = nodemap_set_squash_gid(m->private, squash_gid);
534 * Set/unset the trusted flag.
536 * \param[in] file proc file
537 * \param[in] buffer string, "1" or "0"
538 * \param[in] count \a buffer length
539 * \param[in] off unused
540 * \retval \a count on success
541 * \retval negative number on error
544 nodemap_trusted_seq_write(struct file *file, const char __user *buffer,
545 size_t count, loff_t *off)
547 struct seq_file *m = file->private_data;
551 rc = nodemap_proc_read_flag(buffer, count, &flags);
555 rc = nodemap_set_trust_client_ids(m->private, flags);
563 * Set/unset the admin flag.
565 * \param[in] file proc file
566 * \param[in] buffer string, "1" or "0"
567 * \param[in] count \a buffer length
568 * \param[in] off unused
569 * \retval \a count on success
570 * \retval negative number on error
573 nodemap_admin_seq_write(struct file *file, const char __user *buffer,
574 size_t count, loff_t *off)
576 struct seq_file *m = file->private_data;
580 rc = nodemap_proc_read_flag(buffer, count, &flags);
584 rc = nodemap_set_allow_root(m->private, flags);
594 * \param[in] file proc file
595 * \param[in] buffer string, name of the nodemap to add
596 * \param[in] count \a buffer length
597 * \param[in] off unused
598 * \retval \a count on success
599 * \retval negative number on error
602 lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
603 size_t count, loff_t *off)
605 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
613 if (count >= sizeof(nodemap_name))
616 if (copy_from_user(nodemap_name, buffer, count))
619 nodemap_name[count] = '\0';
621 cpybuf = nodemap_name;
622 pos = strsep(&cpybuf, " \n");
626 rc = nodemap_add(nodemap_name);
632 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
637 * \param[in] file proc file
638 * \param[in] buffer string, name of the nodemap to delete
639 * \param[in] count \a buffer length
640 * \param[in] off unused
641 * \retval \a count on success
642 * \retval negative number on error
645 lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
646 size_t count, loff_t *off)
648 char nodemap_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
656 if (count >= sizeof(nodemap_name))
659 if (copy_from_user(nodemap_name, buffer, count))
662 nodemap_name[count] = '\0';
664 cpybuf = nodemap_name;
665 pos = strsep(&cpybuf, " \n");
669 rc = nodemap_del(nodemap_name);
676 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
679 * Helper function to parse a NID string.
681 * \param[in] rangestr string representation of NIDs, see libcfs_str2nid()
682 * \param[out] nids array of two nids
683 * \retval 0 on success
684 * \retval negative number on error
686 static int parse_nids(char *rangestr, lnet_nid_t nids[2])
688 struct list_head nidlist;
689 char nidstr[2][LNET_NIDSTR_SIZE];
690 char nidrange_str[2 * LNET_NIDSTR_SIZE + 2];
693 INIT_LIST_HEAD(&nidlist);
695 if (cfs_parse_nidlist(rangestr, strlen(rangestr),
699 if (!cfs_nidrange_is_contiguous(&nidlist))
702 cfs_nidrange_find_min_max(&nidlist, nidstr[0], nidstr[1],
704 snprintf(nidrange_str, sizeof(nidrange_str), "%s:%s",
705 nidstr[0], nidstr[1]);
707 rc = nodemap_parse_range(nidrange_str, nids);
711 cfs_free_nidlist(&nidlist);
717 * Add a NID range to nodemap.
719 * \param[in] file proc file
720 * \param[in] buffer string, "<nodemap name> <nid range>"
721 * \param[in] count \a buffer length
722 * \param[in] off unused
723 * \retval \a count on success
724 * \retval negative number on error
727 lprocfs_add_nodemap_range_seq_write(struct file *file,
728 const char __user *buffer,
729 size_t count, loff_t *off)
731 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
732 LNET_NIDSTR_SIZE * 2 + 2];
735 char *rangestr = NULL;
742 if (count >= sizeof(name_range))
743 GOTO(out, rc = -EINVAL);
745 if (copy_from_user(name_range, buffer, count))
746 GOTO(out, rc = -EFAULT);
748 name_range[count] = '\0';
751 name = strsep(&cpybuf, " ");
753 GOTO(out, rc = -EINVAL);
755 rangestr = strsep(&cpybuf, " \n");
756 if (rangestr == NULL)
757 GOTO(out, rc = -EINVAL);
759 rc = parse_nids(rangestr, nids);
763 rc = nodemap_add_range(name, nids);
765 GOTO(out, rc = -EINVAL);
773 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range);
776 * Delete a NID range from nodemap.
778 * \param[in] file proc file
779 * \param[in] buffer string, "<nodemap name> <nid range>"
780 * \param[in] count \a buffer length
781 * \param[in] off unused
782 * \retval \a count on success
783 * \retval negative number on error
786 lprocfs_del_nodemap_range_seq_write(struct file *file,
787 const char __user *buffer,
788 size_t count, loff_t *off)
790 char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
791 LNET_NIDSTR_SIZE * 2 + 2];
794 char *rangestr = NULL;
801 if (count >= sizeof(name_range))
802 GOTO(out, rc = -EINVAL);
804 if (copy_from_user(name_range, buffer, count))
805 GOTO(out, rc = -EFAULT);
807 name_range[count] = '\0';
810 name = strsep(&cpybuf, " ");
812 GOTO(out, rc = -EINVAL);
814 rangestr = strsep(&cpybuf, " \n");
815 if (rangestr == NULL)
816 GOTO(out, rc = -EINVAL);
818 rc = parse_nids(rangestr, nids);
822 rc = nodemap_del_range(name, nids);
824 GOTO(out, rc = -EINVAL);
832 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range);
835 * Add an idmap to nodemap.
837 * \param[in] file proc file
838 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
839 * \param[in] count \a buffer length
840 * \param[in] off unused
841 * \retval \a count on success
842 * \retval negative number on error
845 lprocfs_add_nodemap_idmap_seq_write(struct file *file,
846 const char __user *buffer,
847 size_t count, loff_t *off)
849 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
852 char *idtypestr = NULL;
853 char *idmapstr = NULL;
860 if (count >= sizeof(name_idmapstr))
861 GOTO(out, rc = -EINVAL);
863 if (copy_from_user(name_idmapstr, buffer, count))
864 GOTO(out, rc = -EFAULT);
866 name_idmapstr[count] = '\0';
868 cpybuf = name_idmapstr;
869 name = strsep(&cpybuf, " ");
871 GOTO(out, rc = -EINVAL);
873 idtypestr = strsep(&cpybuf, " ");
874 if (idtypestr == NULL)
875 GOTO(out, rc = -EINVAL);
877 idmapstr = strsep(&cpybuf, " \n");
878 if (idmapstr == NULL)
879 GOTO(out, rc = -EINVAL);
881 rc = nodemap_parse_idmap(idmapstr, idmap);
883 GOTO(out, rc = -EINVAL);
885 if (strcmp(idtypestr, "uid") == 0)
886 rc = nodemap_add_idmap(name, NODEMAP_UID, idmap);
887 else if (strcmp(idtypestr, "gid") == 0)
888 rc = nodemap_add_idmap(name, NODEMAP_GID, idmap);
890 GOTO(out, rc = -EINVAL);
893 GOTO(out, rc = -EINVAL);
901 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap);
904 * Delete an idmap from nodemap.
906 * \param[in] file proc file
907 * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
908 * \param[in] count \a buffer length
909 * \param[in] off unused
910 * \retval \a count on success
911 * \retval negative number on error
914 lprocfs_del_nodemap_idmap_seq_write(struct file *file,
915 const char __user *buffer,
916 size_t count, loff_t *off)
918 char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
921 char *idtypestr = NULL;
922 char *idmapstr = NULL;
929 if (count >= sizeof(name_idmapstr))
930 GOTO(out, rc = -EINVAL);
932 if (copy_from_user(name_idmapstr, buffer, count))
933 GOTO(out, rc = -EFAULT);
935 name_idmapstr[count] = '\0';
937 cpybuf = name_idmapstr;
938 name = strsep(&cpybuf, " ");
940 GOTO(out, rc = -EINVAL);
942 idtypestr = strsep(&cpybuf, " ");
943 if (idtypestr == NULL)
944 GOTO(out, rc = -EINVAL);
946 idmapstr = strsep(&cpybuf, " \n");
947 if (idmapstr == NULL)
948 GOTO(out, rc = -EINVAL);
950 rc = nodemap_parse_idmap(idmapstr, idmap);
952 GOTO(out, rc = -EINVAL);
954 if (strcmp(idtypestr, "uid") == 0)
955 rc = nodemap_del_idmap(name, NODEMAP_UID, idmap);
956 else if (strcmp(idtypestr, "gid") == 0)
957 rc = nodemap_del_idmap(name, NODEMAP_GID, idmap);
959 GOTO(out, rc = -EINVAL);
962 GOTO(out, rc = -EINVAL);
970 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap);
971 #endif /* NODEMAP_PROC_DEBUG */
973 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
976 .fops = &nodemap_active_fops,
978 #ifdef NODEMAP_PROC_DEBUG
980 .name = "add_nodemap",
981 .fops = &nodemap_add_nodemap_fops,
984 .name = "remove_nodemap",
985 .fops = &nodemap_del_nodemap_fops,
988 .name = "add_nodemap_range",
989 .fops = &nodemap_add_nodemap_range_fops,
992 .name = "del_nodemap_range",
993 .fops = &nodemap_del_nodemap_range_fops,
996 .name = "add_nodemap_idmap",
997 .fops = &nodemap_add_nodemap_idmap_fops,
1000 .name = "del_nodemap_idmap",
1001 .fops = &nodemap_del_nodemap_idmap_fops,
1003 #endif /* NODEMAP_PROC_DEBUG */
1009 #ifdef NODEMAP_PROC_DEBUG
1010 LPROC_SEQ_FOPS(nodemap_trusted);
1011 LPROC_SEQ_FOPS(nodemap_admin);
1012 LPROC_SEQ_FOPS(nodemap_squash_uid);
1013 LPROC_SEQ_FOPS(nodemap_squash_gid);
1015 LPROC_SEQ_FOPS_RO(nodemap_trusted);
1016 LPROC_SEQ_FOPS_RO(nodemap_admin);
1017 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
1018 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
1021 const struct file_operations nodemap_ranges_fops = {
1022 .open = nodemap_ranges_open,
1024 .llseek = seq_lseek,
1025 .release = single_release
1028 const struct file_operations nodemap_idmap_fops = {
1029 .open = nodemap_idmap_open,
1031 .llseek = seq_lseek,
1032 .release = single_release
1035 const struct file_operations nodemap_exports_fops = {
1036 .open = nodemap_exports_open,
1038 .llseek = seq_lseek,
1039 .release = single_release
1042 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
1045 .fops = &nodemap_id_fops,
1048 .name = "trusted_nodemap",
1049 .fops = &nodemap_trusted_fops,
1052 .name = "admin_nodemap",
1053 .fops = &nodemap_admin_fops,
1056 .name = "squash_uid",
1057 .fops = &nodemap_squash_uid_fops,
1060 .name = "squash_gid",
1061 .fops = &nodemap_squash_gid_fops,
1065 .fops = &nodemap_ranges_fops,
1069 .fops = &nodemap_exports_fops,
1073 .fops = &nodemap_idmap_fops,
1080 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
1083 .fops = &nodemap_id_fops,
1086 .name = "trusted_nodemap",
1087 .fops = &nodemap_trusted_fops,
1090 .name = "admin_nodemap",
1091 .fops = &nodemap_admin_fops,
1094 .name = "squash_uid",
1095 .fops = &nodemap_squash_uid_fops,
1098 .name = "squash_gid",
1099 .fops = &nodemap_squash_gid_fops,
1103 .fops = &nodemap_exports_fops,
1111 * Initialize the nodemap procfs directory.
1115 int nodemap_procfs_init(void)
1119 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
1121 lprocfs_nm_module_vars,
1123 if (IS_ERR(proc_lustre_nodemap_root)) {
1124 rc = PTR_ERR(proc_lustre_nodemap_root);
1125 CERROR("cannot create 'nodemap' directory: rc = %d\n",
1127 proc_lustre_nodemap_root = NULL;
1133 * Cleanup nodemap proc entry data structures.
1135 void nodemap_procfs_exit(void)
1137 struct nodemap_pde *nm_pde;
1138 struct nodemap_pde *tmp;
1140 lprocfs_remove(&proc_lustre_nodemap_root);
1141 list_for_each_entry_safe(nm_pde, tmp, &nodemap_pde_list,
1143 list_del(&nm_pde->npe_list_member);
1144 OBD_FREE_PTR(nm_pde);
1149 * Remove a nodemap's procfs entry and related data.
1151 void lprocfs_nodemap_remove(struct nodemap_pde *nm_pde)
1153 lprocfs_remove(&nm_pde->npe_proc_entry);
1154 list_del(&nm_pde->npe_list_member);
1155 OBD_FREE_PTR(nm_pde);
1159 * Register the proc directory for a nodemap
1161 * \param nodemap nodemap to make the proc dir for
1162 * \param is_default: 1 if default nodemap
1165 int lprocfs_nodemap_register(struct lu_nodemap *nodemap, bool is_default)
1167 struct nodemap_pde *nm_entry;
1170 OBD_ALLOC_PTR(nm_entry);
1171 if (nm_entry == NULL)
1172 GOTO(out, rc = -ENOMEM);
1174 nm_entry->npe_proc_entry = proc_mkdir(nodemap->nm_name,
1175 proc_lustre_nodemap_root);
1176 if (IS_ERR(nm_entry->npe_proc_entry))
1177 GOTO(out, rc = PTR_ERR(nm_entry->npe_proc_entry));
1179 snprintf(nm_entry->npe_name, sizeof(nm_entry->npe_name), "%s",
1182 /* Use the nodemap name as stored on the PDE as the private data. This
1183 * is so a nodemap struct can be replaced without updating the proc
1186 rc = lprocfs_add_vars(nm_entry->npe_proc_entry,
1187 (is_default ? lprocfs_default_nodemap_vars :
1188 lprocfs_nodemap_vars),
1189 nm_entry->npe_name);
1191 lprocfs_remove(&nm_entry->npe_proc_entry);
1193 list_add(&nm_entry->npe_list_member, &nodemap_pde_list);
1197 CERROR("cannot create 'nodemap/%s': rc = %d\n",
1198 nodemap->nm_name, rc);
1199 if (nm_entry != NULL) {
1200 OBD_FREE_PTR(nm_entry);
1205 nodemap->nm_pde_data = nm_entry;