Whamcloud - gitweb
bring changes from HEAD to b_lustre_ba
authorpschwan <pschwan>
Thu, 14 Nov 2002 00:24:05 +0000 (00:24 +0000)
committerpschwan <pschwan>
Thu, 14 Nov 2002 00:24:05 +0000 (00:24 +0000)
lustre/obdclass/lprocfs_status.c

index d4c65e7..1f8316c 100644 (file)
@@ -17,9 +17,9 @@
  *   You should have received a copy of the GNU General Public License
  *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
+ *   
+ *   Author: Hariharan Thantry thantry@users.sourceforge.net
  */
-
 #define EXPORT_SYMTAB
 #include <linux/config.h>
 #include <linux/module.h>
@@ -29,8 +29,6 @@
 #include <linux/types.h>
 
 #define DEBUG_SUBSYSTEM S_CLASS
-#define MAX_STRING_SIZE 100
-
 #include <linux/lustre_lite.h>
 #include <linux/lprocfs_status.h>
 
@@ -59,12 +57,9 @@ struct proc_dir_entry* lprocfs_mkdir(const char* dname,
                                      struct proc_dir_entry *parent)
 {
         struct proc_dir_entry *child_dir_entry;
-
         child_dir_entry = proc_mkdir(dname, parent);
-
         if (!child_dir_entry)
                 CERROR("lustre: failed to create /proc entry %s\n", dname);
-
         return child_dir_entry;
 }
 
@@ -72,17 +67,14 @@ struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head,
                                     const char* name)
 {
         struct proc_dir_entry* temp;
-
         if (!head)
                 return NULL;
-
         temp = head->subdir;
         while (temp != NULL) {
                 if (!strcmp(temp->name, name))
                         return temp;
                 temp = temp->next;
         }
-
         return NULL;
 }
 
@@ -103,17 +95,18 @@ void lprocfs_remove_all(struct proc_dir_entry* root)
         }
 }
 
