From 2e5bbb95b48b2446cd646e5b9515bf3933a2d7bd Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Thu, 14 Nov 2019 13:58:30 +0100 Subject: [PATCH] Write zone metadata in a single write() --- libcbd/format.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libcbd/format.c b/libcbd/format.c index 3b50fbd..04c2962 100644 --- a/libcbd/format.c +++ b/libcbd/format.c @@ -36,7 +36,8 @@ cbd_format(const char* dev, uint pblk_size; uint lblk_size; struct cbd_header header; - uint8_t buf[PAGE_SIZE]; + uint8_t header_buf[PAGE_SIZE]; + uint8_t* data_buf; uint64_t pblk; uint64_t zone_idx; @@ -132,26 +133,22 @@ cbd_format(const char* dev, printf(" nr_zones=%lu\n", (unsigned long)header.params.nr_zones); printf(" lblk_per_zone=%lu\n", (unsigned long)header.params.lblk_per_zone); - memset(buf, 0, sizeof(buf)); - cbd_header_put(buf, &header); + memset(header_buf, 0, sizeof(header_buf)); + cbd_header_put(header_buf, &header); pblk = 0; - pblk_write(devfd, pblk_size, pblk, 1, buf); + pblk_write(devfd, pblk_size, pblk, 1, header_buf); pblk += CBD_HEADER_BLOCKS; printf("Writing %lu zones ...\n", (unsigned long)header.params.nr_zones); - memset(buf, 0, sizeof(buf)); + data_buf = calloc(zone_metadata_len(&header.params), PAGE_SIZE); for (zone_idx = 0; zone_idx < header.params.nr_zones; ++zone_idx) { - uint32_t count; - uint32_t n; pblk = zone_off(&header.params, zone_idx); - count = zone_metadata_len(&header.params); - for (n = 0; n < count; ++n) { - pblk_write(devfd, pblk_size, pblk + n, 1, buf); - } + pblk_write(devfd, pblk_size, pblk, zone_metadata_len(&header.params), data_buf); } + free(data_buf); return 0; }