Whamcloud - gitweb
0b33aa0afea8226f4822834dc0c5ef79fd290753
[fs/lustre-release.git] / lustre / lmv / lproc_lmv.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #include <linux/seq_file.h>
26 #include <asm/statfs.h>
27 #include <lprocfs_status.h>
28 #include <obd_class.h>
29
30 #ifndef LPROCFS
31 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
32 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
33 #else
34 static int lmv_rd_numobd(char *page, char **start, off_t off, int count,
35                          int *eof, void *data)
36 {
37         struct obd_device *dev = (struct obd_device*)data;
38         struct lmv_desc *desc;
39
40         LASSERT(dev != NULL);
41         desc = &dev->u.lmv.desc;
42         *eof = 1;
43         return snprintf(page, count, "%u\n", desc->ld_tgt_count);
44
45 }
46
47 static int lmv_rd_activeobd(char *page, char **start, off_t off, int count,
48                             int *eof, void *data)
49 {
50         struct obd_device* dev = (struct obd_device*)data;
51         struct lmv_desc *desc;
52
53         LASSERT(dev != NULL);
54         desc = &dev->u.lmv.desc;
55         *eof = 1;
56         return snprintf(page, count, "%u\n", desc->ld_active_tgt_count);
57 }
58
59 static int lmv_rd_desc_uuid(char *page, char **start, off_t off, int count,
60                             int *eof, void *data)
61 {
62         struct obd_device *dev = (struct obd_device*) data;
63         struct lmv_obd *lmv;
64
65         LASSERT(dev != NULL);
66         lmv = &dev->u.lmv;
67         *eof = 1;
68         return snprintf(page, count, "%s\n", lmv->desc.ld_uuid.uuid);
69 }
70
71 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
72 {
73         struct obd_device *dev = p->private;
74         struct lmv_obd *lmv = &dev->u.lmv;
75
76         return (*pos >= lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
77
78 }
79
80 static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
81 {
82         return;
83 }
84
85 static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
86 {
87         struct obd_device *dev = p->private;
88         struct lmv_obd *lmv = &dev->u.lmv;
89
90         ++*pos;
91         return (*pos >=lmv->desc.ld_tgt_count) ? NULL : &(lmv->tgts[*pos]);
92 }
93
94 static int lmv_tgt_seq_show(struct seq_file *p, void *v)
95 {
96         struct lmv_tgt_desc *tgt = v;
97         struct obd_device *dev = p->private;
98         struct lmv_obd *lmv = &dev->u.lmv;
99         int idx = tgt - &(lmv->tgts[0]);
100         
101         return seq_printf(p, "%d: %s %sACTIVE\n", idx, tgt->ltd_uuid.uuid,
102                           tgt->ltd_active ? "" : "IN");
103 }
104
105 struct seq_operations lmv_tgt_sops = {
106         .start = lmv_tgt_seq_start,
107         .stop = lmv_tgt_seq_stop,
108         .next = lmv_tgt_seq_next,
109         .show = lmv_tgt_seq_show,
110 };
111
112 static int lmv_target_seq_open(struct inode *inode, struct file *file)
113 {
114         struct proc_dir_entry *dp = PDE(inode);
115         struct seq_file *seq;
116         int rc = seq_open(file, &lmv_tgt_sops);
117
118         if (rc)
119                 return rc;
120
121         seq = file->private_data;
122         seq->private = dp->data;
123
124         return 0;
125 }
126
127 struct lprocfs_vars lprocfs_obd_vars[] = {
128         { "numobd",       lmv_rd_numobd,          0, 0 },
129         { "activeobd",    lmv_rd_activeobd,       0, 0 },
130         { "uuid",         lprocfs_rd_uuid,        0, 0 },
131         { "desc_uuid",    lmv_rd_desc_uuid,       0, 0 },
132         { 0 }
133 };
134
135 static struct lprocfs_vars lprocfs_module_vars[] = {
136         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
137         { 0 }
138 };
139
140 struct file_operations lmv_proc_target_fops = {
141         .owner   = THIS_MODULE,
142         .open    = lmv_target_seq_open,
143         .read    = seq_read,
144         .llseek  = seq_lseek,
145         .release = seq_release,
146 };
147
148 #endif /* LPROCFS */
149 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)