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 Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_CLASS
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
28 #include <linux/obd_class.h>
29 #include <linux/lprocfs_status.h>
30 #include <linux/seq_file.h>
31 #include "osc_internal.h"
34 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
35 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
38 int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off, int count,
41 struct obd_device *dev = data;
42 struct client_obd *cli = &dev->u.cli;
45 spin_lock(&cli->cl_loi_list_lock);
46 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
47 spin_unlock(&cli->cl_loi_list_lock);
51 int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
52 unsigned long count, void *data)
54 struct obd_device *dev = data;
55 struct client_obd *cli = &dev->u.cli;
58 rc = lprocfs_write_helper(buffer, count, &val);
62 if (val < 1 || val > PTL_MD_MAX_PAGES)
65 spin_lock(&cli->cl_loi_list_lock);
66 cli->cl_max_pages_per_rpc = val;
67 spin_unlock(&cli->cl_loi_list_lock);
72 int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off, int count,
75 struct obd_device *dev = data;
76 struct client_obd *cli = &dev->u.cli;
79 spin_lock(&cli->cl_loi_list_lock);
80 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
81 spin_unlock(&cli->cl_loi_list_lock);
85 int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
86 unsigned long count, void *data)
88 struct obd_device *dev = data;
89 struct client_obd *cli = &dev->u.cli;
92 rc = lprocfs_write_helper(buffer, count, &val);
96 if (val < 1 || val > OSC_MAX_RIF_MAX)
99 spin_lock(&cli->cl_loi_list_lock);
100 cli->cl_max_rpcs_in_flight = val;
101 spin_unlock(&cli->cl_loi_list_lock);
106 int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
107 int *eof, void *data)
109 struct obd_device *dev = data;
110 struct client_obd *cli = &dev->u.cli;
114 spin_lock(&cli->cl_loi_list_lock);
115 val = cli->cl_dirty_max >> 20;
116 rc = snprintf(page, count, "%d\n", val);
117 spin_unlock(&cli->cl_loi_list_lock);
121 int osc_wr_max_dirty_mb(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;
128 rc = lprocfs_write_helper(buffer, count, &val);
132 if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX)
135 spin_lock(&cli->cl_loi_list_lock);
136 cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
137 osc_wake_cache_waiters(cli);
138 spin_unlock(&cli->cl_loi_list_lock);
143 int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off, int count,
144 int *eof, void *data)
146 struct obd_device *dev = data;
147 struct client_obd *cli = &dev->u.cli;
150 spin_lock(&cli->cl_loi_list_lock);
151 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
152 spin_unlock(&cli->cl_loi_list_lock);
156 int osc_rd_cur_grant_bytes(char *page, char **start, off_t off, int count,
157 int *eof, void *data)
159 struct obd_device *dev = data;
160 struct client_obd *cli = &dev->u.cli;
163 spin_lock(&cli->cl_loi_list_lock);
164 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
165 spin_unlock(&cli->cl_loi_list_lock);
169 int osc_rd_create_low_wm(char *page, char **start, off_t off, int count,
170 int *eof, void *data)
172 struct obd_device *obd = data;
177 return snprintf(page, count, "%d\n",
178 obd->u.cli.cl_oscc.oscc_kick_barrier);
181 int osc_wr_create_low_wm(struct file *file, const char *buffer,
182 unsigned long count, void *data)
184 struct obd_device *obd = data;
190 rc = lprocfs_write_helper(buffer, count, &val);
197 spin_lock(&obd->obd_dev_lock);
198 obd->u.cli.cl_oscc.oscc_kick_barrier = val;
199 spin_unlock(&obd->obd_dev_lock);
204 int osc_rd_create_count(char *page, char **start, off_t off, int count,
205 int *eof, void *data)
207 struct obd_device *obd = data;
212 return snprintf(page, count, "%d\n",
213 obd->u.cli.cl_oscc.oscc_grow_count);
216 int osc_wr_create_count(struct file *file, const char *buffer,
217 unsigned long count, void *data)
219 struct obd_device *obd = data;
225 rc = lprocfs_write_helper(buffer, count, &val);
232 obd->u.cli.cl_oscc.oscc_grow_count = val;
237 int osc_rd_prealloc_next_id(char *page, char **start, off_t off, int count,
238 int *eof, void *data)
240 struct obd_device *obd = data;
245 return snprintf(page, count, LPU64"\n",
246 obd->u.cli.cl_oscc.oscc_next_id);
249 int osc_rd_prealloc_last_id(char *page, char **start, off_t off, int count,
250 int *eof, void *data)
252 struct obd_device *obd = data;
257 return snprintf(page, count, LPU64"\n",
258 obd->u.cli.cl_oscc.oscc_last_id);
261 static struct lprocfs_vars lprocfs_obd_vars[] = {
262 { "uuid", lprocfs_rd_uuid, 0, 0 },
263 { "blocksize", lprocfs_rd_blksize, 0, 0 },
264 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
265 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
266 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
267 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
268 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
269 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
270 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
271 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
272 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
273 osc_wr_max_pages_per_rpc, 0 },
274 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
275 osc_wr_max_rpcs_in_flight, 0 },
276 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
277 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
278 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
279 {"create_low_watermark", osc_rd_create_low_wm, osc_wr_create_low_wm, 0},
280 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
281 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
282 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
286 static struct lprocfs_vars lprocfs_module_vars[] = {
287 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
291 #define pct(a,b) (b ? a * 100 / b : 0)
293 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
296 struct obd_device *dev = seq->private;
297 struct client_obd *cli = &dev->u.cli;
299 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
302 do_gettimeofday(&now);
304 spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
306 rpcs = cli->cl_brw_in_flight;
307 r = cli->cl_pending_r_pages;
308 w = cli->cl_pending_w_pages;
310 seq_printf(seq, "snapshot_time: %lu:%lu (secs:usecs)\n",
311 now.tv_sec, now.tv_usec);
312 seq_printf(seq, "RPCs in flight: %d\n", rpcs);
313 seq_printf(seq, "pending write pages: %d\n", w);
314 seq_printf(seq, "pending read pages: %d\n", r);
316 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
317 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
318 seq_printf(seq, " rpcs %% cum %%\n");
320 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
321 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
325 for (i = 0; i < OBD_HIST_MAX; i++) {
326 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
327 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
330 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
331 1 << i, r, pct(r, read_tot),
332 pct(read_cum, read_tot), w,
334 pct(write_cum, write_tot));
335 if (read_cum == read_tot && write_cum == write_tot)
339 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
340 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
341 seq_printf(seq, " rpcs %% cum %%\n");
343 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
344 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
348 for (i = 0; i < OBD_HIST_MAX; i++) {
349 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
350 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
353 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
354 i, r, pct(r, read_tot),
355 pct(read_cum, read_tot), w,
357 pct(write_cum, write_tot));
358 if (read_cum == read_tot && write_cum == write_tot)
362 spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
368 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
374 static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
379 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
382 struct seq_operations osc_rpc_stats_seq_sops = {
383 .start = osc_rpc_stats_seq_start,
384 .stop = osc_rpc_stats_seq_stop,
385 .next = osc_rpc_stats_seq_next,
386 .show = osc_rpc_stats_seq_show,
389 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
391 struct proc_dir_entry *dp = PDE(inode);
392 struct seq_file *seq;
395 rc = seq_open(file, &osc_rpc_stats_seq_sops);
398 seq = file->private_data;
399 seq->private = dp->data;
403 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
404 size_t len, loff_t *off)
406 struct seq_file *seq = file->private_data;
407 struct obd_device *dev = seq->private;
408 struct client_obd *cli = &dev->u.cli;
410 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
411 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
412 lprocfs_oh_clear(&cli->cl_read_page_hist);
413 lprocfs_oh_clear(&cli->cl_write_page_hist);
418 struct file_operations osc_rpc_stats_fops = {
419 .open = osc_rpc_stats_seq_open,
421 .write = osc_rpc_stats_seq_write,
423 .release = seq_release,
426 int lproc_osc_attach_seqstat(struct obd_device *dev)
428 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
429 &osc_rpc_stats_fops, dev);
434 LPROCFS_INIT_VARS(osc,lprocfs_module_vars, lprocfs_obd_vars)