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_resend_count(char *page, char **start, off_t off, int count,
305 int *eof, void *data)
307 struct obd_device *obd = data;
309 return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
312 static int osc_wr_resend_count(struct file *file, const char *buffer,
313 unsigned long count, void *data)
315 struct obd_device *obd = data;
318 rc = lprocfs_write_helper(buffer, count, &val);
325 atomic_set(&obd->u.cli.cl_resends, val);
330 static struct lprocfs_vars lprocfs_obd_vars[] = {
331 { "uuid", lprocfs_rd_uuid, 0, 0 },
332 { "ping", 0, lprocfs_wr_ping, 0 },
333 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
334 { "blocksize", lprocfs_rd_blksize, 0, 0 },
335 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
336 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
337 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
338 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
339 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
340 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
341 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
342 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
343 { "active", osc_rd_active,
345 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
346 osc_wr_max_pages_per_rpc, 0 },
347 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
348 osc_wr_max_rpcs_in_flight, 0 },
349 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
350 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
351 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
352 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
353 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
354 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
355 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
356 { "sptlrpc", sptlrpc_lprocfs_rd, 0, 0 },
357 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
361 static struct lprocfs_vars lprocfs_module_vars[] = {
362 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
366 #define pct(a,b) (b ? a * 100 / b : 0)
368 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
371 struct obd_device *dev = seq->private;
372 struct client_obd *cli = &dev->u.cli;
373 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
376 do_gettimeofday(&now);
378 client_obd_list_lock(&cli->cl_loi_list_lock);
380 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
381 now.tv_sec, now.tv_usec);
382 seq_printf(seq, "read RPCs in flight: %d\n",
383 cli->cl_r_in_flight);
384 seq_printf(seq, "write RPCs in flight: %d\n",
385 cli->cl_w_in_flight);
386 seq_printf(seq, "pending write pages: %d\n",
387 cli->cl_pending_w_pages);
388 seq_printf(seq, "pending read pages: %d\n",
389 cli->cl_pending_r_pages);
391 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
392 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
393 seq_printf(seq, " rpcs %% cum %%\n");
395 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
396 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
400 for (i = 0; i < OBD_HIST_MAX; i++) {
401 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
402 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
405 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
406 1 << i, r, pct(r, read_tot),
407 pct(read_cum, read_tot), w,
409 pct(write_cum, write_tot));
410 if (read_cum == read_tot && write_cum == write_tot)
414 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
415 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
416 seq_printf(seq, " rpcs %% cum %%\n");
418 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
419 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
423 for (i = 0; i < OBD_HIST_MAX; i++) {
424 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
425 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
428 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
429 i, r, pct(r, read_tot),
430 pct(read_cum, read_tot), w,
432 pct(write_cum, write_tot));
433 if (read_cum == read_tot && write_cum == write_tot)
437 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
438 seq_printf(seq, "offset rpcs %% cum %% |");
439 seq_printf(seq, " rpcs %% cum %%\n");
441 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
442 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
446 for (i = 0; i < OBD_HIST_MAX; i++) {
447 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
448 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
451 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
452 (i == 0) ? 0 : 1 << (i - 1),
453 r, pct(r, read_tot), pct(read_cum, read_tot),
454 w, pct(w, write_tot), pct(write_cum, write_tot));
455 if (read_cum == read_tot && write_cum == write_tot)
459 client_obd_list_unlock(&cli->cl_loi_list_lock);
465 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
466 size_t len, loff_t *off)
468 struct seq_file *seq = file->private_data;
469 struct obd_device *dev = seq->private;
470 struct client_obd *cli = &dev->u.cli;
472 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
473 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
474 lprocfs_oh_clear(&cli->cl_read_page_hist);
475 lprocfs_oh_clear(&cli->cl_write_page_hist);
476 lprocfs_oh_clear(&cli->cl_read_offset_hist);
477 lprocfs_oh_clear(&cli->cl_write_offset_hist);
482 LPROC_SEQ_FOPS(osc_rpc_stats);
484 int lproc_osc_attach_seqstat(struct obd_device *dev)
486 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
487 &osc_rpc_stats_fops, dev);
490 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)