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[] = {
206 { "space", &lprocfs_server_fid_space_fops },
207 { "width", &lprocfs_server_fid_width_fops },
208 { "server", &lprocfs_server_fid_server_fops },
212 struct fld_seq_param {
213 struct lu_env fsp_env;
214 struct dt_it *fsp_it;
215 struct lu_server_fld *fsp_fld;
216 struct lu_server_seq *fsp_seq;
217 unsigned int fsp_stop:1;
221 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
222 * we want to avoid this duplication either by exporting the
223 * functions or merging fid and fld into a single module.
225 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
227 struct fld_seq_param *param = p->private;
228 struct lu_server_fld *fld;
229 struct dt_object *obj;
230 const struct dt_it_ops *iops;
232 if (param == NULL || param->fsp_stop)
235 fld = param->fsp_fld;
237 LASSERT(obj != NULL);
238 iops = &obj->do_index_ops->dio_it;
240 iops->load(¶m->fsp_env, param->fsp_it, *pos);
242 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
246 static void fldb_seq_stop(struct seq_file *p, void *v)
248 struct fld_seq_param *param = p->private;
249 const struct dt_it_ops *iops;
250 struct lu_server_fld *fld;
251 struct dt_object *obj;
256 fld = param->fsp_fld;
258 LASSERT(obj != NULL);
259 iops = &obj->do_index_ops->dio_it;
261 iops->put(¶m->fsp_env, param->fsp_it);
264 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
266 struct fld_seq_param *param = p->private;
267 struct lu_server_fld *fld;
268 struct dt_object *obj;
269 const struct dt_it_ops *iops;
272 if (param == NULL || param->fsp_stop)
275 fld = param->fsp_fld;
277 LASSERT(obj != NULL);
278 iops = &obj->do_index_ops->dio_it;
280 rc = iops->next(¶m->fsp_env, param->fsp_it);
286 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
290 static int fldb_seq_show(struct seq_file *p, void *v)
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;
296 struct lu_seq_range fld_rec;
299 if (param == NULL || param->fsp_stop)
302 fld = param->fsp_fld;
304 LASSERT(obj != NULL);
305 iops = &obj->do_index_ops->dio_it;
307 rc = iops->rec(¶m->fsp_env, param->fsp_it,
308 (struct dt_rec *)&fld_rec, 0);
310 CERROR("%s: read record error: rc = %d\n",
312 } else if (fld_rec.lsr_start != 0) {
313 range_be_to_cpu(&fld_rec, &fld_rec);
314 rc = seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
320 struct seq_operations fldb_sops = {
321 .start = fldb_seq_start,
322 .stop = fldb_seq_stop,
323 .next = fldb_seq_next,
324 .show = fldb_seq_show,
327 static int fldb_seq_open(struct inode *inode, struct file *file)
329 struct seq_file *seq;
330 struct lu_server_seq *ss = (struct lu_server_seq *) PDE_DATA(inode);
331 struct lu_server_fld *fld;
332 struct dt_object *obj;
333 const struct dt_it_ops *iops;
334 struct fld_seq_param *param = NULL;
338 fld = ss->lss_site->ss_server_fld;
339 LASSERT(fld != NULL);
341 LPROCFS_ENTRY_CHECK(PDE(inode));
342 rc = seq_open(file, &fldb_sops);
348 seq = file->private_data;
353 OBD_ALLOC_PTR(param);
355 GOTO(out, rc = -ENOMEM);
357 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
362 iops = &obj->do_index_ops->dio_it;
363 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
364 if (IS_ERR(param->fsp_it))
365 GOTO(out, rc = PTR_ERR(param->fsp_it));
367 param->fsp_fld = fld;
371 seq = file->private_data;
372 seq->private = param;
376 lu_env_fini(¶m->fsp_env);
383 static int fldb_seq_release(struct inode *inode, struct file *file)
385 struct seq_file *seq = file->private_data;
386 struct fld_seq_param *param;
387 struct lu_server_fld *fld;
388 struct dt_object *obj;
389 const struct dt_it_ops *iops;
391 param = seq->private;
393 lprocfs_seq_release(inode, file);
397 fld = param->fsp_fld;
399 LASSERT(obj != NULL);
400 iops = &obj->do_index_ops->dio_it;
402 LASSERT(iops != NULL);
403 LASSERT(param->fsp_it != NULL);
404 iops->fini(¶m->fsp_env, param->fsp_it);
405 lu_env_fini(¶m->fsp_env);
407 lprocfs_seq_release(inode, file);
412 static ssize_t fldb_seq_write(struct file *file, const char *buf,
413 size_t len, loff_t *off)
415 struct seq_file *seq = file->private_data;
416 struct fld_seq_param *param;
417 struct lu_seq_range range;
419 char *buffer, *_buffer;
422 param = seq->private;
426 OBD_ALLOC(buffer, len + 1);
429 memcpy(buffer, buf, len);
434 * format - [0x0000000200000007-0x0000000200000008):0:mdt
437 GOTO(out, rc = -EINVAL);
440 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
442 GOTO(out, rc = -EINVAL);
445 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
447 GOTO(out, rc = -EINVAL);
450 GOTO(out, rc = -EINVAL);
453 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
455 GOTO(out, rc = -EINVAL);
458 if (strncmp(buffer, "mdt", 3) == 0)
459 range.lsr_flags = LU_SEQ_RANGE_MDT;
460 else if (strncmp(buffer, "ost", 3) == 0)
461 range.lsr_flags = LU_SEQ_RANGE_OST;
463 GOTO(out, rc = -EINVAL);
465 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
466 &range, ¶m->fsp_env);
469 OBD_FREE(_buffer, len + 1);
470 RETURN(rc < 0 ? rc : len);
473 const struct file_operations seq_fld_proc_seq_fops = {
474 .owner = THIS_MODULE,
475 .open = fldb_seq_open,
477 .write = fldb_seq_write,
478 .release = fldb_seq_release,
481 #endif /* HAVE_SERVER_SUPPORT */
483 /* Client side procfs stuff */
485 lprocfs_client_fid_space_seq_write(struct file *file, const char *buffer,
486 size_t count, loff_t *off)
488 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
492 LASSERT(seq != NULL);
494 mutex_lock(&seq->lcs_mutex);
495 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
497 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
498 seq->lcs_name, PRANGE(&seq->lcs_space));
501 mutex_unlock(&seq->lcs_mutex);
507 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
509 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
513 LASSERT(seq != NULL);
515 mutex_lock(&seq->lcs_mutex);
516 rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
517 PRANGE(&seq->lcs_space));
518 mutex_unlock(&seq->lcs_mutex);
524 lprocfs_client_fid_width_seq_write(struct file *file, const char *buffer,
525 size_t count, loff_t *off)
527 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
532 LASSERT(seq != NULL);
534 mutex_lock(&seq->lcs_mutex);
536 rc = lprocfs_write_helper(buffer, count, &val);
538 mutex_unlock(&seq->lcs_mutex);
542 if (seq->lcs_type == LUSTRE_SEQ_DATA)
543 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
545 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
547 if (val <= max && val > 0) {
548 seq->lcs_width = val;
551 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
552 seq->lcs_name, seq->lcs_width);
555 mutex_unlock(&seq->lcs_mutex);
561 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
563 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
567 LASSERT(seq != NULL);
569 mutex_lock(&seq->lcs_mutex);
570 rc = seq_printf(m, LPU64"\n", seq->lcs_width);
571 mutex_unlock(&seq->lcs_mutex);
577 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
579 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
583 LASSERT(seq != NULL);
585 mutex_lock(&seq->lcs_mutex);
586 rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
587 mutex_unlock(&seq->lcs_mutex);
593 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
595 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
596 struct client_obd *cli;
600 LASSERT(seq != NULL);
602 if (seq->lcs_exp != NULL) {
603 cli = &seq->lcs_exp->exp_obd->u.cli;
604 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
606 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
611 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
612 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
613 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
614 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
616 struct lprocfs_seq_vars seq_client_proc_list[] = {
617 { "space", &lprocfs_client_fid_space_fops },
618 { "width", &lprocfs_client_fid_width_fops },
619 { "server", &lprocfs_client_fid_server_fops },
620 { "fid", &lprocfs_client_fid_fid_fops },