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"
53 #include <md_object.h>
57 * Note: this function is only used for testing, it is no safe for production
61 seq_proc_write_common(struct file *file, const char *buffer,
62 unsigned long count, void *data,
63 struct lu_seq_range *range)
65 struct lu_seq_range tmp;
69 LASSERT(range != NULL);
71 if (count == 5 && strcmp(buffer, "clear") == 0) {
72 memset(range, 0, sizeof(*range));
76 rc = sscanf(buffer, "[%llx - %llx]\n",
77 (long long unsigned *)&tmp.lsr_start,
78 (long long unsigned *)&tmp.lsr_end);
79 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
86 seq_proc_read_common(char *page, char **start, off_t off,
87 int count, int *eof, void *data,
88 struct lu_seq_range *range)
94 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
99 #ifdef HAVE_SERVER_SUPPORT
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 struct lprocfs_vars seq_server_proc_list[] = {
219 seq_server_proc_read_space, seq_server_proc_write_space, NULL },
221 seq_server_proc_read_width, seq_server_proc_write_width, NULL },
223 seq_server_proc_read_server, NULL, NULL },
227 struct fld_seq_param {
228 struct lu_env fsp_env;
229 struct dt_it *fsp_it;
230 struct lu_server_fld *fsp_fld;
231 struct lu_server_seq *fsp_seq;
232 unsigned int fsp_stop:1;
236 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
237 * we want to avoid this duplication either by exporting the
238 * functions or merging fid and fld into a single module.
240 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
242 struct fld_seq_param *param = p->private;
243 struct lu_server_fld *fld;
244 struct dt_object *obj;
245 const struct dt_it_ops *iops;
247 if (param == NULL || param->fsp_stop)
250 fld = param->fsp_fld;
252 LASSERT(obj != NULL);
253 iops = &obj->do_index_ops->dio_it;
255 iops->load(¶m->fsp_env, param->fsp_it, *pos);
257 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
261 static void fldb_seq_stop(struct seq_file *p, void *v)
263 struct fld_seq_param *param = p->private;
264 const struct dt_it_ops *iops;
265 struct lu_server_fld *fld;
266 struct dt_object *obj;
271 fld = param->fsp_fld;
273 LASSERT(obj != NULL);
274 iops = &obj->do_index_ops->dio_it;
276 iops->put(¶m->fsp_env, param->fsp_it);
279 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
281 struct fld_seq_param *param = p->private;
282 struct lu_server_fld *fld;
283 struct dt_object *obj;
284 const struct dt_it_ops *iops;
287 if (param == NULL || param->fsp_stop)
290 fld = param->fsp_fld;
292 LASSERT(obj != NULL);
293 iops = &obj->do_index_ops->dio_it;
295 rc = iops->next(¶m->fsp_env, param->fsp_it);
301 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
305 static int fldb_seq_show(struct seq_file *p, void *v)
307 struct fld_seq_param *param = p->private;
308 struct lu_server_fld *fld;
309 struct dt_object *obj;
310 const struct dt_it_ops *iops;
311 struct lu_seq_range fld_rec;
314 if (param == NULL || param->fsp_stop)
317 fld = param->fsp_fld;
319 LASSERT(obj != NULL);
320 iops = &obj->do_index_ops->dio_it;
322 rc = iops->rec(¶m->fsp_env, param->fsp_it,
323 (struct dt_rec *)&fld_rec, 0);
325 CERROR("%s: read record error: rc = %d\n",
327 } else if (fld_rec.lsr_start != 0) {
328 range_be_to_cpu(&fld_rec, &fld_rec);
329 rc = seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
335 struct seq_operations fldb_sops = {
336 .start = fldb_seq_start,
337 .stop = fldb_seq_stop,
338 .next = fldb_seq_next,
339 .show = fldb_seq_show,
342 static int fldb_seq_open(struct inode *inode, struct file *file)
344 struct proc_dir_entry *dp = PDE(inode);
345 struct seq_file *seq;
346 struct lu_server_seq *ss = (struct lu_server_seq *)dp->data;
347 struct lu_server_fld *fld;
348 struct dt_object *obj;
349 const struct dt_it_ops *iops;
350 struct fld_seq_param *param = NULL;
354 fld = ss->lss_site->ss_server_fld;
355 LASSERT(fld != NULL);
357 LPROCFS_ENTRY_CHECK(dp);
358 rc = seq_open(file, &fldb_sops);
364 seq = file->private_data;
369 OBD_ALLOC_PTR(param);
371 GOTO(out, rc = -ENOMEM);
373 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
378 iops = &obj->do_index_ops->dio_it;
379 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
380 if (IS_ERR(param->fsp_it))
381 GOTO(out, rc = PTR_ERR(param->fsp_it));
383 param->fsp_fld = fld;
387 seq = file->private_data;
388 seq->private = param;
392 lu_env_fini(¶m->fsp_env);
399 static int fldb_seq_release(struct inode *inode, struct file *file)
401 struct seq_file *seq = file->private_data;
402 struct fld_seq_param *param;
403 struct lu_server_fld *fld;
404 struct dt_object *obj;
405 const struct dt_it_ops *iops;
407 param = seq->private;
409 lprocfs_seq_release(inode, file);
413 fld = param->fsp_fld;
415 LASSERT(obj != NULL);
416 iops = &obj->do_index_ops->dio_it;
418 LASSERT(iops != NULL);
419 LASSERT(obj != NULL);
420 LASSERT(param->fsp_it != NULL);
421 iops->fini(¶m->fsp_env, param->fsp_it);
422 lu_env_fini(¶m->fsp_env);
424 lprocfs_seq_release(inode, file);
429 static ssize_t fldb_seq_write(struct file *file, const char *buf,
430 size_t len, loff_t *off)
432 struct seq_file *seq = file->private_data;
433 struct fld_seq_param *param;
434 struct lu_seq_range range;
436 char *buffer, *_buffer;
439 param = seq->private;
443 OBD_ALLOC(buffer, len + 1);
446 memcpy(buffer, buf, len);
451 * format - [0x0000000200000007-0x0000000200000008):0:mdt
454 GOTO(out, rc = -EINVAL);
457 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
459 GOTO(out, rc = -EINVAL);
462 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
464 GOTO(out, rc = -EINVAL);
467 GOTO(out, rc = -EINVAL);
470 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
472 GOTO(out, rc = -EINVAL);
475 if (strncmp(buffer, "mdt", 3) == 0)
476 range.lsr_flags = LU_SEQ_RANGE_MDT;
477 else if (strncmp(buffer, "ost", 3) == 0)
478 range.lsr_flags = LU_SEQ_RANGE_OST;
480 GOTO(out, rc = -EINVAL);
482 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
483 &range, ¶m->fsp_env);
486 OBD_FREE(_buffer, len + 1);
487 RETURN(rc < 0 ? rc : len);
490 const struct file_operations seq_fld_proc_seq_fops = {
491 .owner = THIS_MODULE,
492 .open = fldb_seq_open,
494 .write = fldb_seq_write,
495 .release = fldb_seq_release,
498 #endif /* HAVE_SERVER_SUPPORT */
500 /* Client side procfs stuff */
502 seq_client_proc_write_space(struct file *file, const char *buffer,
503 unsigned long count, void *data)
505 struct lu_client_seq *seq = (struct lu_client_seq *)data;
509 LASSERT(seq != NULL);
511 mutex_lock(&seq->lcs_mutex);
512 rc = seq_proc_write_common(file, buffer, count,
513 data, &seq->lcs_space);
516 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
517 seq->lcs_name, PRANGE(&seq->lcs_space));
520 mutex_unlock(&seq->lcs_mutex);
526 seq_client_proc_read_space(char *page, char **start, off_t off,
527 int count, int *eof, void *data)
529 struct lu_client_seq *seq = (struct lu_client_seq *)data;
533 LASSERT(seq != NULL);
535 mutex_lock(&seq->lcs_mutex);
536 rc = seq_proc_read_common(page, start, off, count, eof,
537 data, &seq->lcs_space);
538 mutex_unlock(&seq->lcs_mutex);
544 seq_client_proc_write_width(struct file *file, const char *buffer,
545 unsigned long count, void *data)
547 struct lu_client_seq *seq = (struct lu_client_seq *)data;
552 LASSERT(seq != NULL);
554 mutex_lock(&seq->lcs_mutex);
556 rc = lprocfs_write_helper(buffer, count, &val);
558 mutex_unlock(&seq->lcs_mutex);
562 if (seq->lcs_type == LUSTRE_SEQ_DATA)
563 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
565 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
567 if (val <= max && val > 0) {
568 seq->lcs_width = val;
571 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
572 seq->lcs_name, seq->lcs_width);
576 mutex_unlock(&seq->lcs_mutex);
582 seq_client_proc_read_width(char *page, char **start, off_t off,
583 int count, int *eof, void *data)
585 struct lu_client_seq *seq = (struct lu_client_seq *)data;
589 LASSERT(seq != NULL);
591 mutex_lock(&seq->lcs_mutex);
592 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
593 mutex_unlock(&seq->lcs_mutex);
599 seq_client_proc_read_fid(char *page, char **start, off_t off,
600 int count, int *eof, void *data)
602 struct lu_client_seq *seq = (struct lu_client_seq *)data;
606 LASSERT(seq != NULL);
608 mutex_lock(&seq->lcs_mutex);
609 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
610 mutex_unlock(&seq->lcs_mutex);
616 seq_client_proc_read_server(char *page, char **start, off_t off,
617 int count, int *eof, void *data)
619 struct lu_client_seq *seq = (struct lu_client_seq *)data;
620 struct client_obd *cli;
624 LASSERT(seq != NULL);
626 if (seq->lcs_exp != NULL) {
627 cli = &seq->lcs_exp->exp_obd->u.cli;
628 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
630 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
635 struct lprocfs_vars seq_client_proc_list[] = {
636 { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL },
637 { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL },
638 { "server", seq_client_proc_read_server, NULL, NULL },
639 { "fid", seq_client_proc_read_fid, NULL, NULL },