diff options
author | David Teigland <teigland@redhat.com> | 2017-08-07 16:52:14 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2017-10-16 11:17:12 -0500 |
commit | 147e1d4f1dd02be48e427059d942d749a104be09 (patch) | |
tree | 4a63e00033cae7e05cbc51119f9137bbcd381c8a | |
parent | 26e205bf1c94fc7806fbeedc1811e3863c3a91c9 (diff) | |
download | lvm2-147e1d4f1dd02be48e427059d942d749a104be09.tar.gz |
scanning: allocate label data struct from mem pool
Use a separate alloc/free loop for ld structs from
mem pool vs the aio-related structs that are not
from pool.
-rw-r--r-- | lib/label/label.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/label/label.c b/lib/label/label.c index 6662be00c..0fc93f0b9 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -453,12 +453,15 @@ static void _free_label_read_list(int do_close) { struct label_read_data *ld, *ld2; - dm_list_iterate_items_safe(ld, ld2, &label_read_list) { - dm_list_del(&ld->list); + dm_list_iterate_items(ld, &label_read_list) { if (do_close) dev_close(ld->dev); if (ld->aio) dev_async_io_destroy(ld->aio); + } + + dm_list_iterate_items_safe(ld, ld2, &label_read_list) { + dm_list_del(&ld->list); free(ld); } } @@ -651,23 +654,25 @@ int label_scan_async(struct cmd_context *cmd) * of the posix_memalign below. Try using mem pool to allocate * all the ld structs first, then allocate all aio and aio->buf. */ - if (!(ld = malloc(sizeof(*ld)))) + if (!(ld = dm_malloc(sizeof(*ld)))) goto_bad; memset(ld, 0, sizeof(*ld)); - if (!(ld->aio = dev_async_io_alloc(buf_len))) - goto_bad; - ld->dev = dev; - ld->buf = ld->aio->buf; - ld->buf_len = buf_len; - dm_list_add(&label_read_list, &ld->list); dev_count++; }; dev_iter_destroy(iter); + dm_list_iterate_items(ld, &label_read_list) { + if (!(ld->aio = dev_async_io_alloc(buf_len))) + goto_bad; + + ld->buf = ld->aio->buf; + ld->buf_len = buf_len; + } + /* * Start the aio reads on each dev. Flag any that * fail and the next loop will try a sync read for it. @@ -754,12 +759,16 @@ bad: dev_iter_destroy(iter); dev_async_context_destroy(ac); - dm_list_iterate_items_safe(ld, ld2, &label_read_list) { - dm_list_del(&ld->list); + dm_list_iterate_items(ld, &label_read_list) { dev_close(ld->dev); dev_async_io_destroy(ld->aio); - free(ld); } + + dm_list_iterate_items_safe(ld, ld2, &label_read_list) { + dm_list_del(&ld->list); + dm_free(ld); + } + return 0; } |