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_cksum.h>
30 #include <obd_class.h>
31 #include <lprocfs_status.h>
32 #include <linux/seq_file.h>
33 #include "osc_internal.h"
36 static int osc_rd_active(char *page, char **start, off_t off,
37 int count, int *eof, void *data)
39 struct obd_device *dev = data;
42 LPROCFS_CLIMP_CHECK(dev);
43 rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
44 LPROCFS_CLIMP_EXIT(dev);
48 static int osc_wr_active(struct file *file, const char *buffer,
49 unsigned long count, void *data)
51 struct obd_device *dev = data;
54 rc = lprocfs_write_helper(buffer, count, &val);
57 if (val < 0 || val > 1)
60 LPROCFS_CLIMP_CHECK(dev);
62 if (dev->u.cli.cl_import->imp_deactive == val)
63 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
65 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
67 LPROCFS_CLIMP_EXIT(dev);
71 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
72 int count, int *eof, void *data)
74 struct obd_device *dev = data;
75 struct client_obd *cli = &dev->u.cli;
78 client_obd_list_lock(&cli->cl_loi_list_lock);
79 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
80 client_obd_list_unlock(&cli->cl_loi_list_lock);
84 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
85 unsigned long count, void *data)
87 struct obd_device *dev = data;
88 struct client_obd *cli = &dev->u.cli;
89 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
92 rc = lprocfs_write_helper(buffer, count, &val);
96 LPROCFS_CLIMP_CHECK(dev);
97 if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
98 LPROCFS_CLIMP_EXIT(dev);
101 client_obd_list_lock(&cli->cl_loi_list_lock);
102 cli->cl_max_pages_per_rpc = val;
103 client_obd_list_unlock(&cli->cl_loi_list_lock);
105 LPROCFS_CLIMP_EXIT(dev);
109 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
110 int count, int *eof, void *data)
112 struct obd_device *dev = data;
113 struct client_obd *cli = &dev->u.cli;
116 client_obd_list_lock(&cli->cl_loi_list_lock);
117 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
118 client_obd_list_unlock(&cli->cl_loi_list_lock);
122 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
123 unsigned long count, void *data)
125 struct obd_device *dev = data;
126 struct client_obd *cli = &dev->u.cli;
127 struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
130 rc = lprocfs_write_helper(buffer, count, &val);
134 if (val < 1 || val > OSC_MAX_RIF_MAX)
137 LPROCFS_CLIMP_CHECK(dev);
138 if (pool && val > cli->cl_max_rpcs_in_flight)
139 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
141 client_obd_list_lock(&cli->cl_loi_list_lock);
142 cli->cl_max_rpcs_in_flight = val;
143 client_obd_list_unlock(&cli->cl_loi_list_lock);
145 LPROCFS_CLIMP_EXIT(dev);
149 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
150 int *eof, void *data)
152 struct obd_device *dev = data;
153 struct client_obd *cli = &dev->u.cli;
157 client_obd_list_lock(&cli->cl_loi_list_lock);
158 val = cli->cl_dirty_max;
159 client_obd_list_unlock(&cli->cl_loi_list_lock);
162 return lprocfs_read_frac_helper(page, count, val, mult);
165 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
166 unsigned long count, void *data)
168 struct obd_device *dev = data;
169 struct client_obd *cli = &dev->u.cli;
170 int pages_number, mult, rc;
172 mult = 1 << (20 - CFS_PAGE_SHIFT);
173 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
177 if (pages_number < 0 ||
178 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
179 pages_number > num_physpages / 4) /* 1/4 of RAM */
182 client_obd_list_lock(&cli->cl_loi_list_lock);
183 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
184 osc_wake_cache_waiters(cli);
185 client_obd_list_unlock(&cli->cl_loi_list_lock);
190 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
191 int count, int *eof, void *data)
193 struct obd_device *dev = data;
194 struct client_obd *cli = &dev->u.cli;
197 client_obd_list_lock(&cli->cl_loi_list_lock);
198 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
199 client_obd_list_unlock(&cli->cl_loi_list_lock);
203 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 struct obd_device *dev = data;
207 struct client_obd *cli = &dev->u.cli;
210 client_obd_list_lock(&cli->cl_loi_list_lock);
211 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
212 client_obd_list_unlock(&cli->cl_loi_list_lock);
216 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
217 int *eof, void *data)
219 struct obd_device *obd = data;
224 return snprintf(page, count, "%d\n",
225 obd->u.cli.cl_oscc.oscc_grow_count);
228 static int osc_wr_create_count(struct file *file, const char *buffer,
229 unsigned long count, void *data)
231 struct obd_device *obd = data;
237 rc = lprocfs_write_helper(buffer, count, &val);
241 /* The MDT ALWAYS needs to limit the precreate count to
242 * OST_MAX_PRECREATE, and the constant cannot be changed
243 * because it is a value shared between the OSC and OST
244 * that is the maximum possible number of objects that will
245 * ever be handled by MDT->OST recovery processing.
247 * If the OST ever gets a request to delete more orphans,
248 * this implies that something has gone badly on the MDT
249 * and the OST will refuse to delete so much data from the
250 * filesystem as a safety measure. */
251 if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
253 if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
256 for (i = 1; (i << 1) <= val; i <<= 1)
258 obd->u.cli.cl_oscc.oscc_grow_count = i;
263 static int osc_rd_max_create_count(char *page, char **start, off_t off,
264 int count, int *eof, void *data)
266 struct obd_device *obd = data;
271 return snprintf(page, count, "%d\n",
272 obd->u.cli.cl_oscc.oscc_max_grow_count);
275 static int osc_wr_max_create_count(struct file *file, const char *buffer,
276 unsigned long count, void *data)
278 struct obd_device *obd = data;
284 rc = lprocfs_write_helper(buffer, count, &val);
290 if (val > OST_MAX_PRECREATE)
293 if (obd->u.cli.cl_oscc.oscc_grow_count > val)
294 obd->u.cli.cl_oscc.oscc_grow_count = val;
296 obd->u.cli.cl_oscc.oscc_max_grow_count = val;
301 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
302 int count, int *eof, void *data)
304 struct obd_device *obd = data;
309 return snprintf(page, count, LPU64"\n",
310 obd->u.cli.cl_oscc.oscc_next_id);
313 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
314 int count, int *eof, void *data)
316 struct obd_device *obd = data;
321 return snprintf(page, count, LPU64"\n",
322 obd->u.cli.cl_oscc.oscc_last_id);
325 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
326 int *eof, void *data)
328 struct obd_device *obd = data;
333 return snprintf(page, count, "%d\n",
334 obd->u.cli.cl_checksum ? 1 : 0);
337 static int osc_wr_checksum(struct file *file, const char *buffer,
338 unsigned long count, void *data)
340 struct obd_device *obd = data;
346 rc = lprocfs_write_helper(buffer, count, &val);
350 obd->u.cli.cl_checksum = (val ? 1 : 0);
355 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
356 int *eof, void *data)
358 struct obd_device *obd = data;
365 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
366 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
368 if (obd->u.cli.cl_cksum_type == (1 << i))
369 len += snprintf(page + len, count - len, "[%s] ",
372 len += snprintf(page + len, count - len, "%s ",
376 len += sprintf(page + len, "\n");
380 static int osc_wd_checksum_type(struct file *file, const char *buffer,
381 unsigned long count, void *data)
383 struct obd_device *obd = data;
391 if (count > sizeof(kernbuf) - 1)
393 if (copy_from_user(kernbuf, buffer, count))
395 if (count > 0 && kernbuf[count - 1] == '\n')
396 kernbuf[count - 1] = '\0';
398 kernbuf[count] = '\0';
400 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
401 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
403 if (!strcmp(kernbuf, cksum_name[i])) {
404 obd->u.cli.cl_cksum_type = 1 << i;
411 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
412 int *eof, void *data)
414 struct obd_device *obd = data;
416 return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
419 static int osc_wr_resend_count(struct file *file, const char *buffer,
420 unsigned long count, void *data)
422 struct obd_device *obd = data;
425 rc = lprocfs_write_helper(buffer, count, &val);
432 atomic_set(&obd->u.cli.cl_resends, val);
437 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
438 { "uuid", lprocfs_rd_uuid, 0, 0 },
439 { "ping", 0, lprocfs_wr_ping, 0 },
440 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
441 { "blocksize", lprocfs_rd_blksize, 0, 0 },
442 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
443 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
444 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
445 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
446 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
447 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
448 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
449 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
450 { "active", osc_rd_active,
452 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
453 osc_wr_max_pages_per_rpc, 0 },
454 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
455 osc_wr_max_rpcs_in_flight, 0 },
456 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
457 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
458 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
459 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
460 { "max_create_count", osc_rd_max_create_count,
461 osc_wr_max_create_count, 0},
462 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
463 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
464 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
465 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
466 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
467 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
471 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
472 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
476 #define pct(a,b) (b ? a * 100 / b : 0)
478 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
481 struct obd_device *dev = seq->private;
482 struct client_obd *cli = &dev->u.cli;
483 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
486 do_gettimeofday(&now);
488 client_obd_list_lock(&cli->cl_loi_list_lock);
490 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
491 now.tv_sec, now.tv_usec);
492 seq_printf(seq, "read RPCs in flight: %d\n",
493 cli->cl_r_in_flight);
494 seq_printf(seq, "write RPCs in flight: %d\n",
495 cli->cl_w_in_flight);
496 seq_printf(seq, "pending write pages: %d\n",
497 cli->cl_pending_w_pages);
498 seq_printf(seq, "pending read pages: %d\n",
499 cli->cl_pending_r_pages);
501 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
502 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
503 seq_printf(seq, " rpcs %% cum %%\n");
505 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
506 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
510 for (i = 0; i < OBD_HIST_MAX; i++) {
511 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
512 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
515 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
516 1 << i, r, pct(r, read_tot),
517 pct(read_cum, read_tot), w,
519 pct(write_cum, write_tot));
520 if (read_cum == read_tot && write_cum == write_tot)
524 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
525 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
526 seq_printf(seq, " rpcs %% cum %%\n");
528 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
529 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
533 for (i = 0; i < OBD_HIST_MAX; i++) {
534 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
535 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
538 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
539 i, r, pct(r, read_tot),
540 pct(read_cum, read_tot), w,
542 pct(write_cum, write_tot));
543 if (read_cum == read_tot && write_cum == write_tot)
547 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
548 seq_printf(seq, "offset rpcs %% cum %% |");
549 seq_printf(seq, " rpcs %% cum %%\n");
551 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
552 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
556 for (i = 0; i < OBD_HIST_MAX; i++) {
557 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
558 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
561 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
562 (i == 0) ? 0 : 1 << (i - 1),
563 r, pct(r, read_tot), pct(read_cum, read_tot),
564 w, pct(w, write_tot), pct(write_cum, write_tot));
565 if (read_cum == read_tot && write_cum == write_tot)
569 client_obd_list_unlock(&cli->cl_loi_list_lock);
575 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
576 size_t len, loff_t *off)
578 struct seq_file *seq = file->private_data;
579 struct obd_device *dev = seq->private;
580 struct client_obd *cli = &dev->u.cli;
582 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
583 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
584 lprocfs_oh_clear(&cli->cl_read_page_hist);
585 lprocfs_oh_clear(&cli->cl_write_page_hist);
586 lprocfs_oh_clear(&cli->cl_read_offset_hist);
587 lprocfs_oh_clear(&cli->cl_write_offset_hist);
592 LPROC_SEQ_FOPS(osc_rpc_stats);
594 int lproc_osc_attach_seqstat(struct obd_device *dev)
596 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
597 &osc_rpc_stats_fops, dev);
600 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
602 lvars->module_vars = lprocfs_osc_module_vars;
603 lvars->obd_vars = lprocfs_osc_obd_vars;