Whamcloud - gitweb
LU-2872 tests: Reenable sanity-quota/1 for ZFS
[fs/lustre-release.git] / lustre / nodemap / nodemap_lproc.c
index 540adad..5eecd68 100644 (file)
 
 #include <lprocfs_status.h>
 #include <lustre_net.h>
+#include <interval_tree.h>
 #include "nodemap_internal.h"
 
-static int nodemap_rd_active(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
+static int nodemap_idmap_show(struct seq_file *m, void *data)
 {
-       int rc;
+       struct lu_nodemap       *nodemap = m->private;
+       struct lu_idmap         *idmap;
+       struct rb_node          *node;
+       bool                    cont = 0;
+
+       seq_printf(m, "[\n");
+       for (node = rb_first(&nodemap->nm_client_to_fs_uidmap); node;
+                               node = rb_next(node)) {
+               if (cont)
+                       seq_printf(m, ",\n");
+               cont = 1;
+               idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
+               if (idmap != NULL)
+                       seq_printf(m, " { idtype: uid, client_id: %u, "
+                                  "fs_id: %u }", idmap->id_client,
+                                  idmap->id_fs);
+       }
+       for (node = rb_first(&nodemap->nm_client_to_fs_gidmap);
+                               node; node = rb_next(node)) {
+               if (cont)
+                       seq_printf(m, ",\n");
+               idmap = rb_entry(node, struct lu_idmap, id_client_to_fs);
+               if (idmap != NULL)
+                       seq_printf(m, " { idtype: gid, client_id: %u, "
+                                  "fs_id: %u }", idmap->id_client,
+                                  idmap->id_fs);
+       }
+       seq_printf(m, "\n");
+       seq_printf(m, "]\n");
 
-       rc = snprintf(page, count, "%u\n", (unsigned int)nodemap_idmap_active);
+       return 0;
+}
 
-       if (count == 0)
-               return 0;
+static int nodemap_idmap_open(struct inode *inode, struct file *file)
+{
+       struct lu_nodemap *nodemap = PDE_DATA(inode);
 
-       return rc;
+       return single_open(file, nodemap_idmap_show, nodemap);
+}
+
+static int nodemap_ranges_show(struct seq_file *m, void *data)
+{
+       struct lu_nodemap               *nodemap = m->private;
+       struct lu_nid_range             *range;
+       struct interval_node_extent     ext;
+       bool                            cont = 0;
+
+       seq_printf(m, "[\n");
+       list_for_each_entry(range, &nodemap->nm_ranges, rn_list) {
+               if (cont)
+                       seq_printf(m, ",\n");
+               cont = 1;
+               ext = range->rn_node.in_extent;
+               seq_printf(m, " { id: %u, start_nid: %s, "
+                               "end_nid: %s }",
+                          range->rn_id, libcfs_nid2str(ext.start),
+                          libcfs_nid2str(ext.end));
+       }
+       seq_printf(m, "\n");
+       seq_printf(m, "]\n");
+
+       return 0;
+}
+
+static int nodemap_ranges_open(struct inode *inode, struct file *file)
+{
+       struct lu_nodemap *nodemap = PDE_DATA(inode);
+
+       return single_open(file, nodemap_ranges_show, nodemap);
+}
+
+static int nodemap_active_seq_show(struct seq_file *m, void *data)
+{
+       return seq_printf(m, "%u\n", (unsigned int)nodemap_active);
 }
 
-static int nodemap_wr_active(struct file *file, const char __user *buffer,
-                            unsigned long count, void *data)
+static ssize_t
+nodemap_active_seq_write(struct file *file, const char __user *buffer,
+                        size_t count, loff_t *off)
 {
        char    active_string[NODEMAP_LPROC_FLAG_LEN + 1];
        __u32   active;
@@ -62,51 +129,46 @@ static int nodemap_wr_active(struct file *file, const char __user *buffer,
 
        active_string[count] = '\0';
        active = simple_strtoul(active_string, NULL, 10);
-       nodemap_idmap_active = active;
+       nodemap_active = active;
 
        return rc;
 }
+LPROC_SEQ_FOPS(nodemap_active);
 
-static int nodemap_rd_id(char *page, char **start, off_t off, int count,
-                        int *eof, void *data)
+static int nodemap_id_seq_show(struct seq_file *m, void *data)
 {
-       struct lu_nodemap *nodemap = data;
+       struct lu_nodemap *nodemap = m->private;
 
-       return snprintf(page, count, "%u\n", nodemap->nm_id);
+       return seq_printf(m, "%u\n", nodemap->nm_id);
 }
+LPROC_SEQ_FOPS_RO(nodemap_id);
 
-static int nodemap_rd_squash_uid(char *page, char **start, off_t off,
-                                int count, int *eof, void *data)
+static int nodemap_squash_uid_seq_show(struct seq_file *m, void *data)
 {
-       struct lu_nodemap *nodemap = data;
+       struct lu_nodemap *nodemap = m->private;
 
-       return snprintf(page, count, "%u\n", nodemap->nm_squash_uid);
+       return seq_printf(m, "%u\n", nodemap->nm_squash_uid);
 }
 
-static int nodemap_rd_squash_gid(char *page, char **start, off_t off,
-                                int count, int *eof, void *data)
+static int nodemap_squash_gid_seq_show(struct seq_file *m, void *data)
 {
-       struct lu_nodemap *nodemap = data;
+       struct lu_nodemap *nodemap = m->private;
 
-       return snprintf(page, count, "%u\n", nodemap->nm_squash_gid);
+       return seq_printf(m, "%u\n", nodemap->nm_squash_gid);
 }
 
-static int nodemap_rd_trusted(char *page, char **start, off_t off,
-                             int count, int *eof, void *data)
+static int nodemap_trusted_seq_show(struct seq_file *m, void *data)
 {
-       struct lu_nodemap *nodemap = data;
+       struct lu_nodemap *nodemap = m->private;
 
-       return snprintf(page, count, "%d\n",
-                       (int)nodemap->nmf_trust_client_ids);
+       return seq_printf(m, "%d\n", (int)nodemap->nmf_trust_client_ids);
 }
 
-static int nodemap_rd_admin(char *page, char **start, off_t off, int count,
-                           int *eof, void *data)
+static int nodemap_admin_seq_show(struct seq_file *m, void *data)
 {
-       struct lu_nodemap *nodemap = data;
+       struct lu_nodemap *nodemap = m->private;
 
-       return snprintf(page, count, "%d\n",
-                       (int)nodemap->nmf_allow_root_access);
+       return seq_printf(m, "%d\n", (int)nodemap->nmf_allow_root_access);
 }
 
 #ifdef NODEMAP_PROC_DEBUG
@@ -130,11 +192,13 @@ static int nodemap_proc_read_flag(const char __user *buffer,
        return 0;
 }
 
-static int nodemap_wr_squash_uid(struct file *file, const char __user *buffer,
-                                unsigned long count, void *data)
+static ssize_t
+nodemap_squash_uid_seq_write(struct file *file, const char __user *buffer,
+                            size_t count, loff_t *off)
 {
        char                    squash[NODEMAP_LPROC_ID_LEN + 1];
-       struct lu_nodemap       *nodemap = data;
+       struct seq_file         *m = file->private_data;
+       struct lu_nodemap       *nodemap = m->private;
        uid_t                   squash_uid;
        int                     rc = count;
 
@@ -154,11 +218,13 @@ static int nodemap_wr_squash_uid(struct file *file, const char __user *buffer,
        return rc;
 }
 
-static int nodemap_wr_squash_gid(struct file *file, const char __user *buffer,
-                                unsigned long count, void *data)
+static ssize_t
+nodemap_squash_gid_seq_write(struct file *file, const char __user *buffer,
+                            size_t count, loff_t *off)
 {
        char                    squash[NODEMAP_LPROC_ID_LEN + 1];
-       struct lu_nodemap       *nodemap = data;
+       struct seq_file         *m = file->private_data;
+       struct lu_nodemap       *nodemap = m->private;
        gid_t                   squash_gid;
        int                     rc = count;
 
@@ -178,10 +244,12 @@ static int nodemap_wr_squash_gid(struct file *file, const char __user *buffer,
        return rc;
 }
 
-static int nodemap_wr_trusted(struct file *file, const char __user *buffer,
-                             unsigned long count, void *data)
+static ssize_t
+nodemap_trusted_seq_write(struct file *file, const char __user *buffer,
+                         size_t count, loff_t *off)
 {
-       struct lu_nodemap       *nodemap = data;
+       struct seq_file         *m = file->private_data;
+       struct lu_nodemap       *nodemap = m->private;
        int                     flags;
        int                     rc;
 
@@ -192,10 +260,12 @@ static int nodemap_wr_trusted(struct file *file, const char __user *buffer,
        return rc;
 }
 
-static int nodemap_wr_admin(struct file *file, const char __user *buffer,
-                           unsigned long count, void *data)
+static ssize_t
+nodemap_admin_seq_write(struct file *file, const char __user *buffer,
+                       size_t count, loff_t *off)
 {
-       struct lu_nodemap       *nodemap = data;
+       struct seq_file         *m = file->private_data;
+       struct lu_nodemap       *nodemap = m->private;
        int                     flags;
        int                     rc;
 
@@ -206,9 +276,9 @@ static int nodemap_wr_admin(struct file *file, const char __user *buffer,
        return rc;
 }
 
-static int nodemap_proc_add_nodemap(struct file *file,
-                                   const char __user *buffer,
-                                   unsigned long count, void *data)
+static ssize_t
+lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer,
+                             size_t count, loff_t *off)
 {
        char    buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
        char    *cpybuf = NULL;
@@ -241,10 +311,11 @@ static int nodemap_proc_add_nodemap(struct file *file,
 
        return rc;
 }
+LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap);
 
-static int nodemap_proc_del_nodemap(struct file *file,
-                                   const char __user *buffer,
-                                   unsigned long count, void *data)
+static ssize_t
+lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer,
+                             size_t count, loff_t *off)
 {
        char    buf[LUSTRE_NODEMAP_NAME_LENGTH + 1];
        char    *cpybuf = NULL;
@@ -278,22 +349,23 @@ static int nodemap_proc_del_nodemap(struct file *file,
        return rc;
 
 }
+LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap);
+
 #endif /* NODEMAP_PROC_DEBUG */
 
-static struct lprocfs_vars lprocfs_nodemap_module_vars[] = {
+static struct lprocfs_seq_vars lprocfs_nodemap_module_vars[] = {
        {
                .name           = "active",
-               .read_fptr      = nodemap_rd_active,
-               .write_fptr     = nodemap_wr_active,
+               .fops           = &nodemap_active_fops,
        },
 #ifdef NODEMAP_PROC_DEBUG
        {
                .name           = "add_nodemap",
-               .write_fptr     = nodemap_proc_add_nodemap,
+               .fops           = &nodemap_add_nodemap_fops,
        },
        {
                .name           = "remove_nodemap",
-               .write_fptr     = nodemap_proc_del_nodemap,
+               .fops           = &nodemap_del_nodemap_fops,
        },
 #endif /* NODEMAP_PROC_DEBUG */
        {
@@ -302,127 +374,99 @@ static struct lprocfs_vars lprocfs_nodemap_module_vars[] = {
 };
 
 #ifdef NODEMAP_PROC_DEBUG
-static struct lprocfs_vars lprocfs_nodemap_vars[] = {
-       {
-               .name           = "id",
-               .read_fptr      = nodemap_rd_id,
-       },
-       {
-               .name           = "trusted_nodemap",
-               .read_fptr      = nodemap_rd_trusted,
-               .write_fptr     = nodemap_wr_trusted,
-       },
-       {
-               .name           = "admin_nodemap",
-               .read_fptr      = nodemap_rd_admin,
-               .write_fptr     = nodemap_wr_admin,
-       },
-       {
-               .name           = "squash_uid",
-               .read_fptr      = nodemap_rd_squash_uid,
-               .write_fptr     = nodemap_wr_squash_uid,
-       },
-       {
-               .name           = "squash_gid",
-               .read_fptr      = nodemap_rd_squash_gid,
-               .write_fptr     = nodemap_wr_squash_gid,
-       },
-       {
-               NULL
-       }
+LPROC_SEQ_FOPS(nodemap_trusted);
+LPROC_SEQ_FOPS(nodemap_admin);
+LPROC_SEQ_FOPS(nodemap_squash_uid);
+LPROC_SEQ_FOPS(nodemap_squash_gid);
+#else
+LPROC_SEQ_FOPS_RO(nodemap_trusted);
+LPROC_SEQ_FOPS_RO(nodemap_admin);
+LPROC_SEQ_FOPS_RO(nodemap_squash_uid);
+LPROC_SEQ_FOPS_RO(nodemap_squash_gid);
+#endif
+
+const struct file_operations nodemap_ranges_fops = {
+       .open                   = nodemap_ranges_open,
+       .read                   = seq_read,
+       .llseek                 = seq_lseek,
+       .release                = single_release
 };
 
-static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
+const struct file_operations nodemap_idmap_fops = {
+       .open                   = nodemap_idmap_open,
+       .read                   = seq_read,
+       .llseek                 = seq_lseek,
+       .release                = single_release
+};
+
+static struct lprocfs_seq_vars lprocfs_nodemap_vars[] = {
        {
                .name           = "id",
-               .read_fptr      = nodemap_rd_id,
+               .fops           = &nodemap_id_fops,
        },
        {
                .name           = "trusted_nodemap",
-               .read_fptr      = nodemap_rd_trusted,
-               .write_fptr     = nodemap_wr_trusted,
+               .fops           = &nodemap_trusted_fops,
        },
        {
                .name           = "admin_nodemap",
-               .read_fptr      = nodemap_rd_admin,
-               .write_fptr     = nodemap_wr_admin,
+               .fops           = &nodemap_admin_fops,
        },
        {
                .name           = "squash_uid",
-               .read_fptr      = nodemap_rd_squash_uid,
-               .write_fptr     = nodemap_wr_squash_uid,
+               .fops           = &nodemap_squash_uid_fops,
        },
        {
                .name           = "squash_gid",
-               .read_fptr      = nodemap_rd_squash_gid,
-               .write_fptr     = nodemap_wr_squash_gid,
-       },
-       {
-               NULL
-       }
-};
-#else
-static struct lprocfs_vars lprocfs_nodemap_vars[] = {
-       {
-               .name           = "id",
-               .read_fptr      = nodemap_rd_id,
+               .fops           = &nodemap_squash_gid_fops,
        },
        {
-               .name           = "trusted_nodemap",
-               .read_fptr      = nodemap_rd_trusted,
+               .name           = "ranges",
+               .fops           = &nodemap_ranges_fops,
        },
        {
-               .name           = "admin_nodemap",
-               .read_fptr      = nodemap_rd_admin,
-       },
-       {
-               .name           = "squash_uid",
-               .read_fptr      = nodemap_rd_squash_uid,
-       },
-       {
-               .name           = "squash_gid",
-               .read_fptr      = nodemap_rd_squash_gid,
+               .name           = "idmap",
+               .fops           = &nodemap_idmap_fops,
        },
        {
                NULL
        }
 };
 
-static struct lprocfs_vars lprocfs_default_nodemap_vars[] = {
+static struct lprocfs_seq_vars lprocfs_default_nodemap_vars[] = {
        {
                .name           = "id",
-               .read_fptr      = nodemap_rd_id,
+               .fops           = &nodemap_id_fops,
        },
        {
                .name           = "trusted_nodemap",
-               .read_fptr      = nodemap_rd_trusted,
+               .fops           = &nodemap_trusted_fops,
        },
        {
                .name           = "admin_nodemap",
-               .read_fptr      = nodemap_rd_admin,
+               .fops           = &nodemap_admin_fops,
        },
        {
                .name           = "squash_uid",
-               .read_fptr      = nodemap_rd_squash_uid,
+               .fops           = &nodemap_squash_uid_fops,
        },
        {
                .name           = "squash_gid",
-               .read_fptr      = nodemap_rd_squash_gid,
+               .fops           = &nodemap_squash_gid_fops,
        },
        {
                NULL
        }
 };
-#endif /* NODEMAP_PROC_DEBUG */
 
 int nodemap_procfs_init(void)
 {
        int rc = 0;
 
-       proc_lustre_nodemap_root = lprocfs_register(LUSTRE_NODEMAP_NAME,
-                                                   proc_lustre_root,
-                                                   lprocfs_nodemap_module_vars,
-                                                   NULL);
+       proc_lustre_nodemap_root = lprocfs_seq_register(LUSTRE_NODEMAP_NAME,
+                                                       proc_lustre_root,
+                                                       lprocfs_nodemap_module_vars,
+                                                       NULL);
 
        if (IS_ERR(proc_lustre_nodemap_root)) {
                rc = PTR_ERR(proc_lustre_nodemap_root);
@@ -450,15 +494,15 @@ int lprocfs_nodemap_register(const char *name,
 
        if (is_default)
                nodemap_proc_entry =
-                       lprocfs_register(name,
+                       lprocfs_seq_register(name,
                                         proc_lustre_nodemap_root,
                                         lprocfs_default_nodemap_vars,
                                         nodemap);
        else
-               nodemap_proc_entry = lprocfs_register(name,
-                                                     proc_lustre_nodemap_root,
-                                                     lprocfs_nodemap_vars,
-                                                     nodemap);
+               nodemap_proc_entry = lprocfs_seq_register(name,
+                                                         proc_lustre_nodemap_root,
+                                                         lprocfs_nodemap_vars,
+                                                         nodemap);
 
        if (IS_ERR(nodemap_proc_entry)) {
                rc = PTR_ERR(nodemap_proc_entry);