bdev: provide all available bdevs when loop bdevs
The bdev hot remove might be an async process. The bdev_open will return an error during the hot remove process. If someone invoke the bdev_get_bdevs API when a bdev is in the middle of a hot remove process, the spdk_for_each_bdev function will stop its loop when a bdev_open return an error. Thus the bdev_get_bdevs will only return partual bdevs or even return an empty list if the hot remove bdev is the first bdev in the loop. When spdk_for_each_bdev and spdk_for_each_bdev_leaf loop for each bdevs, if a bdev returns an error, we skip that bdev instead of stop the whole loop. Signed-off-by: Peng Yu <yupeng0921@gmail.com> Change-Id: Ib35b817e23e47569fc5762a883b4ff8e322ae173 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15322 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Reviewed-by: Mike Gerdts <mgerdts@nvidia.com> Reviewed-by: Xiaodong Liu <xiaodong.liu@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
parent
70f185ea51
commit
c0c333e2ed
@ -6997,6 +6997,12 @@ spdk_for_each_bdev(void *ctx, spdk_for_each_bdev_fn fn)
|
||||
rc = bdev_open(bdev, false, desc);
|
||||
if (rc != 0) {
|
||||
bdev_desc_free(desc);
|
||||
if (rc == -ENODEV) {
|
||||
/* Ignore the error and move to the next bdev. */
|
||||
rc = 0;
|
||||
bdev = spdk_bdev_next(bdev);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
@ -7035,6 +7041,12 @@ spdk_for_each_bdev_leaf(void *ctx, spdk_for_each_bdev_fn fn)
|
||||
rc = bdev_open(bdev, false, desc);
|
||||
if (rc != 0) {
|
||||
bdev_desc_free(desc);
|
||||
if (rc == -ENODEV) {
|
||||
/* Ignore the error and move to the next bdev. */
|
||||
rc = 0;
|
||||
bdev = spdk_bdev_next_leaf(bdev);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
|
@ -5939,6 +5939,7 @@ for_each_bdev_test(void)
|
||||
int rc, count;
|
||||
|
||||
bdev[0] = allocate_bdev("bdev0");
|
||||
bdev[0]->internal.status = SPDK_BDEV_STATUS_REMOVING;
|
||||
|
||||
bdev[1] = allocate_bdev("bdev1");
|
||||
rc = spdk_bdev_module_claim_bdev(bdev[1], NULL, &bdev_ut_if);
|
||||
@ -5963,13 +5964,14 @@ for_each_bdev_test(void)
|
||||
count = 0;
|
||||
rc = spdk_for_each_bdev(&count, count_bdevs);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(count == 8);
|
||||
CU_ASSERT(count == 7);
|
||||
|
||||
count = 0;
|
||||
rc = spdk_for_each_bdev_leaf(&count, count_bdevs);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(count == 5);
|
||||
CU_ASSERT(count == 4);
|
||||
|
||||
bdev[0]->internal.status = SPDK_BDEV_STATUS_READY;
|
||||
free_bdev(bdev[0]);
|
||||
free_bdev(bdev[1]);
|
||||
free_bdev(bdev[2]);
|
||||
|
Loading…
Reference in New Issue
Block a user