Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.c
index d4be2d6..26bbdf7 100644 (file)
  */
 
 #define EXPORT_SYMTAB
+#define DEBUG_SUBSYSTEM S_CLASS
+#ifdef __KERNEL__
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <asm/statfs.h>
+#endif
+
+#else
+#include <liblustre.h>
+#endif
 
-#define DEBUG_SUBSYSTEM S_CLASS
 #include <linux/obd_class.h>
 #include <linux/lprocfs_status.h>
 
@@ -110,7 +118,11 @@ void lprocfs_remove(struct proc_dir_entry* root)
 {
         struct proc_dir_entry *temp = root;
         struct proc_dir_entry *rm_entry;
-        struct proc_dir_entry *parent = root->parent;
+        struct proc_dir_entry *parent;
+
+        LASSERT(root != NULL);
+        parent = root->parent;
+        LASSERT(parent != NULL);
 
         while (1) {
                 while (temp->subdir)
@@ -133,8 +145,8 @@ struct proc_dir_entry *lprocfs_register(const char *name,
         newchild = lprocfs_srch(parent, name);
         if (newchild) {
                 CERROR(" Lproc: Attempting to register %s more than once \n",
-                                name);
-                return NULL;
+                       name);
+                return ERR_PTR(-EALREADY);
         }
 
         newchild = proc_mkdir(name, parent);
@@ -153,6 +165,7 @@ struct proc_dir_entry *lprocfs_register(const char *name,
 int lprocfs_rd_u64(char *page, char **start, off_t off,
                    int count, int *eof, void *data)
 {
+        LASSERT(data != NULL);
         *eof = 1;
         return snprintf(page, count, LPU64"\n", *(__u64 *)data);
 }
@@ -162,6 +175,7 @@ int lprocfs_rd_uuid(char* page, char **start, off_t off, int count,
 {
         struct obd_device* dev = (struct obd_device*)data;
 
+        LASSERT(dev != NULL);
         *eof = 1;
         return snprintf(page, count, "%s\n", dev->obd_uuid.uuid);
 }
@@ -171,6 +185,8 @@ int lprocfs_rd_name(char *page, char **start, off_t off, int count,
 {
         struct obd_device* dev = (struct obd_device *)data;
 
+        LASSERT(dev != NULL);
+        LASSERT(dev->obd_name != NULL);
         *eof = 1;
         return snprintf(page, count, "%s\n", dev->obd_name);
 }
@@ -178,16 +194,20 @@ int lprocfs_rd_name(char *page, char **start, off_t off, int count,
 int lprocfs_rd_blksize(char* page, char **start, off_t off, int count,
                        int *eof, struct statfs *sfs)
 {
+        LASSERT(sfs != NULL);
         *eof = 1;
-
         return snprintf(page, count, "%lu\n", sfs->f_bsize);
 }
 
 int lprocfs_rd_kbytestotal(char* page, char **start, off_t off, int count,
                            int *eof, struct statfs *sfs)
 {
-        __u32 blk_size = sfs->f_bsize >> 10;
-        __u64 result = sfs->f_blocks;
+        __u32 blk_size;
+        __u64 result;
+
+        LASSERT(sfs != NULL);
+        blk_size = sfs->f_bsize >> 10;
+        result = sfs->f_blocks;
 
         while (blk_size >>= 1)
                 result <<= 1;
@@ -199,8 +219,12 @@ int lprocfs_rd_kbytestotal(char* page, char **start, off_t off, int count,
 int lprocfs_rd_kbytesfree(char* page, char **start, off_t off, int count,
                           int *eof, struct statfs *sfs)
 {
-        __u32 blk_size = sfs->f_bsize >> 10;
-        __u64 result = sfs->f_bfree;
+        __u32 blk_size;
+        __u64 result;
+
+        LASSERT(sfs != NULL);
+        blk_size = sfs->f_bsize >> 10;
+        result = sfs->f_bfree;
 
         while (blk_size >>= 1)
                 result <<= 1;
@@ -212,6 +236,7 @@ int lprocfs_rd_kbytesfree(char* page, char **start, off_t off, int count,
 int lprocfs_rd_filestotal(char* page, char **start, off_t off, int count,
                           int *eof, struct statfs *sfs)
 {
+        LASSERT(sfs != NULL);
         *eof = 1;
         return snprintf(page, count, "%ld\n", sfs->f_files);
 }
@@ -219,6 +244,7 @@ int lprocfs_rd_filestotal(char* page, char **start, off_t off, int count,
 int lprocfs_rd_filesfree(char* page, char **start, off_t off, int count,
                          int *eof, struct statfs *sfs)
 {
+        LASSERT(sfs != NULL);
         *eof = 1;
         return snprintf(page, count, "%ld\n", sfs->f_ffree);
 }
@@ -234,7 +260,11 @@ int lprocfs_rd_server_uuid(char* page, char **start, off_t off, int count,
                            int *eof, void *data)
 {
         struct obd_device* obd = (struct obd_device*)data;
-        struct client_obd* cli = &obd->u.cli;
+        struct client_obd* cli;
+
+        LASSERT(obd != NULL);
+        cli = &obd->u.cli;
+        *eof = 1;
         return snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
 }
 
@@ -242,8 +272,11 @@ int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
                          int *eof,  void *data)
 {
         struct obd_device *obd = (struct obd_device*)data;
-        struct ptlrpc_connection *conn = obd->u.cli.cl_import.imp_connection;
+        struct ptlrpc_connection *conn;
 
+        LASSERT(obd != NULL);
+        conn = obd->u.cli.cl_import.imp_connection;
+        LASSERT(conn != NULL);
         *eof = 1;
         return snprintf(page, count, "%s\n", conn->c_remote_uuid.uuid);
 }
@@ -253,6 +286,7 @@ int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
 {
         struct obd_type* class = (struct obd_type*) data;
 
+        LASSERT(class != NULL);
         *eof = 1;
         return snprintf(page, count, "%d\n", class->typ_refcnt);
 }
@@ -260,12 +294,17 @@ int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
 int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list)
 {
         int rc = 0;
+
+        LASSERT(dev != NULL);
+        LASSERT(dev->obd_type != NULL);
+        LASSERT(dev->obd_type->typ_procroot != NULL);
+
         dev->obd_proc_entry = lprocfs_register(dev->obd_name,
                                                dev->obd_type->typ_procroot,
                                                list, dev);
         if (IS_ERR(dev->obd_proc_entry)) {
                 rc = PTR_ERR(dev->obd_proc_entry);
-               dev->obd_proc_entry = NULL;
+                dev->obd_proc_entry = NULL;
         }
         return rc;
 }