Whamcloud - gitweb
LU-7334 lov: Cleanup lov_stripe proc files
[fs/lustre-release.git] / lustre / lov / lproc_lov.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) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2015, 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 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <lprocfs_status.h>
41 #include <obd_class.h>
42 #include <lustre_param.h>
43 #include "lov_internal.h"
44
45 #ifdef CONFIG_PROC_FS
46 static int lov_stripesize_seq_show(struct seq_file *m, void *v)
47 {
48         struct obd_device *dev = (struct obd_device *)m->private;
49         struct lov_desc *desc;
50
51         LASSERT(dev != NULL);
52         desc = &dev->u.lov.desc;
53
54         seq_printf(m, LPU64"\n", desc->ld_default_stripe_size);
55         return 0;
56 }
57 LPROC_SEQ_FOPS_RO(lov_stripesize);
58
59 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
60 {
61         struct obd_device *dev = (struct obd_device *)m->private;
62         struct lov_desc *desc;
63
64         LASSERT(dev != NULL);
65         desc = &dev->u.lov.desc;
66         seq_printf(m, LPU64"\n", desc->ld_default_stripe_offset);
67         return 0;
68 }
69 LPROC_SEQ_FOPS_RO(lov_stripeoffset);
70
71 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
72 {
73         struct obd_device* dev = (struct obd_device*)m->private;
74         struct lov_desc *desc;
75
76         LASSERT(dev != NULL);
77         desc = &dev->u.lov.desc;
78         seq_printf(m, "%u\n", desc->ld_pattern);
79         return 0;
80 }
81 LPROC_SEQ_FOPS_RO(lov_stripetype);
82
83 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
84 {
85         struct obd_device *dev = (struct obd_device *)m->private;
86         struct lov_desc *desc;
87
88         LASSERT(dev != NULL);
89         desc = &dev->u.lov.desc;
90         seq_printf(m, "%d\n",
91                   (__s16)(desc->ld_default_stripe_count + 1) - 1);
92         return 0;
93 }
94 LPROC_SEQ_FOPS_RO(lov_stripecount);
95
96 static int lov_numobd_seq_show(struct seq_file *m, void *v)
97 {
98         struct obd_device *dev = (struct obd_device*)m->private;
99         struct lov_desc *desc;
100
101         LASSERT(dev != NULL);
102         desc = &dev->u.lov.desc;
103         seq_printf(m, "%u\n", desc->ld_tgt_count);
104         return 0;
105 }
106 LPROC_SEQ_FOPS_RO(lov_numobd);
107
108 static int lov_activeobd_seq_show(struct seq_file *m, void *v)
109 {
110         struct obd_device* dev = (struct obd_device*)m->private;
111         struct lov_desc *desc;
112
113         LASSERT(dev != NULL);
114         desc = &dev->u.lov.desc;
115         seq_printf(m, "%u\n", desc->ld_active_tgt_count);
116         return 0;
117 }
118 LPROC_SEQ_FOPS_RO(lov_activeobd);
119
120 static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
121 {
122         struct obd_device *dev = m->private;
123         struct lov_obd *lov;
124
125         LASSERT(dev != NULL);
126         lov = &dev->u.lov;
127         seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
128         return 0;
129 }
130 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
131
132 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
133 {
134         struct obd_device *dev = p->private;
135         struct lov_obd *lov = &dev->u.lov;
136
137         while (*pos < lov->desc.ld_tgt_count) {
138                 if (lov->lov_tgts[*pos])
139                         return lov->lov_tgts[*pos];
140                 ++*pos;
141         }
142         return NULL;
143 }
144
145 static void lov_tgt_seq_stop(struct seq_file *p, void *v)
146 {
147 }
148
149 static void *lov_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
150 {
151         struct obd_device *dev = p->private;
152         struct lov_obd *lov = &dev->u.lov;
153
154         while (++*pos < lov->desc.ld_tgt_count) {
155                 if (lov->lov_tgts[*pos])
156                         return lov->lov_tgts[*pos];
157         }
158         return NULL;
159 }
160
161 static int lov_tgt_seq_show(struct seq_file *p, void *v)
162 {
163         struct lov_tgt_desc *tgt = v;
164         seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index,
165                    obd_uuid2str(&tgt->ltd_uuid),
166                    tgt->ltd_active ? "" : "IN");
167         return 0;
168 }
169
170 static const struct seq_operations lov_tgt_sops = {
171         .start = lov_tgt_seq_start,
172         .stop = lov_tgt_seq_stop,
173         .next = lov_tgt_seq_next,
174         .show = lov_tgt_seq_show,
175 };
176
177 static int lov_target_seq_open(struct inode *inode, struct file *file)
178 {
179         struct seq_file *seq;
180         int rc;
181
182         rc = LPROCFS_ENTRY_CHECK(inode);
183         if (rc < 0)
184                 return rc;
185
186         rc = seq_open(file, &lov_tgt_sops);
187         if (rc)
188                 return rc;
189
190         seq = file->private_data;
191         seq->private = PDE_DATA(inode);
192         return 0;
193 }
194
195 LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
196 LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
197 LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
198 LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
199 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
200 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
201 LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
202
203 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
204         { .name =       "uuid",
205           .fops =       &lov_uuid_fops          },
206         { .name =       "stripesize",
207           .fops =       &lov_stripesize_fops    },
208         { .name =       "stripeoffset",
209           .fops =       &lov_stripeoffset_fops  },
210         { .name =       "stripecount",
211           .fops =       &lov_stripecount_fops   },
212         { .name =       "stripetype",
213           .fops =       &lov_stripetype_fops    },
214         { .name =       "numobd",
215           .fops =       &lov_numobd_fops        },
216         { .name =       "activeobd",
217           .fops =       &lov_activeobd_fops     },
218         { .name =       "filestotal",
219           .fops =       &lov_filestotal_fops    },
220         { .name =       "filesfree",
221           .fops =       &lov_filesfree_fops     },
222         { .name =       "blocksize",
223           .fops =       &lov_blksize_fops       },
224         { .name =       "kbytestotal",
225           .fops =       &lov_kbytestotal_fops   },
226         { .name =       "kbytesfree",
227           .fops =       &lov_kbytesfree_fops    },
228         { .name =       "kbytesavail",
229           .fops =       &lov_kbytesavail_fops   },
230         { .name =       "desc_uuid",
231           .fops =       &lov_desc_uuid_fops     },
232         { NULL }
233 };
234
235 struct file_operations lov_proc_target_fops = {
236         .owner   = THIS_MODULE,
237         .open    = lov_target_seq_open,
238         .read    = seq_read,
239         .llseek  = seq_lseek,
240         .release = lprocfs_seq_release,
241 };
242 #endif /* CONFIG_PROC_FS */