Whamcloud - gitweb
Merge b_md into HEAD
[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/lustre_lite.h>
25 #include <linux/lprocfs_status.h>
26
27 /* /proc/lustre/llite mount point registration */
28
29 #ifndef LPROCFS
30 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
31                                 struct super_block *sb, char *osc, char *mdc)
32 {
33         return 0;
34 }
35 #else
36
37 long long mnt_instance;
38
39 static inline int lprocfs_llite_statfs(void *data, struct statfs *sfs)
40 {
41         struct super_block *sb = (struct super_block*)data;
42         return (sb->s_op->statfs)(sb, sfs);
43 }
44
45 DEFINE_LPROCFS_STATFS_FCT(rd_blksize,     lprocfs_llite_statfs);
46 DEFINE_LPROCFS_STATFS_FCT(rd_kbytestotal, lprocfs_llite_statfs);
47 DEFINE_LPROCFS_STATFS_FCT(rd_kbytesfree,  lprocfs_llite_statfs);
48 DEFINE_LPROCFS_STATFS_FCT(rd_filestotal,  lprocfs_llite_statfs);
49 DEFINE_LPROCFS_STATFS_FCT(rd_filesfree,   lprocfs_llite_statfs);
50 DEFINE_LPROCFS_STATFS_FCT(rd_filegroups,  lprocfs_llite_statfs);
51
52 int rd_path(char *page, char **start, off_t off, int count, int *eof,
53             void *data)
54 {
55         return 0;
56 }
57
58 int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
59               void *data)
60 {
61         struct super_block *sb = (struct super_block*)data;
62
63         *eof = 1;
64         return snprintf(page, count, "%s\n", sb->s_type->name);
65 }
66
67 int rd_sb_uuid(char *page, char **start, off_t off, int count, int *eof,
68                void *data)
69 {
70         struct super_block *sb = (struct super_block *)data;
71
72         *eof = 1;
73         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
74 }
75
76 struct lprocfs_vars lprocfs_obd_vars[] = {
77         { "uuid",        rd_sb_uuid,     0, 0 },
78         { "mntpt_path",  rd_path,        0, 0 },
79         { "fstype",      rd_fstype,      0, 0 },
80         { "blocksize",   rd_blksize,     0, 0 },
81         { "kbytestotal", rd_kbytestotal, 0, 0 },
82         { "kbytesfree",  rd_kbytesfree,  0, 0 },
83         { "filestotal",  rd_filestotal,  0, 0 },
84         { "filesfree",   rd_filesfree,   0, 0 },
85         { "filegroups",  rd_filegroups,  0, 0 },
86         { 0 }
87 };
88
89 #define MAX_STRING_SIZE 128
90 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
91                                 struct super_block *sb, char *osc, char *mdc)
92 {
93         struct lprocfs_vars lvars[2];
94         struct ll_sb_info *sbi = ll_s2sbi(sb);
95         struct obd_device *obd;
96         char name[MAX_STRING_SIZE + 1];
97         struct obd_uuid uuid;
98         int err;
99         ENTRY;
100
101         memset(lvars, 0, sizeof(lvars));
102
103         name[MAX_STRING_SIZE] = '\0';
104         lvars[0].name = name;
105
106         /* Mount info */
107         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
108
109         mnt_instance++;
110         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
111         if (IS_ERR(sbi->ll_proc_root))
112                 RETURN(err = PTR_ERR(sbi->ll_proc_root));
113
114         /* Static configuration info */
115         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
116         if (err)
117                 RETURN(err);
118
119         /* MDC info */
120         strncpy(uuid.uuid, mdc, sizeof(uuid.uuid));
121         obd = class_uuid2obd(&uuid);
122         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
123                  obd->obd_type->typ_name);
124         lvars[0].read_fptr = lprocfs_rd_name;
125         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
126         if (err)
127                 RETURN(err);
128
129         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
130         lvars[0].read_fptr = lprocfs_rd_uuid;
131         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
132         if (err < 0)
133                 RETURN(err);
134
135         /* OSC */
136         strncpy(uuid.uuid, osc, sizeof(uuid.uuid));
137         obd = class_uuid2obd(&uuid);
138
139         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
140                  obd->obd_type->typ_name);
141         lvars[0].read_fptr = lprocfs_rd_name;
142         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
143         if (err)
144                 RETURN(err);
145
146         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
147         lvars[0].read_fptr = lprocfs_rd_uuid;
148         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
149
150         RETURN(err);
151 }
152
153 #undef MAX_STRING_SIZE
154 #endif /* LPROCFS */