Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski...
[linux-2.6-block.git] / drivers / staging / lustre / lustre / osc / lproc_osc.c
CommitLineData
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 *
1dc563a6 30 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
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
45static 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
54static 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);
9ebafb53
SB
64 if (rc)
65 return rc;
66 if (val > 1)
d7e09d03
PT
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 78LUSTRE_RW_ATTR(active);
d7e09d03 79
aab38b00
OD
80static 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
91static 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 130LUSTRE_RW_ATTR(max_rpcs_in_flight);
d7e09d03 131
aab38b00
OD
132static 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
150static 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
09cbfeaf 165 pages_number *= 1 << (20 - PAGE_SHIFT); /* MB -> pages */
aab38b00 166
d7e09d03 167 if (pages_number <= 0 ||
09cbfeaf 168 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_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);
09cbfeaf 173 cli->cl_dirty_max = (u32)(pages_number << PAGE_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 179LUSTRE_RW_ATTR(max_dirty_mb);
d7e09d03 180
73bb1da6 181static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
d7e09d03 182{
73bb1da6 183 struct obd_device *dev = m->private;
d7e09d03 184 struct client_obd *cli = &dev->u.cli;
09cbfeaf 185 int shift = 20 - PAGE_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
198static 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 213
09cbfeaf 214 mult = 1 << (20 - PAGE_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}
c9f6bb96 230
73bb1da6 231LPROC_SEQ_FOPS(osc_cached_mb);
d7e09d03 232
aab38b00
OD
233static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
234 struct attribute *attr,
235 char *buf)
d7e09d03 236{
aab38b00
OD
237 struct obd_device *dev = container_of(kobj, struct obd_device,
238 obd_kobj);
d7e09d03 239 struct client_obd *cli = &dev->u.cli;
aab38b00 240 int len;
d7e09d03
PT
241
242 client_obd_list_lock(&cli->cl_loi_list_lock);
aab38b00 243 len = sprintf(buf, "%lu\n", cli->cl_dirty);
d7e09d03 244 client_obd_list_unlock(&cli->cl_loi_list_lock);
91b3a685 245
aab38b00 246 return len;
d7e09d03 247}
aab38b00 248LUSTRE_RO_ATTR(cur_dirty_bytes);
d7e09d03 249
aab38b00
OD
250static ssize_t cur_grant_bytes_show(struct kobject *kobj,
251 struct attribute *attr,
252 char *buf)
d7e09d03 253{
aab38b00
OD
254 struct obd_device *dev = container_of(kobj, struct obd_device,
255 obd_kobj);
d7e09d03 256 struct client_obd *cli = &dev->u.cli;
aab38b00 257 int len;
d7e09d03
PT
258
259 client_obd_list_lock(&cli->cl_loi_list_lock);
aab38b00 260 len = sprintf(buf, "%lu\n", cli->cl_avail_grant);
d7e09d03 261 client_obd_list_unlock(&cli->cl_loi_list_lock);
91b3a685 262
aab38b00 263 return len;
d7e09d03
PT
264}
265
aab38b00
OD
266static ssize_t cur_grant_bytes_store(struct kobject *kobj,
267 struct attribute *attr,
268 const char *buffer,
269 size_t count)
d7e09d03 270{
aab38b00
OD
271 struct obd_device *obd = container_of(kobj, struct obd_device,
272 obd_kobj);
d7e09d03 273 struct client_obd *cli = &obd->u.cli;
aab38b00
OD
274 int rc;
275 unsigned long long val;
d7e09d03 276
aab38b00 277 rc = kstrtoull(buffer, 10, &val);
d7e09d03
PT
278 if (rc)
279 return rc;
280
281 /* this is only for shrinking grant */
282 client_obd_list_lock(&cli->cl_loi_list_lock);
283 if (val >= cli->cl_avail_grant) {
284 client_obd_list_unlock(&cli->cl_loi_list_lock);
aab38b00 285 return -EINVAL;
d7e09d03
PT
286 }
287 client_obd_list_unlock(&cli->cl_loi_list_lock);
288
d7e09d03
PT
289 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
290 rc = osc_shrink_grant_to_target(cli, val);
d7e09d03
PT
291 if (rc)
292 return rc;
293 return count;
294}
aab38b00 295LUSTRE_RW_ATTR(cur_grant_bytes);
d7e09d03 296
aab38b00
OD
297static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
298 struct attribute *attr,
299 char *buf)
d7e09d03 300{
aab38b00
OD
301 struct obd_device *dev = container_of(kobj, struct obd_device,
302 obd_kobj);
d7e09d03 303 struct client_obd *cli = &dev->u.cli;
aab38b00 304 int len;
d7e09d03
PT
305
306 client_obd_list_lock(&cli->cl_loi_list_lock);
aab38b00 307 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
d7e09d03 308 client_obd_list_unlock(&cli->cl_loi_list_lock);
91b3a685 309
aab38b00 310 return len;
d7e09d03 311}
aab38b00 312LUSTRE_RO_ATTR(cur_lost_grant_bytes);
d7e09d03 313
aab38b00
OD
314static ssize_t grant_shrink_interval_show(struct kobject *kobj,
315 struct attribute *attr,
316 char *buf)
d7e09d03 317{
aab38b00
OD
318 struct obd_device *obd = container_of(kobj, struct obd_device,
319 obd_kobj);
d7e09d03 320
aab38b00 321 return sprintf(buf, "%d\n", obd->u.cli.cl_grant_shrink_interval);
d7e09d03
PT
322}
323
aab38b00
OD
324static ssize_t grant_shrink_interval_store(struct kobject *kobj,
325 struct attribute *attr,
326 const char *buffer,
327 size_t count)
d7e09d03 328{
aab38b00
OD
329 struct obd_device *obd = container_of(kobj, struct obd_device,
330 obd_kobj);
331 int rc;
332 unsigned long val;
d7e09d03 333
aab38b00 334 rc = kstrtoul(buffer, 10, &val);
d7e09d03
PT
335 if (rc)
336 return rc;
337
338 if (val <= 0)
339 return -ERANGE;
340
341 obd->u.cli.cl_grant_shrink_interval = val;
342
343 return count;
344}
aab38b00 345LUSTRE_RW_ATTR(grant_shrink_interval);
d7e09d03 346
aab38b00
OD
347static ssize_t checksums_show(struct kobject *kobj,
348 struct attribute *attr,
349 char *buf)
d7e09d03 350{
aab38b00
OD
351 struct obd_device *obd = container_of(kobj, struct obd_device,
352 obd_kobj);
d7e09d03 353
aab38b00 354 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
d7e09d03
PT
355}
356
aab38b00
OD
357static ssize_t checksums_store(struct kobject *kobj,
358 struct attribute *attr,
359 const char *buffer,
360 size_t count)
d7e09d03 361{
aab38b00
OD
362 struct obd_device *obd = container_of(kobj, struct obd_device,
363 obd_kobj);
364 int rc;
365 unsigned long val;
d7e09d03 366
aab38b00 367 rc = kstrtoul(buffer, 10, &val);
d7e09d03
PT
368 if (rc)
369 return rc;
370
371 obd->u.cli.cl_checksum = (val ? 1 : 0);
372
373 return count;
374}
aab38b00 375LUSTRE_RW_ATTR(checksums);
d7e09d03 376
73bb1da6 377static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
d7e09d03 378{
73bb1da6
PT
379 struct obd_device *obd = m->private;
380 int i;
50ffcb7e 381
d7e09d03
PT
382 DECLARE_CKSUM_NAME;
383
7f1ae4c0 384 if (!obd)
d7e09d03
PT
385 return 0;
386
73bb1da6 387 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
d7e09d03
PT
388 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
389 continue;
390 if (obd->u.cli.cl_cksum_type == (1 << i))
73bb1da6 391 seq_printf(m, "[%s] ", cksum_name[i]);
d7e09d03 392 else
73bb1da6 393 seq_printf(m, "%s ", cksum_name[i]);
d7e09d03 394 }
e6aa864f 395 seq_putc(m, '\n');
73bb1da6 396 return 0;
d7e09d03
PT
397}
398
e84962e3 399static ssize_t osc_checksum_type_seq_write(struct file *file,
79910d7d
OD
400 const char __user *buffer,
401 size_t count, loff_t *off)
d7e09d03 402{
73bb1da6 403 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
d7e09d03 404 int i;
50ffcb7e 405
d7e09d03
PT
406 DECLARE_CKSUM_NAME;
407 char kernbuf[10];
408
7f1ae4c0 409 if (!obd)
d7e09d03
PT
410 return 0;
411
412 if (count > sizeof(kernbuf) - 1)
413 return -EINVAL;
414 if (copy_from_user(kernbuf, buffer, count))
415 return -EFAULT;
416 if (count > 0 && kernbuf[count - 1] == '\n')
417 kernbuf[count - 1] = '\0';
418 else
419 kernbuf[count] = '\0';
420
421 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
422 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
423 continue;
424 if (!strcmp(kernbuf, cksum_name[i])) {
defa220f
OD
425 obd->u.cli.cl_cksum_type = 1 << i;
426 return count;
d7e09d03
PT
427 }
428 }
429 return -EINVAL;
430}
c9f6bb96 431
73bb1da6 432LPROC_SEQ_FOPS(osc_checksum_type);
d7e09d03 433
aab38b00 434static ssize_t resend_count_show(struct kobject *kobj,
29ac6840
CH
435 struct attribute *attr,
436 char *buf)
d7e09d03 437{
aab38b00
OD
438 struct obd_device *obd = container_of(kobj, struct obd_device,
439 obd_kobj);
d7e09d03 440
aab38b00 441 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
d7e09d03
PT
442}
443
aab38b00 444static ssize_t resend_count_store(struct kobject *kobj,
29ac6840
CH
445 struct attribute *attr,
446 const char *buffer,
447 size_t count)
d7e09d03 448{
aab38b00
OD
449 struct obd_device *obd = container_of(kobj, struct obd_device,
450 obd_kobj);
451 int rc;
452 unsigned long val;
d7e09d03 453
aab38b00 454 rc = kstrtoul(buffer, 10, &val);
d7e09d03
PT
455 if (rc)
456 return rc;
457
d7e09d03
PT
458 atomic_set(&obd->u.cli.cl_resends, val);
459
460 return count;
461}
aab38b00 462LUSTRE_RW_ATTR(resend_count);
d7e09d03 463
aab38b00
OD
464static ssize_t contention_seconds_show(struct kobject *kobj,
465 struct attribute *attr,
466 char *buf)
d7e09d03 467{
aab38b00
OD
468 struct obd_device *obd = container_of(kobj, struct obd_device,
469 obd_kobj);
d7e09d03
PT
470 struct osc_device *od = obd2osc_dev(obd);
471
aab38b00 472 return sprintf(buf, "%u\n", od->od_contention_time);
d7e09d03
PT
473}
474
aab38b00
OD
475static ssize_t contention_seconds_store(struct kobject *kobj,
476 struct attribute *attr,
477 const char *buffer,
478 size_t count)
d7e09d03 479{
aab38b00
OD
480 struct obd_device *obd = container_of(kobj, struct obd_device,
481 obd_kobj);
d7e09d03 482 struct osc_device *od = obd2osc_dev(obd);
0dd48a43
OD
483 int rc;
484 int val;
485
486 rc = kstrtoint(buffer, 10, &val);
487 if (rc)
488 return rc;
489
490 if (val < 0)
491 return -EINVAL;
492
493 od->od_contention_time = val;
d7e09d03 494
0dd48a43 495 return count;
d7e09d03 496}
aab38b00 497LUSTRE_RW_ATTR(contention_seconds);
d7e09d03 498
aab38b00
OD
499static ssize_t lockless_truncate_show(struct kobject *kobj,
500 struct attribute *attr,
501 char *buf)
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
aab38b00 507 return sprintf(buf, "%u\n", od->od_lockless_truncate);
d7e09d03
PT
508}
509
aab38b00
OD
510static ssize_t lockless_truncate_store(struct kobject *kobj,
511 struct attribute *attr,
512 const char *buffer,
513 size_t count)
d7e09d03 514{
aab38b00
OD
515 struct obd_device *obd = container_of(kobj, struct obd_device,
516 obd_kobj);
d7e09d03 517 struct osc_device *od = obd2osc_dev(obd);
0dd48a43
OD
518 int rc;
519 unsigned int val;
d7e09d03 520
0dd48a43
OD
521 rc = kstrtouint(buffer, 10, &val);
522 if (rc)
523 return rc;
524
525 od->od_lockless_truncate = val;
526
527 return count;
d7e09d03 528}
aab38b00 529LUSTRE_RW_ATTR(lockless_truncate);
d7e09d03 530
aab38b00
OD
531static ssize_t destroys_in_flight_show(struct kobject *kobj,
532 struct attribute *attr,
533 char *buf)
d7e09d03 534{
aab38b00
OD
535 struct obd_device *obd = container_of(kobj, struct obd_device,
536 obd_kobj);
8faeebdf 537
aab38b00
OD
538 return sprintf(buf, "%u\n",
539 atomic_read(&obd->u.cli.cl_destroy_in_flight));
d7e09d03 540}
aab38b00 541LUSTRE_RO_ATTR(destroys_in_flight);
73bb1da6 542
aab38b00
OD
543static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
544 struct attribute *attr,
545 char *buf)
73bb1da6 546{
aab38b00
OD
547 struct obd_device *dev = container_of(kobj, struct obd_device,
548 obd_kobj);
549 struct client_obd *cli = &dev->u.cli;
550
551 return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
73bb1da6 552}
d7e09d03 553
aab38b00
OD
554static ssize_t max_pages_per_rpc_store(struct kobject *kobj,
555 struct attribute *attr,
556 const char *buffer,
557 size_t count)
d7e09d03 558{
aab38b00
OD
559 struct obd_device *dev = container_of(kobj, struct obd_device,
560 obd_kobj);
d7e09d03
PT
561 struct client_obd *cli = &dev->u.cli;
562 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
563 int chunk_mask, rc;
aab38b00 564 unsigned long long val;
d7e09d03 565
aab38b00 566 rc = kstrtoull(buffer, 10, &val);
d7e09d03
PT
567 if (rc)
568 return rc;
569
570 /* if the max_pages is specified in bytes, convert to pages */
571 if (val >= ONE_MB_BRW_SIZE)
09cbfeaf 572 val >>= PAGE_SHIFT;
d7e09d03 573
09cbfeaf 574 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
d7e09d03
PT
575 /* max_pages_per_rpc must be chunk aligned */
576 val = (val + ~chunk_mask) & chunk_mask;
09cbfeaf 577 if (val == 0 || val > ocd->ocd_brw_size >> PAGE_SHIFT) {
d7e09d03
PT
578 return -ERANGE;
579 }
580 client_obd_list_lock(&cli->cl_loi_list_lock);
581 cli->cl_max_pages_per_rpc = val;
582 client_obd_list_unlock(&cli->cl_loi_list_lock);
583
d7e09d03
PT
584 return count;
585}
aab38b00 586LUSTRE_RW_ATTR(max_pages_per_rpc);
73bb1da6 587
73bb1da6 588LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
73bb1da6
PT
589LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
590LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
591LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
592LPROC_SEQ_FOPS_RO_TYPE(osc, state);
593
594LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
595
596LPROC_SEQ_FOPS_RW_TYPE(osc, import);
597LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
d7e09d03
PT
598
599static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
114a16b1
BKV
600 { "ping", &osc_ping_fops, NULL, 0222 },
601 { "connect_flags", &osc_connect_flags_fops, NULL, 0 },
114a16b1
BKV
602 /*{ "filegroups", lprocfs_rd_filegroups, NULL, 0 },*/
603 { "ost_server_uuid", &osc_server_uuid_fops, NULL, 0 },
604 { "ost_conn_uuid", &osc_conn_uuid_fops, NULL, 0 },
114a16b1 605 { "osc_cached_mb", &osc_cached_mb_fops, NULL },
114a16b1 606 { "checksum_type", &osc_checksum_type_fops, NULL },
114a16b1 607 { "timeouts", &osc_timeouts_fops, NULL, 0 },
114a16b1
BKV
608 { "import", &osc_import_fops, NULL },
609 { "state", &osc_state_fops, NULL, 0 },
610 { "pinger_recov", &osc_pinger_recov_fops, NULL },
611 { NULL }
d7e09d03
PT
612};
613
1d8cb70c 614#define pct(a, b) (b ? a * 100 / b : 0)
d7e09d03
PT
615
616static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
617{
86655400 618 struct timespec64 now;
d7e09d03
PT
619 struct obd_device *dev = seq->private;
620 struct client_obd *cli = &dev->u.cli;
621 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
622 int i;
623
86655400 624 ktime_get_real_ts64(&now);
d7e09d03
PT
625
626 client_obd_list_lock(&cli->cl_loi_list_lock);
627
86655400
AB
628 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
629 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
d7e09d03
PT
630 seq_printf(seq, "read RPCs in flight: %d\n",
631 cli->cl_r_in_flight);
632 seq_printf(seq, "write RPCs in flight: %d\n",
633 cli->cl_w_in_flight);
634 seq_printf(seq, "pending write pages: %d\n",
635 atomic_read(&cli->cl_pending_w_pages));
636 seq_printf(seq, "pending read pages: %d\n",
637 atomic_read(&cli->cl_pending_r_pages));
638
e6aa864f
HA
639 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
640 seq_puts(seq, "pages per rpc rpcs % cum % |");
641 seq_puts(seq, " rpcs % cum %\n");
d7e09d03
PT
642
643 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
644 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
645
646 read_cum = 0;
647 write_cum = 0;
648 for (i = 0; i < OBD_HIST_MAX; i++) {
649 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
650 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
50ffcb7e 651
d7e09d03
PT
652 read_cum += r;
653 write_cum += w;
654 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
79910d7d
OD
655 1 << i, r, pct(r, read_tot),
656 pct(read_cum, read_tot), w,
657 pct(w, write_tot),
658 pct(write_cum, write_tot));
d7e09d03
PT
659 if (read_cum == read_tot && write_cum == write_tot)
660 break;
661 }
662
e6aa864f
HA
663 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
664 seq_puts(seq, "rpcs in flight rpcs % cum % |");
665 seq_puts(seq, " rpcs % cum %\n");
d7e09d03
PT
666
667 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
668 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
669
670 read_cum = 0;
671 write_cum = 0;
672 for (i = 0; i < OBD_HIST_MAX; i++) {
673 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
674 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
50ffcb7e 675
d7e09d03
PT
676 read_cum += r;
677 write_cum += w;
678 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
79910d7d
OD
679 i, r, pct(r, read_tot),
680 pct(read_cum, read_tot), w,
681 pct(w, write_tot),
682 pct(write_cum, write_tot));
d7e09d03
PT
683 if (read_cum == read_tot && write_cum == write_tot)
684 break;
685 }
686
e6aa864f
HA
687 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
688 seq_puts(seq, "offset rpcs % cum % |");
689 seq_puts(seq, " rpcs % cum %\n");
d7e09d03
PT
690
691 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
692 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
693
694 read_cum = 0;
695 write_cum = 0;
696 for (i = 0; i < OBD_HIST_MAX; i++) {
697 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
698 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
50ffcb7e 699
d7e09d03
PT
700 read_cum += r;
701 write_cum += w;
702 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
703 (i == 0) ? 0 : 1 << (i - 1),
704 r, pct(r, read_tot), pct(read_cum, read_tot),
705 w, pct(w, write_tot), pct(write_cum, write_tot));
706 if (read_cum == read_tot && write_cum == write_tot)
707 break;
708 }
709
710 client_obd_list_unlock(&cli->cl_loi_list_lock);
711
712 return 0;
713}
c9f6bb96 714
d7e09d03
PT
715#undef pct
716
e84962e3 717static ssize_t osc_rpc_stats_seq_write(struct file *file,
29ac6840
CH
718 const char __user *buf,
719 size_t len, loff_t *off)
d7e09d03
PT
720{
721 struct seq_file *seq = file->private_data;
722 struct obd_device *dev = seq->private;
723 struct client_obd *cli = &dev->u.cli;
724
725 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
726 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
727 lprocfs_oh_clear(&cli->cl_read_page_hist);
728 lprocfs_oh_clear(&cli->cl_write_page_hist);
729 lprocfs_oh_clear(&cli->cl_read_offset_hist);
730 lprocfs_oh_clear(&cli->cl_write_offset_hist);
731
732 return len;
733}
734
735LPROC_SEQ_FOPS(osc_rpc_stats);
736
737static int osc_stats_seq_show(struct seq_file *seq, void *v)
738{
86655400 739 struct timespec64 now;
d7e09d03
PT
740 struct obd_device *dev = seq->private;
741 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
742
86655400 743 ktime_get_real_ts64(&now);
d7e09d03 744
86655400
AB
745 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
746 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
b0f5aad5 747 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
d7e09d03 748 stats->os_lockless_writes);
b0f5aad5 749 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
d7e09d03 750 stats->os_lockless_reads);
b0f5aad5 751 seq_printf(seq, "lockless_truncate\t\t%llu\n",
d7e09d03
PT
752 stats->os_lockless_truncates);
753 return 0;
754}
755
e84962e3 756static ssize_t osc_stats_seq_write(struct file *file,
29ac6840
CH
757 const char __user *buf,
758 size_t len, loff_t *off)
d7e09d03
PT
759{
760 struct seq_file *seq = file->private_data;
761 struct obd_device *dev = seq->private;
762 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
763
764 memset(stats, 0, sizeof(*stats));
765 return len;
766}
767
768LPROC_SEQ_FOPS(osc_stats);
769
770int lproc_osc_attach_seqstat(struct obd_device *dev)
771{
772 int rc;
773
61e87ab0
DE
774 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "osc_stats", 0644,
775 &osc_stats_fops, dev);
d7e09d03 776 if (rc == 0)
e4ba525e
DE
777 rc = ldebugfs_obd_seq_create(dev, "rpc_stats", 0644,
778 &osc_rpc_stats_fops, dev);
d7e09d03
PT
779
780 return rc;
781}
782
aab38b00
OD
783static struct attribute *osc_attrs[] = {
784 &lustre_attr_active.attr,
785 &lustre_attr_checksums.attr,
786 &lustre_attr_contention_seconds.attr,
787 &lustre_attr_cur_dirty_bytes.attr,
788 &lustre_attr_cur_grant_bytes.attr,
789 &lustre_attr_cur_lost_grant_bytes.attr,
790 &lustre_attr_destroys_in_flight.attr,
791 &lustre_attr_grant_shrink_interval.attr,
792 &lustre_attr_lockless_truncate.attr,
793 &lustre_attr_max_dirty_mb.attr,
794 &lustre_attr_max_pages_per_rpc.attr,
795 &lustre_attr_max_rpcs_in_flight.attr,
796 &lustre_attr_resend_count.attr,
797 NULL,
798};
799
800static struct attribute_group osc_attr_group = {
801 .attrs = osc_attrs,
802};
803
d7e09d03
PT
804void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
805{
aab38b00 806 lvars->sysfs_vars = &osc_attr_group;
d7e09d03
PT
807 lvars->obd_vars = lprocfs_osc_obd_vars;
808}