Whamcloud - gitweb
LU-812 compat: clean up mutex lock to use kernel mutex primitive
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * lustre/fid/lproc_fid.c
39  *
40  * Lustre Sequence Manager
41  *
42  * Author: Yury Umanets <umka@clusterfs.com>
43  */
44
45 #ifndef EXPORT_SYMTAB
46 # define EXPORT_SYMTAB
47 #endif
48 #define DEBUG_SUBSYSTEM S_FID
49
50 #ifdef __KERNEL__
51 # include <libcfs/libcfs.h>
52 # include <linux/module.h>
53 #else /* __KERNEL__ */
54 # include <liblustre.h>
55 #endif
56
57 #include <obd.h>
58 #include <obd_class.h>
59 #include <dt_object.h>
60 #include <md_object.h>
61 #include <obd_support.h>
62 #include <lustre_req_layout.h>
63 #include <lustre_fid.h>
64 #include "fid_internal.h"
65
66 #ifdef LPROCFS
67 /*
68  * Note: this function is only used for testing, it is no safe for production
69  * use.
70  */
71 static int
72 seq_proc_write_common(struct file *file, const char *buffer,
73                       unsigned long count, void *data,
74                       struct lu_seq_range *range)
75 {
76         struct lu_seq_range tmp;
77         int rc;
78         ENTRY;
79
80         LASSERT(range != NULL);
81
82         rc = sscanf(buffer, "[%llx - %llx]\n",
83                     (long long unsigned *)&tmp.lsr_start,
84                     (long long unsigned *)&tmp.lsr_end);
85         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
86                 RETURN(-EINVAL);
87         *range = tmp;
88         RETURN(0);
89 }
90
91 static int
92 seq_proc_read_common(char *page, char **start, off_t off,
93                      int count, int *eof, void *data,
94                      struct lu_seq_range *range)
95 {
96         int rc;
97         ENTRY;
98
99         *eof = 1;
100         rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
101                       PRANGE(range));
102         RETURN(rc);
103 }
104
105 /*
106  * Server side procfs stuff.
107  */
108 static int
109 seq_server_proc_write_space(struct file *file, const char *buffer,
110                             unsigned long count, void *data)
111 {
112         struct lu_server_seq *seq = (struct lu_server_seq *)data;
113         int rc;
114         ENTRY;
115
116         LASSERT(seq != NULL);
117
118         cfs_mutex_lock(&seq->lss_mutex);
119         rc = seq_proc_write_common(file, buffer, count,
120                                    data, &seq->lss_space);
121         if (rc == 0) {
122                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
123                        seq->lss_name, PRANGE(&seq->lss_space));
124         }
125
126         cfs_mutex_unlock(&seq->lss_mutex);
127
128         RETURN(count);
129 }
130
131 static int
132 seq_server_proc_read_space(char *page, char **start, off_t off,
133                            int count, int *eof, void *data)
134 {
135         struct lu_server_seq *seq = (struct lu_server_seq *)data;
136         int rc;
137         ENTRY;
138
139         LASSERT(seq != NULL);
140
141         cfs_mutex_lock(&seq->lss_mutex);
142         rc = seq_proc_read_common(page, start, off, count, eof,
143                                   data, &seq->lss_space);
144         cfs_mutex_unlock(&seq->lss_mutex);
145
146         RETURN(rc);
147 }
148
149 static int
150 seq_server_proc_read_server(char *page, char **start, off_t off,
151                             int count, int *eof, void *data)
152 {
153         struct lu_server_seq *seq = (struct lu_server_seq *)data;
154         struct client_obd *cli;
155         int rc;
156         ENTRY;
157
158         LASSERT(seq != NULL);
159
160         *eof = 1;
161         if (seq->lss_cli) {
162                 if (seq->lss_cli->lcs_exp != NULL) {
163                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
164                         rc = snprintf(page, count, "%s\n",
165                                       cli->cl_target_uuid.uuid);
166                 } else {
167                         rc = snprintf(page, count, "%s\n",
168                                       seq->lss_cli->lcs_srv->lss_name);
169                 }
170         } else {
171                 rc = snprintf(page, count, "<none>\n");
172         }
173
174         RETURN(rc);
175 }
176
177 static int
178 seq_server_proc_write_width(struct file *file, const char *buffer,
179                             unsigned long count, void *data)
180 {
181         struct lu_server_seq *seq = (struct lu_server_seq *)data;
182         int rc, val;
183         ENTRY;
184
185         LASSERT(seq != NULL);
186
187         cfs_mutex_lock(&seq->lss_mutex);
188
189         rc = lprocfs_write_helper(buffer, count, &val);
190         if (rc)
191                 RETURN(rc);
192
193         seq->lss_width = val;
194
195         if (rc == 0) {
196                 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
197                        seq->lss_name, seq->lss_width);
198         }
199
200         cfs_mutex_unlock(&seq->lss_mutex);
201
202         RETURN(count);
203 }
204
205 static int
206 seq_server_proc_read_width(char *page, char **start, off_t off,
207                            int count, int *eof, void *data)
208 {
209         struct lu_server_seq *seq = (struct lu_server_seq *)data;
210         int rc;
211         ENTRY;
212
213         LASSERT(seq != NULL);
214
215         cfs_mutex_lock(&seq->lss_mutex);
216         rc = snprintf(page, count, LPU64"\n", seq->lss_width);
217         cfs_mutex_unlock(&seq->lss_mutex);
218
219         RETURN(rc);
220 }
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         cfs_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         cfs_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         cfs_mutex_lock(&seq->lcs_mutex);
258         rc = seq_proc_read_common(page, start, off, count, eof,
259                                   data, &seq->lcs_space);
260         cfs_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         int rc, val;
271         ENTRY;
272
273         LASSERT(seq != NULL);
274
275         cfs_mutex_lock(&seq->lcs_mutex);
276
277         rc = lprocfs_write_helper(buffer, count, &val);
278         if (rc) {
279                 cfs_mutex_unlock(&seq->lcs_mutex);
280                 RETURN(rc);
281         }
282
283         if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
284                 seq->lcs_width = val;
285
286                 if (rc == 0) {
287                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
288                                seq->lcs_name, seq->lcs_width);
289                 }
290         }
291
292         cfs_mutex_unlock(&seq->lcs_mutex);
293
294         RETURN(count);
295 }
296
297 static int
298 seq_client_proc_read_width(char *page, char **start, off_t off,
299                            int count, int *eof, void *data)
300 {
301         struct lu_client_seq *seq = (struct lu_client_seq *)data;
302         int rc;
303         ENTRY;
304
305         LASSERT(seq != NULL);
306
307         cfs_mutex_lock(&seq->lcs_mutex);
308         rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
309         cfs_mutex_unlock(&seq->lcs_mutex);
310
311         RETURN(rc);
312 }
313
314 static int
315 seq_client_proc_read_fid(char *page, char **start, off_t off,
316                          int count, int *eof, void *data)
317 {
318         struct lu_client_seq *seq = (struct lu_client_seq *)data;
319         int rc;
320         ENTRY;
321
322         LASSERT(seq != NULL);
323
324         cfs_mutex_lock(&seq->lcs_mutex);
325         rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
326         cfs_mutex_unlock(&seq->lcs_mutex);
327
328         RETURN(rc);
329 }
330
331 static int
332 seq_client_proc_read_server(char *page, char **start, off_t off,
333                             int count, int *eof, void *data)
334 {
335         struct lu_client_seq *seq = (struct lu_client_seq *)data;
336         struct client_obd *cli;
337         int rc;
338         ENTRY;
339
340         LASSERT(seq != NULL);
341
342         if (seq->lcs_exp != NULL) {
343                 cli = &seq->lcs_exp->exp_obd->u.cli;
344                 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
345         } else {
346                 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
347         }
348         RETURN(rc);
349 }
350
351 struct lprocfs_vars seq_server_proc_list[] = {
352         { "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
353         { "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
354         { "server",   seq_server_proc_read_server, NULL, NULL },
355         { NULL }};
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