Whamcloud - gitweb
A better fix from Eric.
[fs/lustre-release.git] / lustre / obdclass / lprocfs.c
index eead8be..5166ee9 100644 (file)
@@ -3,26 +3,37 @@
  *
  * Copyright (C) 2002 Intel Corporation
  *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   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
- * File Name: lprocfs.c 
- * 
- * This code is issued under the GNU General Public License.
- * See the file COPYING in this distribution
+ * File Name: lprocfs.c
  *
  * During initialization (of lustre), the following directory materializes
  *          /proc/lustre
  * When the first OBD device of a class is created (due to insmod)
  * the directory
  *         /proc/lustre/devices/<device-class> is created.
- * When an instance of a device is created (during attach) the 
+ * When an instance of a device is created (during attach) the
  * directory entry for that instance along with the variables for
  * that entry gets created. These variables could be counters, string
  * variables etc.
- * Each API further describes the functionality offered. 
- * 
+ * Each API further describes the functionality offered.
+ *
  */
 
 #define EXPORT_SYMTAB
  * Tokenizer array. Change this array to include special
  * characters for string tokenizing
  */
-char tok[]={'/', (char)0};
+char tok[] = {'/', (char)0};
 char enum_char = '_';
 /*
- * Escape character. To be used in directories that 
+ * Escape character. To be used in directories that
  * should not have any counter/variable entries under
  * them. Used for hierarchical directories
  */
 
-char escape_char='%';
+char escape_char = '%';
 
 /*
  * Externs
@@ -74,14 +85,13 @@ static struct proc_dir_entry *proc_lustre_dev_root = 0;
 
 /* struct lustre_lock proc_lustre_lock; */
 /* static struct proc_dir_entry *proc_lustre_conn_root = 0; */
-char* testStr="General..";
+char *testStr = "General..";
 
 /*
  * Link the namespace with the internal array indices for
- * each device class, only if proc lustre is defined 
+ * each device class, only if proc lustre is defined
  */
 
