1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Intel Corporation
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.
23 * Author: Hariharan Thantry
24 * File Name: lprocfs.c
26 * During initialization (of lustre), the following directory materializes
28 * When the first OBD device of a class is created (due to insmod)
30 * /proc/lustre/devices/<device-class> is created.
31 * When an instance of a device is created (during attach) the
32 * directory entry for that instance along with the variables for
33 * that entry gets created. These variables could be counters, string
35 * Each API further describes the functionality offered.
40 #include <linux/config.h>
41 #include <linux/module.h>
42 #include <linux/version.h>
43 #include <linux/proc_fs.h>
44 #include <linux/slab.h>
45 #include <linux/types.h>
47 #define DEBUG_SUBSYSTEM S_CLASS
48 #define MAX_STRING_SIZE 100
50 #include <linux/obd_support.h>
51 #include <linux/obd_class.h>
52 #include <linux/lprocfs.h>
53 #include <linux/string.h>
54 #include <linux/lustre_lib.h>
58 #define DEFAULT_MODE 0644
60 * Tokenizer array. Change this array to include special
61 * characters for string tokenizing
63 char tok[] = {'/', (char)0};
66 * Escape character. To be used in directories that
67 * should not have any counter/variable entries under
68 * them. Used for hierarchical directories
71 char escape_char = '%';
76 extern struct proc_dir_entry proc_root; /* Defined in proc/root.c */
83 static struct proc_dir_entry *proc_lustre_root = 0;
84 static struct proc_dir_entry *proc_lustre_dev_root = 0;
86 /* struct lustre_lock proc_lustre_lock; */
87 /* static struct proc_dir_entry *proc_lustre_conn_root = 0; */
88 char *testStr = "General..";
91 * Link the namespace with the internal array indices for
92 * each device class, only if proc lustre is defined
95 struct namespace_index dir_mdc_index[] = {
96 LPROCFS_DIR_INDEX(mdc, mgmt_setup),
97 LPROCFS_DIR_INDEX(mdc, mgmt_cleanup),
98 LPROCFS_DIR_INDEX(mdc, mgmt_connect),
99 LPROCFS_DIR_INDEX(mdc, mgmt_disconnect),
100 LPROCFS_DIR_INDEX(mdc, reint),
101 LPROCFS_DIR_INDEX(mdc, getstatus),
102 LPROCFS_DIR_INDEX(mdc, getattr),
103 LPROCFS_DIR_INDEX(mdc, setattr),
104 LPROCFS_DIR_INDEX(mdc, open),
105 LPROCFS_DIR_INDEX(mdc, readpage),
106 LPROCFS_DIR_INDEX(mdc, create),
107 LPROCFS_DIR_INDEX(mdc, unlink),
108 LPROCFS_DIR_INDEX(mdc, link),
109 LPROCFS_DIR_INDEX(mdc, rename),
112 struct namespace_index dir_mds_index[] = {
113 LPROCFS_DIR_INDEX(mds, mgmt_setup),
114 LPROCFS_DIR_INDEX(mds, mgmt_cleanup),
115 LPROCFS_DIR_INDEX(mds, mgmt_connect),
116 LPROCFS_DIR_INDEX(mds, mgmt_disconnect),
117 LPROCFS_DIR_INDEX(mds, getstatus),
118 LPROCFS_DIR_INDEX(mds, connect),
119 LPROCFS_DIR_INDEX(mds, disconnect_callback),
120 LPROCFS_DIR_INDEX(mds, getattr),
121 LPROCFS_DIR_INDEX(mds, readpage),
122 LPROCFS_DIR_INDEX(mds, open),
123 LPROCFS_DIR_INDEX(mds, close),
124 LPROCFS_DIR_INDEX(mds, create),
125 LPROCFS_DIR_INDEX(mds, unlink),
126 LPROCFS_DIR_INDEX(mds, link),
127 LPROCFS_DIR_INDEX(mds, rename),
128 LPROCFS_DIR_INDEX(mds, reint_summary),
129 LPROCFS_DIR_INDEX(mds, reint_setattr),
130 LPROCFS_DIR_INDEX(mds, reint_create),
131 LPROCFS_DIR_INDEX(mds, reint_unlink),
132 LPROCFS_DIR_INDEX(mds, reint_link),
133 LPROCFS_DIR_INDEX(mds, reint_rename),
134 LPROCFS_DIR_INDEX(mds, reint_recreate),
137 struct namespace_index dir_osc_index[] = {
138 LPROCFS_DIR_INDEX(osc, mgmt_setup),
139 LPROCFS_DIR_INDEX(osc, mgmt_cleanup),
140 LPROCFS_DIR_INDEX(osc, mgmt_connect),
141 LPROCFS_DIR_INDEX(osc, mgmt_disconnect),
142 LPROCFS_DIR_INDEX(osc, create),
143 LPROCFS_DIR_INDEX(osc, destroy),
144 LPROCFS_DIR_INDEX(osc, getattr),
145 LPROCFS_DIR_INDEX(osc, setattr),
146 LPROCFS_DIR_INDEX(osc, open),
147 LPROCFS_DIR_INDEX(osc, close),
148 LPROCFS_DIR_INDEX(osc, brw),
149 LPROCFS_DIR_INDEX(osc, punch),
150 LPROCFS_DIR_INDEX(osc, summary),
151 LPROCFS_DIR_INDEX(osc, cancel),
154 struct namespace_index dir_ost_index[] = {
155 LPROCFS_DIR_INDEX(ost, mgmt_setup),
156 LPROCFS_DIR_INDEX(ost, mgmt_cleanup),
157 LPROCFS_DIR_INDEX(ost, mgmt_connect),
158 LPROCFS_DIR_INDEX(ost, mgmt_disconnect),
159 LPROCFS_DIR_INDEX(ost, create),
160 LPROCFS_DIR_INDEX(ost, destroy),
161 LPROCFS_DIR_INDEX(ost, getattr),
162 LPROCFS_DIR_INDEX(ost, setattr),
163 LPROCFS_DIR_INDEX(ost, open),
164 LPROCFS_DIR_INDEX(ost, close),
165 LPROCFS_DIR_INDEX(ost, brw),
166 LPROCFS_DIR_INDEX(ost, punch),
167 LPROCFS_DIR_INDEX(ost, summary),
168 LPROCFS_DIR_INDEX(ost, cancel),
169 LPROCFS_DIR_INDEX(ost, getinfo),
172 struct namespace_index dir_lov_index[] = {
173 LPROCFS_DIR_INDEX(lov, mgmt_setup),
174 LPROCFS_DIR_INDEX(lov, mgmt_cleanup),
175 LPROCFS_DIR_INDEX(lov, mgmt_connect),
176 LPROCFS_DIR_INDEX(lov, mgmt_disconnect),
177 LPROCFS_DIR_INDEX(lov, create),
178 LPROCFS_DIR_INDEX(lov, destroy),
179 LPROCFS_DIR_INDEX(lov, getattr),
180 LPROCFS_DIR_INDEX(lov, setattr),
181 LPROCFS_DIR_INDEX(lov, open),
182 LPROCFS_DIR_INDEX(lov, close),
183 LPROCFS_DIR_INDEX(lov, brw),
184 LPROCFS_DIR_INDEX(lov, punch),
185 LPROCFS_DIR_INDEX(lov, summary),
186 LPROCFS_DIR_INDEX(lov, cancel),
187 LPROCFS_DIR_INDEX(lov, getinfo),
190 struct namespace_index dir_obdfilter_index[] = {
191 LPROCFS_DIR_INDEX(obdfilter, mgmt_setup),
192 LPROCFS_DIR_INDEX(obdfilter, mgmt_cleanup),
193 LPROCFS_DIR_INDEX(obdfilter, mgmt_connect),
194 LPROCFS_DIR_INDEX(obdfilter, mgmt_disconnect),
195 LPROCFS_DIR_INDEX(obdfilter, create),
196 LPROCFS_DIR_INDEX(obdfilter, destroy),
197 LPROCFS_DIR_INDEX(obdfilter, getattr),
198 LPROCFS_DIR_INDEX(obdfilter, setattr),
199 LPROCFS_DIR_INDEX(obdfilter, open),
200 LPROCFS_DIR_INDEX(obdfilter, close),
201 LPROCFS_DIR_INDEX(obdfilter, brw),
202 LPROCFS_DIR_INDEX(obdfilter, punch),
203 LPROCFS_DIR_INDEX(obdfilter, summary),
204 LPROCFS_DIR_INDEX(obdfilter, cancel),
205 LPROCFS_DIR_INDEX(obdfilter, getinfo),
208 struct namespace_index dir_ldlm_index[] = {
209 LPROCFS_DIR_INDEX(ldlm, mgmt_setup),
210 LPROCFS_DIR_INDEX(ldlm, mgmt_cleanup),
211 LPROCFS_DIR_INDEX(ldlm, mgmt_connect),
212 LPROCFS_DIR_INDEX(ldlm, mgmt_disconnect),
213 LPROCFS_DIR_INDEX(ldlm, locks_enqueus),
214 LPROCFS_DIR_INDEX(ldlm, locks_cancels),
215 LPROCFS_DIR_INDEX(ldlm, locks_converts),
216 LPROCFS_DIR_INDEX(ldlm, locks_matches),
219 struct namespace_index dir_ptlrpc_index[] = {
220 LPROCFS_DIR_INDEX(ptlrpc, mgmt_setup),
221 LPROCFS_DIR_INDEX(ptlrpc, mgmt_cleanup),
222 LPROCFS_DIR_INDEX(ptlrpc, mgmt_connect),
223 LPROCFS_DIR_INDEX(ptlrpc, mgmt_disconnect),
224 LPROCFS_DIR_INDEX(ptlrpc, counters),
227 struct namespace_index prof_mdc_index[] = {
228 LPROCFS_CNTR_INDEX(mdc, min_time),
229 LPROCFS_CNTR_INDEX(mdc, max_time),
230 LPROCFS_CNTR_INDEX(mdc, sum_time),
231 LPROCFS_CNTR_INDEX(mdc, num_ops),
234 struct namespace_index prof_mds_index[]= {
235 LPROCFS_CNTR_INDEX(mds, min_time),
236 LPROCFS_CNTR_INDEX(mds, max_time),
237 LPROCFS_CNTR_INDEX(mds, sum_time),
238 LPROCFS_CNTR_INDEX(mds, num_ops),
241 struct namespace_index prof_osc_index[]= {
242 LPROCFS_CNTR_INDEX(osc, min_time),
243 LPROCFS_CNTR_INDEX(osc, max_time),
244 LPROCFS_CNTR_INDEX(osc, sum_time),
245 LPROCFS_CNTR_INDEX(osc, num_ops),
248 struct namespace_index prof_ost_index[]= {
249 LPROCFS_CNTR_INDEX(ost, min_time),
250 LPROCFS_CNTR_INDEX(ost, max_time),
251 LPROCFS_CNTR_INDEX(ost, sum_time),
252 LPROCFS_CNTR_INDEX(ost, num_ops),
255 struct namespace_index prof_lov_index[]= {
256 LPROCFS_CNTR_INDEX(lov, min_time),
257 LPROCFS_CNTR_INDEX(lov, max_time),
258 LPROCFS_CNTR_INDEX(lov, sum_time),
259 LPROCFS_CNTR_INDEX(lov, num_ops),
262 struct namespace_index prof_obdfilter_index[]= {
263 LPROCFS_CNTR_INDEX(obdfilter, min_time),
264 LPROCFS_CNTR_INDEX(obdfilter, max_time),
265 LPROCFS_CNTR_INDEX(obdfilter, sum_time),
266 LPROCFS_CNTR_INDEX(obdfilter, num_ops),
269 struct namespace_index prof_ldlm_index[] = {
270 LPROCFS_CNTR_INDEX(ldlm, min_time),
271 LPROCFS_CNTR_INDEX(ldlm, max_time),
272 LPROCFS_CNTR_INDEX(ldlm, sum_time),
273 LPROCFS_CNTR_INDEX(ldlm, num_ops),
274 LPROCFS_CNTR_INDEX(ldlm, num_total),
275 LPROCFS_CNTR_INDEX(ldlm, num_zerolatency),
276 LPROCFS_CNTR_INDEX(ldlm, num_zerolatency_inflight),
277 LPROCFS_CNTR_INDEX(ldlm, num_zerolatency_done),
278 LPROCFS_CNTR_INDEX(ldlm, nonzero_mintime),
279 LPROCFS_CNTR_INDEX(ldlm, nonzero_maxtime),
280 LPROCFS_CNTR_INDEX(ldlm, nonzero_sumtime),
283 struct namespace_index prof_ptlrpc_index[] = {
284 LPROCFS_CNTR_INDEX(ptlrpc, min_time),
285 LPROCFS_CNTR_INDEX(ptlrpc, max_time),
286 LPROCFS_CNTR_INDEX(ptlrpc, sum_time),
287 LPROCFS_CNTR_INDEX(ptlrpc, num_ops),
288 LPROCFS_CNTR_INDEX(ptlrpc, msgs_alloc),
289 LPROCFS_CNTR_INDEX(ptlrpc, msgs_max),
290 LPROCFS_CNTR_INDEX(ptlrpc, recv_count),
291 LPROCFS_CNTR_INDEX(ptlrpc, recv_length),
292 LPROCFS_CNTR_INDEX(ptlrpc, send_count),
293 LPROCFS_CNTR_INDEX(ptlrpc, send_length),
294 LPROCFS_CNTR_INDEX(ptlrpc, portal_kmemory),
298 * Group the device class name, its directory hierarchy and
299 * leaf nodes together
302 struct groupspace_index class_index[] = {
303 LPROCFS_GROUP_CREATE(mdc),
304 LPROCFS_GROUP_CREATE(mds),
305 LPROCFS_GROUP_CREATE(osc),
306 LPROCFS_GROUP_CREATE(ost),
307 LPROCFS_GROUP_CREATE(lov),
308 LPROCFS_GROUP_CREATE(obdfilter),
309 LPROCFS_GROUP_CREATE(ldlm),
310 LPROCFS_GROUP_CREATE(ptlrpc),
315 * API implementations
319 * lprocfs_reg_dev: Registers an instance of the OBD device in the
323 int lprocfs_reg_dev(struct obd_device* device, lprocfs_group_t* namespace,
324 unsigned int cnt_struct_size)
326 unsigned int num_directories = 0;
327 int class_array_index = 0;
329 struct proc_dir_entry* this_dev_root=0;
330 unsigned int i = 0, j = 0;
332 /* Obtain this device root */
333 this_dev_root = lprocfs_mkinitdir(device);
334 if (this_dev_root == 0) {
335 CERROR("Could not create initial directory");
336 return LPROCFS_FAILURE;
340 /* Obtain the class-array index */
341 class_array_index = lprocfs_getclass_idx(class_index,
342 device->obd_type->typ_name);
344 if (class_array_index == LPROCFS_FAILURE) {
345 CERROR("!! Could not find class !! \n");
346 return LPROCFS_FAILURE;
349 /* Create the directory namespace */
350 retval = lprocfs_create_dir_namespace(this_dev_root, namespace,
352 if (retval == LPROCFS_FAILURE) {
353 CERROR("!!Could not create proc directory structure !!\n");
354 return LPROCFS_FAILURE;
357 /* Allocate memory managed by LProcFS for the device. */
358 if (cnt_struct_size != 0) {
359 OBD_ALLOC(device->counters, num_directories*cnt_struct_size);
360 device->cntr_mem_size = num_directories*cnt_struct_size;
364 * Iterate the proc-dir-namespace, obtain corresponding
365 * directory(attribute)
366 * entries. Create the proc-counters from namespace, link them into
369 retval=lprocfs_link_dir_counters(device, this_dev_root, namespace,
370 cnt_struct_size, class_array_index);
372 if (retval == LPROCFS_FAILURE) {
373 CERROR("!! Could not link proc counters to device !!");
374 return LPROCFS_FAILURE;
378 * Test code: This goes into individual modules. strcmp is
379 * unnecessary, since device knows its class. To see the values
380 * from the user space, do a cat on the respective variable
382 if (!(strcmp(device->obd_type->typ_name, "mds"))) {
383 DEV_PROF_START(mds, device, gen, mgmt_setup);
385 for (i = 0; i < 100; i++)
386 for (j = 0; j < 100; j++)
389 DEV_PROF_END(mds, device, gen, mgmt_setup);
391 DEV_PROF_START(mds, device, gen, mgmt_setup);
393 for (i = 0; i < 1000; i++)
394 for (j = 0; j < 1000; j++)
397 DEV_PROF_END(mds, device, gen, mgmt_setup);
400 DEV_PROF_START(mds, device, gen, open);
401 for (i = 0; i < 50; i++) {
402 DEV_PROF_START(mds, device, gen, close);
403 for (j = 0; j < 2000; j++)
405 DEV_PROF_END(mds, device, gen, close);
407 DEV_PROF_END(mds, device, gen, open);
410 if (!(strcmp(device->obd_type->typ_name, "ldlm"))) {
411 DEV_PROF_START(ldlm, device, ldlm, mgmt_connect);
412 for (i = 0; i < 200; i++) {
413 DEV_PROF_START(ldlm, device, ldlm, mgmt_disconnect);
414 for (j = 0; j < 2000; j++)
416 DEV_PROF_END(ldlm, device, ldlm, mgmt_disconnect);
418 DEV_PROF_END(ldlm, device, ldlm, mgmt_connect);
421 return LPROCFS_SUCCESS;
424 int lprocfs_link_dir_counters(struct obd_device* device,
425 struct proc_dir_entry* root,
426 lprocfs_group_t* namespace,
430 struct proc_dir_entry* dir_root=0;
431 lprocfs_group_t* temp;
432 lprocfs_vars_t* fn_ctr;
433 struct namespace_index* cntr_names;
437 unsigned int escape = 0;
442 temp = &namespace[i];
444 if (temp->count_func_namespace == 0)
447 while ((temp->dir_namespace)[j] != 0) {
448 dir_root = lprocfs_add_dir(root,
449 (temp->dir_namespace)[j],
450 (const char*)tok, &escape);
456 dir_idx = lprocfs_get_idx(class_index[cl_idx].directory,
457 (temp->dir_namespace)[j]);
460 fn_ctr = &((temp->count_func_namespace)[k]);
461 if (fn_ctr->read_fptr == 0)
463 cntr_names = class_index[cl_idx].counters;
464 cnt_idx = lprocfs_get_idx(cntr_names,
467 if (lprocfs_add_var(device, dir_root, fn_ctr,
468 dir_idx, cnt_idx, sz,
471 CERROR("Could not create leaf node!");
472 return LPROCFS_FAILURE;
488 return LPROCFS_SUCCESS;
491 int lprocfs_create_dir_namespace(struct proc_dir_entry* root,
492 lprocfs_group_t* namespace,
493 unsigned int *num_dirs)
497 struct proc_dir_entry* dir_root=0;
498 lprocfs_group_t* temp;
499 unsigned int escape = 0;
502 temp = &namespace[i];
503 if (temp->count_func_namespace == 0)
505 while ((temp->dir_namespace)[j] != 0){
506 dir_root = lprocfs_add_dir(root,
507 (temp->dir_namespace)[j],
508 (const char*)tok, &escape);
510 CERROR("!! Could not create dir %s !! \n",
511 (temp->dir_namespace)[j]);
512 return LPROCFS_FAILURE;
514 if (temp->prof_type != e_specific && !escape)
522 return LPROCFS_SUCCESS;
526 int lprocfs_getclass_idx(struct groupspace_index* group, const char* classname)
528 unsigned int idx = 0;
530 while (group[idx].name != "") {
531 if (!strcmp(group[idx].name, classname))
536 return LPROCFS_FAILURE;
539 struct proc_dir_entry* lprocfs_mkinitdir(struct obd_device* device)
541 struct proc_dir_entry* this_dev_root = 0;
542 struct proc_dir_entry* temp_proc = 0;
545 * First check if /proc/lustre exits. If it does not,
546 * instantiate the same and the devices directory
548 if (!proc_lustre_root) {
549 proc_lustre_root = lprocfs_mkdir("lustre", &proc_root);
550 if (!proc_lustre_root) {
551 CERROR(" !! Cannot create /proc/lustre !! \n");
554 proc_lustre_dev_root =
555 lprocfs_mkdir("devices", proc_lustre_root);
557 if (!proc_lustre_dev_root) {
558 CERROR(" !! Cannot create /proc/lustre/devices !! \n");
564 * Check if this is the first instance for a device of
565 * this class in the lprocfs hierarchy.
567 temp_proc = lprocfs_srch(proc_lustre_dev_root,
568 device->obd_type->typ_name);
571 temp_proc = lprocfs_mkdir(device->obd_type->typ_name,
572 proc_lustre_dev_root);
574 CERROR("! Proc dir for device class %s !!\n",
575 device->obd_type->typ_name);
580 /* Next create the proc_dir_entry for this instance */
581 this_dev_root = lprocfs_mkdir(device->obd_name, temp_proc);
582 if (!this_dev_root) {
583 CERROR("!Can't create proc entry for instance %s !! \n",
588 return this_dev_root;
592 int lprocfs_get_idx(struct namespace_index* class, const char* dir_name)
594 unsigned int index = 0;
595 char temp_string[MAX_STRING_SIZE];
597 /* First replace the string tokenizer with enum character */
598 memset(temp_string, 0, MAX_STRING_SIZE);
599 while (dir_name[index]!='\0' && index < MAX_STRING_SIZE) {
600 if (dir_name[index] != tok[0])
601 temp_string[index] = dir_name[index];
603 temp_string[index] = enum_char;
606 temp_string[index] = '\0';
609 while (class[index].name) {
610 if (!strcmp(class[index].name, temp_string))
615 CDEBUG(D_OTHER, "No profiling for %s\n", temp_string);
619 struct proc_dir_entry* lprocfs_mkdir(const char* dname,
620 struct proc_dir_entry *parent)
622 struct proc_dir_entry *child_dir_entry;
624 child_dir_entry = proc_mkdir(dname, parent);
626 if (!child_dir_entry)
627 CERROR("lustre: failed to create /proc entry %s\n", dname);
629 return child_dir_entry;
633 * Create the variable struct entry for /proc. This will also
634 * register the read/write function pointers with
636 * Returns non-zero on success, zero on failure
638 unsigned int lprocfs_add_var(struct obd_device* device,
639 struct proc_dir_entry* root,
640 lprocfs_vars_t* variable, int dir_idx, int cnt_idx,
641 unsigned int sz, lprofilers_e type)
643 struct proc_dir_entry* new_proc_entry;
645 unsigned int actual_idx;
646 unsigned int blk_size;
648 new_proc_entry = create_proc_entry(variable->name, DEFAULT_MODE, root);
650 return LPROCFS_FAILURE;
652 new_proc_entry->read_proc = variable->read_fptr;
653 new_proc_entry->write_proc = variable->write_fptr;
657 if (device->counters) {
658 if (dir_idx != -1 && cnt_idx != -1) {
659 temp = (__u64*)device->counters;
660 blk_size = ((sz) / (sizeof(__u64)));
661 actual_idx = (dir_idx*blk_size) + cnt_idx;
663 new_proc_entry->data = (__u64*)temp;
668 new_proc_entry->data = device;
672 return LPROCFS_SUCCESS;
677 * Tokenize name, based on tok and end-of-string. Create and return the
678 * new directory entry. Set escape variable if the directory name contained
679 * the escaping character (#)
682 struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry *root,
685 unsigned int* escape)
687 struct proc_dir_entry* new_root = 0;
688 struct proc_dir_entry* temp_entry = 0;
689 struct proc_dir_entry* new_entry = 0;
690 char temp_string[MAX_STRING_SIZE];
695 * Remove trailing escaping character
697 memset(temp_string, 0, MAX_STRING_SIZE);
698 if (strlen(string) >= MAX_STRING_SIZE) {
699 CERROR("Directory namespace too long");
703 if (strchr(string, escape_char)) {
705 strncpy(temp_string,string,strlen(string) - 1);
706 temp_string[strlen(string)] = '\0';
709 strcpy(temp_string, string);
710 temp_string[strlen(string) + 1] = '\0';
715 /* Using strsep() instead */
716 mover_str=temp_string;
717 while ((my_str = strsep(&mover_str, tok))) {
720 temp_entry = lprocfs_srch(new_root, my_str);
721 if (temp_entry == 0) {
722 new_entry = lprocfs_mkdir(my_str, new_root);
723 if (new_entry == 0) {
724 CERROR("! Did not create new dir %s !!\n",
730 new_root = temp_entry;
736 struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head,
739 struct proc_dir_entry* temp;
744 while (temp != NULL) {
745 if (!strcmp(temp->name, name))
753 #warning FIXME: recursive code is VERY bad in the kernel because of stack limit
754 struct proc_dir_entry* lprocfs_bfs_srch(struct proc_dir_entry* root,
757 struct proc_dir_entry* temp = root;
762 if (!strcmp(temp->name, name))
765 if ((temp = lprocfs_bfs_srch(root->next, name)) != 0)
768 if ((temp = lprocfs_bfs_srch(root->subdir, name)) != 0)
774 int lprocfs_get_nm(char* name, lprocfs_obd_nm_t* collection)
777 while (collection[i].obd_names != 0) {
778 if(!strcmp(collection[i].obd_clname, name))
786 int lprocfs_dereg_dev(struct obd_device* device)
788 struct proc_dir_entry* temp;
790 CDEBUG(D_OTHER, "LPROCFS removing device = %s\n", \
794 CDEBUG(D_OTHER, "! LProcfs: Null pointer !\n");
795 return LPROCFS_SUCCESS;
798 if (!(device->obd_name)) {
799 CERROR(" !! Device does not have a name !! \n");
800 return LPROCFS_FAILURE;
803 temp = lprocfs_bfs_srch(proc_lustre_dev_root->subdir, \
806 CERROR("!! No root obtained, device does not exist !!\n");
807 return LPROCFS_FAILURE;
810 lprocfs_remove_all(temp);
813 * Free the memory held by counters
815 if (device->counters)
816 OBD_FREE(device->counters, device->cntr_mem_size);
818 CDEBUG(D_OTHER, "LPROCFS removed device = %s\n", \
821 return LPROCFS_SUCCESS;
824 void lprocfs_remove_all(struct proc_dir_entry* root)
826 if (root->subdir != 0)
827 lprocfs_remove_all(root->subdir);
830 lprocfs_remove_all(root->next);
832 if (root->parent != 0)
833 remove_proc_entry(root->name, root->parent);
835 remove_proc_entry(root->name, NULL);
838 int rd_uuid(char* page, char **start, off_t off,
839 int count, int *eof, void *data)
842 struct obd_device *temp = (struct obd_device *)data;
844 len = sprintf(page, "%s\n", temp->obd_uuid);
849 int wr_uuid(struct file* file, const char *buffer,
850 unsigned long count, void *data)
856 int rd_blksize(char* page, char **start, off_t off,
857 int count, int *eof, void *data)
860 //struct obd_device *temp = (struct obd_device *)data;
865 int rd_blktotal(char* page, char **start, off_t off,
866 int count, int *eof, void *data)
871 int rd_blkfree(char* page, char **start, off_t off,
872 int count, int *eof, void *data)
877 int rd_kbfree(char* page, char **start, off_t off,
878 int count, int *eof, void *data)
883 int rd_numobjects(char* page, char **start, off_t off,
884 int count, int *eof, void *data)
889 int rd_objfree(char* page, char **start, off_t off,
890 int count, int *eof, void *data)
895 int rd_objgroups(char* page, char **start, off_t off,
896 int count, int *eof, void *data)
902 int lprocfs_ll_rd(char *page, char **start, off_t off,
903 int count, int *eof, void *data)
905 __u64 *temp = (__u64 *)data;
908 len = snprintf(page, count, LPU64"\n", *temp);
913 int rd_fs_type(char* page, char **start, off_t off,
914 int count, int *eof, void *data)
919 int rd_other(char* page, char **start, off_t off, int count, int *eof,
925 int rd_string(char* page, char **start, off_t off, int count, int *eof,
928 printk("Hello string");
932 int lprocfs_ll_wr(struct file* file, const char *buffer, unsigned long count,
938 int wr_other(struct file* file, const char *buffer, unsigned long count,
944 int wr_string(struct file* file, const char *buffer, unsigned long count,
950 int lprocfs_reg_conn(unsigned int conn_number,
951 struct lprocfs_conn_namespace* namespace)
956 int lprocfs_dereg_conn(unsigned int conn_number)
964 int lprocfs_add_export(unsigned int conn_number, struct obd_device* device)
969 int lprocfs_add_import(unsigned int conn_number, struct obd_device* device)
974 int lprocfs_remove_export(unsigned int conn_number, struct obd_device* device)
979 int lprocfs_remove_import(unsigned int conn_number, struct obd_device* device)