4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <linux/version.h>
35 #include <linux/vfs.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include <lustre_osc.h>
39 #include <cl_object.h>
41 #include "mdc_internal.h"
44 static int mdc_active_seq_show(struct seq_file *m, void *v)
46 struct obd_device *dev = m->private;
48 LPROCFS_CLIMP_CHECK(dev);
49 seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
50 LPROCFS_CLIMP_EXIT(dev);
54 static ssize_t mdc_active_seq_write(struct file *file,
55 const char __user *buffer,
56 size_t count, loff_t *off)
58 struct obd_device *dev;
62 dev = ((struct seq_file *)file->private_data)->private;
63 rc = kstrtobool_from_user(buffer, count, &val);
68 if (dev->u.cli.cl_import->imp_deactive == val)
69 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
71 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
76 LPROC_SEQ_FOPS(mdc_active);
78 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
80 struct obd_device *dev = m->private;
81 struct client_obd *cli = &dev->u.cli;
85 spin_lock(&cli->cl_loi_list_lock);
86 val = cli->cl_dirty_max_pages;
87 spin_unlock(&cli->cl_loi_list_lock);
89 mult = 1 << (20 - PAGE_SHIFT);
90 return lprocfs_seq_read_frac_helper(m, val, mult);
93 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
94 const char __user *buffer,
95 size_t count, loff_t *off)
97 struct seq_file *sfl = file->private_data;
98 struct obd_device *dev = sfl->private;
99 struct client_obd *cli = &dev->u.cli;
103 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
107 pages_number >>= PAGE_SHIFT;
109 if (pages_number <= 0 ||
110 pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
111 pages_number > totalram_pages / 4) /* 1/4 of RAM */
114 spin_lock(&cli->cl_loi_list_lock);
115 cli->cl_dirty_max_pages = pages_number;
116 osc_wake_cache_waiters(cli);
117 spin_unlock(&cli->cl_loi_list_lock);
121 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
123 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
125 struct obd_device *dev = m->private;
126 struct client_obd *cli = &dev->u.cli;
127 int shift = 20 - PAGE_SHIFT;
129 seq_printf(m, "used_mb: %ld\n"
132 (atomic_long_read(&cli->cl_lru_in_list) +
133 atomic_long_read(&cli->cl_lru_busy)) >> shift,
134 atomic_long_read(&cli->cl_lru_busy),
135 cli->cl_lru_reclaim);
140 /* shrink the number of caching pages to a specific number */
142 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
143 size_t count, loff_t *off)
145 struct seq_file *sfl = file->private_data;
146 struct obd_device *dev = sfl->private;
147 struct client_obd *cli = &dev->u.cli;
152 if (count >= sizeof(kernbuf))
155 if (copy_from_user(kernbuf, buffer, count))
159 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
161 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
165 pages_number >>= PAGE_SHIFT;
167 if (pages_number < 0)
170 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
175 env = cl_env_get(&refcheck);
177 (void)osc_lru_shrink(env, cli, rc, true);
178 cl_env_put(env, &refcheck);
184 LPROC_SEQ_FOPS(mdc_cached_mb);
186 static int mdc_contention_seconds_seq_show(struct seq_file *m, void *v)
188 struct obd_device *obd = m->private;
189 struct osc_device *od = obd2osc_dev(obd);
191 seq_printf(m, "%lld\n", od->od_contention_time);
195 static ssize_t mdc_contention_seconds_seq_write(struct file *file,
196 const char __user *buffer,
197 size_t count, loff_t *off)
199 struct seq_file *sfl = file->private_data;
200 struct obd_device *obd = sfl->private;
201 struct osc_device *od = obd2osc_dev(obd);
205 rc = kstrtoll_from_user(buffer, count, 0, &val);
209 od->od_contention_time = val;
213 LPROC_SEQ_FOPS(mdc_contention_seconds);
215 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
217 struct obd_device *dev = m->private;
218 struct client_obd *cli = &dev->u.cli;
222 pages = atomic_long_read(&cli->cl_unstable_count);
223 mb = (pages * PAGE_SIZE) >> 20;
225 seq_printf(m, "unstable_pages: %20ld\n"
226 "unstable_mb: %10d\n", pages, mb);
229 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
231 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
233 struct obd_device *dev = m->private;
236 max = obd_get_max_rpcs_in_flight(&dev->u.cli);
237 seq_printf(m, "%u\n", max);
242 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
243 const char __user *buffer,
244 size_t count, loff_t *off)
246 struct obd_device *dev;
250 dev = ((struct seq_file *)file->private_data)->private;
251 rc = kstrtouint_from_user(buffer, count, 0, &val);
255 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
261 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
263 static int mdc_max_mod_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
265 struct obd_device *dev = m->private;
268 max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
269 seq_printf(m, "%hu\n", max);
274 static ssize_t mdc_max_mod_rpcs_in_flight_seq_write(struct file *file,
275 const char __user *buffer,
276 size_t count, loff_t *off)
278 struct obd_device *dev;
282 dev = ((struct seq_file *)file->private_data)->private;
283 rc = kstrtou16_from_user(buffer, count, 0, &val);
287 rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
293 LPROC_SEQ_FOPS(mdc_max_mod_rpcs_in_flight);
295 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
296 const char __user *buf,
297 size_t len, loff_t *off)
299 struct seq_file *seq = file->private_data;
300 struct obd_device *dev = seq->private;
301 struct client_obd *cli = &dev->u.cli;
303 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
305 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
306 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
307 lprocfs_oh_clear(&cli->cl_read_page_hist);
308 lprocfs_oh_clear(&cli->cl_write_page_hist);
309 lprocfs_oh_clear(&cli->cl_read_offset_hist);
310 lprocfs_oh_clear(&cli->cl_write_offset_hist);
315 #define pct(a, b) (b ? a * 100 / b : 0)
316 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
318 struct obd_device *dev = seq->private;
319 struct client_obd *cli = &dev->u.cli;
320 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
323 obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
325 spin_lock(&cli->cl_loi_list_lock);
327 seq_printf(seq, "\nread RPCs in flight: %d\n",
328 cli->cl_r_in_flight);
329 seq_printf(seq, "write RPCs in flight: %d\n",
330 cli->cl_w_in_flight);
331 seq_printf(seq, "pending write pages: %d\n",
332 atomic_read(&cli->cl_pending_w_pages));
333 seq_printf(seq, "pending read pages: %d\n",
334 atomic_read(&cli->cl_pending_r_pages));
336 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
337 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
338 seq_printf(seq, " rpcs %% cum %%\n");
340 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
341 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
345 for (i = 0; i < OBD_HIST_MAX; i++) {
346 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
347 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
351 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
352 1 << i, r, pct(r, read_tot),
353 pct(read_cum, read_tot), w,
355 pct(write_cum, write_tot));
356 if (read_cum == read_tot && write_cum == write_tot)
360 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
361 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
362 seq_printf(seq, " rpcs %% cum %%\n");
364 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
365 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
369 for (i = 0; i < OBD_HIST_MAX; i++) {
370 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
371 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
375 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
376 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
377 pct(w, write_tot), pct(write_cum, write_tot));
378 if (read_cum == read_tot && write_cum == write_tot)
382 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
383 seq_printf(seq, "offset rpcs %% cum %% |");
384 seq_printf(seq, " rpcs %% cum %%\n");
386 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
387 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
391 for (i = 0; i < OBD_HIST_MAX; i++) {
392 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
393 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
397 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
398 (i == 0) ? 0 : 1 << (i - 1),
399 r, pct(r, read_tot), pct(read_cum, read_tot),
400 w, pct(w, write_tot), pct(write_cum, write_tot));
401 if (read_cum == read_tot && write_cum == write_tot)
404 spin_unlock(&cli->cl_loi_list_lock);
409 LPROC_SEQ_FOPS(mdc_rpc_stats);
411 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
413 struct timespec64 now;
414 struct obd_device *dev = seq->private;
415 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
417 ktime_get_real_ts64(&now);
419 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
420 (s64)now.tv_sec, now.tv_nsec);
421 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
422 stats->os_lockless_writes);
423 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
424 stats->os_lockless_reads);
425 seq_printf(seq, "lockless_truncate\t\t%llu\n",
426 stats->os_lockless_truncates);
430 static ssize_t mdc_stats_seq_write(struct file *file,
431 const char __user *buf,
432 size_t len, loff_t *off)
434 struct seq_file *seq = file->private_data;
435 struct obd_device *dev = seq->private;
436 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
438 memset(stats, 0, sizeof(*stats));
441 LPROC_SEQ_FOPS(mdc_stats);
443 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
445 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
446 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
447 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
448 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
449 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
450 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
451 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
452 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
454 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
456 .fops = &mdc_ping_fops,
458 { .name = "connect_flags",
459 .fops = &mdc_connect_flags_fops },
460 { .name = "mds_server_uuid",
461 .fops = &mdc_server_uuid_fops },
462 { .name = "mds_conn_uuid",
463 .fops = &mdc_conn_uuid_fops },
464 { .name = "max_pages_per_rpc",
465 .fops = &mdc_obd_max_pages_per_rpc_fops },
466 { .name = "max_rpcs_in_flight",
467 .fops = &mdc_max_rpcs_in_flight_fops },
468 { .name = "max_mod_rpcs_in_flight",
469 .fops = &mdc_max_mod_rpcs_in_flight_fops },
470 { .name = "max_dirty_mb",
471 .fops = &mdc_max_dirty_mb_fops },
472 { .name = "mdc_cached_mb",
473 .fops = &mdc_cached_mb_fops },
474 { .name = "timeouts",
475 .fops = &mdc_timeouts_fops },
476 { .name = "contention_seconds",
477 .fops = &mdc_contention_seconds_fops },
479 .fops = &mdc_import_fops },
481 .fops = &mdc_state_fops },
482 { .name = "pinger_recov",
483 .fops = &mdc_pinger_recov_fops },
484 { .name = "rpc_stats",
485 .fops = &mdc_rpc_stats_fops },
487 .fops = &mdc_active_fops },
488 { .name = "unstable_stats",
489 .fops = &mdc_unstable_stats_fops },
490 { .name = "mdc_stats",
491 .fops = &mdc_stats_fops },
495 #endif /* CONFIG_PROC_FS */