1 /* proc_lustre.c manages /proc/lustre/obd.
3 * OBD devices materialize in /proc as a directory:
4 * /proc/lustre/obd/<number>
5 * when /dev/obd<number> is opened. When the device is closed, the
6 * directory entry disappears.
8 * For each open OBD device, code in this file also creates a file
9 * named <status>. "cat /proc/lustre/obd/<number>/status" gives
10 * information about the OBD device's configuration.
11 * The class driver manages the "status" entry.
13 * Other logical drivers can create their own entries. For example,
14 * the obdtrace driver creates /proc/lustre/obd/<obdid>/stats entry.
16 * This file defines three functions
17 * proc_lustre_register_obd_device()
18 * proc_lustre_release_obd_device()
19 * proc_lustre_remove_obd_entry()
20 * that dynamically create/delete /proc/lustre/obd entries:
22 * proc_lustre_register_obd_device() registers an obd device,
23 * and, if this is the first OBD device, creates /proc/lustre/obd.
25 * proc_lustre_release_obd_device() removes device information
26 * from /proc/lustre/obd, and if this is the last OBD device
27 * removes /proc/lustre/obd.
29 * proc_lustre_remove_obd_entry() removes a
30 * /proc/lustre/obd/<obdid>/ entry by name. This is the only
31 * function that is exported to other modules.
33 * Copyright (c) 2001 Rumi Zahir <rumi.zahir@intel.com>
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/version.h>
39 #include <linux/proc_fs.h>
41 #include <linux/obd_support.h>
42 #include <linux/obd_class.h>
46 extern struct proc_dir_entry proc_root;
48 static struct proc_dir_entry *proc_lustre_dir_entry = 0;
49 static struct proc_dir_entry *proc_lustre_obd_dir_entry = 0;
51 static struct proc_dir_entry *
52 proc_lustre_mkdir(const char* dname, struct proc_dir_entry *parent)
54 struct proc_dir_entry *child_dir_entry;
56 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) /*0x20300 */
57 child_dir_entry = proc_mkdir(dname, parent);
59 child_dir_entry = create_proc_entry(dname,
60 S_IFDIR | S_IRUGO | S_IXUGO,
64 printk ("lustre: failed to create /proc entry %s\n", dname);
66 return child_dir_entry;
69 static int read_lustre_status(char *page, char **start, off_t offset,
70 int count, int *eof, void *data)
72 struct obd_device * obddev = (struct obd_device *) data;
75 p = sprintf(&page[0], "/dev/obd%d: ", obddev->obd_minor);
77 if (obddev->obd_refcnt==0) {
79 p += sprintf(&page[p], "open but unused\n\0");
81 else { /* obd in use */
82 p += sprintf(&page[p], "refcnt(%d)", obddev->obd_refcnt);
84 if (obddev->obd_flags & OBD_ATTACHED) {
85 p += sprintf(&page[p], ", attached(%s)",
86 obddev->obd_type->typ_name);
89 if (obddev->obd_flags & OBD_SET_UP) {
90 struct dentry *my_dentry;
91 struct vfsmount *root_mnt;
95 if (!(pathpage = (char*) __get_free_page(GFP_KERNEL)))
98 my_dentry = obddev->obd_fsname.dentry;
99 root_mnt = mntget(current->fs->rootmnt);
100 path = d_path(my_dentry,root_mnt,pathpage,PAGE_SIZE);
102 p += sprintf(&page[p], ", setup(%s)", path);
104 free_page((unsigned long) pathpage);
107 /* print connections */
109 struct list_head * lh;
110 struct obd_client * cli=0;
112 lh = &obddev->obd_gen_clients;
113 while ((lh = lh->next) != &obddev->obd_gen_clients) {
114 p += sprintf(&page[p],
115 ((cli==0) ? ", connections(" : ",") );
116 cli = list_entry(lh, struct obd_client, cli_chain);
117 p += sprintf(&page[p], "%d", cli->cli_id);
119 if (cli!=0) { /* there was at least one client */
120 p += sprintf(&page[p], ")");
124 p += sprintf(&page[p], "\n\0");
127 /* Compute eof and return value */
129 if (offset + count >= p) {
136 struct proc_dir_entry *
137 proc_lustre_register_obd_device(struct obd_device *obd)
140 struct proc_dir_entry *obd_dir;
141 struct proc_dir_entry *obd_status = 0;
143 if (!proc_lustre_dir_entry) {
144 proc_lustre_dir_entry =
145 proc_lustre_mkdir("lustre", &proc_root);
146 if (!proc_lustre_dir_entry)
149 proc_lustre_obd_dir_entry =
150 proc_lustre_mkdir("obd", proc_lustre_dir_entry);
151 if (!proc_lustre_obd_dir_entry)
155 sprintf(obdname, "%d", obd->obd_minor);
157 obd_dir = proc_lustre_mkdir(obdname, proc_lustre_obd_dir_entry);
160 obd_status = create_proc_entry("status", S_IRUSR | S_IFREG, obd_dir);
163 obd_status->read_proc = read_lustre_status;
164 obd_status->data = (void*) obd;
170 void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd)
172 struct proc_dir_entry *obd_entry = 0;
173 struct proc_dir_entry *obd_dir = obd->obd_proc_entry;
175 remove_proc_entry(name, obd_dir);
177 while (obd_dir->subdir==0) {
178 /* if we removed last entry in this directory,
179 * then remove parent directory unless this
182 if (obd_dir == &proc_root)
186 obd_dir = obd_dir->parent;
188 /* If /proc/lustre/obd/XXX or /proc/lustre/obd or
189 * /proc/lustre are being removed, then reset
193 if (obd_entry == obd->obd_proc_entry)
194 obd->obd_proc_entry=0; /* /proc/lustre/obd/XXX */
196 if (obd_entry == proc_lustre_obd_dir_entry)
197 proc_lustre_obd_dir_entry=0;
199 if (obd_entry == proc_lustre_dir_entry)
200 proc_lustre_dir_entry=0;
202 remove_proc_entry(obd_entry->name, obd_dir);
206 void proc_lustre_release_obd_device(struct obd_device *obd)
208 proc_lustre_remove_obd_entry("status", obd);
212 #else /* CONFIG_PROC_FS */
214 struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd)
219 void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd) {}
220 void proc_lustre_release_obd_device(struct obd_device *obd) {}
222 #endif /* CONFIG_PROC_FS */
224 EXPORT_SYMBOL(proc_lustre_remove_obd_entry);