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, "[%llx - %llx]\n",
81 (long long unsigned *)&tmp.lsr_start,
82 (long long unsigned *)&tmp.lsr_end);
83 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
90 seq_proc_read_common(char *page, char **start, off_t off,
91 int count, int *eof, void *data,
92 struct lu_seq_range *range)
98 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
104 * Server side procfs stuff.
107 seq_server_proc_write_space(struct file *file, const char *buffer,
108 unsigned long count, void *data)
110 struct lu_server_seq *seq = (struct lu_server_seq *)data;
114 LASSERT(seq != NULL);
116 cfs_down(&seq->lss_sem);
117 rc = seq_proc_write_common(file, buffer, count,
118 data, &seq->lss_space);
120 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
121 seq->lss_name, PRANGE(&seq->lss_space));
124 cfs_up(&seq->lss_sem);
130 seq_server_proc_read_space(char *page, char **start, off_t off,
131 int count, int *eof, void *data)
133 struct lu_server_seq *seq = (struct lu_server_seq *)data;
137 LASSERT(seq != NULL);
139 cfs_down(&seq->lss_sem);
140 rc = seq_proc_read_common(page, start, off, count, eof,
141 data, &seq->lss_space);
142 cfs_up(&seq->lss_sem);
148 seq_server_proc_read_server(char *page, char **start, off_t off,
149 int count, int *eof, void *data)
151 struct lu_server_seq *seq = (struct lu_server_seq *)data;
152 struct client_obd *cli;
156 LASSERT(seq != NULL);
160 if (seq->lss_cli->lcs_exp != NULL) {
161 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
162 rc = snprintf(page, count, "%s\n",
163 cli->cl_target_uuid.uuid);
165 rc = snprintf(page, count, "%s\n",
166 seq->lss_cli->lcs_srv->lss_name);
169 rc = snprintf(page, count, "<none>\n");
176 seq_server_proc_write_width(struct file *file, const char *buffer,
177 unsigned long count, void *data)
179 struct lu_server_seq *seq = (struct lu_server_seq *)data;
183 LASSERT(seq != NULL);
185 cfs_down(&seq->lss_sem);
187 rc = lprocfs_write_helper(buffer, count, &val);
191 seq->lss_width = val;
194 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
195 seq->lss_name, seq->lss_width);
198 cfs_up(&seq->lss_sem);
204 seq_server_proc_read_width(char *page, char **start, off_t off,
205 int count, int *eof, void *data)
207 struct lu_server_seq *seq = (struct lu_server_seq *)data;
211 LASSERT(seq != NULL);
213 cfs_down(&seq->lss_sem);
214 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
215 cfs_up(&seq->lss_sem);
220 /* Client side procfs stuff */
222 seq_client_proc_write_space(struct file *file, const char *buffer,
223 unsigned long count, void *data)
225 struct lu_client_seq *seq = (struct lu_client_seq *)data;
229 LASSERT(seq != NULL);
231 cfs_down(&seq->lcs_sem);
232 rc = seq_proc_write_common(file, buffer, count,
233 data, &seq->lcs_space);
236 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
237 seq->lcs_name, PRANGE(&seq->lcs_space));
240 cfs_up(&seq->lcs_sem);
246 seq_client_proc_read_space(char *page, char **start, off_t off,
247 int count, int *eof, void *data)
249 struct lu_client_seq *seq = (struct lu_client_seq *)data;
253 LASSERT(seq != NULL);
255 cfs_down(&seq->lcs_sem);
256 rc = seq_proc_read_common(page, start, off, count, eof,
257 data, &seq->lcs_space);
258 cfs_up(&seq->lcs_sem);
264 seq_client_proc_write_width(struct file *file, const char *buffer,
265 unsigned long count, void *data)
267 struct lu_client_seq *seq = (struct lu_client_seq *)data;
271 LASSERT(seq != NULL);
273 cfs_down(&seq->lcs_sem);
275 rc = lprocfs_write_helper(buffer, count, &val);
277 cfs_up(&seq->lcs_sem);
281 if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
282 seq->lcs_width = val;
285 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
286 seq->lcs_name, seq->lcs_width);
290 cfs_up(&seq->lcs_sem);
296 seq_client_proc_read_width(char *page, char **start, off_t off,
297 int count, int *eof, void *data)
299 struct lu_client_seq *seq = (struct lu_client_seq *)data;
303 LASSERT(seq != NULL);
305 cfs_down(&seq->lcs_sem);
306 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
307 cfs_up(&seq->lcs_sem);
313 seq_client_proc_read_fid(char *page, char **start, off_t off,
314 int count, int *eof, void *data)
316 struct lu_client_seq *seq = (struct lu_client_seq *)data;
320 LASSERT(seq != NULL);
322 cfs_down(&seq->lcs_sem);
323 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
324 cfs_up(&seq->lcs_sem);
330 seq_client_proc_read_server(char *page, char **start, off_t off,
331 int count, int *eof, void *data)
333 struct lu_client_seq *seq = (struct lu_client_seq *)data;
334 struct client_obd *cli;
338 LASSERT(seq != NULL);
340 if (seq->lcs_exp != NULL) {
341 cli = &seq->lcs_exp->exp_obd->u.cli;
342 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
344 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
349 struct lprocfs_vars seq_server_proc_list[] = {
350 { "space", seq_server_proc_read_space, seq_server_proc_write_space, NULL },
351 { "width", seq_server_proc_read_width, seq_server_proc_write_width, NULL },
352 { "server", seq_server_proc_read_server, NULL, NULL },
355 struct lprocfs_vars seq_client_proc_list[] = {
356 { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL },
357 { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL },
358 { "server", seq_client_proc_read_server, NULL, NULL },
359 { "fid", seq_client_proc_read_fid, NULL, NULL },