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