Whamcloud - gitweb
59cec1fc84f88784fe3685aac6efb1dc52809d23
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 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_LLITE
23
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/lustre_lite.h>
29 #include <linux/lprocfs_status.h>
30
31 /* /proc/lustre/llite mount point registration */
32
33 #ifndef LPROCFS
34 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
35                                 struct super_block *sb, char *osc, char *mdc)
36 {
37         return 0;
38 }
39 #else
40
41 #define LPROC_LLITE_STAT_FCT(fct_name, get_statfs_fct)                    \
42 int fct_name(char *page, char **start, off_t off,                         \
43              int count, int *eof, void *data)                             \
44 {                                                                         \
45         struct statfs sfs;                                                \
46         int rc;                                                           \
47         LASSERT(data != NULL);                                            \
48         rc = get_statfs_fct((struct super_block*)data, &sfs);             \
49         return (rc==0                                                     \
50                 ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
51                 : rc);                                                    \
52 }
53
54 long long mnt_instance;
55
56 LPROC_LLITE_STAT_FCT(rd_blksize,     vfs_statfs);
57 LPROC_LLITE_STAT_FCT(rd_kbytestotal, vfs_statfs);
58 LPROC_LLITE_STAT_FCT(rd_kbytesfree,  vfs_statfs);
59 LPROC_LLITE_STAT_FCT(rd_filestotal,  vfs_statfs);
60 LPROC_LLITE_STAT_FCT(rd_filesfree,   vfs_statfs);
61 LPROC_LLITE_STAT_FCT(rd_filegroups,  vfs_statfs);
62
63 int rd_path(char *page, char **start, off_t off, int count, int *eof,
64             void *data)
65 {
66         return 0;
67 }
68
69 int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
70               void *data)
71 {
72         struct super_block *sb = (struct super_block*)data;
73
74         LASSERT(sb != NULL);
75         *eof = 1;
76         return snprintf(page, count, "%s\n", sb->s_type->name);
77 }
78
79 int rd_sb_uuid(char *page, char **start, off_t off, int count, int *eof,
80                void *data)
81 {
82         struct super_block *sb = (struct super_block *)data;
83
84         LASSERT(sb != NULL);
85         *eof = 1;
86         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
87 }
88
89 struct lprocfs_vars lprocfs_obd_vars[] = {
90         { "uuid",        rd_sb_uuid,     0, 0 },
91         { "mntpt_path",  rd_path,        0, 0 },
92         { "fstype",      rd_fstype,      0, 0 },
93         { "blocksize",   rd_blksize,     0, 0 },
94         { "kbytestotal", rd_kbytestotal, 0, 0 },
95         { "kbytesfree",  rd_kbytesfree,  0, 0 },
96         { "filestotal",  rd_filestotal,  0, 0 },
97         { "filesfree",   rd_filesfree,   0, 0 },
98         { "filegroups",  rd_filegroups,  0, 0 },
99         { 0 }
100 };
101
102 #define MAX_STRING_SIZE 128
103 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
104                                 struct super_block *sb, char *osc, char *mdc)
105 {
106         struct lprocfs_vars lvars[2];
107         struct ll_sb_info *sbi = ll_s2sbi(sb);
108         struct obd_device *obd;
109         struct proc_dir_entry *entry;
110         char name[MAX_STRING_SIZE + 1];
111         struct obd_uuid uuid;
112         int err;
113         ENTRY;
114
115         memset(lvars, 0, sizeof(lvars));
116
117         name[MAX_STRING_SIZE] = '\0';
118         lvars[0].name = name;
119
120         LASSERT(sbi != NULL);
121         LASSERT(mdc != NULL);
122         LASSERT(osc != NULL);
123
124         /* Mount info */
125         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
126
127         mnt_instance++;
128         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
129         if (IS_ERR(sbi->ll_proc_root)) {
130                 err = PTR_ERR(sbi->ll_proc_root);
131                 sbi->ll_proc_root = NULL;
132                 RETURN(err);
133         }
134         /* Static configuration info */
135         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
136         if (err)
137                 RETURN(err);
138
139         /* llite page cache stats */
140         entry = create_proc_entry("pgcache", 0444, sbi->ll_proc_root);
141         if (entry == NULL)
142                 RETURN(-ENOMEM);
143         entry->proc_fops = &ll_pgcache_seq_fops;
144         entry->data = sbi;
145
146         /* MDC info */
147         strncpy(uuid.uuid, mdc, sizeof(uuid.uuid));
148         obd = class_uuid2obd(&uuid);
149
150         LASSERT(obd != NULL);
151         LASSERT(obd->obd_type != NULL);
152         LASSERT(obd->obd_type->typ_name != NULL);
153
154         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
155                  obd->obd_type->typ_name);
156         lvars[0].read_fptr = lprocfs_rd_name;
157         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
158         if (err)
159                 RETURN(err);
160
161         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
162         lvars[0].read_fptr = lprocfs_rd_uuid;
163         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
164         if (err < 0)
165                 RETURN(err);
166
167         /* OSC */
168         strncpy(uuid.uuid, osc, sizeof(uuid.uuid));
169         obd = class_uuid2obd(&uuid);
170
171         LASSERT(obd != NULL);
172         LASSERT(obd->obd_type != NULL);
173         LASSERT(obd->obd_type->typ_name != NULL);
174
175         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
176                  obd->obd_type->typ_name);
177         lvars[0].read_fptr = lprocfs_rd_name;
178         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
179         if (err)
180                 RETURN(err);
181
182         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
183         lvars[0].read_fptr = lprocfs_rd_uuid;
184         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
185
186         RETURN(err);
187 }
188
189 #undef MAX_STRING_SIZE
190 #endif /* LPROCFS */