Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
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) 2002, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | */ | |
36 | #define DEBUG_SUBSYSTEM S_CLASS | |
37 | ||
382e0955 | 38 | #include <linux/statfs.h> |
3ee30015 GKH |
39 | #include "../include/obd_cksum.h" |
40 | #include "../include/obd_class.h" | |
41 | #include "../include/lprocfs_status.h" | |
d7e09d03 PT |
42 | #include <linux/seq_file.h> |
43 | #include "osc_internal.h" | |
44 | ||
aab38b00 OD |
45 | static ssize_t active_show(struct kobject *kobj, struct attribute *attr, |
46 | char *buf) | |
d7e09d03 | 47 | { |
aab38b00 OD |
48 | struct obd_device *dev = container_of(kobj, struct obd_device, |
49 | obd_kobj); | |
91b3a685 | 50 | |
aab38b00 | 51 | return sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive); |
d7e09d03 PT |
52 | } |
53 | ||
aab38b00 OD |
54 | static ssize_t active_store(struct kobject *kobj, struct attribute *attr, |
55 | const char *buffer, | |
56 | size_t count) | |
d7e09d03 | 57 | { |
aab38b00 OD |
58 | struct obd_device *dev = container_of(kobj, struct obd_device, |
59 | obd_kobj); | |
60 | int rc; | |
61 | unsigned long val; | |
d7e09d03 | 62 | |
aab38b00 | 63 | rc = kstrtoul(buffer, 10, &val); |
fea6fc64 | 64 | if (rc < 0) |
d7e09d03 PT |
65 | return -ERANGE; |
66 | ||
67 | /* opposite senses */ | |
68 | if (dev->u.cli.cl_import->imp_deactive == val) | |
69 | rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val); | |
70 | else | |
aab38b00 OD |
71 | CDEBUG(D_CONFIG, "activate %ld: ignoring repeat request\n", |
72 | val); | |
d7e09d03 PT |
73 | |
74 | return count; | |
75 | } | |
aab38b00 | 76 | LUSTRE_RW_ATTR(active); |
d7e09d03 | 77 | |
aab38b00 OD |
78 | static ssize_t max_rpcs_in_flight_show(struct kobject *kobj, |
79 | struct attribute *attr, | |
80 | char *buf) | |
d7e09d03 | 81 | { |
aab38b00 OD |
82 | struct obd_device *dev = container_of(kobj, struct obd_device, |
83 | obd_kobj); | |
d7e09d03 | 84 | struct client_obd *cli = &dev->u.cli; |
d7e09d03 | 85 | |
aab38b00 | 86 | return sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight); |
d7e09d03 PT |
87 | } |
88 | ||
aab38b00 OD |
89 | static ssize_t max_rpcs_in_flight_store(struct kobject *kobj, |
90 | struct attribute *attr, | |
91 | const char *buffer, | |
92 | size_t count) | |
d7e09d03 | 93 | { |
aab38b00 OD |
94 | struct obd_device *dev = container_of(kobj, struct obd_device, |
95 | obd_kobj); | |
d7e09d03 | 96 | struct client_obd *cli = &dev->u.cli; |
aab38b00 OD |
97 | int rc; |
98 | unsigned long val; | |
aefd9d71 | 99 | int adding, added, req_count; |
d7e09d03 | 100 | |
aab38b00 | 101 | rc = kstrtoul(buffer, 10, &val); |
d7e09d03 PT |
102 | if (rc) |
103 | return rc; | |
104 | ||
105 | if (val < 1 || val > OSC_MAX_RIF_MAX) | |
106 | return -ERANGE; | |
107 | ||
aefd9d71 LX |
108 | adding = val - cli->cl_max_rpcs_in_flight; |
109 | req_count = atomic_read(&osc_pool_req_count); | |
110 | if (adding > 0 && req_count < osc_reqpool_maxreqcount) { | |
111 | /* | |
112 | * There might be some race which will cause over-limit | |
113 | * allocation, but it is fine. | |
114 | */ | |
115 | if (req_count + adding > osc_reqpool_maxreqcount) | |
116 | adding = osc_reqpool_maxreqcount - req_count; | |
117 | ||
118 | added = osc_rq_pool->prp_populate(osc_rq_pool, adding); | |
119 | atomic_add(added, &osc_pool_req_count); | |
120 | } | |
d7e09d03 PT |
121 | |
122 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
123 | cli->cl_max_rpcs_in_flight = val; | |
124 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
125 | ||
d7e09d03 PT |
126 | return count; |
127 | } | |
aab38b00 | 128 | LUSTRE_RW_ATTR(max_rpcs_in_flight); |
d7e09d03 | 129 | |
aab38b00 OD |
130 | static ssize_t max_dirty_mb_show(struct kobject *kobj, |
131 | struct attribute *attr, | |
132 | char *buf) | |
d7e09d03 | 133 | { |
aab38b00 OD |
134 | struct obd_device *dev = container_of(kobj, struct obd_device, |
135 | obd_kobj); | |
d7e09d03 PT |
136 | struct client_obd *cli = &dev->u.cli; |
137 | long val; | |
138 | int mult; | |
139 | ||
140 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
141 | val = cli->cl_dirty_max; | |
142 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
143 | ||
144 | mult = 1 << 20; | |
aab38b00 | 145 | return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult); |
d7e09d03 PT |
146 | } |
147 | ||
aab38b00 OD |
148 | static ssize_t max_dirty_mb_store(struct kobject *kobj, |
149 | struct attribute *attr, | |
150 | const char *buffer, | |
151 | size_t count) | |
d7e09d03 | 152 | { |
aab38b00 OD |
153 | struct obd_device *dev = container_of(kobj, struct obd_device, |
154 | obd_kobj); | |
d7e09d03 | 155 | struct client_obd *cli = &dev->u.cli; |
aab38b00 OD |
156 | int rc; |
157 | unsigned long pages_number; | |
d7e09d03 | 158 | |
aab38b00 | 159 | rc = kstrtoul(buffer, 10, &pages_number); |
d7e09d03 PT |
160 | if (rc) |
161 | return rc; | |
162 | ||
aab38b00 OD |
163 | pages_number *= 1 << (20 - PAGE_CACHE_SHIFT); /* MB -> pages */ |
164 | ||
d7e09d03 PT |
165 | if (pages_number <= 0 || |
166 | pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) || | |
4f6cc9ab | 167 | pages_number > totalram_pages / 4) /* 1/4 of RAM */ |
d7e09d03 PT |
168 | return -ERANGE; |
169 | ||
170 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
21aef7d9 | 171 | cli->cl_dirty_max = (u32)(pages_number << PAGE_CACHE_SHIFT); |
d7e09d03 PT |
172 | osc_wake_cache_waiters(cli); |
173 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
174 | ||
175 | return count; | |
176 | } | |
aab38b00 | 177 | LUSTRE_RW_ATTR(max_dirty_mb); |
d7e09d03 | 178 | |
73bb1da6 | 179 | static int osc_cached_mb_seq_show(struct seq_file *m, void *v) |
d7e09d03 | 180 | { |
73bb1da6 | 181 | struct obd_device *dev = m->private; |
d7e09d03 PT |
182 | struct client_obd *cli = &dev->u.cli; |
183 | int shift = 20 - PAGE_CACHE_SHIFT; | |
d7e09d03 | 184 | |
91b3a685 JP |
185 | seq_printf(m, |
186 | "used_mb: %d\n" | |
187 | "busy_cnt: %d\n", | |
188 | (atomic_read(&cli->cl_lru_in_list) + | |
189 | atomic_read(&cli->cl_lru_busy)) >> shift, | |
190 | atomic_read(&cli->cl_lru_busy)); | |
191 | ||
192 | return 0; | |
d7e09d03 PT |
193 | } |
194 | ||
195 | /* shrink the number of caching pages to a specific number */ | |
a1e7e2d4 OD |
196 | static ssize_t osc_cached_mb_seq_write(struct file *file, |
197 | const char __user *buffer, | |
198 | size_t count, loff_t *off) | |
d7e09d03 | 199 | { |
73bb1da6 | 200 | struct obd_device *dev = ((struct seq_file *)file->private_data)->private; |
d7e09d03 PT |
201 | struct client_obd *cli = &dev->u.cli; |
202 | int pages_number, mult, rc; | |
a1e7e2d4 OD |
203 | char kernbuf[128]; |
204 | ||
205 | if (count >= sizeof(kernbuf)) | |
206 | return -EINVAL; | |
207 | ||
208 | if (copy_from_user(kernbuf, buffer, count)) | |
209 | return -EFAULT; | |
210 | kernbuf[count] = 0; | |
d7e09d03 PT |
211 | |
212 | mult = 1 << (20 - PAGE_CACHE_SHIFT); | |
a1e7e2d4 OD |
213 | buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) - |
214 | kernbuf; | |
d7e09d03 PT |
215 | rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult); |
216 | if (rc) | |
217 | return rc; | |
218 | ||
219 | if (pages_number < 0) | |
220 | return -ERANGE; | |
221 | ||
222 | rc = atomic_read(&cli->cl_lru_in_list) - pages_number; | |
223 | if (rc > 0) | |
224 | (void)osc_lru_shrink(cli, rc); | |
225 | ||
226 | return count; | |
227 | } | |
c9f6bb96 | 228 | |
73bb1da6 | 229 | LPROC_SEQ_FOPS(osc_cached_mb); |
d7e09d03 | 230 | |
aab38b00 OD |
231 | static ssize_t cur_dirty_bytes_show(struct kobject *kobj, |
232 | struct attribute *attr, | |
233 | char *buf) | |
d7e09d03 | 234 | { |
aab38b00 OD |
235 | struct obd_device *dev = container_of(kobj, struct obd_device, |
236 | obd_kobj); | |
d7e09d03 | 237 | struct client_obd *cli = &dev->u.cli; |
aab38b00 | 238 | int len; |
d7e09d03 PT |
239 | |
240 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
aab38b00 | 241 | len = sprintf(buf, "%lu\n", cli->cl_dirty); |
d7e09d03 | 242 | client_obd_list_unlock(&cli->cl_loi_list_lock); |
91b3a685 | 243 | |
aab38b00 | 244 | return len; |
d7e09d03 | 245 | } |
aab38b00 | 246 | LUSTRE_RO_ATTR(cur_dirty_bytes); |
d7e09d03 | 247 | |
aab38b00 OD |
248 | static ssize_t cur_grant_bytes_show(struct kobject *kobj, |
249 | struct attribute *attr, | |
250 | char *buf) | |
d7e09d03 | 251 | { |
aab38b00 OD |
252 | struct obd_device *dev = container_of(kobj, struct obd_device, |
253 | obd_kobj); | |
d7e09d03 | 254 | struct client_obd *cli = &dev->u.cli; |
aab38b00 | 255 | int len; |
d7e09d03 PT |
256 | |
257 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
aab38b00 | 258 | len = sprintf(buf, "%lu\n", cli->cl_avail_grant); |
d7e09d03 | 259 | client_obd_list_unlock(&cli->cl_loi_list_lock); |
91b3a685 | 260 | |
aab38b00 | 261 | return len; |
d7e09d03 PT |
262 | } |
263 | ||
aab38b00 OD |
264 | static ssize_t cur_grant_bytes_store(struct kobject *kobj, |
265 | struct attribute *attr, | |
266 | const char *buffer, | |
267 | size_t count) | |
d7e09d03 | 268 | { |
aab38b00 OD |
269 | struct obd_device *obd = container_of(kobj, struct obd_device, |
270 | obd_kobj); | |
d7e09d03 | 271 | struct client_obd *cli = &obd->u.cli; |
aab38b00 OD |
272 | int rc; |
273 | unsigned long long val; | |
d7e09d03 | 274 | |
aab38b00 | 275 | rc = kstrtoull(buffer, 10, &val); |
d7e09d03 PT |
276 | if (rc) |
277 | return rc; | |
278 | ||
279 | /* this is only for shrinking grant */ | |
280 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
281 | if (val >= cli->cl_avail_grant) { | |
282 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
aab38b00 | 283 | return -EINVAL; |
d7e09d03 PT |
284 | } |
285 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
286 | ||
d7e09d03 PT |
287 | if (cli->cl_import->imp_state == LUSTRE_IMP_FULL) |
288 | rc = osc_shrink_grant_to_target(cli, val); | |
d7e09d03 PT |
289 | if (rc) |
290 | return rc; | |
291 | return count; | |
292 | } | |
aab38b00 | 293 | LUSTRE_RW_ATTR(cur_grant_bytes); |
d7e09d03 | 294 | |
aab38b00 OD |
295 | static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj, |
296 | struct attribute *attr, | |
297 | char *buf) | |
d7e09d03 | 298 | { |
aab38b00 OD |
299 | struct obd_device *dev = container_of(kobj, struct obd_device, |
300 | obd_kobj); | |
d7e09d03 | 301 | struct client_obd *cli = &dev->u.cli; |
aab38b00 | 302 | int len; |
d7e09d03 PT |
303 | |
304 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
aab38b00 | 305 | len = sprintf(buf, "%lu\n", cli->cl_lost_grant); |
d7e09d03 | 306 | client_obd_list_unlock(&cli->cl_loi_list_lock); |
91b3a685 | 307 | |
aab38b00 | 308 | return len; |
d7e09d03 | 309 | } |
aab38b00 | 310 | LUSTRE_RO_ATTR(cur_lost_grant_bytes); |
d7e09d03 | 311 | |
aab38b00 OD |
312 | static ssize_t grant_shrink_interval_show(struct kobject *kobj, |
313 | struct attribute *attr, | |
314 | char *buf) | |
d7e09d03 | 315 | { |
aab38b00 OD |
316 | struct obd_device *obd = container_of(kobj, struct obd_device, |
317 | obd_kobj); | |
d7e09d03 | 318 | |
aab38b00 | 319 | return sprintf(buf, "%d\n", obd->u.cli.cl_grant_shrink_interval); |
d7e09d03 PT |
320 | } |
321 | ||
aab38b00 OD |
322 | static ssize_t grant_shrink_interval_store(struct kobject *kobj, |
323 | struct attribute *attr, | |
324 | const char *buffer, | |
325 | size_t count) | |
d7e09d03 | 326 | { |
aab38b00 OD |
327 | struct obd_device *obd = container_of(kobj, struct obd_device, |
328 | obd_kobj); | |
329 | int rc; | |
330 | unsigned long val; | |
d7e09d03 | 331 | |
aab38b00 | 332 | rc = kstrtoul(buffer, 10, &val); |
d7e09d03 PT |
333 | if (rc) |
334 | return rc; | |
335 | ||
336 | if (val <= 0) | |
337 | return -ERANGE; | |
338 | ||
339 | obd->u.cli.cl_grant_shrink_interval = val; | |
340 | ||
341 | return count; | |
342 | } | |
aab38b00 | 343 | LUSTRE_RW_ATTR(grant_shrink_interval); |
d7e09d03 | 344 | |
aab38b00 OD |
345 | static ssize_t checksums_show(struct kobject *kobj, |
346 | struct attribute *attr, | |
347 | char *buf) | |
d7e09d03 | 348 | { |
aab38b00 OD |
349 | struct obd_device *obd = container_of(kobj, struct obd_device, |
350 | obd_kobj); | |
d7e09d03 | 351 | |
aab38b00 | 352 | return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0); |
d7e09d03 PT |
353 | } |
354 | ||
aab38b00 OD |
355 | static ssize_t checksums_store(struct kobject *kobj, |
356 | struct attribute *attr, | |
357 | const char *buffer, | |
358 | size_t count) | |
d7e09d03 | 359 | { |
aab38b00 OD |
360 | struct obd_device *obd = container_of(kobj, struct obd_device, |
361 | obd_kobj); | |
362 | int rc; | |
363 | unsigned long val; | |
d7e09d03 | 364 | |
aab38b00 | 365 | rc = kstrtoul(buffer, 10, &val); |
d7e09d03 PT |
366 | if (rc) |
367 | return rc; | |
368 | ||
369 | obd->u.cli.cl_checksum = (val ? 1 : 0); | |
370 | ||
371 | return count; | |
372 | } | |
aab38b00 | 373 | LUSTRE_RW_ATTR(checksums); |
d7e09d03 | 374 | |
73bb1da6 | 375 | static int osc_checksum_type_seq_show(struct seq_file *m, void *v) |
d7e09d03 | 376 | { |
73bb1da6 PT |
377 | struct obd_device *obd = m->private; |
378 | int i; | |
50ffcb7e | 379 | |
d7e09d03 PT |
380 | DECLARE_CKSUM_NAME; |
381 | ||
382 | if (obd == NULL) | |
383 | return 0; | |
384 | ||
73bb1da6 | 385 | for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { |
d7e09d03 PT |
386 | if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0) |
387 | continue; | |
388 | if (obd->u.cli.cl_cksum_type == (1 << i)) | |
73bb1da6 | 389 | seq_printf(m, "[%s] ", cksum_name[i]); |
d7e09d03 | 390 | else |
73bb1da6 | 391 | seq_printf(m, "%s ", cksum_name[i]); |
d7e09d03 | 392 | } |
e6aa864f | 393 | seq_putc(m, '\n'); |
73bb1da6 | 394 | return 0; |
d7e09d03 PT |
395 | } |
396 | ||
e84962e3 TL |
397 | static ssize_t osc_checksum_type_seq_write(struct file *file, |
398 | const char __user *buffer, | |
73bb1da6 | 399 | size_t count, loff_t *off) |
d7e09d03 | 400 | { |
73bb1da6 | 401 | struct obd_device *obd = ((struct seq_file *)file->private_data)->private; |
d7e09d03 | 402 | int i; |
50ffcb7e | 403 | |
d7e09d03 PT |
404 | DECLARE_CKSUM_NAME; |
405 | char kernbuf[10]; | |
406 | ||
407 | if (obd == NULL) | |
408 | return 0; | |
409 | ||
410 | if (count > sizeof(kernbuf) - 1) | |
411 | return -EINVAL; | |
412 | if (copy_from_user(kernbuf, buffer, count)) | |
413 | return -EFAULT; | |
414 | if (count > 0 && kernbuf[count - 1] == '\n') | |
415 | kernbuf[count - 1] = '\0'; | |
416 | else | |
417 | kernbuf[count] = '\0'; | |
418 | ||
419 | for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { | |
420 | if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0) | |
421 | continue; | |
422 | if (!strcmp(kernbuf, cksum_name[i])) { | |
423 | obd->u.cli.cl_cksum_type = 1 << i; | |
424 | return count; | |
425 | } | |
426 | } | |
427 | return -EINVAL; | |
428 | } | |
c9f6bb96 | 429 | |
73bb1da6 | 430 | LPROC_SEQ_FOPS(osc_checksum_type); |
d7e09d03 | 431 | |
aab38b00 | 432 | static ssize_t resend_count_show(struct kobject *kobj, |
29ac6840 CH |
433 | struct attribute *attr, |
434 | char *buf) | |
d7e09d03 | 435 | { |
aab38b00 OD |
436 | struct obd_device *obd = container_of(kobj, struct obd_device, |
437 | obd_kobj); | |
d7e09d03 | 438 | |
aab38b00 | 439 | return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends)); |
d7e09d03 PT |
440 | } |
441 | ||
aab38b00 | 442 | static ssize_t resend_count_store(struct kobject *kobj, |
29ac6840 CH |
443 | struct attribute *attr, |
444 | const char *buffer, | |
445 | size_t count) | |
d7e09d03 | 446 | { |
aab38b00 OD |
447 | struct obd_device *obd = container_of(kobj, struct obd_device, |
448 | obd_kobj); | |
449 | int rc; | |
450 | unsigned long val; | |
d7e09d03 | 451 | |
aab38b00 | 452 | rc = kstrtoul(buffer, 10, &val); |
d7e09d03 PT |
453 | if (rc) |
454 | return rc; | |
455 | ||
d7e09d03 PT |
456 | atomic_set(&obd->u.cli.cl_resends, val); |
457 | ||
458 | return count; | |
459 | } | |
aab38b00 | 460 | LUSTRE_RW_ATTR(resend_count); |
d7e09d03 | 461 | |
aab38b00 OD |
462 | static ssize_t contention_seconds_show(struct kobject *kobj, |
463 | struct attribute *attr, | |
464 | char *buf) | |
d7e09d03 | 465 | { |
aab38b00 OD |
466 | struct obd_device *obd = container_of(kobj, struct obd_device, |
467 | obd_kobj); | |
d7e09d03 PT |
468 | struct osc_device *od = obd2osc_dev(obd); |
469 | ||
aab38b00 | 470 | return sprintf(buf, "%u\n", od->od_contention_time); |
d7e09d03 PT |
471 | } |
472 | ||
aab38b00 OD |
473 | static ssize_t contention_seconds_store(struct kobject *kobj, |
474 | struct attribute *attr, | |
475 | const char *buffer, | |
476 | size_t count) | |
d7e09d03 | 477 | { |
aab38b00 OD |
478 | struct obd_device *obd = container_of(kobj, struct obd_device, |
479 | obd_kobj); | |
d7e09d03 PT |
480 | struct osc_device *od = obd2osc_dev(obd); |
481 | ||
482 | return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?: | |
483 | count; | |
484 | } | |
aab38b00 | 485 | LUSTRE_RW_ATTR(contention_seconds); |
d7e09d03 | 486 | |
aab38b00 OD |
487 | static ssize_t lockless_truncate_show(struct kobject *kobj, |
488 | struct attribute *attr, | |
489 | char *buf) | |
d7e09d03 | 490 | { |
aab38b00 OD |
491 | struct obd_device *obd = container_of(kobj, struct obd_device, |
492 | obd_kobj); | |
d7e09d03 PT |
493 | struct osc_device *od = obd2osc_dev(obd); |
494 | ||
aab38b00 | 495 | return sprintf(buf, "%u\n", od->od_lockless_truncate); |
d7e09d03 PT |
496 | } |
497 | ||
aab38b00 OD |
498 | static ssize_t lockless_truncate_store(struct kobject *kobj, |
499 | struct attribute *attr, | |
500 | const char *buffer, | |
501 | size_t count) | |
d7e09d03 | 502 | { |
aab38b00 OD |
503 | struct obd_device *obd = container_of(kobj, struct obd_device, |
504 | obd_kobj); | |
d7e09d03 PT |
505 | struct osc_device *od = obd2osc_dev(obd); |
506 | ||
507 | return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?: | |
508 | count; | |
509 | } | |
aab38b00 | 510 | LUSTRE_RW_ATTR(lockless_truncate); |
d7e09d03 | 511 | |
aab38b00 OD |
512 | static ssize_t destroys_in_flight_show(struct kobject *kobj, |
513 | struct attribute *attr, | |
514 | char *buf) | |
d7e09d03 | 515 | { |
aab38b00 OD |
516 | struct obd_device *obd = container_of(kobj, struct obd_device, |
517 | obd_kobj); | |
8faeebdf | 518 | |
aab38b00 OD |
519 | return sprintf(buf, "%u\n", |
520 | atomic_read(&obd->u.cli.cl_destroy_in_flight)); | |
d7e09d03 | 521 | } |
aab38b00 | 522 | LUSTRE_RO_ATTR(destroys_in_flight); |
73bb1da6 | 523 | |
aab38b00 OD |
524 | static ssize_t max_pages_per_rpc_show(struct kobject *kobj, |
525 | struct attribute *attr, | |
526 | char *buf) | |
73bb1da6 | 527 | { |
aab38b00 OD |
528 | struct obd_device *dev = container_of(kobj, struct obd_device, |
529 | obd_kobj); | |
530 | struct client_obd *cli = &dev->u.cli; | |
531 | ||
532 | return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc); | |
73bb1da6 | 533 | } |
d7e09d03 | 534 | |
aab38b00 OD |
535 | static ssize_t max_pages_per_rpc_store(struct kobject *kobj, |
536 | struct attribute *attr, | |
537 | const char *buffer, | |
538 | size_t count) | |
d7e09d03 | 539 | { |
aab38b00 OD |
540 | struct obd_device *dev = container_of(kobj, struct obd_device, |
541 | obd_kobj); | |
d7e09d03 PT |
542 | struct client_obd *cli = &dev->u.cli; |
543 | struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data; | |
544 | int chunk_mask, rc; | |
aab38b00 | 545 | unsigned long long val; |
d7e09d03 | 546 | |
aab38b00 | 547 | rc = kstrtoull(buffer, 10, &val); |
d7e09d03 PT |
548 | if (rc) |
549 | return rc; | |
550 | ||
551 | /* if the max_pages is specified in bytes, convert to pages */ | |
552 | if (val >= ONE_MB_BRW_SIZE) | |
553 | val >>= PAGE_CACHE_SHIFT; | |
554 | ||
d7e09d03 PT |
555 | chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1); |
556 | /* max_pages_per_rpc must be chunk aligned */ | |
557 | val = (val + ~chunk_mask) & chunk_mask; | |
558 | if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) { | |
d7e09d03 PT |
559 | return -ERANGE; |
560 | } | |
561 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
562 | cli->cl_max_pages_per_rpc = val; | |
563 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
564 | ||
d7e09d03 PT |
565 | return count; |
566 | } | |
aab38b00 | 567 | LUSTRE_RW_ATTR(max_pages_per_rpc); |
73bb1da6 | 568 | |
73bb1da6 | 569 | LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags); |
73bb1da6 PT |
570 | LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid); |
571 | LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid); | |
572 | LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts); | |
573 | LPROC_SEQ_FOPS_RO_TYPE(osc, state); | |
574 | ||
575 | LPROC_SEQ_FOPS_WR_ONLY(osc, ping); | |
576 | ||
577 | LPROC_SEQ_FOPS_RW_TYPE(osc, import); | |
578 | LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov); | |
d7e09d03 PT |
579 | |
580 | static struct lprocfs_vars lprocfs_osc_obd_vars[] = { | |
114a16b1 BKV |
581 | { "ping", &osc_ping_fops, NULL, 0222 }, |
582 | { "connect_flags", &osc_connect_flags_fops, NULL, 0 }, | |
114a16b1 BKV |
583 | /*{ "filegroups", lprocfs_rd_filegroups, NULL, 0 },*/ |
584 | { "ost_server_uuid", &osc_server_uuid_fops, NULL, 0 }, | |
585 | { "ost_conn_uuid", &osc_conn_uuid_fops, NULL, 0 }, | |
114a16b1 | 586 | { "osc_cached_mb", &osc_cached_mb_fops, NULL }, |
114a16b1 | 587 | { "checksum_type", &osc_checksum_type_fops, NULL }, |
114a16b1 | 588 | { "timeouts", &osc_timeouts_fops, NULL, 0 }, |
114a16b1 BKV |
589 | { "import", &osc_import_fops, NULL }, |
590 | { "state", &osc_state_fops, NULL, 0 }, | |
591 | { "pinger_recov", &osc_pinger_recov_fops, NULL }, | |
592 | { NULL } | |
d7e09d03 PT |
593 | }; |
594 | ||
1d8cb70c | 595 | #define pct(a, b) (b ? a * 100 / b : 0) |
d7e09d03 PT |
596 | |
597 | static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) | |
598 | { | |
86655400 | 599 | struct timespec64 now; |
d7e09d03 PT |
600 | struct obd_device *dev = seq->private; |
601 | struct client_obd *cli = &dev->u.cli; | |
602 | unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum; | |
603 | int i; | |
604 | ||
86655400 | 605 | ktime_get_real_ts64(&now); |
d7e09d03 PT |
606 | |
607 | client_obd_list_lock(&cli->cl_loi_list_lock); | |
608 | ||
86655400 AB |
609 | seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n", |
610 | (s64)now.tv_sec, (unsigned long)now.tv_nsec); | |
d7e09d03 PT |
611 | seq_printf(seq, "read RPCs in flight: %d\n", |
612 | cli->cl_r_in_flight); | |
613 | seq_printf(seq, "write RPCs in flight: %d\n", | |
614 | cli->cl_w_in_flight); | |
615 | seq_printf(seq, "pending write pages: %d\n", | |
616 | atomic_read(&cli->cl_pending_w_pages)); | |
617 | seq_printf(seq, "pending read pages: %d\n", | |
618 | atomic_read(&cli->cl_pending_r_pages)); | |
619 | ||
e6aa864f HA |
620 | seq_puts(seq, "\n\t\t\tread\t\t\twrite\n"); |
621 | seq_puts(seq, "pages per rpc rpcs % cum % |"); | |
622 | seq_puts(seq, " rpcs % cum %\n"); | |
d7e09d03 PT |
623 | |
624 | read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist); | |
625 | write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist); | |
626 | ||
627 | read_cum = 0; | |
628 | write_cum = 0; | |
629 | for (i = 0; i < OBD_HIST_MAX; i++) { | |
630 | unsigned long r = cli->cl_read_page_hist.oh_buckets[i]; | |
631 | unsigned long w = cli->cl_write_page_hist.oh_buckets[i]; | |
50ffcb7e | 632 | |
d7e09d03 PT |
633 | read_cum += r; |
634 | write_cum += w; | |
635 | seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", | |
636 | 1 << i, r, pct(r, read_tot), | |
637 | pct(read_cum, read_tot), w, | |
638 | pct(w, write_tot), | |
639 | pct(write_cum, write_tot)); | |
640 | if (read_cum == read_tot && write_cum == write_tot) | |
641 | break; | |
642 | } | |
643 | ||
e6aa864f HA |
644 | seq_puts(seq, "\n\t\t\tread\t\t\twrite\n"); |
645 | seq_puts(seq, "rpcs in flight rpcs % cum % |"); | |
646 | seq_puts(seq, " rpcs % cum %\n"); | |
d7e09d03 PT |
647 | |
648 | read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist); | |
649 | write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist); | |
650 | ||
651 | read_cum = 0; | |
652 | write_cum = 0; | |
653 | for (i = 0; i < OBD_HIST_MAX; i++) { | |
654 | unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i]; | |
655 | unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i]; | |
50ffcb7e | 656 | |
d7e09d03 PT |
657 | read_cum += r; |
658 | write_cum += w; | |
659 | seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", | |
660 | i, r, pct(r, read_tot), | |
661 | pct(read_cum, read_tot), w, | |
662 | pct(w, write_tot), | |
663 | pct(write_cum, write_tot)); | |
664 | if (read_cum == read_tot && write_cum == write_tot) | |
665 | break; | |
666 | } | |
667 | ||
e6aa864f HA |
668 | seq_puts(seq, "\n\t\t\tread\t\t\twrite\n"); |
669 | seq_puts(seq, "offset rpcs % cum % |"); | |
670 | seq_puts(seq, " rpcs % cum %\n"); | |
d7e09d03 PT |
671 | |
672 | read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist); | |
673 | write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist); | |
674 | ||
675 | read_cum = 0; | |
676 | write_cum = 0; | |
677 | for (i = 0; i < OBD_HIST_MAX; i++) { | |
678 | unsigned long r = cli->cl_read_offset_hist.oh_buckets[i]; | |
679 | unsigned long w = cli->cl_write_offset_hist.oh_buckets[i]; | |
50ffcb7e | 680 | |
d7e09d03 PT |
681 | read_cum += r; |
682 | write_cum += w; | |
683 | seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", | |
684 | (i == 0) ? 0 : 1 << (i - 1), | |
685 | r, pct(r, read_tot), pct(read_cum, read_tot), | |
686 | w, pct(w, write_tot), pct(write_cum, write_tot)); | |
687 | if (read_cum == read_tot && write_cum == write_tot) | |
688 | break; | |
689 | } | |
690 | ||
691 | client_obd_list_unlock(&cli->cl_loi_list_lock); | |
692 | ||
693 | return 0; | |
694 | } | |
c9f6bb96 | 695 | |
d7e09d03 PT |
696 | #undef pct |
697 | ||
e84962e3 | 698 | static ssize_t osc_rpc_stats_seq_write(struct file *file, |
29ac6840 CH |
699 | const char __user *buf, |
700 | size_t len, loff_t *off) | |
d7e09d03 PT |
701 | { |
702 | struct seq_file *seq = file->private_data; | |
703 | struct obd_device *dev = seq->private; | |
704 | struct client_obd *cli = &dev->u.cli; | |
705 | ||
706 | lprocfs_oh_clear(&cli->cl_read_rpc_hist); | |
707 | lprocfs_oh_clear(&cli->cl_write_rpc_hist); | |
708 | lprocfs_oh_clear(&cli->cl_read_page_hist); | |
709 | lprocfs_oh_clear(&cli->cl_write_page_hist); | |
710 | lprocfs_oh_clear(&cli->cl_read_offset_hist); | |
711 | lprocfs_oh_clear(&cli->cl_write_offset_hist); | |
712 | ||
713 | return len; | |
714 | } | |
715 | ||
716 | LPROC_SEQ_FOPS(osc_rpc_stats); | |
717 | ||
718 | static int osc_stats_seq_show(struct seq_file *seq, void *v) | |
719 | { | |
86655400 | 720 | struct timespec64 now; |
d7e09d03 PT |
721 | struct obd_device *dev = seq->private; |
722 | struct osc_stats *stats = &obd2osc_dev(dev)->od_stats; | |
723 | ||
86655400 | 724 | ktime_get_real_ts64(&now); |
d7e09d03 | 725 | |
86655400 AB |
726 | seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n", |
727 | (s64)now.tv_sec, (unsigned long)now.tv_nsec); | |
b0f5aad5 | 728 | seq_printf(seq, "lockless_write_bytes\t\t%llu\n", |
d7e09d03 | 729 | stats->os_lockless_writes); |
b0f5aad5 | 730 | seq_printf(seq, "lockless_read_bytes\t\t%llu\n", |
d7e09d03 | 731 | stats->os_lockless_reads); |
b0f5aad5 | 732 | seq_printf(seq, "lockless_truncate\t\t%llu\n", |
d7e09d03 PT |
733 | stats->os_lockless_truncates); |
734 | return 0; | |
735 | } | |
736 | ||
e84962e3 | 737 | static ssize_t osc_stats_seq_write(struct file *file, |
29ac6840 CH |
738 | const char __user *buf, |
739 | size_t len, loff_t *off) | |
d7e09d03 PT |
740 | { |
741 | struct seq_file *seq = file->private_data; | |
742 | struct obd_device *dev = seq->private; | |
743 | struct osc_stats *stats = &obd2osc_dev(dev)->od_stats; | |
744 | ||
745 | memset(stats, 0, sizeof(*stats)); | |
746 | return len; | |
747 | } | |
748 | ||
749 | LPROC_SEQ_FOPS(osc_stats); | |
750 | ||
751 | int lproc_osc_attach_seqstat(struct obd_device *dev) | |
752 | { | |
753 | int rc; | |
754 | ||
61e87ab0 DE |
755 | rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "osc_stats", 0644, |
756 | &osc_stats_fops, dev); | |
d7e09d03 | 757 | if (rc == 0) |
e4ba525e DE |
758 | rc = ldebugfs_obd_seq_create(dev, "rpc_stats", 0644, |
759 | &osc_rpc_stats_fops, dev); | |
d7e09d03 PT |
760 | |
761 | return rc; | |
762 | } | |
763 | ||
aab38b00 OD |
764 | static struct attribute *osc_attrs[] = { |
765 | &lustre_attr_active.attr, | |
766 | &lustre_attr_checksums.attr, | |
767 | &lustre_attr_contention_seconds.attr, | |
768 | &lustre_attr_cur_dirty_bytes.attr, | |
769 | &lustre_attr_cur_grant_bytes.attr, | |
770 | &lustre_attr_cur_lost_grant_bytes.attr, | |
771 | &lustre_attr_destroys_in_flight.attr, | |
772 | &lustre_attr_grant_shrink_interval.attr, | |
773 | &lustre_attr_lockless_truncate.attr, | |
774 | &lustre_attr_max_dirty_mb.attr, | |
775 | &lustre_attr_max_pages_per_rpc.attr, | |
776 | &lustre_attr_max_rpcs_in_flight.attr, | |
777 | &lustre_attr_resend_count.attr, | |
778 | NULL, | |
779 | }; | |
780 | ||
781 | static struct attribute_group osc_attr_group = { | |
782 | .attrs = osc_attrs, | |
783 | }; | |
784 | ||
d7e09d03 PT |
785 | void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars) |
786 | { | |
aab38b00 | 787 | lvars->sysfs_vars = &osc_attr_group; |
d7e09d03 PT |
788 | lvars->obd_vars = lprocfs_osc_obd_vars; |
789 | } |