Whamcloud - gitweb
LU-6210 ptlrpc: Use C99 initializer in ptlrpc_register_rqbd()
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_lproc.c
index f9692e3..fc13b00 100644 (file)
@@ -210,15 +210,33 @@ nodemap_fileset_seq_write(struct file *file,
                                      size_t count, loff_t *off)
 {
        struct seq_file *m = file->private_data;
+       char *nm_fileset;
        int rc = 0;
+       ENTRY;
 
-       if (count > 0)
-               rc = nodemap_set_fileset(m->private, buffer);
+       if (count == 0)
+               RETURN(0);
+
+       if (count > PATH_MAX)
+               RETURN(-EINVAL);
+
+       OBD_ALLOC(nm_fileset, count + 1);
+       /* OBD_ALLOC zero-fills the buffer */
+       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)
-               return -EINVAL;
+               GOTO(out, rc = -EINVAL);
 
-       return count;
+       rc = count;
+out:
+       OBD_FREE(nm_fileset, count + 1);
+
+       return rc;
 }
 LPROC_SEQ_FOPS(nodemap_fileset);
 
@@ -464,6 +482,39 @@ static int nodemap_admin_seq_show(struct seq_file *m, void *data)
 }
 
 /**
+ * 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
@@ -705,7 +756,7 @@ lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
 
        return rc;
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap);
 
 /**
  * Delete a nodemap.
@@ -749,7 +800,7 @@ lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
        return rc;
 
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap);
 
 /**
  * Helper function to parse a NID string.
@@ -846,7 +897,7 @@ lprocfs_add_nodemap_range_seq_write(struct file *file,
 out:
        return rc;
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap_range);
 
 /**
  * Delete a NID range from nodemap.
@@ -905,7 +956,7 @@ lprocfs_del_nodemap_range_seq_write(struct file *file,
 out:
        return rc;
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap_range);
 
 /**
  * Add an idmap to nodemap.
@@ -974,7 +1025,7 @@ lprocfs_add_nodemap_idmap_seq_write(struct file *file,
 out:
        return rc;
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap_idmap);
 
 /**
  * Delete an idmap from nodemap.
@@ -1043,7 +1094,7 @@ lprocfs_del_nodemap_idmap_seq_write(struct file *file,
 out:
        return rc;
 }
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap);
+LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap_idmap);
 #endif /* NODEMAP_PROC_DEBUG */
 
 static struct lprocfs_vars lprocfs_nm_module_vars[] = {
@@ -1095,6 +1146,7 @@ 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,
@@ -1135,6 +1187,10 @@ static struct lprocfs_vars lprocfs_nodemap_vars[] = {
                .fops           = &nodemap_deny_unknown_fops,
        },
        {
+               .name           = "map_mode",
+               .fops           = &nodemap_map_mode_fops,
+       },
+       {
                .name           = "squash_uid",
                .fops           = &nodemap_squash_uid_fops,
        },