Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index 0ccfb9c..b5e6620 100644 (file)
  */
 #define DEBUG_SUBSYSTEM S_LLITE
 
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <asm/statfs.h>
+#endif
 #include <linux/lustre_lite.h>
 #include <linux/lprocfs_status.h>
 
+/* /proc/lustre/llite mount point registration */
 
-int rd_path(char* page, char **start, off_t off, int count, int *eof, 
-            void *data)
+#ifndef LPROCFS
+int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
+                                struct super_block *sb, char *osc, char *mdc)
 {
         return 0;
 }
-int rd_fstype(char* page, char **start, off_t off, int count, int *eof, 
-              void *data)
-{
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        
-        len += snprintf(page, count, "%s\n", sb->s_type->name); 
-        return len;
+#else
+
+#define LPROC_LLITE_STAT_FCT(fct_name, get_statfs_fct)                    \
+int fct_name(char *page, char **start, off_t off,                         \
+             int count, int *eof, void *data)                             \
+{                                                                         \
+        struct statfs sfs;                                                \
+        int rc;                                                           \
+        LASSERT(data != NULL);                                            \
+        rc = get_statfs_fct((struct super_block*)data, &sfs);             \
+        return (rc==0                                                     \
+                ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
+                : rc);                                                    \
 }
-int rd_blksize(char* page, char **start, off_t off, int count, int *eof, 
-               void *data)
-{
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        struct statfs mystats;
 
-        (sb->s_op->statfs)(sb, &mystats);
-        len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_bsize)); 
-        return len;
-
-}
-int rd_kbytestotal(char* page, char **start, off_t off, int count, int *eof, 
-                   void *data)
-{
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        struct statfs mystats;
-        __u32 blk_size;
-        __u64 result;
-
-        (sb->s_op->statfs)(sb, &mystats);
-        blk_size = mystats.f_bsize;
-        blk_size >>= 10;
-        result = mystats.f_blocks;
-        
-        while(blk_size >>= 1){
-                result <<= 1;
-        }
-       
-        len += snprintf(page, count, LPU64"\n", result); 
-        return len;
-        
-}
+long long mnt_instance;
 
+LPROC_LLITE_STAT_FCT(rd_blksize,     vfs_statfs);
+LPROC_LLITE_STAT_FCT(rd_kbytestotal, vfs_statfs);
+LPROC_LLITE_STAT_FCT(rd_kbytesfree,  vfs_statfs);
+LPROC_LLITE_STAT_FCT(rd_filestotal,  vfs_statfs);
+LPROC_LLITE_STAT_FCT(rd_filesfree,   vfs_statfs);
+LPROC_LLITE_STAT_FCT(rd_filegroups,  vfs_statfs);
 
-int rd_kbytesfree(char* page, char **start, off_t off, int count, int *eof, 
-                  void *data)
-{
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        struct statfs mystats; 
-        __u32 blk_size;
-        __u64 result;
-
-        (sb->s_op->statfs)(sb, &mystats);
-        blk_size = mystats.f_bsize;
-        blk_size >>= 10;
-        result = mystats.f_bfree;
-        
-        while(blk_size >>= 1){
-                result <<= 1;
-        }
-       
-        len += snprintf(page, count, LPU64"\n", result); 
-        return len;
-
-        
-}
-
-int rd_filestotal(char* page, char **start, off_t off, int count, int *eof, 
-                  void *data)
+int rd_path(char *page, char **start, off_t off, int count, int *eof,
+            void *data)
 {
-        
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        struct statfs mystats; 
-        
-        (sb->s_op->statfs)(sb, &mystats);
-        len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_files)); 
-        return len;
+        return 0;
 }
 
-int rd_filesfree(char* page, char **start, off_t off, int count, int *eof, 
-                 void *data)
+int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
+              void *data)
 {
-        
-        int len = 0;
         struct super_block *sb = (struct super_block*)data;
-        struct statfs mystats; 
-        
-        (sb->s_op->statfs)(sb, &mystats);
-        len += snprintf(page, count, LPU64"\n", (__u64)(mystats.f_ffree)); 
-        return len;
-}
 
