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, "["LPX64" - "LPX64"]:%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;
172 LASSERT(seq != NULL);
174 mutex_lock(&seq->lss_mutex);
176 rc = lprocfs_write_helper(buffer, count, &val);
178 CERROR("%s: invalid width.\n", seq->lss_name);
179 GOTO(out_unlock, count = rc);
182 seq->lss_width = val;
184 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
185 seq->lss_name, seq->lss_width);
187 mutex_unlock(&seq->lss_mutex);
193 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
195 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
198 LASSERT(seq != NULL);
200 mutex_lock(&seq->lss_mutex);
201 seq_printf(m, LPU64"\n", seq->lss_width);
202 mutex_unlock(&seq->lss_mutex);
207 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
208 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
209 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
211 struct lprocfs_vars seq_server_proc_list[] = {
213 .fops = &lprocfs_server_fid_space_fops },
215 .fops = &lprocfs_server_fid_width_fops },
217 .fops = &lprocfs_server_fid_server_fops },
221 struct fld_seq_param {
222 struct lu_env fsp_env;
223 struct dt_it *fsp_it;
224 struct lu_server_fld *fsp_fld;
225 struct lu_server_seq *fsp_seq;
226 unsigned int fsp_stop:1;
230 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
231 * we want to avoid this duplication either by exporting the
232 * functions or merging fid and fld into a single module.
234 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
236 struct fld_seq_param *param = p->private;
237 struct lu_server_fld *fld;
238 struct dt_object *obj;
239 const struct dt_it_ops *iops;
243 if (param == NULL || param->fsp_stop)
246 fld = param->fsp_fld;
248 LASSERT(obj != NULL);
249 iops = &obj->do_index_ops->dio_it;
251 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
255 key = iops->key(¶m->fsp_env, param->fsp_it);
259 *pos = be64_to_cpu(*(__u64 *)key);
264 static void fldb_seq_stop(struct seq_file *p, void *v)
266 struct fld_seq_param *param = p->private;
267 const struct dt_it_ops *iops;
268 struct lu_server_fld *fld;
269 struct dt_object *obj;
274 fld = param->fsp_fld;
276 LASSERT(obj != NULL);
277 iops = &obj->do_index_ops->dio_it;
279 iops->put(¶m->fsp_env, param->fsp_it);
282 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
284 struct fld_seq_param *param = p->private;
285 struct lu_server_fld *fld;
286 struct dt_object *obj;
287 const struct dt_it_ops *iops;
290 if (param == NULL || param->fsp_stop)
293 fld = param->fsp_fld;
295 LASSERT(obj != NULL);
296 iops = &obj->do_index_ops->dio_it;
298 rc = iops->next(¶m->fsp_env, param->fsp_it);
304 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
308 static int fldb_seq_show(struct seq_file *p, void *v)
310 struct fld_seq_param *param = p->private;
311 struct lu_server_fld *fld;
312 struct dt_object *obj;
313 const struct dt_it_ops *iops;
314 struct lu_seq_range fld_rec;
317 if (param == NULL || param->fsp_stop)
320 fld = param->fsp_fld;
322 LASSERT(obj != NULL);
323 iops = &obj->do_index_ops->dio_it;
325 rc = iops->rec(¶m->fsp_env, param->fsp_it,
326 (struct dt_rec *)&fld_rec, 0);
328 CERROR("%s: read record error: rc = %d\n",
330 } else if (fld_rec.lsr_start != 0) {
331 range_be_to_cpu(&fld_rec, &fld_rec);
332 seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
338 struct seq_operations fldb_sops = {
339 .start = fldb_seq_start,
340 .stop = fldb_seq_stop,
341 .next = fldb_seq_next,
342 .show = fldb_seq_show,
345 static int fldb_seq_open(struct inode *inode, struct file *file)
347 struct seq_file *seq;
348 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
349 struct lu_server_fld *fld;
350 struct dt_object *obj;
351 const struct dt_it_ops *iops;
352 struct fld_seq_param *param = NULL;
356 fld = ss->lss_site->ss_server_fld;
357 LASSERT(fld != NULL);
359 rc = LPROCFS_ENTRY_CHECK(inode);
363 rc = seq_open(file, &fldb_sops);
369 seq = file->private_data;
374 OBD_ALLOC_PTR(param);
376 GOTO(out, rc = -ENOMEM);
378 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
383 iops = &obj->do_index_ops->dio_it;
384 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
385 if (IS_ERR(param->fsp_it))
386 GOTO(out, rc = PTR_ERR(param->fsp_it));
388 param->fsp_fld = fld;
392 seq = file->private_data;
393 seq->private = param;
397 lu_env_fini(¶m->fsp_env);
404 static int fldb_seq_release(struct inode *inode, struct file *file)
406 struct seq_file *seq = file->private_data;
407 struct fld_seq_param *param;
408 struct lu_server_fld *fld;
409 struct dt_object *obj;
410 const struct dt_it_ops *iops;
412 param = seq->private;
414 lprocfs_seq_release(inode, file);
418 fld = param->fsp_fld;
420 LASSERT(obj != NULL);
421 iops = &obj->do_index_ops->dio_it;
423 LASSERT(iops != NULL);
424 LASSERT(param->fsp_it != NULL);
425 iops->fini(¶m->fsp_env, param->fsp_it);
426 lu_env_fini(¶m->fsp_env);
428 lprocfs_seq_release(inode, file);
433 static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
434 size_t len, loff_t *off)
436 struct seq_file *seq = file->private_data;
437 struct fld_seq_param *param;
438 struct lu_seq_range range;
440 char _buffer[MAX_FID_RANGE_STRLEN];
441 char *buffer = _buffer;
444 param = seq->private;
448 if (len >= sizeof(_buffer))
451 if (copy_from_user(buffer, buf, len))
452 GOTO(out, rc = -EFAULT);
456 * format - [0x0000000200000007-0x0000000200000008):0:mdt
459 GOTO(out, rc = -EINVAL);
462 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
464 GOTO(out, rc = -EINVAL);
467 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
469 GOTO(out, rc = -EINVAL);
472 GOTO(out, rc = -EINVAL);
475 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
477 GOTO(out, rc = -EINVAL);
480 if (strncmp(buffer, "mdt", 3) == 0)
481 range.lsr_flags = LU_SEQ_RANGE_MDT;
482 else if (strncmp(buffer, "ost", 3) == 0)
483 range.lsr_flags = LU_SEQ_RANGE_OST;
485 GOTO(out, rc = -EINVAL);
487 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
488 &range, ¶m->fsp_env);
491 RETURN(rc < 0 ? rc : len);
494 const struct file_operations seq_fld_proc_seq_fops = {
495 .owner = THIS_MODULE,
496 .open = fldb_seq_open,
498 .write = fldb_seq_write,
499 .release = fldb_seq_release,
502 #endif /* HAVE_SERVER_SUPPORT */
504 /* Client side procfs stuff */
506 lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
507 size_t count, loff_t *off)
509 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
513 LASSERT(seq != NULL);
515 mutex_lock(&seq->lcs_mutex);
516 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
518 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
519 seq->lcs_name, PRANGE(&seq->lcs_space));
522 mutex_unlock(&seq->lcs_mutex);
528 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
530 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
533 LASSERT(seq != NULL);
535 mutex_lock(&seq->lcs_mutex);
536 seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
537 PRANGE(&seq->lcs_space));
538 mutex_unlock(&seq->lcs_mutex);
544 lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
545 size_t count, loff_t *off)
547 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
552 LASSERT(seq != NULL);
554 mutex_lock(&seq->lcs_mutex);
556 rc = lprocfs_write_helper(buffer, count, &val);
558 mutex_unlock(&seq->lcs_mutex);
562 if (seq->lcs_type == LUSTRE_SEQ_DATA)
563 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
565 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
567 if (val <= max && val > 0) {
568 seq->lcs_width = val;
570 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
571 seq->lcs_name, seq->lcs_width);
573 mutex_unlock(&seq->lcs_mutex);
579 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
581 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
584 LASSERT(seq != NULL);
586 mutex_lock(&seq->lcs_mutex);
587 seq_printf(m, LPU64"\n", seq->lcs_width);
588 mutex_unlock(&seq->lcs_mutex);
594 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
596 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
599 LASSERT(seq != NULL);
601 mutex_lock(&seq->lcs_mutex);
602 seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
603 mutex_unlock(&seq->lcs_mutex);
609 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
611 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
612 struct client_obd *cli;
615 LASSERT(seq != NULL);
617 if (seq->lcs_exp != NULL) {
618 cli = &seq->lcs_exp->exp_obd->u.cli;
619 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
621 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
626 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
627 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
628 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
629 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
631 struct lprocfs_vars seq_client_proc_list[] = {
633 .fops = &lprocfs_client_fid_space_fops },
635 .fops = &lprocfs_client_fid_width_fops },
637 .fops = &lprocfs_client_fid_server_fops },
639 .fops = &lprocfs_client_fid_fid_fops },
643 #endif /* CONFIG_PROC_FS */