Whamcloud - gitweb
- landed b_hd_cray_merge3
[fs/lustre-release.git] / lustre / ost / lproc_ost.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_OST
23
24 #include <linux/obd_class.h>
25 #include <linux/lprocfs_status.h>
26 #include <linux/seq_file.h>
27
28 #ifndef LPROCFS
29 static struct lprocfs_vars lprocfs_obd_vars[]  = { {0} };
30 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
31 #else
32 static struct lprocfs_vars lprocfs_obd_vars[] = {
33         { "uuid",            lprocfs_rd_uuid,   0, 0 },
34         { 0 }
35 };
36
37 static struct lprocfs_vars lprocfs_module_vars[] = {
38         { "num_refs",       lprocfs_rd_numrefs, 0, 0 },
39         { 0 }
40 };
41
42 #define PRINTF_STIME(stime) (unsigned long)(stime)->st_num,     \
43         lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
44
45 static int ost_stimes_seq_show(struct seq_file *seq, void *v)
46 {
47         struct timeval now;
48         struct obd_device *dev = seq->private;
49         struct ost_obd *ost = &dev->u.ost;
50
51         do_gettimeofday(&now);
52
53         spin_lock(&ost->ost_lock);
54
55         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
56                    now.tv_sec, now.tv_usec);
57
58         seq_printf(seq, "\nread rpc service time: (rpcs, average ms)\n");
59         seq_printf(seq, "\tprep\t%lu\t%lu.%04lu\n",
60                         PRINTF_STIME(&ost->ost_stimes[0]));
61         seq_printf(seq, "\tbulk\t%lu\t%lu.%04lu\n\n",
62                         PRINTF_STIME(&ost->ost_stimes[1]));
63         seq_printf(seq, "\tcommit\t%lu\t%lu.%04lu\n\n",
64                         PRINTF_STIME(&ost->ost_stimes[2]));
65
66         seq_printf(seq, "\nwrite rpc service time: (rpcs, average ms)\n");
67         seq_printf(seq, "\tprep\t%lu\t%lu.%04lu\n",
68                         PRINTF_STIME(&ost->ost_stimes[3]));
69         seq_printf(seq, "\tbulk\t%lu\t%lu.%04lu\n\n",
70                         PRINTF_STIME(&ost->ost_stimes[4]));
71         seq_printf(seq, "\tcommit\t%lu\t%lu.%04lu\n\n",
72                         PRINTF_STIME(&ost->ost_stimes[5]));
73
74         spin_unlock(&ost->ost_lock);
75
76         return 0;
77 }
78
79 static void *ost_stimes_seq_start(struct seq_file *p, loff_t *pos)
80 {
81         if (*pos == 0)
82                 return (void *)1;
83         return NULL;
84 }
85 static void *ost_stimes_seq_next(struct seq_file *p, void *v, loff_t *pos)
86 {
87         ++*pos;
88         return NULL;
89 }
90 static void ost_stimes_seq_stop(struct seq_file *p, void *v)
91 {
92 }
93 struct seq_operations ost_stimes_seq_sops = {
94         .start = ost_stimes_seq_start,
95         .stop = ost_stimes_seq_stop,
96         .next = ost_stimes_seq_next,
97         .show = ost_stimes_seq_show,
98 };
99
100 static int ost_stimes_seq_open(struct inode *inode, struct file *file)
101 {
102         struct proc_dir_entry *dp = PDE(inode);
103         struct seq_file *seq;
104         int rc;
105
106         rc = seq_open(file, &ost_stimes_seq_sops);
107         if (rc)
108                 return rc;
109         seq = file->private_data;
110         seq->private = dp->data;
111         return 0;
112 }
113
114 static ssize_t ost_stimes_seq_write(struct file *file, const char *buf,
115                                        size_t len, loff_t *off)
116 {
117         struct seq_file *seq = file->private_data;
118         struct obd_device *dev = seq->private;
119         struct ost_obd *ost = &dev->u.ost;
120
121         spin_lock(&ost->ost_lock);
122         memset(&ost->ost_stimes, 0, sizeof(ost->ost_stimes));
123         spin_unlock(&ost->ost_lock);
124
125         return len;
126 }
127
128 struct file_operations ost_stimes_fops = {
129         .owner   = THIS_MODULE,
130         .open    = ost_stimes_seq_open,
131         .read    = seq_read,
132         .write   = ost_stimes_seq_write,
133         .llseek  = seq_lseek,
134         .release = seq_release,
135 };
136
137 #endif /* LPROCFS */
138 LPROCFS_INIT_VARS(ost, lprocfs_module_vars, lprocfs_obd_vars)