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