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, 2015, 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"
56 /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
57 #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
59 * Reduce the SEQ range allocated to a node to a strict subset of the range
60 * currently-allocated SEQ range. If the specified range is "clear", then
61 * drop all allocated sequences and request a new one from the master.
63 * Note: this function should only be used for testing, it is not necessarily
64 * safe for production use.
67 lprocfs_fid_write_common(const char __user *buffer, size_t count,
68 struct lu_seq_range *range)
70 struct lu_seq_range tmp = { 0, };
72 char kernbuf[MAX_FID_RANGE_STRLEN];
75 LASSERT(range != NULL);
77 if (count >= sizeof(kernbuf))
80 if (copy_from_user(kernbuf, buffer, count))
85 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
86 memset(range, 0, sizeof(*range));
90 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
91 rc = sscanf(kernbuf, "[%llx - %llx]\n",
92 (long long unsigned *)&tmp.lsr_start,
93 (long long unsigned *)&tmp.lsr_end);
94 if (!lu_seq_range_is_sane(&tmp) || lu_seq_range_is_zero(&tmp) ||
95 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
101 #ifdef HAVE_SERVER_SUPPORT
103 * Server side procfs stuff.
106 lprocfs_server_fid_space_seq_write(struct file *file, const char __user *buffer,
107 size_t count, loff_t *off)
109 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
113 LASSERT(seq != NULL);
115 mutex_lock(&seq->lss_mutex);
116 rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
118 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
119 seq->lss_name, PRANGE(&seq->lss_space));
121 mutex_unlock(&seq->lss_mutex);
127 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
129 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
132 LASSERT(seq != NULL);
134 mutex_lock(&seq->lss_mutex);
135 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lss_space));
136 mutex_unlock(&seq->lss_mutex);
142 lprocfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
144 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
145 struct client_obd *cli;
148 LASSERT(seq != NULL);
151 if (seq->lss_cli->lcs_exp != NULL) {
152 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
153 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
155 seq_printf(m, "%s\n", seq->lss_cli->lcs_srv->lss_name);
158 seq_puts(m, "<none>\n");
165 lprocfs_server_fid_width_seq_write(struct file *file, const char __user *buffer,
166 size_t count, loff_t *off)
168 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
173 LASSERT(seq != NULL);
175 mutex_lock(&seq->lss_mutex);
177 rc = lprocfs_str_to_s64(buffer, count, &val);
179 CERROR("%s: invalid FID sequence width: rc = %d\n",
181 GOTO(out_unlock, count = rc);
185 CERROR("%s: invalid FID sequence width: rc = %d\n",
186 seq->lss_name, -ERANGE);
187 GOTO(out_unlock, count = -ERANGE);
190 seq->lss_width = val;
192 CDEBUG(D_INFO, "%s: Width: %llu\n",
193 seq->lss_name, seq->lss_width);
195 mutex_unlock(&seq->lss_mutex);
201 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
203 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
206 LASSERT(seq != NULL);
208 mutex_lock(&seq->lss_mutex);
209 seq_printf(m, "%llu\n", seq->lss_width);
210 mutex_unlock(&seq->lss_mutex);
215 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
216 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
217 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
219 struct lprocfs_vars seq_server_proc_list[] = {
221 .fops = &lprocfs_server_fid_space_fops },
223 .fops = &lprocfs_server_fid_width_fops },
225 .fops = &lprocfs_server_fid_server_fops },
229 struct fld_seq_param {
230 struct lu_env fsp_env;
231 struct dt_it *fsp_it;
232 struct lu_server_fld *fsp_fld;
233 struct lu_server_seq *fsp_seq;
234 unsigned int fsp_stop:1;
238 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
239 * we want to avoid this duplication either by exporting the
240 * functions or merging fid and fld into a single module.
242 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
244 struct fld_seq_param *param = p->private;
245 struct lu_server_fld *fld;
246 struct dt_object *obj;
247 const struct dt_it_ops *iops;
251 if (param == NULL || param->fsp_stop)
254 fld = param->fsp_fld;
256 LASSERT(obj != NULL);
257 iops = &obj->do_index_ops->dio_it;
259 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
263 key = iops->key(¶m->fsp_env, param->fsp_it);
267 *pos = be64_to_cpu(*(__u64 *)key);
272 static void fldb_seq_stop(struct seq_file *p, void *v)
274 struct fld_seq_param *param = p->private;
275 const struct dt_it_ops *iops;
276 struct lu_server_fld *fld;
277 struct dt_object *obj;
282 fld = param->fsp_fld;
284 LASSERT(obj != NULL);
285 iops = &obj->do_index_ops->dio_it;
287 iops->put(¶m->fsp_env, param->fsp_it);
290 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
292 struct fld_seq_param *param = p->private;
293 struct lu_server_fld *fld;
294 struct dt_object *obj;
295 const struct dt_it_ops *iops;
298 if (param == NULL || param->fsp_stop)
301 fld = param->fsp_fld;
303 LASSERT(obj != NULL);
304 iops = &obj->do_index_ops->dio_it;
306 rc = iops->next(¶m->fsp_env, param->fsp_it);
312 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
316 static int fldb_seq_show(struct seq_file *p, void *v)
318 struct fld_seq_param *param = p->private;
319 struct lu_server_fld *fld;
320 struct dt_object *obj;
321 const struct dt_it_ops *iops;
322 struct lu_seq_range fld_rec;
325 if (param == NULL || param->fsp_stop)
328 fld = param->fsp_fld;
330 LASSERT(obj != NULL);
331 iops = &obj->do_index_ops->dio_it;
333 rc = iops->rec(¶m->fsp_env, param->fsp_it,
334 (struct dt_rec *)&fld_rec, 0);
336 CERROR("%s: read record error: rc = %d\n",
338 } else if (fld_rec.lsr_start != 0) {
339 range_be_to_cpu(&fld_rec, &fld_rec);
340 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
346 struct seq_operations fldb_sops = {
347 .start = fldb_seq_start,
348 .stop = fldb_seq_stop,
349 .next = fldb_seq_next,
350 .show = fldb_seq_show,
353 static int fldb_seq_open(struct inode *inode, struct file *file)
355 struct seq_file *seq;
356 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
357 struct lu_server_fld *fld;
358 struct dt_object *obj;
359 const struct dt_it_ops *iops;
360 struct fld_seq_param *param = NULL;
364 fld = ss->lss_site->ss_server_fld;
365 LASSERT(fld != NULL);
367 rc = LPROCFS_ENTRY_CHECK(inode);
371 rc = seq_open(file, &fldb_sops);
377 seq = file->private_data;
382 OBD_ALLOC_PTR(param);
384 GOTO(out, rc = -ENOMEM);
386 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
391 iops = &obj->do_index_ops->dio_it;
392 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
393 if (IS_ERR(param->fsp_it))
394 GOTO(out, rc = PTR_ERR(param->fsp_it));
396 param->fsp_fld = fld;
400 seq = file->private_data;
401 seq->private = param;
405 lu_env_fini(¶m->fsp_env);
412 static int fldb_seq_release(struct inode *inode, struct file *file)
414 struct seq_file *seq = file->private_data;
415 struct fld_seq_param *param;
416 struct lu_server_fld *fld;
417 struct dt_object *obj;
418 const struct dt_it_ops *iops;
420 param = seq->private;
422 lprocfs_seq_release(inode, file);
426 fld = param->fsp_fld;
428 LASSERT(obj != NULL);
429 iops = &obj->do_index_ops->dio_it;
431 LASSERT(iops != NULL);
432 LASSERT(param->fsp_it != NULL);
433 iops->fini(¶m->fsp_env, param->fsp_it);
434 lu_env_fini(¶m->fsp_env);
436 lprocfs_seq_release(inode, file);
441 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
442 size_t len, loff_t *off)
444 struct seq_file *seq = file->private_data;
445 struct fld_seq_param *param;
446 struct lu_seq_range range;
448 char _buffer[MAX_FID_RANGE_STRLEN];
449 char *buffer = _buffer;
452 param = seq->private;
456 if (len >= sizeof(_buffer))
459 if (copy_from_user(buffer, buf, len))
460 GOTO(out, rc = -EFAULT);
464 * format - [0x0000000200000007-0x0000000200000008):0:mdt
467 GOTO(out, rc = -EINVAL);
470 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
472 GOTO(out, rc = -EINVAL);
475 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
477 GOTO(out, rc = -EINVAL);
480 GOTO(out, rc = -EINVAL);
483 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
485 GOTO(out, rc = -EINVAL);
488 if (strncmp(buffer, "mdt", 3) == 0)
489 range.lsr_flags = LU_SEQ_RANGE_MDT;
490 else if (strncmp(buffer, "ost", 3) == 0)
491 range.lsr_flags = LU_SEQ_RANGE_OST;
493 GOTO(out, rc = -EINVAL);
495 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
496 &range, ¶m->fsp_env);
499 RETURN(rc < 0 ? rc : len);
502 const struct file_operations seq_fld_proc_seq_fops = {
503 .owner = THIS_MODULE,
504 .open = fldb_seq_open,
506 .write = fldb_seq_write,
507 .release = fldb_seq_release,
510 #endif /* HAVE_SERVER_SUPPORT */
512 /* Client side procfs stuff */
514 lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
515 size_t count, loff_t *off)
517 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
521 LASSERT(seq != NULL);
523 mutex_lock(&seq->lcs_mutex);
524 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
526 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
527 seq->lcs_name, PRANGE(&seq->lcs_space));
530 mutex_unlock(&seq->lcs_mutex);
536 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
538 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
541 LASSERT(seq != NULL);
543 mutex_lock(&seq->lcs_mutex);
544 seq_printf(m, "[%#llx - %#llx]:%x:%s\n",
545 PRANGE(&seq->lcs_space));
546 mutex_unlock(&seq->lcs_mutex);
552 lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
553 size_t count, loff_t *off)
555 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
561 LASSERT(seq != NULL);
563 mutex_lock(&seq->lcs_mutex);
565 rc = lprocfs_str_to_s64(buffer, count, &val);
567 GOTO(out_unlock, count = rc);
570 if (seq->lcs_type == LUSTRE_SEQ_DATA)
571 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
573 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
575 if (val <= max && val > 0) {
576 seq->lcs_width = val;
578 CDEBUG(D_INFO, "%s: Sequence size: %llu\n",
579 seq->lcs_name, seq->lcs_width);
581 GOTO(out_unlock, count = -ERANGE);
585 mutex_unlock(&seq->lcs_mutex);
590 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
592 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
595 LASSERT(seq != NULL);
597 mutex_lock(&seq->lcs_mutex);
598 seq_printf(m, "%llu\n", seq->lcs_width);
599 mutex_unlock(&seq->lcs_mutex);
605 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
607 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
610 LASSERT(seq != NULL);
612 mutex_lock(&seq->lcs_mutex);
613 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
614 mutex_unlock(&seq->lcs_mutex);
620 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
622 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
623 struct client_obd *cli;
626 LASSERT(seq != NULL);
628 if (seq->lcs_exp != NULL) {
629 cli = &seq->lcs_exp->exp_obd->u.cli;
630 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
632 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
637 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
638 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
639 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
640 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
642 struct lprocfs_vars seq_client_proc_list[] = {
644 .fops = &lprocfs_client_fid_space_fops },
646 .fops = &lprocfs_client_fid_width_fops },
648 .fops = &lprocfs_client_fid_server_fops },
650 .fops = &lprocfs_client_fid_fid_fops },
654 #endif /* CONFIG_PROC_FS */