Whamcloud - gitweb
LU-1187 tests: Add DNE test cases in sanity.
[fs/lustre-release.git] / lustre / lmv / lproc_lmv.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #define DEBUG_SUBSYSTEM S_CLASS
36
37 #include <linux/version.h>
38 #include <linux/seq_file.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42
43 #ifndef LPROCFS
44 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
45 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
46 #else
47 static int lmv_rd_numobd(char *page, char **start, off_t off, int count,
48                          int *eof, void *data)
49 {
50         struct obd_device       *dev = (struct obd_device*)data;
51         struct lmv_desc         *desc;
52
53         LASSERT(dev != NULL);
54         desc = &dev->u.lmv.desc;
55         *eof = 1;
56         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
57
58 }
59
60 static const char *placement_name[] = {
61         [PLACEMENT_CHAR_POLICY] = "CHAR",
62         [PLACEMENT_NID_POLICY]  = "NID"
63 };
64
65 static placement_policy_t placement_name2policy(char *name, int len)
66 {
67         int                     i;
68
69         for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
70                 if (!strncmp(placement_name[i], name, len))
71                         return i;
72         }
73         return PLACEMENT_INVAL_POLICY;
74 }
75
76 static const char *placement_policy2name(placement_policy_t placement)
77 {
78         LASSERT(placement < PLACEMENT_MAX_POLICY);
79         return placement_name[placement];
80 }
81
82 static int lmv_rd_placement(char *page, char **start, off_t off, int count,
83                             int *eof, void *data)
84 {
85         struct obd_device       *dev = (struct obd_device*)data;
86         struct lmv_obd          *lmv;
87
88         LASSERT(dev != NULL);
89         lmv = &dev->u.lmv;
90         *eof = 1;
91         return snprintf(page, count, "%s\n",
92                         placement_policy2name(lmv->lmv_placement));
93
94 }
95
96 #define MAX_POLICY_STRING_SIZE 64
97
98 static int lmv_wr_placement(struct file *file, const char *buffer,
99                             unsigned long count, void *data)
100 {
101         struct obd_device       *dev = (struct obd_device *)data;
102         char                     dummy[MAX_POLICY_STRING_SIZE + 1];
103         int                      len = count;
104         placement_policy_t       policy;
105         struct lmv_obd          *lmv;
106
107         if (cfs_copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
108                 return -EFAULT;
109
110         LASSERT(dev != NULL);
111         lmv = &dev->u.lmv;
112
113         if (len > MAX_POLICY_STRING_SIZE)
114                 len = MAX_POLICY_STRING_SIZE;
115
116         if (dummy[len - 1] == '\n')
117                 len--;
118         dummy[len] = '\0';
119
120         policy = placement_name2policy(dummy, len);
121         if (policy != PLACEMENT_INVAL_POLICY) {
122                 spin_lock(&lmv->lmv_lock);
123                 lmv->lmv_placement = policy;
124                 spin_unlock(&lmv->lmv_lock);
125         } else {
126                 CERROR("Invalid placement policy \"%s\"!\n", dummy);
127                 return -EINVAL;
128         }
129         return count;
130 }
131
132 static int lmv_rd_activeobd(char *page, char **start, off_t off, int count,
133                             int *eof, void *data)
134 {
135         struct obd_device       *dev = (struct obd_device*)data;
136         struct lmv_desc         *desc;
137
138         LASSERT(dev != NULL);
139         desc = &dev->u.lmv.desc;
140         *eof = 1;
141         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
142 }
143
144 static int lmv_rd_desc_uuid(char *page, char **start, off_t off, int count,
145                             int *eof, void *data)
146 {
147         struct obd_device       *dev = (struct obd_device*) data;
148         struct lmv_obd          *lmv;
149
150         LASSERT(dev != NULL);
151         lmv = &dev->u.lmv;
152         *eof = 1;
153         return snprintf(page, count, "%s\n", lmv->desc.ld_uuid.uuid);
154 }
155
156 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
157 {
158         struct obd_device       *dev = p->private;
159         struct lmv_obd          *lmv = &dev->u.lmv;
160         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
161
162 }
163
164 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
165 {
166         return;
167 }
168
169 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
170 {
171         struct obd_device       *dev = p->private;
172         struct lmv_obd          *lmv = &dev->u.lmv;
173         ++*pos;
174         return (*pos >=lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
175 }
176
177 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
178 {
179         struct lmv_tgt_desc     *tgt = v;
180         struct obd_device       *dev = p->private;
181         struct lmv_obd          *lmv = &dev->u.lmv;
182         int                      idx = tgt - &(lmv->tgts[0]);
183
184         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->ltd_uuid.uuid,
185                           tgt->ltd_active ? "" : "IN");
186 }
187
188 struct seq_operations lmv_tgt_sops = {
189         .start                 = lmv_tgt_seq_start,
190         .stop                  = lmv_tgt_seq_stop,
191         .next                  = lmv_tgt_seq_next,
192         .show                  = lmv_tgt_seq_show,
193 };
194
195 static int lmv_target_seq_open(struct inode *inode, struct file *file)
196 {
197         struct proc_dir_entry   *dp = PDE(inode);
198         struct seq_file         *seq;
199         int                     rc;
200
201         rc = seq_open(file, &lmv_tgt_sops);
202         if (rc)
203                 return rc;
204
205         seq = file->private_data;
206         seq->private = dp->data;
207
208         return 0;
209 }
210
211 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
212         { "numobd",             lmv_rd_numobd,          0, 0 },
213         { "placement",          lmv_rd_placement,       lmv_wr_placement, 0 },
214         { "activeobd",          lmv_rd_activeobd,       0, 0 },
215         { "uuid",               lprocfs_rd_uuid,        0, 0 },
216         { "desc_uuid",          lmv_rd_desc_uuid,       0, 0 },
217         { 0 }
218 };
219
220 static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
221         { "num_refs",           lprocfs_rd_numrefs,     0, 0 },
222         { 0 }
223 };
224
225 struct file_operations lmv_proc_target_fops = {
226         .owner                = THIS_MODULE,
227         .open                 = lmv_target_seq_open,
228         .read                 = seq_read,
229         .llseek               = seq_lseek,
230         .release              = seq_release,
231 };
232
233 #endif /* LPROCFS */
234 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
235 {
236         lvars->module_vars    = lprocfs_lmv_module_vars;
237         lvars->obd_vars       = lprocfs_lmv_obd_vars;
238 }