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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/fid/lproc_fid.c
40 * Lustre Sequence Manager
42 * Author: Yury Umanets <umka@clusterfs.com>
46 # define EXPORT_SYMTAB
48 #define DEBUG_SUBSYSTEM S_FID
51 # include <libcfs/libcfs.h>
52 # include <linux/module.h>
53 #else /* __KERNEL__ */
54 # include <liblustre.h>
58 #include <obd_class.h>
59 #include <dt_object.h>
60 #include <md_object.h>
61 #include <obd_support.h>
62 #include <lustre_req_layout.h>
63 #include <lustre_fid.h>
64 #include "fid_internal.h"
68 * Note: this function is only used for testing, it is no safe for production
72 seq_proc_write_common(struct file *file, const char *buffer,
73 unsigned long count, void *data,
74 struct lu_seq_range *range)
76 struct lu_seq_range tmp;
80 LASSERT(range != NULL);
82 rc = sscanf(buffer, "[%llx - %llx]\n",
83 (long long unsigned *)&tmp.lsr_start,
84 (long long unsigned *)&tmp.lsr_end);
85 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
92 seq_proc_read_common(char *page, char **start, off_t off,
93 int count, int *eof, void *data,
94 struct lu_seq_range *range)
100 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
106 * Server side procfs stuff.
109 seq_server_proc_write_space(struct file *file, const char *buffer,
110 unsigned long count, void *data)
112 struct lu_server_seq *seq = (struct lu_server_seq *)data;
116 LASSERT(seq != NULL);
118 cfs_mutex_lock(&seq->lss_mutex);
119 rc = seq_proc_write_common(file, buffer, count,
120 data, &seq->lss_space);
122 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
123 seq->lss_name, PRANGE(&seq->lss_space));
126 cfs_mutex_unlock(&seq->lss_mutex);
132 seq_server_proc_read_space(char *page, char **start, off_t off,
133 int count, int *eof, void *data)
135 struct lu_server_seq *seq = (struct lu_server_seq *)data;
139 LASSERT(seq != NULL);
141 cfs_mutex_lock(&seq->lss_mutex);
142 rc = seq_proc_read_common(page, start, off, count, eof,
143 data, &seq->lss_space);
144 cfs_mutex_unlock(&seq->lss_mutex);
150 seq_server_proc_read_server(char *page, char **start, off_t off,
151 int count, int *eof, void *data)
153 struct lu_server_seq *seq = (struct lu_server_seq *)data;
154 struct client_obd *cli;
158 LASSERT(seq != NULL);
162 if (seq->lss_cli->lcs_exp != NULL) {
163 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
164 rc = snprintf(page, count, "%s\n",
165 cli->cl_target_uuid.uuid);
167 rc = snprintf(page, count, "%s\n",
168 seq->lss_cli->lcs_srv->lss_name);
171 rc = snprintf(page, count, "<none>\n");
178 seq_server_proc_write_width(struct file *file, const char *buffer,
179 unsigned long count, void *data)
181 struct lu_server_seq *seq = (struct lu_server_seq *)data;
185 LASSERT(seq != NULL);
187 cfs_mutex_lock(&seq->lss_mutex);
189 rc = lprocfs_write_helper(buffer, count, &val);
193 seq->lss_width = val;
196 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
197 seq->lss_name, seq->lss_width);
200 cfs_mutex_unlock(&seq->lss_mutex);
206 seq_server_proc_read_width(char *page, char **start, off_t off,
207 int count, int *eof, void *data)
209 struct lu_server_seq *seq = (struct lu_server_seq *)data;
213 LASSERT(seq != NULL);
215 cfs_mutex_lock(&seq->lss_mutex);
216 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
217 cfs_mutex_unlock(&seq->lss_mutex);
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 cfs_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 cfs_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 cfs_mutex_lock(&seq->lcs_mutex);
258 rc = seq_proc_read_common(page, start, off, count, eof,
259 data, &seq->lcs_space);
260 cfs_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;
273 LASSERT(seq != NULL);
275 cfs_mutex_lock(&seq->lcs_mutex);
277 rc = lprocfs_write_helper(buffer, count, &val);
279 cfs_mutex_unlock(&seq->lcs_mutex);
283 if (val <= LUSTRE_SEQ_MAX_WIDTH && val > 0) {
284 seq->lcs_width = val;
287 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
288 seq->lcs_name, seq->lcs_width);
292 cfs_mutex_unlock(&seq->lcs_mutex);
298 seq_client_proc_read_width(char *page, char **start, off_t off,
299 int count, int *eof, void *data)
301 struct lu_client_seq *seq = (struct lu_client_seq *)data;
305 LASSERT(seq != NULL);
307 cfs_mutex_lock(&seq->lcs_mutex);
308 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
309 cfs_mutex_unlock(&seq->lcs_mutex);
315 seq_client_proc_read_fid(char *page, char **start, off_t off,
316 int count, int *eof, void *data)
318 struct lu_client_seq *seq = (struct lu_client_seq *)data;
322 LASSERT(seq != NULL);
324 cfs_mutex_lock(&seq->lcs_mutex);
325 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
326 cfs_mutex_unlock(&seq->lcs_mutex);
332 seq_client_proc_read_server(char *page, char **start, off_t off,
333 int count, int *eof, void *data)
335 struct lu_client_seq *seq = (struct lu_client_seq *)data;
336 struct client_obd *cli;
340 LASSERT(seq != NULL);
342 if (seq->lcs_exp != NULL) {
343 cli = &seq->lcs_exp->exp_obd->u.cli;
344 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
346 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
351 struct lprocfs_vars seq_server_proc_list[] = {
352 { "space", seq_server_proc_read_space, seq_server_proc_write_space, NULL },
353 { "width", seq_server_proc_read_width, seq_server_proc_write_width, NULL },
354 { "server", seq_server_proc_read_server, NULL, NULL },
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 },