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