Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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 | seq_proc_write_common(struct file *file, const char *buffer, | |
64 | unsigned long count, void *data, | |
65 | struct lu_seq_range *range) | |
66 | { | |
67 | struct lu_seq_range tmp; | |
68 | int rc; | |
69 | ENTRY; | |
70 | ||
71 | LASSERT(range != NULL); | |
72 | ||
73 | rc = sscanf(buffer, "[%llx - %llx]\n", | |
74 | (long long unsigned *)&tmp.lsr_start, | |
75 | (long long unsigned *)&tmp.lsr_end); | |
76 | if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp)) | |
77 | RETURN(-EINVAL); | |
78 | *range = tmp; | |
79 | RETURN(0); | |
80 | } | |
81 | ||
82 | static int | |
83 | seq_proc_read_common(char *page, char **start, off_t off, | |
84 | int count, int *eof, void *data, | |
85 | struct lu_seq_range *range) | |
86 | { | |
87 | int rc; | |
88 | ENTRY; | |
89 | ||
90 | *eof = 1; | |
91 | rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n", | |
92 | PRANGE(range)); | |
93 | RETURN(rc); | |
94 | } | |
95 | ||
96 | /* | |
97 | * Server side procfs stuff. | |
98 | */ | |
99 | static int | |
100 | seq_server_proc_write_space(struct file *file, const char *buffer, | |
101 | unsigned long count, void *data) | |
102 | { | |
103 | struct lu_server_seq *seq = (struct lu_server_seq *)data; | |
104 | int rc; | |
105 | ENTRY; | |
106 | ||
107 | LASSERT(seq != NULL); | |
108 | ||
109 | mutex_lock(&seq->lss_mutex); | |
110 | rc = seq_proc_write_common(file, buffer, count, | |
111 | data, &seq->lss_space); | |
112 | if (rc == 0) { | |
113 | CDEBUG(D_INFO, "%s: Space: "DRANGE"\n", | |
114 | seq->lss_name, PRANGE(&seq->lss_space)); | |
115 | } | |
116 | ||
117 | mutex_unlock(&seq->lss_mutex); | |
118 | ||
119 | RETURN(count); | |
120 | } | |
121 | ||
122 | static int | |
123 | seq_server_proc_read_space(char *page, char **start, off_t off, | |
124 | int count, int *eof, void *data) | |
125 | { | |
126 | struct lu_server_seq *seq = (struct lu_server_seq *)data; | |
127 | int rc; | |
128 | ENTRY; | |
129 | ||
130 | LASSERT(seq != NULL); | |
131 | ||
132 | mutex_lock(&seq->lss_mutex); | |
133 | rc = seq_proc_read_common(page, start, off, count, eof, | |
134 | data, &seq->lss_space); | |
135 | mutex_unlock(&seq->lss_mutex); | |
136 | ||
137 | RETURN(rc); | |
138 | } | |
139 | ||
140 | static int | |
141 | seq_server_proc_read_server(char *page, char **start, off_t off, | |
142 | int count, int *eof, void *data) | |
143 | { | |
144 | struct lu_server_seq *seq = (struct lu_server_seq *)data; | |
145 | struct client_obd *cli; | |
146 | int rc; | |
147 | ENTRY; | |
148 | ||
149 | LASSERT(seq != NULL); | |
150 | ||
151 | *eof = 1; | |
152 | if (seq->lss_cli) { | |
153 | if (seq->lss_cli->lcs_exp != NULL) { | |
154 | cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli; | |
155 | rc = snprintf(page, count, "%s\n", | |
156 | cli->cl_target_uuid.uuid); | |
157 | } else { | |
158 | rc = snprintf(page, count, "%s\n", | |
159 | seq->lss_cli->lcs_srv->lss_name); | |
160 | } | |
161 | } else { | |
162 | rc = snprintf(page, count, "<none>\n"); | |
163 | } | |
164 | ||
165 | RETURN(rc); | |
166 | } | |
167 | ||
168 | static int | |
169 | seq_server_proc_write_width(struct file *file, const char *buffer, | |
170 | unsigned long count, void *data) | |
171 | { | |
172 | struct lu_server_seq *seq = (struct lu_server_seq *)data; | |
173 | int rc, val; | |
174 | ENTRY; | |
175 | ||
176 | LASSERT(seq != NULL); | |
177 | ||
178 | mutex_lock(&seq->lss_mutex); | |
179 | ||
180 | rc = lprocfs_write_helper(buffer, count, &val); | |
181 | if (rc != 0) { | |
182 | CERROR("%s: invalid width.\n", seq->lss_name); | |
183 | GOTO(out_unlock, rc); | |
184 | } | |
185 | ||
186 | seq->lss_width = val; | |
187 | ||
188 | CDEBUG(D_INFO, "%s: Width: "LPU64"\n", | |
189 | seq->lss_name, seq->lss_width); | |
190 | out_unlock: | |
191 | mutex_unlock(&seq->lss_mutex); | |
192 | ||
193 | RETURN(count); | |
194 | } | |
195 | ||
196 | static int | |
197 | seq_server_proc_read_width(char *page, char **start, off_t off, | |
198 | int count, int *eof, void *data) | |
199 | { | |
200 | struct lu_server_seq *seq = (struct lu_server_seq *)data; | |
201 | int rc; | |
202 | ENTRY; | |
203 | ||
204 | LASSERT(seq != NULL); | |
205 | ||
206 | mutex_lock(&seq->lss_mutex); | |
207 | rc = snprintf(page, count, LPU64"\n", seq->lss_width); | |
208 | mutex_unlock(&seq->lss_mutex); | |
209 | ||
210 | RETURN(rc); | |
211 | } | |
212 | ||
213 | /* Client side procfs stuff */ | |
214 | static int | |
215 | seq_client_proc_write_space(struct file *file, const char *buffer, | |
216 | unsigned long count, void *data) | |
217 | { | |
218 | struct lu_client_seq *seq = (struct lu_client_seq *)data; | |
219 | int rc; | |
220 | ENTRY; | |
221 | ||
222 | LASSERT(seq != NULL); | |
223 | ||
224 | mutex_lock(&seq->lcs_mutex); | |
225 | rc = seq_proc_write_common(file, buffer, count, | |
226 | data, &seq->lcs_space); | |
227 | ||
228 | if (rc == 0) { | |
229 | CDEBUG(D_INFO, "%s: Space: "DRANGE"\n", | |
230 | seq->lcs_name, PRANGE(&seq->lcs_space)); | |
231 | } | |
232 | ||
233 | mutex_unlock(&seq->lcs_mutex); | |
234 | ||
235 | RETURN(count); | |
236 | } | |
237 | ||
238 | static int | |
239 | seq_client_proc_read_space(char *page, char **start, off_t off, | |
240 | int count, int *eof, void *data) | |
241 | { | |
242 | struct lu_client_seq *seq = (struct lu_client_seq *)data; | |
243 | int rc; | |
244 | ENTRY; | |
245 | ||
246 | LASSERT(seq != NULL); | |
247 | ||
248 | mutex_lock(&seq->lcs_mutex); | |
249 | rc = seq_proc_read_common(page, start, off, count, eof, | |
250 | data, &seq->lcs_space); | |
251 | mutex_unlock(&seq->lcs_mutex); | |
252 | ||
253 | RETURN(rc); | |
254 | } | |
255 | ||
256 | static int | |
257 | seq_client_proc_write_width(struct file *file, const char *buffer, | |
258 | unsigned long count, void *data) | |
259 | { | |
260 | struct lu_client_seq *seq = (struct lu_client_seq *)data; | |
261 | __u64 max; | |
262 | int rc, val; | |
263 | ENTRY; | |
264 | ||
265 | LASSERT(seq != NULL); | |
266 | ||
267 | mutex_lock(&seq->lcs_mutex); | |
268 | ||
269 | rc = lprocfs_write_helper(buffer, count, &val); | |
270 | if (rc) { | |
271 | mutex_unlock(&seq->lcs_mutex); | |
272 | RETURN(rc); | |
273 | } | |
274 | ||
275 | if (seq->lcs_type == LUSTRE_SEQ_DATA) | |
276 | max = LUSTRE_DATA_SEQ_MAX_WIDTH; | |
277 | else | |
278 | max = LUSTRE_METADATA_SEQ_MAX_WIDTH; | |
279 | ||
280 | if (val <= max && 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 | 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 | mutex_lock(&seq->lcs_mutex); | |
305 | rc = snprintf(page, count, LPU64"\n", seq->lcs_width); | |
306 | 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 | mutex_lock(&seq->lcs_mutex); | |
322 | rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid)); | |
323 | 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 |