Whamcloud - gitweb
- update from parent
[fs/lustre-release.git] / lustre / lov / lproc_lov.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
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.
13  *
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.
18  *
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.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <linux/lprocfs_status.h>
32 #include <linux/obd_class.h>
33 #include <linux/seq_file.h>
34
35 #ifdef LPROCFS
36 static int lov_rd_stripesize(char *page, char **start, off_t off, int count,
37                              int *eof, void *data)
38 {
39         struct obd_device *dev = (struct obd_device *)data;
40         struct lov_desc *desc;
41
42         LASSERT(dev != NULL);
43         desc = &dev->u.lov.desc;
44         *eof = 1;
45         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_size);
46 }
47
48 static int lov_rd_stripeoffset(char *page, char **start, off_t off, int count,
49                                int *eof, void *data)
50 {
51         struct obd_device *dev = (struct obd_device *)data;
52         struct lov_desc *desc;
53
54         LASSERT(dev != NULL);
55         desc = &dev->u.lov.desc;
56         *eof = 1;
57         return snprintf(page, count, LPU64"\n", desc->ld_default_stripe_offset);
58 }
59
60 static int lov_rd_stripetype(char *page, char **start, off_t off, int count,
61                              int *eof, void *data)
62 {
63         struct obd_device* dev = (struct obd_device*)data;
64         struct lov_desc *desc;
65
66         LASSERT(dev != NULL);
67         desc = &dev->u.lov.desc;
68         *eof = 1;
69         return snprintf(page, count, "%u\n", desc->ld_pattern);
70 }
71
72 static int lov_rd_stripecount(char *page, char **start, off_t off, int count,
73                               int *eof, void *data)
74 {
75         struct obd_device *dev = (struct obd_device *)data;
76         struct lov_desc *desc;
77
78         LASSERT(dev != NULL);
79         desc = &dev->u.lov.desc;
80         *eof = 1;
81         return snprintf(page, count, "%u\n", desc->ld_default_stripe_count);
82 }
83
84 static int lov_rd_numobd(char *page, char **start, off_t off, int count,
85                          int *eof, void *data)
86 {
87         struct obd_device *dev = (struct obd_device*)data;
88         struct lov_desc *desc;
89
90         LASSERT(dev != NULL);
91         desc = &dev->u.lov.desc;
92         *eof = 1;
93         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
94
95 }
96
97 static int lov_rd_activeobd(char *page, char **start, off_t off, int count,
98                             int *eof, void *data)
99 {
100         struct obd_device* dev = (struct obd_device*)data;
101         struct lov_desc *desc;
102
103         LASSERT(dev != NULL);
104         desc = &dev->u.lov.desc;
105         *eof = 1;
106         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
107 }
108
109 static int lov_rd_desc_uuid(char *page, char **start, off_t off, int count,
110                             int *eof, void *data)
111 {
112         struct obd_device *dev = (struct obd_device*) data;
113         struct lov_obd *lov;
114
115         LASSERT(dev != NULL);
116         lov = &dev->u.lov;
117         *eof = 1;
118         return snprintf(page, count, "%s\n", lov->desc.ld_uuid.uuid);
119 }
120
121 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
122 {
123         struct obd_device *dev = p->private;
124         struct lov_obd *lov = &dev->u.lov;
125
126         return (*pos >= lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
127
128 }
129
130 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
131 {
132 }
133
134 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
135 {
136         struct obd_device *dev = p->private;
137         struct lov_obd *lov = &dev->u.lov;
138
139         ++*pos;
140         return (*pos >=lov->desc.ld_tgt_count) ? NULL : &(lov->tgts[*pos]);
141 }
142
143 static int lov_tgt_seq_show(struct seq_file *p, void *v)
144 {
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");
151 }
152
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,
158 };
159
160 static int lov_target_seq_open(struct inode *inode, struct file *file)
161 {
162         struct proc_dir_entry *dp = PDE(inode);
163         struct seq_file *seq;
164         int rc = seq_open(file, &lov_tgt_sops);
165
166         if (rc)
167                 return rc;
168
169         seq = file->private_data;
170         seq->private = dp->data;
171
172         return 0;
173 }
174
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 },
191         { 0 }
192 };
193
194 static struct lprocfs_vars lprocfs_module_vars[] = {
195         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
196         { 0 }
197 };
198
199 struct file_operations lov_proc_target_fops = {
200         .owner   = THIS_MODULE,
201         .open    = lov_target_seq_open,
202         .read    = seq_read,
203         .llseek  = seq_lseek,
204         .release = seq_release,
205 };
206
207 LPROCFS_INIT_VARS(lov, lprocfs_module_vars, lprocfs_obd_vars)
208 #endif /* LPROCFS */