1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_FID
49 # include <libcfs/libcfs.h>
50 # include <linux/module.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
56 #include <obd_class.h>
57 #include <dt_object.h>
58 #include <md_object.h>
59 #include <obd_support.h>
60 #include <lustre_req_layout.h>
61 #include <lustre_fid.h>
62 #include "fid_internal.h"
66 * Note: this function is only used for testing, it is no safe for production
70 seq_proc_write_common(struct file *file, const char *buffer,
71 unsigned long count, void *data,
72 struct lu_seq_range *range)
74 struct lu_seq_range tmp;
78 LASSERT(range != NULL);
80 rc = sscanf(buffer, "[%Lx - %Lx]\n",(long long unsigned *)&tmp.lsr_start,
81 (long long unsigned *)&tmp.lsr_end);
82 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
89 seq_proc_read_common(char *page, char **start, off_t off,
90 int count, int *eof, void *data,
91 struct lu_seq_range *range)
97 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x\n",
103 * Server side procfs stuff.
106 seq_server_proc_write_space(struct file *file, const char *buffer,
107 unsigned long count, void *data)
109 struct lu_server_seq *seq = (struct lu_server_seq *)data;
113 LASSERT(seq != NULL);
115 cfs_down(&seq->lss_sem);
116 rc = seq_proc_write_common(file, buffer, count,
117 data, &seq->lss_space);
119 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
120 seq->lss_name, PRANGE(&seq->lss_space));
123 cfs_up(&seq->lss_sem);
129 seq_server_proc_read_space(char *page, char **start, off_t off,
130 int count, int *eof, void *data)
132 struct lu_server_seq *seq = (struct lu_server_seq *)data;
136 LASSERT(seq != NULL);
138 cfs_down(&seq->lss_sem);
139 rc = seq_proc_read_common(page, start, off, count, eof,
140 data, &seq->lss_space);
141 cfs_up(&seq->lss_sem);
147 seq_server_proc_read_server(char *page, char **start, off_t off,
148 int count, int *eof, void *data)
150 struct lu_server_seq *seq = (struct lu_server_seq *)data;
151 struct client_obd *cli;
155 LASSERT(seq != NULL);
159 if (seq->lss_cli->lcs_exp != NULL) {
160 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
161 rc = snprintf(page, count, "%s\n",
162 cli->cl_target_uuid.uuid);
164 rc = snprintf(page, count, "%s\n",
165 seq->lss_cli->lcs_srv->lss_name);
168 rc = snprintf(page, count, "<none>\n");
175 seq_server_proc_write_width(struct file *file, const char *buffer,
176 unsigned long count, void *data)
178 struct lu_server_seq *seq = (struct lu_server_seq *)data;
182 LASSERT(seq != NULL);
184 cfs_down(&seq->lss_sem);
186 rc = lprocfs_write_helper(buffer, count, &val);
190 seq->lss_width = val;
193 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
194 seq->lss_name, seq->lss_width);
197 cfs_up(&seq->lss_sem);
203 seq_server_proc_read_width(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 struct lu_server_seq *seq = (struct lu_server_seq *)data;
210 LASSERT(seq != NULL);
212 cfs_down(&seq->lss_sem);
213 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
214 cfs_up(&seq->lss_sem);
219 /* Client side procfs stuff */
221 seq_client_proc_write_space(struct file *file, const char *buffer,
222 unsigned long count, void *data)
224 struct lu_client_seq *seq = (struct lu_client_seq *)data;
228 LASSERT(seq != NULL);
230 cfs_down(&seq->lcs_sem);
231 rc = seq_proc_write_common(file, buffer, count,
232 data, &seq->lcs_space);
235 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
236 seq->lcs_name, PRANGE(&seq->lcs_space));
239 cfs_up(&seq->lcs_sem);
245 seq_client_proc_read_space(char *page, char **start, off_t off,
246 int count, int *eof, void *data)
248 struct lu_client_seq *seq = (struct lu_client_seq *)data;
252 LASSERT(seq != NULL);
254 cfs_down(&seq->lcs_sem);
255 rc = seq_proc_read_common(page, start, off, count, eof,
256 data, &seq->lcs_space);
257 cfs_up(&seq->lcs_sem);
263 seq_client_proc_write_width(struct file *file, const char *buffer,
264 unsigned long count, void *data)
266 struct lu_client_seq *seq = (struct lu_client_seq *)data;
270 LASSERT(seq != NULL);
272 cfs_down(&seq->lcs_sem);
274 rc = lprocfs_write_helper(buffer, count, &val);
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_up(&seq->lcs_sem);
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_down(&seq->lcs_sem);
303 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
304 cfs_up(&seq->lcs_sem);
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_down(&seq->lcs_sem);
320 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
321 cfs_up(&seq->lcs_sem);
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 },