1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 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 <linux/lprocfs_status.h>
32 #include <linux/obd_class.h>
33 #include <linux/seq_file.h>
36 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
39 struct obd_device *dev = (struct obd_device *)data;
40 struct lov_desc *desc;
43 desc = &dev->u.lov.desc;
45 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
48 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
51 struct obd_device *dev = (struct obd_device *)data;
52 struct lov_desc *desc;
55 desc = &dev->u.lov.desc;
57 return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
60 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
63 struct obd_device* dev = (struct obd_device*)data;
64 struct lov_desc *desc;
67 desc = &dev->u.lov.desc;
69 return snprintf(page, count, "%u\n", desc->ld_pattern);
72 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
75 struct obd_device *dev = (struct obd_device *)data;
76 struct lov_desc *desc;
79 desc = &dev->u.lov.desc;
81 return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
84 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
87 struct obd_device *dev = (struct obd_device*)data;
88 struct lov_desc *desc;
91 desc = &dev->u.lov.desc;
93 return snprintf(page, count, "%u\n", desc->ld_tgt_count);
97 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
100 struct obd_device* dev = (struct obd_device*)data;
101 struct lov_desc *desc;
103 LASSERT(dev != NULL);
104 desc = &dev->u.lov.desc;
106 return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
109 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
110 int *eof, void *data)
112 struct obd_device *dev = (struct obd_device*) data;
115 LASSERT(dev != NULL);
118 return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
121 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
123 struct obd_device *dev = p->private;
124 struct lov_obd *lov = &dev->u.lov;
126 return (*pos >= lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
130 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
134 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
136 struct obd_device *dev = p->private;
137 struct lov_obd *lov = &dev->u.lov;
140 return (*pos >=lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
143 static int lov_tgt_seq_show(struct seq_file *p, void *v)
145 struct lov_tgt_desc *tgt = v;
146 struct obd_device *dev = p->private;
147 struct lov_obd *lov = &dev->u.lov;
148 int idx = tgt - &(lov->tgts[0]);
149 return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->uuid.uuid,
150 tgt->active ? "" : "IN");
153 struct seq_operations lov_tgt_sops = {
154 .start = lov_tgt_seq_start,
155 .stop = lov_tgt_seq_stop,
156 .next = lov_tgt_seq_next,
157 .show = lov_tgt_seq_show,
160 static int lov_target_seq_open(struct inode *inode, struct file *file)
162 struct proc_dir_entry *dp = PDE(inode);
163 struct seq_file *seq;
164 int rc = seq_open(file, &lov_tgt_sops);
169 seq = file->private_data;
170 seq->private = dp->data;
175 struct lprocfs_vars lprocfs_obd_vars[] = {
176 { "uuid", lprocfs_rd_uuid, 0, 0 },
177 { "stripesize", lov_rd_stripesize, 0, 0 },
178 { "stripeoffset", lov_rd_stripeoffset, 0, 0 },
179 { "stripecount", lov_rd_stripecount, 0, 0 },
180 { "stripetype", lov_rd_stripetype, 0, 0 },
181 { "numobd", lov_rd_numobd, 0, 0 },
182 { "activeobd", lov_rd_activeobd, 0, 0 },
183 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
184 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
185 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
186 { "blocksize", lprocfs_rd_blksize, 0, 0 },
187 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
188 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
189 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
190 { "desc_uuid", lov_rd_desc_uuid, 0, 0 },
194 static struct lprocfs_vars lprocfs_module_vars[] = {
195 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
199 struct file_operations lov_proc_target_fops = {
200 .owner = THIS_MODULE,
201 .open = lov_target_seq_open,
204 .release = seq_release,
207 LPROCFS_INIT_VARS(lov, lprocfs_module_vars, lprocfs_obd_vars)