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);
229 * Set OSC creator's osc_creator::oscc_grow_count
231 * \param file proc file
232 * \param buffer buffer containing the value
233 * \param count buffer size
234 * \param data obd device
238 static int osc_wr_create_count(struct file *file, const char *buffer,
239 unsigned long count, void *data)
241 struct obd_device *obd = data;
247 rc = lprocfs_write_helper(buffer, count, &val);
251 /* The MDT ALWAYS needs to limit the precreate count to
252 * OST_MAX_PRECREATE, and the constant cannot be changed
253 * because it is a value shared between the OSC and OST
254 * that is the maximum possible number of objects that will
255 * ever be handled by MDT->OST recovery processing.
257 * If the OST ever gets a request to delete more orphans,
258 * this implies that something has gone badly on the MDT
259 * and the OST will refuse to delete so much data from the
260 * filesystem as a safety measure. */
261 if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
263 if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
266 for (i = 1; (i << 1) <= val; i <<= 1)
268 obd->u.cli.cl_oscc.oscc_grow_count = i;
274 * Read OSC creator's osc_creator::oscc_max_grow_count
276 * \param page buffer to hold the returning string
281 * proc read function parameters, please refer to kernel
282 * code fs/proc/generic.c proc_file_read()
283 * \param data obd device
285 * \retval number of characters printed.
287 static int osc_rd_max_create_count(char *page, char **start, off_t off,
288 int count, int *eof, void *data)
290 struct obd_device *obd = data;
295 return snprintf(page, count, "%d\n",
296 obd->u.cli.cl_oscc.oscc_max_grow_count);
300 * Set OSC creator's osc_creator::oscc_max_grow_count
302 * \param file proc file
303 * \param buffer buffer containing the value
304 * \param count buffer size
305 * \param data obd device
309 static int osc_wr_max_create_count(struct file *file, const char *buffer,
310 unsigned long count, void *data)
312 struct obd_device *obd = data;
318 rc = lprocfs_write_helper(buffer, count, &val);
324 if (val > OST_MAX_PRECREATE)
327 if (obd->u.cli.cl_oscc.oscc_grow_count > val)
328 obd->u.cli.cl_oscc.oscc_grow_count = val;
330 obd->u.cli.cl_oscc.oscc_max_grow_count = val;
335 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
336 int count, int *eof, void *data)
338 struct obd_device *obd = data;
343 return snprintf(page, count, LPU64"\n",
344 obd->u.cli.cl_oscc.oscc_next_id);
347 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
348 int count, int *eof, void *data)
350 struct obd_device *obd = data;
355 return snprintf(page, count, LPU64"\n",
356 obd->u.cli.cl_oscc.oscc_last_id);
359 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
360 int *eof, void *data)
362 struct obd_device *obd = data;
367 return snprintf(page, count, "%d\n",
368 obd->u.cli.cl_checksum ? 1 : 0);
371 static int osc_wr_checksum(struct file *file, const char *buffer,
372 unsigned long count, void *data)
374 struct obd_device *obd = data;
380 rc = lprocfs_write_helper(buffer, count, &val);
384 obd->u.cli.cl_checksum = (val ? 1 : 0);
389 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
390 int *eof, void *data)
392 struct obd_device *obd = data;
399 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
400 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
402 if (obd->u.cli.cl_cksum_type == (1 << i))
403 len += snprintf(page + len, count - len, "[%s] ",
406 len += snprintf(page + len, count - len, "%s ",
410 len += sprintf(page + len, "\n");
414 static int osc_wd_checksum_type(struct file *file, const char *buffer,
415 unsigned long count, void *data)
417 struct obd_device *obd = data;
425 if (count > sizeof(kernbuf) - 1)
427 if (copy_from_user(kernbuf, buffer, count))
429 if (count > 0 && kernbuf[count - 1] == '\n')
430 kernbuf[count - 1] = '\0';
432 kernbuf[count] = '\0';
434 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
435 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
437 if (!strcmp(kernbuf, cksum_name[i])) {
438 obd->u.cli.cl_cksum_type = 1 << i;
445 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
446 int *eof, void *data)
448 struct obd_device *obd = data;
450 return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
453 static int osc_wr_resend_count(struct file *file, const char *buffer,
454 unsigned long count, void *data)
456 struct obd_device *obd = data;
459 rc = lprocfs_write_helper(buffer, count, &val);
466 atomic_set(&obd->u.cli.cl_resends, val);
471 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
472 { "uuid", lprocfs_rd_uuid, 0, 0 },
473 { "ping", 0, lprocfs_wr_ping, 0 },
474 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
475 { "blocksize", lprocfs_rd_blksize, 0, 0 },
476 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
477 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
478 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
479 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
480 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
481 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
482 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
483 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
484 { "active", osc_rd_active,
486 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
487 osc_wr_max_pages_per_rpc, 0 },
488 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
489 osc_wr_max_rpcs_in_flight, 0 },
490 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
491 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
492 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
493 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
494 { "max_create_count", osc_rd_max_create_count,
495 osc_wr_max_create_count, 0},
496 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
497 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
498 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
499 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
500 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
501 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
505 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
506 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
510 #define pct(a,b) (b ? a * 100 / b : 0)
512 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
515 struct obd_device *dev = seq->private;
516 struct client_obd *cli = &dev->u.cli;
517 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
520 do_gettimeofday(&now);
522 client_obd_list_lock(&cli->cl_loi_list_lock);
524 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
525 now.tv_sec, now.tv_usec);
526 seq_printf(seq, "read RPCs in flight: %d\n",
527 cli->cl_r_in_flight);
528 seq_printf(seq, "write RPCs in flight: %d\n",
529 cli->cl_w_in_flight);
530 seq_printf(seq, "pending write pages: %d\n",
531 cli->cl_pending_w_pages);
532 seq_printf(seq, "pending read pages: %d\n",
533 cli->cl_pending_r_pages);
535 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
536 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
537 seq_printf(seq, " rpcs %% cum %%\n");
539 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
540 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
544 for (i = 0; i < OBD_HIST_MAX; i++) {
545 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
546 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
549 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
550 1 << i, r, pct(r, read_tot),
551 pct(read_cum, read_tot), w,
553 pct(write_cum, write_tot));
554 if (read_cum == read_tot && write_cum == write_tot)
558 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
559 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
560 seq_printf(seq, " rpcs %% cum %%\n");
562 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
563 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
567 for (i = 0; i < OBD_HIST_MAX; i++) {
568 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
569 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
572 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
573 i, r, pct(r, read_tot),
574 pct(read_cum, read_tot), w,
576 pct(write_cum, write_tot));
577 if (read_cum == read_tot && write_cum == write_tot)
581 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
582 seq_printf(seq, "offset rpcs %% cum %% |");
583 seq_printf(seq, " rpcs %% cum %%\n");
585 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
586 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
590 for (i = 0; i < OBD_HIST_MAX; i++) {
591 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
592 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
595 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
596 (i == 0) ? 0 : 1 << (i - 1),
597 r, pct(r, read_tot), pct(read_cum, read_tot),
598 w, pct(w, write_tot), pct(write_cum, write_tot));
599 if (read_cum == read_tot && write_cum == write_tot)
603 client_obd_list_unlock(&cli->cl_loi_list_lock);
609 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
610 size_t len, loff_t *off)
612 struct seq_file *seq = file->private_data;
613 struct obd_device *dev = seq->private;
614 struct client_obd *cli = &dev->u.cli;
616 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
617 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
618 lprocfs_oh_clear(&cli->cl_read_page_hist);
619 lprocfs_oh_clear(&cli->cl_write_page_hist);
620 lprocfs_oh_clear(&cli->cl_read_offset_hist);
621 lprocfs_oh_clear(&cli->cl_write_offset_hist);
626 LPROC_SEQ_FOPS(osc_rpc_stats);
628 int lproc_osc_attach_seqstat(struct obd_device *dev)
630 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
631 &osc_rpc_stats_fops, dev);
634 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
636 lvars->module_vars = lprocfs_osc_module_vars;
637 lvars->obd_vars = lprocfs_osc_obd_vars;