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
24 * Author: Joshua Walgenbach <jjw@iu.edu>
27 #define NODEMAP_LPROC_ID_LEN 16
28 #define NODEMAP_LPROC_FLAG_LEN 2
30 #define NODEMAP_PROC_DEBUG 1
32 #include <lprocfs_status.h>
33 #include <lustre_net.h>
34 #include "nodemap_internal.h"
36 static int nodemap_active_seq_show(struct seq_file *m, void *data)
38 return seq_printf(m, "%u\n", (unsigned int)nodemap_idmap_active);
42 nodemap_active_seq_write(struct file *file, const char __user *buffer,
43 size_t count, loff_t *off)
45 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
52 if (count > NODEMAP_LPROC_FLAG_LEN)
55 if (copy_from_user(active_string, buffer, count))
58 active_string[count] = '\0';
59 active = simple_strtoul(active_string, NULL, 10);
60 nodemap_idmap_active = active;
64 LPROC_SEQ_FOPS(nodemap_active);
66 static int nodemap_id_seq_show(struct seq_file *m, void *data)
68 struct lu_nodemap *nodemap = m->private;
70 return seq_printf(m, "%u\n", nodemap->nm_id);
72 LPROC_SEQ_FOPS_RO(nodemap_id);
74 static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
76 struct lu_nodemap *nodemap = m->private;
78 return seq_printf(m, "%u\n", nodemap->nm_squash_uid);
81 static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
83 struct lu_nodemap *nodemap = m->private;
85 return seq_printf(m, "%u\n", nodemap->nm_squash_gid);
88 static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
90 struct lu_nodemap *nodemap = m->private;
92 return seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
95 static int nodemap_admin_seq_show(struct seq_file *m, void *data)
97 struct lu_nodemap *nodemap = m->private;
99 return seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
102 #ifdef NODEMAP_PROC_DEBUG
103 static int nodemap_proc_read_flag(const char __user *buffer,
104 unsigned long count, unsigned int *flag_p)
106 char scratch[NODEMAP_LPROC_FLAG_LEN + 1];
111 if (count > NODEMAP_LPROC_FLAG_LEN)
114 if (copy_from_user(scratch, buffer, count))
117 scratch[count] = '\0';
118 *flag_p = simple_strtoul(scratch, NULL, 10);
124 nodemap_squash_uid_seq_write(struct file *file, const char __user *buffer,
125 size_t count, loff_t *off)
127 char squash[NODEMAP_LPROC_ID_LEN + 1];
128 struct seq_file *m = file->private_data;
129 struct lu_nodemap *nodemap = m->private;
136 if (count > NODEMAP_LPROC_FLAG_LEN)
139 if (copy_from_user(squash, buffer, count))
142 squash[count] = '\0';
143 squash_uid = simple_strtoul(squash, NULL, 10);
144 nodemap->nm_squash_uid = squash_uid;
150 nodemap_squash_gid_seq_write(struct file *file, const char __user *buffer,
151 size_t count, loff_t *off)
153 char squash[NODEMAP_LPROC_ID_LEN + 1];
154 struct seq_file *m = file->private_data;
155 struct lu_nodemap *nodemap = m->private;
162 if (count > NODEMAP_LPROC_FLAG_LEN)
165 if (copy_from_user(squash, buffer, count))
168 squash[count] = '\0';
169 squash_gid = simple_strtoul(squash, NULL, 10);
170 nodemap->nm_squash_gid = squash_gid;
176 nodemap_trusted_seq_write(struct file *file, const char __user *buffer,
177 size_t count, loff_t *off)
179 struct seq_file *m = file->private_data;
180 struct lu_nodemap *nodemap = m->private;
184 rc = nodemap_proc_read_flag(buffer, count, &flags);
186 nodemap->nmf_trust_client_ids = !!flags;
192 nodemap_admin_seq_write(struct file *file, const char __user *buffer,
193 size_t count, loff_t *off)
195 struct seq_file *m = file->private_data;
196 struct lu_nodemap *nodemap = m->private;
200 rc = nodemap_proc_read_flag(buffer, count, &flags);
202 nodemap->nmf_allow_root_access = !!flags;
208 lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
209 size_t count, loff_t *off)
211 char buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
220 if (count > LUSTRE_NODEMAP_NAME_LENGTH)
223 if (copy_from_user(buf, buffer, count))
227 pos = strchr(buf, '\n');
232 name = strsep(&cpybuf, " ");
236 rc = nodemap_add(name);
242 LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
245 lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
246 size_t count, loff_t *off)
248 char buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
257 if (count > LUSTRE_NODEMAP_NAME_LENGTH)
260 if (copy_from_user(buf, buffer, count))
264 pos = strchr(buf, '\n');
269 name = strsep(&cpybuf, " ");
273 rc = nodemap_del(name);
280 LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
282 #endif /* NODEMAP_PROC_DEBUG */
284 static struct lprocfs_seq_vars lprocfs_nodemap_module_vars[] = {
287 .fops = &nodemap_active_fops,
289 #ifdef NODEMAP_PROC_DEBUG
291 .name = "add_nodemap",
292 .fops = &nodemap_add_nodemap_fops,
295 .name = "remove_nodemap",
296 .fops = &nodemap_del_nodemap_fops,
298 #endif /* NODEMAP_PROC_DEBUG */
304 #ifdef NODEMAP_PROC_DEBUG
305 LPROC_SEQ_FOPS(nodemap_trusted);
306 LPROC_SEQ_FOPS(nodemap_admin);
307 LPROC_SEQ_FOPS(nodemap_squash_uid);
308 LPROC_SEQ_FOPS(nodemap_squash_gid);
310 LPROC_SEQ_FOPS_RO(nodemap_trusted);
311 LPROC_SEQ_FOPS_RO(nodemap_admin);
312 LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
313 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
316 static struct lprocfs_seq_vars lprocfs_nodemap_vars[] = {
319 .fops = &nodemap_id_fops,
322 .name = "trusted_nodemap",
323 .fops = &nodemap_trusted_fops,
326 .name = "admin_nodemap",
327 .fops = &nodemap_admin_fops,
330 .name = "squash_uid",
331 .fops = &nodemap_squash_uid_fops,
334 .name = "squash_gid",
335 .fops = &nodemap_squash_gid_fops,
342 static struct lprocfs_seq_vars lprocfs_default_nodemap_vars[] = {
345 .fops = &nodemap_id_fops,
348 .name = "trusted_nodemap",
349 .fops = &nodemap_trusted_fops,
352 .name = "admin_nodemap",
353 .fops = &nodemap_admin_fops,
356 .name = "squash_uid",
357 .fops = &nodemap_squash_uid_fops,
360 .name = "squash_gid",
361 .fops = &nodemap_squash_gid_fops,
368 int nodemap_procfs_init(void)
372 proc_lustre_nodemap_root = lprocfs_seq_register(LUSTRE_NODEMAP_NAME,
374 lprocfs_nodemap_module_vars,
377 if (IS_ERR(proc_lustre_nodemap_root)) {
378 rc = PTR_ERR(proc_lustre_nodemap_root);
379 CERROR("cannot create 'nodemap' directory: rc = %d\n",
381 proc_lustre_nodemap_root = NULL;
388 * Register the proc directory for a nodemap
390 * \param name name of nodemap
391 * \param is_default: 1 if default nodemap
394 int lprocfs_nodemap_register(const char *name,
396 struct lu_nodemap *nodemap)
398 struct proc_dir_entry *nodemap_proc_entry;
403 lprocfs_seq_register(name,
404 proc_lustre_nodemap_root,
405 lprocfs_default_nodemap_vars,
408 nodemap_proc_entry = lprocfs_seq_register(name,
409 proc_lustre_nodemap_root,
410 lprocfs_nodemap_vars,
413 if (IS_ERR(nodemap_proc_entry)) {
414 rc = PTR_ERR(nodemap_proc_entry);
415 CERROR("cannot create 'nodemap/%s': rc = %d\n", name, rc);
416 nodemap_proc_entry = NULL;
419 nodemap->nm_proc_entry = nodemap_proc_entry;