Whamcloud - gitweb
LU-2960 lmv: typo fix for output of "lfs mdts"
[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  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_CLASS
38
39 #include <linux/version.h>
40 #include <linux/seq_file.h>
41 #include <asm/statfs.h>
42 #include <lprocfs_status.h>
43 #include <obd_class.h>
44
45 #ifndef LPROCFS
46 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
47 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
48 #else
49 static int lmv_rd_numobd(char *page, char **start, off_t off, int count,
50                          int *eof, void *data)
51 {
52         struct obd_device       *dev = (struct obd_device*)data;
53         struct lmv_desc         *desc;
54
55         LASSERT(dev != NULL);
56         desc = &dev->u.lmv.desc;
57         *eof = 1;
58         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
59
60 }
61
62 static const char *placement_name[] = {
63         [PLACEMENT_CHAR_POLICY] = "CHAR",
64         [PLACEMENT_NID_POLICY]  = "NID",
65         [PLACEMENT_INVAL_POLICY]  = "INVAL"
66 };
67
68 static placement_policy_t placement_name2policy(char *name, int len)
69 {
70         int                     i;
71
72         for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
73                 if (!strncmp(placement_name[i], name, len))
74                         return i;
75         }
76         return PLACEMENT_INVAL_POLICY;
77 }
78
79 static const char *placement_policy2name(placement_policy_t placement)
80 {
81         LASSERT(placement < PLACEMENT_MAX_POLICY);
82         return placement_name[placement];
83 }
84
85 static int lmv_rd_placement(char *page, char **start, off_t off, int count,
86                             int *eof, void *data)
87 {
88         struct obd_device       *dev = (struct obd_device*)data;
89         struct lmv_obd          *lmv;
90
91         LASSERT(dev != NULL);
92         lmv = &dev->u.lmv;
93         *eof = 1;
94         return snprintf(page, count, "%s\n",
95                         placement_policy2name(lmv->lmv_placement));
96
97 }
98
99 #define MAX_POLICY_STRING_SIZE 64
100
101 static int lmv_wr_placement(struct file *file, const char *buffer,
102                             unsigned long count, void *data)
103 {
104         struct obd_device       *dev = (struct obd_device *)data;
105         char                     dummy[MAX_POLICY_STRING_SIZE + 1];
106         int                      len = count;
107         placement_policy_t       policy;
108         struct lmv_obd          *lmv;
109
110         if (cfs_copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
111                 return -EFAULT;
112
113         LASSERT(dev != NULL);
114         lmv = &dev->u.lmv;
115
116         if (len > MAX_POLICY_STRING_SIZE)
117                 len = MAX_POLICY_STRING_SIZE;
118
119         if (dummy[len - 1] == '\n')
120                 len--;
121         dummy[len] = '\0';
122
123         policy = placement_name2policy(dummy, len);
124         if (policy != PLACEMENT_INVAL_POLICY) {
125                 spin_lock(&lmv->lmv_lock);
126                 lmv->lmv_placement = policy;
127                 spin_unlock(&lmv->lmv_lock);
128         } else {
129                 CERROR("Invalid placement policy \"%s\"!\n", dummy);
130                 return -EINVAL;
131         }
132         return count;
133 }
134
135 static int lmv_rd_activeobd(char *page, char **start, off_t off, int count,
136                             int *eof, void *data)
137 {
138         struct obd_device       *dev = (struct obd_device*)data;
139         struct lmv_desc         *desc;
140
141         LASSERT(dev != NULL);
142         desc = &dev->u.lmv.desc;
143         *eof = 1;
144         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
145 }
146
147 static int lmv_rd_desc_uuid(char *page, char **start, off_t off, int count,
148                             int *eof, void *data)
149 {
150         struct obd_device       *dev = (struct obd_device*) data;
151         struct lmv_obd          *lmv;
152
153         LASSERT(dev != NULL);
154         lmv = &dev->u.lmv;
155         *eof = 1;
156         return snprintf(page, count, "%s\n", lmv->desc.ld_uuid.uuid);
157 }
158
159 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
160 {
161         struct obd_device       *dev = p->private;
162         struct lmv_obd          *lmv = &dev->u.lmv;
163         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
164 }
165
166 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
167 {
168         return;
169 }
170
171 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
172 {
173         struct obd_device       *dev = p->private;
174         struct lmv_obd          *lmv = &dev->u.lmv;
175         ++*pos;
176         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
177 }
178
179 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
180 {
181         struct lmv_tgt_desc     *tgt = v;
182
183         if (tgt == NULL)
184                 return 0;
185         return seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_idx,
186                           tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
187 }
188
189 struct seq_operations lmv_tgt_sops = {
190         .start                 = lmv_tgt_seq_start,
191         .stop                  = lmv_tgt_seq_stop,
192         .next                  = lmv_tgt_seq_next,
193         .show                  = lmv_tgt_seq_show,
194 };
195
196 static int lmv_target_seq_open(struct inode *inode, struct file *file)
197 {
198         struct proc_dir_entry   *dp = PDE(inode);
199         struct seq_file         *seq;
200         int                     rc;
201
202         rc = seq_open(file, &lmv_tgt_sops);
203         if (rc)
204                 return rc;
205
206         seq = file->private_data;
207         seq->private = dp->data;
208
209         return 0;
210 }
211
212 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
213         { "numobd",             lmv_rd_numobd,          0, 0 },
214         { "placement",          lmv_rd_placement,       lmv_wr_placement, 0 },
215         { "activeobd",          lmv_rd_activeobd,       0, 0 },
216         { "uuid",               lprocfs_rd_uuid,        0, 0 },
217         { "desc_uuid",          lmv_rd_desc_uuid,       0, 0 },
218         { 0 }
219 };
220
221 static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
222         { "num_refs",           lprocfs_rd_numrefs,     0, 0 },
223         { 0 }
224 };
225
226 struct file_operations lmv_proc_target_fops = {
227         .owner                = THIS_MODULE,
228         .open                 = lmv_target_seq_open,
229         .read                 = seq_read,
230         .llseek               = seq_lseek,
231         .release              = seq_release,
232 };
233
234 #endif /* LPROCFS */
235 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
236 {
237         lvars->module_vars    = lprocfs_lmv_module_vars;
238         lvars->obd_vars       = lprocfs_lmv_obd_vars;
239 }