1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#define DEBUG_SUBSYSTEM S_FID
44
45#include "../../include/linux/libcfs/libcfs.h"
46#include <linux/module.h>
47
48#include "../include/obd.h"
49#include "../include/obd_class.h"
50#include "../include/dt_object.h"
51#include "../include/obd_support.h"
52#include "../include/lustre_req_layout.h"
53#include "../include/lustre_fid.h"
54#include "fid_internal.h"
55
56
57#define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
58
59
60
61
62static int
63ldebugfs_fid_write_common(const char __user *buffer, size_t count,
64 struct lu_seq_range *range)
65{
66 struct lu_seq_range tmp;
67 int rc;
68 char kernbuf[MAX_FID_RANGE_STRLEN];
69
70 LASSERT(range != NULL);
71
72 if (count >= sizeof(kernbuf))
73 return -EINVAL;
74
75 if (copy_from_user(kernbuf, buffer, count))
76 return -EFAULT;
77
78 kernbuf[count] = 0;
79
80 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
81 memset(range, 0, sizeof(*range));
82 return count;
83 }
84
85
86 rc = sscanf(kernbuf, "[%llx - %llx]\n",
87 (unsigned long long *)&tmp.lsr_start,
88 (unsigned long long *)&tmp.lsr_end);
89 if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
90 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
91 return -EINVAL;
92 *range = tmp;
93 return count;
94}
95
96
97static ssize_t
98ldebugfs_fid_space_seq_write(struct file *file,
99 const char __user *buffer,
100 size_t count, loff_t *off)
101{
102 struct lu_client_seq *seq;
103 int rc;
104
105 seq = ((struct seq_file *)file->private_data)->private;
106 LASSERT(seq != NULL);
107
108 mutex_lock(&seq->lcs_mutex);
109 rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
110
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
118 return count;
119}
120
121static int
122ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused)
123{
124 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
125
126 LASSERT(seq != NULL);
127
128 mutex_lock(&seq->lcs_mutex);
129 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
130 mutex_unlock(&seq->lcs_mutex);
131
132 return 0;
133}
134
135static ssize_t
136ldebugfs_fid_width_seq_write(struct file *file,
137 const char __user *buffer,
138 size_t count, loff_t *off)
139{
140 struct lu_client_seq *seq;
141 __u64 max;
142 int rc, val;
143
144 seq = ((struct seq_file *)file->private_data)->private;
145 LASSERT(seq != NULL);
146
147 rc = lprocfs_write_helper(buffer, count, &val);
148 if (rc)
149 return rc;
150
151 mutex_lock(&seq->lcs_mutex);
152 if (seq->lcs_type == LUSTRE_SEQ_DATA)
153 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
154 else
155 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
156
157 if (val <= max && val > 0) {
158 seq->lcs_width = val;
159
160 CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name,
161 seq->lcs_width);
162 }
163
164 mutex_unlock(&seq->lcs_mutex);
165
166 return count;
167}
168
169static int
170ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused)
171{
172 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
173
174 LASSERT(seq != NULL);
175
176 mutex_lock(&seq->lcs_mutex);
177 seq_printf(m, "%llu\n", seq->lcs_width);
178 mutex_unlock(&seq->lcs_mutex);
179
180 return 0;
181}
182
183static int
184ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused)
185{
186 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
187
188 LASSERT(seq != NULL);
189
190 mutex_lock(&seq->lcs_mutex);
191 seq_printf(m, DFID "\n", PFID(&seq->lcs_fid));
192 mutex_unlock(&seq->lcs_mutex);
193
194 return 0;
195}
196
197static int
198ldebugfs_fid_server_seq_show(struct seq_file *m, void *unused)
199{
200 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
201 struct client_obd *cli;
202
203 LASSERT(seq != NULL);
204
205 if (seq->lcs_exp != NULL) {
206 cli = &seq->lcs_exp->exp_obd->u.cli;
207 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
208 } else {
209 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
210 }
211
212 return 0;
213}
214
215LPROC_SEQ_FOPS(ldebugfs_fid_space);
216LPROC_SEQ_FOPS(ldebugfs_fid_width);
217LPROC_SEQ_FOPS_RO(ldebugfs_fid_server);
218LPROC_SEQ_FOPS_RO(ldebugfs_fid_fid);
219
220struct lprocfs_vars seq_client_debugfs_list[] = {
221 { "space", &ldebugfs_fid_space_fops },
222 { "width", &ldebugfs_fid_width_fops },
223 { "server", &ldebugfs_fid_server_fops },
224 { "fid", &ldebugfs_fid_fid_fops },
225 { NULL }
226};
227