Whamcloud - gitweb
Branch HEAD
[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
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  * 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_seq_range *range)
73 {
74         struct lu_seq_range tmp;
75         int rc;
76         ENTRY;
77
78         LASSERT(range != NULL);
79
80         rc = sscanf(buffer, "[%Lx - %Lx]\n",(long long unsigned *)&tmp.lsr_start,
81                     (long long unsigned *)&tmp.lsr_end);
82         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
83                 RETURN(-EINVAL);
84         *range = tmp;
85         RETURN(0);
86 }
87
88 static int
89 seq_proc_read_common(char *page, char **start, off_t off,
90                      int count, int *eof, void *data,
91                      struct lu_seq_range *range)
92 {
93         int rc;
94         ENTRY;
95
96         *eof = 1;
97         rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x\n",
98                       PRANGE(range));
99         RETURN(rc);
100 }
101
102 /*
103  * Server side procfs stuff.
104  */
105 static int
106 seq_server_proc_write_space(struct file *file, const char *buffer,
107                             unsigned long count, void *data)
108 {
109         struct lu_server_seq *seq = (struct lu_server_seq *)data;
110         int rc;
111         ENTRY;
112
113         LASSERT(seq != NULL);
114
115         down(&seq->lss_sem);
116         rc = seq_proc_write_common(file, buffer, count,
117                                    data, &seq->lss_space);
118         if (rc == 0) {
119                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
120                        seq->lss_name, PRANGE(&seq->lss_space));
121         }
122         
123         up(&seq->lss_sem);
124         
125         RETURN(count);
126 }
127
128 static int
129 seq_server_proc_read_space(char *page, char **start, off_t off,
130                            int count, int *eof, void *data)
131 {
132         struct lu_server_seq *seq = (struct lu_server_seq *)data;
133         int rc;
134         ENTRY;
135
136         LASSERT(seq != NULL);
137
138         down(&seq->lss_sem);
139         rc = seq_proc_read_common(page, start, off, count, eof,
140                                   data, &seq->lss_space);
141         up(&seq->lss_sem);
142         
143         RETURN(rc);
144 }
145
146 static int
147 seq_server_proc_read_server(char *page, char **start, off_t off,
148                             int count, int *eof, void *data)
149 {
150         struct lu_server_seq *seq = (struct lu_server_seq *)data;
151         struct client_obd *cli;
152         int rc;
153         ENTRY;
154
155         LASSERT(seq != NULL);
156
157         *eof = 1;
158         if (seq->lss_cli) {
159                 if (seq->lss_cli->lcs_exp != NULL) {
160                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
161                         rc = snprintf(page, count, "%s\n",
162                                       cli->cl_target_uuid.uuid);
163                 } else {
164                         rc = snprintf(page, count, "%s\n",
165                                       seq->lss_cli->lcs_srv->lss_name);
166                 }
167         } else {
168                 rc = snprintf(page, count, "<none>\n");
169         }
170         
171         RETURN(rc);
172 }
173
174 static int
175 seq_server_proc_write_width(struct file *file, const char *buffer,
176                             unsigned long count, void *data)
177 {
178         struct lu_server_seq *seq = (struct lu_server_seq *)data;
179         int rc, val;
180         ENTRY;
181
182         LASSERT(seq != NULL);
183
184         down(&seq->lss_sem);
185
186         rc = lprocfs_write_helper(buffer, count, &val);
187         if (rc)
188                 RETURN(rc);
189
190         seq->lss_width = val;
191
192         if (rc == 0) {
193                 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
194                        seq->lss_name, seq->lss_width);
195         }
196         
197         up(&seq->lss_sem);
198         
199         RETURN(count);
200 }
201
202 static int
203 seq_server_proc_read_width(char *page, char **start, off_t off,
204                            int count, int *eof, void *data)
205 {
206         struct lu_server_seq *seq = (struct lu_server_seq *)data;
207         int rc;
208         ENTRY;
209
210         LASSERT(seq != NULL);
211
212         down(&seq->lss_sem);
213         rc = snprintf(page, count, LPU64"\n", seq->lss_width);
214         up(&seq->lss_sem);
215         
216         RETURN(rc);
217 }
218
219 /* Client side procfs stuff */
220 static int
221 seq_client_proc_write_space(struct file *file, const char *buffer,
222                             unsigned long count, void *data)
223 {
224         struct lu_client_seq *seq = (struct lu_client_seq *)data;
225         int rc;
226         ENTRY;
227
228         LASSERT(seq != NULL);
229
230         down(&seq->lcs_sem);
231         rc = seq_proc_write_common(file, buffer, count,
232                                    data, &seq->lcs_space);
233
234         if (rc == 0) {
235                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
236                        seq->lcs_name, PRANGE(&seq->lcs_space));
237         }
238         
239         up(&seq->lcs_sem);
240         
241         RETURN(count);
242 }
243
244 static int
245 seq_client_proc_read_space(char *page, char **start, off_t off,
246                            int count, int *eof, void *data)
247 {
248         struct lu_client_seq *seq = (struct lu_client_seq *)data;
249         int rc;
250         ENTRY;
251
252         LASSERT(seq != NULL);
253
254         down(&seq->lcs_sem);
255         rc = seq_proc_read_common(page, start, off, count, eof,
256                                   data, &seq->lcs_space);
257         up(&seq->lcs_sem);
258         
259         RETURN(rc);
260 }
261
262 static int
263 seq_client_proc_write_width(struct file *file, const char *buffer,
264                             unsigned long count, void *data)
265 {
266         struct lu_client_seq *seq = (struct lu_client_seq *)data;
267         int rc, val;
268         ENTRY;
269
270         LASSERT(seq != NULL);
271
272         down(&seq->lcs_sem);
273
274         rc = lprocfs_write_helper(buffer, count, &val);
275         if (rc)
276                 RETURN(rc);
277
278         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
279                 seq->lcs_width = val;
280
281                 if (rc == 0) {
282                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
283                                seq->lcs_name, seq->lcs_width);
284                 }
285         }
286         
287         up(&seq->lcs_sem);
288         
289         RETURN(count);
290 }
291
292 static int
293 seq_client_proc_read_width(char *page, char **start, off_t off,
294                            int count, int *eof, void *data)
295 {
296         struct lu_client_seq *seq = (struct lu_client_seq *)data;
297         int rc;
298         ENTRY;
299
300         LASSERT(seq != NULL);
301
302         down(&seq->lcs_sem);
303         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
304         up(&seq->lcs_sem);
305         
306         RETURN(rc);
307 }
308
309 static int
310 seq_client_proc_read_fid(char *page, char **start, off_t off,
311                          int count, int *eof, void *data)
312 {
313         struct lu_client_seq *seq = (struct lu_client_seq *)data;
314         int rc;
315         ENTRY;
316
317         LASSERT(seq != NULL);
318
319         down(&seq->lcs_sem);
320         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
321         up(&seq->lcs_sem);
322         
323         RETURN(rc);
324 }
325
326 static int
327 seq_client_proc_read_server(char *page, char **start, off_t off,
328                             int count, int *eof, void *data)
329 {
330         struct lu_client_seq *seq = (struct lu_client_seq *)data;
331         struct client_obd *cli;
332         int rc;
333         ENTRY;
334
335         LASSERT(seq != NULL);
336
337         if (seq->lcs_exp != NULL) {
338                 cli = &seq->lcs_exp->exp_obd->u.cli;
339                 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
340         } else {
341                 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
342         }
343         RETURN(rc);
344 }
345
346 struct lprocfs_vars seq_server_proc_list[] = {
347         { "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
348         { "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
349         { "server",   seq_server_proc_read_server, NULL, NULL },
350         { NULL }};
351
352 struct lprocfs_vars seq_client_proc_list[] = {
353         { "space",    seq_client_proc_read_space, seq_client_proc_write_space, NULL },
354         { "width",    seq_client_proc_read_width, seq_client_proc_write_width, NULL },
355         { "server",   seq_client_proc_read_server, NULL, NULL },
356         { "fid",      seq_client_proc_read_fid, NULL, NULL },
357         { NULL }};
358 #endif