Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / fid / lproc_fid.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 [sun.com URL with a
20  * copy of GPLv2].
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  * lustre/fid/lproc_fid.c
37  *
38  * Lustre Sequence Manager
39  *
40  * Author: Yury Umanets <umka@clusterfs.com>
41  */
42
43 #ifndef EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #define DEBUG_SUBSYSTEM S_FID
47
48 #ifdef __KERNEL__
49 # include <libcfs/libcfs.h>
50 # include <linux/module.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
53 #endif
54
55 #include <obd.h>
56 #include <obd_class.h>
57 #include <dt_object.h>
58 #include <md_object.h>
59 #include <obd_support.h>
60 #include <lustre_req_layout.h>
61 #include <lustre_fid.h>
62 #include "fid_internal.h"
63
64 #ifdef LPROCFS
65 /*
66  * Note: this function is only used for testing, it is no safe for production
67  * use.
68  */
69 static int
70 seq_proc_write_common(struct file *file, const char *buffer,
71                       unsigned long count, void *data,
72                       struct lu_range *range)
73 {
74         struct lu_range tmp;
75         int rc;
76         ENTRY;
77
78         LASSERT(range != NULL);
79
80         rc = sscanf(buffer, "[%Lx - %Lx]\n", &tmp.lr_start, &tmp.lr_end);
81         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
82                 RETURN(-EINVAL);
83         *range = tmp;
84         RETURN(0);
85 }
86
87 static int
88 seq_proc_read_common(char *page, char **start, off_t off,
89                      int count, int *eof, void *data,
90                      struct lu_range *range)
91 {
92         int rc;
93         ENTRY;
94
95         *eof = 1;
96         rc = snprintf(page, count, "[%Lx - %Lx]\n",
97                       PRANGE(range));
98         RETURN(rc);
99 }
100
101 /*
102  * Server side procfs stuff.
103  */
104 static int
105 seq_server_proc_write_space(struct file *file, const char *buffer,
106                             unsigned long count, void *data)
107 {
108         struct lu_server_seq *seq = (struct lu_server_seq *)data;
109         int rc;
110         ENTRY;
111
112         LASSERT(seq != NULL);
113
114         down(&seq->lss_sem);
115         rc = seq_proc_write_common(file, buffer, count,
116                                    data, &seq->lss_space);
117         if (rc == 0) {
118                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
119                        seq->lss_name, PRANGE(&seq->lss_space));
120         }
121         
122         up(&seq->lss_sem);
123         
124         RETURN(count);
125 }
126
127 static int
128 seq_server_proc_read_space(char *page, char **start, off_t off,
129                            int count, int *eof, void *data)
130 {
131         struct lu_server_seq *seq = (struct lu_server_seq *)data;
132         int rc;
133         ENTRY;
134
135         LASSERT(seq != NULL);
136
137         down(&seq->lss_sem);
138         rc = seq_proc_read_common(page, start, off, count, eof,
139                                   data, &seq->lss_space);
140         up(&seq->lss_sem);
141         
142         RETURN(rc);
143 }
144
145 static int
146 seq_server_proc_read_server(char *page, char **start, off_t off,
147                             int count, int *eof, void *data)
148 {
149         struct lu_server_seq *seq = (struct lu_server_seq *)data;
150         struct client_obd *cli;
151         int rc;
152         ENTRY;
153
154         LASSERT(seq != NULL);
155
156         *eof = 1;
157         if (seq->lss_cli) {
158                 if (seq->lss_cli->lcs_exp != NULL) {
159                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
160                         rc = snprintf(page, count, "%s\n",
161                                       cli->cl_target_uuid.uuid);
162                 } else {
163                         rc = snprintf(page, count, "%s\n",
164                                       seq->lss_cli->lcs_srv->lss_name);
165                 }
166         } else {
167                 rc = snprintf(page, count, "<none>\n");
168         }
169         
170         RETURN(rc);
171 }
172
173 static int
174 seq_server_proc_write_width(struct file *file, const char *buffer,
175                             unsigned long count, void *data)
176 {
177         struct lu_server_seq *seq = (struct lu_server_seq *)data;
178         int rc, val;
179         ENTRY;
180
181         LASSERT(seq != NULL);
182
183         down(&seq->lss_sem);
184
185         rc = lprocfs_write_helper(buffer, count, &val);
186         if (rc)
187                 RETURN(rc);
188
189         seq->lss_width = val;
190
191         if (rc == 0) {
192                 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
193                        seq->lss_name, seq->lss_width);
194         }
195         
196         up(&seq->lss_sem);
197         
198         RETURN(count);
199 }
200
201 static int
202 seq_server_proc_read_width(char *page, char **start, off_t off,
203                            int count, int *eof, void *data)
204 {
205         struct lu_server_seq *seq = (struct lu_server_seq *)data;
206         int rc;
207         ENTRY;
208
209         LASSERT(seq != NULL);
210
211         down(&seq->lss_sem);
212         rc = snprintf(page, count, LPU64"\n", seq->lss_width);
213         up(&seq->lss_sem);
214         
215         RETURN(rc);
216 }
217
218 /* Client side procfs stuff */
219 static int
220 seq_client_proc_write_space(struct file *file, const char *buffer,
221                             unsigned long count, void *data)
222 {
223         struct lu_client_seq *seq = (struct lu_client_seq *)data;
224         int rc;
225         ENTRY;
226
227         LASSERT(seq != NULL);
228
229         down(&seq->lcs_sem);
230         rc = seq_proc_write_common(file, buffer, count,
231                                    data, &seq->lcs_space);
232
233         if (rc == 0) {
234                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
235                        seq->lcs_name, PRANGE(&seq->lcs_space));
236         }
237         
238         up(&seq->lcs_sem);
239         
240         RETURN(count);
241 }
242
243 static int
244 seq_client_proc_read_space(char *page, char **start, off_t off,
245                            int count, int *eof, void *data)
246 {
247         struct lu_client_seq *seq = (struct lu_client_seq *)data;
248         int rc;
249         ENTRY;
250
251         LASSERT(seq != NULL);
252
253         down(&seq->lcs_sem);
254         rc = seq_proc_read_common(page, start, off, count, eof,
255                                   data, &seq->lcs_space);
256         up(&seq->lcs_sem);
257         
258         RETURN(rc);
259 }
260
261 static int
262 seq_client_proc_write_width(struct file *file, const char *buffer,
263                             unsigned long count, void *data)
264 {
265         struct lu_client_seq *seq = (struct lu_client_seq *)data;
266         int rc, val;
267         ENTRY;
268
269         LASSERT(seq != NULL);
270
271         down(&seq->lcs_sem);
272
273         rc = lprocfs_write_helper(buffer, count, &val);
274         if (rc)
275                 RETURN(rc);
276
277         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
278                 seq->lcs_width = val;
279
280                 if (rc == 0) {
281                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
282                                seq->lcs_name, seq->lcs_width);
283                 }
284         }
285         
286         up(&seq->lcs_sem);
287         
288         RETURN(count);
289 }
290
291 static int
292 seq_client_proc_read_width(char *page, char **start, off_t off,
293                            int count, int *eof, void *data)
294 {
295         struct lu_client_seq *seq = (struct lu_client_seq *)data;
296         int rc;
297         ENTRY;
298
299         LASSERT(seq != NULL);
300
301         down(&seq->lcs_sem);
302         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
303         up(&seq->lcs_sem);
304         
305         RETURN(rc);
306 }
307
308 static int
309 seq_client_proc_read_fid(char *page, char **start, off_t off,
310                          int count, int *eof, void *data)
311 {
312         struct lu_client_seq *seq = (struct lu_client_seq *)data;
313         int rc;
314         ENTRY;
315
316         LASSERT(seq != NULL);
317
318         down(&seq->lcs_sem);
319         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
320         up(&seq->lcs_sem);
321         
322         RETURN(rc);
323 }
324
325 static int
326 seq_client_proc_read_server(char *page, char **start, off_t off,
327                             int count, int *eof, void *data)
328 {
329         struct lu_client_seq *seq = (struct lu_client_seq *)data;
330         struct client_obd *cli;
331         int rc;
332         ENTRY;
333
334         LASSERT(seq != NULL);
335
336         if (seq->lcs_exp != NULL) {
337                 cli = &seq->lcs_exp->exp_obd->u.cli;
338                 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
339         } else {
340                 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
341         }
342         RETURN(rc);
343 }
344
345 struct lprocfs_vars seq_server_proc_list[] = {
346         { "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
347         { "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
348         { "server",   seq_server_proc_read_server, NULL, NULL },
349         { NULL }};
350
351 struct lprocfs_vars seq_client_proc_list[] = {
352         { "space",    seq_client_proc_read_space, seq_client_proc_write_space, NULL },
353         { "width",    seq_client_proc_read_width, seq_client_proc_write_width, NULL },
354         { "server",   seq_client_proc_read_server, NULL, NULL },
355         { "fid",      seq_client_proc_read_fid, NULL, NULL },
356         { NULL }};
357 #endif