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