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 lu_server_seq *seq;
112 seq = ((struct seq_file *)file->private_data)->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 lprocfs_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;
281 if (param == NULL || param->fsp_stop)
284 fld = param->fsp_fld;
286 LASSERT(obj != NULL);
287 iops = &obj->do_index_ops->dio_it;
289 rc = iops->next(¶m->fsp_env, param->fsp_it);
295 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
299 static int fldb_seq_show(struct seq_file *p, void *v)
301 struct fld_seq_param *param = p->private;
302 struct lu_server_fld *fld;
303 struct dt_object *obj;
304 const struct dt_it_ops *iops;
305 struct lu_seq_range fld_rec;
308 if (param == NULL || param->fsp_stop)
311 fld = param->fsp_fld;
313 LASSERT(obj != NULL);
314 iops = &obj->do_index_ops->dio_it;
316 rc = iops->rec(¶m->fsp_env, param->fsp_it,
317 (struct dt_rec *)&fld_rec, 0);
319 CERROR("%s: read record error: rc = %d\n",
321 } else if (fld_rec.lsr_start != 0) {
322 range_be_to_cpu(&fld_rec, &fld_rec);
323 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
329 struct seq_operations fldb_sops = {
330 .start = fldb_seq_start,
331 .stop = fldb_seq_stop,
332 .next = fldb_seq_next,
333 .show = fldb_seq_show,
336 static int fldb_seq_open(struct inode *inode, struct file *file)
338 struct seq_file *seq;
339 struct lu_server_seq *ss = inode->i_private;
340 struct lu_server_fld *fld;
341 struct dt_object *obj;
342 const struct dt_it_ops *iops;
343 struct fld_seq_param *param = NULL;
347 fld = ss->lss_site->ss_server_fld;
348 LASSERT(fld != NULL);
350 rc = seq_open(file, &fldb_sops);
356 seq = file->private_data;
361 OBD_ALLOC_PTR(param);
363 GOTO(out, rc = -ENOMEM);
365 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
370 iops = &obj->do_index_ops->dio_it;
371 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
372 if (IS_ERR(param->fsp_it))
373 GOTO(out, rc = PTR_ERR(param->fsp_it));
375 param->fsp_fld = fld;
379 seq = file->private_data;
380 seq->private = param;
384 lu_env_fini(¶m->fsp_env);
391 static int fldb_seq_release(struct inode *inode, struct file *file)
393 struct seq_file *seq = file->private_data;
394 struct fld_seq_param *param;
395 struct lu_server_fld *fld;
396 struct dt_object *obj;
397 const struct dt_it_ops *iops;
399 param = seq->private;
401 seq_release(inode, file);
405 fld = param->fsp_fld;
407 LASSERT(obj != NULL);
408 iops = &obj->do_index_ops->dio_it;
410 LASSERT(iops != NULL);
411 LASSERT(param->fsp_it != NULL);
412 iops->fini(¶m->fsp_env, param->fsp_it);
413 lu_env_fini(¶m->fsp_env);
415 seq_release(inode, file);
420 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
421 size_t len, loff_t *off)
423 struct seq_file *seq = file->private_data;
424 struct fld_seq_param *param;
425 struct lu_seq_range range;
427 char _buffer[MAX_FID_RANGE_STRLEN];
428 char *buffer = _buffer;
431 param = seq->private;
435 if (len >= sizeof(_buffer))
438 if (copy_from_user(buffer, buf, len))
439 GOTO(out, rc = -EFAULT);
443 * format - [0x0000000200000007-0x0000000200000008):0:mdt
446 GOTO(out, rc = -EINVAL);
449 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
451 GOTO(out, rc = -EINVAL);
454 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
456 GOTO(out, rc = -EINVAL);
459 GOTO(out, rc = -EINVAL);
462 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
464 GOTO(out, rc = -EINVAL);
467 if (strncmp(buffer, "mdt", 3) == 0)
468 range.lsr_flags = LU_SEQ_RANGE_MDT;
469 else if (strncmp(buffer, "ost", 3) == 0)
470 range.lsr_flags = LU_SEQ_RANGE_OST;
472 GOTO(out, rc = -EINVAL);
474 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
475 &range, ¶m->fsp_env);
478 RETURN(rc < 0 ? rc : len);
481 const struct file_operations seq_fld_debugfs_seq_fops = {
482 .owner = THIS_MODULE,
483 .open = fldb_seq_open,
485 .write = fldb_seq_write,
486 .release = fldb_seq_release,
489 #endif /* HAVE_SERVER_SUPPORT */
491 /* Client side debugfs stuff */
493 ldebugfs_client_fid_space_seq_write(struct file *file,
494 const char __user *buffer,
495 size_t count, loff_t *off)
497 struct lu_client_seq *seq;
501 seq = ((struct seq_file *)file->private_data)->private;
503 mutex_lock(&seq->lcs_mutex);
504 rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
506 CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
507 seq->lcs_name, PRANGE(&seq->lcs_space));
510 mutex_unlock(&seq->lcs_mutex);
515 static int ldebugfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
517 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
520 mutex_lock(&seq->lcs_mutex);
521 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
522 mutex_unlock(&seq->lcs_mutex);
527 static ssize_t ldebugfs_client_fid_width_seq_write(struct file *file,
528 const char __user *buffer,
529 size_t count, loff_t *off)
531 struct seq_file *m = file->private_data;
532 struct lu_client_seq *seq = m->private;
538 rc = kstrtoull_from_user(buffer, count, 0, &val);
542 mutex_lock(&seq->lcs_mutex);
543 if (seq->lcs_type == LUSTRE_SEQ_DATA)
544 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
546 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
549 seq->lcs_width = val;
551 CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name,
557 mutex_unlock(&seq->lcs_mutex);
562 ldebugfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
564 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
567 mutex_lock(&seq->lcs_mutex);
568 seq_printf(m, "%llu\n", seq->lcs_width);
569 mutex_unlock(&seq->lcs_mutex);
575 ldebugfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
577 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
580 mutex_lock(&seq->lcs_mutex);
581 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
582 mutex_unlock(&seq->lcs_mutex);
588 ldebugfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
590 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
591 struct client_obd *cli;
595 cli = &seq->lcs_exp->exp_obd->u.cli;
596 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
597 #ifdef HAVE_SERVER_SUPPORT
599 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
600 #endif /* HAVE_SERVER_SUPPORT */
606 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_space);
607 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_width);
608 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_server);
609 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_fid);
611 struct lprocfs_vars seq_client_debugfs_list[] = {
613 .fops = &ldebugfs_client_fid_space_fops },
615 .fops = &ldebugfs_client_fid_width_fops },
617 .fops = &ldebugfs_client_fid_server_fops},
619 .fops = &ldebugfs_client_fid_fid_fops },