Whamcloud - gitweb
Lproc-snmp code drop
[fs/lustre-release.git] / lustre / obdclass / lprocfs.c
index f5486f3..aef4b9b 100644 (file)
@@ -1,27 +1,22 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002 Intel Corporation
+ *  Copyright (C) 2002 Cluster File Systems, Inc.
  *
- */
-
-/*
- * Author: Hariharan Thantry
- * File Name: lprocfs.c
+ *   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.
  *
- * This code is issued under the GNU General Public License.
- * See the file COPYING in this distribution
+ *   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.
  *
- * 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
- * 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.
+ *   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.
  *
  */
 
 #include <linux/proc_fs.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/string.h>
 
 #define DEBUG_SUBSYSTEM S_CLASS
 #define MAX_STRING_SIZE 100
 
+
 #include <linux/obd_support.h>
 #include <linux/obd_class.h>
 #include <linux/lprocfs.h>
@@ -63,18 +60,16 @@ char escape_char = '%';
  * Externs
  */
 extern struct proc_dir_entry proc_root; /* Defined in proc/root.c */
-
+extern struct obd_type *class_nm_to_type(char *nm);
 
 /*
  * Globals
  */
+struct proc_dir_entry *proc_lustre_root = 0;
+struct proc_dir_entry *proc_lustre_dev_root = 0;
+
 
-static struct proc_dir_entry *proc_lustre_root = 0;
-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..";
 
 /*
  * Link the namespace with the internal array indices for
@@ -123,6 +118,13 @@ struct namespace_index dir_mds_index[] = {
         LPROCFS_DIR_INDEX(mds, reint_recreate),
 };
 
+struct namespace_index dir_mdt_index[] = {
+        LPROCFS_DIR_INDEX(mdt, mgmt_setup),
+        LPROCFS_DIR_INDEX(mdt, mgmt_cleanup),
+        LPROCFS_DIR_INDEX(mdt, mgmt_connect),
+        LPROCFS_DIR_INDEX(mdt, mgmt_disconnect),
+};
+
 struct namespace_index dir_osc_index[] = {
         LPROCFS_DIR_INDEX(osc, mgmt_setup),
         LPROCFS_DIR_INDEX(osc, mgmt_cleanup),
@@ -227,6 +229,13 @@ struct namespace_index prof_mds_index[]= {
         LPROCFS_CNTR_INDEX(mds, num_ops),
 };
 
+struct namespace_index prof_mdt_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[]= {
         LPROCFS_CNTR_INDEX(osc, min_time),
         LPROCFS_CNTR_INDEX(osc, max_time),
@@ -291,6 +300,7 @@ struct namespace_index prof_ptlrpc_index[] = {
 struct groupspace_index class_index[] = {
         LPROCFS_GROUP_CREATE(mdc),
         LPROCFS_GROUP_CREATE(mds),
+        LPROCFS_GROUP_CREATE(mdt),
         LPROCFS_GROUP_CREATE(osc),
         LPROCFS_GROUP_CREATE(ost),
         LPROCFS_GROUP_CREATE(lov),
@@ -300,14 +310,6 @@ struct groupspace_index class_index[] = {
 };
 
 
-/*
- *  API implementations
- */
-
-/*
- * lprocfs_reg_dev: Registers an instance of the OBD device in the
- *                       proc hierarchy
- */
 
 int lprocfs_reg_dev(struct obd_device* device, lprocfs_group_t* namespace,
                     unsigned int cnt_struct_size)
@@ -325,15 +327,16 @@ int lprocfs_reg_dev(struct obd_device* device, lprocfs_group_t* namespace,
                 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) {
-                CERROR("!! Could not find class !! \n");
+                CERROR("Could not find class for %s\n",
+                       device->obd_type->typ_name);
                 return LPROCFS_FAILURE;
         }
