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, 2012, Intel Corporation.
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:%s\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 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 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 mutex_lock(&seq->lss_mutex);
137 rc = seq_proc_read_common(page, start, off, count, eof,
138 data, &seq->lss_space);
139 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 mutex_lock(&seq->lss_mutex);
184 rc = lprocfs_write_helper(buffer, count, &val);
186 CERROR("%s: invalid width.\n", seq->lss_name);
187 GOTO(out_unlock, rc);
190 seq->lss_width = val;
192 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
193 seq->lss_name, seq->lss_width);
195 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 mutex_lock(&seq->lss_mutex);
211 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
212 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 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 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 mutex_lock(&seq->lcs_mutex);
253 rc = seq_proc_read_common(page, start, off, count, eof,
254 data, &seq->lcs_space);
255 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;
269 LASSERT(seq != NULL);
271 mutex_lock(&seq->lcs_mutex);
273 rc = lprocfs_write_helper(buffer, count, &val);
275 mutex_unlock(&seq->lcs_mutex);
279 if (seq->lcs_type == LUSTRE_SEQ_DATA)
280 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
282 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
284 if (val <= max && val > 0) {
285 seq->lcs_width = val;
288 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
289 seq->lcs_name, seq->lcs_width);
293 mutex_unlock(&seq->lcs_mutex);
299 seq_client_proc_read_width(char *page, char **start, off_t off,
300 int count, int *eof, void *data)
302 struct lu_client_seq *seq = (struct lu_client_seq *)data;
306 LASSERT(seq != NULL);
308 mutex_lock(&seq->lcs_mutex);
309 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
310 mutex_unlock(&seq->lcs_mutex);
316 seq_client_proc_read_fid(char *page, char **start, off_t off,
317 int count, int *eof, void *data)
319 struct lu_client_seq *seq = (struct lu_client_seq *)data;
323 LASSERT(seq != NULL);
325 mutex_lock(&seq->lcs_mutex);
326 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
327 mutex_unlock(&seq->lcs_mutex);
333 seq_client_proc_read_server(char *page, char **start, off_t off,
334 int count, int *eof, void *data)
336 struct lu_client_seq *seq = (struct lu_client_seq *)data;
337 struct client_obd *cli;
341 LASSERT(seq != NULL);
343 if (seq->lcs_exp != NULL) {
344 cli = &seq->lcs_exp->exp_obd->u.cli;
345 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
347 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
352 struct lprocfs_vars seq_server_proc_list[] = {
353 { "space", seq_server_proc_read_space, seq_server_proc_write_space, NULL },
354 { "width", seq_server_proc_read_width, seq_server_proc_write_width, NULL },
355 { "server", seq_server_proc_read_server, NULL, NULL },
358 struct lprocfs_vars seq_client_proc_list[] = {
359 { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL },
360 { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL },
361 { "server", seq_client_proc_read_server, NULL, NULL },
362 { "fid", seq_client_proc_read_fid, NULL, NULL },