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.
24 /* OBD devices materialize in /proc as a directory:
25 * /proc/lustre/obd/<number>
26 * when /dev/obd<number> is opened. When the device is closed, the
27 * directory entry disappears.
29 * For each open OBD device, code in this file also creates a file
30 * named <status>. "cat /proc/lustre/obd/<number>/status" gives
31 * information about the OBD device's configuration.
32 * The class driver manages the "status" entry.
34 * Other logical drivers can create their own entries. For example,
35 * the obdtrace driver creates /proc/lustre/obd/<obdid>/stats entry.
37 * This file defines three functions
38 * proc_lustre_register_obd_device() - called at device attach time
39 * proc_lustre_release_obd_device() - called at detach
40 * proc_lustre_remove_obd_entry()
41 * that dynamically create/delete /proc/lustre/obd entries:
43 * proc_lustre_register_obd_device() registers an obd device,
44 * and, if this is the first OBD device, creates /proc/lustre/obd.
46 * proc_lustre_release_obd_device() removes device information
47 * from /proc/lustre/obd, and if this is the last OBD device
48 * removes /proc/lustre/obd.
50 * proc_lustre_remove_obd_entry() removes a
51 * /proc/lustre/obd/<obdid>/ entry by name. This is the only
52 * function that is exported to other modules.
56 #include <linux/config.h>
57 #include <linux/module.h>
58 #include <linux/version.h>
59 #include <linux/proc_fs.h>
61 #define DEBUG_SUBSYSTEM S_CLASS
63 #include <linux/obd_support.h>
64 #include <linux/obd_class.h>
67 extern struct proc_dir_entry proc_root;
68 static struct proc_dir_entry *proc_lustre_dir_entry = NULL;
69 static struct proc_dir_entry *proc_lustre_obd_dir_entry = NULL;
71 static int read_lustre_status(char *page, char **start, off_t offset,
72 int count, int *eof, void *data)
74 struct obd_device * obddev = (struct obd_device *)data;
77 #warning FIXME: This function is madness, completely unsafe, a disaster waiting to happen.
79 p = sprintf(&page[0], "device=%d\n", obddev->obd_minor);
80 p += sprintf(&page[p], "name=%s\n", MKSTR(obddev->obd_name));
81 p += sprintf(&page[p], "uuid=%s\n", obddev->obd_uuid);
82 p += sprintf(&page[p], "attached=1\n");
83 p += sprintf(&page[p], "type=%s\n", MKSTR(obddev->obd_type->typ_name));
85 if (obddev->obd_flags & OBD_SET_UP)
86 p += sprintf(&page[p], "setup=1\n");
91 struct obd_export *export = NULL;
93 lh = &obddev->obd_exports;
94 while ((lh = lh->next) != &obddev->obd_exports) {
95 p += sprintf(&page[p],
96 ((export == NULL) ? ", connections(" : ",") );
97 export = list_entry(lh, struct obd_export, exp_chain);
98 p += sprintf(&page[p], "%p", export);
100 if (export != 0) { /* there was at least one export */
101 p += sprintf(&page[p], ")");
105 p += sprintf(&page[p], "\n");
107 /* Compute eof and return value */
108 if (offset + count >= p) {
115 struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd)
117 struct proc_dir_entry *obd_dir;
118 struct proc_dir_entry *obd_status = NULL;
120 if (!proc_lustre_dir_entry) {
121 proc_lustre_dir_entry = proc_mkdir("lustre", &proc_root);
122 if (IS_ERR(proc_lustre_dir_entry))
125 proc_lustre_obd_dir_entry =
126 proc_mkdir("devices", proc_lustre_dir_entry);
127 if (IS_ERR(proc_lustre_obd_dir_entry))
130 obd_dir = proc_mkdir(obd->obd_name, proc_lustre_obd_dir_entry);
133 obd_status = create_proc_entry("status", S_IRUSR | S_IFREG,
137 obd_status->read_proc = read_lustre_status;
138 obd_status->data = (void *)obd;
144 void proc_lustre_remove_obd_entry(const char *name, struct obd_device *obd)
146 struct proc_dir_entry *obd_entry = NULL;
147 struct proc_dir_entry *obd_dir = obd->obd_proc_entry;
149 remove_proc_entry(name, obd_dir);
151 while (obd_dir->subdir == NULL) {
152 /* if we removed last entry in this directory, then
153 * remove parent directory unless this is /proc itself */
154 if (obd_dir == &proc_root)
158 obd_dir = obd_dir->parent;
160 /* If /proc/lustre/obd/foo or /proc/lustre/obd or
161 * /proc/lustre is being removed, then reset internal
164 if (obd_entry == obd->obd_proc_entry)
165 obd->obd_proc_entry = NULL; /* /proc/lustre/obd/foo */
166 else if (obd_entry == proc_lustre_obd_dir_entry)
167 proc_lustre_obd_dir_entry = NULL; /* /proc/lustre/obd */
168 else if (obd_entry == proc_lustre_dir_entry)
169 proc_lustre_dir_entry = NULL; /* /proc/lustre */
171 remove_proc_entry(obd_entry->name, obd_dir);
175 void proc_lustre_release_obd_device(struct obd_device *obd)
177 proc_lustre_remove_obd_entry("status", obd);
181 #else /* CONFIG_PROC_FS */
183 struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd)
188 void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd)
192 void proc_lustre_release_obd_device(struct obd_device *obd)
196 #endif /* CONFIG_PROC_FS */
198 EXPORT_SYMBOL(proc_lustre_remove_obd_entry);