1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#define DEBUG_SUBSYSTEM S_CLASS
38
39#include <linux/seq_file.h>
40#include <linux/statfs.h>
41#include "../include/lprocfs_status.h"
42#include "../include/obd_class.h"
43#include "lmv_internal.h"
44
45static int lmv_numobd_seq_show(struct seq_file *m, void *v)
46{
47 struct obd_device *dev = (struct obd_device *)m->private;
48 struct lmv_desc *desc;
49
50 LASSERT(dev != NULL);
51 desc = &dev->u.lmv.desc;
52 seq_printf(m, "%u\n", desc->ld_tgt_count);
53 return 0;
54}
55LPROC_SEQ_FOPS_RO(lmv_numobd);
56
57static const char *placement_name[] = {
58 [PLACEMENT_CHAR_POLICY] = "CHAR",
59 [PLACEMENT_NID_POLICY] = "NID",
60 [PLACEMENT_INVAL_POLICY] = "INVAL"
61};
62
63static enum placement_policy placement_name2policy(char *name, int len)
64{
65 int i;
66
67 for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
68 if (!strncmp(placement_name[i], name, len))
69 return i;
70 }
71 return PLACEMENT_INVAL_POLICY;
72}
73
74static const char *placement_policy2name(enum placement_policy placement)
75{
76 LASSERT(placement < PLACEMENT_MAX_POLICY);
77 return placement_name[placement];
78}
79
80static int lmv_placement_seq_show(struct seq_file *m, void *v)
81{
82 struct obd_device *dev = (struct obd_device *)m->private;
83 struct lmv_obd *lmv;
84
85 LASSERT(dev != NULL);
86 lmv = &dev->u.lmv;
87 seq_printf(m, "%s\n", placement_policy2name(lmv->lmv_placement));
88 return 0;
89}
90
91#define MAX_POLICY_STRING_SIZE 64
92
93static ssize_t lmv_placement_seq_write(struct file *file,
94 const char __user *buffer,
95 size_t count, loff_t *off)
96{
97 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
98 char dummy[MAX_POLICY_STRING_SIZE + 1];
99 int len = count;
100 enum placement_policy policy;
101 struct lmv_obd *lmv;
102
103 if (copy_from_user(dummy, buffer, MAX_POLICY_STRING_SIZE))
104 return -EFAULT;
105
106 LASSERT(dev != NULL);
107 lmv = &dev->u.lmv;
108
109 if (len > MAX_POLICY_STRING_SIZE)
110 len = MAX_POLICY_STRING_SIZE;
111
112 if (dummy[len - 1] == '\n')
113 len--;
114 dummy[len] = '\0';
115
116 policy = placement_name2policy(dummy, len);
117 if (policy != PLACEMENT_INVAL_POLICY) {
118 spin_lock(&lmv->lmv_lock);
119 lmv->lmv_placement = policy;
120 spin_unlock(&lmv->lmv_lock);
121 } else {
122 CERROR("Invalid placement policy \"%s\"!\n", dummy);
123 return -EINVAL;
124 }
125 return count;
126}
127LPROC_SEQ_FOPS(lmv_placement);
128
129static int lmv_activeobd_seq_show(struct seq_file *m, void *v)
130{
131 struct obd_device *dev = (struct obd_device *)m->private;
132 struct lmv_desc *desc;
133
134 LASSERT(dev != NULL);
135 desc = &dev->u.lmv.desc;
136 seq_printf(m, "%u\n", desc->ld_active_tgt_count);
137 return 0;
138}
139LPROC_SEQ_FOPS_RO(lmv_activeobd);
140
141static 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 seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
149 return 0;
150}
151LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
152
153static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
154{
155 struct obd_device *dev = p->private;
156 struct lmv_obd *lmv = &dev->u.lmv;
157 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
158}
159
160static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
161{
162 return;
163}
164
165static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
166{
167 struct obd_device *dev = p->private;
168 struct lmv_obd *lmv = &dev->u.lmv;
169 ++*pos;
170 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
171}
172
173static int lmv_tgt_seq_show(struct seq_file *p, void *v)
174{
175 struct lmv_tgt_desc *tgt = v;
176
177 if (tgt == NULL)
178 return 0;
179 seq_printf(p, "%d: %s %sACTIVE\n",
180 tgt->ltd_idx, tgt->ltd_uuid.uuid,
181 tgt->ltd_active ? "" : "IN");
182 return 0;
183}
184
185static struct seq_operations lmv_tgt_sops = {
186 .start = lmv_tgt_seq_start,
187 .stop = lmv_tgt_seq_stop,
188 .next = lmv_tgt_seq_next,
189 .show = lmv_tgt_seq_show,
190};
191
192static int lmv_target_seq_open(struct inode *inode, struct file *file)
193{
194 struct seq_file *seq;
195 int rc;
196
197 rc = seq_open(file, &lmv_tgt_sops);
198 if (rc)
199 return rc;
200
201 seq = file->private_data;
202 seq->private = PDE_DATA(inode);
203
204 return 0;
205}
206
207LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
208
209static struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
210 { "numobd", &lmv_numobd_fops, NULL, 0 },
211 { "placement", &lmv_placement_fops, NULL, 0 },
212 { "activeobd", &lmv_activeobd_fops, NULL, 0 },
213 { "uuid", &lmv_uuid_fops, NULL, 0 },
214 { "desc_uuid", &lmv_desc_uuid_fops, NULL, 0 },
215 { NULL }
216};
217
218LPROC_SEQ_FOPS_RO_TYPE(lmv, numrefs);
219
220static struct lprocfs_vars lprocfs_lmv_module_vars[] = {
221 { "num_refs", &lmv_numrefs_fops, NULL, 0 },
222 { NULL }
223};
224
225struct 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
233void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
234{
235 lvars->module_vars = lprocfs_lmv_module_vars;
236 lvars->obd_vars = lprocfs_lmv_obd_vars;
237}
238