]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/lustre/lustre/fid/lproc_fid.c
294070da9d43217eeff7a1b2b211284054b2257f
[karo-tx-linux.git] / drivers / staging / lustre / 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, 2012, 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 <linux/libcfs/libcfs.h>
46 # include <linux/module.h>
47
48 #include <obd.h>
49 #include <obd_class.h>
50 #include <dt_object.h>
51 #include <md_object.h>
52 #include <obd_support.h>
53 #include <lustre_req_layout.h>
54 #include <lustre_fid.h>
55 #include "fid_internal.h"
56
57 #ifdef LPROCFS
58 /*
59  * Note: this function is only used for testing, it is no safe for production
60  * use.
61  */
62 static int
63 lprocfs_fid_write_common(const char *buffer, unsigned long count,
64                          struct lu_seq_range *range)
65 {
66         struct lu_seq_range tmp;
67         int rc;
68
69         LASSERT(range != NULL);
70
71         rc = sscanf(buffer, "[%llx - %llx]\n",
72                     (long long unsigned *)&tmp.lsr_start,
73                     (long long unsigned *)&tmp.lsr_end);
74         if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
75                 return -EINVAL;
76         *range = tmp;
77         return 0;
78 }
79
80 /* Client side procfs stuff */
81 static ssize_t
82 lprocfs_fid_space_seq_write(struct file *file, const char *buffer,
83                             size_t count, loff_t *off)
84 {
85         struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
86         int rc;
87
88         LASSERT(seq != NULL);
89
90         mutex_lock(&seq->lcs_mutex);
91         rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
92
93         if (rc == 0) {
94                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
95                        seq->lcs_name, PRANGE(&seq->lcs_space));
96         }
97
98         mutex_unlock(&seq->lcs_mutex);
99
100         return count;
101 }
102
103 static int
104 lprocfs_fid_space_seq_show(struct seq_file *m, void *unused)
105 {
106         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
107         int rc;
108
109         LASSERT(seq != NULL);
110
111         mutex_lock(&seq->lcs_mutex);
112         rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n", PRANGE(&seq->lcs_space));
113         mutex_unlock(&seq->lcs_mutex);
114
115         return rc;
116 }
117
118 static ssize_t
119 lprocfs_fid_width_seq_write(struct file *file, const char *buffer,
120                             size_t count, loff_t *off)
121 {
122         struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
123         __u64  max;
124         int rc, val;
125
126         LASSERT(seq != NULL);
127
128         rc = lprocfs_write_helper(buffer, count, &val);
129         if (rc)
130                 return rc;
131
132         mutex_lock(&seq->lcs_mutex);
133         if (seq->lcs_type == LUSTRE_SEQ_DATA)
134                 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
135         else
136                 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
137
138         if (val <= max && val > 0) {
139                 seq->lcs_width = val;
140
141                 if (rc == 0) {
142                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
143                                seq->lcs_name, seq->lcs_width);
144                 }
145         }
146
147         mutex_unlock(&seq->lcs_mutex);
148
149         return count;
150 }
151
152 static int
153 lprocfs_fid_width_seq_show(struct seq_file *m, void *unused)
154 {
155         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
156         int rc;
157
158         LASSERT(seq != NULL);
159
160         mutex_lock(&seq->lcs_mutex);
161         rc = seq_printf(m, LPU64"\n", seq->lcs_width);
162         mutex_unlock(&seq->lcs_mutex);
163
164         return rc;
165 }
166
167 static int
168 lprocfs_fid_fid_seq_show(struct seq_file *m, void *unused)
169 {
170         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
171         int rc;
172
173         LASSERT(seq != NULL);
174
175         mutex_lock(&seq->lcs_mutex);
176         rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
177         mutex_unlock(&seq->lcs_mutex);
178
179         return rc;
180 }
181
182 static int
183 lprocfs_fid_server_seq_show(struct seq_file *m, void *unused)
184 {
185         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
186         struct client_obd *cli;
187         int rc;
188
189         LASSERT(seq != NULL);
190
191         if (seq->lcs_exp != NULL) {
192                 cli = &seq->lcs_exp->exp_obd->u.cli;
193                 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
194         } else {
195                 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
196         }
197         return rc;
198 }
199
200 LPROC_SEQ_FOPS(lprocfs_fid_space);
201 LPROC_SEQ_FOPS(lprocfs_fid_width);
202 LPROC_SEQ_FOPS_RO(lprocfs_fid_server);
203 LPROC_SEQ_FOPS_RO(lprocfs_fid_fid);
204
205 struct lprocfs_vars seq_client_proc_list[] = {
206         { "space", &lprocfs_fid_space_fops },
207         { "width", &lprocfs_fid_width_fops },
208         { "server", &lprocfs_fid_server_fops },
209         { "fid", &lprocfs_fid_fid_fops },
210         { NULL }
211 };
212 #endif