Whamcloud - gitweb
Lproc-snmp code drop
[fs/lustre-release.git] / lustre / obdecho / echo.c
index 5292cad..f310687 100644 (file)
  * and Andreas Dilger <adilger@clusterfs.com>
  */
 
-static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.30 2002/09/03 20:19:20 adilger Exp $";
-#define OBDECHO_VERSION "$Revision: 1.30 $"
+static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.42 2002/11/01 17:23:13 thantry Exp $";
+#define OBDECHO_VERSION "$Revision: 1.42 $"
 
 #define EXPORT_SYMTAB
 
 #include <linux/version.h>
 #include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/fs.h>
 #include <linux/stat.h>
-#include <linux/locks.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/ext2_fs.h>
 #include <linux/quotaops.h>
 #include <linux/proc_fs.h>
@@ -35,33 +38,28 @@ static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.30 2002/09/03 20:1
 #include <linux/obd_echo.h>
 #include <linux/lustre_debug.h>
 #include <linux/lustre_dlm.h>
+#include <linux/lprocfs_status.h>
 
-extern struct obd_device obd_dev[MAX_OBD_DEVICES];
+static atomic_t echo_page_rws;
+static atomic_t echo_getattrs;
 
 #define ECHO_PROC_STAT "sys/obdecho"
+#define ECHO_INIT_OBJID 0x1000000000000000ULL
+
+extern lprocfs_vars_t status_var_nm_1[];
+extern lprocfs_vars_t status_class_var[];
 
 int echo_proc_read(char *page, char **start, off_t off, int count, int *eof,
                    void *data)
 {
-        struct obd_device *obd;
-        long long attrs = 0;
-        long long pages = 0;
+        long long attrs = atomic_read(&echo_getattrs);
+        long long pages = atomic_read(&echo_page_rws);
         int len;
-        int i;
 
         *eof = 1;
         if (off != 0)
                 return (0);
 
-        for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++) {
-                if (strcmp(obd->obd_type->typ_name, OBD_ECHO_DEVICENAME))
-                        continue;
-                attrs += atomic_read(&obd->u.echo.eo_getattr) +
-                         atomic_read(&obd->u.echo.eo_setattr);
-                pages += atomic_read(&obd->u.echo.eo_read) +
-                         atomic_read(&obd->u.echo.eo_write);
-        }
-
         len = sprintf(page, "%Ld %Ld\n", attrs, pages);
 
         *start = page;
@@ -71,20 +69,9 @@ int echo_proc_read(char *page, char **start, off_t off, int count, int *eof,
 int echo_proc_write(struct file *file, const char *ubuffer,
                     unsigned long count, void *data)
 {
-        struct obd_device *obd;
-        int i;
-
-        for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++) {
-                if (strcmp(obd->obd_type->typ_name, OBD_ECHO_DEVICENAME))
-                        continue;
-
-                atomic_set(&obd->u.echo.eo_getattr, 0);
-                atomic_set(&obd->u.echo.eo_setattr, 0);
-                atomic_set(&obd->u.echo.eo_read, 0);
-                atomic_set(&obd->u.echo.eo_write, 0);
-        }
-
         /* Ignore what we've been asked to write, and just zero the counters */
+        atomic_set (&echo_page_rws, 0);
+        atomic_set (&echo_getattrs, 0);
 
         return (count);
 }
