Whamcloud - gitweb
956358ed9fd430887e096f5ca47cee4087a3e51e
[fs/lustre-release.git] / lustre / fid / lproc_fid.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Whamcloud, Inc.
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, "[%llx - %llx]\n",
81                     (long long unsigned *)&tmp.lsr_start,
82                     (long long unsigned *)&tmp.lsr_end);
83         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
84                 RETURN(-EINVAL);
85         *range = tmp;
86         RETURN(0);
87 }
88
89 static int
90 seq_proc_read_common(char *page, char **start, off_t off,
91                      int count, int *eof, void *data,
92                      struct lu_seq_range *range)
93 {
94         int rc;
95         ENTRY;
96
97         *eof = 1;
98         rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
99                       PRANGE(range));
100         RETURN(rc);
101 }
102
103 /*
104  * Server side procfs stuff.
105  */
106 static int
107 seq_server_proc_write_space(struct file *file, const char *buffer,
108                             unsigned long count, void *data)
109 {
110         struct lu_server_seq *seq = (struct lu_server_seq *)data;
111         int rc;
112         ENTRY;
113
114         LASSERT(seq != NULL);
115
116         cfs_mutex_lock(&seq->lss_mutex);
117         rc = seq_proc_write_common(file, buffer, count,
118                                    data, &seq->lss_space);
119         if (rc == 0) {
120                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
121                        seq->lss_name, PRANGE(&seq->lss_space));
122         }
123
124         cfs_mutex_unlock(&seq->lss_mutex);
125
126         RETURN(count);
127 }
128
129 static int
130 seq_server_proc_read_space(char *page, char **start, off_t off,
131                            int count, int *eof, void *data)
132 {
133         struct lu_server_seq *seq = (struct lu_server_seq *)data;
134         int rc;
135         ENTRY;
136
137         LASSERT(seq != NULL);
138
139         cfs_mutex_lock(&seq->lss_mutex);
140         rc = seq_proc_read_common(page, start, off, count, eof,
141                                   data, &seq->lss_space);
142         cfs_mutex_unlock(&seq->lss_mutex);
143
144         RETURN(rc);
145 }
146
147 static int
148 seq_server_proc_read_server(char *page, char **start, off_t off,
149                             int count, int *eof, void *data)
150 {
151         struct lu_server_seq *seq = (struct lu_server_seq *)data;
152         struct client_obd *cli;
153         int rc;
154         ENTRY;
155
156         LASSERT(seq != NULL);
157
158         *eof = 1;
159         if (seq->lss_cli) {
160                 if (seq->lss_cli->lcs_exp != NULL) {
161                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
162                         rc = snprintf(page, count, "%s\n",
163                                       cli->cl_target_uuid.uuid);
164                 } else {
165                         rc = snprintf(page, count, "%s\n",
166                                       seq->lss_cli->lcs_srv->lss_name);
167                 }
168         } else {
169                 rc = snprintf(page, count, "<none>\n");
170         }
171
172         RETURN(rc);
173 }
174
175 static int
176 seq_server_proc_write_width(struct file *file, const char *buffer,
177                             unsigned long count, void *data)
178 {
179         struct lu_server_seq *seq = (struct lu_server_seq *)data;
180         int rc, val;
181         ENTRY;
182
183         LASSERT(seq != NULL);
184
185         cfs_mutex_lock(&seq->lss_mutex);
186
187         rc = lprocfs_write_helper(buffer, count, &val);
188         if (rc)
189                 RETURN(rc);
190
191         seq->lss_width = val;
192
193         if (rc == 0) {
194                 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
195                        seq->lss_name, seq->lss_width);
196         }
197
198         cfs_mutex_unlock(&seq->lss_mutex);
199
200         RETURN(count);
201 }
202
203 static int
204 seq_server_proc_read_width(char *page, char **start, off_t off,
205                            int count, int *eof, void *data)
206 {
207         struct lu_server_seq *seq = (struct lu_server_seq *)data;
208         int rc;
209         ENTRY;
210
211         LASSERT(seq != NULL);
212
213         cfs_mutex_lock(&seq->lss_mutex);
214         rc = snprintf(page, count, LPU64"\n", seq->lss_width);
215         cfs_mutex_unlock(&seq->lss_mutex);
216
217         RETURN(rc);
218 }
219
220 /* Client side procfs stuff */
221 static int
222 seq_client_proc_write_space(struct file *file, const char *buffer,
223                             unsigned long count, void *data)
224 {
225         struct lu_client_seq *seq = (struct lu_client_seq *)data;
226         int rc;
227         ENTRY;
228
229         LASSERT(seq != NULL);
230
231         cfs_mutex_lock(&seq->lcs_mutex);
232         rc = seq_proc_write_common(file, buffer, count,
233                                    data, &seq->lcs_space);
234
235         if (rc == 0) {
236                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
237                        seq->lcs_name, PRANGE(&seq->lcs_space));
238         }
239
240         cfs_mutex_unlock(&seq->lcs_mutex);
241
242         RETURN(count);
243 }
244
245 static int
246 seq_client_proc_read_space(char *page, char **start, off_t off,
247                            int count, int *eof, void *data)
248 {
249         struct lu_client_seq *seq = (struct lu_client_seq *)data;
250         int rc;
251         ENTRY;
252
253         LASSERT(seq != NULL);
254
255         cfs_mutex_lock(&seq->lcs_mutex);
256         rc = seq_proc_read_common(page, start, off, count, eof,
257                                   data, &seq->lcs_space);
258         cfs_mutex_unlock(&seq->lcs_mutex);
259
260         RETURN(rc);
261 }
262
263 static int
264 seq_client_proc_write_width(struct file *file, const char *buffer,
265                             unsigned long count, void *data)
266 {
267         struct lu_client_seq *seq = (struct lu_client_seq *)data;
268         int rc, val;
269         ENTRY;
270
271         LASSERT(seq != NULL);
272
273         cfs_mutex_lock(&seq->lcs_mutex);
274
275         rc = lprocfs_write_helper(buffer, count, &val);
276         if (rc) {
277                 cfs_mutex_unlock(&seq->lcs_mutex);
278                 RETURN(rc);
279         }
280
281         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
282                 seq->lcs_width = val;
283
284                 if (rc == 0) {
285                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
286                                seq->lcs_name, seq->lcs_width);
287                 }
288         }
289
290         cfs_mutex_unlock(&seq->lcs_mutex);
291
292         RETURN(count);
293 }
294
295 static int
296 seq_client_proc_read_width(char *page, char **start, off_t off,
297                            int count, int *eof, void *data)
298 {
299         struct lu_client_seq *seq = (struct lu_client_seq *)data;
300         int rc;
301         ENTRY;
302
303         LASSERT(seq != NULL);
304
305         cfs_mutex_lock(&seq->lcs_mutex);
306         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
307         cfs_mutex_unlock(&seq->lcs_mutex);
308
309         RETURN(rc);
310 }
311
312 static int
313 seq_client_proc_read_fid(char *page, char **start, off_t off,
314                          int count, int *eof, void *data)
315 {
316         struct lu_client_seq *seq = (struct lu_client_seq *)data;
317         int rc;
318         ENTRY;
319
320         LASSERT(seq != NULL);
321
322         cfs_mutex_lock(&seq->lcs_mutex);
323         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
324         cfs_mutex_unlock(&seq->lcs_mutex);
325
326         RETURN(rc);
327 }
328
329 static int
330 seq_client_proc_read_server(char *page, char **start, off_t off,
331                             int count, int *eof, void *data)
332 {
333         struct lu_client_seq *seq = (struct lu_client_seq *)data;
334         struct client_obd *cli;
335         int rc;
336         ENTRY;
337
338         LASSERT(seq != NULL);
339
340         if (seq->lcs_exp != NULL) {
341                 cli = &seq->lcs_exp->exp_obd->u.cli;
342                 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
343         } else {
344                 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
345         }
346         RETURN(rc);
347 }
348
349 struct lprocfs_vars seq_server_proc_list[] = {
350         { "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
351         { "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
352         { "server",   seq_server_proc_read_server, NULL, NULL },
353         { NULL }};
354
355 struct lprocfs_vars seq_client_proc_list[] = {
356         { "space",    seq_client_proc_read_space, seq_client_proc_write_space, NULL },
357         { "width",    seq_client_proc_read_width, seq_client_proc_write_width, NULL },
358         { "server",   seq_client_proc_read_server, NULL, NULL },
359         { "fid",      seq_client_proc_read_fid, NULL, NULL },
360         { NULL }};
361 #endif