Whamcloud - gitweb
b=19955
[fs/lustre-release.git] / lustre / mdc / lproc_mdc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <linux/vfs.h>
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <lustre_log.h>
43
44 #ifdef LPROCFS
45
46 static int mdc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
47                                      int count, int *eof, void *data)
48 {
49         struct obd_device *dev = data;
50         struct client_obd *cli = &dev->u.cli;
51         int rc;
52
53         client_obd_list_lock(&cli->cl_loi_list_lock);
54         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
55         client_obd_list_unlock(&cli->cl_loi_list_lock);
56         return rc;
57 }
58
59 static int mdc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
60                                      unsigned long count, void *data)
61 {
62         struct obd_device *dev = data;
63         struct client_obd *cli = &dev->u.cli;
64         int val, rc;
65
66         rc = lprocfs_write_helper(buffer, count, &val);
67         if (rc)
68                 return rc;
69
70         if (val < 1 || val > MDC_MAX_RIF_MAX)
71                 return -ERANGE;
72
73         client_obd_list_lock(&cli->cl_loi_list_lock);
74         cli->cl_max_rpcs_in_flight = val;
75         client_obd_list_unlock(&cli->cl_loi_list_lock);
76
77         return count;
78 }
79
80 static int mdc_changelog_seq_release(struct inode *inode, struct file *file)
81 {
82         struct seq_file *seq = file->private_data;
83         struct changelog_seq_iter *csi = seq->private;
84
85         if (csi && csi->csi_llh)
86                 llog_cat_put(csi->csi_llh);
87         if (csi && csi->csi_ctxt)
88                 llog_ctxt_put(csi->csi_ctxt);
89
90         return (changelog_seq_release(inode, file));
91 }
92
93 static int mdc_changelog_seq_open(struct inode *inode, struct file *file)
94 {
95         struct changelog_seq_iter *csi;
96         int rc;
97         ENTRY;
98
99         rc = changelog_seq_open(inode, file, &csi);
100         if (rc)
101                 RETURN(rc);
102
103         /* Set up the remote catalog handle */
104         /* Note the proc file is set up with obd in data, not mdc_device */
105         csi->csi_ctxt = llog_get_context((struct obd_device *)csi->csi_dev,
106                                          LLOG_CHANGELOG_REPL_CTXT);
107         if (csi->csi_ctxt == NULL)
108                 GOTO(out, rc = -ENOENT);
109         rc = llog_create(csi->csi_ctxt, &csi->csi_llh, NULL, CHANGELOG_CATALOG);
110         if (rc) {
111                 CERROR("llog_create() failed %d\n", rc);
112                 GOTO(out, rc);
113         }
114         rc = llog_init_handle(csi->csi_llh, LLOG_F_IS_CAT, NULL);
115         if (rc) {
116                 CERROR("llog_init_handle failed %d\n", rc);
117                 GOTO(out, rc);
118         }
119
120 out:
121         if (rc)
122                 mdc_changelog_seq_release(inode, file);
123         RETURN(rc);
124 }
125
126 static struct file_operations mdc_changelog_fops = {
127         .owner   = THIS_MODULE,
128         .open    = mdc_changelog_seq_open,
129         .read    = seq_read,
130         .llseek  = changelog_seq_lseek,
131         .release = mdc_changelog_seq_release,
132 };
133
134
135 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
136         { "uuid",            lprocfs_rd_uuid,        0, 0 },
137         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
138         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
139         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
140         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
141         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
142         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
143         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
144         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
145         /*{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },*/
146         { "mds_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
147         { "mds_conn_uuid",   lprocfs_rd_conn_uuid,   0, 0 },
148         { "max_rpcs_in_flight", mdc_rd_max_rpcs_in_flight,
149                                 mdc_wr_max_rpcs_in_flight, 0 },
150         { "timeouts",        lprocfs_rd_timeouts,    0, 0 },
151         { "import",          lprocfs_rd_import,      0, 0 },
152         { "state",           lprocfs_rd_state,       0, 0 },
153         { "changelog",       0, 0, 0, &mdc_changelog_fops, 0400 },
154         { 0 }
155 };
156
157 static struct lprocfs_vars lprocfs_mdc_module_vars[] = {
158         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
159         { 0 }
160 };
161
162 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
163 {
164     lvars->module_vars  = lprocfs_mdc_module_vars;
165     lvars->obd_vars     = lprocfs_mdc_obd_vars;
166 }
167 #endif /* LPROCFS */