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