1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_CLASS
27 #include <linux/version.h>
28 #include <asm/statfs.h>
29 #include <obd_class.h>
30 #include <lprocfs_status.h>
31 #include <linux/seq_file.h>
32 #include "osc_internal.h"
35 static int osc_rd_active(char *page, char **start, off_t off,
36 int count, int *eof, void *data)
38 struct obd_device *dev = data;
41 LPROCFS_CLIMP_CHECK(dev);
42 rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
43 LPROCFS_CLIMP_EXIT(dev);
47 static int osc_wr_active(struct file *file, const char *buffer,
48 unsigned long count, void *data)
50 struct obd_device *dev = data;
53 rc = lprocfs_write_helper(buffer, count, &val);
56 if (val < 0 || val > 1)
59 LPROCFS_CLIMP_CHECK(dev);
61 if (dev->u.cli.cl_import->imp_deactive == val)
62 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
64 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
66 LPROCFS_CLIMP_EXIT(dev);
70 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
71 int count, int *eof, void *data)
73 struct obd_device *dev = data;
74 struct client_obd *cli = &dev->u.cli;
77 client_obd_list_lock(&cli->cl_loi_list_lock);
78 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
79 client_obd_list_unlock(&cli->cl_loi_list_lock);
83 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
84 unsigned long count, void *data)
86 struct obd_device *dev = data;
87 struct client_obd *cli = &dev->u.cli;
88 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
91 rc = lprocfs_write_helper(buffer, count, &val);
95 LPROCFS_CLIMP_CHECK(dev);
96 if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
97 LPROCFS_CLIMP_EXIT(dev);
100 client_obd_list_lock(&cli->cl_loi_list_lock);
101 cli->cl_max_pages_per_rpc = val;
102 client_obd_list_unlock(&cli->cl_loi_list_lock);
104 LPROCFS_CLIMP_EXIT(dev);
108 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
109 int count, int *eof, void *data)
111 struct obd_device *dev = data;
112 struct client_obd *cli = &dev->u.cli;
115 client_obd_list_lock(&cli->cl_loi_list_lock);
116 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
117 client_obd_list_unlock(&cli->cl_loi_list_lock);
121 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
122 unsigned long count, void *data)
124 struct obd_device *dev = data;
125 struct client_obd *cli = &dev->u.cli;
126 struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
129 rc = lprocfs_write_helper(buffer, count, &val);
133 if (val < 1 || val > OSC_MAX_RIF_MAX)
136 LPROCFS_CLIMP_CHECK(dev);
137 if (pool && val > cli->cl_max_rpcs_in_flight)
138 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
140 client_obd_list_lock(&cli->cl_loi_list_lock);
141 cli->cl_max_rpcs_in_flight = val;
142 client_obd_list_unlock(&cli->cl_loi_list_lock);
144 LPROCFS_CLIMP_EXIT(dev);
148 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
149 int *eof, void *data)
151 struct obd_device *dev = data;
152 struct client_obd *cli = &dev->u.cli;
156 client_obd_list_lock(&cli->cl_loi_list_lock);
157 val = cli->cl_dirty_max;
158 client_obd_list_unlock(&cli->cl_loi_list_lock);
161 return lprocfs_read_frac_helper(page, count, val, mult);
164 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
165 unsigned long count, void *data)
167 struct obd_device *dev = data;
168 struct client_obd *cli = &dev->u.cli;
169 int pages_number, mult, rc;
171 mult = 1 << (20 - CFS_PAGE_SHIFT);
172 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
176 if (pages_number < 0 ||
177 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
178 pages_number > num_physpages / 4) /* 1/4 of RAM */
181 client_obd_list_lock(&cli->cl_loi_list_lock);
182 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
183 osc_wake_cache_waiters(cli);
184 client_obd_list_unlock(&cli->cl_loi_list_lock);
189 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
190 int count, int *eof, void *data)
192 struct obd_device *dev = data;
193 struct client_obd *cli = &dev->u.cli;
196 client_obd_list_lock(&cli->cl_loi_list_lock);
197 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
198 client_obd_list_unlock(&cli->cl_loi_list_lock);
202 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
203 int count, int *eof, void *data)
205 struct obd_device *dev = data;
206 struct client_obd *cli = &dev->u.cli;
209 client_obd_list_lock(&cli->cl_loi_list_lock);
210 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
211 client_obd_list_unlock(&cli->cl_loi_list_lock);
215 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
216 int *eof, void *data)
218 struct obd_device *obd = data;
223 return snprintf(page, count, "%d\n",
224 obd->u.cli.cl_oscc.oscc_grow_count);
227 static int osc_wr_create_count(struct file *file, const char *buffer,
228 unsigned long count, void *data)
230 struct obd_device *obd = data;
236 rc = lprocfs_write_helper(buffer, count, &val);
242 if (val > OST_MAX_PRECREATE)
245 obd->u.cli.cl_oscc.oscc_grow_count = val;
250 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
251 int count, int *eof, void *data)
253 struct obd_device *obd = data;
258 return snprintf(page, count, LPU64"\n",
259 obd->u.cli.cl_oscc.oscc_next_id);
262 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
263 int count, int *eof, void *data)
265 struct obd_device *obd = data;
270 return snprintf(page, count, LPU64"\n",
271 obd->u.cli.cl_oscc.oscc_last_id);
274 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
275 int *eof, void *data)
277 struct obd_device *obd = data;
282 return snprintf(page, count, "%d\n",
283 obd->u.cli.cl_checksum ? 1 : 0);
286 static int osc_wr_checksum(struct file *file, const char *buffer,
287 unsigned long count, void *data)
289 struct obd_device *obd = data;
295 rc = lprocfs_write_helper(buffer, count, &val);
299 obd->u.cli.cl_checksum = (val ? 1 : 0);
304 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
305 int *eof, void *data)
307 struct obd_device *obd = data;
314 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
315 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
317 if (obd->u.cli.cl_cksum_type == (1 << i))
318 len += snprintf(page + len, count - len, "[%s] ",
321 len += snprintf(page + len, count - len, "%s ",
325 len += sprintf(page + len, "\n");
329 static int osc_wd_checksum_type(struct file *file, const char *buffer,
330 unsigned long count, void *data)
332 struct obd_device *obd = data;
340 if (count > sizeof(kernbuf) - 1)
342 if (copy_from_user(kernbuf, buffer, count))
344 if (count > 0 && kernbuf[count - 1] == '\n')
345 kernbuf[count - 1] = '\0';
347 kernbuf[count] = '\0';
349 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
350 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
352 if (!strcmp(kernbuf, cksum_name[i])) {
353 obd->u.cli.cl_cksum_type = 1 << i;
360 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
361 int *eof, void *data)
363 struct obd_device *obd = data;
365 return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
368 static int osc_wr_resend_count(struct file *file, const char *buffer,
369 unsigned long count, void *data)
371 struct obd_device *obd = data;
374 rc = lprocfs_write_helper(buffer, count, &val);
381 atomic_set(&obd->u.cli.cl_resends, val);
386 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
387 { "uuid", lprocfs_rd_uuid, 0, 0 },
388 { "ping", 0, lprocfs_wr_ping, 0 },
389 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
390 { "blocksize", lprocfs_rd_blksize, 0, 0 },
391 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
392 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
393 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
394 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
395 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
396 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
397 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
398 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
399 { "active", osc_rd_active,
401 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
402 osc_wr_max_pages_per_rpc, 0 },
403 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
404 osc_wr_max_rpcs_in_flight, 0 },
405 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
406 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
407 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
408 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
409 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
410 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
411 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
412 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
413 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
417 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
418 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
422 #define pct(a,b) (b ? a * 100 / b : 0)
424 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
427 struct obd_device *dev = seq->private;
428 struct client_obd *cli = &dev->u.cli;
429 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
432 do_gettimeofday(&now);
434 client_obd_list_lock(&cli->cl_loi_list_lock);
436 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
437 now.tv_sec, now.tv_usec);
438 seq_printf(seq, "read RPCs in flight: %d\n",
439 cli->cl_r_in_flight);
440 seq_printf(seq, "write RPCs in flight: %d\n",
441 cli->cl_w_in_flight);
442 seq_printf(seq, "pending write pages: %d\n",
443 cli->cl_pending_w_pages);
444 seq_printf(seq, "pending read pages: %d\n",
445 cli->cl_pending_r_pages);
447 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
448 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
449 seq_printf(seq, " rpcs %% cum %%\n");
451 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
452 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
456 for (i = 0; i < OBD_HIST_MAX; i++) {
457 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
458 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
461 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
462 1 << i, r, pct(r, read_tot),
463 pct(read_cum, read_tot), w,
465 pct(write_cum, write_tot));
466 if (read_cum == read_tot && write_cum == write_tot)
470 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
471 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
472 seq_printf(seq, " rpcs %% cum %%\n");
474 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
475 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
479 for (i = 0; i < OBD_HIST_MAX; i++) {
480 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
481 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
484 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
485 i, r, pct(r, read_tot),
486 pct(read_cum, read_tot), w,
488 pct(write_cum, write_tot));
489 if (read_cum == read_tot && write_cum == write_tot)
493 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
494 seq_printf(seq, "offset rpcs %% cum %% |");
495 seq_printf(seq, " rpcs %% cum %%\n");
497 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
498 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
502 for (i = 0; i < OBD_HIST_MAX; i++) {
503 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
504 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
507 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
508 (i == 0) ? 0 : 1 << (i - 1),
509 r, pct(r, read_tot), pct(read_cum, read_tot),
510 w, pct(w, write_tot), pct(write_cum, write_tot));
511 if (read_cum == read_tot && write_cum == write_tot)
515 client_obd_list_unlock(&cli->cl_loi_list_lock);
521 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
522 size_t len, loff_t *off)
524 struct seq_file *seq = file->private_data;
525 struct obd_device *dev = seq->private;
526 struct client_obd *cli = &dev->u.cli;
528 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
529 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
530 lprocfs_oh_clear(&cli->cl_read_page_hist);
531 lprocfs_oh_clear(&cli->cl_write_page_hist);
532 lprocfs_oh_clear(&cli->cl_read_offset_hist);
533 lprocfs_oh_clear(&cli->cl_write_offset_hist);
538 LPROC_SEQ_FOPS(osc_rpc_stats);
540 int lproc_osc_attach_seqstat(struct obd_device *dev)
542 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
543 &osc_rpc_stats_fops, dev);
546 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
548 lvars->module_vars = lprocfs_osc_module_vars;
549 lvars->obd_vars = lprocfs_osc_obd_vars;