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, 2016, 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"
52 /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
53 #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
55 * Reduce the SEQ range allocated to a node to a strict subset of the range
56 * currently-allocated SEQ range. If the specified range is "clear", then
57 * drop all allocated sequences and request a new one from the master.
59 * Note: this function should only be used for testing, it is not necessarily
60 * safe for production use.
63 lprocfs_fid_write_common(const char __user *buffer, size_t count,
64 struct lu_seq_range *range)
66 struct lu_seq_range tmp = {
69 char kernbuf[MAX_FID_RANGE_STRLEN];
72 LASSERT(range != NULL);
74 if (count >= sizeof(kernbuf))
77 if (copy_from_user(kernbuf, buffer, count))
82 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
83 memset(range, 0, sizeof(*range));
87 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
88 sscanf(kernbuf, "[%llx - %llx]\n",
89 (long long unsigned *)&tmp.lsr_start,
90 (long long unsigned *)&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 procfs stuff.
103 lprocfs_server_fid_space_seq_write(struct file *file, const char __user *buffer,
104 size_t count, loff_t *off)
106 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
110 LASSERT(seq != NULL);
112 mutex_lock(&seq->lss_mutex);
113 rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
115 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
116 seq->lss_name, PRANGE(&seq->lss_space));
118 mutex_unlock(&seq->lss_mutex);
124 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
126 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
129 LASSERT(seq != NULL);
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 lprocfs_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;
145 LASSERT(seq != NULL);
148 if (seq->lss_cli->lcs_exp != NULL) {
149 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
150 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
152 seq_printf(m, "%s\n", seq->lss_cli->lcs_srv->lss_name);
155 seq_puts(m, "<none>\n");
162 lprocfs_server_fid_width_seq_write(struct file *file, const char __user *buffer,
163 size_t count, loff_t *off)
165 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
170 LASSERT(seq != NULL);
172 mutex_lock(&seq->lss_mutex);
174 rc = lprocfs_str_to_s64(buffer, count, &val);
176 CERROR("%s: invalid FID sequence width: rc = %d\n",
178 GOTO(out_unlock, count = rc);
182 CERROR("%s: invalid FID sequence width: rc = %d\n",
183 seq->lss_name, -ERANGE);
184 GOTO(out_unlock, count = -ERANGE);
187 seq->lss_width = val;
189 CDEBUG(D_INFO, "%s: Width: %llu\n",
190 seq->lss_name, seq->lss_width);
192 mutex_unlock(&seq->lss_mutex);
198 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
200 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
203 LASSERT(seq != NULL);
205 mutex_lock(&seq->lss_mutex);
206 seq_printf(m, "%llu\n", seq->lss_width);
207 mutex_unlock(&seq->lss_mutex);
212 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
213 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
214 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
216 struct lprocfs_vars seq_server_proc_list[] = {
218 .fops = &lprocfs_server_fid_space_fops },
220 .fops = &lprocfs_server_fid_width_fops },
222 .fops = &lprocfs_server_fid_server_fops },
226 struct fld_seq_param {
227 struct lu_env fsp_env;
228 struct dt_it *fsp_it;
229 struct lu_server_fld *fsp_fld;
230 struct lu_server_seq *fsp_seq;
231 unsigned int fsp_stop:1;
235 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
236 * we want to avoid this duplication either by exporting the
237 * functions or merging fid and fld into a single module.
239 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
241 struct fld_seq_param *param = p->private;
242 struct lu_server_fld *fld;
243 struct dt_object *obj;
244 const struct dt_it_ops *iops;
248 if (param == NULL || param->fsp_stop)
251 fld = param->fsp_fld;
253 LASSERT(obj != NULL);
254 iops = &obj->do_index_ops->dio_it;
256 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
260 key = iops->key(¶m->fsp_env, param->fsp_it);
264 *pos = be64_to_cpu(*(__u64 *)key);
269 static void fldb_seq_stop(struct seq_file *p, void *v)
271 struct fld_seq_param *param = p->private;
272 const struct dt_it_ops *iops;
273 struct lu_server_fld *fld;
274 struct dt_object *obj;
279 fld = param->fsp_fld;
281 LASSERT(obj != NULL);
282 iops = &obj->do_index_ops->dio_it;
284 iops->put(¶m->fsp_env, param->fsp_it);
287 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
289 struct fld_seq_param *param = p->private;
290 struct lu_server_fld *fld;
291 struct dt_object *obj;
292 const struct dt_it_ops *iops;
295 if (param == NULL || param->fsp_stop)
298 fld = param->fsp_fld;
300 LASSERT(obj != NULL);
301 iops = &obj->do_index_ops->dio_it;
303 rc = iops->next(¶m->fsp_env, param->fsp_it);
309 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
313 static int fldb_seq_show(struct seq_file *p, void *v)
315 struct fld_seq_param *param = p->private;
316 struct lu_server_fld *fld;
317 struct dt_object *obj;
318 const struct dt_it_ops *iops;
319 struct lu_seq_range fld_rec;
322 if (param == NULL || param->fsp_stop)
325 fld = param->fsp_fld;
327 LASSERT(obj != NULL);
328 iops = &obj->do_index_ops->dio_it;
330 rc = iops->rec(¶m->fsp_env, param->fsp_it,
331 (struct dt_rec *)&fld_rec, 0);
333 CERROR("%s: read record error: rc = %d\n",
335 } else if (fld_rec.lsr_start != 0) {
336 range_be_to_cpu(&fld_rec, &fld_rec);
337 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
343 struct seq_operations fldb_sops = {
344 .start = fldb_seq_start,
345 .stop = fldb_seq_stop,
346 .next = fldb_seq_next,
347 .show = fldb_seq_show,
350 static int fldb_seq_open(struct inode *inode, struct file *file)
352 struct seq_file *seq;
353 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
354 struct lu_server_fld *fld;
355 struct dt_object *obj;
356 const struct dt_it_ops *iops;
357 struct fld_seq_param *param = NULL;
361 fld = ss->lss_site->ss_server_fld;
362 LASSERT(fld != NULL);
364 rc = LPROCFS_ENTRY_CHECK(inode);
368 rc = seq_open(file, &fldb_sops);
374 seq = file->private_data;
379 OBD_ALLOC_PTR(param);
381 GOTO(out, rc = -ENOMEM);
383 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
388 iops = &obj->do_index_ops->dio_it;
389 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
390 if (IS_ERR(param->fsp_it))
391 GOTO(out, rc = PTR_ERR(param->fsp_it));
393 param->fsp_fld = fld;
397 seq = file->private_data;
398 seq->private = param;
402 lu_env_fini(¶m->fsp_env);
409 static int fldb_seq_release(struct inode *inode, struct file *file)
411 struct seq_file *seq = file->private_data;
412 struct fld_seq_param *param;
413 struct lu_server_fld *fld;
414 struct dt_object *obj;
415 const struct dt_it_ops *iops;
417 param = seq->private;
419 lprocfs_seq_release(inode, file);
423 fld = param->fsp_fld;
425 LASSERT(obj != NULL);
426 iops = &obj->do_index_ops->dio_it;
428 LASSERT(iops != NULL);
429 LASSERT(param->fsp_it != NULL);
430 iops->fini(¶m->fsp_env, param->fsp_it);
431 lu_env_fini(¶m->fsp_env);
433 lprocfs_seq_release(inode, file);
438 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
439 size_t len, loff_t *off)
441 struct seq_file *seq = file->private_data;
442 struct fld_seq_param *param;
443 struct lu_seq_range range;
445 char _buffer[MAX_FID_RANGE_STRLEN];
446 char *buffer = _buffer;
449 param = seq->private;
453 if (len >= sizeof(_buffer))
456 if (copy_from_user(buffer, buf, len))
457 GOTO(out, rc = -EFAULT);
461 * format - [0x0000000200000007-0x0000000200000008):0:mdt
464 GOTO(out, rc = -EINVAL);
467 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
469 GOTO(out, rc = -EINVAL);
472 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
474 GOTO(out, rc = -EINVAL);
477 GOTO(out, rc = -EINVAL);
480 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
482 GOTO(out, rc = -EINVAL);
485 if (strncmp(buffer, "mdt", 3) == 0)
486 range.lsr_flags = LU_SEQ_RANGE_MDT;
487 else if (strncmp(buffer, "ost", 3) == 0)
488 range.lsr_flags = LU_SEQ_RANGE_OST;
490 GOTO(out, rc = -EINVAL);
492 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
493 &range, ¶m->fsp_env);
496 RETURN(rc < 0 ? rc : len);
499 const struct file_operations seq_fld_proc_seq_fops = {
500 .owner = THIS_MODULE,
501 .open = fldb_seq_open,
503 .write = fldb_seq_write,
504 .release = fldb_seq_release,
507 #endif /* HAVE_SERVER_SUPPORT */
509 /* Client side procfs stuff */
511 lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
512 size_t count, loff_t *off)
514 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
518 LASSERT(seq != NULL);
520 mutex_lock(&seq->lcs_mutex);
521 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
523 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
524 seq->lcs_name, PRANGE(&seq->lcs_space));
527 mutex_unlock(&seq->lcs_mutex);
533 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
535 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
538 LASSERT(seq != NULL);
540 mutex_lock(&seq->lcs_mutex);
541 seq_printf(m, "[%#llx - %#llx]:%x:%s\n",
542 PRANGE(&seq->lcs_space));
543 mutex_unlock(&seq->lcs_mutex);
549 lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
550 size_t count, loff_t *off)
552 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
558 LASSERT(seq != NULL);
560 mutex_lock(&seq->lcs_mutex);
562 rc = lprocfs_str_to_s64(buffer, count, &val);
564 GOTO(out_unlock, count = rc);
567 if (seq->lcs_type == LUSTRE_SEQ_DATA)
568 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
570 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
572 if (val <= max && val > 0) {
573 seq->lcs_width = val;
575 CDEBUG(D_INFO, "%s: Sequence size: %llu\n",
576 seq->lcs_name, seq->lcs_width);
578 GOTO(out_unlock, count = -ERANGE);
582 mutex_unlock(&seq->lcs_mutex);
587 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
589 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
592 LASSERT(seq != NULL);
594 mutex_lock(&seq->lcs_mutex);
595 seq_printf(m, "%llu\n", seq->lcs_width);
596 mutex_unlock(&seq->lcs_mutex);
602 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
604 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
607 LASSERT(seq != NULL);
609 mutex_lock(&seq->lcs_mutex);
610 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
611 mutex_unlock(&seq->lcs_mutex);
617 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
619 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
620 struct client_obd *cli;
623 LASSERT(seq != NULL);
625 if (seq->lcs_exp != NULL) {
626 cli = &seq->lcs_exp->exp_obd->u.cli;
627 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
629 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
634 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
635 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
636 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
637 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
639 struct lprocfs_vars seq_client_proc_list[] = {
641 .fops = &lprocfs_client_fid_space_fops },
643 .fops = &lprocfs_client_fid_width_fops },
645 .fops = &lprocfs_client_fid_server_fops },
647 .fops = &lprocfs_client_fid_fid_fops },
651 #endif /* CONFIG_PROC_FS */