summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2017-08-07 16:52:14 -0500
committerDavid Teigland <teigland@redhat.com>2017-10-18 14:09:12 -0500
commit99e56c9f77770c5b04df634f5dab7eca27f58240 (patch)
tree22e35ab3e011347aef73bb25926d40dd6f5915db
parent37d8fc2836c37d1e0ceb742f537c5862fe7c5f7c (diff)
downloadlvm2-99e56c9f77770c5b04df634f5dab7eca27f58240.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.c33
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;
}