Whamcloud - gitweb
- changes in error messages of seq and fld.
[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 /*
74  * Server side procfs stuff.
75  */
76 static int
77 seq_proc_read_common(char *page, char **start, off_t off,
78                      int count, int *eof, void *data,
79                      struct lu_range *range)
80 {
81         int rc;
82         ENTRY;
83
84         *eof = 1;
85         rc = snprintf(page, count, DRANGE"]\n",
86                       PRANGE(range));
87         RETURN(rc);
88 }
89
90 static int
91 seq_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_WARNING, "%s: Sequences space has "
105                        "changed to "DRANGE"\n", seq->lss_name,
106                        PRANGE(&seq->lss_space));
107         }
108         
109         up(&seq->lss_sem);
110         
111         RETURN(count);
112 }
113
114 static int
115 seq_proc_read_space(char *page, char **start, off_t off,
116                     int count, int *eof, void *data)
117 {
118         struct lu_server_seq *seq = (struct lu_server_seq *)data;
119         int rc;
120         ENTRY;
121
122         LASSERT(seq != NULL);
123
124         down(&seq->lss_sem);
125         rc = seq_proc_read_common(page, start, off, count, eof,
126                                   data, &seq->lss_space);
127         up(&seq->lss_sem);
128         
129         RETURN(rc);
130 }
131
132 static int
133 seq_proc_write_super(struct file *file, const char *buffer,
134                      unsigned long count, void *data)
135 {
136         struct lu_server_seq *seq = (struct lu_server_seq *)data;
137         int rc;
138         ENTRY;
139
140         LASSERT(seq != NULL);
141
142         down(&seq->lss_sem);
143         rc = seq_proc_write_common(file, buffer, count,
144                                    data, &seq->lss_super);
145
146         if (rc == 0) {
147                 CDEBUG(D_WARNING, "%s: Super has changed to "
148                        DRANGE"\n", seq->lss_name, PRANGE(&seq->lss_super));
149         }
150         
151         up(&seq->lss_sem);
152         
153         RETURN(count);
154 }
155
156 static int
157 seq_proc_read_super(char *page, char **start, off_t off,
158                     int count, int *eof, void *data)
159 {
160         struct lu_server_seq *seq = (struct lu_server_seq *)data;
161         int rc;
162         ENTRY;
163
164         LASSERT(seq != NULL);
165
166         down(&seq->lss_sem);
167         rc = seq_proc_read_common(page, start, off, count, eof,
168                                   data, &seq->lss_super);
169         up(&seq->lss_sem);
170         
171         RETURN(rc);
172 }
173
174 static int
175 seq_proc_read_controller(char *page, char **start, off_t off,
176                          int count, int *eof, void *data)
177 {
178         struct lu_server_seq *seq = (struct lu_server_seq *)data;
179         int rc;
180         ENTRY;
181
182         LASSERT(seq != NULL);
183
184         *eof = 1;
185         if (seq->lss_cli) {
186                 struct obd_export *exp = seq->lss_cli->lcs_exp;
187
188                 rc = snprintf(page, count, "%s\n",
189                               exp->exp_client_uuid.uuid);
190         } else {
191                 rc = snprintf(page, count, "<not assigned>\n");
192         }
193         
194         RETURN(rc);
195 }
196
197 static int
198 seq_proc_write_super_width(struct file *file, const char *buffer,
199                            unsigned long count, void *data)
200 {
201         struct lu_server_seq *seq = (struct lu_server_seq *)data;
202         int rc, val;
203         ENTRY;
204
205         LASSERT(seq != NULL);
206
207         down(&seq->lss_sem);
208
209         rc = lprocfs_write_helper(buffer, count, &val);
210         if (rc)
211                 RETURN(rc);
212
213         seq->lss_super_width = val;
214         
215         if (rc == 0) {
216                 CDEBUG(D_WARNING, "%s: Super width has changed to "
217                        LPU64"\n", seq->lss_name, seq->lss_super_width);
218         }
219         
220         up(&seq->lss_sem);
221         
222         RETURN(count);
223 }
224
225 static int
226 seq_proc_read_super_width(char *page, char **start, off_t off,
227                           int count, int *eof, void *data)
228 {
229         struct lu_server_seq *seq = (struct lu_server_seq *)data;
230         int rc;
231         ENTRY;
232
233         LASSERT(seq != NULL);
234
235         down(&seq->lss_sem);
236         rc = snprintf(page, count, LPU64"\n", seq->lss_super_width);
237         up(&seq->lss_sem);
238         
239         RETURN(rc);
240 }
241
242 static int
243 seq_proc_write_meta_width(struct file *file, const char *buffer,
244                           unsigned long count, void *data)
245 {
246         struct lu_server_seq *seq = (struct lu_server_seq *)data;
247         int rc, val;
248         ENTRY;
249
250         LASSERT(seq != NULL);
251
252         down(&seq->lss_sem);
253
254         rc = lprocfs_write_helper(buffer, count, &val);
255         if (rc)
256                 RETURN(rc);
257
258         if (val <= seq->lss_super_width) {
259                 seq->lss_meta_width = val;
260                 
261                 if (rc == 0) {
262                         CDEBUG(D_WARNING, "%s: Meta width has changed to "
263                                LPU64"\n", seq->lss_name, seq->lss_meta_width);
264                 }
265         }
266         
267         up(&seq->lss_sem);
268         RETURN(count);
269 }
270
271 static int
272 seq_proc_read_meta_width(char *page, char **start, off_t off,
273                          int count, int *eof, void *data)
274 {
275         struct lu_server_seq *seq = (struct lu_server_seq *)data;
276         int rc;
277         ENTRY;
278
279         LASSERT(seq != NULL);
280
281         down(&seq->lss_sem);
282         rc = snprintf(page, count, LPU64"\n", seq->lss_meta_width);
283         up(&seq->lss_sem);
284         
285         RETURN(rc);
286 }
287
288 /* client side procfs stuff */
289 static int
290 seq_proc_write_range(struct file *file, const char *buffer,
291                      unsigned long count, void *data)
292 {
293         struct lu_client_seq *seq = (struct lu_client_seq *)data;
294         int rc;
295         ENTRY;
296
297         LASSERT(seq != NULL);
298
299         down(&seq->lcs_sem);
300         rc = seq_proc_write_common(file, buffer, count,
301                                    data, &seq->lcs_range);
302
303         if (rc == 0) {
304                 CDEBUG(D_WARNING, "%s: Range has changed to "
305                        DRANGE"\n", seq->lcs_name, PRANGE(&seq->lcs_range));
306         }
307         
308         up(&seq->lcs_sem);
309         
310         RETURN(count);
311 }
312
313 static int
314 seq_proc_read_range(char *page, char **start, off_t off,
315                     int count, int *eof, void *data)
316 {
317         struct lu_client_seq *seq = (struct lu_client_seq *)data;
318         int rc;
319         ENTRY;
320
321         LASSERT(seq != NULL);
322
323         down(&seq->lcs_sem);
324         rc = seq_proc_read_common(page, start, off, count, eof,
325                                   data, &seq->lcs_range);
326         up(&seq->lcs_sem);
327         
328         RETURN(rc);
329 }
330
331 static int
332 seq_proc_write_seq_width(struct file *file, const char *buffer,
333                          unsigned long count, void *data)
334 {
335         struct lu_client_seq *seq = (struct lu_client_seq *)data;
336         int rc, val;
337         ENTRY;
338
339         LASSERT(seq != NULL);
340
341         down(&seq->lcs_sem);
342
343         rc = lprocfs_write_helper(buffer, count, &val);
344         if (rc)
345                 RETURN(rc);
346
347         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
348                 seq->lcs_width = val;
349                 
350                 if (rc == 0) {
351                         CDEBUG(D_WARNING, "%s: Sequence width "
352                                "has changed to "LPU64"\n",
353                                seq->lcs_name, seq->lcs_width);
354                 }
355         }
356         
357         up(&seq->lcs_sem);
358         
359         RETURN(count);
360 }
361
362 static int
363 seq_proc_read_seq_width(char *page, char **start, off_t off,
364                         int count, int *eof, void *data)
365 {
366         struct lu_client_seq *seq = (struct lu_client_seq *)data;
367         int rc;
368         ENTRY;
369
370         LASSERT(seq != NULL);
371
372         down(&seq->lcs_sem);
373         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
374         up(&seq->lcs_sem);
375         
376         RETURN(rc);
377 }
378
379 static int
380 seq_proc_read_next_fid(char *page, char **start, off_t off,
381                        int count, int *eof, void *data)
382 {
383         struct lu_client_seq *seq = (struct lu_client_seq *)data;
384         int rc;
385         ENTRY;
386
387         LASSERT(seq != NULL);
388
389         down(&seq->lcs_sem);
390         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
391         up(&seq->lcs_sem);
392         
393         RETURN(rc);
394 }
395
396 static int
397 seq_proc_read_server(char *page, char **start, off_t off,
398                      int count, int *eof, void *data)
399 {
400         struct lu_client_seq *seq = (struct lu_client_seq *)data;
401         struct client_obd *cli = &seq->lcs_exp->exp_obd->u.cli;
402         int rc;
403         ENTRY;
404
405         LASSERT(seq != NULL);
406         rc = snprintf(page, count, "%s\n",
407                       cli->cl_target_uuid.uuid);
408         RETURN(rc);
409 }
410
411 struct lprocfs_vars seq_server_proc_list[] = {
412         { "space",       seq_proc_read_space, seq_proc_write_space, NULL },
413         { "super",       seq_proc_read_super, seq_proc_write_super, NULL },
414         { "controller",  seq_proc_read_controller, NULL, NULL },
415         { "super_width", seq_proc_read_super_width, seq_proc_write_super_width, NULL },
416         { "meta_width",  seq_proc_read_meta_width, seq_proc_write_meta_width, NULL },
417         { NULL }};
418
419 struct lprocfs_vars seq_client_proc_list[] = {
420         { "range",       seq_proc_read_range, seq_proc_write_range, NULL },
421         { "server",      seq_proc_read_server, NULL, NULL },
422         { "next_fid" ,   seq_proc_read_next_fid, NULL, NULL },
423         { "seq_width",   seq_proc_read_seq_width, seq_proc_write_seq_width, NULL },
424         { NULL }};
425 #endif