configfs: switch ->default groups to a linked list
Replace the current NULL-terminated array of default groups with a linked list. This gets rid of lots of nasty code to size and/or dynamically allocate the array. While we're at it also provide a conveniant helper to remove the default groups. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Felipe Balbi <balbi@kernel.org> [drivers/usb/gadget] Acked-by: Joel Becker <jlbec@evilplan.org> Acked-by: Nicholas Bellinger <nab@linux-iscsi.org> Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
This commit is contained in:
@@ -346,7 +346,6 @@ static struct config_group *make_cluster(struct config_group *g,
|
||||
void *gps = NULL;
|
||||
|
||||
cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS);
|
||||
gps = kcalloc(3, sizeof(struct config_group *), GFP_NOFS);
|
||||
sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS);
|
||||
cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS);
|
||||
|
||||
@@ -357,10 +356,8 @@ static struct config_group *make_cluster(struct config_group *g,
|
||||
config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type);
|
||||
config_group_init_type_name(&cms->cs_group, "comms", &comms_type);
|
||||
|
||||
cl->group.default_groups = gps;
|
||||
cl->group.default_groups[0] = &sps->ss_group;
|
||||
cl->group.default_groups[1] = &cms->cs_group;
|
||||
cl->group.default_groups[2] = NULL;
|
||||
configfs_add_default_group(&sps->ss_group, &cl->group);
|
||||
configfs_add_default_group(&cms->cs_group, &cl->group);
|
||||
|
||||
cl->cl_tcp_port = dlm_config.ci_tcp_port;
|
||||
cl->cl_buffer_size = dlm_config.ci_buffer_size;
|
||||
@@ -383,7 +380,6 @@ static struct config_group *make_cluster(struct config_group *g,
|
||||
|
||||
fail:
|
||||
kfree(cl);
|
||||
kfree(gps);
|
||||
kfree(sps);
|
||||
kfree(cms);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
@@ -392,14 +388,8 @@ static struct config_group *make_cluster(struct config_group *g,
|
||||
static void drop_cluster(struct config_group *g, struct config_item *i)
|
||||
{
|
||||
struct dlm_cluster *cl = config_item_to_cluster(i);
|
||||
struct config_item *tmp;
|
||||
int j;
|
||||
|
||||
for (j = 0; cl->group.default_groups[j]; j++) {
|
||||
tmp = &cl->group.default_groups[j]->cg_item;
|
||||
cl->group.default_groups[j] = NULL;
|
||||
config_item_put(tmp);
|
||||
}
|
||||
configfs_remove_default_groups(&cl->group);
|
||||
|
||||
space_list = NULL;
|
||||
comm_list = NULL;
|
||||
@@ -410,7 +400,6 @@ static void drop_cluster(struct config_group *g, struct config_item *i)
|
||||
static void release_cluster(struct config_item *i)
|
||||
{
|
||||
struct dlm_cluster *cl = config_item_to_cluster(i);
|
||||
kfree(cl->group.default_groups);
|
||||
kfree(cl);
|
||||
}
|
||||
|
||||
@@ -418,21 +407,17 @@ static struct config_group *make_space(struct config_group *g, const char *name)
|
||||
{
|
||||
struct dlm_space *sp = NULL;
|
||||
struct dlm_nodes *nds = NULL;
|
||||
void *gps = NULL;
|
||||
|
||||
sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS);
|
||||
gps = kcalloc(2, sizeof(struct config_group *), GFP_NOFS);
|
||||
nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS);
|
||||
|
||||
if (!sp || !gps || !nds)
|
||||
if (!sp || !nds)
|
||||
goto fail;
|
||||
|
||||
config_group_init_type_name(&sp->group, name, &space_type);
|
||||
config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type);
|
||||
|
||||
sp->group.default_groups = gps;
|
||||
sp->group.default_groups[0] = &nds->ns_group;
|
||||
sp->group.default_groups[1] = NULL;
|
||||
config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type);
|
||||
configfs_add_default_group(&nds->ns_group, &sp->group);
|
||||
|
||||
INIT_LIST_HEAD(&sp->members);
|
||||
mutex_init(&sp->members_lock);
|
||||
@@ -441,7 +426,6 @@ static struct config_group *make_space(struct config_group *g, const char *name)
|
||||
|
||||
fail:
|
||||
kfree(sp);
|
||||
kfree(gps);
|
||||
kfree(nds);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
@@ -449,24 +433,16 @@ static struct config_group *make_space(struct config_group *g, const char *name)
|
||||
static void drop_space(struct config_group *g, struct config_item *i)
|
||||
{
|
||||
struct dlm_space *sp = config_item_to_space(i);
|
||||
struct config_item *tmp;
|
||||
int j;
|
||||
|
||||
/* assert list_empty(&sp->members) */
|
||||
|
||||
for (j = 0; sp->group.default_groups[j]; j++) {
|
||||
tmp = &sp->group.default_groups[j]->cg_item;
|
||||
sp->group.default_groups[j] = NULL;
|
||||
config_item_put(tmp);
|
||||
}
|
||||
|
||||
configfs_remove_default_groups(&sp->group);
|
||||
config_item_put(i);
|
||||
}
|
||||
|
||||
static void release_space(struct config_item *i)
|
||||
{
|
||||
struct dlm_space *sp = config_item_to_space(i);
|
||||
kfree(sp->group.default_groups);
|
||||
kfree(sp);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user