1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/version.h>
27 #include <linux/proc_fs.h>
28 #include <linux/slab.h>
29 #include <linux/types.h>
31 #define DEBUG_SUBSYSTEM S_CLASS
32 #define MAX_STRING_SIZE 100
34 #include <linux/lustre_lite.h>
35 #include <linux/lprocfs_status.h>
39 #define DEFAULT_MODE 0444
41 * Tokenizer array. Change this array to include special
42 * characters for string tokenizing
44 char tok[] = {'/', (char)0};
49 extern struct proc_dir_entry proc_root; /* Defined in proc/root.c */
54 struct proc_dir_entry *proc_lustre_root = 0;
55 struct proc_dir_entry *proc_lustre_dev_root = 0;
56 struct proc_dir_entry *proc_lustre_fs_root=0;
58 struct proc_dir_entry* lprocfs_mkdir(const char* dname,
59 struct proc_dir_entry *parent)
61 struct proc_dir_entry *child_dir_entry;
63 child_dir_entry = proc_mkdir(dname, parent);
66 CERROR("lustre: failed to create /proc entry %s\n", dname);
68 return child_dir_entry;
70 struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head,
73 struct proc_dir_entry* temp;
78 while (temp != NULL) {
79 if (!strcmp(temp->name, name))
88 void lprocfs_remove_all(struct proc_dir_entry* root)
91 struct proc_dir_entry *temp=root;
92 struct proc_dir_entry* rm_entry;
93 struct proc_dir_entry* parent=root->parent;
102 remove_proc_entry(rm_entry->name, rm_entry->parent);
103 if(temp==parent) break;
110 struct proc_dir_entry* lprocfs_new_dir(struct proc_dir_entry* root,
114 struct proc_dir_entry* new_root = 0;
115 struct proc_dir_entry* temp_entry = 0;
117 char temp_string[MAX_STRING_SIZE];
122 strncpy(temp_string, string, MAX_STRING_SIZE-1);
123 temp_string[strlen(string) + 1] = '\0';
126 mover_str=temp_string;
127 while ((my_str = strsep(&mover_str, tok))) {
130 CDEBUG(D_OTHER, "SEARCH= %s\t, ROOT=%s\n", my_str,
132 temp_entry = lprocfs_srch(new_root, my_str);
133 if (temp_entry == 0) {
134 CDEBUG(D_OTHER, "Adding: %s\n", my_str);
135 temp_entry = lprocfs_mkdir(my_str, new_root);
136 if (temp_entry == 0) {
138 "! Did not create new dir %s !!\n",
143 new_root = temp_entry;
149 int lprocfs_new_vars(struct proc_dir_entry* root,
150 struct lprocfs_vars* list,
154 struct proc_dir_entry* temp_root=0;
155 struct proc_dir_entry* new_leaf=0;
156 struct proc_dir_entry* new_parent=0;
157 char temp_string[MAX_STRING_SIZE];
163 temp_root=lprocfs_new_dir(root, list->name, tok);
166 CDEBUG(D_OTHER, "!LProcFS: Mods: No root!");
169 /* Convert the last element into a leaf-node */
171 strncpy(temp_string, temp_root->name, MAX_STRING_SIZE-1);
172 temp_string[strlen(temp_root->name) + 1] = '\0';
173 new_parent=temp_root->parent;
174 if (new_parent != 0){
175 remove_proc_entry(temp_root->name, new_parent);
177 remove_proc_entry(temp_root->name, NULL);
179 new_leaf = create_proc_entry(temp_string, DEFAULT_MODE,
181 new_leaf->read_proc = list->read_fptr;
182 new_leaf->write_proc = list->write_fptr;
191 * API implementations
194 int lprocfs_add_vars(struct proc_dir_entry* root,
195 struct lprocfs_vars* var,
199 return lprocfs_new_vars(root, var,
200 (const char*) tok, data);
205 int lprocfs_reg_obd(struct obd_device* device,
206 struct lprocfs_vars* list,
211 struct proc_dir_entry* this_dev_root=0;
213 /* Obtain this device root */
214 this_dev_root = lprocfs_mkdir(device->obd_name,
215 device->obd_type->typ_procroot);
217 device->obd_proc_entry=this_dev_root;
218 retval=lprocfs_add_vars(this_dev_root, list,
224 int lprocfs_dereg_obd(struct obd_device* device)
227 CDEBUG(D_OTHER, "LPROCFS removing device = %s\n", device->obd_name);
230 CDEBUG(D_OTHER, "! LProcfs: Null pointer !\n");
234 lprocfs_remove_all(device->obd_proc_entry);
236 if (device->counters)
237 OBD_FREE(device->counters, device->cntr_mem_size);
242 struct proc_dir_entry* lprocfs_reg_mnt(char* mnt_name)
244 return lprocfs_mkdir(mnt_name, proc_lustre_fs_root);
248 int lprocfs_dereg_mnt(struct proc_dir_entry* root)
250 lprocfs_remove_all(root);
255 int lprocfs_reg_class(struct obd_type* type,
256 struct lprocfs_vars* list,
259 struct proc_dir_entry* root;
262 root=lprocfs_mkdir(type->typ_name, proc_lustre_dev_root);
264 type->typ_procroot=root;
266 retval=lprocfs_add_vars(root, list, data);
271 int lprocfs_dereg_class(struct obd_type* class)
274 CDEBUG(D_OTHER, "Non-existent class",
279 lprocfs_remove_all(class->typ_procroot);
281 CDEBUG(D_OTHER, "LPROCFS removed = %s\n", class->typ_name);
286 int lprocfs_reg_main()
288 proc_lustre_root = lprocfs_mkdir("lustre", &proc_root);
289 if (!proc_lustre_root) {
290 CERROR(" !! Cannot create /proc/lustre !! \n");
294 proc_lustre_dev_root =lprocfs_mkdir("devices", proc_lustre_root);
296 if (!proc_lustre_dev_root) {
297 CERROR(" !! Cannot create /proc/lustre/devices !! \n");
300 proc_lustre_fs_root=lprocfs_mkdir("mnt_pnt", proc_lustre_root);
302 if (!proc_lustre_fs_root) {
303 CERROR(" !! Cannot create /proc/lustre/mnt_pnt !! \n");
311 int lprocfs_dereg_main()
313 lprocfs_remove_all(proc_lustre_root);
315 proc_lustre_dev_root=0;
316 proc_lustre_fs_root=0;
326 int lprocfs_ll_rd(char *page, char **start, off_t off,
327 int count, int *eof, void *data)
329 __u64 *temp = (__u64 *)data;
332 len = snprintf(page, count, LPU64"\n", *temp);
337 #endif /* LPROC_SNMP */
340 EXPORT_SYMBOL(lprocfs_reg_obd);
341 EXPORT_SYMBOL(lprocfs_dereg_obd);
342 EXPORT_SYMBOL(lprocfs_reg_main);
343 EXPORT_SYMBOL(lprocfs_dereg_main);
344 EXPORT_SYMBOL(lprocfs_reg_mnt);
345 EXPORT_SYMBOL(lprocfs_dereg_mnt);
346 EXPORT_SYMBOL(lprocfs_add_vars);
347 EXPORT_SYMBOL(lprocfs_reg_class);
348 EXPORT_SYMBOL(lprocfs_dereg_class);
349 EXPORT_SYMBOL(lprocfs_ll_rd);