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.
64 static int seq_proc_write_common(struct file *file, const char *buffer,
65 unsigned long count, void *data,
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 static int seq_proc_read_common(char *page, char **start, off_t off,
91 int count, int *eof, void *data,
92 struct lu_seq_range *range)
98 rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
103 #ifdef HAVE_SERVER_SUPPORT
105 * Server side procfs stuff.
108 seq_server_proc_write_space(struct file *file, const char *buffer,
109 unsigned long count, void *data)
111 struct lu_server_seq *seq = (struct lu_server_seq *)data;
115 LASSERT(seq != NULL);
117 mutex_lock(&seq->lss_mutex);
118 rc = seq_proc_write_common(file, buffer, count,
119 data, &seq->lss_space);
121 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
122 seq->lss_name, PRANGE(&seq->lss_space));
125 mutex_unlock(&seq->lss_mutex);
131 seq_server_proc_read_space(char *page, char **start, off_t off,
132 int count, int *eof, void *data)
134 struct lu_server_seq *seq = (struct lu_server_seq *)data;
138 LASSERT(seq != NULL);
140 mutex_lock(&seq->lss_mutex);
141 rc = seq_proc_read_common(page, start, off, count, eof,
142 data, &seq->lss_space);
143 mutex_unlock(&seq->lss_mutex);
149 seq_server_proc_read_server(char *page, char **start, off_t off,
150 int count, int *eof, void *data)
152 struct lu_server_seq *seq = (struct lu_server_seq *)data;
153 struct client_obd *cli;
157 LASSERT(seq != NULL);
161 if (seq->lss_cli->lcs_exp != NULL) {
162 cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
163 rc = snprintf(page, count, "%s\n",
164 cli->cl_target_uuid.uuid);
166 rc = snprintf(page, count, "%s\n",
167 seq->lss_cli->lcs_srv->lss_name);
170 rc = snprintf(page, count, "<none>\n");
177 seq_server_proc_write_width(struct file *file, const char *buffer,
178 unsigned long count, void *data)
180 struct lu_server_seq *seq = (struct lu_server_seq *)data;
184 LASSERT(seq != NULL);
186 mutex_lock(&seq->lss_mutex);
188 rc = lprocfs_write_helper(buffer, count, &val);
190 CERROR("%s: invalid width.\n", seq->lss_name);
191 GOTO(out_unlock, count = rc);
194 seq->lss_width = val;
196 CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
197 seq->lss_name, seq->lss_width);
199 mutex_unlock(&seq->lss_mutex);
205 seq_server_proc_read_width(char *page, char **start, off_t off,
206 int count, int *eof, void *data)
208 struct lu_server_seq *seq = (struct lu_server_seq *)data;
212 LASSERT(seq != NULL);
214 mutex_lock(&seq->lss_mutex);
215 rc = snprintf(page, count, LPU64"\n", seq->lss_width);
216 mutex_unlock(&seq->lss_mutex);
221 struct lprocfs_vars seq_server_proc_list[] = {
223 seq_server_proc_read_space, seq_server_proc_write_space, NULL },
225 seq_server_proc_read_width, seq_server_proc_write_width, NULL },
227 seq_server_proc_read_server, NULL, NULL },
231 struct fld_seq_param {
232 struct lu_env fsp_env;
233 struct dt_it *fsp_it;
234 struct lu_server_fld *fsp_fld;
235 struct lu_server_seq *fsp_seq;
236 unsigned int fsp_stop:1;
240 * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
241 * we want to avoid this duplication either by exporting the
242 * functions or merging fid and fld into a single module.
244 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
246 struct fld_seq_param *param = p->private;
247 struct lu_server_fld *fld;
248 struct dt_object *obj;
249 const struct dt_it_ops *iops;
251 if (param == NULL || param->fsp_stop)
254 fld = param->fsp_fld;
256 LASSERT(obj != NULL);
257 iops = &obj->do_index_ops->dio_it;
259 iops->load(¶m->fsp_env, param->fsp_it, *pos);
261 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
265 static void fldb_seq_stop(struct seq_file *p, void *v)
267 struct fld_seq_param *param = p->private;
268 const struct dt_it_ops *iops;
269 struct lu_server_fld *fld;
270 struct dt_object *obj;
275 fld = param->fsp_fld;
277 LASSERT(obj != NULL);
278 iops = &obj->do_index_ops->dio_it;
280 iops->put(¶m->fsp_env, param->fsp_it);
283 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
285 struct fld_seq_param *param = p->private;
286 struct lu_server_fld *fld;
287 struct dt_object *obj;
288 const struct dt_it_ops *iops;
291 if (param == NULL || param->fsp_stop)
294 fld = param->fsp_fld;
296 LASSERT(obj != NULL);
297 iops = &obj->do_index_ops->dio_it;
299 rc = iops->next(¶m->fsp_env, param->fsp_it);
305 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
309 static int fldb_seq_show(struct seq_file *p, void *v)
311 struct fld_seq_param *param = p->private;
312 struct lu_server_fld *fld;
313 struct dt_object *obj;
314 const struct dt_it_ops *iops;
315 struct lu_seq_range fld_rec;
318 if (param == NULL || param->fsp_stop)
321 fld = param->fsp_fld;
323 LASSERT(obj != NULL);
324 iops = &obj->do_index_ops->dio_it;
326 rc = iops->rec(¶m->fsp_env, param->fsp_it,
327 (struct dt_rec *)&fld_rec, 0);
329 CERROR("%s: read record error: rc = %d\n",
331 } else if (fld_rec.lsr_start != 0) {
332 range_be_to_cpu(&fld_rec, &fld_rec);
333 rc = seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
339 struct seq_operations fldb_sops = {
340 .start = fldb_seq_start,
341 .stop = fldb_seq_stop,
342 .next = fldb_seq_next,
343 .show = fldb_seq_show,
346 static int fldb_seq_open(struct inode *inode, struct file *file)
348 struct proc_dir_entry *dp = PDE(inode);
349 struct seq_file *seq;
350 struct lu_server_seq *ss = (struct lu_server_seq *)dp->data;
351 struct lu_server_fld *fld;
352 struct dt_object *obj;
353 const struct dt_it_ops *iops;
354 struct fld_seq_param *param = NULL;
358 fld = ss->lss_site->ss_server_fld;
359 LASSERT(fld != NULL);
361 LPROCFS_ENTRY_CHECK(dp);
362 rc = seq_open(file, &fldb_sops);
368 seq = file->private_data;
373 OBD_ALLOC_PTR(param);
375 GOTO(out, rc = -ENOMEM);
377 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
382 iops = &obj->do_index_ops->dio_it;
383 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
384 if (IS_ERR(param->fsp_it))
385 GOTO(out, rc = PTR_ERR(param->fsp_it));
387 param->fsp_fld = fld;
391 seq = file->private_data;
392 seq->private = param;
396 lu_env_fini(¶m->fsp_env);
403 static int fldb_seq_release(struct inode *inode, struct file *file)
405 struct seq_file *seq = file->private_data;
406 struct fld_seq_param *param;
407 struct lu_server_fld *fld;
408 struct dt_object *obj;
409 const struct dt_it_ops *iops;
411 param = seq->private;
413 lprocfs_seq_release(inode, file);
417 fld = param->fsp_fld;
419 LASSERT(obj != NULL);
420 iops = &obj->do_index_ops->dio_it;
422 LASSERT(iops != NULL);
423 LASSERT(param->fsp_it != NULL);
424 iops->fini(¶m->fsp_env, param->fsp_it);
425 lu_env_fini(¶m->fsp_env);
427 lprocfs_seq_release(inode, file);
432 static ssize_t fldb_seq_write(struct file *file, const char *buf,
433 size_t len, loff_t *off)
435 struct seq_file *seq = file->private_data;
436 struct fld_seq_param *param;
437 struct lu_seq_range range;
439 char *buffer, *_buffer;
442 param = seq->private;
446 OBD_ALLOC(buffer, len + 1);
449 memcpy(buffer, buf, len);
454 * format - [0x0000000200000007-0x0000000200000008):0:mdt
457 GOTO(out, rc = -EINVAL);
460 range.lsr_start = simple_strtoull(buffer, &buffer, 0);
462 GOTO(out, rc = -EINVAL);
465 range.lsr_end = simple_strtoull(buffer, &buffer, 0);
467 GOTO(out, rc = -EINVAL);
470 GOTO(out, rc = -EINVAL);
473 range.lsr_index = simple_strtoul(buffer, &buffer, 0);
475 GOTO(out, rc = -EINVAL);
478 if (strncmp(buffer, "mdt", 3) == 0)
479 range.lsr_flags = LU_SEQ_RANGE_MDT;
480 else if (strncmp(buffer, "ost", 3) == 0)
481 range.lsr_flags = LU_SEQ_RANGE_OST;
483 GOTO(out, rc = -EINVAL);
485 rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
486 &range, ¶m->fsp_env);
489 OBD_FREE(_buffer, len + 1);
490 RETURN(rc < 0 ? rc : len);
493 const struct file_operations seq_fld_proc_seq_fops = {
494 .owner = THIS_MODULE,
495 .open = fldb_seq_open,
497 .write = fldb_seq_write,
498 .release = fldb_seq_release,
501 #endif /* HAVE_SERVER_SUPPORT */
503 /* Client side procfs stuff */
505 seq_client_proc_write_space(struct file *file, const char *buffer,
506 unsigned long count, void *data)
508 struct lu_client_seq *seq = (struct lu_client_seq *)data;
512 LASSERT(seq != NULL);
514 mutex_lock(&seq->lcs_mutex);
515 rc = seq_proc_write_common(file, buffer, count,
516 data, &seq->lcs_space);
519 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
520 seq->lcs_name, PRANGE(&seq->lcs_space));
523 mutex_unlock(&seq->lcs_mutex);
529 seq_client_proc_read_space(char *page, char **start, off_t off,
530 int count, int *eof, void *data)
532 struct lu_client_seq *seq = (struct lu_client_seq *)data;
536 LASSERT(seq != NULL);
538 mutex_lock(&seq->lcs_mutex);
539 rc = seq_proc_read_common(page, start, off, count, eof,
540 data, &seq->lcs_space);
541 mutex_unlock(&seq->lcs_mutex);
547 seq_client_proc_write_width(struct file *file, const char *buffer,
548 unsigned long count, void *data)
550 struct lu_client_seq *seq = (struct lu_client_seq *)data;
555 LASSERT(seq != NULL);
557 mutex_lock(&seq->lcs_mutex);
559 rc = lprocfs_write_helper(buffer, count, &val);
561 mutex_unlock(&seq->lcs_mutex);
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;
574 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
575 seq->lcs_name, seq->lcs_width);
579 mutex_unlock(&seq->lcs_mutex);
585 seq_client_proc_read_width(char *page, char **start, off_t off,
586 int count, int *eof, void *data)
588 struct lu_client_seq *seq = (struct lu_client_seq *)data;
592 LASSERT(seq != NULL);
594 mutex_lock(&seq->lcs_mutex);
595 rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
596 mutex_unlock(&seq->lcs_mutex);
602 seq_client_proc_read_fid(char *page, char **start, off_t off,
603 int count, int *eof, void *data)
605 struct lu_client_seq *seq = (struct lu_client_seq *)data;
609 LASSERT(seq != NULL);
611 mutex_lock(&seq->lcs_mutex);
612 rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
613 mutex_unlock(&seq->lcs_mutex);
619 seq_client_proc_read_server(char *page, char **start, off_t off,
620 int count, int *eof, void *data)
622 struct lu_client_seq *seq = (struct lu_client_seq *)data;
623 struct client_obd *cli;
627 LASSERT(seq != NULL);
629 if (seq->lcs_exp != NULL) {
630 cli = &seq->lcs_exp->exp_obd->u.cli;
631 rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
633 rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
638 struct lprocfs_vars seq_client_proc_list[] = {
639 { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL },
640 { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL },
641 { "server", seq_client_proc_read_server, NULL, NULL },
642 { "fid", seq_client_proc_read_fid, NULL, NULL },