Commit d96097b4 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

keyring: add spdk_key_dup()



It's often useful to increase the refcnt of a key, e.g. to transfer its
ownership.  It could be achieved by doing
spdk_keyring_get(spdk_key_get_name(key)), but spdk_key_dup(key) is less
cumbersome.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I805e0fe8a7ef154d19fe62621d5e736585620715
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22653


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Community-CI: Mellanox Build Bot
parent 84e4df8c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -57,6 +57,16 @@ const char *spdk_key_get_name(struct spdk_key *key);
 */
int spdk_key_get_key(struct spdk_key *key, void *buf, int len);

/**
 * Duplicate a key.  The returned key reference might be a pointer to the same exact object.  After
 * duplicating a key, the new reference should be released via `spdk_keyring_put_key()`.
 *
 * \param key Reference to a key.
 *
 * \return Pointer to the key reference.
 */
struct spdk_key *spdk_key_dup(struct spdk_key *key);

/**
 * Initialize the keyring library.
 *
+10 −0
Original line number Diff line number Diff line
@@ -240,6 +240,16 @@ spdk_keyring_put_key(struct spdk_key *key)
	pthread_mutex_unlock(&g_keyring.mutex);
}

struct spdk_key *
spdk_key_dup(struct spdk_key *key)
{
	pthread_mutex_lock(&g_keyring.mutex);
	key->refcnt++;
	pthread_mutex_unlock(&g_keyring.mutex);

	return key;
}

const char *
spdk_key_get_name(struct spdk_key *key)
{
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
	spdk_key_get_key;
	spdk_key_get_ctx;
	spdk_key_get_module;
	spdk_key_dup;

	local: *;
};