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 #include <lprocfs_status.h>
31 #include <lustre_net.h>
32 #include "nodemap_internal.h"
34 static int nodemap_rd_active(char *page, char **start, off_t off, int count,
39 rc = snprintf(page, count, "%u\n", (unsigned int)nodemap_idmap_active);
47 static int nodemap_wr_active(struct file *file, const char __user *buffer,
48 unsigned long count, void *data)
50 char active_string[NODEMAP_LPROC_FLAG_LEN + 1];
57 if (count > NODEMAP_LPROC_FLAG_LEN)
60 if (copy_from_user(active_string, buffer, count))
63 active_string[count] = '\0';
64 active = simple_strtoul(active_string, NULL, 10);
65 nodemap_idmap_active = active;
70 static int nodemap_rd_id(char *page, char **start, off_t off, int count,
73 struct lu_nodemap *nodemap = data;
75 return snprintf(page, count, "%u\n", nodemap->nm_id);
78 static int nodemap_rd_squash_uid(char *page, char **start, off_t off,
79 int count, int *eof, void *data)
81 struct lu_nodemap *nodemap = data;
83 return snprintf(page, count, "%u\n", nodemap->nm_squash_uid);
86 static int nodemap_rd_squash_gid(char *page, char **start, off_t off,
87 int count, int *eof, void *data)
89 struct lu_nodemap *nodemap = data;
91 return snprintf(page, count, "%u\n", nodemap->nm_squash_gid);
94 static int nodemap_rd_trusted(char *page, char **start, off_t off,
95 int count, int *eof, void *data)
97 struct lu_nodemap *nodemap = data;
99 return snprintf(page, count, "%d\n",
100 (int)nodemap->nmf_trust_client_ids);
103 static int nodemap_rd_admin(char *page, char **start, off_t off, int count,
104 int *eof, void *data)
106 struct lu_nodemap *nodemap = data;
108 return snprintf(page, count, "%d\n",
109 (int)nodemap->nmf_allow_root_access);
112 #ifdef NODEMAP_PROC_DEBUG
113 static int nodemap_proc_read_flag(const char __user *buffer,
114 unsigned long count, unsigned int *flag_p)
116 char scratch[NODEMAP_LPROC_FLAG_LEN + 1];
121 if (count > NODEMAP_LPROC_FLAG_LEN)
124 if (copy_from_user(scratch, buffer, count))
127 scratch[count] = '\0';
128 *flag_p = simple_strtoul(scratch, NULL, 10);
133 static int nodemap_wr_squash_uid(struct file *file, const char __user *buffer,
134 unsigned long count, void *data)
136 char squash[NODEMAP_LPROC_ID_LEN + 1];
137 struct lu_nodemap *nodemap = data;
144 if (count > NODEMAP_LPROC_FLAG_LEN)
147 if (copy_from_user(squash, buffer, count))
150 squash[count] = '\0';
151 squash_uid = simple_strtoul(squash, NULL, 10);
152 nodemap->nm_squash_uid = squash_uid;
157 static int nodemap_wr_squash_gid(struct file *file, const char __user *buffer,
158 unsigned long count, void *data)
160 char squash[NODEMAP_LPROC_ID_LEN + 1];
161 struct lu_nodemap *nodemap = data;
168 if (count > NODEMAP_LPROC_FLAG_LEN)
171 if (copy_from_user(squash, buffer, count))
174 squash[count] = '\0';
175 squash_gid = simple_strtoul(squash, NULL, 10);
176 nodemap->nm_squash_gid = squash_gid;
181 static int nodemap_wr_trusted(struct file *file, const char __user *buffer,
182 unsigned long count, void *data)
184 struct lu_nodemap *nodemap = data;
188 rc = nodemap_proc_read_flag(buffer, count, &flags);
190 nodemap->nmf_trust_client_ids = !!flags;
195 static int nodemap_wr_admin(struct file *file, const char __user *buffer,
196 unsigned long count, void *data)
198 struct lu_nodemap *nodemap = data;
202 rc = nodemap_proc_read_flag(buffer, count, &flags);
204 nodemap->nmf_allow_root_access = !!flags;
209 static int nodemap_proc_add_nodemap(struct file *file,
210 const char __user *buffer,
211 unsigned long count, void *data)
213 char buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
222 if (count > LUSTRE_NODEMAP_NAME_LENGTH)
225 if (copy_from_user(buf, buffer, count))
229 pos = strchr(buf, '\n');
234 name = strsep(&cpybuf, " ");
238 rc = nodemap_add(name);
245 static int nodemap_proc_del_nodemap(struct file *file,
246 const char __user *buffer,
247 unsigned long count, void *data)
249 char buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
258 if (count > LUSTRE_NODEMAP_NAME_LENGTH)
261 if (copy_from_user(buf, buffer, count))
265 pos = strchr(buf, '\n');
270 name = strsep(&cpybuf, " ");
274 rc = nodemap_del(name);
281 #endif /* NODEMAP_PROC_DEBUG */
283 static struct lprocfs_vars lprocfs_nodemap_module_vars[] = {
286 .read_fptr = nodemap_rd_active,
287 .write_fptr = nodemap_wr_active,
289 #ifdef NODEMAP_PROC_DEBUG
291 .name = "add_nodemap",
292 .write_fptr = nodemap_proc_add_nodemap,
295 .name = "remove_nodemap",
296 .write_fptr = nodemap_proc_del_nodemap,
298 #endif /* NODEMAP_PROC_DEBUG */
304 #ifdef NODEMAP_PROC_DEBUG
305 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
308 .read_fptr = nodemap_rd_id,
311 .name = "trusted_nodemap",
312 .read_fptr = nodemap_rd_trusted,
313 .write_fptr = nodemap_wr_trusted,
316 .name = "admin_nodemap",
317 .read_fptr = nodemap_rd_admin,
318 .write_fptr = nodemap_wr_admin,
321 .name = "squash_uid",
322 .read_fptr = nodemap_rd_squash_uid,
323 .write_fptr = nodemap_wr_squash_uid,
326 .name = "squash_gid",
327 .read_fptr = nodemap_rd_squash_gid,
328 .write_fptr = nodemap_wr_squash_gid,
335 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
338 .read_fptr = nodemap_rd_id,
341 .name = "trusted_nodemap",
342 .read_fptr = nodemap_rd_trusted,
343 .write_fptr = nodemap_wr_trusted,
346 .name = "admin_nodemap",
347 .read_fptr = nodemap_rd_admin,
348 .write_fptr = nodemap_wr_admin,
351 .name = "squash_uid",
352 .read_fptr = nodemap_rd_squash_uid,
353 .write_fptr = nodemap_wr_squash_uid,
356 .name = "squash_gid",
357 .read_fptr = nodemap_rd_squash_gid,
358 .write_fptr = nodemap_wr_squash_gid,
365 static struct lprocfs_vars lprocfs_nodemap_vars[] = {
368 .read_fptr = nodemap_rd_id,
371 .name = "trusted_nodemap",
372 .read_fptr = nodemap_rd_trusted,
375 .name = "admin_nodemap",
376 .read_fptr = nodemap_rd_admin,
379 .name = "squash_uid",
380 .read_fptr = nodemap_rd_squash_uid,
383 .name = "squash_gid",
384 .read_fptr = nodemap_rd_squash_gid,
391 static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
394 .read_fptr = nodemap_rd_id,
397 .name = "trusted_nodemap",
398 .read_fptr = nodemap_rd_trusted,
401 .name = "admin_nodemap",
402 .read_fptr = nodemap_rd_admin,
405 .name = "squash_uid",
406 .read_fptr = nodemap_rd_squash_uid,
409 .name = "squash_gid",
410 .read_fptr = nodemap_rd_squash_gid,
416 #endif /* NODEMAP_PROC_DEBUG */
418 int nodemap_procfs_init(void)
422 proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
424 lprocfs_nodemap_module_vars,
427 if (IS_ERR(proc_lustre_nodemap_root)) {
428 rc = PTR_ERR(proc_lustre_nodemap_root);
429 CERROR("cannot create 'nodemap' directory: rc = %d\n",
431 proc_lustre_nodemap_root = NULL;
438 * Register the proc directory for a nodemap
440 * \param name name of nodemap
441 * \param is_default: 1 if default nodemap
444 int lprocfs_nodemap_register(const char *name,
446 struct lu_nodemap *nodemap)
448 struct proc_dir_entry *nodemap_proc_entry;
453 lprocfs_register(name,
454 proc_lustre_nodemap_root,
455 lprocfs_default_nodemap_vars,
458 nodemap_proc_entry = lprocfs_register(name,
459 proc_lustre_nodemap_root,
460 lprocfs_nodemap_vars,
463 if (IS_ERR(nodemap_proc_entry)) {
464 rc = PTR_ERR(nodemap_proc_entry);
465 CERROR("cannot create 'nodemap/%s': rc = %d\n", name, rc);
466 nodemap_proc_entry = NULL;
469 nodemap->nm_proc_entry = nodemap_proc_entry;