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, 2013, 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"
53 #include <md_object.h>
57 * Reduce the SEQ range allocated to a node to a strict subset of the range
58 * currently-allocated SEQ range. If the specified range is "clear", then
59 * drop all allocated sequences and request a new one from the master.
61 * Note: this function should only be used for testing, it is not necessarily
62 * safe for production use.
65 lprocfs_fid_write_common(const char *buffer, unsigned long count,
66 struct lu_seq_range *range)
68 struct lu_seq_range tmp = { 0, };
72 LASSERT(range != NULL);
74 if (count == 5 && strcmp(buffer, "clear") == 0) {
75 memset(range, 0, sizeof(*range));
79 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
80 rc = sscanf(buffer, "[%llx - %llx]\n",
81 (long long unsigned *)&tmp.lsr_start,
82 (long long unsigned *)&tmp.lsr_end);
83 if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
84 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
90 #ifdef HAVE_SERVER_SUPPORT
92 * Server side procfs stuff.
95 lprocfs_server_fid_space_seq_write(struct file *file, const char *buffer,
96 size_t count, loff_t *off)
98 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
102 LASSERT(seq != NULL);
104 mutex_lock(&seq->lss_mutex);
105 rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
107 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
108 seq->lss_name, PRANGE(&seq->lss_space));
110 mutex_unlock(&seq->lss_mutex);
116 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
118 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
122 LASSERT(seq != NULL);
124 mutex_lock(&seq->lss_mutex);
125 rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
126 PRANGE(&seq->lss_space));
127 mutex_unlock(&seq->lss_mutex);
133 lprocfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
135 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
136 struct client_obd *cli;
140 LASSERT(seq != NULL);
143 if (seq->lss_cli->lcs_exp != NULL) {
144 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
145 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
147 rc = seq_printf(m, "%s\n",
148 seq->lss_cli->lcs_srv->lss_name);
151 rc = seq_printf(m, "<none>\n");
158 lprocfs_server_fid_width_seq_write(struct file *file, const char *buffer,
159 size_t count, loff_t *off)
161 struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
165 LASSERT(seq != NULL);
167 mutex_lock(&seq->lss_mutex);
169 rc = lprocfs_write_helper(buffer, count, &val);
171 CERROR("%s: invalid width.\n", seq->lss_name);
172 GOTO(out_unlock, count = rc);
175 seq->lss_width = val;
177 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
178 seq->lss_name, seq->lss_width);
180 mutex_unlock(&seq->lss_mutex);
186 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
188 struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
192 LASSERT(seq != NULL);
194 mutex_lock(&seq->lss_mutex);
195 rc = seq_printf(m, LPU64"\n", seq->lss_width);
196 mutex_unlock(&seq->lss_mutex);
201 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
202 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
203 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
205 struct lprocfs_seq_vars seq_server_proc_list[] = {
207 .fops = &lprocfs_server_fid_space_fops },
209 .fops = &lprocfs_server_fid_width_fops },
211 .fops = &lprocfs_server_fid_server_fops },
215 struct fld_seq_param {
216 struct lu_env fsp_env;
217 struct dt_it *fsp_it;
218 struct lu_server_fld *fsp_fld;
219 struct lu_server_seq *fsp_seq;
220 unsigned int fsp_stop:1;
224 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
225 * we want to avoid this duplication either by exporting the
226 * functions or merging fid and fld into a single module.
228 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
230 struct fld_seq_param *param = p->private;
231 struct lu_server_fld *fld;
232 struct dt_object *obj;
233 const struct dt_it_ops *iops;
237 if (param == NULL || param->fsp_stop)
240 fld = param->fsp_fld;
242 LASSERT(obj != NULL);
243 iops = &obj->do_index_ops->dio_it;
245 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
249 key = iops->key(¶m->fsp_env, param->fsp_it);
253 *pos = be64_to_cpu(*(__u64 *)key);
258 static void fldb_seq_stop(struct seq_file *p, void *v)
260 struct fld_seq_param *param = p->private;
261 const struct dt_it_ops *iops;
262 struct lu_server_fld *fld;
263 struct dt_object *obj;
268 fld = param->fsp_fld;
270 LASSERT(obj != NULL);
271 iops = &obj->do_index_ops->dio_it;
273 iops->put(¶m->fsp_env, param->fsp_it);
276 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
278 struct fld_seq_param *param = p->private;
279 struct lu_server_fld *fld;
280 struct dt_object *obj;
281 const struct dt_it_ops *iops;
284 if (param == NULL || param->fsp_stop)
287 fld = param->fsp_fld;
289 LASSERT(obj != NULL);
290 iops = &obj->do_index_ops->dio_it;
292 rc = iops->next(¶m->fsp_env, param->fsp_it);
298 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
302 static int fldb_seq_show(struct seq_file *p, void *v)
304 struct fld_seq_param *param = p->private;
305 struct lu_server_fld *fld;
306 struct dt_object *obj;
307 const struct dt_it_ops *iops;
308 struct lu_seq_range fld_rec;
311 if (param == NULL || param->fsp_stop)
314 fld = param->fsp_fld;
316 LASSERT(obj != NULL);
317 iops = &obj->do_index_ops->dio_it;
319 rc = iops->rec(¶m->fsp_env, param->fsp_it,
320 (struct dt_rec *)&fld_rec, 0);
322 CERROR("%s: read record error: rc = %d\n",
324 } else if (fld_rec.lsr_start != 0) {
325 range_be_to_cpu(&fld_rec, &fld_rec);
326 rc = seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
332 struct seq_operations fldb_sops = {
333 .start = fldb_seq_start,
334 .stop = fldb_seq_stop,
335 .next = fldb_seq_next,
336 .show = fldb_seq_show,
339 static int fldb_seq_open(struct inode *inode, struct file *file)
341 struct seq_file *seq;
342 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
343 struct lu_server_fld *fld;
344 struct dt_object *obj;
345 const struct dt_it_ops *iops;
346 struct fld_seq_param *param = NULL;
350 fld = ss->lss_site->ss_server_fld;
351 LASSERT(fld != NULL);
353 LPROCFS_ENTRY_CHECK(PDE(inode));
354 rc = seq_open(file, &fldb_sops);
360 seq = file->private_data;
365 OBD_ALLOC_PTR(param);
367 GOTO(out, rc = -ENOMEM);
369 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
374 iops = &obj->do_index_ops->dio_it;
375 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
376 if (IS_ERR(param->fsp_it))
377 GOTO(out, rc = PTR_ERR(param->fsp_it));
379 param->fsp_fld = fld;
383 seq = file->private_data;
384 seq->private = param;
388 lu_env_fini(¶m->fsp_env);
395 static int fldb_seq_release(struct inode *inode, struct file *file)
397 struct seq_file *seq = file->private_data;
398 struct fld_seq_param *param;
399 struct lu_server_fld *fld;
400 struct dt_object *obj;
401 const struct dt_it_ops *iops;
403 param = seq->private;
405 lprocfs_seq_release(inode, file);
409 fld = param->fsp_fld;
411 LASSERT(obj != NULL);
412 iops = &obj->do_index_ops->dio_it;
414 LASSERT(iops != NULL);
415 LASSERT(param->fsp_it != NULL);
416 iops->fini(¶m->fsp_env, param->fsp_it);
417 lu_env_fini(¶m->fsp_env);
419 lprocfs_seq_release(inode, file);
424 static ssize_t fldb_seq_write(struct file *file, const char *buf,
425 size_t len, loff_t *off)
427 struct seq_file *seq = file->private_data;
428 struct fld_seq_param *param;
429 struct lu_seq_range range;
431 char *buffer, *_buffer;
434 param = seq->private;
438 OBD_ALLOC(buffer, len + 1);
441 memcpy(buffer, buf, len);
446 * format - [0x0000000200000007-0x0000000200000008):0:mdt
449 GOTO(out, rc = -EINVAL);
452 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
454 GOTO(out, rc = -EINVAL);
457 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
459 GOTO(out, rc = -EINVAL);
462 GOTO(out, rc = -EINVAL);
465 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
467 GOTO(out, rc = -EINVAL);
470 if (strncmp(buffer, "mdt", 3) == 0)
471 range.lsr_flags = LU_SEQ_RANGE_MDT;
472 else if (strncmp(buffer, "ost", 3) == 0)
473 range.lsr_flags = LU_SEQ_RANGE_OST;
475 GOTO(out, rc = -EINVAL);
477 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
478 &range, ¶m->fsp_env);
481 OBD_FREE(_buffer, len + 1);
482 RETURN(rc < 0 ? rc : len);
485 const struct file_operations seq_fld_proc_seq_fops = {
486 .owner = THIS_MODULE,
487 .open = fldb_seq_open,
489 .write = fldb_seq_write,
490 .release = fldb_seq_release,
493 #endif /* HAVE_SERVER_SUPPORT */
495 /* Client side procfs stuff */
497 lprocfs_client_fid_space_seq_write(struct file *file, const char *buffer,
498 size_t count, loff_t *off)
500 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
504 LASSERT(seq != NULL);
506 mutex_lock(&seq->lcs_mutex);
507 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
509 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
510 seq->lcs_name, PRANGE(&seq->lcs_space));
513 mutex_unlock(&seq->lcs_mutex);
519 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
521 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
525 LASSERT(seq != NULL);
527 mutex_lock(&seq->lcs_mutex);
528 rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
529 PRANGE(&seq->lcs_space));
530 mutex_unlock(&seq->lcs_mutex);
536 lprocfs_client_fid_width_seq_write(struct file *file, const char *buffer,
537 size_t count, loff_t *off)
539 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
544 LASSERT(seq != NULL);
546 mutex_lock(&seq->lcs_mutex);
548 rc = lprocfs_write_helper(buffer, count, &val);
550 mutex_unlock(&seq->lcs_mutex);
554 if (seq->lcs_type == LUSTRE_SEQ_DATA)
555 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
557 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
559 if (val <= max && val > 0) {
560 seq->lcs_width = val;
563 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
564 seq->lcs_name, seq->lcs_width);
567 mutex_unlock(&seq->lcs_mutex);
573 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
575 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
579 LASSERT(seq != NULL);
581 mutex_lock(&seq->lcs_mutex);
582 rc = seq_printf(m, LPU64"\n", seq->lcs_width);
583 mutex_unlock(&seq->lcs_mutex);
589 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
591 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
595 LASSERT(seq != NULL);
597 mutex_lock(&seq->lcs_mutex);
598 rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
599 mutex_unlock(&seq->lcs_mutex);
605 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
607 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
608 struct client_obd *cli;
612 LASSERT(seq != NULL);
614 if (seq->lcs_exp != NULL) {
615 cli = &seq->lcs_exp->exp_obd->u.cli;
616 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
618 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
623 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
624 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
625 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
626 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
628 struct lprocfs_seq_vars seq_client_proc_list[] = {
630 .fops = &lprocfs_client_fid_space_fops },
632 .fops = &lprocfs_client_fid_width_fops },
634 .fops = &lprocfs_client_fid_server_fops },
636 .fops = &lprocfs_client_fid_fid_fops },