Whamcloud - gitweb
LU-8851 nodemap: add uid/gid only flags to control mapping
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_lproc.c
index a77c478..c384785 100644 (file)
 #include <interval_tree.h>
 #include "nodemap_internal.h"
 
-/* Turn on proc debug interface to allow OSS and
- * MDS nodes to configure nodemap independently of
- * MGS (since the nodemap distribution is not written
- * yet */
-#define NODEMAP_PROC_DEBUG 1
-
 static LIST_HEAD(nodemap_pde_list);
 
 /**
@@ -174,6 +168,78 @@ static int nodemap_ranges_open(struct inode *inode, struct file *file)
 }
 
 /**
+ * Reads and prints the fileset for the given nodemap.
+ *
+ * \param      m               seq file in proc fs
+ * \param      data            unused
+ * \retval     0               success
+ */
+static int nodemap_fileset_seq_show(struct seq_file *m, void *data)
+{
+       struct lu_nodemap *nodemap;
+       int rc = 0;
+
+       mutex_lock(&active_config_lock);
+       nodemap = nodemap_lookup(m->private);
+       mutex_unlock(&active_config_lock);
+       if (IS_ERR(nodemap)) {
+               rc = PTR_ERR(nodemap);
+               CERROR("cannot find nodemap '%s': rc = %d\n",
+                       (char *)m->private, rc);
+               return rc;
+       }
+
+       seq_printf(m, "%s\n", nodemap->nm_fileset);
+       nodemap_putref(nodemap);
+       return rc;
+}
+
+/**
+ * Set a fileset on a nodemap.
+ *
+ * \param[in] file      proc file
+ * \param[in] buffer    string, "<fileset>"
+ * \param[in] count     \a buffer length
+ * \param[in] off       unused
+ * \retval              \a count on success
+ * \retval              negative number on error
+ */
+static ssize_t
+nodemap_fileset_seq_write(struct file *file,
+                                     const char __user *buffer,
+                                     size_t count, loff_t *off)
+{
+       struct seq_file *m = file->private_data;
+       char *nm_fileset;
+       int rc = 0;
+       ENTRY;
+
+       if (count == 0)
+               RETURN(0);
+
+       if (count > PATH_MAX)
+               RETURN(-EINVAL);
+
+       OBD_ALLOC(nm_fileset, count);
+       if (nm_fileset == NULL)
+               RETURN(-ENOMEM);
+
+       if (copy_from_user(nm_fileset, buffer, count))
+               GOTO(out, rc = -EFAULT);
+
+       rc = nodemap_set_fileset(m->private, nm_fileset);
+       if (rc != 0)
+               GOTO(out, rc = -EINVAL);
+
+       rc = count;
+out:
+       OBD_FREE(nm_fileset, count);
+
+       return rc;
+}
+LPROC_SEQ_FOPS(nodemap_fileset);
+
+/**
  * Reads and prints the exports attached to the given nodemap.
  *
  * \param      m               seq file in proc fs, stores nodemap
@@ -414,6 +480,66 @@ static int nodemap_admin_seq_show(struct seq_file *m, void *data)
        return 0;
 }
 
+/**
+ * Reads and prints the mapping mode for the given nodemap.
+ *
+ * \param      m               seq file in proc fs
+ * \param      data            unused
+ * \retval     0               success
+ */
+static int nodemap_map_mode_seq_show(struct seq_file *m, void *data)
+{
+       struct lu_nodemap *nodemap;
+       int rc;
+
+       mutex_lock(&active_config_lock);
+       nodemap = nodemap_lookup(m->private);
+       mutex_unlock(&active_config_lock);
+       if (IS_ERR(nodemap)) {
+               rc = PTR_ERR(nodemap);
+               CERROR("cannot find nodemap '%s': rc = %d\n",
+                       (char *)m->private, rc);
+               return rc;
+       }
+
+       if (nodemap->nmf_map_uid_only)
+               seq_printf(m, "uid_only\n");
+       else if (nodemap->nmf_map_gid_only)
+               seq_printf(m, "gid_only\n");
+       else
+               seq_printf(m, "both\n");
+
+       nodemap_putref(nodemap);
+       return 0;
+}
+
+/**
+ * Reads and prints the deny_unknown flag for the given nodemap.
+ *
+ * \param      m               seq file in proc fs
+ * \param      data            unused
+ * \retval     0               success
+ */
+static int nodemap_deny_unknown_seq_show(struct seq_file *m, void *data)
+{
+       struct lu_nodemap *nodemap;
+       int rc;
+
+       mutex_lock(&active_config_lock);
+       nodemap = nodemap_lookup(m->private);
+       mutex_unlock(&active_config_lock);
+       if (IS_ERR(nodemap)) {
+               rc = PTR_ERR(nodemap);
+               CERROR("cannot find nodemap '%s': rc = %d\n",
+                       (char *)m->private, rc);
+               return rc;
+       }
+
+       seq_printf(m, "%d\n", (int)nodemap->nmf_deny_unknown);
+       nodemap_putref(nodemap);
+       return 0;
+}
+
 #ifdef NODEMAP_PROC_DEBUG
 /**
  * Helper functions to set nodemap flags.
@@ -1018,6 +1144,9 @@ LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
 LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
 #endif
 
+LPROC_SEQ_FOPS_RO(nodemap_deny_unknown);
+LPROC_SEQ_FOPS_RO(nodemap_map_mode);
+
 const struct file_operations nodemap_ranges_fops = {
        .open                   = nodemap_ranges_open,
        .read                   = seq_read,
@@ -1053,6 +1182,14 @@ static struct lprocfs_vars lprocfs_nodemap_vars[] = {
                .fops           = &nodemap_admin_fops,
        },
        {
+               .name           = "deny_unknown",
+               .fops           = &nodemap_deny_unknown_fops,
+       },
+       {
+               .name           = "map_mode",
+               .fops           = &nodemap_map_mode_fops,
+       },
+       {
                .name           = "squash_uid",
                .fops           = &nodemap_squash_uid_fops,
        },
@@ -1065,6 +1202,10 @@ static struct lprocfs_vars lprocfs_nodemap_vars[] = {
                .fops           = &nodemap_ranges_fops,
        },
        {
+               .name           = "fileset",
+               .fops           = &nodemap_fileset_fops,
+       },
+       {
                .name           = "exports",
                .fops           = &nodemap_exports_fops,
        },