Until now, the allocation of the in-core bitmaps was done in pre-resume by metadata_resize(). In preparation for the next commit, which makes it possible for a metadata operation, e.g. an era rollover, to run before pre-resume runs, allocate the in-core bitmaps as part of opening the metadata. Also, set the number of blocks of the era device in era_ctr() to the number of blocks in the metadata. This avoids attempting to resize the metadata every time we create a new target instance, even if the metadata size hasn't changed. Fixes: eec40579d8487 ("dm: add era target") Cc: stable@xxxxxxxxxxxxxxx # v3.15+ Signed-off-by: Nikos Tsironis <ntsironis@xxxxxxxxxxx> --- drivers/md/dm-era-target.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c index e92c1afc3677..3332bed2f412 100644 --- a/drivers/md/dm-era-target.c +++ b/drivers/md/dm-era-target.c @@ -788,6 +788,7 @@ static int metadata_digest_start(struct era_metadata *md, struct digest *d) * High level metadata interface. Target methods should use these, and not * the lower level ones. *--------------------------------------------------------------*/ +static void metadata_close(struct era_metadata *md); static struct era_metadata *metadata_open(struct block_device *bdev, sector_t block_size, bool may_format) @@ -811,6 +812,24 @@ static struct era_metadata *metadata_open(struct block_device *bdev, return ERR_PTR(r); } + if (md->nr_blocks == 0) + return md; + + /* Allocate in-core writesets */ + r = writeset_alloc(&md->writesets[0], md->nr_blocks); + if (r) { + DMERR("%s: writeset_alloc failed for writeset 0", __func__); + metadata_close(md); + return ERR_PTR(r); + } + + r = writeset_alloc(&md->writesets[1], md->nr_blocks); + if (r) { + DMERR("%s: writeset_alloc failed for writeset 1", __func__); + metadata_close(md); + return ERR_PTR(r); + } + return md; } @@ -1504,6 +1523,7 @@ static int era_ctr(struct dm_target *ti, unsigned argc, char **argv) return PTR_ERR(md); } era->md = md; + era->nr_blocks = md->nr_blocks; era->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM); if (!era->wq) { -- 2.30.2 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel