Commit b7d84562 authored by Mike Gerdts's avatar Mike Gerdts Committed by Jim Harris
Browse files

lvol: add spdk_lvol_iter_immediate_clones()



Add an interator that calls a callback for each clone of a snapshot
volume. This follows the typical pattern of stopping iteration when the
callback returns non-zero.

Signed-off-by: default avatarMike Gerdts <mgerdts@nvidia.com>
Change-Id: If88ad769b72a19ba0993303e89da107db8a6adfc
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17545


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 30399f31
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@ multiple readers.

New function `spdk_env_get_main_core` was added.

### lvol

New API `spdk_lvol_iter_immediate_clones` was added to iterate the clones of an lvol.

### nvmf

New `spdk_nvmf_request_copy_to/from_buf()` APIs have been added, which support
+21 −0
Original line number Diff line number Diff line
@@ -115,6 +115,15 @@ typedef void (*spdk_lvol_op_with_handle_complete)(void *cb_arg, struct spdk_lvol
 */
typedef void (*spdk_lvol_op_complete)(void *cb_arg, int lvolerrno);

/**
 * Callback definition for spdk_lvol_iter_clones.
 *
 * \param lvol An iterated lvol.
 * \param cb_arg Opaque context passed to spdk_lvol_iter_clone().
 * \return 0 to continue iterating, any other value to stop iterating.
 */
typedef int (*spdk_lvol_iter_cb)(void *cb_arg, struct spdk_lvol *lvol);

/**
 * Initialize lvolstore on given bs_bdev.
 *
@@ -260,6 +269,18 @@ void spdk_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void
 */
void spdk_lvol_close(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);

/**
 * Iterate clones of an lvol.
 *
 * Iteration stops if cb_fn(cb_arg, clone_lvol) returns non-zero.
 *
 * \param lvol Handle to lvol.
 * \param cb_fn Function to call for each lvol that clones this lvol.
 * \param cb_arg Context to pass wtih cb_fn.
 * \return -ENOMEM if memory allocation failed, non-zero return from cb_fn(), or 0.
 */
int spdk_lvol_iter_immediate_clones(struct spdk_lvol *lvol, spdk_lvol_iter_cb cb_fn, void *cb_arg);

/**
 * Get I/O channel of bdev associated with specified lvol.
 *
+51 −0
Original line number Diff line number Diff line
@@ -2063,3 +2063,54 @@ spdk_lvs_notify_hotplug(const void *esnap_id, uint32_t id_len)

	return ret;
}

int
spdk_lvol_iter_immediate_clones(struct spdk_lvol *lvol, spdk_lvol_iter_cb cb_fn, void *cb_arg)
{
	struct spdk_lvol_store *lvs = lvol->lvol_store;
	struct spdk_blob_store *bs = lvs->blobstore;
	struct spdk_lvol *clone;
	spdk_blob_id *ids;
	size_t id_cnt = 0;
	size_t i;
	int rc;

	rc = spdk_blob_get_clones(bs, lvol->blob_id, NULL, &id_cnt);
	if (rc != -ENOMEM) {
		/* -ENOMEM says id_cnt is valid, no other errors should be returned. */
		assert(rc == 0);
		return rc;
	}

	ids = calloc(id_cnt, sizeof(*ids));
	if (ids == NULL) {
		SPDK_ERRLOG("lvol %s: out of memory while iterating clones\n", lvol->unique_id);
		return -ENOMEM;
	}

	rc = spdk_blob_get_clones(bs, lvol->blob_id, ids, &id_cnt);
	if (rc != 0) {
		SPDK_ERRLOG("lvol %s: unable to get clone blob IDs: %d\n", lvol->unique_id, rc);
		free(ids);
		return rc;
	}

	for (i = 0; i < id_cnt; i++) {
		clone = lvs_get_lvol_by_blob_id(lvs, ids[i]);
		if (clone == NULL) {
			SPDK_NOTICELOG("lvol %s: unable to find clone lvol with blob id 0x%"
				       PRIx64 "\n", lvol->unique_id, ids[i]);
			continue;
		}
		rc = cb_fn(cb_arg, clone);
		if (rc != 0) {
			SPDK_DEBUGLOG(lvol, "lvol %s: iteration stopped when lvol %s (blob 0x%"
				      PRIx64 ") returned %d\n", lvol->unique_id, clone->unique_id,
				      ids[i], rc);
			break;
		}
	}

	free(ids);
	return rc;
}
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
	spdk_lvol_inflate;
	spdk_lvol_decouple_parent;
	spdk_lvol_create_esnap_clone;
	spdk_lvol_iter_immediate_clones;

	# internal functions
	spdk_lvol_resize;
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ DEFINE_STUB(spdk_bdev_get_memory_domains, int, (struct spdk_bdev *bdev,
DEFINE_STUB(spdk_blob_get_esnap_id, int,
	    (struct spdk_blob *blob, const void **id, size_t *len), -ENOTSUP);
DEFINE_STUB(spdk_blob_is_esnap_clone, bool, (const struct spdk_blob *blob), false);
DEFINE_STUB(spdk_lvol_iter_immediate_clones, int,
	    (struct spdk_lvol *lvol, spdk_lvol_iter_cb cb_fn, void *cb_arg), -ENOTSUP);

const struct spdk_bdev_aliases_list *
spdk_bdev_get_aliases(const struct spdk_bdev *bdev)
Loading