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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
31 #include <obd_class.h>
32 #include <lprocfs_status.h>
33 #include <linux/seq_file.h>
34 #include "osc_internal.h"
37 static int osc_rd_active(char *page, char **start, off_t off,
38 int count, int *eof, void *data)
40 struct obd_device *dev = data;
43 LPROCFS_CLIMP_CHECK(dev);
44 rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
45 LPROCFS_CLIMP_EXIT(dev);
49 static int osc_wr_active(struct file *file, const char *buffer,
50 unsigned long count, void *data)
52 struct obd_device *dev = data;
55 rc = lprocfs_write_helper(buffer, count, &val);
58 if (val < 0 || val > 1)
61 LPROCFS_CLIMP_CHECK(dev);
63 if (dev->u.cli.cl_import->imp_deactive == val)
64 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
66 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
68 LPROCFS_CLIMP_EXIT(dev);
73 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
74 int count, int *eof, void *data)
76 struct obd_device *dev = data;
77 struct client_obd *cli = &dev->u.cli;
80 client_obd_list_lock(&cli->cl_loi_list_lock);
81 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
82 client_obd_list_unlock(&cli->cl_loi_list_lock);
86 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
87 unsigned long count, void *data)
89 struct obd_device *dev = data;
90 struct client_obd *cli = &dev->u.cli;
91 struct obd_connect_data *ocd;
94 rc = lprocfs_write_helper(buffer, count, &val);
98 LPROCFS_CLIMP_CHECK(dev);
99 ocd = &cli->cl_import->imp_connect_data;
100 if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
101 LPROCFS_CLIMP_EXIT(dev);
104 client_obd_list_lock(&cli->cl_loi_list_lock);
105 cli->cl_max_pages_per_rpc = val;
106 client_obd_list_unlock(&cli->cl_loi_list_lock);
107 LPROCFS_CLIMP_EXIT(dev);
111 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
112 int count, int *eof, void *data)
114 struct obd_device *dev = data;
115 struct client_obd *cli = &dev->u.cli;
118 client_obd_list_lock(&cli->cl_loi_list_lock);
119 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
120 client_obd_list_unlock(&cli->cl_loi_list_lock);
124 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
125 unsigned long count, void *data)
127 struct obd_device *dev = data;
128 struct client_obd *cli = &dev->u.cli;
129 struct ptlrpc_request_pool *pool;
132 rc = lprocfs_write_helper(buffer, count, &val);
135 if (val < 1 || val > OSC_MAX_RIF_MAX)
138 LPROCFS_CLIMP_CHECK(dev);
139 pool = cli->cl_import->imp_rq_pool;
140 if (pool && val > cli->cl_max_rpcs_in_flight)
141 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
143 client_obd_list_lock(&cli->cl_loi_list_lock);
144 cli->cl_max_rpcs_in_flight = val;
145 client_obd_list_unlock(&cli->cl_loi_list_lock);
147 LPROCFS_CLIMP_EXIT(dev);
151 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
152 int *eof, void *data)
154 struct obd_device *dev = data;
155 struct client_obd *cli = &dev->u.cli;
159 client_obd_list_lock(&cli->cl_loi_list_lock);
160 val = cli->cl_dirty_max;
161 client_obd_list_unlock(&cli->cl_loi_list_lock);
164 return lprocfs_read_frac_helper(page, count, val, mult);
167 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
168 unsigned long count, void *data)
170 struct obd_device *dev = data;
171 struct client_obd *cli = &dev->u.cli;
172 int pages_number, mult, rc;
174 mult = 1 << (20 - CFS_PAGE_SHIFT);
175 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
179 if (pages_number < 0 || pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
180 pages_number > num_physpages / 4) /* 1/4 of RAM */
183 client_obd_list_lock(&cli->cl_loi_list_lock);
184 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
185 osc_wake_cache_waiters(cli);
186 client_obd_list_unlock(&cli->cl_loi_list_lock);
191 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
192 int count, int *eof, void *data)
194 struct obd_device *dev = data;
195 struct client_obd *cli = &dev->u.cli;
198 client_obd_list_lock(&cli->cl_loi_list_lock);
199 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
200 client_obd_list_unlock(&cli->cl_loi_list_lock);
204 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
205 int count, int *eof, void *data)
207 struct obd_device *dev = data;
208 struct client_obd *cli = &dev->u.cli;
211 client_obd_list_lock(&cli->cl_loi_list_lock);
212 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
213 client_obd_list_unlock(&cli->cl_loi_list_lock);
217 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
218 int *eof, void *data)
220 struct obd_device *obd = data;
225 return snprintf(page, count, "%d\n",
226 obd->u.cli.cl_oscc.oscc_grow_count);
229 static int osc_wr_create_count(struct file *file, const char *buffer,
230 unsigned long count, void *data)
232 struct obd_device *obd = data;
238 rc = lprocfs_write_helper(buffer, count, &val);
244 if (val > OST_MAX_PRECREATE)
247 obd->u.cli.cl_oscc.oscc_grow_count = val;
252 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
253 int count, int *eof, void *data)
255 struct obd_device *obd = data;
260 return snprintf(page, count, LPU64"\n",
261 obd->u.cli.cl_oscc.oscc_next_id);
264 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
265 int count, int *eof, void *data)
267 struct obd_device *obd = data;
272 return snprintf(page, count, LPU64"\n",
273 obd->u.cli.cl_oscc.oscc_last_id);
276 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
277 int *eof, void *data)
279 struct obd_device *obd = data;
284 return snprintf(page, count, "%d\n",
285 obd->u.cli.cl_checksum ? 1 : 0);
288 static int osc_wr_checksum(struct file *file, const char *buffer,
289 unsigned long count, void *data)
291 struct obd_device *obd = data;
297 rc = lprocfs_write_helper(buffer, count, &val);
301 obd->u.cli.cl_checksum = (val ? 1 : 0);
306 static int osc_rd_resendtime(char *page, char **start, off_t off, int count,
307 int *eof, void *data)
309 return snprintf(page, count, CFS_TIME_T,
310 cfs_duration_sec(atomic_read(&osc_resend_time)));
313 static int osc_wr_resendtime(struct file *file, const char *buffer,
314 unsigned long count, void *data)
318 rc = lprocfs_write_helper(buffer, count, &val);
325 atomic_set(&osc_resend_time, cfs_time_seconds(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 },
359 static struct lprocfs_vars lprocfs_module_vars[] = {
360 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
361 { "resend_timeout", osc_rd_resendtime, osc_wr_resendtime, 0},
365 #define pct(a,b) (b ? a * 100 / b : 0)
367 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
370 struct obd_device *dev = seq->private;
371 struct client_obd *cli = &dev->u.cli;
372 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
375 do_gettimeofday(&now);
377 client_obd_list_lock(&cli->cl_loi_list_lock);
379 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
380 now.tv_sec, now.tv_usec);
381 seq_printf(seq, "read RPCs in flight: %d\n",
382 cli->cl_r_in_flight);
383 seq_printf(seq, "write RPCs in flight: %d\n",
384 cli->cl_w_in_flight);
385 seq_printf(seq, "pending write pages: %d\n",
386 cli->cl_pending_w_pages);
387 seq_printf(seq, "pending read pages: %d\n",
388 cli->cl_pending_r_pages);
390 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
391 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
392 seq_printf(seq, " rpcs %% cum %%\n");
394 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
395 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
399 for (i = 0; i < OBD_HIST_MAX; i++) {
400 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
401 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
404 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
405 1 << i, r, pct(r, read_tot),
406 pct(read_cum, read_tot), w,
408 pct(write_cum, write_tot));
409 if (read_cum == read_tot && write_cum == write_tot)
413 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
414 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
415 seq_printf(seq, " rpcs %% cum %%\n");
417 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
418 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
422 for (i = 0; i < OBD_HIST_MAX; i++) {
423 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
424 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
427 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
428 i, r, pct(r, read_tot),
429 pct(read_cum, read_tot), w,
431 pct(write_cum, write_tot));
432 if (read_cum == read_tot && write_cum == write_tot)
436 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
437 seq_printf(seq, "offset rpcs %% cum %% |");
438 seq_printf(seq, " rpcs %% cum %%\n");
440 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
441 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
445 for (i = 0; i < OBD_HIST_MAX; i++) {
446 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
447 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
450 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
451 (i == 0) ? 0 : 1 << (i - 1),
452 r, pct(r, read_tot), pct(read_cum, read_tot),
453 w, pct(w, write_tot), pct(write_cum, write_tot));
454 if (read_cum == read_tot && write_cum == write_tot)
458 client_obd_list_unlock(&cli->cl_loi_list_lock);
464 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
465 size_t len, loff_t *off)
467 struct seq_file *seq = file->private_data;
468 struct obd_device *dev = seq->private;
469 struct client_obd *cli = &dev->u.cli;
471 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
472 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
473 lprocfs_oh_clear(&cli->cl_read_page_hist);
474 lprocfs_oh_clear(&cli->cl_write_page_hist);
475 lprocfs_oh_clear(&cli->cl_read_offset_hist);
476 lprocfs_oh_clear(&cli->cl_write_offset_hist);
481 LPROC_SEQ_FOPS(osc_rpc_stats);
483 int lproc_osc_attach_seqstat(struct obd_device *dev)
485 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
486 &osc_rpc_stats_fops, dev);
489 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)