-
 struct namespace_index dir_mdc_index[] = {
         LPROCFS_DIR_INDEX(mdc, mgmt_setup),
         LPROCFS_DIR_INDEX(mdc, mgmt_cleanup),
@@ -97,8 +107,8 @@ struct namespace_index dir_mdc_index[] = {
         LPROCFS_DIR_INDEX(mdc, unlink),
         LPROCFS_DIR_INDEX(mdc, link),
         LPROCFS_DIR_INDEX(mdc, rename),
-
 };
+
 struct namespace_index dir_mds_index[] = {
         LPROCFS_DIR_INDEX(mds, mgmt_setup),
         LPROCFS_DIR_INDEX(mds, mgmt_cleanup),
@@ -122,8 +132,6 @@ struct namespace_index dir_mds_index[] = {
         LPROCFS_DIR_INDEX(mds, reint_link),
         LPROCFS_DIR_INDEX(mds, reint_rename),
         LPROCFS_DIR_INDEX(mds, reint_recreate),
-
-
 };
 
 struct namespace_index dir_osc_index[] = {
@@ -141,7 +149,6 @@ struct namespace_index dir_osc_index[] = {
         LPROCFS_DIR_INDEX(osc, punch),
         LPROCFS_DIR_INDEX(osc, summary),
         LPROCFS_DIR_INDEX(osc, cancel),
-
 };
 
 struct namespace_index dir_ost_index[] = {
@@ -160,8 +167,8 @@ struct namespace_index dir_ost_index[] = {
         LPROCFS_DIR_INDEX(ost, summary),
         LPROCFS_DIR_INDEX(ost, cancel),
         LPROCFS_DIR_INDEX(ost, getinfo),
-
 };
+
 struct namespace_index dir_lov_index[] = {
         LPROCFS_DIR_INDEX(lov, mgmt_setup),
         LPROCFS_DIR_INDEX(lov, mgmt_cleanup),
@@ -178,10 +185,9 @@ struct namespace_index dir_lov_index[] = {
         LPROCFS_DIR_INDEX(lov, summary),
         LPROCFS_DIR_INDEX(lov, cancel),
         LPROCFS_DIR_INDEX(lov, getinfo),
-
 };
-struct namespace_index dir_obdfilter_index[] = {
 
+struct namespace_index dir_obdfilter_index[] = {
         LPROCFS_DIR_INDEX(obdfilter, mgmt_setup),
         LPROCFS_DIR_INDEX(obdfilter, mgmt_cleanup),
         LPROCFS_DIR_INDEX(obdfilter, mgmt_connect),
@@ -197,10 +203,9 @@ struct namespace_index dir_obdfilter_index[] = {
         LPROCFS_DIR_INDEX(obdfilter, summary),
         LPROCFS_DIR_INDEX(obdfilter, cancel),
         LPROCFS_DIR_INDEX(obdfilter, getinfo),
-};  
+};
 
 struct namespace_index dir_ldlm_index[] = {
-
         LPROCFS_DIR_INDEX(ldlm, mgmt_setup),
         LPROCFS_DIR_INDEX(ldlm, mgmt_cleanup),
         LPROCFS_DIR_INDEX(ldlm, mgmt_connect),
@@ -209,63 +214,52 @@ struct namespace_index dir_ldlm_index[] = {
         LPROCFS_DIR_INDEX(ldlm, locks_cancels),
         LPROCFS_DIR_INDEX(ldlm, locks_converts),
         LPROCFS_DIR_INDEX(ldlm, locks_matches),
-};  
-struct namespace_index dir_ptlrpc_index[] = {
+};
 
+struct namespace_index dir_ptlrpc_index[] = {
         LPROCFS_DIR_INDEX(ptlrpc, mgmt_setup),
         LPROCFS_DIR_INDEX(ptlrpc, mgmt_cleanup),
         LPROCFS_DIR_INDEX(ptlrpc, mgmt_connect),
         LPROCFS_DIR_INDEX(ptlrpc, mgmt_disconnect),
         LPROCFS_DIR_INDEX(ptlrpc, counters),
-};  
-
-
-
+};
 
 struct namespace_index prof_mdc_index[] = {
-        
         LPROCFS_CNTR_INDEX(mdc, min_time),
         LPROCFS_CNTR_INDEX(mdc, max_time),
         LPROCFS_CNTR_INDEX(mdc, sum_time),
         LPROCFS_CNTR_INDEX(mdc, num_ops),
-
-
 };
-struct namespace_index prof_mds_index[]= {
 
-  
+struct namespace_index prof_mds_index[]= {
         LPROCFS_CNTR_INDEX(mds, min_time),
         LPROCFS_CNTR_INDEX(mds, max_time),
         LPROCFS_CNTR_INDEX(mds, sum_time),
         LPROCFS_CNTR_INDEX(mds, num_ops),
 };
-struct namespace_index prof_osc_index[]= {
 
-  
+struct namespace_index prof_osc_index[]= {
         LPROCFS_CNTR_INDEX(osc, min_time),
         LPROCFS_CNTR_INDEX(osc, max_time),
         LPROCFS_CNTR_INDEX(osc, sum_time),
         LPROCFS_CNTR_INDEX(osc, num_ops),
 };
-struct namespace_index prof_ost_index[]= {
 
-  
+struct namespace_index prof_ost_index[]= {
         LPROCFS_CNTR_INDEX(ost, min_time),
         LPROCFS_CNTR_INDEX(ost, max_time),
         LPROCFS_CNTR_INDEX(ost, sum_time),
         LPROCFS_CNTR_INDEX(ost, num_ops),
 };
-struct namespace_index prof_lov_index[]= {
 
-  
+struct namespace_index prof_lov_index[]= {
         LPROCFS_CNTR_INDEX(lov, min_time),
         LPROCFS_CNTR_INDEX(lov, max_time),
         LPROCFS_CNTR_INDEX(lov, sum_time),
         LPROCFS_CNTR_INDEX(lov, num_ops),
 };
-struct namespace_index prof_obdfilter_index[]= {
 
-  
+struct namespace_index prof_obdfilter_index[]= {
         LPROCFS_CNTR_INDEX(obdfilter, min_time),
         LPROCFS_CNTR_INDEX(obdfilter, max_time),
         LPROCFS_CNTR_INDEX(obdfilter, sum_time),
@@ -284,8 +278,6 @@ struct namespace_index prof_ldlm_index[] = {
         LPROCFS_CNTR_INDEX(ldlm, nonzero_mintime),
         LPROCFS_CNTR_INDEX(ldlm, nonzero_maxtime),
         LPROCFS_CNTR_INDEX(ldlm, nonzero_sumtime),
-
-
 };
 
 struct namespace_index prof_ptlrpc_index[] = {
@@ -300,8 +292,6 @@ struct namespace_index prof_ptlrpc_index[] = {
         LPROCFS_CNTR_INDEX(ptlrpc, send_count),
         LPROCFS_CNTR_INDEX(ptlrpc, send_length),
         LPROCFS_CNTR_INDEX(ptlrpc, portal_kmemory),
-
-
 };
 
 /*
@@ -310,7 +300,6 @@ struct namespace_index prof_ptlrpc_index[] = {
  */
 
 struct groupspace_index class_index[] = {
-
         LPROCFS_GROUP_CREATE(mdc),
         LPROCFS_GROUP_CREATE(mds),
         LPROCFS_GROUP_CREATE(osc),
@@ -319,11 +308,10 @@ struct groupspace_index class_index[] = {
         LPROCFS_GROUP_CREATE(obdfilter),
         LPROCFS_GROUP_CREATE(ldlm),
         LPROCFS_GROUP_CREATE(ptlrpc),
-
 };
 
 
-/* 
+/*
  *  API implementations
  */
 
@@ -332,665 +320,639 @@ struct groupspace_index class_index[] = {
  *                       proc hierarchy
  */
 
-int lprocfs_reg_dev(struct obd_device* device, 
-                         lprocfs_group_t* namespace, 
-                         unsigned int cnt_struct_size)
-{
-        
-        
-        unsigned int num_directories=0;
-        int class_array_index=0;
-        int retval=0; 
-        
-        struct proc_dir_entry* this_dev_root=0; 
-        
-        unsigned int i=0, j=0; 
-        
-        /*
-         * Obtain this device root
-         */
-        
-        this_dev_root=lprocfs_mkinitdir(device);
-        if(this_dev_root==0){
+int lprocfs_reg_dev(struct obd_device* device, lprocfs_group_t* namespace,
+                    unsigned int cnt_struct_size)
+{
+        unsigned int num_directories = 0;
+        int class_array_index = 0;
+        int retval = 0;
+        struct proc_dir_entry* this_dev_root=0;
+        unsigned int i = 0, j = 0;
+
+        /* Obtain this device root */
+        this_dev_root = lprocfs_mkinitdir(device);
+        if (this_dev_root == 0) {
                 CERROR("Could not create initial directory");
                 return LPROCFS_FAILURE;
         }
-        
-        
-        /*
-         * Obtain the class-array index
-         */
-        
-        class_array_index=lprocfs_getclass_idx(class_index, \
-                                               device->obd_type->typ_name);
-        
-        if(class_array_index==LPROCFS_FAILURE){
+
+
+        /* Obtain the class-array index */
+        class_array_index = lprocfs_getclass_idx(class_index,
+                                                 device->obd_type->typ_name);
+
+        if (class_array_index == LPROCFS_FAILURE) {
                 CERROR("!! Could not find class !! \n");
                 return LPROCFS_FAILURE;
         }
-        
-        
-        /*
-         * Create the directory namespace
-         */
-        
-        retval=lprocfs_create_dir_namespace(this_dev_root, \
-                                            namespace,\
-                                            &num_directories);
-        if(retval==LPROCFS_FAILURE){
+
+        /* Create the directory namespace */
+        retval = lprocfs_create_dir_namespace(this_dev_root, namespace,
+                                              &num_directories);
+        if (retval == LPROCFS_FAILURE) {
                 CERROR("!!Could not create proc directory structure !!\n");
                 return LPROCFS_FAILURE;
         }
-        
-        
-        
-        /* 
-         * Allocate memory managed by LProcFS for the device.
-         */
-        
-        if(cnt_struct_size!=0){
+
+        /* Allocate memory managed by LProcFS for the device. */
+        if (cnt_struct_size != 0) {
                 OBD_ALLOC(device->counters, num_directories*cnt_struct_size);
-                device->cntr_mem_size=num_directories*cnt_struct_size;
-        } 
-        
-        
+                device->cntr_mem_size = num_directories*cnt_struct_size;
+        }
+
         /*
-         * Iterate the proc-dir-namespace, obtain corresponding 
+         * Iterate the proc-dir-namespace, obtain corresponding
          * directory(attribute)
-         * entries. Create the proc-counters from namespace, link them into 
+         * entries. Create the proc-counters from namespace, link them into
          * dev counters
          */
-        
-        retval=lprocfs_link_dir_counters(device, \
-                                         this_dev_root, \
-                                         namespace, \
-                                         cnt_struct_size, \
-                                         class_array_index);
-        
-        
-        if(retval==LPROCFS_FAILURE){
+        retval=lprocfs_link_dir_counters(device, this_dev_root, namespace,
+                                         cnt_struct_size, class_array_index);
+
+        if (retval == LPROCFS_FAILURE) {
                 CERROR("!! Could not link proc counters to device !!");
                 return LPROCFS_FAILURE;
-                
         }
-        
 
         /*
          * Test code: This goes into individual modules. strcmp is
          * unnecessary, since device knows its class. To see the values
          * from the user space, do a cat on the respective variable
          */
-        
-        if(!(strcmp(device->obd_type->typ_name, "mds"))){
-                DEV_PROF_START(mds, device, gen, mgmt_setup); 
-                
-                for(i=0; i<100; i++)
-                        for(j=0; j<100; j++)
+        if (!(strcmp(device->obd_type->typ_name, "mds"))) {
+                DEV_PROF_START(mds, device, gen, mgmt_setup);
+
+                for (i = 0; i < 100; i++)
+                        for (j = 0; j < 100; j++)
                                 continue;
-                
+
                 DEV_PROF_END(mds, device, gen, mgmt_setup);
-                
-                DEV_PROF_START(mds, device, gen, mgmt_setup); 
-                
-                for(i=0; i<1000; i++)
-                        for(j=0; j<1000; j++)
+
+                DEV_PROF_START(mds, device, gen, mgmt_setup);
+
+                for (i = 0; i < 1000; i++)
+                        for (j = 0; j < 1000; j++)
                                 continue;
-                
+
                 DEV_PROF_END(mds, device, gen, mgmt_setup);
-                
-                
+
+
                 DEV_PROF_START(mds, device, gen, open);
-                for(i=0; i<50; i++){
+                for (i = 0; i < 50; i++) {
                         DEV_PROF_START(mds, device, gen, close);
-                        for(j=0; j<2000; j++)
+                        for (j = 0; j < 2000; j++)
                                 continue;
                         DEV_PROF_END(mds, device, gen, close);
                 }
                 DEV_PROF_END(mds, device, gen, open);
-                
-                
         }
-        
-        
-        if(!(strcmp(device->obd_type->typ_name, "ldlm"))){
-                
+
+        if (!(strcmp(device->obd_type->typ_name, "ldlm"))) {
                 DEV_PROF_START(ldlm, device, ldlm, mgmt_connect);
-                for(i=0; i<200; i++){
+                for (i = 0; i < 200; i++) {
                         DEV_PROF_START(ldlm, device, ldlm, mgmt_disconnect);
-                        for(j=0; j<2000; j++)
+                        for (j = 0; j < 2000; j++)
                                 continue;
                         DEV_PROF_END(ldlm, device, ldlm, mgmt_disconnect);
                 }
-                DEV_PROF_END(ldlm, device, ldlm, mgmt_connect);        
+                DEV_PROF_END(ldlm, device, ldlm, mgmt_connect);
         }
-        
-        
+
         return LPROCFS_SUCCESS;
 }
 
-int lprocfs_link_dir_counters(struct obd_device* device, 
-                              struct proc_dir_entry* root, 
-                              lprocfs_group_t* namespace, 
-                              unsigned int sz, 
+int lprocfs_link_dir_counters(struct obd_device* device,
+                              struct proc_dir_entry* root,
+                              lprocfs_group_t* namespace,
+                              unsigned int sz,
                               unsigned int cl_idx)
 {
-        
-        
-        unsigned int i=0;
-        unsigned int j=0;
-        unsigned int k=0;
-        unsigned int escape=0;
-        int dir_idx=-1;
-        int cnt_idx=-1;
-        
         struct proc_dir_entry* dir_root=0;
         lprocfs_group_t* temp;
         lprocfs_vars_t* fn_ctr;
         struct namespace_index* cntr_names;
-        
+        unsigned int i = 0;
+        unsigned int j = 0;
+        unsigned int k = 0;
+        unsigned int escape = 0;
+        int dir_idx = -1;
+        int cnt_idx = -1;
+
         while(1) {
-                temp=&namespace[i];
-                dir_idx=-1;
-                if(temp->count_func_namespace==0) break;
-                
-                while((temp->dir_namespace)[j]!=0){
-                        dir_root=lprocfs_add_dir(root,\
-                                                 (temp->dir_namespace)[j], \
-                                                 (const char*)tok, &escape);
-                        if(escape){
+                temp = &namespace[i];
+                dir_idx = -1;
+                if (temp->count_func_namespace == 0)
+                        break;
+
+                while ((temp->dir_namespace)[j] != 0) {
+                        dir_root = lprocfs_add_dir(root,
+                                                   (temp->dir_namespace)[j],
+                                                   (const char*)tok, &escape);
+                        if (escape) {
                                 j++;
                                 continue;
                         }
-                        dir_idx=lprocfs_get_idx(class_index[cl_idx].directory,\
-                                                (temp->dir_namespace)[j]);
-                        while(1){
-                                cnt_idx=-1;
-                                fn_ctr=&((temp->count_func_namespace)[k]);
-                                if(fn_ctr->read_fptr==0)break;
-                                cntr_names=class_index[cl_idx].counters;
-                                cnt_idx=lprocfs_get_idx(cntr_names, \
-                                                        fn_ctr->name);
-                               
-                                if(lprocfs_add_var(device, \
-                                                   dir_root, \
-                                                   fn_ctr, \
-                                                   dir_idx, \
-                                                   cnt_idx, \
-                                                   sz, \
-                                                   temp->prof_type)==\
+
+                        dir_idx = lprocfs_get_idx(class_index[cl_idx].directory,
+                                                  (temp->dir_namespace)[j]);
+                        while(1) {
+                                cnt_idx = -1;
+                                fn_ctr = &((temp->count_func_namespace)[k]);
+                                if (fn_ctr->read_fptr == 0)
+                                        break;
+                                cntr_names = class_index[cl_idx].counters;
+                                cnt_idx = lprocfs_get_idx(cntr_names,
+                                                          fn_ctr->name);
+
+                                if (lprocfs_add_var(device, dir_root, fn_ctr,
+                                                   dir_idx, cnt_idx, sz,
+                                                   temp->prof_type) ==
                                    LPROCFS_FAILURE){
                                         CERROR("Could not create leaf node!");
                                         return LPROCFS_FAILURE;
-                                        
+
                                 }
-                                
+
                                 k++;
                         }
-                        
-                        k=0;      
+
+                        k=0;
                         j++;
-                        
+
                 }
                 k=0;
                 j=0;
-                i++;         
+                i++;
         }
-        
+
         return LPROCFS_SUCCESS;
-        
 }
 
-
-
-
-int lprocfs_create_dir_namespace(struct proc_dir_entry* root, \
-                                 lprocfs_group_t* namespace, \
+int lprocfs_create_dir_namespace(struct proc_dir_entry* root,
+                                 lprocfs_group_t* namespace,
                                  unsigned int *num_dirs)
-
 {
-        unsigned int i=0;
-        unsigned int j=0;
+        unsigned int i = 0;
+        unsigned int j = 0;
         struct proc_dir_entry* dir_root=0;
         lprocfs_group_t* temp;
-        unsigned int escape=0;
-
-        while(1) {
-                temp=&namespace[i];
-                if(temp->count_func_namespace==0) break;
-                while((temp->dir_namespace)[j]!=0){
-                        dir_root=lprocfs_add_dir(root, \
-                                                 (temp->dir_namespace)[j], \
-                                                 (const char*)tok, &escape);
-                        if(dir_root==0){
-                                CERROR("!! Could not create dir  %s !! \n", \
+        unsigned int escape = 0;
+
+        while (1) {
+                temp = &namespace[i];
+                if (temp->count_func_namespace == 0)
+                        break;
+                while ((temp->dir_namespace)[j] != 0){
+                        dir_root = lprocfs_add_dir(root,
+                                                   (temp->dir_namespace)[j],
+                                                   (const char*)tok, &escape);
+                        if (dir_root == 0) {
+                                CERROR("!! Could not create dir  %s !! \n",
                                        (temp->dir_namespace)[j]);
                                 return LPROCFS_FAILURE;
                         }
-                        if(temp->prof_type!=e_specific && !escape)
+                        if (temp->prof_type != e_specific && !escape)
                                 (*num_dirs)++;
                         j++;
-                        
                 }
-                j=0;
-                i++;         
+                j = 0;
+                i++;
         }
 
         return LPROCFS_SUCCESS;
-
 }
 
 
-
-
-int lprocfs_getclass_idx(struct groupspace_index* group, 
-                         const char* classname)
+int lprocfs_getclass_idx(struct groupspace_index* group, const char* classname)
 {
-        unsigned int idx=0;
-        while(group[idx].name!=""){
-                if(!strcmp(group[idx].name, classname))
+        unsigned int idx = 0;
+
+        while (group[idx].name != NULL) {
+                if (!strcmp(group[idx].name, classname))
                         return idx;
-                
                 idx++;
         }
 
         return LPROCFS_FAILURE;
-
 }
 
 struct proc_dir_entry* lprocfs_mkinitdir(struct obd_device* device)
 {
+        struct proc_dir_entry* this_dev_root = 0;
+        struct proc_dir_entry* temp_proc = 0;
 
-        struct proc_dir_entry* this_dev_root=0;
-        struct proc_dir_entry* temp_proc=0;
         /*
          * First check if /proc/lustre exits. If it does not,
          * instantiate the same and the devices directory
          */
-        
         if (!proc_lustre_root) {
-                proc_lustre_root = 
-                        lprocfs_mkdir("lustre", &proc_root);
-                if (!proc_lustre_root){
+                proc_lustre_root = lprocfs_mkdir("lustre", &proc_root);
+                if (!proc_lustre_root) {
                         CERROR(" !! Cannot create /proc/lustre !! \n");
                         return 0;
                 }
-                proc_lustre_dev_root = 
+                proc_lustre_dev_root =
                         lprocfs_mkdir("devices", proc_lustre_root);
-                
-                if(!proc_lustre_dev_root){
+
+                if (!proc_lustre_dev_root) {
                         CERROR(" !! Cannot create /proc/lustre/devices !! \n");
                         return 0;
                 }
-                
-        } 
+        }
+
         /*
          * Check if this is the first instance for a device of
-         * this class in the lprocfs hierarchy. 
+         * this class in the lprocfs hierarchy.
          */
-        
-        temp_proc=lprocfs_srch(proc_lustre_dev_root, \
+        temp_proc = lprocfs_srch(proc_lustre_dev_root,
                                  device->obd_type->typ_name);
-        
-        if(!temp_proc){
-                temp_proc=lprocfs_mkdir(device->obd_type->typ_name, \
-                                        proc_lustre_dev_root);
-                if(!temp_proc){
-                        CERROR("! Proc dir for device class %s !!\n", \
+
+        if (!temp_proc) {
+                temp_proc = lprocfs_mkdir(device->obd_type->typ_name,
+                                          proc_lustre_dev_root);
+                if (!temp_proc) {
+                        CERROR("! Proc dir for device class %s !!\n",
                                device->obd_type->typ_name);
                         return 0;
                 }
         }
-        /*
-         * Next create the proc_dir_entry for this instance
-         */
-        
-        this_dev_root=lprocfs_mkdir(device->obd_name, temp_proc);
-        if(!this_dev_root){
-                CERROR("!Cant create proc entry for instance %s !! \n", \
+
+        /* Next create the proc_dir_entry for this instance */
+        this_dev_root = lprocfs_mkdir(device->obd_name, temp_proc);
+        if (!this_dev_root) {
+                CERROR("!Can't create proc entry for instance %s !! \n",
                        device->obd_name);
                 return 0;
         }
-        
-        return this_dev_root;
-        
 
+        return this_dev_root;
 }
 
 
-
-int lprocfs_get_idx(struct namespace_index* class, 
-                    const char* dir_name)
+int lprocfs_get_idx(struct namespace_index* class, const char* dir_name)
 {
-
         unsigned int index = 0;
         char temp_string[MAX_STRING_SIZE];
-        
-        /*
-         * First replace the string tokenizer with
-         * enum character
-         */
 
+        /* First replace the string tokenizer with enum character */
         memset(temp_string, 0, MAX_STRING_SIZE);
-        while(dir_name[index]!='\0' && index<MAX_STRING_SIZE){
-                if(dir_name[index]!=tok[0])
-                        temp_string[index]=dir_name[index];
+        while (dir_name[index]!='\0' && index < MAX_STRING_SIZE) {
+                if (dir_name[index] != tok[0])
+                        temp_string[index] = dir_name[index];
                 else
-                        temp_string[index]=enum_char;
+                        temp_string[index] = enum_char;
                 index++;
         }
-        temp_string[index]='\0';
-        
-        index=0;
-        while(class[index].name){
-                if(!strcmp(class[index].name, temp_string))
+        temp_string[index] = '\0';
+
+        index = 0;
+        while (class[index].name) {
+                if (!strcmp(class[index].name, temp_string))
                         return index;
                 index++;
-
         }
 
-        printk("No profiling for %s\n", temp_string);
+        CDEBUG(D_OTHER, "No profiling for %s\n", temp_string);
         return -1;
 }
 
-
-
-
-struct proc_dir_entry* lprocfs_mkdir(const char* dname, 
+struct proc_dir_entry* lprocfs_mkdir(const char* dname,
                                      struct proc_dir_entry *parent)
 {
-       struct proc_dir_entry *child_dir_entry;
-        
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) /*0x20300 */
-       child_dir_entry = proc_mkdir(dname, parent);
-#else
-       child_dir_entry = create_proc_entry(dname,
-                                           S_IFDIR | S_IRUGO | S_IXUGO,
-                                           &proc_root);
-#endif
-       if (!child_dir_entry)
+        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;
+
+        return child_dir_entry;
 }
 
-/* 
+/*
  * Create the variable struct entry for /proc. This will also
  * register the read/write function pointers with
- * /proc/lustre. 
+ * /proc/lustre.
  * Returns non-zero on success, zero on failure
  */
-
-unsigned int lprocfs_add_var(struct obd_device* device, 
-                             struct proc_dir_entry* root, 
-                             lprocfs_vars_t* variable, 
-                             int dir_idx, 
-                             int cnt_idx, 
-                             unsigned int sz, 
-                             lprofilers_e type 
-                             )
+unsigned int lprocfs_add_var(struct obd_device* device,
+                             struct proc_dir_entry* root,
+                             lprocfs_vars_t* variable, int dir_idx, int cnt_idx,
+                             unsigned int sz, lprofilers_e type)
 {
         struct proc_dir_entry* new_proc_entry;
         __u64* temp;
         unsigned int actual_idx;
         unsigned int blk_size;
-                       
-        new_proc_entry=create_proc_entry(variable->name, \
-                                         DEFAULT_MODE,
-                                         root);
-        if(!new_proc_entry) return LPROCFS_FAILURE;
-
-       
-        new_proc_entry->read_proc=variable->read_fptr;
-        new_proc_entry->write_proc=variable->write_fptr;
-       
+
+        new_proc_entry = create_proc_entry(variable->name, DEFAULT_MODE, root);
+        if (!new_proc_entry)
+                return LPROCFS_FAILURE;
+
+        new_proc_entry->read_proc = variable->read_fptr;
+        new_proc_entry->write_proc = variable->write_fptr;
+
         switch(type){
         case e_generic:
-                if(device->counters) {
-                        if(dir_idx!=-1 && cnt_idx!=-1){
-                                temp=(__u64*)device->counters;
-                                blk_size=((sz)/(sizeof(__u64)));
-                                actual_idx=(dir_idx*blk_size)+cnt_idx;
-                                temp+=actual_idx;
-                                new_proc_entry->data =(__u64*)temp;
+                if (device->counters) {
+                        if (dir_idx != -1 && cnt_idx != -1) {
+                                temp = (__u64*)device->counters;
+                                blk_size = ((sz) / (sizeof(__u64)));
+                                actual_idx = (dir_idx*blk_size) + cnt_idx;
+                                temp += actual_idx;
+                                new_proc_entry->data = (__u64*)temp;
                         }
                 }
                 break;
         case e_specific:
-
-
-                              
-                break;
+                 new_proc_entry->data = device;
+                 break;
         }
-        
-      
+
         return LPROCFS_SUCCESS;
 }
 
 
-
 /*
  * Tokenize name, based on tok and end-of-string. Create and return the
  * new directory entry. Set escape variable if the directory name contained
  * the escaping character (#)
  */
 
-struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root, 
-                                       const char* string,          
-                                       const char* tok,             
+struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
+                                       const char* string,
+                                       const char* tok,
                                        unsigned int* escape)
 {
-        struct proc_dir_entry* new_root=0;
-        struct proc_dir_entry* temp_entry=0;
-        struct proc_dir_entry* new_entry=0;
-        
-
+        struct proc_dir_entry* new_root = 0;
+        struct proc_dir_entry* temp_entry = 0;
+        struct proc_dir_entry* new_entry = 0;
         char temp_string[MAX_STRING_SIZE];
         char* my_str;
+        char* mover_str;
 
         /*
          * Remove trailing escaping character
          */
-
         memset(temp_string, 0, MAX_STRING_SIZE);
-        if(strlen(string)>= MAX_STRING_SIZE){
+        if (strlen(string) >= MAX_STRING_SIZE) {
                 CERROR("Directory namespace too long");
                 return 0;
-
         }
-        if(strchr(string, escape_char)!=NULL){
-                *escape=1;
-                strncpy(temp_string,string,strlen(string)-1);
-                temp_string[strlen(string)]='\0';
-                
+
+        if (strchr(string, escape_char)) {
+                *escape = 1;
+                strncpy(temp_string,string,strlen(string) - 1);
+                temp_string[strlen(string)] = '\0';
         } else {
-                *escape=0;
+                *escape = 0;
                 strcpy(temp_string, string);
-                temp_string[strlen(string)+1]='\0';
-
+                temp_string[strlen(string) + 1] = '\0';
         }
-        
-        my_str=strtok(temp_string, tok);
 
         new_root=root;
-        while(my_str!=NULL){
-                temp_entry=lprocfs_srch(new_root, my_str);
-                if(temp_entry==0){
-                        new_entry=lprocfs_mkdir(my_str, new_root);
-                        if(new_entry==0){
-                                CERROR("! Did not create new dir %s !!\n", \
+
+        /* Using strsep() instead */
+        mover_str=temp_string;
+        while ((my_str = strsep(&mover_str, tok))) {
+                if(!*my_str)
+                        continue;
+                temp_entry = lprocfs_srch(new_root, my_str);
+                if (temp_entry == 0) {
+                        new_entry = lprocfs_mkdir(my_str, new_root);
+                        if (new_entry == 0) {
+                                CERROR("! Did not create new dir %s !!\n",
                                        my_str);
                                 return 0;
-                                }
+                        }
                         return new_entry;
                 }
-                
-                new_root=temp_entry;
-                my_str=strtok(NULL, tok);
-                
+                new_root = temp_entry;
         }
+
         return new_root;
 }
 
-
-struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head, 
+struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head,
                                     const char* name)
 {
         struct proc_dir_entry* temp;
 
-        if(!head) return 0;
-        temp=head->subdir;
-        while(temp!=NULL){
-                if(!strcmp(temp->name, name))
+        if (!head)
+                return 0;
+        temp = head->subdir;
+        while (temp != NULL) {
+                if (!strcmp(temp->name, name))
                         return temp;
-                temp=temp->next;
+                temp = temp->next;
         }
-        return 0;
-} 
 
+        return 0;
+}
 
+#warning FIXME: recursive code is VERY bad in the kernel because of stack limit
+struct proc_dir_entry* lprocfs_bfs_srch(struct proc_dir_entry* root,
+                                        const char* name)
+{
+        struct proc_dir_entry* temp = root;
 
-struct proc_dir_entry* lprocfs_bfs_srch(struct proc_dir_entry* root, const char* name)
-{                                                          
-    
-        struct proc_dir_entry* temp=root;    
-        
-        if(!temp){
+        if (!temp)
                 return 0;
-        }
-        if(!strcmp(temp->name, name)){
+
+        if (!strcmp(temp->name, name))
                 return temp;
-        }
-        if((temp=lprocfs_bfs_srch(root->next, name))!=0){
+
+        if ((temp = lprocfs_bfs_srch(root->next, name)) != 0)
                 return temp;
-        }
-        if((temp=lprocfs_bfs_srch(root->subdir, name))!=0){
+
+        if ((temp = lprocfs_bfs_srch(root->subdir, name)) != 0)
                 return temp;
-        }
+
         return temp;
-} 
+}
 
-int  lprocfs_get_nm(char* name, \
-                    lprocfs_obd_nm_t* collection)
+int lprocfs_get_nm(char* name, lprocfs_obd_nm_t* collection)
 {
-        int i=0;
-        while(collection[i].obd_names!=0){
-                if(!strcmp(collection[i].obd_clname, name)){
+        int i = 0;
+        while (collection[i].obd_names != 0) {
+                if(!strcmp(collection[i].obd_clname, name))
                         return i;
-                }
                 i++;
         }
-        return -1;
 
+        return -1;
 }
 
-int lprocfs_dereg_dev (struct obd_device* device)
+int lprocfs_dereg_dev(struct obd_device* device)
 {
-
         struct proc_dir_entry* temp;
-        
-        
-        if(!device){
-                CERROR("!! Null pointer passed !!\n");
-                return LPROCFS_FAILURE;
+
+        CDEBUG(D_OTHER, "LPROCFS removing device = %s\n", \
+               device->obd_name);
+
+        if (!device) {
+                CDEBUG(D_OTHER, "! LProcfs:  Null pointer !\n");
+                return LPROCFS_SUCCESS;
         }
-        if(!(device->obd_name)){
+
+        if (!(device->obd_name)) {
                 CERROR(" !! Device does not have a name !! \n");
                 return LPROCFS_FAILURE;
-                
         }
-        printk("SEARCH: Device = %s\n", device->obd_name);
-        
-        temp=lprocfs_bfs_srch(proc_lustre_dev_root->subdir, \
-                              device->obd_name);
-        if(temp==0){
+
+        temp = lprocfs_bfs_srch(proc_lustre_dev_root->subdir, \
+                                device->obd_name);
+        if (temp == 0) {
                 CERROR("!! No root obtained, device does not exist !!\n");
                 return LPROCFS_FAILURE;
         }
-        
+
         lprocfs_remove_all(temp);
-        
+
         /*
          * Free the memory held by counters
          */
-        if(device->counters)
-                OBD_FREE(device->counters, 
-                         device->cntr_mem_size);
-        
-        
+        if (device->counters)
+                OBD_FREE(device->counters, device->cntr_mem_size);
+
+        CDEBUG(D_OTHER, "LPROCFS removed device = %s\n", \
+               device->obd_name);
+
         return LPROCFS_SUCCESS;
-           
-           
 }
 
 void lprocfs_remove_all(struct proc_dir_entry* root)
 {
-        if(root->subdir!=0)
+        if (root->subdir != 0)
                 lprocfs_remove_all(root->subdir);
-  
-       if(root->next!=0)
+
+        if (root->next != 0)
                 lprocfs_remove_all(root->next);
-        
-        if(root->parent!=0)
+
+        if (root->parent != 0)
                 remove_proc_entry(root->name, root->parent);
         else
                 remove_proc_entry(root->name, NULL);
-
 }
 
-
-int lprocfs_ll_rd(char* page, char **start, off_t off,
-                int count, int *eof, void *data)
+int rd_uuid(char* page, char **start, off_t off,
+            int count, int *eof, void *data)
 {
         int len;
-        __u64* temp=(__u64*)data;
-        
-        len=sprintf(page, "%lld\n", *temp);
-        
+        struct obd_device *temp = (struct obd_device *)data;
+
+        len = sprintf(page, "%s\n", temp->obd_uuid);
+
         return len;
 }
 
-int rd_other(char* page, char **start, off_t off,
-                int count, int *eof, void *data)
+int wr_uuid(struct file* file, const char *buffer,
+            unsigned long count, void *data)
+{
+
+        return 0;
+}
+
+int rd_blksize(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
 {
-  printk("Hello other");
-  return 0;
+        //int len=0;
+        //struct obd_device *temp = (struct obd_device *)data;
+
+        return 0;
 
 }
-int rd_string(char* page, char **start, off_t off,
-                int count, int *eof, void *data)
+int rd_blktotal(char* page, char **start, off_t off,
+                int count, int *eof, void *data)
 {
-  printk("Hello string");
-  return 0;
+        return 0;
 }
-int lprocfs_ll_wr(struct file* file, const char *buffer,
-                 unsigned long count, void *data)
+
+int rd_blkfree(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
 {
-  printk("Write default");
-  return 0;
+        return 0;
+}
 
+int rd_kbfree(char* page, char **start, off_t off,
+              int count, int *eof, void *data)
+{
+        return 0;
 }
 
-int wr_other(struct file* file, const char *buffer,
-                 unsigned long count, void *data)
+int rd_numobjects(char* page, char **start, off_t off,
+                  int count, int *eof, void *data)
 {
-  printk("Write other");
-  return 0;
+        return 0;
+}
 
+int rd_objfree(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
+{
+        return 0;
 }
 
-int wr_string(struct file* file, const char *buffer,
-                  unsigned long count, void *data)
+int rd_objgroups(char* page, char **start, off_t off,
+                 int count, int *eof, void *data)
 {
-        printk("Write string");
         return 0;
+}
+
 
+int lprocfs_ll_rd(char *page, char **start, off_t off,
+                  int count, int *eof, void *data)
+{
+        __u64 *temp = (__u64 *)data;
+        int len;
+
+        len = snprintf(page, count, LPU64"\n", *temp);
+
+        return len;
 }
 
-int lprocfs_reg_conn(unsigned int conn_number, 
-                          struct lprocfs_conn_namespace* namespace)
+int rd_fs_type(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
 {
         return 0;
 }
+
+int rd_other(char* page, char **start, off_t off, int count, int *eof,
+             void *data)
+{
+        return 0;
+}
+
+int rd_string(char* page, char **start, off_t off, int count, int *eof,
+              void *data)
+{
+        printk("Hello string");
+        return 0;
+}
+
+int lprocfs_ll_wr(struct file* file, const char *buffer, unsigned long count,
+                  void *data)
+{
+        return 0;
+}
+
+int wr_other(struct file* file, const char *buffer, unsigned long count,
+             void *data)
+{
+        return 0;
+}
+
+int wr_string(struct file* file, const char *buffer, unsigned long count,
+              void *data)
+{
+        return 0;
+}
+
+int lprocfs_reg_conn(unsigned int conn_number,
+                     struct lprocfs_conn_namespace* namespace)
+{
+        return 0;
+}
+
 int lprocfs_dereg_conn(unsigned int conn_number)
 {
         return 0;
@@ -999,25 +961,24 @@ int lprocfs_dereg_conn(unsigned int conn_number)
 /*
  * Import/Export APIs
  */
-int lprocfs_add_export(unsigned int conn_number, 
-                       struct obd_device* device)
+int lprocfs_add_export(unsigned int conn_number, struct obd_device* device)
 {
         return 0;
 }
-int lprocfs_add_import(unsigned int conn_number, 
-                       struct obd_device* device)
+
+int lprocfs_add_import(unsigned int conn_number, struct obd_device* device)
 {
         return 0;
 }
-int lprocfs_remove_export(unsigned int conn_number, 
-                          struct obd_device* device)
+
+int lprocfs_remove_export(unsigned int conn_number, struct obd_device* device)
 {
         return 0;
 }
-int lprocfs_remove_import(unsigned int conn_number, 
-                          struct obd_device* device)
+
+int lprocfs_remove_import(unsigned int conn_number, struct obd_device* device)
 {
         return 0;
 }
 
-#endif 
+#endif