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/
31 * lustre/fid/lproc_fid.c
33 * Lustre Sequence Manager
35 * Author: Yury Umanets <umka@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_FID
40 #include <libcfs/libcfs.h>
41 #include <linux/module.h>
43 #include <obd_class.h>
44 #include <obd_support.h>
45 #include <lustre_fid.h>
46 #include <lprocfs_status.h>
47 #include "fid_internal.h"
49 /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
50 #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
52 * Reduce the SEQ range allocated to a node to a strict subset of the range
53 * currently-allocated SEQ range. If the specified range is "clear", then
54 * drop all allocated sequences and request a new one from the master.
56 * Note: this function should only be used for testing, it is not necessarily
57 * safe for production use.
60 ldebugfs_fid_write_common(const char __user *buffer, size_t count,
61 struct lu_seq_range *range)
63 char kernbuf[MAX_FID_RANGE_STRLEN];
64 struct lu_seq_range tmp = {
72 if (count >= sizeof(kernbuf))
75 if (copy_from_user(kernbuf, buffer, count))
80 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
81 memset(range, 0, sizeof(*range));
85 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
86 rc = sscanf(kernbuf, "[%llx - %llx]\n",
87 (unsigned long long *)&tmp.lsr_start,
88 (unsigned long long *)&tmp.lsr_end);
91 if (!lu_seq_range_is_sane(&tmp) || lu_seq_range_is_zero(&tmp) ||
92 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
98 #ifdef HAVE_SERVER_SUPPORT
100 * Server side debugfs stuff.
103 ldebugfs_server_fid_space_seq_write(struct file *file,
104 const char __user *buffer,
105 size_t count, loff_t *off)
107 struct seq_file *m = file->private_data;
108 struct lu_server_seq *seq = m->private;
113 mutex_lock(&seq->lss_mutex);
114 rc = ldebugfs_fid_write_common(buffer, count, &seq->lss_space);
116 CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
117 seq->lss_name, PRANGE(&seq->lss_space));
119 mutex_unlock(&seq->lss_mutex);
125 ldebugfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
127 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
130 mutex_lock(&seq->lss_mutex);
131 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lss_space));
132 mutex_unlock(&seq->lss_mutex);
138 ldebugfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
140 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
141 struct client_obd *cli;
145 if (seq->lss_cli->lcs_exp != NULL) {
146 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
147 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
149 seq_printf(m, "%s\n", seq->lss_cli->lcs_srv->lss_name);
152 seq_puts(m, "<none>\n");
158 static ssize_t ldebugfs_server_fid_width_seq_write(struct file *file,
159 const char __user *buffer,
160 size_t count, loff_t *off)
162 struct seq_file *m = file->private_data;
163 struct lu_server_seq *seq = m->private;
167 mutex_lock(&seq->lss_mutex);
169 rc = kstrtoull_from_user(buffer, count, 0, &seq->lss_width);
171 CERROR("%s: invalid FID sequence width: rc = %d\n",
173 GOTO(out_unlock, count = rc);
176 CDEBUG(D_INFO, "%s: Width: %llu\n",
177 seq->lss_name, seq->lss_width);
179 mutex_unlock(&seq->lss_mutex);
185 ldebugfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
187 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
190 mutex_lock(&seq->lss_mutex);
191 seq_printf(m, "%llu\n", seq->lss_width);
192 mutex_unlock(&seq->lss_mutex);
197 LDEBUGFS_SEQ_FOPS(ldebugfs_server_fid_space);
198 LDEBUGFS_SEQ_FOPS(ldebugfs_server_fid_width);
199 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_server_fid_server);
201 struct ldebugfs_vars seq_server_debugfs_list[] = {
203 .fops = &ldebugfs_server_fid_space_fops },
205 .fops = &ldebugfs_server_fid_width_fops },
207 .fops = &ldebugfs_server_fid_server_fops},
211 struct fld_seq_param {
212 struct lu_env fsp_env;
213 struct dt_it *fsp_it;
214 struct lu_server_fld *fsp_fld;
215 struct lu_server_seq *fsp_seq;
216 unsigned int fsp_stop:1;
220 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
221 * we want to avoid this duplication either by exporting the
222 * functions or merging fid and fld into a single module.
224 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
226 struct fld_seq_param *param = p->private;
227 struct lu_server_fld *fld;
228 struct dt_object *obj;
229 const struct dt_it_ops *iops;
233 if (param == NULL || param->fsp_stop)
236 fld = param->fsp_fld;
238 LASSERT(obj != NULL);
239 iops = &obj->do_index_ops->dio_it;
241 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
245 key = iops->key(¶m->fsp_env, param->fsp_it);
249 *pos = be64_to_cpu(*(__u64 *)key);
254 static void fldb_seq_stop(struct seq_file *p, void *v)
256 struct fld_seq_param *param = p->private;
257 const struct dt_it_ops *iops;
258 struct lu_server_fld *fld;
259 struct dt_object *obj;
264 fld = param->fsp_fld;
266 LASSERT(obj != NULL);
267 iops = &obj->do_index_ops->dio_it;
269 iops->put(¶m->fsp_env, param->fsp_it);
272 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
274 struct fld_seq_param *param = p->private;
275 struct lu_server_fld *fld;
276 struct dt_object *obj;
277 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 static const 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;
432 param = seq->private;
436 if (len >= sizeof(_buffer))
439 if (copy_from_user(buffer, buf, len))
440 GOTO(out, rc = -EFAULT);
444 * format - [0x0000000200000007-0x0000000200000008):0:mdt
447 GOTO(out, rc = -EINVAL);
450 tmp = strchr(buffer, '-');
452 GOTO(out, rc = -EINVAL);
454 rc = kstrtoull(buffer, 0, &range.lsr_start);
459 tmp = strchr(buffer, ')');
461 GOTO(out, rc = -EINVAL);
463 rc = kstrtoull(buffer, 0, &range.lsr_end);
469 GOTO(out, rc = -EINVAL);
472 tmp = strchr(buffer, ':');
474 GOTO(out, rc = -EINVAL);
476 rc = kstrtouint(buffer, 0, &range.lsr_index);
481 if (strncmp(buffer, "mdt", 3) == 0)
482 range.lsr_flags = LU_SEQ_RANGE_MDT;
483 else if (strncmp(buffer, "ost", 3) == 0)
484 range.lsr_flags = LU_SEQ_RANGE_OST;
486 GOTO(out, rc = -EINVAL);
488 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
489 &range, ¶m->fsp_env);
492 RETURN(rc < 0 ? rc : len);
495 const struct file_operations seq_fld_debugfs_seq_fops = {
496 .owner = THIS_MODULE,
497 .open = fldb_seq_open,
499 .write = fldb_seq_write,
500 .release = fldb_seq_release,
503 #endif /* HAVE_SERVER_SUPPORT */
505 /* Client side debugfs stuff */
507 ldebugfs_client_fid_space_seq_write(struct file *file,
508 const char __user *buffer,
509 size_t count, loff_t *off)
511 struct seq_file *m = file->private_data;
512 struct lu_client_seq *seq = m->private;
517 mutex_lock(&seq->lcs_mutex);
518 rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
520 CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
521 seq->lcs_name, PRANGE(&seq->lcs_space));
524 mutex_unlock(&seq->lcs_mutex);
529 static int ldebugfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
531 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
534 mutex_lock(&seq->lcs_mutex);
535 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
536 mutex_unlock(&seq->lcs_mutex);
541 static ssize_t ldebugfs_client_fid_width_seq_write(struct file *file,
542 const char __user *buffer,
543 size_t count, loff_t *off)
545 struct seq_file *m = file->private_data;
546 struct lu_client_seq *seq = m->private;
552 rc = kstrtoull_from_user(buffer, count, 0, &val);
556 mutex_lock(&seq->lcs_mutex);
557 if (seq->lcs_type == LUSTRE_SEQ_DATA)
558 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
560 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
563 seq->lcs_width = val;
565 CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name,
571 mutex_unlock(&seq->lcs_mutex);
576 ldebugfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
578 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
581 mutex_lock(&seq->lcs_mutex);
582 seq_printf(m, "%llu\n", seq->lcs_width);
583 mutex_unlock(&seq->lcs_mutex);
589 ldebugfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
591 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
594 mutex_lock(&seq->lcs_mutex);
595 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
596 mutex_unlock(&seq->lcs_mutex);
602 ldebugfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
604 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
605 struct client_obd *cli;
609 cli = &seq->lcs_exp->exp_obd->u.cli;
610 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
611 #ifdef HAVE_SERVER_SUPPORT
613 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
614 #endif /* HAVE_SERVER_SUPPORT */
620 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_space);
621 LDEBUGFS_SEQ_FOPS(ldebugfs_client_fid_width);
622 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_server);
623 LDEBUGFS_SEQ_FOPS_RO(ldebugfs_client_fid_fid);
625 struct ldebugfs_vars seq_client_debugfs_list[] = {
627 .fops = &ldebugfs_client_fid_space_fops },
629 .fops = &ldebugfs_client_fid_width_fops },
631 .fops = &ldebugfs_client_fid_server_fops},
633 .fops = &ldebugfs_client_fid_fid_fops },