Whamcloud - gitweb
LU-7931 tests: setup/cleanup after every test script
[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, 2014, 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 #include "lmv_internal.h"
46
47 #ifndef CONFIG_PROC_FS
48 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
49 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
50 #else
51 static int lmv_numobd_seq_show(struct seq_file *m, void *v)
52 {
53         struct obd_device       *dev = (struct obd_device *)m->private;
54         struct lmv_desc         *desc;
55
56         LASSERT(dev != NULL);
57         desc = &dev->u.lmv.desc;
58         seq_printf(m, "%u\n", desc->ld_tgt_count);
59         return 0;
60 }
61 LPROC_SEQ_FOPS_RO(lmv_numobd);
62
63 static const char *placement_name[] = {
64         [PLACEMENT_CHAR_POLICY] = "CHAR",
65         [PLACEMENT_NID_POLICY]  = "NID",
66         [PLACEMENT_INVAL_POLICY]  = "INVAL"
67 };
68
69 static placement_policy_t placement_name2policy(char *name, int len)
70 {
71         int                     i;
72
73         for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
74                 if (!strncmp(placement_name[i], name, len))
75                         return i;
76         }
77         return PLACEMENT_INVAL_POLICY;
78 }
79
80 static const char *placement_policy2name(placement_policy_t placement)
81 {
82         LASSERT(placement < PLACEMENT_MAX_POLICY);
83         return placement_name[placement];
84 }
85
86 static int lmv_placement_seq_show(struct seq_file *m, void *v)
87 {
88         struct obd_device       *dev = (struct obd_device *)m->private;
89         struct lmv_obd          *lmv;
90
91         LASSERT(dev != NULL);
92         lmv = &dev->u.lmv;
93         seq_printf(m, "%s\n", placement_policy2name(lmv->lmv_placement));
94         return 0;
95 }
96
97 #define MAX_POLICY_STRING_SIZE 64
98
99 static ssize_t lmv_placement_seq_write(struct file *file,
100                                        const char __user *buffer,
101                                        size_t count, loff_t *off)
102 {
103         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
104         char                     dummy[MAX_POLICY_STRING_SIZE + 1];
105         int                      len = count;
106         placement_policy_t       policy;
107         struct lmv_obd          *lmv;
108
109         if (copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
110                 return -EFAULT;
111
112         LASSERT(dev != NULL);
113         lmv = &dev->u.lmv;
114
115         if (len > MAX_POLICY_STRING_SIZE)
116                 len = MAX_POLICY_STRING_SIZE;
117
118         if (dummy[len - 1] == '\n')
119                 len--;
120         dummy[len] = '\0';
121
122         policy = placement_name2policy(dummy, len);
123         if (policy != PLACEMENT_INVAL_POLICY) {
124                 spin_lock(&lmv->lmv_lock);
125                 lmv->lmv_placement = policy;
126                 spin_unlock(&lmv->lmv_lock);
127         } else {
128                 CERROR("Invalid placement policy \"%s\"!\n", dummy);
129                 return -EINVAL;
130         }
131         return count;
132 }
133 LPROC_SEQ_FOPS(lmv_placement);
134
135 static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
136 {
137         struct obd_device       *dev = (struct obd_device *)m->private;
138         struct lmv_desc         *desc;
139
140         LASSERT(dev != NULL);
141         desc = &dev->u.lmv.desc;
142         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
143         return 0;
144 }
145 LPROC_SEQ_FOPS_RO(lmv_activeobd);
146
147 static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
148 {
149         struct obd_device       *dev = (struct obd_device*)m->private;
150         struct lmv_obd          *lmv;
151
152         LASSERT(dev != NULL);
153         lmv = &dev->u.lmv;
154         seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
155         return 0;
156 }
157 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
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
164         while (*pos < lmv->tgts_size) {
165                 if (lmv->tgts[*pos] != NULL)
166                         return lmv->tgts[*pos];
167
168                 ++*pos;
169         }
170
171         return  NULL;
172 }
173
174 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
175 {
176         return;
177 }
178
179 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
180 {
181         struct obd_device       *dev = p->private;
182         struct lmv_obd          *lmv = &dev->u.lmv;
183
184         ++*pos;
185         while (*pos < lmv->tgts_size) {
186                 if (lmv->tgts[*pos] != NULL)
187                         return lmv->tgts[*pos];
188
189                 ++*pos;
190         }
191
192         return  NULL;
193 }
194
195 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
196 {
197         struct lmv_tgt_desc     *tgt = v;
198
199         if (tgt == NULL)
200                 return 0;
201         seq_printf(p, "%u: %s %sACTIVE\n", tgt->ltd_idx,
202                   tgt->ltd_uuid.uuid, tgt->ltd_active ? "" : "IN");
203         return 0;
204 }
205
206 static const struct seq_operations lmv_tgt_sops = {
207         .start                 = lmv_tgt_seq_start,
208         .stop                  = lmv_tgt_seq_stop,
209         .next                  = lmv_tgt_seq_next,
210         .show                  = lmv_tgt_seq_show,
211 };
212
213 static int lmv_target_seq_open(struct inode *inode, struct file *file)
214 {
215         struct seq_file         *seq;
216         int                     rc;
217
218         rc = seq_open(file, &lmv_tgt_sops);
219         if (rc)
220                 return rc;
221
222         seq = file->private_data;
223         seq->private = PDE_DATA(inode);
224         return 0;
225 }
226
227 LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
228
229 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
230         { .name =       "numobd",
231           .fops =       &lmv_numobd_fops        },
232         { .name =       "placement",
233           .fops =       &lmv_placement_fops     },
234         { .name =       "activeobd",
235           .fops =       &lmv_activeobd_fops     },
236         { .name =       "uuid",
237           .fops =       &lmv_uuid_fops          },
238         { .name =       "desc_uuid",
239           .fops =       &lmv_desc_uuid_fops     },
240         { NULL }
241 };
242
243 struct file_operations lmv_proc_target_fops = {
244         .owner                = THIS_MODULE,
245         .open                 = lmv_target_seq_open,
246         .read                 = seq_read,
247         .llseek               = seq_lseek,
248         .release              = seq_release,
249 };
250 #endif /* CONFIG_PROC_FS */