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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/fid/lproc_fid.c
34 * Lustre Sequence Manager
36 * Author: Yury Umanets <umka@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_FID
41 #include <libcfs/libcfs.h>
42 #include <linux/module.h>
44 #include <obd_class.h>
45 #include <obd_support.h>
46 #include <lustre_fid.h>
47 #include <lprocfs_status.h>
48 #include "fid_internal.h"
50 /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
51 #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
53 * Reduce the SEQ range allocated to a node to a strict subset of the range
54 * currently-allocated SEQ range. If the specified range is "clear", then
55 * drop all allocated sequences and request a new one from the master.
57 * Note: this function should only be used for testing, it is not necessarily
58 * safe for production use.
61 ldebugfs_fid_write_common(const char __user *buffer, size_t count,
62 struct lu_seq_range *range)
64 char kernbuf[MAX_FID_RANGE_STRLEN];
65 struct lu_seq_range tmp = {
73 if (count >= sizeof(kernbuf))
76 if (copy_from_user(kernbuf, buffer, count))
81 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
82 memset(range, 0, sizeof(*range));
86 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
87 rc = sscanf(kernbuf, "[%llx - %llx]\n",
88 (unsigned long long *)&tmp.lsr_start,
89 (unsigned long long *)&tmp.lsr_end);
92 if (!lu_seq_range_is_sane(&tmp) || lu_seq_range_is_zero(&tmp) ||
93 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
99 #ifdef HAVE_SERVER_SUPPORT
101 * Server side debugfs stuff.
104 ldebugfs_server_fid_space_seq_write(struct file *file,
105 const char __user *buffer,
106 size_t count, loff_t *off)
108 struct seq_file *m = file->private_data;
109 struct lu_server_seq *seq = m->private;
114 mutex_lock(&seq->lss_mutex);
115 rc = ldebugfs_fid_write_common(buffer, count, &seq->lss_space);
117 CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
118 seq->lss_name, PRANGE(&seq->lss_space));
120 mutex_unlock(&seq->lss_mutex);
126 ldebugfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
128 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
131 mutex_lock(&seq->lss_mutex);
132 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lss_space));
133 mutex_unlock(&seq->lss_mutex);
139 ldebugfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
141 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
142 struct client_obd *cli;
146 if (seq->lss_cli->lcs_exp != NULL) {
147 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
148 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
150 seq_printf(m, "%s\n", seq->lss_cli->lcs_srv->lss_name);
153 seq_puts(m, "<none>\n");
159 static ssize_t ldebugfs_server_fid_width_seq_write(struct file *file,
160 const char __user *buffer,
161 size_t count, loff_t *off)
163 struct seq_file *m = file->private_data;
164 struct lu_server_seq *seq = m->private;
168 mutex_lock(&seq->lss_mutex);
170 rc = kstrtoull_from_user(buffer, count, 0, &seq->lss_width);
172 CERROR("%s: invalid FID sequence width: rc = %d\n",
174 GOTO(out_unlock, count = rc);
177 CDEBUG(D_INFO, "%s: Width: %llu\n",
178 seq->lss_name, seq->lss_width);
180 mutex_unlock(&seq->lss_mutex);
186 ldebugfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
188 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
191 mutex_lock(&seq->lss_mutex);
192 seq_printf(m, "%llu\n", seq->lss_width);
193 mutex_unlock(&seq->lss_mutex);
198 LDEBUGFS_SEQ_FOPS(ldebugfs_server_fid_space);
199 LDEBUGFS_SEQ_FOPS(ldebugfs_server_fid_width);
200 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_server_fid_server);
202 struct ldebugfs_vars seq_server_debugfs_list[] = {
204 .fops = &ldebugfs_server_fid_space_fops },
206 .fops = &ldebugfs_server_fid_width_fops },
208 .fops = &ldebugfs_server_fid_server_fops},
212 struct fld_seq_param {
213 struct lu_env fsp_env;
214 struct dt_it *fsp_it;
215 struct lu_server_fld *fsp_fld;
216 struct lu_server_seq *fsp_seq;
217 unsigned int fsp_stop:1;
221 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
222 * we want to avoid this duplication either by exporting the
223 * functions or merging fid and fld into a single module.
225 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
227 struct fld_seq_param *param = p->private;
228 struct lu_server_fld *fld;
229 struct dt_object *obj;
230 const struct dt_it_ops *iops;
234 if (param == NULL || param->fsp_stop)
237 fld = param->fsp_fld;
239 LASSERT(obj != NULL);
240 iops = &obj->do_index_ops->dio_it;
242 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
246 key = iops->key(¶m->fsp_env, param->fsp_it);
250 *pos = be64_to_cpu(*(__u64 *)key);
255 static void fldb_seq_stop(struct seq_file *p, void *v)
257 struct fld_seq_param *param = p->private;
258 const struct dt_it_ops *iops;
259 struct lu_server_fld *fld;
260 struct dt_object *obj;
265 fld = param->fsp_fld;
267 LASSERT(obj != NULL);
268 iops = &obj->do_index_ops->dio_it;
270 iops->put(¶m->fsp_env, param->fsp_it);
273 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
275 struct fld_seq_param *param = p->private;
276 struct lu_server_fld *fld;
277 struct dt_object *obj;
278 const struct dt_it_ops *iops;
282 if (param == NULL || param->fsp_stop)
285 fld = param->fsp_fld;
287 LASSERT(obj != NULL);
288 iops = &obj->do_index_ops->dio_it;
290 rc = iops->next(¶m->fsp_env, param->fsp_it);
296 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
300 static int fldb_seq_show(struct seq_file *p, void *v)
302 struct fld_seq_param *param = p->private;
303 struct lu_server_fld *fld;
304 struct dt_object *obj;
305 const struct dt_it_ops *iops;
306 struct lu_seq_range fld_rec;
309 if (param == NULL || param->fsp_stop)
312 fld = param->fsp_fld;
314 LASSERT(obj != NULL);
315 iops = &obj->do_index_ops->dio_it;
317 rc = iops->rec(¶m->fsp_env, param->fsp_it,
318 (struct dt_rec *)&fld_rec, 0);
320 CERROR("%s: read record error: rc = %d\n",
322 } else if (fld_rec.lsr_start != 0) {
323 range_be_to_cpu(&fld_rec, &fld_rec);
324 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
330 static const struct seq_operations fldb_sops = {
331 .start = fldb_seq_start,
332 .stop = fldb_seq_stop,
333 .next = fldb_seq_next,
334 .show = fldb_seq_show,
337 static int fldb_seq_open(struct inode *inode, struct file *file)
339 struct seq_file *seq;
340 struct lu_server_seq *ss = inode->i_private;
341 struct lu_server_fld *fld;
342 struct dt_object *obj;
343 const struct dt_it_ops *iops;
344 struct fld_seq_param *param = NULL;
348 fld = ss->lss_site->ss_server_fld;
349 LASSERT(fld != NULL);
351 rc = seq_open(file, &fldb_sops);
357 seq = file->private_data;
362 OBD_ALLOC_PTR(param);
364 GOTO(out, rc = -ENOMEM);
366 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
371 iops = &obj->do_index_ops->dio_it;
372 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
373 if (IS_ERR(param->fsp_it))
374 GOTO(out, rc = PTR_ERR(param->fsp_it));
376 param->fsp_fld = fld;
380 seq = file->private_data;
381 seq->private = param;
385 lu_env_fini(¶m->fsp_env);
392 static int fldb_seq_release(struct inode *inode, struct file *file)
394 struct seq_file *seq = file->private_data;
395 struct fld_seq_param *param;
396 struct lu_server_fld *fld;
397 struct dt_object *obj;
398 const struct dt_it_ops *iops;
400 param = seq->private;
402 seq_release(inode, file);
406 fld = param->fsp_fld;
408 LASSERT(obj != NULL);
409 iops = &obj->do_index_ops->dio_it;
411 LASSERT(iops != NULL);
412 LASSERT(param->fsp_it != NULL);
413 iops->fini(¶m->fsp_env, param->fsp_it);
414 lu_env_fini(¶m->fsp_env);
416 seq_release(inode, file);
421 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
422 size_t len, loff_t *off)
424 struct seq_file *seq = file->private_data;
425 struct fld_seq_param *param;
426 struct lu_seq_range range;
428 char _buffer[MAX_FID_RANGE_STRLEN];
429 char *buffer = _buffer;
433 param = seq->private;
437 if (len >= sizeof(_buffer))
440 if (copy_from_user(buffer, buf, len))
441 GOTO(out, rc = -EFAULT);
445 * format - [0x0000000200000007-0x0000000200000008):0:mdt
448 GOTO(out, rc = -EINVAL);
451 tmp = strchr(buffer, '-');
453 GOTO(out, rc = -EINVAL);
455 rc = kstrtoull(buffer, 0, &range.lsr_start);
460 tmp = strchr(buffer, ')');
462 GOTO(out, rc = -EINVAL);
464 rc = kstrtoull(buffer, 0, &range.lsr_end);
470 GOTO(out, rc = -EINVAL);
473 tmp = strchr(buffer, ':');
475 GOTO(out, rc = -EINVAL);
477 rc = kstrtouint(buffer, 0, &range.lsr_index);
482 if (strncmp(buffer, "mdt", 3) == 0)
483 range.lsr_flags = LU_SEQ_RANGE_MDT;
484 else if (strncmp(buffer, "ost", 3) == 0)
485 range.lsr_flags = LU_SEQ_RANGE_OST;
487 GOTO(out, rc = -EINVAL);
489 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
490 &range, ¶m->fsp_env);
493 RETURN(rc < 0 ? rc : len);
496 const struct file_operations seq_fld_debugfs_seq_fops = {
497 .owner = THIS_MODULE,
498 .open = fldb_seq_open,
500 .write = fldb_seq_write,
501 .release = fldb_seq_release,
504 #endif /* HAVE_SERVER_SUPPORT */
506 /* Client side debugfs stuff */
508 ldebugfs_client_fid_space_seq_write(struct file *file,
509 const char __user *buffer,
510 size_t count, loff_t *off)
512 struct seq_file *m = file->private_data;
513 struct lu_client_seq *seq = m->private;
518 mutex_lock(&seq->lcs_mutex);
519 rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
521 CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
522 seq->lcs_name, PRANGE(&seq->lcs_space));
525 mutex_unlock(&seq->lcs_mutex);
530 static int ldebugfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
532 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
535 mutex_lock(&seq->lcs_mutex);
536 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
537 mutex_unlock(&seq->lcs_mutex);
542 static ssize_t ldebugfs_client_fid_width_seq_write(struct file *file,
543 const char __user *buffer,
544 size_t count, loff_t *off)
546 struct seq_file *m = file->private_data;
547 struct lu_client_seq *seq = m->private;
553 rc = kstrtoull_from_user(buffer, count, 0, &val);
557 mutex_lock(&seq->lcs_mutex);
558 if (seq->lcs_type == LUSTRE_SEQ_DATA)
559 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
561 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
564 seq->lcs_width = val;
566 CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name,
572 mutex_unlock(&seq->lcs_mutex);
577 ldebugfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
579 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
582 mutex_lock(&seq->lcs_mutex);
583 seq_printf(m, "%llu\n", seq->lcs_width);
584 mutex_unlock(&seq->lcs_mutex);
590 ldebugfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
592 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
595 mutex_lock(&seq->lcs_mutex);
596 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
597 mutex_unlock(&seq->lcs_mutex);
603 ldebugfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
605 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
606 struct client_obd *cli;
610 cli = &seq->lcs_exp->exp_obd->u.cli;
611 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
612 #ifdef HAVE_SERVER_SUPPORT
614 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
615 #endif /* HAVE_SERVER_SUPPORT */
621 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_space);
622 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_width);
623 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_server);
624 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_fid);
626 struct ldebugfs_vars seq_client_debugfs_list[] = {
628 .fops = &ldebugfs_client_fid_space_fops },
630 .fops = &ldebugfs_client_fid_width_fops },
632 .fops = &ldebugfs_client_fid_server_fops},
634 .fops = &ldebugfs_client_fid_fid_fops },