-int rd_filegroups(char* page, char **start, off_t off, int count, int *eof, 
-                  void *data)
-{
-        return 0;
+        LASSERT(sb != NULL);
+        *eof = 1;
+        return snprintf(page, count, "%s\n", sb->s_type->name);
 }
-int rd_uuid(char* page, char **start, off_t off, int count, int *eof, 
-            void *data)
-{
-        int len = 0;
-        struct super_block *sb = (struct super_block*)data;
-        struct ll_sb_info *sbi = ll_s2sbi(sb);
-        len += snprintf(page, count, "%s\n", sbi->ll_sb_uuid); 
-        return len;    
 
-}
-int rd_dev_name(char* page, char **start, off_t off, int count, int *eof, 
-                void *data)
+int rd_sb_uuid(char *page, char **start, off_t off, int count, int *eof,
+               void *data)
 {
-        int len = 0;
-        struct obd_device* dev = (struct obd_device*)data;
-        len += snprintf(page, count, "%s\n", dev->obd_name);
-        return len;
-}
+        struct super_block *sb = (struct super_block *)data;
 
-int rd_dev_uuid(char* page, char **start, off_t off, int count, int *eof, 
-                void *data)
-{
-        int len = 0;
-        struct obd_device* dev = (struct obd_device*)data;
-        len += snprintf(page, count, "%s\n", dev->obd_uuid);
-        return len;
+        LASSERT(sb != NULL);
+        *eof = 1;
+        return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
 }
 
-
-struct lprocfs_vars status_var_nm_1[] = {
-        {"status/uuid", rd_uuid, 0, 0},
-        {"status/mntpt_path", rd_path, 0, 0},
-        {"status/fstype", rd_fstype, 0, 0},
-        {"status/blocksize",rd_blksize, 0, 0},
-        {"status/kbytestotal",rd_kbytestotal, 0, 0},
-        {"status/kbytesfree", rd_kbytesfree, 0, 0},
-        {"status/filestotal", rd_filestotal, 0, 0},
-        {"status/filesfree", rd_filesfree, 0, 0},
-        {"status/filegroups", rd_filegroups, 0, 0},
-        {0}
+struct lprocfs_vars lprocfs_obd_vars[] = {
+        { "uuid",        rd_sb_uuid,     0, 0 },
+        { "mntpt_path",  rd_path,        0, 0 },
+        { "fstype",      rd_fstype,      0, 0 },
+        { "blocksize",   rd_blksize,     0, 0 },
+        { "kbytestotal", rd_kbytestotal, 0, 0 },
+        { "kbytesfree",  rd_kbytesfree,  0, 0 },
+        { "filestotal",  rd_filestotal,  0, 0 },
+        { "filesfree",   rd_filesfree,   0, 0 },
+        { "filegroups",  rd_filegroups,  0, 0 },
+        { 0 }
 };
 
-/* 
- * Proc registration function for Lustre
- * file system
- */
-
-
-#define MAX_STRING_SIZE 100
-void ll_proc_namespace(struct super_block* sb, char* osc, char* mdc)
+#define MAX_STRING_SIZE 128
+int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
+                                struct super_block *sb, char *osc, char *mdc)
 {
-        char mnt_name[MAX_STRING_SIZE];
-        char uuid_name[MAX_STRING_SIZE];
-        struct lprocfs_vars d_vars[3];
+        struct lprocfs_vars lvars[2];
         struct ll_sb_info *sbi = ll_s2sbi(sb);
-        struct obd_device* obd;
+        struct obd_device *obd;
+        char name[MAX_STRING_SIZE + 1];
+        struct obd_uuid uuid;
         int err;
+        ENTRY;
 
-        
-        /* Register this mount instance with LProcFS */
-        snprintf(mnt_name, 100, "mount_%s", sbi->ll_sb_uuid);
-        sbi->ll_proc_root = lprocfs_reg_mnt(mnt_name);
-        if (!sbi->ll_proc_root)
-                CDEBUG(D_OTHER, "Could not register FS");
-        /* Add the static configuration info */
-        err = lprocfs_add_vars(sbi->ll_proc_root,status_var_nm_1, sb);
-        if (err)
-                CDEBUG(D_OTHER, "Unable to add procfs variables\n");
-
-        /* MDC */
-        obd = class_uuid2obd(mdc);
+        memset(lvars, 0, sizeof(lvars));
 
-        
-        snprintf(mnt_name, MAX_STRING_SIZE, "status/%s/common_name", 
-                 obd->obd_type->typ_name);
+        name[MAX_STRING_SIZE] = '\0';
+        lvars[0].name = name;
 
-        memset(d_vars, 0, sizeof(d_vars));
-        d_vars[0].read_fptr = rd_dev_name;
-        d_vars[0].write_fptr = NULL;
-        d_vars[0].name = mnt_name;
+        LASSERT(sbi != NULL);
+        LASSERT(mdc != NULL);
+        LASSERT(osc != NULL);
 
-        snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid",
-                 obd->obd_type->typ_name);
-        d_vars[1].read_fptr = rd_dev_uuid;
-        d_vars[1].write_fptr = NULL;
-        d_vars[1].name = uuid_name;
+        /* Mount info */
+        snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
 
