提交 9372a828 编写于 作者: P Peter Oberparleiter 提交者: Heiko Carstens

s390/debug: fix debug area life cycle

Currently allocation and registration of s390dbf debug areas are tied
together. As a result, a debug area cannot be unregistered and
re-registered while any process has an associated debugfs file open.

Fix this by splitting alloc/release from register/unregister.
Signed-off-by: NPeter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
上级 12047778
...@@ -314,24 +314,6 @@ static debug_info_t *debug_info_create(const char *name, int pages_per_area, ...@@ -314,24 +314,6 @@ static debug_info_t *debug_info_create(const char *name, int pages_per_area,
goto out; goto out;
rc->mode = mode & ~S_IFMT; rc->mode = mode & ~S_IFMT;
/* create root directory */
rc->debugfs_root_entry = debugfs_create_dir(rc->name,
debug_debugfs_root_entry);
/* append new element to linked list */
if (!debug_area_first) {
/* first element in list */
debug_area_first = rc;
rc->prev = NULL;
} else {
/* append element to end of list */
debug_area_last->next = rc;
rc->prev = debug_area_last;
}
debug_area_last = rc;
rc->next = NULL;
refcount_set(&rc->ref_count, 1); refcount_set(&rc->ref_count, 1);
out: out:
return rc; return rc;
...@@ -391,27 +373,10 @@ static void debug_info_get(debug_info_t *db_info) ...@@ -391,27 +373,10 @@ static void debug_info_get(debug_info_t *db_info)
*/ */
static void debug_info_put(debug_info_t *db_info) static void debug_info_put(debug_info_t *db_info)
{ {
int i;
if (!db_info) if (!db_info)
return; return;
if (refcount_dec_and_test(&db_info->ref_count)) { if (refcount_dec_and_test(&db_info->ref_count))
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (!db_info->views[i])
continue;
debugfs_remove(db_info->debugfs_entries[i]);
}
debugfs_remove(db_info->debugfs_root_entry);
if (db_info == debug_area_first)
debug_area_first = db_info->next;
if (db_info == debug_area_last)
debug_area_last = db_info->prev;
if (db_info->prev)
db_info->prev->next = db_info->next;
if (db_info->next)
db_info->next->prev = db_info->prev;
debug_info_free(db_info); debug_info_free(db_info);
}
} }
/* /*
...@@ -635,6 +600,31 @@ static int debug_close(struct inode *inode, struct file *file) ...@@ -635,6 +600,31 @@ static int debug_close(struct inode *inode, struct file *file)
return 0; /* success */ return 0; /* success */
} }
/* Create debugfs entries and add to internal list. */
static void _debug_register(debug_info_t *id)
{
/* create root directory */
id->debugfs_root_entry = debugfs_create_dir(id->name,
debug_debugfs_root_entry);
/* append new element to linked list */
if (!debug_area_first) {
/* first element in list */
debug_area_first = id;
id->prev = NULL;
} else {
/* append element to end of list */
debug_area_last->next = id;
id->prev = debug_area_last;
}
debug_area_last = id;
id->next = NULL;
debug_register_view(id, &debug_level_view);
debug_register_view(id, &debug_flush_view);
debug_register_view(id, &debug_pages_view);
}
/** /**
* debug_register_mode() - creates and initializes debug area. * debug_register_mode() - creates and initializes debug area.
* *
...@@ -664,19 +654,16 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area, ...@@ -664,19 +654,16 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
if ((uid != 0) || (gid != 0)) if ((uid != 0) || (gid != 0))
pr_warn("Root becomes the owner of all s390dbf files in sysfs\n"); pr_warn("Root becomes the owner of all s390dbf files in sysfs\n");
BUG_ON(!initialized); BUG_ON(!initialized);
mutex_lock(&debug_mutex);
/* create new debug_info */ /* create new debug_info */
rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode); rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
if (!rc) if (rc) {
goto out; mutex_lock(&debug_mutex);
debug_register_view(rc, &debug_level_view); _debug_register(rc);
debug_register_view(rc, &debug_flush_view); mutex_unlock(&debug_mutex);
debug_register_view(rc, &debug_pages_view); } else {
out:
if (!rc)
pr_err("Registering debug feature %s failed\n", name); pr_err("Registering debug feature %s failed\n", name);
mutex_unlock(&debug_mutex); }
return rc; return rc;
} }
EXPORT_SYMBOL(debug_register_mode); EXPORT_SYMBOL(debug_register_mode);
...@@ -705,6 +692,27 @@ debug_info_t *debug_register(const char *name, int pages_per_area, ...@@ -705,6 +692,27 @@ debug_info_t *debug_register(const char *name, int pages_per_area,
} }
EXPORT_SYMBOL(debug_register); EXPORT_SYMBOL(debug_register);
/* Remove debugfs entries and remove from internal list. */
static void _debug_unregister(debug_info_t *id)
{
int i;
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (!id->views[i])
continue;
debugfs_remove(id->debugfs_entries[i]);
}
debugfs_remove(id->debugfs_root_entry);
if (id == debug_area_first)
debug_area_first = id->next;
if (id == debug_area_last)
debug_area_last = id->prev;
if (id->prev)
id->prev->next = id->next;
if (id->next)
id->next->prev = id->prev;
}
/** /**
* debug_unregister() - give back debug area. * debug_unregister() - give back debug area.
* *
...@@ -718,8 +726,10 @@ void debug_unregister(debug_info_t *id) ...@@ -718,8 +726,10 @@ void debug_unregister(debug_info_t *id)
if (!id) if (!id)
return; return;
mutex_lock(&debug_mutex); mutex_lock(&debug_mutex);
debug_info_put(id); _debug_unregister(id);
mutex_unlock(&debug_mutex); mutex_unlock(&debug_mutex);
debug_info_put(id);
} }
EXPORT_SYMBOL(debug_unregister); EXPORT_SYMBOL(debug_unregister);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册