diff options
author | Christoph Hellwig <hch@lst.de> | 2016-02-26 05:02:14 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2016-03-06 10:11:24 -0500 |
commit | 1ae1602de028acaa42a0f6ff18d19756f8e825c6 (patch) | |
tree | 3370e5c29945370f62b9c72adeec587ed102d048 /fs/dlm | |
parent | b1f1a29d8fb5eeaeec2cafe4c62f276d950c015b (diff) |
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>
Diffstat (limited to 'fs/dlm')
-rw-r--r-- | fs/dlm/config.c | 38 |
1 files changed, 7 insertions, 31 deletions
diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 8e294fbbac39..519112168a9e 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c | |||
@@ -346,7 +346,6 @@ static struct config_group *make_cluster(struct config_group *g, | |||
346 | void *gps = NULL; | 346 | void *gps = NULL; |
347 | 347 | ||
348 | cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS); | 348 | cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS); |
349 | gps = kcalloc(3, sizeof(struct config_group *), GFP_NOFS); | ||
350 | sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS); | 349 | sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS); |
351 | cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS); | 350 | cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS); |
352 | 351 | ||
@@ -357,10 +356,8 @@ static struct config_group *make_cluster(struct config_group *g, | |||
357 | config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type); | 356 | config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type); |
358 | config_group_init_type_name(&cms->cs_group, "comms", &comms_type); | 357 | config_group_init_type_name(&cms->cs_group, "comms", &comms_type); |
359 | 358 | ||
360 | cl->group.default_groups = gps; | 359 | configfs_add_default_group(&sps->ss_group, &cl->group); |
361 | cl->group.default_groups[0] = &sps->ss_group; | 360 | configfs_add_default_group(&cms->cs_group, &cl->group); |
362 | cl->group.default_groups[1] = &cms->cs_group; | ||
363 | cl->group.default_groups[2] = NULL; | ||
364 | 361 | ||
365 | cl->cl_tcp_port = dlm_config.ci_tcp_port; | 362 | cl->cl_tcp_port = dlm_config.ci_tcp_port; |
366 | cl->cl_buffer_size = dlm_config.ci_buffer_size; | 363 | cl->cl_buffer_size = dlm_config.ci_buffer_size; |
@@ -383,7 +380,6 @@ static struct config_group *make_cluster(struct config_group *g, | |||
383 | 380 | ||
384 | fail: | 381 | fail: |
385 | kfree(cl); | 382 | kfree(cl); |
386 | kfree(gps); | ||
387 | kfree(sps); | 383 | kfree(sps); |
388 | kfree(cms); | 384 | kfree(cms); |
389 | return ERR_PTR(-ENOMEM); | 385 | return ERR_PTR(-ENOMEM); |
@@ -392,14 +388,8 @@ static struct config_group *make_cluster(struct config_group *g, | |||
392 | static void drop_cluster(struct config_group *g, struct config_item *i) | 388 | static void drop_cluster(struct config_group *g, struct config_item *i) |
393 | { | 389 | { |
394 | struct dlm_cluster *cl = config_item_to_cluster(i); | 390 | struct dlm_cluster *cl = config_item_to_cluster(i); |
395 | struct config_item *tmp; | ||
396 | int j; | ||
397 | 391 | ||
398 | for (j = 0; cl->group.default_groups[j]; j++) { | 392 | configfs_remove_default_groups(&cl->group); |
399 | tmp = &cl->group.default_groups[j]->cg_item; | ||
400 | cl->group.default_groups[j] = NULL; | ||
401 | config_item_put(tmp); | ||
402 | } | ||
403 | 393 | ||
404 | space_list = NULL; | 394 | space_list = NULL; |
405 | comm_list = NULL; | 395 | comm_list = NULL; |
@@ -410,7 +400,6 @@ static void drop_cluster(struct config_group *g, struct config_item *i) | |||
410 | static void release_cluster(struct config_item *i) | 400 | static void release_cluster(struct config_item *i) |
411 | { | 401 | { |
412 | struct dlm_cluster *cl = config_item_to_cluster(i); | 402 | struct dlm_cluster *cl = config_item_to_cluster(i); |
413 | kfree(cl->group.default_groups); | ||
414 | kfree(cl); | 403 | kfree(cl); |
415 | } | 404 | } |
416 | 405 | ||
@@ -418,21 +407,17 @@ static struct config_group *make_space(struct config_group *g, const char *name) | |||
418 | { | 407 | { |
419 | struct dlm_space *sp = NULL; | 408 | struct dlm_space *sp = NULL; |
420 | struct dlm_nodes *nds = NULL; | 409 | struct dlm_nodes *nds = NULL; |
421 | void *gps = NULL; | ||
422 | 410 | ||
423 | sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS); | 411 | sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS); |
424 | gps = kcalloc(2, sizeof(struct config_group *), GFP_NOFS); | ||
425 | nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS); | 412 | nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS); |
426 | 413 | ||
427 | if (!sp || !gps || !nds) | 414 | if (!sp || !nds) |
428 | goto fail; | 415 | goto fail; |
429 | 416 | ||
430 | config_group_init_type_name(&sp->group, name, &space_type); | 417 | config_group_init_type_name(&sp->group, name, &space_type); |
431 | config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type); | ||
432 | 418 | ||
433 | sp->group.default_groups = gps; | 419 | config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type); |
434 | sp->group.default_groups[0] = &nds->ns_group; | 420 | configfs_add_default_group(&nds->ns_group, &sp->group); |
435 | sp->group.default_groups[1] = NULL; | ||
436 | 421 | ||
437 | INIT_LIST_HEAD(&sp->members); | 422 | INIT_LIST_HEAD(&sp->members); |
438 | mutex_init(&sp->members_lock); | 423 | mutex_init(&sp->members_lock); |
@@ -441,7 +426,6 @@ static struct config_group *make_space(struct config_group *g, const char *name) | |||
441 | 426 | ||
442 | fail: | 427 | fail: |
443 | kfree(sp); | 428 | kfree(sp); |
444 | kfree(gps); | ||
445 | kfree(nds); | 429 | kfree(nds); |
446 | return ERR_PTR(-ENOMEM); | 430 | return ERR_PTR(-ENOMEM); |
447 | } | 431 | } |
@@ -449,24 +433,16 @@ static struct config_group *make_space(struct config_group *g, const char *name) | |||
449 | static void drop_space(struct config_group *g, struct config_item *i) | 433 | static void drop_space(struct config_group *g, struct config_item *i) |
450 | { | 434 | { |
451 | struct dlm_space *sp = config_item_to_space(i); | 435 | struct dlm_space *sp = config_item_to_space(i); |
452 | struct config_item *tmp; | ||
453 | int j; | ||
454 | 436 | ||
455 | /* assert list_empty(&sp->members) */ | 437 | /* assert list_empty(&sp->members) */ |
456 | 438 | ||
457 | for (j = 0; sp->group.default_groups[j]; j++) { | 439 | configfs_remove_default_groups(&sp->group); |
458 | tmp = &sp->group.default_groups[j]->cg_item; | ||
459 | sp->group.default_groups[j] = NULL; | ||
460 | config_item_put(tmp); | ||
461 | } | ||
462 | |||
463 | config_item_put(i); | 440 | config_item_put(i); |
464 | } | 441 | } |
465 | 442 | ||
466 | static void release_space(struct config_item *i) | 443 | static void release_space(struct config_item *i) |
467 | { | 444 | { |
468 | struct dlm_space *sp = config_item_to_space(i); | 445 | struct dlm_space *sp = config_item_to_space(i); |
469 | kfree(sp->group.default_groups); | ||
470 | kfree(sp); | 446 | kfree(sp); |
471 | } | 447 | } |
472 | 448 | ||