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, 2013, 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
45 #include <libcfs/libcfs.h>
46 #include <linux/module.h>
48 #include <obd_class.h>
49 #include <obd_support.h>
50 #include <lustre_fid.h>
51 #include <lprocfs_status.h>
52 #include "fid_internal.h"
56 * Note: this function is only used for testing, it is no safe for production
60 seq_proc_write_common(struct file *file, const char *buffer,
61 unsigned long count, void *data,
62 struct lu_seq_range *range)
64 struct lu_seq_range tmp;
68 LASSERT(range != NULL);
70 rc = sscanf(buffer, "[%llx - %llx]\n",
71 (long long unsigned *)&tmp.lsr_start,
72 (long long unsigned *)&tmp.lsr_end);
73 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
80 seq_proc_read_common(char *page, char **start, off_t off,
81 int count, int *eof, void *data,
82 struct lu_seq_range *range)
88 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
93 #ifdef HAVE_SERVER_SUPPORT
95 * Server side procfs stuff.
98 seq_server_proc_write_space(struct file *file, const char *buffer,
99 unsigned long count, void *data)
101 struct lu_server_seq *seq = (struct lu_server_seq *)data;
105 LASSERT(seq != NULL);
107 mutex_lock(&seq->lss_mutex);
108 rc = seq_proc_write_common(file, buffer, count,
109 data, &seq->lss_space);
111 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
112 seq->lss_name, PRANGE(&seq->lss_space));
115 mutex_unlock(&seq->lss_mutex);
121 seq_server_proc_read_space(char *page, char **start, off_t off,
122 int count, int *eof, void *data)
124 struct lu_server_seq *seq = (struct lu_server_seq *)data;
128 LASSERT(seq != NULL);
130 mutex_lock(&seq->lss_mutex);
131 rc = seq_proc_read_common(page, start, off, count, eof,
132 data, &seq->lss_space);
133 mutex_unlock(&seq->lss_mutex);
139 seq_server_proc_read_server(char *page, char **start, off_t off,
140 int count, int *eof, void *data)
142 struct lu_server_seq *seq = (struct lu_server_seq *)data;
143 struct client_obd *cli;
147 LASSERT(seq != NULL);
151 if (seq->lss_cli->lcs_exp != NULL) {
152 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
153 rc = snprintf(page, count, "%s\n",
154 cli->cl_target_uuid.uuid);
156 rc = snprintf(page, count, "%s\n",
157 seq->lss_cli->lcs_srv->lss_name);
160 rc = snprintf(page, count, "<none>\n");
167 seq_server_proc_write_width(struct file *file, const char *buffer,
168 unsigned long count, void *data)
170 struct lu_server_seq *seq = (struct lu_server_seq *)data;
174 LASSERT(seq != NULL);
176 mutex_lock(&seq->lss_mutex);
178 rc = lprocfs_write_helper(buffer, count, &val);
180 CERROR("%s: invalid width.\n", seq->lss_name);
181 GOTO(out_unlock, rc);
184 seq->lss_width = val;
186 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
187 seq->lss_name, seq->lss_width);
189 mutex_unlock(&seq->lss_mutex);
195 seq_server_proc_read_width(char *page, char **start, off_t off,
196 int count, int *eof, void *data)
198 struct lu_server_seq *seq = (struct lu_server_seq *)data;
202 LASSERT(seq != NULL);
204 mutex_lock(&seq->lss_mutex);
205 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
206 mutex_unlock(&seq->lss_mutex);
211 struct lprocfs_vars seq_server_proc_list[] = {
213 seq_server_proc_read_space, seq_server_proc_write_space, NULL },
215 seq_server_proc_read_width, seq_server_proc_write_width, NULL },
217 seq_server_proc_read_server, NULL, NULL },
220 #endif /* HAVE_SERVER_SUPPORT */
222 /* Client side procfs stuff */
224 seq_client_proc_write_space(struct file *file, const char *buffer,
225 unsigned long count, void *data)
227 struct lu_client_seq *seq = (struct lu_client_seq *)data;
231 LASSERT(seq != NULL);
233 mutex_lock(&seq->lcs_mutex);
234 rc = seq_proc_write_common(file, buffer, count,
235 data, &seq->lcs_space);
238 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
239 seq->lcs_name, PRANGE(&seq->lcs_space));
242 mutex_unlock(&seq->lcs_mutex);
248 seq_client_proc_read_space(char *page, char **start, off_t off,
249 int count, int *eof, void *data)
251 struct lu_client_seq *seq = (struct lu_client_seq *)data;
255 LASSERT(seq != NULL);
257 mutex_lock(&seq->lcs_mutex);
258 rc = seq_proc_read_common(page, start, off, count, eof,
259 data, &seq->lcs_space);
260 mutex_unlock(&seq->lcs_mutex);
266 seq_client_proc_write_width(struct file *file, const char *buffer,
267 unsigned long count, void *data)
269 struct lu_client_seq *seq = (struct lu_client_seq *)data;
274 LASSERT(seq != NULL);
276 mutex_lock(&seq->lcs_mutex);
278 rc = lprocfs_write_helper(buffer, count, &val);
280 mutex_unlock(&seq->lcs_mutex);
284 if (seq->lcs_type == LUSTRE_SEQ_DATA)
285 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
287 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
289 if (val <= max && val > 0) {
290 seq->lcs_width = val;
293 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
294 seq->lcs_name, seq->lcs_width);
298 mutex_unlock(&seq->lcs_mutex);
304 seq_client_proc_read_width(char *page, char **start, off_t off,
305 int count, int *eof, void *data)
307 struct lu_client_seq *seq = (struct lu_client_seq *)data;
311 LASSERT(seq != NULL);
313 mutex_lock(&seq->lcs_mutex);
314 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
315 mutex_unlock(&seq->lcs_mutex);
321 seq_client_proc_read_fid(char *page, char **start, off_t off,
322 int count, int *eof, void *data)
324 struct lu_client_seq *seq = (struct lu_client_seq *)data;
328 LASSERT(seq != NULL);
330 mutex_lock(&seq->lcs_mutex);
331 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
332 mutex_unlock(&seq->lcs_mutex);
338 seq_client_proc_read_server(char *page, char **start, off_t off,
339 int count, int *eof, void *data)
341 struct lu_client_seq *seq = (struct lu_client_seq *)data;
342 struct client_obd *cli;
346 LASSERT(seq != NULL);
348 if (seq->lcs_exp != NULL) {
349 cli = &seq->lcs_exp->exp_obd->u.cli;
350 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
352 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
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 },