1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * proc_lustre.c manages /proc/lustre
6 * Copyright (c) 2001 Rumi Zahir <rumi.zahir@intel.com>
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* OBD devices materialize in /proc as a directory:
24 * /proc/lustre/obd/<number>
25 * when /dev/obd<number> is opened. When the device is closed, the
26 * directory entry disappears.
28 * For each open OBD device, code in this file also creates a file
29 * named <status>. "cat /proc/lustre/obd/<number>/status" gives
30 * information about the OBD device's configuration.
31 * The class driver manages the "status" entry.
33 * Other logical drivers can create their own entries. For example,
34 * the obdtrace driver creates /proc/lustre/obd/<obdid>/stats entry.
36 * This file defines three functions
37 * proc_lustre_register_obd_device() - called at device attach time
38 * proc_lustre_release_obd_device() - called at detach
39 * proc_lustre_remove_obd_entry()
40 * that dynamically create/delete /proc/lustre/obd entries:
42 * proc_lustre_register_obd_device() registers an obd device,
43 * and, if this is the first OBD device, creates /proc/lustre/obd.
45 * proc_lustre_release_obd_device() removes device information
46 * from /proc/lustre/obd, and if this is the last OBD device
47 * removes /proc/lustre/obd.
49 * proc_lustre_remove_obd_entry() removes a
50 * /proc/lustre/obd/<obdid>/ entry by name. This is the only
51 * function that is exported to other modules.
55 #include <linux/config.h>
56 #include <linux/module.h>
57 #include <linux/version.h>
58 #include <linux/proc_fs.h>
60 #define DEBUG_SUBSYSTEM S_CLASS
62 #include <linux/obd_support.h>
63 #include <linux/obd_class.h>
66 extern struct proc_dir_entry proc_root;
67 static struct proc_dir_entry *proc_lustre_dir_entry = NULL;
68 static struct proc_dir_entry *proc_lustre_obd_dir_entry = NULL;
70 static int read_lustre_status(char *page, char **start, off_t offset,
71 int count, int *eof, void *data)
73 struct obd_device * obddev = (struct obd_device *)data;
76 #warning FIXME: This function is madness, completely unsafe, a disaster waiting to happen.
78 p = sprintf(&page[0], "device=%d\n", obddev->obd_minor);
79 p += sprintf(&page[p], "name=%s\n", MKSTR(obddev->obd_name));
80 p += sprintf(&page[p], "uuid=%s\n", obddev->obd_uuid);
81 p += sprintf(&page[p], "attached=1\n");
82 p += sprintf(&page[p], "type=%s\n", MKSTR(obddev->obd_type->typ_name));
84 if (obddev->obd_flags & OBD_SET_UP)
85 p += sprintf(&page[p], "setup=1\n");
90 struct obd_export *export = NULL;
92 lh = &obddev->obd_exports;
93 while ((lh = lh->next) != &obddev->obd_exports) {
94 p += sprintf(&page[p],
95 ((export == NULL) ? ", connections(" : ",") );
96 export = list_entry(lh, struct obd_export, exp_chain);
97 p += sprintf(&page[p], "%p", export);
99 if (export != 0) { /* there was at least one export */
100 p += sprintf(&page[p], ")");
104 p += sprintf(&page[p], "\n");
106 /* Compute eof and return value */
107 if (offset + count >= p) {
114 struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd)
116 struct proc_dir_entry *obd_dir;
117 struct proc_dir_entry *obd_status = NULL;
119 if (!proc_lustre_dir_entry) {
120 proc_lustre_dir_entry = proc_mkdir("lustre", &proc_root);
121 if (IS_ERR(proc_lustre_dir_entry))
124 proc_lustre_obd_dir_entry =
125 proc_mkdir("devices", proc_lustre_dir_entry);
126 if (IS_ERR(proc_lustre_obd_dir_entry))
129 obd_dir = proc_mkdir(obd->obd_name, proc_lustre_obd_dir_entry);
132 obd_status = create_proc_entry("status", S_IRUSR | S_IFREG,
136 obd_status->read_proc = read_lustre_status;
137 obd_status->data = (void *)obd;
143 void proc_lustre_remove_obd_entry(const char *name, struct obd_device *obd)
145 struct proc_dir_entry *obd_entry = NULL;
146 struct proc_dir_entry *obd_dir = obd->obd_proc_entry;
148 remove_proc_entry(name, obd_dir);
150 while (obd_dir->subdir == NULL) {
151 /* if we removed last entry in this directory, then
152 * remove parent directory unless this is /proc itself */
153 if (obd_dir == &proc_root)
157 obd_dir = obd_dir->parent;
159 /* If /proc/lustre/obd/foo or /proc/lustre/obd or
160 * /proc/lustre is being removed, then reset internal
163 if (obd_entry == obd->obd_proc_entry)
164 obd->obd_proc_entry = NULL; /* /proc/lustre/obd/foo */
165 else if (obd_entry == proc_lustre_obd_dir_entry)
166 proc_lustre_obd_dir_entry = NULL; /* /proc/lustre/obd */
167 else if (obd_entry == proc_lustre_dir_entry)
168 proc_lustre_dir_entry = NULL; /* /proc/lustre */
170 remove_proc_entry(obd_entry->name, obd_dir);
174 void proc_lustre_release_obd_device(struct obd_device *obd)
176 proc_lustre_remove_obd_entry("status", obd);
180 #else /* CONFIG_PROC_FS */
182 struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd)
187 void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd)
191 void proc_lustre_release_obd_device(struct obd_device *obd)
195 #endif /* CONFIG_PROC_FS */
197 EXPORT_SYMBOL(proc_lustre_remove_obd_entry);