-        err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd);
+        mnt_instance++;
+        sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
+        if (IS_ERR(sbi->ll_proc_root)) {
+                err = PTR_ERR(sbi->ll_proc_root);
+                sbi->ll_proc_root = NULL;
+                RETURN(err);
+        }
+        /* Static configuration info */
+        err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
         if (err)
-                CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n");
+                RETURN(err);
+
+        /* MDC info */
+        strncpy(uuid.uuid, mdc, sizeof(uuid.uuid));
+        obd = class_uuid2obd(&uuid);
 
-        /* OSC or LOV*/
-        obd = class_uuid2obd(osc);
+        LASSERT(obd != NULL);
+        LASSERT(obd->obd_type != NULL);
+        LASSERT(obd->obd_type->typ_name != NULL);
 
-        /* Reuse mnt_name */
-        snprintf(mnt_name, MAX_STRING_SIZE, "status/%s/common_name",
+        snprintf(name, MAX_STRING_SIZE, "%s/common_name",
                  obd->obd_type->typ_name);
+        lvars[0].read_fptr = lprocfs_rd_name;
+        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
+        if (err)
+                RETURN(err);
 
-        memset(d_vars, 0, sizeof(d_vars));
-        d_vars[0].read_fptr = rd_dev_name;
-        d_vars[0].write_fptr = NULL;
-        d_vars[0].name = mnt_name;
+        snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
+        lvars[0].read_fptr = lprocfs_rd_uuid;
+        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
+        if (err < 0)
+                RETURN(err);
 
-        snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid",
-                 obd->obd_type->typ_name);
-        d_vars[1].read_fptr = rd_dev_uuid;
-        d_vars[1].write_fptr = NULL;
-        d_vars[1].name = uuid_name;
+        /* OSC */
+        strncpy(uuid.uuid, osc, sizeof(uuid.uuid));
+        obd = class_uuid2obd(&uuid);
+
+        LASSERT(obd != NULL);
+        LASSERT(obd->obd_type != NULL);
+        LASSERT(obd->obd_type->typ_name != NULL);
 
-        err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd);
+        snprintf(name, MAX_STRING_SIZE, "%s/common_name",
+                 obd->obd_type->typ_name);
+        lvars[0].read_fptr = lprocfs_rd_name;
+        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
         if (err)
-                CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n");
+                RETURN(err);
+
+        snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
+        lvars[0].read_fptr = lprocfs_rd_uuid;
+        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
 
+        RETURN(err);
 }
+
 #undef MAX_STRING_SIZE
+#endif /* LPROCFS */