+#define MAX_STRING_SIZE 100
 struct proc_dir_entry* lprocfs_new_dir(struct proc_dir_entry* root,
                                        const char* string, const char* tok)
 {
-        struct proc_dir_entry* new_root = 0;
-        struct proc_dir_entry* temp_entry = 0;
+        struct proc_dir_entry* new_root;
+        struct proc_dir_entry* temp_entry;
         char temp_string[MAX_STRING_SIZE];
         char* my_str;
         char* mover_str;
 
         strncpy(temp_string, string, MAX_STRING_SIZE-1);
-        temp_string[strlen(string) + 1] = '\0';
+        temp_string[MAX_STRING_SIZE] = '\0';
 
         new_root = root;
         mover_str = temp_string;
@@ -123,23 +116,23 @@ struct proc_dir_entry* lprocfs_new_dir(struct proc_dir_entry* root,
                 CDEBUG(D_OTHER, "SEARCH= %s\t, ROOT=%s\n", my_str,
                        new_root->name);
                 temp_entry = lprocfs_srch(new_root, my_str);
-                if (temp_entry == 0) {
+                if (temp_entry == NULL) {
                         CDEBUG(D_OTHER, "Adding: %s\n", my_str);
                         temp_entry = lprocfs_mkdir(my_str, new_root);
-                        if (temp_entry == 0) {
+                        if (temp_entry == NULL) {
                                 CDEBUG(D_OTHER, 
                                        "! Did not create new dir %s !!\n",
                                        my_str);
-                                return 0;
+                                return temp_entry;
                         }
                 }
                 new_root = temp_entry;
         }
-
         return new_root;
 }
 
-int lprocfs_new_vars(struct proc_dir_entry* root, struct lprocfs_vars* list,
+int lprocfs_new_vars(struct proc_dir_entry* root, 
+                     struct lprocfs_vars* list,
                      const char* tok, void* data)
 {
         struct proc_dir_entry *temp_root;
@@ -147,47 +140,55 @@ int lprocfs_new_vars(struct proc_dir_entry* root, struct lprocfs_vars* list,
         struct proc_dir_entry *new_parent;
         char temp_string[MAX_STRING_SIZE];
 
-        if (!list)
+        if (list == NULL)
                 return 0;
 
         while (list->name) {
                 temp_root = lprocfs_new_dir(root, list->name, tok);
-
-                if (!temp_root) {
+                if (temp_root == NULL) {
                         CDEBUG(D_OTHER, "!LProcFS: Mods: No root!");
                         return -EINVAL;
                 }
 
                 /* Convert the last element into a leaf-node */
                 strncpy(temp_string, temp_root->name, MAX_STRING_SIZE-1);
-                temp_string[strlen(temp_root->name) + 1] = '\0';
+                temp_string[MAX_STRING_SIZE] = '\0';
                 new_parent = temp_root->parent;
                 remove_proc_entry(temp_root->name, new_parent);
-
                 new_leaf = create_proc_entry(temp_string, DEFAULT_MODE,
                                              new_parent);
                 new_leaf->read_proc = list->read_fptr;
                 new_leaf->write_proc = list->write_fptr;
-                new_leaf->data = data;
+                if (data)
+                        new_leaf->data=data;
+                else
+                        new_leaf->data=list->data;
                 list++;
         }
         return 0;
-}
 
+}
+#undef MAX_STRING_SIZE
 /*
  *  API implementations
  */
 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *var,
                      void *data)
 {
-        return lprocfs_new_vars(root, var, (const char*) tok, data);
+        return lprocfs_new_vars(root, var, tok, data);
 }
 
 int lprocfs_reg_obd(struct obd_device *device, struct lprocfs_vars *list,
                     void *data)
 {
-        int retval = 0;
-        struct proc_dir_entry* this_dev_root = 0;
+        struct proc_dir_entry* this_dev_root;
+        int retval;
+        
+        if(lprocfs_srch(device->obd_type->typ_procroot, device->obd_name)){
+                CDEBUG(D_OTHER, "Device with name [%s] exists!", 
+                                device->obd_name);
+                return 0;
+        }
 
         /* Obtain this device root */
         this_dev_root = lprocfs_mkdir(device->obd_name,
@@ -203,13 +204,16 @@ int lprocfs_dereg_obd(struct obd_device* device)
 {
         CDEBUG(D_OTHER, "LPROCFS removing device = %s\n", device->obd_name);
 
-        if (!device) {
+        if (device == NULL) {
                 CDEBUG(D_OTHER, "! LProcfs:  Null pointer !\n");
                 return 0;
         }
-
+        if (device->obd_proc_entry == NULL) {
+                CDEBUG(D_OTHER, "! Proc entry non-existent !");
+                return 0;
+        }
         lprocfs_remove_all(device->obd_proc_entry);
-
+        device->obd_proc_entry = NULL;
         if (device->counters)
                 OBD_FREE(device->counters, device->cntr_mem_size);
 
@@ -218,11 +222,19 @@ int lprocfs_dereg_obd(struct obd_device* device)
 
 struct proc_dir_entry* lprocfs_reg_mnt(char* mnt_name)
 {
+        if(lprocfs_srch(proc_lustre_fs_root, mnt_name)){
+                CDEBUG(D_OTHER, "Mount with same name exists!");
+                return 0;
+        }
         return lprocfs_mkdir(mnt_name, proc_lustre_fs_root);
 }
 
 int lprocfs_dereg_mnt(struct proc_dir_entry* root)
 {
+        if(root == NULL){
+                CDEBUG(D_OTHER, "Non-existent root!");
+                return 0;
+        }
         lprocfs_remove_all(root);
         return 0;
 }
@@ -230,49 +242,45 @@ int lprocfs_dereg_mnt(struct proc_dir_entry* root)
 int lprocfs_reg_class(struct obd_type* type, struct lprocfs_vars* list,
                       void* data)
 {
+        
         struct proc_dir_entry* root;
         int retval;
-
         root = lprocfs_mkdir(type->typ_name, proc_lustre_dev_root);
-
+        lprocfs_add_vars(root, list, data);
         type->typ_procroot = root;
-
         retval = lprocfs_add_vars(root, list, data);
-
         return retval;
 }
 
 int lprocfs_dereg_class(struct obd_type* class)
 {
-        if(!class){
+        if(class == NULL){
                 CDEBUG(D_OTHER, "Non-existent class",
                        class->typ_name);
                 return 0;
         }
-
         lprocfs_remove_all(class->typ_procroot);
-
+        class->typ_procroot = NULL;
         CDEBUG(D_OTHER, "LPROCFS removed = %s\n", class->typ_name);
-
         return 0;
 
 }
 int lprocfs_reg_main()
 {
         proc_lustre_root = lprocfs_mkdir("lustre", &proc_root);
-        if (!proc_lustre_root) {
+        if (proc_lustre_root == NULL) {
                 CERROR(" !! Cannot create /proc/lustre !! \n");
                 return -EINVAL;
         }
 
         proc_lustre_dev_root = lprocfs_mkdir("devices", proc_lustre_root);
-        if (!proc_lustre_dev_root) {
+        if (proc_lustre_dev_root == NULL) {
                 CERROR(" !! Cannot create /proc/lustre/devices !! \n");
                 return -EINVAL;
         }
         proc_lustre_fs_root = lprocfs_mkdir("mnt_pnt", proc_lustre_root);
 
-        if (!proc_lustre_fs_root) {
+        if (proc_lustre_fs_root == NULL) {
                 CERROR(" !! Cannot create /proc/lustre/mnt_pnt !! \n");
                 return -EINVAL;
         }
@@ -283,10 +291,9 @@ int lprocfs_reg_main()
 int lprocfs_dereg_main()
 {
         lprocfs_remove_all(proc_lustre_root);
-        proc_lustre_root = 0;
-        proc_lustre_dev_root = 0;
-        proc_lustre_fs_root = 0;
-
+        proc_lustre_root = NULL;
+        proc_lustre_dev_root = NULL;
+        proc_lustre_fs_root = NULL;
         return 0;
 }
 
@@ -299,9 +306,7 @@ int lprocfs_ll_rd(char *page, char **start, off_t off,
 {
         __u64 *temp = (__u64 *)data;
         int len;
-
         len = snprintf(page, count, LPU64"\n", *temp);
-
         return len;
 }