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