Whamcloud - gitweb
b=21919 Do not resend quota_ctl requests
[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 struct lnl_hdr *changelog_lnl_alloc(int len, int flags)
81 {
82         struct lnl_hdr *lh;
83
84         OBD_ALLOC(lh, len);
85         if (lh == NULL)
86                 RETURN(NULL);
87
88         lh->lnl_magic = LNL_MAGIC;
89         lh->lnl_transport = LNL_TRANSPORT_CHANGELOG;
90         lh->lnl_flags = flags;
91         lh->lnl_msgtype = CL_RECORD;
92         lh->lnl_msglen = len;
93         return lh;
94 }
95
96 #define D_CHANGELOG 0
97
98 static int changelog_show_cb(struct llog_handle *llh, struct llog_rec_hdr *hdr,
99                              void *data)
100 {
101         struct changelog_show *cs = data;
102         struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
103         struct lnl_hdr *lh;
104         int len, rc;
105         ENTRY;
106
107         if ((rec->cr_hdr.lrh_type != CHANGELOG_REC) ||
108             (rec->cr.cr_type >= CL_LAST)) {
109                 CERROR("Not a changelog rec %d/%d\n", rec->cr_hdr.lrh_type,
110                        rec->cr.cr_type);
111                 RETURN(-EINVAL);
112         }
113
114         if (rec->cr.cr_index < cs->cs_startrec) {
115                 /* Skip entries earlier than what we are interested in */
116                 CDEBUG(D_CHANGELOG, "rec="LPU64" start="LPU64"\n",
117                        rec->cr.cr_index, cs->cs_startrec);
118                 RETURN(0);
119         }
120
121         CDEBUG(D_CHANGELOG, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID
122                " %.*s\n", rec->cr.cr_index, rec->cr.cr_type,
123                changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
124                rec->cr.cr_flags & CLF_FLAGMASK,
125                PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
126                rec->cr.cr_namelen, rec->cr.cr_name);
127
128         len = sizeof(*lh) + sizeof(rec->cr) + rec->cr.cr_namelen;
129
130         /* Set up the netlink message */
131         lh = changelog_lnl_alloc(len, cs->cs_flags);
132         if (lh == NULL)
133                 RETURN(-ENOMEM);
134         memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
135
136         rc = libcfs_klnl_msg_put(cs->cs_pid, 0, lh);
137         CDEBUG(D_CHANGELOG, "nlmsg pid %d len %d rc %d\n", cs->cs_pid, len, rc);
138
139         OBD_FREE(lh, len);
140
141         RETURN(rc);
142 }
143
144 static int lproc_mdc_wr_changelog(struct file *file, const char *buffer,
145                                   unsigned long count, void *data)
146 {
147         struct obd_device *obd = data;
148         struct llog_ctxt *ctxt;
149         struct llog_handle *llh;
150         struct lnl_hdr *lnlh;
151         struct changelog_show cs = {};
152         int rc;
153
154         if (count != sizeof(cs))
155                 return -EINVAL;
156
157         if (cfs_copy_from_user(&cs, buffer, sizeof(cs)))
158                 return -EFAULT;
159
160         CDEBUG(D_CHANGELOG, "changelog to pid=%d start "LPU64"\n",
161                cs.cs_pid, cs.cs_startrec);
162
163         /* Set up the remote catalog handle */
164         ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
165         if (ctxt == NULL)
166                 RETURN(-ENOENT);
167         rc = llog_create(ctxt, &llh, NULL, CHANGELOG_CATALOG);
168         if (rc) {
169                 CERROR("llog_create() failed %d\n", rc);
170                 GOTO(out, rc);
171         }
172         rc = llog_init_handle(llh, LLOG_F_IS_CAT, NULL);
173         if (rc) {
174                 CERROR("llog_init_handle failed %d\n", rc);
175                 GOTO(out, rc);
176         }
177
178         rc = llog_cat_process(llh, changelog_show_cb, &cs, 0, 0);
179
180         /* Send EOF */
181         if ((lnlh = changelog_lnl_alloc(sizeof(*lnlh), cs.cs_flags))) {
182                 lnlh->lnl_msgtype = CL_EOF;
183                 libcfs_klnl_msg_put(cs.cs_pid, 0, lnlh);
184                 OBD_FREE(lnlh, sizeof(*lnlh));
185         }
186
187 out:
188         if (llh)
189                 llog_cat_put(llh);
190         if (ctxt)
191                 llog_ctxt_put(ctxt);
192         if (rc < 0)
193                 return rc;
194         return count;
195 }
196
197 /* temporary for testing */
198 static int mdc_wr_netlink(struct file *file, const char *buffer,
199                           unsigned long count, void *data)
200 {
201         struct obd_device *obd = data;
202         struct lnl_hdr *lh;
203         struct hsm_action_list *hal;
204         struct hsm_action_item *hai;
205         int len;
206         int pid, rc;
207
208         rc = lprocfs_write_helper(buffer, count, &pid);
209         if (rc)
210                 return rc;
211
212         if (pid < 0)
213                 return -ERANGE;
214         CWARN("message to pid %d\n", pid);
215
216         len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
217                 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
218
219         OBD_ALLOC(lh, len);
220
221         lh->lnl_magic = LNL_MAGIC;
222         lh->lnl_transport = LNL_TRANSPORT_HSM;
223         lh->lnl_msgtype = HMT_ACTION_LIST;
224         lh->lnl_msglen = len;
225
226         hal = (struct hsm_action_list *)(lh + 1);
227         hal->hal_version = HAL_VERSION;
228         hal->hal_archive_num = 1;
229         obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);
230
231         /* mock up an action list */
232         hal->hal_count = 2;
233         hai = hai_zero(hal);
234         hai->hai_action = HSMA_ARCHIVE;
235         hai->hai_fid.f_oid = 5;
236         hai->hai_len = sizeof(*hai);
237         hai = hai_next(hai);
238         hai->hai_action = HSMA_RESTORE;
239         hai->hai_fid.f_oid = 10;
240         hai->hai_len = sizeof(*hai);
241
242         /* This works for either broadcast or unicast to a single pid */
243         rc = libcfs_klnl_msg_put(pid, pid == 0 ? LNL_GRP_HSM : 0, lh);
244
245         OBD_FREE(lh, len);
246         if (rc < 0)
247                 return rc;
248         return count;
249 }
250
251 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
252         { "uuid",            lprocfs_rd_uuid,        0, 0 },
253         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
254         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
255         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
256         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
257         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
258         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
259         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
260         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
261         /*{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },*/
262         { "mds_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
263         { "mds_conn_uuid",   lprocfs_rd_conn_uuid,   0, 0 },
264         { "max_rpcs_in_flight", mdc_rd_max_rpcs_in_flight,
265                                 mdc_wr_max_rpcs_in_flight, 0 },
266         { "timeouts",        lprocfs_rd_timeouts,    0, 0 },
267         { "import",          lprocfs_rd_import,      0, 0 },
268         { "state",           lprocfs_rd_state,       0, 0 },
269         { "changelog_trigger",0,lproc_mdc_wr_changelog, 0 },
270         { "hsm_nl",          0, mdc_wr_netlink,      0, 0, 0222 },
271         { 0 }
272 };
273
274 static struct lprocfs_vars lprocfs_mdc_module_vars[] = {
275         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
276         { 0 }
277 };
278
279 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
280 {
281     lvars->module_vars  = lprocfs_mdc_module_vars;
282     lvars->obd_vars     = lprocfs_mdc_obd_vars;
283 }
284 #endif /* LPROCFS */