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  *  lustre/fid/lproc_fid.c
5  *  Lustre Sequence Manager
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Yury Umanets <umka@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32 #define DEBUG_SUBSYSTEM S_FID
33
34 #ifdef __KERNEL__
35 # include <libcfs/libcfs.h>
36 # include <linux/module.h>
37 #else /* __KERNEL__ */
38 # include <liblustre.h>
39 #endif
40
41 #include <obd.h>
42 #include <obd_class.h>
43 #include <dt_object.h>
44 #include <md_object.h>
45 #include <obd_support.h>
46 #include <lustre_req_layout.h>
47 #include <lustre_fid.h>
48 #include "fid_internal.h"
49
50 #ifdef LPROCFS
51 /*
52  * Note: this function is only used for testing, it is no safe for production
53  * use.
54  */
55 static int
56 seq_proc_write_common(struct file *file, const char *buffer,
57                       unsigned long count, void *data,
58                       struct lu_range *range)
59 {
60         struct lu_range tmp;
61         int rc;
62         ENTRY;
63
64         LASSERT(range != NULL);
65
66         rc = sscanf(buffer, "[%Lx - %Lx]\n", &tmp.lr_start, &tmp.lr_end);
67         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
68                 RETURN(-EINVAL);
69         *range = tmp;
70         RETURN(0);
71 }
72
73 static int
74 seq_proc_read_common(char *page, char **start, off_t off,
75                      int count, int *eof, void *data,
76                      struct lu_range *range)
77 {
78         int rc;
79         ENTRY;
80
81         *eof = 1;
82         rc = snprintf(page, count, "[%Lx - %Lx]\n",
83                       PRANGE(range));
84         RETURN(rc);
85 }
86
87 /*
88  * Server side procfs stuff.
89  */
90 static int
91 seq_server_proc_write_space(struct file *file, const char *buffer,
92                             unsigned long count, void *data)
93 {
94         struct lu_server_seq *seq = (struct lu_server_seq *)data;
95         int rc;
96         ENTRY;
97
98         LASSERT(seq != NULL);
99
100         down(&seq->lss_sem);
101         rc = seq_proc_write_common(file, buffer, count,
102                                    data, &seq->lss_space);
103         if (rc == 0) {
104                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
105                        seq->lss_name, PRANGE(&seq->lss_space));
106         }
107         
108         up(&seq->lss_sem);
109         
110         RETURN(count);
111 }
112
113 static int
114 seq_server_proc_read_space(char *page, char **start, off_t off,
115                            int count, int *eof, void *data)
116 {
117         struct lu_server_seq *seq = (struct lu_server_seq *)data;
118         int rc;
119         ENTRY;
120
121         LASSERT(seq != NULL);
122
123         down(&seq->lss_sem);
124         rc = seq_proc_read_common(page, start, off, count, eof,
125                                   data, &seq->lss_space);
126         up(&seq->lss_sem);
127         
128         RETURN(rc);
129 }
130
131 static int
132 seq_server_proc_read_server(char *page, char **start, off_t off,
133                             int count, int *eof, void *data)
134 {
135         struct lu_server_seq *seq = (struct lu_server_seq *)data;
136         struct client_obd *cli;
137         int rc;
138         ENTRY;
139
140         LASSERT(seq != NULL);
141
142         *eof = 1;
143         if (seq->lss_cli) {
144                 if (seq->lss_cli->lcs_exp != NULL) {
145                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
146                         rc = snprintf(page, count, "%s\n",
147                                       cli->cl_target_uuid.uuid);
148                 } else {
149                         rc = snprintf(page, count, "%s\n",
150                                       seq->lss_cli->lcs_srv->lss_name);
151                 }
152         } else {
153                 rc = snprintf(page, count, "<none>\n");
154         }
155         
156         RETURN(rc);
157 }
158
159 static int
160 seq_server_proc_write_width(struct file *file, const char *buffer,
161                             unsigned long count, void *data)
162 {
163         struct lu_server_seq *seq = (struct lu_server_seq *)data;
164         int rc, val;
165         ENTRY;
166
167         LASSERT(seq != NULL);
168
169         down(&seq->lss_sem);
170
171         rc = lprocfs_write_helper(buffer, count, &val);
172         if (rc)
173                 RETURN(rc);
174
175         seq->lss_width = val;
176
177         if (rc == 0) {
178                 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
179                        seq->lss_name, seq->lss_width);
180         }
181         
182         up(&seq->lss_sem);
183         
184         RETURN(count);
185 }
186
187 static int
188 seq_server_proc_read_width(char *page, char **start, off_t off,
189                            int count, int *eof, void *data)
190 {
191         struct lu_server_seq *seq = (struct lu_server_seq *)data;
192         int rc;
193         ENTRY;
194
195         LASSERT(seq != NULL);
196
197         down(&seq->lss_sem);
198         rc = snprintf(page, count, LPU64"\n", seq->lss_width);
199         up(&seq->lss_sem);
200         
201         RETURN(rc);
202 }
203
204 /* Client side procfs stuff */
205 static int
206 seq_client_proc_write_space(struct file *file, const char *buffer,
207                             unsigned long count, void *data)
208 {
209         struct lu_client_seq *seq = (struct lu_client_seq *)data;
210         int rc;
211         ENTRY;
212
213         LASSERT(seq != NULL);
214
215         down(&seq->lcs_sem);
216         rc = seq_proc_write_common(file, buffer, count,
217                                    data, &seq->lcs_space);
218
219         if (rc == 0) {
220                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
221                        seq->lcs_name, PRANGE(&seq->lcs_space));
222         }
223         
224         up(&seq->lcs_sem);
225         
226         RETURN(count);
227 }
228
229 static int
230 seq_client_proc_read_space(char *page, char **start, off_t off,
231                            int count, int *eof, void *data)
232 {
233         struct lu_client_seq *seq = (struct lu_client_seq *)data;
234         int rc;
235         ENTRY;
236
237         LASSERT(seq != NULL);
238
239         down(&seq->lcs_sem);
240         rc = seq_proc_read_common(page, start, off, count, eof,
241                                   data, &seq->lcs_space);
242         up(&seq->lcs_sem);
243         
244         RETURN(rc);
245 }
246
247 static int
248 seq_client_proc_write_width(struct file *file, const char *buffer,
249                             unsigned long count, void *data)
250 {
251         struct lu_client_seq *seq = (struct lu_client_seq *)data;
252         int rc, val;
253         ENTRY;
254
255         LASSERT(seq != NULL);
256
257         down(&seq->lcs_sem);
258
259         rc = lprocfs_write_helper(buffer, count, &val);
260         if (rc)
261                 RETURN(rc);
262
263         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
264                 seq->lcs_width = val;
265
266                 if (rc == 0) {
267                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
268                                seq->lcs_name, seq->lcs_width);
269                 }
270         }
271         
272         up(&seq->lcs_sem);
273         
274         RETURN(count);
275 }
276
277 static int
278 seq_client_proc_read_width(char *page, char **start, off_t off,
279                            int count, int *eof, void *data)
280 {
281         struct lu_client_seq *seq = (struct lu_client_seq *)data;
282         int rc;
283         ENTRY;
284
285         LASSERT(seq != NULL);
286
287         down(&seq->lcs_sem);
288         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
289         up(&seq->lcs_sem);
290         
291         RETURN(rc);
292 }
293
294 static int
295 seq_client_proc_read_fid(char *page, char **start, off_t off,
296                          int count, int *eof, void *data)
297 {
298         struct lu_client_seq *seq = (struct lu_client_seq *)data;
299         int rc;
300         ENTRY;
301
302         LASSERT(seq != NULL);
303
304         down(&seq->lcs_sem);
305         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
306         up(&seq->lcs_sem);
307         
308         RETURN(rc);
309 }
310
311 static int
312 seq_client_proc_read_server(char *page, char **start, off_t off,
313                             int count, int *eof, void *data)
314 {
315         struct lu_client_seq *seq = (struct lu_client_seq *)data;
316         struct client_obd *cli;
317         int rc;
318         ENTRY;
319
320         LASSERT(seq != NULL);
321
322         if (seq->lcs_exp != NULL) {
323                 cli = &seq->lcs_exp->exp_obd->u.cli;
324                 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
325         } else {
326                 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
327         }
328         RETURN(rc);
329 }
330
331 struct lprocfs_vars seq_server_proc_list[] = {
332         { "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
333         { "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
334         { "server",   seq_server_proc_read_server, NULL, NULL },
335         { NULL }};
336
337 struct lprocfs_vars seq_client_proc_list[] = {
338         { "space",    seq_client_proc_read_space, seq_client_proc_write_space, NULL },
339         { "width",    seq_client_proc_read_width, seq_client_proc_write_width, NULL },
340         { "server",   seq_client_proc_read_server, NULL, NULL },
341         { "fid",      seq_client_proc_read_fid, NULL, NULL },
342         { NULL }};
343 #endif