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"
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 = { 0, };
68 char kernbuf[MAX_FID_RANGE_STRLEN];
71 LASSERT(range != NULL);
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 (long long unsigned *)&tmp.lsr_start,
89 (long long unsigned *)&tmp.lsr_end);
90 if (!lu_seq_range_is_sane(&tmp) || lu_seq_range_is_zero(&tmp) ||
91 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
97 #ifdef HAVE_SERVER_SUPPORT
99 * Server side procfs stuff.
102 lprocfs_server_fid_space_seq_write(struct file *file, const char __user *buffer,
103 size_t count, loff_t *off)
105 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
109 LASSERT(seq != NULL);
111 mutex_lock(&seq->lss_mutex);
112 rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
114 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
115 seq->lss_name, PRANGE(&seq->lss_space));
117 mutex_unlock(&seq->lss_mutex);
123 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
125 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
128 LASSERT(seq != NULL);
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 lprocfs_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;
144 LASSERT(seq != NULL);
147 if (seq->lss_cli->lcs_exp != NULL) {
148 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
149 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
151 seq_printf(m, "%s\n", seq->lss_cli->lcs_srv->lss_name);
154 seq_puts(m, "<none>\n");
161 lprocfs_server_fid_width_seq_write(struct file *file, const char __user *buffer,
162 size_t count, loff_t *off)
164 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
169 LASSERT(seq != NULL);
171 mutex_lock(&seq->lss_mutex);
173 rc = lprocfs_str_to_s64(buffer, count, &val);
175 CERROR("%s: invalid FID sequence width: rc = %d\n",
177 GOTO(out_unlock, count = rc);
181 CERROR("%s: invalid FID sequence width: rc = %d\n",
182 seq->lss_name, -ERANGE);
183 GOTO(out_unlock, count = -ERANGE);
186 seq->lss_width = val;
188 CDEBUG(D_INFO, "%s: Width: %llu\n",
189 seq->lss_name, seq->lss_width);
191 mutex_unlock(&seq->lss_mutex);
197 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
199 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
202 LASSERT(seq != NULL);
204 mutex_lock(&seq->lss_mutex);
205 seq_printf(m, "%llu\n", seq->lss_width);
206 mutex_unlock(&seq->lss_mutex);
211 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
212 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
213 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
215 struct lprocfs_vars seq_server_proc_list[] = {
217 .fops = &lprocfs_server_fid_space_fops },
219 .fops = &lprocfs_server_fid_width_fops },
221 .fops = &lprocfs_server_fid_server_fops },
225 struct fld_seq_param {
226 struct lu_env fsp_env;
227 struct dt_it *fsp_it;
228 struct lu_server_fld *fsp_fld;
229 struct lu_server_seq *fsp_seq;
230 unsigned int fsp_stop:1;
234 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
235 * we want to avoid this duplication either by exporting the
236 * functions or merging fid and fld into a single module.
238 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
240 struct fld_seq_param *param = p->private;
241 struct lu_server_fld *fld;
242 struct dt_object *obj;
243 const struct dt_it_ops *iops;
247 if (param == NULL || param->fsp_stop)
250 fld = param->fsp_fld;
252 LASSERT(obj != NULL);
253 iops = &obj->do_index_ops->dio_it;
255 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
259 key = iops->key(¶m->fsp_env, param->fsp_it);
263 *pos = be64_to_cpu(*(__u64 *)key);
268 static void fldb_seq_stop(struct seq_file *p, void *v)
270 struct fld_seq_param *param = p->private;
271 const struct dt_it_ops *iops;
272 struct lu_server_fld *fld;
273 struct dt_object *obj;
278 fld = param->fsp_fld;
280 LASSERT(obj != NULL);
281 iops = &obj->do_index_ops->dio_it;
283 iops->put(¶m->fsp_env, param->fsp_it);
286 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
288 struct fld_seq_param *param = p->private;
289 struct lu_server_fld *fld;
290 struct dt_object *obj;
291 const struct dt_it_ops *iops;
294 if (param == NULL || param->fsp_stop)
297 fld = param->fsp_fld;
299 LASSERT(obj != NULL);
300 iops = &obj->do_index_ops->dio_it;
302 rc = iops->next(¶m->fsp_env, param->fsp_it);
308 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
312 static int fldb_seq_show(struct seq_file *p, void *v)
314 struct fld_seq_param *param = p->private;
315 struct lu_server_fld *fld;
316 struct dt_object *obj;
317 const struct dt_it_ops *iops;
318 struct lu_seq_range fld_rec;
321 if (param == NULL || param->fsp_stop)
324 fld = param->fsp_fld;
326 LASSERT(obj != NULL);
327 iops = &obj->do_index_ops->dio_it;
329 rc = iops->rec(¶m->fsp_env, param->fsp_it,
330 (struct dt_rec *)&fld_rec, 0);
332 CERROR("%s: read record error: rc = %d\n",
334 } else if (fld_rec.lsr_start != 0) {
335 range_be_to_cpu(&fld_rec, &fld_rec);
336 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
342 struct seq_operations fldb_sops = {
343 .start = fldb_seq_start,
344 .stop = fldb_seq_stop,
345 .next = fldb_seq_next,
346 .show = fldb_seq_show,
349 static int fldb_seq_open(struct inode *inode, struct file *file)
351 struct seq_file *seq;
352 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
353 struct lu_server_fld *fld;
354 struct dt_object *obj;
355 const struct dt_it_ops *iops;
356 struct fld_seq_param *param = NULL;
360 fld = ss->lss_site->ss_server_fld;
361 LASSERT(fld != NULL);
363 rc = LPROCFS_ENTRY_CHECK(inode);
367 rc = seq_open(file, &fldb_sops);
373 seq = file->private_data;
378 OBD_ALLOC_PTR(param);
380 GOTO(out, rc = -ENOMEM);
382 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
387 iops = &obj->do_index_ops->dio_it;
388 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
389 if (IS_ERR(param->fsp_it))
390 GOTO(out, rc = PTR_ERR(param->fsp_it));
392 param->fsp_fld = fld;
396 seq = file->private_data;
397 seq->private = param;
401 lu_env_fini(¶m->fsp_env);
408 static int fldb_seq_release(struct inode *inode, struct file *file)
410 struct seq_file *seq = file->private_data;
411 struct fld_seq_param *param;
412 struct lu_server_fld *fld;
413 struct dt_object *obj;
414 const struct dt_it_ops *iops;
416 param = seq->private;
418 lprocfs_seq_release(inode, file);
422 fld = param->fsp_fld;
424 LASSERT(obj != NULL);
425 iops = &obj->do_index_ops->dio_it;
427 LASSERT(iops != NULL);
428 LASSERT(param->fsp_it != NULL);
429 iops->fini(¶m->fsp_env, param->fsp_it);
430 lu_env_fini(¶m->fsp_env);
432 lprocfs_seq_release(inode, file);
437 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
438 size_t len, loff_t *off)
440 struct seq_file *seq = file->private_data;
441 struct fld_seq_param *param;
442 struct lu_seq_range range;
444 char _buffer[MAX_FID_RANGE_STRLEN];
445 char *buffer = _buffer;
448 param = seq->private;
452 if (len >= sizeof(_buffer))
455 if (copy_from_user(buffer, buf, len))
456 GOTO(out, rc = -EFAULT);
460 * format - [0x0000000200000007-0x0000000200000008):0:mdt
463 GOTO(out, rc = -EINVAL);
466 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
468 GOTO(out, rc = -EINVAL);
471 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
473 GOTO(out, rc = -EINVAL);
476 GOTO(out, rc = -EINVAL);
479 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
481 GOTO(out, rc = -EINVAL);
484 if (strncmp(buffer, "mdt", 3) == 0)
485 range.lsr_flags = LU_SEQ_RANGE_MDT;
486 else if (strncmp(buffer, "ost", 3) == 0)
487 range.lsr_flags = LU_SEQ_RANGE_OST;
489 GOTO(out, rc = -EINVAL);
491 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
492 &range, ¶m->fsp_env);
495 RETURN(rc < 0 ? rc : len);
498 const struct file_operations seq_fld_proc_seq_fops = {
499 .owner = THIS_MODULE,
500 .open = fldb_seq_open,
502 .write = fldb_seq_write,
503 .release = fldb_seq_release,
506 #endif /* HAVE_SERVER_SUPPORT */
508 /* Client side procfs stuff */
510 lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
511 size_t count, loff_t *off)
513 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
517 LASSERT(seq != NULL);
519 mutex_lock(&seq->lcs_mutex);
520 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
522 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
523 seq->lcs_name, PRANGE(&seq->lcs_space));
526 mutex_unlock(&seq->lcs_mutex);
532 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
534 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
537 LASSERT(seq != NULL);
539 mutex_lock(&seq->lcs_mutex);
540 seq_printf(m, "[%#llx - %#llx]:%x:%s\n",
541 PRANGE(&seq->lcs_space));
542 mutex_unlock(&seq->lcs_mutex);
548 lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
549 size_t count, loff_t *off)
551 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
557 LASSERT(seq != NULL);
559 mutex_lock(&seq->lcs_mutex);
561 rc = lprocfs_str_to_s64(buffer, count, &val);
563 GOTO(out_unlock, count = rc);
566 if (seq->lcs_type == LUSTRE_SEQ_DATA)
567 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
569 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
571 if (val <= max && val > 0) {
572 seq->lcs_width = val;
574 CDEBUG(D_INFO, "%s: Sequence size: %llu\n",
575 seq->lcs_name, seq->lcs_width);
577 GOTO(out_unlock, count = -ERANGE);
581 mutex_unlock(&seq->lcs_mutex);
586 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
588 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
591 LASSERT(seq != NULL);
593 mutex_lock(&seq->lcs_mutex);
594 seq_printf(m, "%llu\n", seq->lcs_width);
595 mutex_unlock(&seq->lcs_mutex);
601 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
603 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
606 LASSERT(seq != NULL);
608 mutex_lock(&seq->lcs_mutex);
609 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
610 mutex_unlock(&seq->lcs_mutex);
616 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
618 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
619 struct client_obd *cli;
622 LASSERT(seq != NULL);
624 if (seq->lcs_exp != NULL) {
625 cli = &seq->lcs_exp->exp_obd->u.cli;
626 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
628 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
633 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
634 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
635 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
636 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
638 struct lprocfs_vars seq_client_proc_list[] = {
640 .fops = &lprocfs_client_fid_space_fops },
642 .fops = &lprocfs_client_fid_width_fops },
644 .fops = &lprocfs_client_fid_server_fops },
646 .fops = &lprocfs_client_fid_fid_fops },
650 #endif /* CONFIG_PROC_FS */