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 = { 0, };
67 char kernbuf[MAX_FID_RANGE_STRLEN];
70 LASSERT(range != NULL);
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 sscanf(kernbuf, "[%llx - %llx]\n",
87 (long long unsigned *)&tmp.lsr_start,
88 (long long unsigned *)&tmp.lsr_end);
89 if (!lu_seq_range_is_sane(&tmp) || lu_seq_range_is_zero(&tmp) ||
90 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
96 #ifdef HAVE_SERVER_SUPPORT
98 * Server side procfs stuff.
101 lprocfs_server_fid_space_seq_write(struct file *file, const char __user *buffer,
102 size_t count, loff_t *off)
104 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
108 LASSERT(seq != NULL);
110 mutex_lock(&seq->lss_mutex);
111 rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
113 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
114 seq->lss_name, PRANGE(&seq->lss_space));
116 mutex_unlock(&seq->lss_mutex);
122 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
124 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
127 LASSERT(seq != NULL);
129 mutex_lock(&seq->lss_mutex);
130 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lss_space));
131 mutex_unlock(&seq->lss_mutex);
137 lprocfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
139 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
140 struct client_obd *cli;
143 LASSERT(seq != NULL);
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");
160 lprocfs_server_fid_width_seq_write(struct file *file, const char __user *buffer,
161 size_t count, loff_t *off)
163 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
168 LASSERT(seq != NULL);
170 mutex_lock(&seq->lss_mutex);
172 rc = lprocfs_str_to_s64(buffer, count, &val);
174 CERROR("%s: invalid FID sequence width: rc = %d\n",
176 GOTO(out_unlock, count = rc);
180 CERROR("%s: invalid FID sequence width: rc = %d\n",
181 seq->lss_name, -ERANGE);
182 GOTO(out_unlock, count = -ERANGE);
185 seq->lss_width = val;
187 CDEBUG(D_INFO, "%s: Width: %llu\n",
188 seq->lss_name, seq->lss_width);
190 mutex_unlock(&seq->lss_mutex);
196 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
198 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
201 LASSERT(seq != NULL);
203 mutex_lock(&seq->lss_mutex);
204 seq_printf(m, "%llu\n", seq->lss_width);
205 mutex_unlock(&seq->lss_mutex);
210 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
211 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
212 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
214 struct lprocfs_vars seq_server_proc_list[] = {
216 .fops = &lprocfs_server_fid_space_fops },
218 .fops = &lprocfs_server_fid_width_fops },
220 .fops = &lprocfs_server_fid_server_fops },
224 struct fld_seq_param {
225 struct lu_env fsp_env;
226 struct dt_it *fsp_it;
227 struct lu_server_fld *fsp_fld;
228 struct lu_server_seq *fsp_seq;
229 unsigned int fsp_stop:1;
233 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
234 * we want to avoid this duplication either by exporting the
235 * functions or merging fid and fld into a single module.
237 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
239 struct fld_seq_param *param = p->private;
240 struct lu_server_fld *fld;
241 struct dt_object *obj;
242 const struct dt_it_ops *iops;
246 if (param == NULL || param->fsp_stop)
249 fld = param->fsp_fld;
251 LASSERT(obj != NULL);
252 iops = &obj->do_index_ops->dio_it;
254 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
258 key = iops->key(¶m->fsp_env, param->fsp_it);
262 *pos = be64_to_cpu(*(__u64 *)key);
267 static void fldb_seq_stop(struct seq_file *p, void *v)
269 struct fld_seq_param *param = p->private;
270 const struct dt_it_ops *iops;
271 struct lu_server_fld *fld;
272 struct dt_object *obj;
277 fld = param->fsp_fld;
279 LASSERT(obj != NULL);
280 iops = &obj->do_index_ops->dio_it;
282 iops->put(¶m->fsp_env, param->fsp_it);
285 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
287 struct fld_seq_param *param = p->private;
288 struct lu_server_fld *fld;
289 struct dt_object *obj;
290 const struct dt_it_ops *iops;
293 if (param == NULL || param->fsp_stop)
296 fld = param->fsp_fld;
298 LASSERT(obj != NULL);
299 iops = &obj->do_index_ops->dio_it;
301 rc = iops->next(¶m->fsp_env, param->fsp_it);
307 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
311 static int fldb_seq_show(struct seq_file *p, void *v)
313 struct fld_seq_param *param = p->private;
314 struct lu_server_fld *fld;
315 struct dt_object *obj;
316 const struct dt_it_ops *iops;
317 struct lu_seq_range fld_rec;
320 if (param == NULL || param->fsp_stop)
323 fld = param->fsp_fld;
325 LASSERT(obj != NULL);
326 iops = &obj->do_index_ops->dio_it;
328 rc = iops->rec(¶m->fsp_env, param->fsp_it,
329 (struct dt_rec *)&fld_rec, 0);
331 CERROR("%s: read record error: rc = %d\n",
333 } else if (fld_rec.lsr_start != 0) {
334 range_be_to_cpu(&fld_rec, &fld_rec);
335 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
341 struct seq_operations fldb_sops = {
342 .start = fldb_seq_start,
343 .stop = fldb_seq_stop,
344 .next = fldb_seq_next,
345 .show = fldb_seq_show,
348 static int fldb_seq_open(struct inode *inode, struct file *file)
350 struct seq_file *seq;
351 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
352 struct lu_server_fld *fld;
353 struct dt_object *obj;
354 const struct dt_it_ops *iops;
355 struct fld_seq_param *param = NULL;
359 fld = ss->lss_site->ss_server_fld;
360 LASSERT(fld != NULL);
362 rc = LPROCFS_ENTRY_CHECK(inode);
366 rc = seq_open(file, &fldb_sops);
372 seq = file->private_data;
377 OBD_ALLOC_PTR(param);
379 GOTO(out, rc = -ENOMEM);
381 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
386 iops = &obj->do_index_ops->dio_it;
387 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
388 if (IS_ERR(param->fsp_it))
389 GOTO(out, rc = PTR_ERR(param->fsp_it));
391 param->fsp_fld = fld;
395 seq = file->private_data;
396 seq->private = param;
400 lu_env_fini(¶m->fsp_env);
407 static int fldb_seq_release(struct inode *inode, struct file *file)
409 struct seq_file *seq = file->private_data;
410 struct fld_seq_param *param;
411 struct lu_server_fld *fld;
412 struct dt_object *obj;
413 const struct dt_it_ops *iops;
415 param = seq->private;
417 lprocfs_seq_release(inode, file);
421 fld = param->fsp_fld;
423 LASSERT(obj != NULL);
424 iops = &obj->do_index_ops->dio_it;
426 LASSERT(iops != NULL);
427 LASSERT(param->fsp_it != NULL);
428 iops->fini(¶m->fsp_env, param->fsp_it);
429 lu_env_fini(¶m->fsp_env);
431 lprocfs_seq_release(inode, file);
436 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
437 size_t len, loff_t *off)
439 struct seq_file *seq = file->private_data;
440 struct fld_seq_param *param;
441 struct lu_seq_range range;
443 char _buffer[MAX_FID_RANGE_STRLEN];
444 char *buffer = _buffer;
447 param = seq->private;
451 if (len >= sizeof(_buffer))
454 if (copy_from_user(buffer, buf, len))
455 GOTO(out, rc = -EFAULT);
459 * format - [0x0000000200000007-0x0000000200000008):0:mdt
462 GOTO(out, rc = -EINVAL);
465 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
467 GOTO(out, rc = -EINVAL);
470 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
472 GOTO(out, rc = -EINVAL);
475 GOTO(out, rc = -EINVAL);
478 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
480 GOTO(out, rc = -EINVAL);
483 if (strncmp(buffer, "mdt", 3) == 0)
484 range.lsr_flags = LU_SEQ_RANGE_MDT;
485 else if (strncmp(buffer, "ost", 3) == 0)
486 range.lsr_flags = LU_SEQ_RANGE_OST;
488 GOTO(out, rc = -EINVAL);
490 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
491 &range, ¶m->fsp_env);
494 RETURN(rc < 0 ? rc : len);
497 const struct file_operations seq_fld_proc_seq_fops = {
498 .owner = THIS_MODULE,
499 .open = fldb_seq_open,
501 .write = fldb_seq_write,
502 .release = fldb_seq_release,
505 #endif /* HAVE_SERVER_SUPPORT */
507 /* Client side procfs stuff */
509 lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
510 size_t count, loff_t *off)
512 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
516 LASSERT(seq != NULL);
518 mutex_lock(&seq->lcs_mutex);
519 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
521 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
522 seq->lcs_name, PRANGE(&seq->lcs_space));
525 mutex_unlock(&seq->lcs_mutex);
531 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
533 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
536 LASSERT(seq != NULL);
538 mutex_lock(&seq->lcs_mutex);
539 seq_printf(m, "[%#llx - %#llx]:%x:%s\n",
540 PRANGE(&seq->lcs_space));
541 mutex_unlock(&seq->lcs_mutex);
547 lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
548 size_t count, loff_t *off)
550 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
556 LASSERT(seq != NULL);
558 mutex_lock(&seq->lcs_mutex);
560 rc = lprocfs_str_to_s64(buffer, count, &val);
562 GOTO(out_unlock, count = rc);
565 if (seq->lcs_type == LUSTRE_SEQ_DATA)
566 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
568 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
570 if (val <= max && val > 0) {
571 seq->lcs_width = val;
573 CDEBUG(D_INFO, "%s: Sequence size: %llu\n",
574 seq->lcs_name, seq->lcs_width);
576 GOTO(out_unlock, count = -ERANGE);
580 mutex_unlock(&seq->lcs_mutex);
585 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
587 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
590 LASSERT(seq != NULL);
592 mutex_lock(&seq->lcs_mutex);
593 seq_printf(m, "%llu\n", seq->lcs_width);
594 mutex_unlock(&seq->lcs_mutex);
600 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
602 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
605 LASSERT(seq != NULL);
607 mutex_lock(&seq->lcs_mutex);
608 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
609 mutex_unlock(&seq->lcs_mutex);
615 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
617 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
618 struct client_obd *cli;
621 LASSERT(seq != NULL);
623 if (seq->lcs_exp != NULL) {
624 cli = &seq->lcs_exp->exp_obd->u.cli;
625 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
627 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
632 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
633 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
634 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
635 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
637 struct lprocfs_vars seq_client_proc_list[] = {
639 .fops = &lprocfs_client_fid_space_fops },
641 .fops = &lprocfs_client_fid_width_fops },
643 .fops = &lprocfs_client_fid_server_fops },
645 .fops = &lprocfs_client_fid_fid_fops },
649 #endif /* CONFIG_PROC_FS */