Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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         char name[MAX_STRING_SIZE + 1];
110         struct obd_uuid uuid;
111         int err;
112         ENTRY;
113
114         memset(lvars, 0, sizeof(lvars));
115
116         name[MAX_STRING_SIZE] = '\0';
117         lvars[0].name = name;
118
119         LASSERT(sbi != NULL);
120         LASSERT(mdc != NULL);
121         LASSERT(osc != NULL);
122
123         /* Mount info */
124         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
125
126         mnt_instance++;
127         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
128         if (IS_ERR(sbi->ll_proc_root)) {
129                 err = PTR_ERR(sbi->ll_proc_root);
130                 sbi->ll_proc_root = NULL;
131                 RETURN(err);
132         }
133         /* Static configuration info */
134         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
135         if (err)
136                 RETURN(err);
137
138         /* MDC info */
139         strncpy(uuid.uuid, mdc, sizeof(uuid.uuid));
140         obd = class_uuid2obd(&uuid);
141
142         LASSERT(obd != NULL);
143         LASSERT(obd->obd_type != NULL);
144         LASSERT(obd->obd_type->typ_name != NULL);
145
146         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
147                  obd->obd_type->typ_name);
148         lvars[0].read_fptr = lprocfs_rd_name;
149         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
150         if (err)
151                 RETURN(err);
152
153         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
154         lvars[0].read_fptr = lprocfs_rd_uuid;
155         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
156         if (err < 0)
157                 RETURN(err);
158
159         /* OSC */
160         strncpy(uuid.uuid, osc, sizeof(uuid.uuid));
161         obd = class_uuid2obd(&uuid);
162
163         LASSERT(obd != NULL);
164         LASSERT(obd->obd_type != NULL);
165         LASSERT(obd->obd_type->typ_name != NULL);
166
167         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
168                  obd->obd_type->typ_name);
169         lvars[0].read_fptr = lprocfs_rd_name;
170         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
171         if (err)
172                 RETURN(err);
173
174         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
175         lvars[0].read_fptr = lprocfs_rd_uuid;
176         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
177
178         RETURN(err);
179 }
180
181 #undef MAX_STRING_SIZE
182 #endif /* LPROCFS */