blob: 1f0e78686278dd69f6b6c9bc67ccbe62c7ae34ee [file] [log] [blame]
Peng Taod7e09d02013-05-02 16:46:55 +08001/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
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).
15 *
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
19 *
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
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
Andreas Dilger1dc563a2015-11-08 18:09:37 -050030 * Copyright (c) 2011, 2015, Intel Corporation.
Peng Taod7e09d02013-05-02 16:46:55 +080031 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 *
36 * lustre/fid/lproc_fid.c
37 *
38 * Lustre Sequence Manager
39 *
40 * Author: Yury Umanets <umka@clusterfs.com>
41 */
42
43#define DEBUG_SUBSYSTEM S_FID
44
Greg Kroah-Hartman9fdaf8c2014-07-11 20:51:16 -070045#include "../../include/linux/libcfs/libcfs.h"
46#include <linux/module.h>
Peng Taod7e09d02013-05-02 16:46:55 +080047
Greg Kroah-Hartman61566392014-07-11 21:50:29 -070048#include "../include/obd.h"
49#include "../include/obd_class.h"
Greg Kroah-Hartman61566392014-07-11 21:50:29 -070050#include "../include/obd_support.h"
51#include "../include/lustre_req_layout.h"
52#include "../include/lustre_fid.h"
Peng Taod7e09d02013-05-02 16:46:55 +080053#include "fid_internal.h"
54
Oleg Drokina1e7e2d2014-04-27 13:07:10 -040055/* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
56#define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
Peng Taod7e09d02013-05-02 16:46:55 +080057/*
58 * Note: this function is only used for testing, it is no safe for production
59 * use.
60 */
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -040061static int
62ldebugfs_fid_write_common(const char __user *buffer, size_t count,
63 struct lu_seq_range *range)
Peng Taod7e09d02013-05-02 16:46:55 +080064{
65 struct lu_seq_range tmp;
66 int rc;
Oleg Drokina1e7e2d2014-04-27 13:07:10 -040067 char kernbuf[MAX_FID_RANGE_STRLEN];
Peng Taod7e09d02013-05-02 16:46:55 +080068
Oleg Drokin6a9f7482016-02-16 00:46:49 -050069 LASSERT(range);
Peng Taod7e09d02013-05-02 16:46:55 +080070
Oleg Drokina1e7e2d2014-04-27 13:07:10 -040071 if (count >= sizeof(kernbuf))
72 return -EINVAL;
73
74 if (copy_from_user(kernbuf, buffer, count))
75 return -EFAULT;
76
77 kernbuf[count] = 0;
78
79 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
80 memset(range, 0, sizeof(*range));
81 return count;
82 }
83
84 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
85 rc = sscanf(kernbuf, "[%llx - %llx]\n",
Eddie Kovsky2a3b60d2014-09-08 15:22:58 -060086 (unsigned long long *)&tmp.lsr_start,
87 (unsigned long long *)&tmp.lsr_end);
Valdis Kletnieksf65a0922015-12-22 19:36:50 -050088 if (rc != 2)
89 return -EINVAL;
Oleg Drokina1e7e2d2014-04-27 13:07:10 -040090 if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
91 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +080092 return -EINVAL;
Peng Taod7e09d02013-05-02 16:46:55 +080093 *range = tmp;
Oleg Drokina1e7e2d2014-04-27 13:07:10 -040094 return count;
Peng Taod7e09d02013-05-02 16:46:55 +080095}
96
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -040097/* Client side debugfs stuff */
98static ssize_t
99ldebugfs_fid_space_seq_write(struct file *file,
100 const char __user *buffer,
101 size_t count, loff_t *off)
Peng Taod7e09d02013-05-02 16:46:55 +0800102{
Anil Belurd1acbe52014-06-19 17:29:01 +1000103 struct lu_client_seq *seq;
Peng Taod7e09d02013-05-02 16:46:55 +0800104 int rc;
Peng Taod7e09d02013-05-02 16:46:55 +0800105
Anil Belurd1acbe52014-06-19 17:29:01 +1000106 seq = ((struct seq_file *)file->private_data)->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800107
108 mutex_lock(&seq->lcs_mutex);
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400109 rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
Peng Taod7e09d02013-05-02 16:46:55 +0800110
111 if (rc == 0) {
112 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
113 seq->lcs_name, PRANGE(&seq->lcs_space));
114 }
115
116 mutex_unlock(&seq->lcs_mutex);
117
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800118 return count;
Peng Taod7e09d02013-05-02 16:46:55 +0800119}
120
121static int
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400122ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused)
Peng Taod7e09d02013-05-02 16:46:55 +0800123{
Peng Tao73bb1da2013-05-29 21:40:55 +0800124 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800125
Peng Taod7e09d02013-05-02 16:46:55 +0800126 mutex_lock(&seq->lcs_mutex);
Joe Perches91b3a682015-03-01 19:58:57 -0800127 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
Peng Taod7e09d02013-05-02 16:46:55 +0800128 mutex_unlock(&seq->lcs_mutex);
129
Joe Perches91b3a682015-03-01 19:58:57 -0800130 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800131}
132
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400133static ssize_t
134ldebugfs_fid_width_seq_write(struct file *file,
135 const char __user *buffer,
136 size_t count, loff_t *off)
Peng Taod7e09d02013-05-02 16:46:55 +0800137{
Anil Belurd1acbe52014-06-19 17:29:01 +1000138 struct lu_client_seq *seq;
Peng Taod7e09d02013-05-02 16:46:55 +0800139 __u64 max;
140 int rc, val;
Peng Taod7e09d02013-05-02 16:46:55 +0800141
Anil Belurd1acbe52014-06-19 17:29:01 +1000142 seq = ((struct seq_file *)file->private_data)->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800143
Peng Taod7e09d02013-05-02 16:46:55 +0800144 rc = lprocfs_write_helper(buffer, count, &val);
Peng Tao73bb1da2013-05-29 21:40:55 +0800145 if (rc)
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800146 return rc;
Peng Taod7e09d02013-05-02 16:46:55 +0800147
Peng Tao73bb1da2013-05-29 21:40:55 +0800148 mutex_lock(&seq->lcs_mutex);
Peng Taod7e09d02013-05-02 16:46:55 +0800149 if (seq->lcs_type == LUSTRE_SEQ_DATA)
150 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
151 else
152 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
153
154 if (val <= max && val > 0) {
155 seq->lcs_width = val;
156
Dan Carpenter1c017372015-06-05 12:23:31 +0300157 CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name,
158 seq->lcs_width);
Peng Taod7e09d02013-05-02 16:46:55 +0800159 }
160
161 mutex_unlock(&seq->lcs_mutex);
162
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800163 return count;
Peng Taod7e09d02013-05-02 16:46:55 +0800164}
165
166static int
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400167ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused)
Peng Taod7e09d02013-05-02 16:46:55 +0800168{
Peng Tao73bb1da2013-05-29 21:40:55 +0800169 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800170
Peng Taod7e09d02013-05-02 16:46:55 +0800171 mutex_lock(&seq->lcs_mutex);
Joe Perches91b3a682015-03-01 19:58:57 -0800172 seq_printf(m, "%llu\n", seq->lcs_width);
Peng Taod7e09d02013-05-02 16:46:55 +0800173 mutex_unlock(&seq->lcs_mutex);
174
Joe Perches91b3a682015-03-01 19:58:57 -0800175 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800176}
177
178static int
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400179ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused)
Peng Taod7e09d02013-05-02 16:46:55 +0800180{
Peng Tao73bb1da2013-05-29 21:40:55 +0800181 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800182
Peng Taod7e09d02013-05-02 16:46:55 +0800183 mutex_lock(&seq->lcs_mutex);
Joe Perches91b3a682015-03-01 19:58:57 -0800184 seq_printf(m, DFID "\n", PFID(&seq->lcs_fid));
Peng Taod7e09d02013-05-02 16:46:55 +0800185 mutex_unlock(&seq->lcs_mutex);
186
Joe Perches91b3a682015-03-01 19:58:57 -0800187 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800188}
189
190static int
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400191ldebugfs_fid_server_seq_show(struct seq_file *m, void *unused)
Peng Taod7e09d02013-05-02 16:46:55 +0800192{
Peng Tao73bb1da2013-05-29 21:40:55 +0800193 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
Peng Taod7e09d02013-05-02 16:46:55 +0800194 struct client_obd *cli;
Peng Taod7e09d02013-05-02 16:46:55 +0800195
Oleg Drokin6a9f7482016-02-16 00:46:49 -0500196 if (seq->lcs_exp) {
Peng Taod7e09d02013-05-02 16:46:55 +0800197 cli = &seq->lcs_exp->exp_obd->u.cli;
Joe Perches91b3a682015-03-01 19:58:57 -0800198 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
Peng Taod7e09d02013-05-02 16:46:55 +0800199 }
Joe Perches91b3a682015-03-01 19:58:57 -0800200
201 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800202}
203
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400204LPROC_SEQ_FOPS(ldebugfs_fid_space);
205LPROC_SEQ_FOPS(ldebugfs_fid_width);
206LPROC_SEQ_FOPS_RO(ldebugfs_fid_server);
207LPROC_SEQ_FOPS_RO(ldebugfs_fid_fid);
Peng Taod7e09d02013-05-02 16:46:55 +0800208
Dmitry Ereminf3aa79f2015-05-21 15:32:25 -0400209struct lprocfs_vars seq_client_debugfs_list[] = {
210 { "space", &ldebugfs_fid_space_fops },
211 { "width", &ldebugfs_fid_width_fops },
212 { "server", &ldebugfs_fid_server_fops },
213 { "fid", &ldebugfs_fid_fid_fops },
Peng Tao73bb1da2013-05-29 21:40:55 +0800214 { NULL }
215};