Whamcloud - gitweb
b=6063
[fs/lustre-release.git] / lustre / ost / lproc_ost.c
index 1fa1c59..beef27a 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (C) 2002 Cluster File Systems, Inc.
+ *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
  */
 #define DEBUG_SUBSYSTEM S_OST
 
-#include <linux/lustre_lite.h>
+#include <linux/obd_class.h>
 #include <linux/lprocfs_status.h>
+#include <linux/seq_file.h>
 
+#ifndef LPROCFS
+static struct lprocfs_vars lprocfs_obd_vars[]  = { {0} };
+static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
+#else
+static struct lprocfs_vars lprocfs_obd_vars[] = {
+        { "uuid",            lprocfs_rd_uuid,   0, 0 },
+        { 0 }
+};
+
+static struct lprocfs_vars lprocfs_module_vars[] = {
+        { "num_refs",       lprocfs_rd_numrefs, 0, 0 },
+        { 0 }
+};
+
+#define PRINTF_STIME(stime) (unsigned long)(stime)->st_num,     \
+        lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
 
-int rd_uuid(char* page, char **start, off_t off, int count, int *eof, 
-            void *data)
+static int ost_stimes_seq_show(struct seq_file *seq, void *v)
 {
-         
-        struct obd_device* temp = (struct obd_device*)data;
-        int len = 0;
-        len += snprintf(page, count, "%s\n", temp->obd_uuid); 
-        return len;
-        
+        struct timeval now;
+        struct obd_device *dev = seq->private;
+        struct ost_obd *ost = &dev->u.ost;
+
+        do_gettimeofday(&now);
+
+        spin_lock(&ost->ost_lock);
 
+        seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
+                   now.tv_sec, now.tv_usec);
+
+        seq_printf(seq, "\nread rpc service time: (rpcs, average ms)\n");
+        seq_printf(seq, "\tprep\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&ost->ost_stimes[0]));
+        seq_printf(seq, "\tbulk\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&ost->ost_stimes[1]));
+        seq_printf(seq, "\tcommit\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&ost->ost_stimes[2]));
+
+        seq_printf(seq, "\nwrite rpc service time: (rpcs, average ms)\n");
+        seq_printf(seq, "\tprep\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&ost->ost_stimes[3]));
+        seq_printf(seq, "\tbulk\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&ost->ost_stimes[4]));
+        seq_printf(seq, "\tcommit\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&ost->ost_stimes[5]));
+
+        spin_unlock(&ost->ost_lock);
+
+        return 0;
 }
-int rd_blksize(char* page, char **start, off_t off, int count, int *eof, 
-               void *data)
+
+static void *ost_stimes_seq_start(struct seq_file *p, loff_t *pos)
 {
-        
-        struct obd_device* temp = (struct obd_device*)data;
-        struct ost_obd *ost = &temp->u.ost;
-        struct lustre_handle *conn = &ost->ost_conn;
-        struct obd_statfs mystats;
-        int len = 0;
-        
-        obd_statfs(conn, &mystats);
-        len += snprintf(page, count, "%d\n", mystats.os_bsize); 
-        return len;
-        
+        if (*pos == 0)
+                return (void *)1;
+        return NULL;
 }
-int rd_kbtotal(char* page, char **start, off_t off, int count, int *eof, 
-               void *data)
+static void *ost_stimes_seq_next(struct seq_file *p, void *v, loff_t *pos)
 {
-        struct obd_device* temp = (struct obd_device*)data;
-        struct ost_obd *ost = &temp->u.ost;
-        struct lustre_handle *conn = &ost->ost_conn;
-        struct obd_statfs mystats;
-        int len = 0;
-        __u32 blk_size;
-        __u64 result;
-                
-        obd_statfs(conn, &mystats);
-        blk_size = mystats.os_bsize;
-        blk_size >>= 10;
-        result = mystats.os_blocks;
-        while(blk_size >>= 1){
-                result <<= 1;
-        }
-        len += snprintf(page, count, LPU64"\n", result);
-        return len;
-                
+        ++*pos;
+        return NULL;
 }
-
-
-int rd_kbfree(char* page, char **start, off_t off, int count, int *eof, 
-              void *data)
+static void ost_stimes_seq_stop(struct seq_file *p, void *v)
 {
-        
-        struct obd_device* temp = (struct obd_device*)data;
-        struct ost_obd *ost = &temp->u.ost;
-        struct lustre_handle *conn = &ost->ost_conn;
-        struct obd_statfs mystats;
-        int len = 0;
-        __u32 blk_size;
-        __u64 result;
-
-        obd_statfs(conn, &mystats);
-        blk_size = mystats.os_bsize;
-        blk_size >>= 10;
-        result = mystats.os_bfree;
-        while(blk_size >>= 1){
-                result <<= 1;
-        }
-        len += snprintf(page, count, LPU64"\n", result);
-        return len;  
 }
+struct seq_operations ost_stimes_seq_sops = {
+        .start = ost_stimes_seq_start,
+        .stop = ost_stimes_seq_stop,
+        .next = ost_stimes_seq_next,
+        .show = ost_stimes_seq_show,
+};
 
-int rd_filestotal(char* page, char **start, off_t off, int count, int *eof, 
-                  void *data)
+static int ost_stimes_seq_open(struct inode *inode, struct file *file)
 {
-        struct obd_device* temp = (struct obd_device*)data;
-        struct ost_obd *ost = &temp->u.ost;
-        struct lustre_handle *conn = &ost->ost_conn;
-        struct obd_statfs mystats;
-        int len = 0;
-        
-        obd_statfs(conn, &mystats);
-        len += snprintf(page, count, LPU64"\n",mystats.os_files); 
-        return len;
-        
-}
+        struct proc_dir_entry *dp = PDE(inode);
+        struct seq_file *seq;
+        int rc;
 
-int rd_filesfree(char* page, char **start, off_t off, int count, int *eof, 
-                 void *data)
-{
-        
-        struct obd_device* temp = (struct obd_device*)data;
-        struct ost_obd *ost = &temp->u.ost;
-        struct lustre_handle *conn = &ost->ost_conn;
-        struct obd_statfs mystats;
-        int len = 0;
-        
-        obd_statfs(conn, &mystats);
-        len += snprintf(page, count, LPU64"\n", mystats.os_ffree); 
-        return len;
-        
+        rc = seq_open(file, &ost_stimes_seq_sops);
+        if (rc)
+                return rc;
+        seq = file->private_data;
+        seq->private = dp->data;
+        return 0;
 }
 
-int rd_filegroups(char* page, char **start, off_t off, int count, int *eof, 
-                  void *data)
+static ssize_t ost_stimes_seq_write(struct file *file, const char *buf,
+                                       size_t len, loff_t *off)
 {
-        return 0;
-}
+        struct seq_file *seq = file->private_data;
+        struct obd_device *dev = seq->private;
+        struct ost_obd *ost = &dev->u.ost;
 
-struct lprocfs_vars status_var_nm_1[] = {
-        {"status/uuid", rd_uuid, 0, 0},
-        {"status/blocksize",rd_blksize, 0, 0},
-        {"status/kbytesfree", rd_kbfree, 0, 0},
-        {"status/kbytestotal", rd_kbtotal, 0, 0},
-        {"status/filestotal", rd_filestotal, 0, 0},
-        {"status/filesfree", rd_filesfree, 0, 0},
-        {"status/filegroups", rd_filegroups, 0, 0},
-        {0}
-};
+        spin_lock(&ost->ost_lock);
+        memset(&ost->ost_stimes, 0, sizeof(ost->ost_stimes));
+        spin_unlock(&ost->ost_lock);
 
-int rd_numrefs(char* page, char **start, off_t off, int count, int *eof, 
-               void *data)
-{
-        struct obd_type* class = (struct obd_type*)data;
-        int len = 0;
-        len += snprintf(page, count, "%d\n", class->typ_refcnt);
         return len;
 }
 
-struct lprocfs_vars status_class_var[] = {
-        {"status/num_refs", rd_numrefs, 0, 0},
-        {0}
+struct file_operations ost_stimes_fops = {
+        .owner   = THIS_MODULE,
+        .open    = ost_stimes_seq_open,
+        .read    = seq_read,
+        .write   = ost_stimes_seq_write,
+        .llseek  = seq_lseek,
+        .release = seq_release,
 };
+
+#endif /* LPROCFS */
+LPROCFS_INIT_VARS(ost, lprocfs_module_vars, lprocfs_obd_vars)