@@ -111,7 +98,8 @@ void echo_proc_fini(void)
 }
 
 static int echo_connect(struct lustre_handle *conn, struct obd_device *obd,
-                        char *cluuid)
+                        obd_uuid_t cluuid, struct recovd_obd *recovd,
+                        ptlrpc_recovery_cb_t recover)
 {
         int rc;
 
@@ -161,7 +149,7 @@ int echo_create(struct lustre_handle *conn, struct obdo *oa,
                 return -ENOENT;
         }
 
-        if (!(oa->o_valid & OBD_MD_FLMODE)) {
+        if (!(oa->o_valid & OBD_MD_FLTYPE)) {
                 CERROR("invalid o_valid %08x\n", oa->o_valid);
                 return -EINVAL;
         }
@@ -188,8 +176,8 @@ int echo_destroy(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
-        if (oa->o_id > obd->u.echo.eo_lastino) {
-                CERROR("bad destroy objid: %Ld\n", (long long)oa->o_id);
+        if (oa->o_id > obd->u.echo.eo_lastino || oa->o_id < ECHO_INIT_OBJID) {
+                CERROR("bad destroy objid: "LPX64"\n", oa->o_id);
                 RETURN(-EINVAL);
         }
 
@@ -198,6 +186,18 @@ int echo_destroy(struct lustre_handle *conn, struct obdo *oa,
         return 0;
 }
 
+static int echo_open(struct lustre_handle *conn, struct obdo *oa,
+                     struct lov_stripe_md *md)
+{
+        return 0;
+}
+
+static int echo_close(struct lustre_handle *conn, struct obdo *oa,
+                      struct lov_stripe_md *md)
+{
+        return 0;
+}
+
 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa,
                         struct lov_stripe_md *md)
 {
@@ -218,7 +218,7 @@ static int echo_getattr(struct lustre_handle *conn, struct obdo *oa,
         oa->o_id = id;
         oa->o_valid |= OBD_MD_FLID;
 
-        atomic_inc(&obd->u.echo.eo_getattr);
+        atomic_inc(&echo_getattrs);
 
         return 0;
 }
@@ -343,11 +343,9 @@ int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
         if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) {
                 CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n",
                        objcount, niocount);
-                atomic_inc(&obd->u.echo.eo_read);
         } else {
                 CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n",
                        objcount, niocount);
-                atomic_inc(&obd->u.echo.eo_write);
         }
 
         if (niocount && !r) {
@@ -373,7 +371,7 @@ int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
                                 GOTO(commitrw_cleanup, rc = -EFAULT);
                         }
 
-                        atomic_inc(&obd->u.echo.eo_read);
+                        atomic_inc(&echo_page_rws);
 
                         CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
                                r->page, addr, r->offset);
@@ -414,6 +412,8 @@ static int echo_setup(struct obd_device *obddev, obd_count len, void *buf)
                 LBUG();
                 RETURN(-ENOMEM);
         }
+        spin_lock_init(&obddev->u.echo.eo_lock);
+        obddev->u.echo.eo_lastino = ECHO_INIT_OBJID;
 
         RETURN(0);
 }
@@ -423,26 +423,38 @@ static int echo_cleanup(struct obd_device *obddev)
         ENTRY;
 
         ldlm_namespace_free(obddev->obd_namespace);
-        printk(KERN_INFO "%s: %u getattrs, %u setattrs\n", OBD_ECHO_DEVICENAME,
-               atomic_read(&obddev->u.echo.eo_getattr),
-               atomic_read(&obddev->u.echo.eo_setattr));
-        printk(KERN_INFO "%s: %u reads, %u writes (%d leaked)\n",
-               OBD_ECHO_DEVICENAME,
-               atomic_read(&obddev->u.echo.eo_read),
-               atomic_read(&obddev->u.echo.eo_write),
+        CERROR("%d prep/commitrw pages leaked\n",
                atomic_read(&obddev->u.echo.eo_prep));
-        printk(KERN_INFO "%s: %u creates, %u destroys\n", OBD_ECHO_DEVICENAME,
-               atomic_read(&obddev->u.echo.eo_create),
-               atomic_read(&obddev->u.echo.eo_destroy));
 
         RETURN(0);
 }
 
+int echo_attach(struct obd_device *dev, 
+                   obd_count len, void *data)
+{
+        int rc;
+        rc = lprocfs_reg_obd(dev, (lprocfs_vars_t*)status_var_nm_1, (void*)dev);
+        return rc; 
+}
+
+int echo_detach(struct obd_device *dev)
+{
+        int rc;
+        rc = lprocfs_dereg_obd(dev);
+        return rc;
+
+}
+
+
 struct obd_ops echo_obd_ops = {
+        o_attach:       echo_attach,
+        o_detach:       echo_detach,
         o_connect:      echo_connect,
         o_disconnect:   echo_disconnect,
         o_create:       echo_create,
         o_destroy:      echo_destroy,
+        o_open:         echo_open,
+        o_close:        echo_close,
         o_getattr:      echo_getattr,
         o_setattr:      echo_setattr,
         o_preprw:       echo_preprw,
@@ -453,16 +465,25 @@ struct obd_ops echo_obd_ops = {
 
 static int __init obdecho_init(void)
 {
+        int rc;
+        
+
         printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION
                " info@clusterfs.com\n");
 
         echo_proc_init();
+        rc = class_register_type(&echo_obd_ops, 
+                                 (lprocfs_vars_t*)status_class_var, 
+                                 OBD_ECHO_DEVICENAME);
+        if (rc) RETURN(rc);
+        
+        return 0;
 
-        return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
 }
 
 static void __exit obdecho_exit(void)
 {
+                
         echo_proc_fini();
 
         class_unregister_type(OBD_ECHO_DEVICENAME);