4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/fid/lproc_fid.c
38 * Lustre Sequence Manager
40 * Author: Yury Umanets <umka@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_FID
46 # include <libcfs/libcfs.h>
47 # include <linux/module.h>
48 #else /* __KERNEL__ */
49 # include <liblustre.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"
63 * Note: this function is only used for testing, it is no safe for production
67 seq_proc_write_common(struct file *file, const char *buffer,
68 unsigned long count, void *data,
69 struct lu_seq_range *range)
71 struct lu_seq_range tmp;
75 LASSERT(range != NULL);
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))
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)
95 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
101 * Server side procfs stuff.
104 seq_server_proc_write_space(struct file *file, const char *buffer,
105 unsigned long count, void *data)
107 struct lu_server_seq *seq = (struct lu_server_seq *)data;
111 LASSERT(seq != NULL);
113 cfs_mutex_lock(&seq->lss_mutex);
114 rc = seq_proc_write_common(file, buffer, count,
115 data, &seq->lss_space);
117 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
118 seq->lss_name, PRANGE(&seq->lss_space));
121 cfs_mutex_unlock(&seq->lss_mutex);
127 seq_server_proc_read_space(char *page, char **start, off_t off,
128 int count, int *eof, void *data)
130 struct lu_server_seq *seq = (struct lu_server_seq *)data;
134 LASSERT(seq != NULL);
136 cfs_mutex_lock(&seq->lss_mutex);
137 rc = seq_proc_read_common(page, start, off, count, eof,
138 data, &seq->lss_space);
139 cfs_mutex_unlock(&seq->lss_mutex);
145 seq_server_proc_read_server(char *page, char **start, off_t off,
146 int count, int *eof, void *data)
148 struct lu_server_seq *seq = (struct lu_server_seq *)data;
149 struct client_obd *cli;
153 LASSERT(seq != NULL);
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);
162 rc = snprintf(page, count, "%s\n",
163 seq->lss_cli->lcs_srv->lss_name);
166 rc = snprintf(page, count, "<none>\n");
173 seq_server_proc_write_width(struct file *file, const char *buffer,
174 unsigned long count, void *data)
176 struct lu_server_seq *seq = (struct lu_server_seq *)data;
180 LASSERT(seq != NULL);
182 cfs_mutex_lock(&seq->lss_mutex);
184 rc = lprocfs_write_helper(buffer, count, &val);
188 seq->lss_width = val;
191 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
192 seq->lss_name, seq->lss_width);
195 cfs_mutex_unlock(&seq->lss_mutex);
201 seq_server_proc_read_width(char *page, char **start, off_t off,
202 int count, int *eof, void *data)
204 struct lu_server_seq *seq = (struct lu_server_seq *)data;
208 LASSERT(seq != NULL);
210 cfs_mutex_lock(&seq->lss_mutex);
211 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
212 cfs_mutex_unlock(&seq->lss_mutex);
217 /* Client side procfs stuff */
219 seq_client_proc_write_space(struct file *file, const char *buffer,
220 unsigned long count, void *data)
222 struct lu_client_seq *seq = (struct lu_client_seq *)data;
226 LASSERT(seq != NULL);
228 cfs_mutex_lock(&seq->lcs_mutex);
229 rc = seq_proc_write_common(file, buffer, count,
230 data, &seq->lcs_space);
233 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
234 seq->lcs_name, PRANGE(&seq->lcs_space));
237 cfs_mutex_unlock(&seq->lcs_mutex);
243 seq_client_proc_read_space(char *page, char **start, off_t off,
244 int count, int *eof, void *data)
246 struct lu_client_seq *seq = (struct lu_client_seq *)data;
250 LASSERT(seq != NULL);
252 cfs_mutex_lock(&seq->lcs_mutex);
253 rc = seq_proc_read_common(page, start, off, count, eof,
254 data, &seq->lcs_space);
255 cfs_mutex_unlock(&seq->lcs_mutex);
261 seq_client_proc_write_width(struct file *file, const char *buffer,
262 unsigned long count, void *data)
264 struct lu_client_seq *seq = (struct lu_client_seq *)data;
268 LASSERT(seq != NULL);
270 cfs_mutex_lock(&seq->lcs_mutex);
272 rc = lprocfs_write_helper(buffer, count, &val);
274 cfs_mutex_unlock(&seq->lcs_mutex);
278 if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
279 seq->lcs_width = val;
282 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
283 seq->lcs_name, seq->lcs_width);
287 cfs_mutex_unlock(&seq->lcs_mutex);
293 seq_client_proc_read_width(char *page, char **start, off_t off,
294 int count, int *eof, void *data)
296 struct lu_client_seq *seq = (struct lu_client_seq *)data;
300 LASSERT(seq != NULL);
302 cfs_mutex_lock(&seq->lcs_mutex);
303 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
304 cfs_mutex_unlock(&seq->lcs_mutex);
310 seq_client_proc_read_fid(char *page, char **start, off_t off,
311 int count, int *eof, void *data)
313 struct lu_client_seq *seq = (struct lu_client_seq *)data;
317 LASSERT(seq != NULL);
319 cfs_mutex_lock(&seq->lcs_mutex);
320 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
321 cfs_mutex_unlock(&seq->lcs_mutex);
327 seq_client_proc_read_server(char *page, char **start, off_t off,
328 int count, int *eof, void *data)
330 struct lu_client_seq *seq = (struct lu_client_seq *)data;
331 struct client_obd *cli;
335 LASSERT(seq != NULL);
337 if (seq->lcs_exp != NULL) {
338 cli = &seq->lcs_exp->exp_obd->u.cli;
339 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
341 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
346 struct lprocfs_vars seq_server_proc_list[] = {
347 { "space", seq_server_proc_read_space, seq_server_proc_write_space, NULL },
348 { "width", seq_server_proc_read_width, seq_server_proc_write_width, NULL },
349 { "server", seq_server_proc_read_server, NULL, NULL },
352 struct lprocfs_vars seq_client_proc_list[] = {
353 { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL },
354 { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL },
355 { "server", seq_client_proc_read_server, NULL, NULL },
356 { "fid", seq_client_proc_read_fid, NULL, NULL },