staging/lustre/llite: to configure max_cached_mb correctly
[deliverable/linux.git] / drivers / staging / lustre / lustre / llite / lproc_llite.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_LLITE
37
67a235f5
GKH
38#include "../include/lustre_lite.h"
39#include "../include/lprocfs_status.h"
d7e09d03 40#include <linux/seq_file.h>
67a235f5 41#include "../include/obd_support.h"
d7e09d03
PT
42
43#include "llite_internal.h"
2d95f10e 44#include "vvp_internal.h"
d7e09d03 45
d7e09d03 46/* /proc/lustre/llite mount point registration */
b9c98cfa
FF
47static struct file_operations ll_rw_extents_stats_fops;
48static struct file_operations ll_rw_extents_stats_pp_fops;
49static struct file_operations ll_rw_offset_stats_fops;
d7e09d03 50
73bb1da6 51static int ll_blksize_seq_show(struct seq_file *m, void *v)
d7e09d03 52{
73bb1da6 53 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
54 struct obd_statfs osfs;
55 int rc;
56
57 LASSERT(sb != NULL);
58 rc = ll_statfs_internal(sb, &osfs,
59 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
60 OBD_STATFS_NODELAY);
73bb1da6
PT
61 if (!rc)
62 rc = seq_printf(m, "%u\n", osfs.os_bsize);
d7e09d03
PT
63
64 return rc;
65}
73bb1da6 66LPROC_SEQ_FOPS_RO(ll_blksize);
d7e09d03 67
73bb1da6 68static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
d7e09d03 69{
73bb1da6 70 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
71 struct obd_statfs osfs;
72 int rc;
73
74 LASSERT(sb != NULL);
75 rc = ll_statfs_internal(sb, &osfs,
76 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
77 OBD_STATFS_NODELAY);
78 if (!rc) {
79 __u32 blk_size = osfs.os_bsize >> 10;
80 __u64 result = osfs.os_blocks;
81
82 while (blk_size >>= 1)
83 result <<= 1;
84
b0f5aad5 85 rc = seq_printf(m, "%llu\n", result);
d7e09d03
PT
86 }
87 return rc;
d7e09d03 88}
73bb1da6 89LPROC_SEQ_FOPS_RO(ll_kbytestotal);
d7e09d03 90
73bb1da6 91static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
d7e09d03 92{
73bb1da6 93 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
94 struct obd_statfs osfs;
95 int rc;
96
97 LASSERT(sb != NULL);
98 rc = ll_statfs_internal(sb, &osfs,
99 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
100 OBD_STATFS_NODELAY);
101 if (!rc) {
102 __u32 blk_size = osfs.os_bsize >> 10;
103 __u64 result = osfs.os_bfree;
104
105 while (blk_size >>= 1)
106 result <<= 1;
107
b0f5aad5 108 rc = seq_printf(m, "%llu\n", result);
d7e09d03
PT
109 }
110 return rc;
111}
73bb1da6 112LPROC_SEQ_FOPS_RO(ll_kbytesfree);
d7e09d03 113
73bb1da6 114static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
d7e09d03 115{
73bb1da6 116 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
117 struct obd_statfs osfs;
118 int rc;
119
120 LASSERT(sb != NULL);
121 rc = ll_statfs_internal(sb, &osfs,
122 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
123 OBD_STATFS_NODELAY);
124 if (!rc) {
125 __u32 blk_size = osfs.os_bsize >> 10;
126 __u64 result = osfs.os_bavail;
127
128 while (blk_size >>= 1)
129 result <<= 1;
130
b0f5aad5 131 rc = seq_printf(m, "%llu\n", result);
d7e09d03
PT
132 }
133 return rc;
134}
73bb1da6 135LPROC_SEQ_FOPS_RO(ll_kbytesavail);
d7e09d03 136
73bb1da6 137static int ll_filestotal_seq_show(struct seq_file *m, void *v)
d7e09d03 138{
73bb1da6 139 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
140 struct obd_statfs osfs;
141 int rc;
142
143 LASSERT(sb != NULL);
144 rc = ll_statfs_internal(sb, &osfs,
145 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
146 OBD_STATFS_NODELAY);
73bb1da6 147 if (!rc)
b0f5aad5 148 rc = seq_printf(m, "%llu\n", osfs.os_files);
d7e09d03
PT
149 return rc;
150}
73bb1da6 151LPROC_SEQ_FOPS_RO(ll_filestotal);
d7e09d03 152
73bb1da6 153static int ll_filesfree_seq_show(struct seq_file *m, void *v)
d7e09d03 154{
73bb1da6 155 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
156 struct obd_statfs osfs;
157 int rc;
158
159 LASSERT(sb != NULL);
160 rc = ll_statfs_internal(sb, &osfs,
161 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
162 OBD_STATFS_NODELAY);
73bb1da6 163 if (!rc)
b0f5aad5 164 rc = seq_printf(m, "%llu\n", osfs.os_ffree);
d7e09d03 165 return rc;
d7e09d03 166}
73bb1da6 167LPROC_SEQ_FOPS_RO(ll_filesfree);
d7e09d03 168
73bb1da6 169static int ll_client_type_seq_show(struct seq_file *m, void *v)
d7e09d03 170{
73bb1da6 171 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
d7e09d03
PT
172 int rc;
173
174 LASSERT(sbi != NULL);
175
d7e09d03 176 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
73bb1da6 177 rc = seq_printf(m, "remote client\n");
d7e09d03 178 else
73bb1da6 179 rc = seq_printf(m, "local client\n");
d7e09d03
PT
180
181 return rc;
182}
73bb1da6 183LPROC_SEQ_FOPS_RO(ll_client_type);
d7e09d03 184
73bb1da6 185static int ll_fstype_seq_show(struct seq_file *m, void *v)
d7e09d03 186{
73bb1da6 187 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
188
189 LASSERT(sb != NULL);
73bb1da6 190 return seq_printf(m, "%s\n", sb->s_type->name);
d7e09d03 191}
73bb1da6 192LPROC_SEQ_FOPS_RO(ll_fstype);
d7e09d03 193
73bb1da6 194static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
d7e09d03 195{
73bb1da6 196 struct super_block *sb = (struct super_block *)m->private;
d7e09d03
PT
197
198 LASSERT(sb != NULL);
73bb1da6 199 return seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
d7e09d03 200}
73bb1da6 201LPROC_SEQ_FOPS_RO(ll_sb_uuid);
d7e09d03 202
73bb1da6 203static int ll_site_stats_seq_show(struct seq_file *m, void *v)
d7e09d03 204{
73bb1da6 205 struct super_block *sb = m->private;
d7e09d03
PT
206
207 /*
208 * See description of statistical counters in struct cl_site, and
209 * struct lu_site.
210 */
73bb1da6 211 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
d7e09d03 212}
73bb1da6 213LPROC_SEQ_FOPS_RO(ll_site_stats);
d7e09d03 214
73bb1da6 215static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
d7e09d03 216{
73bb1da6 217 struct super_block *sb = m->private;
d7e09d03
PT
218 struct ll_sb_info *sbi = ll_s2sbi(sb);
219 long pages_number;
220 int mult;
221
222 spin_lock(&sbi->ll_lock);
223 pages_number = sbi->ll_ra_info.ra_max_pages;
224 spin_unlock(&sbi->ll_lock);
225
226 mult = 1 << (20 - PAGE_CACHE_SHIFT);
73bb1da6 227 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
d7e09d03
PT
228}
229
5a13503e
AL
230static ssize_t ll_max_readahead_mb_seq_write(struct file *file,
231 const char __user *buffer,
232 size_t count, loff_t *off)
d7e09d03 233{
73bb1da6 234 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
235 struct ll_sb_info *sbi = ll_s2sbi(sb);
236 int mult, rc, pages_number;
237
238 mult = 1 << (20 - PAGE_CACHE_SHIFT);
239 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
240 if (rc)
241 return rc;
242
4f6cc9ab 243 if (pages_number < 0 || pages_number > totalram_pages / 2) {
d7e09d03 244 CERROR("can't set file readahead more than %lu MB\n",
4f6cc9ab 245 totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1)); /*1/2 of RAM*/
d7e09d03
PT
246 return -ERANGE;
247 }
248
249 spin_lock(&sbi->ll_lock);
250 sbi->ll_ra_info.ra_max_pages = pages_number;
251 spin_unlock(&sbi->ll_lock);
252
253 return count;
254}
73bb1da6 255LPROC_SEQ_FOPS(ll_max_readahead_mb);
d7e09d03 256
73bb1da6 257static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
d7e09d03 258{
73bb1da6 259 struct super_block *sb = m->private;
d7e09d03
PT
260 struct ll_sb_info *sbi = ll_s2sbi(sb);
261 long pages_number;
262 int mult;
263
264 spin_lock(&sbi->ll_lock);
265 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
266 spin_unlock(&sbi->ll_lock);
267
268 mult = 1 << (20 - PAGE_CACHE_SHIFT);
73bb1da6 269 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
d7e09d03
PT
270}
271
73bb1da6 272static ssize_t ll_max_readahead_per_file_mb_seq_write(struct file *file,
5a13503e 273 const char __user *buffer,
73bb1da6 274 size_t count, loff_t *off)
d7e09d03 275{
73bb1da6 276 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
277 struct ll_sb_info *sbi = ll_s2sbi(sb);
278 int mult, rc, pages_number;
279
280 mult = 1 << (20 - PAGE_CACHE_SHIFT);
281 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
282 if (rc)
283 return rc;
284
285 if (pages_number < 0 ||
286 pages_number > sbi->ll_ra_info.ra_max_pages) {
2d00bd17 287 CERROR("can't set file readahead more than max_read_ahead_mb %lu MB\n",
d7e09d03
PT
288 sbi->ll_ra_info.ra_max_pages);
289 return -ERANGE;
290 }
291
292 spin_lock(&sbi->ll_lock);
293 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
294 spin_unlock(&sbi->ll_lock);
295
296 return count;
297}
73bb1da6 298LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
d7e09d03 299
73bb1da6 300static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *unused)
d7e09d03 301{
73bb1da6 302 struct super_block *sb = m->private;
d7e09d03
PT
303 struct ll_sb_info *sbi = ll_s2sbi(sb);
304 long pages_number;
305 int mult;
306
307 spin_lock(&sbi->ll_lock);
308 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
309 spin_unlock(&sbi->ll_lock);
310
311 mult = 1 << (20 - PAGE_CACHE_SHIFT);
73bb1da6 312 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
d7e09d03
PT
313}
314
73bb1da6 315static ssize_t ll_max_read_ahead_whole_mb_seq_write(struct file *file,
5a13503e 316 const char __user *buffer,
73bb1da6 317 size_t count, loff_t *off)
d7e09d03 318{
73bb1da6 319 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
320 struct ll_sb_info *sbi = ll_s2sbi(sb);
321 int mult, rc, pages_number;
322
323 mult = 1 << (20 - PAGE_CACHE_SHIFT);
324 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
325 if (rc)
326 return rc;
327
328 /* Cap this at the current max readahead window size, the readahead
329 * algorithm does this anyway so it's pointless to set it larger. */
330 if (pages_number < 0 ||
331 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
2d00bd17
JP
332 CERROR("can't set max_read_ahead_whole_mb more than max_read_ahead_per_file_mb: %lu\n",
333 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - PAGE_CACHE_SHIFT));
d7e09d03
PT
334 return -ERANGE;
335 }
336
337 spin_lock(&sbi->ll_lock);
338 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
339 spin_unlock(&sbi->ll_lock);
340
341 return count;
342}
73bb1da6 343LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
d7e09d03 344
73bb1da6 345static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
d7e09d03 346{
73bb1da6 347 struct super_block *sb = m->private;
d7e09d03
PT
348 struct ll_sb_info *sbi = ll_s2sbi(sb);
349 struct cl_client_cache *cache = &sbi->ll_cache;
350 int shift = 20 - PAGE_CACHE_SHIFT;
351 int max_cached_mb;
352 int unused_mb;
353
d7e09d03
PT
354 max_cached_mb = cache->ccc_lru_max >> shift;
355 unused_mb = atomic_read(&cache->ccc_lru_left) >> shift;
73bb1da6 356 return seq_printf(m,
d7e09d03
PT
357 "users: %d\n"
358 "max_cached_mb: %d\n"
359 "used_mb: %d\n"
360 "unused_mb: %d\n"
361 "reclaim_count: %u\n",
362 atomic_read(&cache->ccc_users),
363 max_cached_mb,
364 max_cached_mb - unused_mb,
365 unused_mb,
366 cache->ccc_lru_shrinkers);
367}
368
a1e7e2d4
OD
369static ssize_t ll_max_cached_mb_seq_write(struct file *file,
370 const char __user *buffer,
371 size_t count, loff_t *off)
d7e09d03 372{
73bb1da6 373 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
374 struct ll_sb_info *sbi = ll_s2sbi(sb);
375 struct cl_client_cache *cache = &sbi->ll_cache;
376 int mult, rc, pages_number;
377 int diff = 0;
378 int nrpages = 0;
a1e7e2d4
OD
379 char kernbuf[128];
380
381 if (count >= sizeof(kernbuf))
382 return -EINVAL;
383
384 if (copy_from_user(kernbuf, buffer, count))
385 return -EFAULT;
386 kernbuf[count] = 0;
d7e09d03
PT
387
388 mult = 1 << (20 - PAGE_CACHE_SHIFT);
a1e7e2d4
OD
389 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
390 kernbuf;
d7e09d03
PT
391 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
392 if (rc)
0a3bdb00 393 return rc;
d7e09d03 394
4f6cc9ab 395 if (pages_number < 0 || pages_number > totalram_pages) {
d7e09d03
PT
396 CERROR("%s: can't set max cache more than %lu MB\n",
397 ll_get_fsname(sb, NULL, 0),
4f6cc9ab 398 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
0a3bdb00 399 return -ERANGE;
d7e09d03
PT
400 }
401
d7e09d03
PT
402 spin_lock(&sbi->ll_lock);
403 diff = pages_number - cache->ccc_lru_max;
404 spin_unlock(&sbi->ll_lock);
405
406 /* easy - add more LRU slots. */
407 if (diff >= 0) {
408 atomic_add(diff, &cache->ccc_lru_left);
34e1f2bb
JL
409 rc = 0;
410 goto out;
d7e09d03
PT
411 }
412
413 diff = -diff;
414 while (diff > 0) {
415 int tmp;
416
417 /* reduce LRU budget from free slots. */
418 do {
419 int ov, nv;
420
421 ov = atomic_read(&cache->ccc_lru_left);
422 if (ov == 0)
423 break;
424
425 nv = ov > diff ? ov - diff : 0;
305ec768 426 rc = atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
d7e09d03
PT
427 if (likely(ov == rc)) {
428 diff -= ov - nv;
429 nrpages += ov - nv;
430 break;
431 }
432 } while (1);
433
434 if (diff <= 0)
435 break;
436
c2fcdf6c
JX
437 if (sbi->ll_dt_exp == NULL) { /* being initialized */
438 rc = -ENODEV;
439 break;
440 }
441
d7e09d03
PT
442 /* difficult - have to ask OSCs to drop LRU slots. */
443 tmp = diff << 1;
444 rc = obd_set_info_async(NULL, sbi->ll_dt_exp,
445 sizeof(KEY_CACHE_LRU_SHRINK),
446 KEY_CACHE_LRU_SHRINK,
447 sizeof(tmp), &tmp, NULL);
448 if (rc < 0)
449 break;
450 }
451
452out:
453 if (rc >= 0) {
454 spin_lock(&sbi->ll_lock);
455 cache->ccc_lru_max = pages_number;
456 spin_unlock(&sbi->ll_lock);
457 rc = count;
458 } else {
459 atomic_add(nrpages, &cache->ccc_lru_left);
460 }
461 return rc;
462}
73bb1da6 463LPROC_SEQ_FOPS(ll_max_cached_mb);
d7e09d03 464
73bb1da6 465static int ll_checksum_seq_show(struct seq_file *m, void *v)
d7e09d03 466{
73bb1da6 467 struct super_block *sb = m->private;
d7e09d03
PT
468 struct ll_sb_info *sbi = ll_s2sbi(sb);
469
73bb1da6 470 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
d7e09d03
PT
471}
472
5a13503e
AL
473static ssize_t ll_checksum_seq_write(struct file *file,
474 const char __user *buffer,
475 size_t count, loff_t *off)
d7e09d03 476{
73bb1da6 477 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
478 struct ll_sb_info *sbi = ll_s2sbi(sb);
479 int val, rc;
480
481 if (!sbi->ll_dt_exp)
482 /* Not set up yet */
483 return -EAGAIN;
484
485 rc = lprocfs_write_helper(buffer, count, &val);
486 if (rc)
487 return rc;
488 if (val)
489 sbi->ll_flags |= LL_SBI_CHECKSUM;
490 else
491 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
492
493 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
494 KEY_CHECKSUM, sizeof(val), &val, NULL);
495 if (rc)
496 CWARN("Failed to set OSC checksum flags: %d\n", rc);
497
498 return count;
499}
73bb1da6 500LPROC_SEQ_FOPS(ll_checksum);
d7e09d03 501
73bb1da6 502static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
d7e09d03 503{
73bb1da6 504 struct super_block *sb = m->private;
d7e09d03 505
73bb1da6 506 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
d7e09d03
PT
507}
508
5a13503e
AL
509static ssize_t ll_max_rw_chunk_seq_write(struct file *file,
510 const char __user *buffer,
511 size_t count, loff_t *off)
d7e09d03 512{
73bb1da6 513 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
514 int rc, val;
515
516 rc = lprocfs_write_helper(buffer, count, &val);
517 if (rc)
518 return rc;
519 ll_s2sbi(sb)->ll_max_rw_chunk = val;
520 return count;
521}
73bb1da6 522LPROC_SEQ_FOPS(ll_max_rw_chunk);
d7e09d03 523
73bb1da6 524static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
d7e09d03 525{
73bb1da6 526 struct super_block *sb = m->private;
d7e09d03
PT
527
528 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
73bb1da6 529 return seq_printf(m, "%d\n",
d7e09d03
PT
530 ll_s2sbi(sb)->ll_stats_track_id);
531
532 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
73bb1da6 533 return seq_printf(m, "0 (all)\n");
d7e09d03 534 } else {
73bb1da6 535 return seq_printf(m, "untracked\n");
d7e09d03
PT
536 }
537}
538
5a13503e
AL
539static int ll_wr_track_id(const char __user *buffer, unsigned long count,
540 void *data, enum stats_track_type type)
d7e09d03
PT
541{
542 struct super_block *sb = data;
543 int rc, pid;
544
545 rc = lprocfs_write_helper(buffer, count, &pid);
546 if (rc)
547 return rc;
548 ll_s2sbi(sb)->ll_stats_track_id = pid;
549 if (pid == 0)
550 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
551 else
552 ll_s2sbi(sb)->ll_stats_track_type = type;
553 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
554 return count;
555}
556
73bb1da6 557static int ll_track_pid_seq_show(struct seq_file *m, void *v)
d7e09d03 558{
73bb1da6 559 return ll_rd_track_id(m, STATS_TRACK_PID);
d7e09d03
PT
560}
561
5a13503e
AL
562static ssize_t ll_track_pid_seq_write(struct file *file,
563 const char __user *buffer,
564 size_t count, loff_t *off)
d7e09d03 565{
73bb1da6
PT
566 struct seq_file *seq = file->private_data;
567 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
d7e09d03 568}
73bb1da6 569LPROC_SEQ_FOPS(ll_track_pid);
d7e09d03 570
73bb1da6 571static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
d7e09d03 572{
73bb1da6 573 return ll_rd_track_id(m, STATS_TRACK_PPID);
d7e09d03
PT
574}
575
5a13503e
AL
576static ssize_t ll_track_ppid_seq_write(struct file *file,
577 const char __user *buffer,
578 size_t count, loff_t *off)
d7e09d03 579{
73bb1da6
PT
580 struct seq_file *seq = file->private_data;
581 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
d7e09d03 582}
73bb1da6 583LPROC_SEQ_FOPS(ll_track_ppid);
d7e09d03 584
73bb1da6 585static int ll_track_gid_seq_show(struct seq_file *m, void *v)
d7e09d03 586{
73bb1da6 587 return ll_rd_track_id(m, STATS_TRACK_GID);
d7e09d03
PT
588}
589
5a13503e
AL
590static ssize_t ll_track_gid_seq_write(struct file *file,
591 const char __user *buffer,
592 size_t count, loff_t *off)
d7e09d03 593{
73bb1da6
PT
594 struct seq_file *seq = file->private_data;
595 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
d7e09d03 596}
73bb1da6 597LPROC_SEQ_FOPS(ll_track_gid);
d7e09d03 598
73bb1da6 599static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
d7e09d03 600{
73bb1da6 601 struct super_block *sb = m->private;
d7e09d03
PT
602 struct ll_sb_info *sbi = ll_s2sbi(sb);
603
73bb1da6 604 return seq_printf(m, "%u\n", sbi->ll_sa_max);
d7e09d03
PT
605}
606
5a13503e
AL
607static ssize_t ll_statahead_max_seq_write(struct file *file,
608 const char __user *buffer,
609 size_t count, loff_t *off)
d7e09d03 610{
73bb1da6 611 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
612 struct ll_sb_info *sbi = ll_s2sbi(sb);
613 int val, rc;
614
615 rc = lprocfs_write_helper(buffer, count, &val);
616 if (rc)
617 return rc;
618
619 if (val >= 0 && val <= LL_SA_RPC_MAX)
620 sbi->ll_sa_max = val;
621 else
2d00bd17
JP
622 CERROR("Bad statahead_max value %d. Valid values are in the range [0, %d]\n",
623 val, LL_SA_RPC_MAX);
d7e09d03
PT
624
625 return count;
626}
73bb1da6 627LPROC_SEQ_FOPS(ll_statahead_max);
d7e09d03 628
73bb1da6 629static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
d7e09d03 630{
73bb1da6 631 struct super_block *sb = m->private;
d7e09d03
PT
632 struct ll_sb_info *sbi = ll_s2sbi(sb);
633
73bb1da6 634 return seq_printf(m, "%u\n",
d7e09d03
PT
635 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
636}
637
5a13503e
AL
638static ssize_t ll_statahead_agl_seq_write(struct file *file,
639 const char __user *buffer,
640 size_t count, loff_t *off)
d7e09d03 641{
73bb1da6 642 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
643 struct ll_sb_info *sbi = ll_s2sbi(sb);
644 int val, rc;
645
646 rc = lprocfs_write_helper(buffer, count, &val);
647 if (rc)
648 return rc;
649
650 if (val)
651 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
652 else
653 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
654
655 return count;
656}
73bb1da6 657LPROC_SEQ_FOPS(ll_statahead_agl);
d7e09d03 658
73bb1da6 659static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
d7e09d03 660{
73bb1da6 661 struct super_block *sb = m->private;
d7e09d03
PT
662 struct ll_sb_info *sbi = ll_s2sbi(sb);
663
73bb1da6 664 return seq_printf(m,
d7e09d03
PT
665 "statahead total: %u\n"
666 "statahead wrong: %u\n"
667 "agl total: %u\n",
668 atomic_read(&sbi->ll_sa_total),
669 atomic_read(&sbi->ll_sa_wrong),
670 atomic_read(&sbi->ll_agl_total));
671}
73bb1da6 672LPROC_SEQ_FOPS_RO(ll_statahead_stats);
d7e09d03 673
73bb1da6 674static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
d7e09d03 675{
73bb1da6 676 struct super_block *sb = m->private;
d7e09d03
PT
677 struct ll_sb_info *sbi = ll_s2sbi(sb);
678
73bb1da6 679 return seq_printf(m, "%u\n",
d7e09d03
PT
680 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
681}
682
5a13503e
AL
683static ssize_t ll_lazystatfs_seq_write(struct file *file,
684 const char __user *buffer,
685 size_t count, loff_t *off)
d7e09d03 686{
73bb1da6 687 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
688 struct ll_sb_info *sbi = ll_s2sbi(sb);
689 int val, rc;
690
691 rc = lprocfs_write_helper(buffer, count, &val);
692 if (rc)
693 return rc;
694
695 if (val)
696 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
697 else
698 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
699
700 return count;
701}
73bb1da6 702LPROC_SEQ_FOPS(ll_lazystatfs);
d7e09d03 703
44779340 704static int ll_max_easize_seq_show(struct seq_file *m, void *v)
d7e09d03 705{
73bb1da6 706 struct super_block *sb = m->private;
d7e09d03
PT
707 struct ll_sb_info *sbi = ll_s2sbi(sb);
708 unsigned int ealen;
709 int rc;
710
711 rc = ll_get_max_mdsize(sbi, &ealen);
712 if (rc)
713 return rc;
714
73bb1da6 715 return seq_printf(m, "%u\n", ealen);
d7e09d03 716}
44779340
BB
717LPROC_SEQ_FOPS_RO(ll_max_easize);
718
719static int ll_defult_easize_seq_show(struct seq_file *m, void *v)
720{
721 struct super_block *sb = m->private;
722 struct ll_sb_info *sbi = ll_s2sbi(sb);
723 unsigned int ealen;
724 int rc;
725
726 rc = ll_get_default_mdsize(sbi, &ealen);
727 if (rc)
728 return rc;
729
730 return seq_printf(m, "%u\n", ealen);
731}
732LPROC_SEQ_FOPS_RO(ll_defult_easize);
733
734static int ll_max_cookiesize_seq_show(struct seq_file *m, void *v)
735{
736 struct super_block *sb = m->private;
737 struct ll_sb_info *sbi = ll_s2sbi(sb);
738 unsigned int cookielen;
739 int rc;
740
741 rc = ll_get_max_cookiesize(sbi, &cookielen);
742 if (rc)
743 return rc;
744
745 return seq_printf(m, "%u\n", cookielen);
746}
747LPROC_SEQ_FOPS_RO(ll_max_cookiesize);
748
749static int ll_defult_cookiesize_seq_show(struct seq_file *m, void *v)
750{
751 struct super_block *sb = m->private;
752 struct ll_sb_info *sbi = ll_s2sbi(sb);
753 unsigned int cookielen;
754 int rc;
755
756 rc = ll_get_default_cookiesize(sbi, &cookielen);
757 if (rc)
758 return rc;
759
760 return seq_printf(m, "%u\n", cookielen);
761}
762LPROC_SEQ_FOPS_RO(ll_defult_cookiesize);
d7e09d03 763
73bb1da6 764static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
d7e09d03
PT
765{
766 const char *str[] = LL_SBI_FLAGS;
73bb1da6 767 struct super_block *sb = m->private;
d7e09d03
PT
768 int flags = ll_s2sbi(sb)->ll_flags;
769 int i = 0;
d7e09d03
PT
770
771 while (flags != 0) {
772 if (ARRAY_SIZE(str) <= i) {
2d00bd17
JP
773 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi flags please.\n",
774 ll_get_fsname(sb, NULL, 0));
d7e09d03
PT
775 return -EINVAL;
776 }
777
778 if (flags & 0x1)
73bb1da6 779 seq_printf(m, "%s ", str[i]);
d7e09d03
PT
780 flags >>= 1;
781 ++i;
782 }
73bb1da6
PT
783 seq_printf(m, "\b\n");
784 return 0;
d7e09d03 785}
73bb1da6 786LPROC_SEQ_FOPS_RO(ll_sbi_flags);
d7e09d03 787
7fc1f831
AP
788static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
789{
790 struct super_block *sb = m->private;
791 struct ll_sb_info *sbi = ll_s2sbi(sb);
792 int rc;
793
794 rc = seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
795
796 return rc;
797}
798
5a13503e
AL
799static ssize_t ll_xattr_cache_seq_write(struct file *file,
800 const char __user *buffer,
7fc1f831
AP
801 size_t count, loff_t *off)
802{
803 struct seq_file *seq = file->private_data;
804 struct super_block *sb = seq->private;
805 struct ll_sb_info *sbi = ll_s2sbi(sb);
806 int val, rc;
807
808 rc = lprocfs_write_helper(buffer, count, &val);
809 if (rc)
810 return rc;
811
812 if (val != 0 && val != 1)
813 return -ERANGE;
814
815 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
816 return -ENOTSUPP;
817
818 sbi->ll_xattr_cache_enabled = val;
819
820 return count;
821}
822LPROC_SEQ_FOPS(ll_xattr_cache);
823
d7e09d03 824static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
95b86a76 825 { "uuid", &ll_sb_uuid_fops, NULL, 0 },
588bf52a 826 /* { "mntpt_path", ll_rd_path, 0, 0 }, */
95b86a76
SL
827 { "fstype", &ll_fstype_fops, NULL, 0 },
828 { "site", &ll_site_stats_fops, NULL, 0 },
829 { "blocksize", &ll_blksize_fops, NULL, 0 },
830 { "kbytestotal", &ll_kbytestotal_fops, NULL, 0 },
831 { "kbytesfree", &ll_kbytesfree_fops, NULL, 0 },
832 { "kbytesavail", &ll_kbytesavail_fops, NULL, 0 },
833 { "filestotal", &ll_filestotal_fops, NULL, 0 },
834 { "filesfree", &ll_filesfree_fops, NULL, 0 },
835 { "client_type", &ll_client_type_fops, NULL, 0 },
588bf52a 836 /* { "filegroups", lprocfs_rd_filegroups, 0, 0 }, */
95b86a76
SL
837 { "max_read_ahead_mb", &ll_max_readahead_mb_fops, NULL },
838 { "max_read_ahead_per_file_mb", &ll_max_readahead_per_file_mb_fops,
839 NULL },
840 { "max_read_ahead_whole_mb", &ll_max_read_ahead_whole_mb_fops, NULL },
841 { "max_cached_mb", &ll_max_cached_mb_fops, NULL },
842 { "checksum_pages", &ll_checksum_fops, NULL },
843 { "max_rw_chunk", &ll_max_rw_chunk_fops, NULL },
844 { "stats_track_pid", &ll_track_pid_fops, NULL },
845 { "stats_track_ppid", &ll_track_ppid_fops, NULL },
846 { "stats_track_gid", &ll_track_gid_fops, NULL },
847 { "statahead_max", &ll_statahead_max_fops, NULL },
848 { "statahead_agl", &ll_statahead_agl_fops, NULL },
849 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 },
850 { "lazystatfs", &ll_lazystatfs_fops, NULL },
851 { "max_easize", &ll_max_easize_fops, NULL, 0 },
852 { "default_easize", &ll_defult_easize_fops, NULL, 0 },
853 { "max_cookiesize", &ll_max_cookiesize_fops, NULL, 0 },
854 { "default_cookiesize", &ll_defult_cookiesize_fops, NULL, 0 },
855 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 },
856 { "xattr_cache", &ll_xattr_cache_fops, NULL, 0 },
ea7893bb 857 { NULL }
d7e09d03
PT
858};
859
860#define MAX_STRING_SIZE 128
861
2d95f10e 862static const struct llite_file_opcode {
d7e09d03
PT
863 __u32 opcode;
864 __u32 type;
865 const char *opname;
866} llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
867 /* file operation */
868 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
869 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
870 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
871 "read_bytes" },
872 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
873 "write_bytes" },
874 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
875 "brw_read" },
876 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
877 "brw_write" },
878 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
879 "osc_read" },
880 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
881 "osc_write" },
882 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
883 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
884 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
885 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
886 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
887 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
888 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
889 /* inode operation */
890 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
891 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
892 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
893 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
894 /* dir inode operation */
895 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
896 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
897 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
898 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
899 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
900 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
901 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
902 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
903 /* special inode operation */
904 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
905 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
906 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
907 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
7fc1f831 908 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
d7e09d03
PT
909 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
910 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
911 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
912};
913
914void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
915{
916 if (!sbi->ll_stats)
917 return;
918 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
919 lprocfs_counter_add(sbi->ll_stats, op, count);
920 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
921 sbi->ll_stats_track_id == current->pid)
922 lprocfs_counter_add(sbi->ll_stats, op, count);
923 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
b1beb91b 924 sbi->ll_stats_track_id == current->real_parent->pid)
d7e09d03
PT
925 lprocfs_counter_add(sbi->ll_stats, op, count);
926 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
4b1a25f0
PT
927 sbi->ll_stats_track_id ==
928 from_kgid(&init_user_ns, current_gid()))
d7e09d03
PT
929 lprocfs_counter_add(sbi->ll_stats, op, count);
930}
931EXPORT_SYMBOL(ll_stats_ops_tally);
932
933static const char *ra_stat_string[] = {
934 [RA_STAT_HIT] = "hits",
935 [RA_STAT_MISS] = "misses",
936 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
937 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
938 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
939 [RA_STAT_FAILED_MATCH] = "failed lock match",
940 [RA_STAT_DISCARDED] = "read but discarded",
941 [RA_STAT_ZERO_LEN] = "zero length file",
942 [RA_STAT_ZERO_WINDOW] = "zero size window",
943 [RA_STAT_EOF] = "read-ahead to EOF",
944 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
945 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
946};
947
73bb1da6
PT
948LPROC_SEQ_FOPS_RO_TYPE(llite, name);
949LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
d7e09d03
PT
950
951int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
952 struct super_block *sb, char *osc, char *mdc)
953{
954 struct lprocfs_vars lvars[2];
955 struct lustre_sb_info *lsi = s2lsi(sb);
956 struct ll_sb_info *sbi = ll_s2sbi(sb);
957 struct obd_device *obd;
b59fe845 958 struct proc_dir_entry *dir;
d7e09d03
PT
959 char name[MAX_STRING_SIZE + 1], *ptr;
960 int err, id, len, rc;
d7e09d03
PT
961
962 memset(lvars, 0, sizeof(lvars));
963
964 name[MAX_STRING_SIZE] = '\0';
965 lvars[0].name = name;
966
967 LASSERT(sbi != NULL);
968 LASSERT(mdc != NULL);
969 LASSERT(osc != NULL);
970
971 /* Get fsname */
972 len = strlen(lsi->lsi_lmd->lmd_profile);
973 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
974 if (ptr && (strcmp(ptr, "-client") == 0))
975 len -= 7;
976
977 /* Mount info */
978 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
979 lsi->lsi_lmd->lmd_profile, sb);
980
981 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
982 if (IS_ERR(sbi->ll_proc_root)) {
983 err = PTR_ERR(sbi->ll_proc_root);
984 sbi->ll_proc_root = NULL;
0a3bdb00 985 return err;
d7e09d03
PT
986 }
987
988 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
989 &vvp_dump_pgcache_file_ops, sbi);
990 if (rc)
991 CWARN("Error adding the dump_page_cache file\n");
992
993 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
994 &ll_rw_extents_stats_fops, sbi);
995 if (rc)
996 CWARN("Error adding the extent_stats file\n");
997
998 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
999 0644, &ll_rw_extents_stats_pp_fops, sbi);
1000 if (rc)
1001 CWARN("Error adding the extents_stats_per_process file\n");
1002
1003 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1004 &ll_rw_offset_stats_fops, sbi);
1005 if (rc)
1006 CWARN("Error adding the offset_stats file\n");
1007
1008 /* File operations stats */
1009 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1010 LPROCFS_STATS_FLAG_NONE);
34e1f2bb
JL
1011 if (sbi->ll_stats == NULL) {
1012 err = -ENOMEM;
1013 goto out;
1014 }
d7e09d03
PT
1015 /* do counter init */
1016 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1017 __u32 type = llite_opcode_table[id].type;
1018 void *ptr = NULL;
1019 if (type & LPROCFS_TYPE_REGS)
1020 ptr = "regs";
1021 else if (type & LPROCFS_TYPE_BYTES)
1022 ptr = "bytes";
1023 else if (type & LPROCFS_TYPE_PAGES)
1024 ptr = "pages";
1025 lprocfs_counter_init(sbi->ll_stats,
1026 llite_opcode_table[id].opcode,
1027 (type & LPROCFS_CNTR_AVGMINMAX),
1028 llite_opcode_table[id].opname, ptr);
1029 }
1030 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1031 if (err)
34e1f2bb 1032 goto out;
d7e09d03
PT
1033
1034 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1035 LPROCFS_STATS_FLAG_NONE);
34e1f2bb
JL
1036 if (sbi->ll_ra_stats == NULL) {
1037 err = -ENOMEM;
1038 goto out;
1039 }
d7e09d03
PT
1040
1041 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1042 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1043 ra_stat_string[id], "pages");
1044 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1045 sbi->ll_ra_stats);
1046 if (err)
34e1f2bb 1047 goto out;
d7e09d03
PT
1048
1049
1050 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1051 if (err)
34e1f2bb 1052 goto out;
d7e09d03
PT
1053
1054 /* MDC info */
1055 obd = class_name2obd(mdc);
1056
1057 LASSERT(obd != NULL);
1058 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1059 LASSERT(obd->obd_type->typ_name != NULL);
1060
73bb1da6 1061 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
34e1f2bb
JL
1062 if (dir == NULL) {
1063 err = -ENOMEM;
1064 goto out;
1065 }
73bb1da6
PT
1066
1067 snprintf(name, MAX_STRING_SIZE, "common_name");
1068 lvars[0].fops = &llite_name_fops;
1069 err = lprocfs_add_vars(dir, lvars, obd);
d7e09d03 1070 if (err)
34e1f2bb 1071 goto out;
d7e09d03 1072
73bb1da6
PT
1073 snprintf(name, MAX_STRING_SIZE, "uuid");
1074 lvars[0].fops = &llite_uuid_fops;
1075 err = lprocfs_add_vars(dir, lvars, obd);
d7e09d03 1076 if (err)
34e1f2bb 1077 goto out;
d7e09d03
PT
1078
1079 /* OSC */
1080 obd = class_name2obd(osc);
1081
1082 LASSERT(obd != NULL);
1083 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1084 LASSERT(obd->obd_type->typ_name != NULL);
1085
73bb1da6 1086 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
34e1f2bb
JL
1087 if (dir == NULL) {
1088 err = -ENOMEM;
1089 goto out;
1090 }
73bb1da6
PT
1091
1092 snprintf(name, MAX_STRING_SIZE, "common_name");
1093 lvars[0].fops = &llite_name_fops;
1094 err = lprocfs_add_vars(dir, lvars, obd);
d7e09d03 1095 if (err)
34e1f2bb 1096 goto out;
d7e09d03 1097
73bb1da6
PT
1098 snprintf(name, MAX_STRING_SIZE, "uuid");
1099 lvars[0].fops = &llite_uuid_fops;
1100 err = lprocfs_add_vars(dir, lvars, obd);
d7e09d03
PT
1101out:
1102 if (err) {
1103 lprocfs_remove(&sbi->ll_proc_root);
1104 lprocfs_free_stats(&sbi->ll_ra_stats);
1105 lprocfs_free_stats(&sbi->ll_stats);
1106 }
0a3bdb00 1107 return err;
d7e09d03
PT
1108}
1109
1110void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1111{
1112 if (sbi->ll_proc_root) {
1113 lprocfs_remove(&sbi->ll_proc_root);
1114 lprocfs_free_stats(&sbi->ll_ra_stats);
1115 lprocfs_free_stats(&sbi->ll_stats);
1116 }
1117}
1118#undef MAX_STRING_SIZE
1119
1d8cb70c 1120#define pct(a, b) (b ? a * 100 / b : 0)
d7e09d03
PT
1121
1122static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1123 struct seq_file *seq, int which)
1124{
1125 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1126 unsigned long start, end, r, w;
1127 char *unitp = "KMGTPEZY";
1128 int i, units = 10;
1129 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1130
1131 read_cum = 0;
1132 write_cum = 0;
1133 start = 0;
1134
a58a38ac 1135 for (i = 0; i < LL_HIST_MAX; i++) {
d7e09d03
PT
1136 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1137 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1138 }
1139
a58a38ac 1140 for (i = 0; i < LL_HIST_MAX; i++) {
d7e09d03
PT
1141 r = pp_info->pp_r_hist.oh_buckets[i];
1142 w = pp_info->pp_w_hist.oh_buckets[i];
1143 read_cum += r;
1144 write_cum += w;
1145 end = 1 << (i + LL_HIST_START - units);
2d00bd17
JP
1146 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | %14lu %4lu %4lu\n",
1147 start, *unitp, end, *unitp,
d7e09d03
PT
1148 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1149 r, pct(r, read_tot), pct(read_cum, read_tot),
1150 w, pct(w, write_tot), pct(write_cum, write_tot));
1151 start = end;
1152 if (start == 1<<10) {
1153 start = 1;
1154 units += 10;
1155 unitp++;
1156 }
1157 if (read_cum == read_tot && write_cum == write_tot)
1158 break;
1159 }
1160}
1161
1162static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1163{
1164 struct timeval now;
1165 struct ll_sb_info *sbi = seq->private;
1166 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1167 int k;
1168
1169 do_gettimeofday(&now);
1170
1171 if (!sbi->ll_rw_stats_on) {
1172 seq_printf(seq, "disabled\n"
2d00bd17 1173 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
d7e09d03
PT
1174 return 0;
1175 }
1176 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
996adff8 1177 now.tv_sec, (unsigned long)now.tv_usec);
d7e09d03
PT
1178 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1179 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1180 "extents", "calls", "%", "cum%",
1181 "calls", "%", "cum%");
1182 spin_lock(&sbi->ll_pp_extent_lock);
1183 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1184 if (io_extents->pp_extents[k].pid != 0) {
1185 seq_printf(seq, "\nPID: %d\n",
1186 io_extents->pp_extents[k].pid);
1187 ll_display_extents_info(io_extents, seq, k);
1188 }
1189 }
1190 spin_unlock(&sbi->ll_pp_extent_lock);
1191 return 0;
1192}
1193
1194static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
a1e7e2d4
OD
1195 const char __user *buf,
1196 size_t len,
d7e09d03
PT
1197 loff_t *off)
1198{
1199 struct seq_file *seq = file->private_data;
1200 struct ll_sb_info *sbi = seq->private;
1201 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1202 int i;
1203 int value = 1, rc = 0;
1204
a1e7e2d4
OD
1205 if (len == 0)
1206 return -EINVAL;
1207
d7e09d03 1208 rc = lprocfs_write_helper(buf, len, &value);
a1e7e2d4
OD
1209 if (rc < 0 && len < 16) {
1210 char kernbuf[16];
1211
1212 if (copy_from_user(kernbuf, buf, len))
1213 return -EFAULT;
1214 kernbuf[len] = 0;
1215
1216 if (kernbuf[len - 1] == '\n')
1217 kernbuf[len - 1] = 0;
1218
1219 if (strcmp(kernbuf, "disabled") == 0 ||
1220 strcmp(kernbuf, "Disabled") == 0)
1221 value = 0;
1222 }
d7e09d03
PT
1223
1224 if (value == 0)
1225 sbi->ll_rw_stats_on = 0;
1226 else
1227 sbi->ll_rw_stats_on = 1;
1228
1229 spin_lock(&sbi->ll_pp_extent_lock);
1230 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1231 io_extents->pp_extents[i].pid = 0;
1232 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1233 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1234 }
1235 spin_unlock(&sbi->ll_pp_extent_lock);
1236 return len;
1237}
1238
1239LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1240
1241static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1242{
1243 struct timeval now;
1244 struct ll_sb_info *sbi = seq->private;
1245 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1246
1247 do_gettimeofday(&now);
1248
1249 if (!sbi->ll_rw_stats_on) {
1250 seq_printf(seq, "disabled\n"
2d00bd17 1251 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
d7e09d03
PT
1252 return 0;
1253 }
1254 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
996adff8 1255 now.tv_sec, (unsigned long)now.tv_usec);
d7e09d03
PT
1256
1257 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1258 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1259 "extents", "calls", "%", "cum%",
1260 "calls", "%", "cum%");
1261 spin_lock(&sbi->ll_lock);
1262 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1263 spin_unlock(&sbi->ll_lock);
1264
1265 return 0;
1266}
1267
a1e7e2d4
OD
1268static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1269 const char __user *buf,
1270 size_t len, loff_t *off)
d7e09d03
PT
1271{
1272 struct seq_file *seq = file->private_data;
1273 struct ll_sb_info *sbi = seq->private;
1274 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1275 int i;
1276 int value = 1, rc = 0;
1277
a1e7e2d4
OD
1278 if (len == 0)
1279 return -EINVAL;
1280
d7e09d03 1281 rc = lprocfs_write_helper(buf, len, &value);
a1e7e2d4
OD
1282 if (rc < 0 && len < 16) {
1283 char kernbuf[16];
1284
1285 if (copy_from_user(kernbuf, buf, len))
1286 return -EFAULT;
1287 kernbuf[len] = 0;
1288
1289 if (kernbuf[len - 1] == '\n')
1290 kernbuf[len - 1] = 0;
1291
1292 if (strcmp(kernbuf, "disabled") == 0 ||
1293 strcmp(kernbuf, "Disabled") == 0)
1294 value = 0;
1295 }
d7e09d03
PT
1296
1297 if (value == 0)
1298 sbi->ll_rw_stats_on = 0;
1299 else
1300 sbi->ll_rw_stats_on = 1;
a1e7e2d4 1301
d7e09d03
PT
1302 spin_lock(&sbi->ll_pp_extent_lock);
1303 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1304 io_extents->pp_extents[i].pid = 0;
1305 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1306 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1307 }
1308 spin_unlock(&sbi->ll_pp_extent_lock);
1309
1310 return len;
1311}
d7e09d03
PT
1312LPROC_SEQ_FOPS(ll_rw_extents_stats);
1313
1314void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1315 struct ll_file_data *file, loff_t pos,
1316 size_t count, int rw)
1317{
1318 int i, cur = -1;
1319 struct ll_rw_process_info *process;
1320 struct ll_rw_process_info *offset;
1321 int *off_count = &sbi->ll_rw_offset_entry_count;
1322 int *process_count = &sbi->ll_offset_process_count;
1323 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1324
a58a38ac 1325 if (!sbi->ll_rw_stats_on)
d7e09d03
PT
1326 return;
1327 process = sbi->ll_rw_process_info;
1328 offset = sbi->ll_rw_offset_info;
1329
1330 spin_lock(&sbi->ll_pp_extent_lock);
1331 /* Extent statistics */
a58a38ac
GD
1332 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1333 if (io_extents->pp_extents[i].pid == pid) {
d7e09d03
PT
1334 cur = i;
1335 break;
1336 }
1337 }
1338
1339 if (cur == -1) {
1340 /* new process */
1341 sbi->ll_extent_process_count =
1342 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1343 cur = sbi->ll_extent_process_count;
1344 io_extents->pp_extents[cur].pid = pid;
1345 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1346 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1347 }
1348
1349 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1350 (i < (LL_HIST_MAX - 1)); i++);
1351 if (rw == 0) {
1352 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1353 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1354 } else {
1355 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1356 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1357 }
1358 spin_unlock(&sbi->ll_pp_extent_lock);
1359
1360 spin_lock(&sbi->ll_process_lock);
1361 /* Offset statistics */
1362 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1363 if (process[i].rw_pid == pid) {
1364 if (process[i].rw_last_file != file) {
1365 process[i].rw_range_start = pos;
1366 process[i].rw_last_file_pos = pos + count;
1367 process[i].rw_smallest_extent = count;
1368 process[i].rw_largest_extent = count;
1369 process[i].rw_offset = 0;
1370 process[i].rw_last_file = file;
1371 spin_unlock(&sbi->ll_process_lock);
1372 return;
1373 }
1374 if (process[i].rw_last_file_pos != pos) {
1375 *off_count =
1376 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1377 offset[*off_count].rw_op = process[i].rw_op;
1378 offset[*off_count].rw_pid = pid;
1379 offset[*off_count].rw_range_start =
1380 process[i].rw_range_start;
1381 offset[*off_count].rw_range_end =
1382 process[i].rw_last_file_pos;
1383 offset[*off_count].rw_smallest_extent =
1384 process[i].rw_smallest_extent;
1385 offset[*off_count].rw_largest_extent =
1386 process[i].rw_largest_extent;
1387 offset[*off_count].rw_offset =
1388 process[i].rw_offset;
1389 process[i].rw_op = rw;
1390 process[i].rw_range_start = pos;
1391 process[i].rw_smallest_extent = count;
1392 process[i].rw_largest_extent = count;
1393 process[i].rw_offset = pos -
1394 process[i].rw_last_file_pos;
1395 }
a58a38ac 1396 if (process[i].rw_smallest_extent > count)
d7e09d03 1397 process[i].rw_smallest_extent = count;
a58a38ac 1398 if (process[i].rw_largest_extent < count)
d7e09d03
PT
1399 process[i].rw_largest_extent = count;
1400 process[i].rw_last_file_pos = pos + count;
1401 spin_unlock(&sbi->ll_process_lock);
1402 return;
1403 }
1404 }
1405 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1406 process[*process_count].rw_pid = pid;
1407 process[*process_count].rw_op = rw;
1408 process[*process_count].rw_range_start = pos;
1409 process[*process_count].rw_last_file_pos = pos + count;
1410 process[*process_count].rw_smallest_extent = count;
1411 process[*process_count].rw_largest_extent = count;
1412 process[*process_count].rw_offset = 0;
1413 process[*process_count].rw_last_file = file;
1414 spin_unlock(&sbi->ll_process_lock);
1415}
1416
1417static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1418{
1419 struct timeval now;
1420 struct ll_sb_info *sbi = seq->private;
1421 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1422 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1423 int i;
1424
1425 do_gettimeofday(&now);
1426
1427 if (!sbi->ll_rw_stats_on) {
1428 seq_printf(seq, "disabled\n"
2d00bd17 1429 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
d7e09d03
PT
1430 return 0;
1431 }
1432 spin_lock(&sbi->ll_process_lock);
1433
1434 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
996adff8 1435 now.tv_sec, (unsigned long)now.tv_usec);
d7e09d03
PT
1436 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1437 "R/W", "PID", "RANGE START", "RANGE END",
1438 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1439 /* We stored the discontiguous offsets here; print them first */
a58a38ac 1440 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
d7e09d03 1441 if (offset[i].rw_pid != 0)
4f37bc04
JH
1442 seq_printf(seq,
1443 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1444 offset[i].rw_op == READ ? 'R' : 'W',
d7e09d03
PT
1445 offset[i].rw_pid,
1446 offset[i].rw_range_start,
1447 offset[i].rw_range_end,
1448 (unsigned long)offset[i].rw_smallest_extent,
1449 (unsigned long)offset[i].rw_largest_extent,
1450 offset[i].rw_offset);
1451 }
1452 /* Then print the current offsets for each process */
a58a38ac 1453 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
d7e09d03 1454 if (process[i].rw_pid != 0)
4f37bc04
JH
1455 seq_printf(seq,
1456 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1457 process[i].rw_op == READ ? 'R' : 'W',
d7e09d03
PT
1458 process[i].rw_pid,
1459 process[i].rw_range_start,
1460 process[i].rw_last_file_pos,
1461 (unsigned long)process[i].rw_smallest_extent,
1462 (unsigned long)process[i].rw_largest_extent,
1463 process[i].rw_offset);
1464 }
1465 spin_unlock(&sbi->ll_process_lock);
1466
1467 return 0;
1468}
1469
a1e7e2d4
OD
1470static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1471 const char __user *buf,
1472 size_t len, loff_t *off)
d7e09d03
PT
1473{
1474 struct seq_file *seq = file->private_data;
1475 struct ll_sb_info *sbi = seq->private;
1476 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1477 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1478 int value = 1, rc = 0;
1479
a1e7e2d4
OD
1480 if (len == 0)
1481 return -EINVAL;
1482
d7e09d03
PT
1483 rc = lprocfs_write_helper(buf, len, &value);
1484
a1e7e2d4
OD
1485 if (rc < 0 && len < 16) {
1486 char kernbuf[16];
1487
1488 if (copy_from_user(kernbuf, buf, len))
1489 return -EFAULT;
1490 kernbuf[len] = 0;
1491
1492 if (kernbuf[len - 1] == '\n')
1493 kernbuf[len - 1] = 0;
1494
1495 if (strcmp(kernbuf, "disabled") == 0 ||
1496 strcmp(kernbuf, "Disabled") == 0)
1497 value = 0;
1498 }
d7e09d03
PT
1499
1500 if (value == 0)
1501 sbi->ll_rw_stats_on = 0;
1502 else
1503 sbi->ll_rw_stats_on = 1;
1504
1505 spin_lock(&sbi->ll_process_lock);
1506 sbi->ll_offset_process_count = 0;
1507 sbi->ll_rw_offset_entry_count = 0;
1508 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1509 LL_PROCESS_HIST_MAX);
1510 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1511 LL_OFFSET_HIST_MAX);
1512 spin_unlock(&sbi->ll_process_lock);
1513
1514 return len;
1515}
1516
1517LPROC_SEQ_FOPS(ll_rw_offset_stats);
1518
1519void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1520{
1521 lvars->module_vars = NULL;
1522 lvars->obd_vars = lprocfs_llite_obd_vars;
1523}
This page took 0.38784 seconds and 5 git commands to generate.