Commit c0c333e2 authored by yupeng's avatar yupeng Committed by Tomasz Zawadzki
Browse files

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: default avatarPeng Yu <yupeng0921@gmail.com>
Change-Id: Ib35b817e23e47569fc5762a883b4ff8e322ae173
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15322


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarMike Gerdts <mgerdts@nvidia.com>
Reviewed-by: default avatarXiaodong Liu <xiaodong.liu@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 70f185ea
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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);
+4 −2
Original line number Diff line number Diff line
@@ -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]);