configfs: Convert subsystem semaphore to mutex
Convert the su_sem member of struct configfs_subsystem to a struct
mutex, as that's what it is. Also convert all the users and update
Documentation/configfs.txt and Documentation/configfs_example.c
accordingly.
[ Conflict in fs/dlm/config.c with commit
3168b0780d
manually resolved. --Mark ]
Inspired-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
This commit is contained in:
parent
3fe6c5ce11
commit
e6bd07aee7
|
@ -280,18 +280,18 @@ tells configfs to make the subsystem appear in the file tree.
|
||||||
|
|
||||||
struct configfs_subsystem {
|
struct configfs_subsystem {
|
||||||
struct config_group su_group;
|
struct config_group su_group;
|
||||||
struct semaphore su_sem;
|
struct mutex su_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
int configfs_register_subsystem(struct configfs_subsystem *subsys);
|
int configfs_register_subsystem(struct configfs_subsystem *subsys);
|
||||||
void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
|
void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
|
||||||
|
|
||||||
A subsystem consists of a toplevel config_group and a semaphore.
|
A subsystem consists of a toplevel config_group and a mutex.
|
||||||
The group is where child config_items are created. For a subsystem,
|
The group is where child config_items are created. For a subsystem,
|
||||||
this group is usually defined statically. Before calling
|
this group is usually defined statically. Before calling
|
||||||
configfs_register_subsystem(), the subsystem must have initialized the
|
configfs_register_subsystem(), the subsystem must have initialized the
|
||||||
group via the usual group _init() functions, and it must also have
|
group via the usual group _init() functions, and it must also have
|
||||||
initialized the semaphore.
|
initialized the mutex.
|
||||||
When the register call returns, the subsystem is live, and it
|
When the register call returns, the subsystem is live, and it
|
||||||
will be visible via configfs. At that point, mkdir(2) can be called and
|
will be visible via configfs. At that point, mkdir(2) can be called and
|
||||||
the subsystem must be ready for it.
|
the subsystem must be ready for it.
|
||||||
|
@ -303,7 +303,7 @@ subsystem/group and the simple_child item in configfs_example.c It
|
||||||
shows a trivial object displaying and storing an attribute, and a simple
|
shows a trivial object displaying and storing an attribute, and a simple
|
||||||
group creating and destroying these children.
|
group creating and destroying these children.
|
||||||
|
|
||||||
[Hierarchy Navigation and the Subsystem Semaphore]
|
[Hierarchy Navigation and the Subsystem Mutex]
|
||||||
|
|
||||||
There is an extra bonus that configfs provides. The config_groups and
|
There is an extra bonus that configfs provides. The config_groups and
|
||||||
config_items are arranged in a hierarchy due to the fact that they
|
config_items are arranged in a hierarchy due to the fact that they
|
||||||
|
@ -314,19 +314,19 @@ and config_item->ci_parent structure members.
|
||||||
|
|
||||||
A subsystem can navigate the cg_children list and the ci_parent pointer
|
A subsystem can navigate the cg_children list and the ci_parent pointer
|
||||||
to see the tree created by the subsystem. This can race with configfs'
|
to see the tree created by the subsystem. This can race with configfs'
|
||||||
management of the hierarchy, so configfs uses the subsystem semaphore to
|
management of the hierarchy, so configfs uses the subsystem mutex to
|
||||||
protect modifications. Whenever a subsystem wants to navigate the
|
protect modifications. Whenever a subsystem wants to navigate the
|
||||||
hierarchy, it must do so under the protection of the subsystem
|
hierarchy, it must do so under the protection of the subsystem
|
||||||
semaphore.
|
mutex.
|
||||||
|
|
||||||
A subsystem will be prevented from acquiring the semaphore while a newly
|
A subsystem will be prevented from acquiring the mutex while a newly
|
||||||
allocated item has not been linked into this hierarchy. Similarly, it
|
allocated item has not been linked into this hierarchy. Similarly, it
|
||||||
will not be able to acquire the semaphore while a dropping item has not
|
will not be able to acquire the mutex while a dropping item has not
|
||||||
yet been unlinked. This means that an item's ci_parent pointer will
|
yet been unlinked. This means that an item's ci_parent pointer will
|
||||||
never be NULL while the item is in configfs, and that an item will only
|
never be NULL while the item is in configfs, and that an item will only
|
||||||
be in its parent's cg_children list for the same duration. This allows
|
be in its parent's cg_children list for the same duration. This allows
|
||||||
a subsystem to trust ci_parent and cg_children while they hold the
|
a subsystem to trust ci_parent and cg_children while they hold the
|
||||||
semaphore.
|
mutex.
|
||||||
|
|
||||||
[Item Aggregation Via symlink(2)]
|
[Item Aggregation Via symlink(2)]
|
||||||
|
|
||||||
|
|
|
@ -453,7 +453,7 @@ static int __init configfs_example_init(void)
|
||||||
subsys = example_subsys[i];
|
subsys = example_subsys[i];
|
||||||
|
|
||||||
config_group_init(&subsys->su_group);
|
config_group_init(&subsys->su_group);
|
||||||
init_MUTEX(&subsys->su_sem);
|
mutex_init(&subsys->su_mutex);
|
||||||
ret = configfs_register_subsystem(subsys);
|
ret = configfs_register_subsystem(subsys);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "Error %d while registering subsystem %s\n",
|
printk(KERN_ERR "Error %d while registering subsystem %s\n",
|
||||||
|
|
|
@ -562,7 +562,7 @@ static int populate_groups(struct config_group *group)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All of link_obj/unlink_obj/link_group/unlink_group require that
|
* All of link_obj/unlink_obj/link_group/unlink_group require that
|
||||||
* subsys->su_sem is held.
|
* subsys->su_mutex is held.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void unlink_obj(struct config_item *item)
|
static void unlink_obj(struct config_item *item)
|
||||||
|
@ -783,7 +783,7 @@ static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||||
|
|
||||||
snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
|
snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
|
||||||
|
|
||||||
down(&subsys->su_sem);
|
mutex_lock(&subsys->su_mutex);
|
||||||
group = NULL;
|
group = NULL;
|
||||||
item = NULL;
|
item = NULL;
|
||||||
if (type->ct_group_ops->make_group) {
|
if (type->ct_group_ops->make_group) {
|
||||||
|
@ -797,7 +797,7 @@ static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||||
if (item)
|
if (item)
|
||||||
link_obj(parent_item, item);
|
link_obj(parent_item, item);
|
||||||
}
|
}
|
||||||
up(&subsys->su_sem);
|
mutex_unlock(&subsys->su_mutex);
|
||||||
|
|
||||||
kfree(name);
|
kfree(name);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
|
@ -841,13 +841,13 @@ static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||||
out_unlink:
|
out_unlink:
|
||||||
if (ret) {
|
if (ret) {
|
||||||
/* Tear down everything we built up */
|
/* Tear down everything we built up */
|
||||||
down(&subsys->su_sem);
|
mutex_lock(&subsys->su_mutex);
|
||||||
if (group)
|
if (group)
|
||||||
unlink_group(group);
|
unlink_group(group);
|
||||||
else
|
else
|
||||||
unlink_obj(item);
|
unlink_obj(item);
|
||||||
client_drop_item(parent_item, item);
|
client_drop_item(parent_item, item);
|
||||||
up(&subsys->su_sem);
|
mutex_unlock(&subsys->su_mutex);
|
||||||
|
|
||||||
if (module_got)
|
if (module_got)
|
||||||
module_put(owner);
|
module_put(owner);
|
||||||
|
@ -910,17 +910,17 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
|
||||||
if (sd->s_type & CONFIGFS_USET_DIR) {
|
if (sd->s_type & CONFIGFS_USET_DIR) {
|
||||||
configfs_detach_group(item);
|
configfs_detach_group(item);
|
||||||
|
|
||||||
down(&subsys->su_sem);
|
mutex_lock(&subsys->su_mutex);
|
||||||
unlink_group(to_config_group(item));
|
unlink_group(to_config_group(item));
|
||||||
} else {
|
} else {
|
||||||
configfs_detach_item(item);
|
configfs_detach_item(item);
|
||||||
|
|
||||||
down(&subsys->su_sem);
|
mutex_lock(&subsys->su_mutex);
|
||||||
unlink_obj(item);
|
unlink_obj(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
client_drop_item(parent_item, item);
|
client_drop_item(parent_item, item);
|
||||||
up(&subsys->su_sem);
|
mutex_unlock(&subsys->su_mutex);
|
||||||
|
|
||||||
/* Drop our reference from above */
|
/* Drop our reference from above */
|
||||||
config_item_put(item);
|
config_item_put(item);
|
||||||
|
|
|
@ -607,7 +607,7 @@ static struct clusters clusters_root = {
|
||||||
int dlm_config_init(void)
|
int dlm_config_init(void)
|
||||||
{
|
{
|
||||||
config_group_init(&clusters_root.subsys.su_group);
|
config_group_init(&clusters_root.subsys.su_group);
|
||||||
init_MUTEX(&clusters_root.subsys.su_sem);
|
mutex_init(&clusters_root.subsys.su_mutex);
|
||||||
return configfs_register_subsystem(&clusters_root.subsys);
|
return configfs_register_subsystem(&clusters_root.subsys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,9 +751,9 @@ static struct space *get_space(char *name)
|
||||||
if (!space_list)
|
if (!space_list)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
down(&space_list->cg_subsys->su_sem);
|
mutex_lock(&space_list->cg_subsys->su_mutex);
|
||||||
i = config_group_find_item(space_list, name);
|
i = config_group_find_item(space_list, name);
|
||||||
up(&space_list->cg_subsys->su_sem);
|
mutex_unlock(&space_list->cg_subsys->su_mutex);
|
||||||
|
|
||||||
return to_space(i);
|
return to_space(i);
|
||||||
}
|
}
|
||||||
|
@ -772,7 +772,7 @@ static struct comm *get_comm(int nodeid, struct sockaddr_storage *addr)
|
||||||
if (!comm_list)
|
if (!comm_list)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
down(&clusters_root.subsys.su_sem);
|
mutex_lock(&clusters_root.subsys.su_mutex);
|
||||||
|
|
||||||
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
|
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
|
||||||
cm = to_comm(i);
|
cm = to_comm(i);
|
||||||
|
@ -792,7 +792,7 @@ static struct comm *get_comm(int nodeid, struct sockaddr_storage *addr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
up(&clusters_root.subsys.su_sem);
|
mutex_unlock(&clusters_root.subsys.su_mutex);
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
cm = NULL;
|
cm = NULL;
|
||||||
|
|
|
@ -934,7 +934,7 @@ static int __init init_o2nm(void)
|
||||||
goto out_sysctl;
|
goto out_sysctl;
|
||||||
|
|
||||||
config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
|
config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
|
||||||
init_MUTEX(&o2nm_cluster_group.cs_subsys.su_sem);
|
mutex_init(&o2nm_cluster_group.cs_subsys.su_mutex);
|
||||||
ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
|
ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
|
printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/kref.h>
|
#include <linux/kref.h>
|
||||||
|
#include <linux/mutex.h>
|
||||||
|
|
||||||
#include <asm/atomic.h>
|
#include <asm/atomic.h>
|
||||||
#include <asm/semaphore.h>
|
|
||||||
|
|
||||||
#define CONFIGFS_ITEM_NAME_LEN 20
|
#define CONFIGFS_ITEM_NAME_LEN 20
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ struct configfs_group_operations {
|
||||||
|
|
||||||
struct configfs_subsystem {
|
struct configfs_subsystem {
|
||||||
struct config_group su_group;
|
struct config_group su_group;
|
||||||
struct semaphore su_sem;
|
struct mutex su_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
|
static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
|
||||||
|
|
Loading…
Reference in a new issue