dm thin metadata: don't treat a device id lookup error as unused
PATCH 1/1 dm thin metadata: don't treat a device id lookup error as unused
Both __create_thin() and __create_snap() check that the device id is unused before creating the device. The check only tests for a successful lookup, so it treats any lookup error as an unused id and proceeds to the create path.
On a lookup error such as -EIO, the create path inserts the device into the top-level tree. If the id already exists, the insert overwrites its entry and deletes the corresponding mapping tree. This happens before __open_device() runs, so __open_device() cannot catch it.
Fix by propagating the lookup error and creating the device only on -ENODATA.
Fixes 991d9fa02da0 ("dm: add thin provisioning target")
Signed-off-by Ming-Hung Tsai <[email protected]>
--- drivers/md/dm-thin-metadata.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/dm-thin-metadata.c +4 -4
@@ -1116,8 +1116,8 @@ static int __create_thin(struct dm_pool_metadata *pmd, r =dm_btree_lookup (&pmd->details_info, pmd->details_root, &key,NULL ); -if (!r) -return -EEXIST ; +if (r != -ENODATA ) +return r ? r : -EEXIST ;/* * Create an empty btree for the mappings.
@@ -1193,8 +1193,8 @@ static int __create_snap(struct dm_pool_metadata *pmd,/* check this device is unused */ r =dm_btree_lookup (&pmd->details_info, pmd->details_root, &dev_key,NULL ); -if (!r) -return -EEXIST ; +if (r != -ENODATA ) +return r ? r : -EEXIST ;/* find the mapping tree for the origin */ r =dm_btree_lookup (&pmd->tl_info, pmd->root, &key, &value);
Signature · 1 line
2.49.0