+        CDEBUG(D_OTHER, "Obtained the class array index\n");
 
         /* Create the directory namespace */
         retval = lprocfs_create_dir_namespace(this_dev_root, namespace,
@@ -477,7 +480,6 @@ int lprocfs_link_dir_counters(struct obd_device* device,
         return LPROCFS_SUCCESS;
 }
 
-
 int lprocfs_create_dir_namespace(struct proc_dir_entry* root,
                                  lprocfs_group_t* namespace,
                                  unsigned int *num_dirs)
@@ -490,7 +492,7 @@ int lprocfs_create_dir_namespace(struct proc_dir_entry* root,
 
         while (1) {
                 temp = &namespace[i];
-                if (temp->count_func_namespace == 0)
+                if (temp->count_func_namespace)
                         break;
                 while ((temp->dir_namespace)[j] != 0){
                         dir_root = lprocfs_add_dir(root,
@@ -513,13 +515,11 @@ int lprocfs_create_dir_namespace(struct proc_dir_entry* root,
 }
 
 
-
-
 int lprocfs_getclass_idx(struct groupspace_index* group, const char* classname)
 {
         unsigned int idx = 0;
 
-        while (group[idx].name != "") {
+        while (group[idx].name != NULL) {
                 if (!strcmp(group[idx].name, classname))
                         return idx;
                 idx++;
@@ -528,61 +528,6 @@ int lprocfs_getclass_idx(struct groupspace_index* group, const char* classname)
         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;
-        /*
-         * 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) {
-                        CERROR(" !! Cannot create /proc/lustre !! \n");
-                        return 0;
-                }
-                proc_lustre_dev_root =
-                        lprocfs_mkdir("devices", proc_lustre_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.
-         */
-
-        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",
-                               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("!Can't create proc entry for instance %s !! \n",
-                       device->obd_name);
-                return 0;
-        }
-
-        return this_dev_root;
-}
-
 
 
 int lprocfs_get_idx(struct namespace_index* class, const char* dir_name)
@@ -612,20 +557,17 @@ int lprocfs_get_idx(struct namespace_index* class, const char* dir_name)
         return -1;
 }
 
-
-
-
 struct proc_dir_entry* lprocfs_mkdir(const char* dname,
                                      struct proc_dir_entry *parent)
 {
-       struct proc_dir_entry *child_dir_entry;
+        struct proc_dir_entry *child_dir_entry;
 
-       child_dir_entry = proc_mkdir(dname, parent);
+        child_dir_entry = proc_mkdir(dname, parent);
 
-       if (!child_dir_entry)
+        if (!child_dir_entry)
                 CERROR("lustre: failed to create /proc entry %s\n", dname);
 
-       return child_dir_entry;
+        return child_dir_entry;
 }
 
 /*
@@ -634,7 +576,6 @@ struct proc_dir_entry* lprocfs_mkdir(const char* dname,
  * /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,
@@ -665,14 +606,14 @@ unsigned int lprocfs_add_var(struct obd_device* device,
                 }
                 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
@@ -689,6 +630,7 @@ struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
         struct proc_dir_entry* new_entry = 0;
         char temp_string[MAX_STRING_SIZE];
         char* my_str;
+        char* mover_str;
 
         /*
          * Remove trailing escaping character
@@ -699,7 +641,7 @@ struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
                 return 0;
         }
 
-        if (strchr(string, escape_char) != NULL) {
+        if (strchr(string, escape_char)) {
                 *escape = 1;
                 strncpy(temp_string,string,strlen(string) - 1);
                 temp_string[strlen(string)] = '\0';
@@ -709,10 +651,13 @@ struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
                 temp_string[strlen(string) + 1] = '\0';
         }
 
-        my_str = strtok(temp_string, tok);
-
         new_root=root;
-        while (my_str != NULL) {
+
+        /* 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);
@@ -723,52 +668,13 @@ struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
                         }
                         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,
-                                    const char* name)
-{
-        struct proc_dir_entry* temp;
-
-        if (!head)
-                return 0;
-        temp = head->subdir;
-        while (temp != NULL) {
-                if (!strcmp(temp->name, name))
-                        return temp;
-                temp = temp->next;
-        }
-        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;
-
-        if (!temp)
-                return 0;
-
-        if (!strcmp(temp->name, name))
-                return temp;
-
-        if ((temp = lprocfs_bfs_srch(root->next, name)) != 0)
-                return temp;
-
-        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 i = 0;
@@ -785,6 +691,8 @@ int lprocfs_dereg_dev(struct obd_device* device)
 {
         struct proc_dir_entry* temp;
 
+        CDEBUG(D_OTHER, "LPROCFS removing device = %s\n", device->obd_name);
+
         if (!device) {
                 CDEBUG(D_OTHER, "! LProcfs:  Null pointer !\n");
                 return LPROCFS_SUCCESS;
@@ -795,11 +703,9 @@ int lprocfs_dereg_dev(struct obd_device* device)
                 return LPROCFS_FAILURE;
         }
 
-        CDEBUG(D_OTHER, "SEARCH: Device = %s\n", device->obd_name);
-
         temp = lprocfs_bfs_srch(proc_lustre_dev_root->subdir, device->obd_name);
         if (temp == 0) {
-                CERROR("!! No root obtained, device does not exist !!\n");
+                CERROR("Device %s not in lprocfs\n", device->obd_name);
                 return LPROCFS_FAILURE;
         }
 
@@ -811,6 +717,8 @@ int lprocfs_dereg_dev(struct obd_device* device)
         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;
 }
@@ -829,22 +737,90 @@ void lprocfs_remove_all(struct proc_dir_entry* root)
                 remove_proc_entry(root->name, NULL);
 }
 
+int rd_uuid(char* page, char **start, off_t off,
+            int count, int *eof, void *data)
+{
+        int len;
+        struct obd_device *temp = (struct obd_device *)data;
+
+        len = sprintf(page, "%s\n", temp->obd_uuid);
+
+        return len;
+}
+
+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)
+{
+        //int len=0;
+        //struct obd_device *temp = (struct obd_device *)data;
+
+        return 0;
+
+}
+int rd_blktotal(char* page, char **start, off_t off,
+                int count, int *eof, void *data)
+{
+        return 0;
+}
+
+int rd_blkfree(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
+{
+        return 0;
+}
+
+int rd_kbfree(char* page, char **start, off_t off,
+              int count, int *eof, void *data)
+{
+        return 0;
+}
+
+int rd_numobjects(char* page, char **start, off_t off,
+                  int count, int *eof, void *data)
+{
+        return 0;
+}
+
+int rd_objfree(char* page, char **start, off_t off,
+               int count, int *eof, void *data)
+{
+        return 0;
+}
+
+int rd_objgroups(char* page, char **start, off_t off,
+                 int count, int *eof, void *data)
+{
+        return 0;
+}
+
 
 int lprocfs_ll_rd(char *page, char **start, off_t off,
                   int count, int *eof, void *data)
 {
-        int len;
         __u64 *temp = (__u64 *)data;
+        int len;
 
-        len = snprintf(page, count, "%Lu\n", *temp);
+        len = snprintf(page, count, LPU64"\n", *temp);
 
         return len;
 }
 
+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)
 {
-        printk("Hello other");
         return 0;
 }
 
@@ -858,21 +834,18 @@ int rd_string(char* page, char **start, off_t off, int count, int *eof,
 int lprocfs_ll_wr(struct file* file, const char *buffer, unsigned long count,
                   void *data)
 {
-        printk("Write default");
         return 0;
 }
 
 int wr_other(struct file* file, const char *buffer, unsigned long count,
              void *data)
 {
-        printk("Write other");
         return 0;
 }
 
 int wr_string(struct file* file, const char *buffer, unsigned long count,
               void *data)
 {
-        printk("Write string");
         return 0;
 }