Skip to content

Commit

Permalink
Add bdev_rbd_wait_for_latest_osdmap
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
(cherry picked from commit 2500e6f)
  • Loading branch information
Alexander Indenbaum committed Apr 11, 2024
1 parent b754eaa commit d9acca7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
39 changes: 39 additions & 0 deletions module/bdev/rbd/bdev_rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,45 @@ dump_single_cluster_entry(struct bdev_rbd_cluster *entry, struct spdk_json_write
spdk_json_write_object_end(w);
}

static void *
_bdev_rbd_wait_for_latest_osdmap(void *arg)
{
struct bdev_rbd_cluster *entry;
const char *name = arg;
assert(name != NULL);
void *ret = NULL; // failure by default

pthread_mutex_lock(&g_map_bdev_rbd_cluster_mutex);

STAILQ_FOREACH(entry, &g_map_bdev_rbd_cluster, link) {
if (strcmp(name, entry->name) == 0) {
int rc = rados_wait_for_latest_osdmap(entry->cluster);
if (rc) {
SPDK_ERRLOG("Failed to wait for latest osd map, rados cluster=%s, rc=%d\n",
name, rc);
} else {
ret = arg; // non-NULL is returned on success
}
break;
}
}

pthread_mutex_unlock(&g_map_bdev_rbd_cluster_mutex);
return ret;
}

int
bdev_rbd_wait_for_latest_osdmap(const char *name)
{
/* Wait for osd map on cluster name need to be performed in non SPDK-thread to avoid CPU
* resource contention */
if (spdk_call_unaffinitized(_bdev_rbd_wait_for_latest_osdmap, (void *)name) == NULL) {
return -1;
}

return 0;
}

int
bdev_rbd_get_clusters_info(struct spdk_jsonrpc_request *request, const char *name)
{
Expand Down
8 changes: 8 additions & 0 deletions module/bdev/rbd/bdev_rbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ int bdev_rbd_unregister_cluster(const char *name);
*/
int bdev_rbd_get_clusters_info(struct spdk_jsonrpc_request *request, const char *name);

/**
* Wait for latest osd map on cluster identified by name.
* Part of blocklist logic
*
* \param name the name of the cluster.
*/
int bdev_rbd_wait_for_latest_osdmap(const char *name);

#endif /* SPDK_BDEV_RBD_H */
42 changes: 42 additions & 0 deletions module/bdev/rbd/bdev_rbd_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,45 @@ rpc_bdev_rbd_get_clusters_info(struct spdk_jsonrpc_request *request,
free_rpc_bdev_rbd_get_cluster_info(&req);
}
SPDK_RPC_REGISTER("bdev_rbd_get_clusters_info", rpc_bdev_rbd_get_clusters_info, SPDK_RPC_RUNTIME)

struct rpc_bdev_rbd_wait_for_latest_osdmap_cluster {
char *name;
};

static void
free_rpc_bdev_rbd_wait_for_latest_osdmap_cluster(struct rpc_bdev_rbd_wait_for_latest_osdmap_cluster *req)
{
free(req->name);
}

static const struct spdk_json_object_decoder rpc_bdev_rbd_wait_for_latest_osdmap_cluster_decoders[] = {
{"name", offsetof(struct rpc_bdev_rbd_wait_for_latest_osdmap_cluster, name), spdk_json_decode_string, true},
};

static void
rpc_bdev_rbd_wait_for_latest_osdmap(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_bdev_rbd_wait_for_latest_osdmap_cluster req = {NULL};
int rc;

if (spdk_json_decode_object(params, rpc_bdev_rbd_wait_for_latest_osdmap_cluster_decoders,
SPDK_COUNTOF(rpc_bdev_rbd_wait_for_latest_osdmap_cluster_decoders),
&req)) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
goto cleanup;
}

rc = bdev_rbd_wait_for_latest_osdmap(req.name);
if (rc) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
goto cleanup;
}

spdk_jsonrpc_send_bool_response(request, true);

cleanup:
free_rpc_bdev_rbd_wait_for_latest_osdmap_cluster(&req);
}
SPDK_RPC_REGISTER("bdev_rbd_wait_for_latest_osdmap", rpc_bdev_rbd_wait_for_latest_osdmap, SPDK_RPC_RUNTIME)
9 changes: 9 additions & 0 deletions python/spdk/rpc/bdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,15 @@ def bdev_rbd_unregister_cluster(client, name):
params = {'name': name}
return client.call('bdev_rbd_unregister_cluster', params)

def bdev_rbd_wait_for_latest_osdmap(client, name):
"""Wait for latest osd map on cluster identified by name.
Args:
name: name of Rados cluster
"""
params = {'name': name}
return client.call('bdev_rbd_wait_for_latest_osdmap', params)


def bdev_rbd_get_clusters_info(client, name):
"""Get the cluster(s) info
Expand Down

0 comments on commit d9acca7

Please sign in to comment.