Commit 23850b03 authored by Krzysztof Smolinski's avatar Krzysztof Smolinski Committed by Tomasz Zawadzki
Browse files

module/raid: bdev_raid_remove_base_bdev rpc



Change-Id: I4829f6cd0c10bfcd2c6893cf9412fc974c4b338c
Signed-off-by: default avatarKrzysztof Smolinski <krzysztof.smolinski@intel.com>
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15267


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent 597fbea9
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -10153,6 +10153,41 @@ Example response:
}
~~~

### bdev_raid_remove_base_bdev {#rpc_bdev_raid_remove_base_bdev}

Remove base bdev from existing raid bdev.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Base bdev name in RAID

#### Example

Example request:

~~~json
{
  "jsonrpc": "2.0",
  "method": "bdev_raid_remove_base_bdev",
  "id": 1,
  "params": {
    "name": "Raid0"
  }
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

## SPLIT

### bdev_split_create {#rpc_bdev_split_create}
+17 −5
Original line number Diff line number Diff line
@@ -1261,12 +1261,16 @@ raid_bdev_remove_base_bdev_on_unquiesced(void *ctx, int status)
	if (status != 0) {
		SPDK_ERRLOG("Failed to unquiesce raid bdev %s: %s\n",
			    raid_bdev->bdev.name, spdk_strerror(-status));
		return;
		goto out;
	}

	spdk_spin_lock(&raid_bdev->base_bdev_lock);
	raid_bdev_free_base_bdev_resource(base_info);
	spdk_spin_unlock(&raid_bdev->base_bdev_lock);
out:
	if (base_info->remove_cb != NULL) {
		base_info->remove_cb(base_info->remove_cb_ctx, status);
	}
}

static void
@@ -1307,6 +1311,9 @@ raid_bdev_remove_base_bdev_on_quiesced(void *ctx, int status)
		SPDK_ERRLOG("Failed to quiesce raid bdev %s: %s\n",
			    raid_bdev->bdev.name, spdk_strerror(-status));
		base_info->remove_scheduled = false;
		if (base_info->remove_cb != NULL) {
			base_info->remove_cb(base_info->remove_cb_ctx, status);
		}
		return;
	}

@@ -1321,12 +1328,15 @@ raid_bdev_remove_base_bdev_on_quiesced(void *ctx, int status)
 * or not. If yes, it takes necessary action on that particular raid bdev.
 * params:
 * base_bdev - pointer to base bdev which got removed
 * cb_fn - callback function
 * cb_arg - argument to callback function
 * returns:
 * 0 - success
 * non zero - failure
 */
static int
raid_bdev_remove_base_bdev(struct spdk_bdev *base_bdev)
int
raid_bdev_remove_base_bdev(struct spdk_bdev *base_bdev, raid_bdev_remove_base_bdev_cb cb_fn,
			   void *cb_ctx)
{
	struct raid_bdev *raid_bdev;
	struct raid_base_bdev_info *base_info;
@@ -1349,6 +1359,8 @@ raid_bdev_remove_base_bdev(struct spdk_bdev *base_bdev)

	assert(base_info->desc);
	base_info->remove_scheduled = true;
	base_info->remove_cb = cb_fn;
	base_info->remove_cb_ctx = cb_ctx;

	if (raid_bdev->state != RAID_BDEV_STATE_ONLINE) {
		/*
@@ -1365,7 +1377,7 @@ raid_bdev_remove_base_bdev(struct spdk_bdev *base_bdev)
		 * After this base bdev is removed there will not be enough base bdevs
		 * to keep the raid bdev operational.
		 */
		raid_bdev_deconfigure(raid_bdev, NULL, NULL);
		raid_bdev_deconfigure(raid_bdev, cb_fn, cb_ctx);
	} else {
		int ret;

@@ -1435,7 +1447,7 @@ raid_bdev_event_base_bdev(enum spdk_bdev_event_type type, struct spdk_bdev *bdev

	switch (type) {
	case SPDK_BDEV_EVENT_REMOVE:
		rc = raid_bdev_remove_base_bdev(bdev);
		rc = raid_bdev_remove_base_bdev(bdev, NULL, NULL);
		if (rc != 0) {
			SPDK_ERRLOG("Failed to remove base bdev %s: %s\n",
				    spdk_bdev_get_name(bdev), spdk_strerror(-rc));
+10 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ enum raid_bdev_state {
	RAID_BDEV_STATE_MAX
};

typedef void (*raid_bdev_remove_base_bdev_cb)(void *ctx, int status);

/*
 * raid_base_bdev_info contains information for the base bdevs which are part of some
 * raid. This structure contains the per base bdev information. Whatever is
@@ -66,6 +68,12 @@ struct raid_base_bdev_info {
	 */
	bool			remove_scheduled;

	/* callback for base bdev removal */
	raid_bdev_remove_base_bdev_cb remove_cb;

	/* context of the callback */
	void			*remove_cb_ctx;

	/* Hold the number of blocks to know how large the base bdev is resized. */
	uint64_t		blockcnt;
};
@@ -183,6 +191,8 @@ const char *raid_bdev_level_to_str(enum raid_level level);
enum raid_bdev_state raid_bdev_str_to_state(const char *str);
const char *raid_bdev_state_to_str(enum raid_bdev_state state);
void raid_bdev_write_info_json(struct raid_bdev *raid_bdev, struct spdk_json_write_ctx *w);
int raid_bdev_remove_base_bdev(struct spdk_bdev *base_bdev, raid_bdev_remove_base_bdev_cb cb_fn,
			       void *cb_ctx);

/*
 * RAID module descriptor
+62 −0
Original line number Diff line number Diff line
@@ -381,3 +381,65 @@ cleanup:
	free(ctx);
}
SPDK_RPC_REGISTER("bdev_raid_delete", rpc_bdev_raid_delete, SPDK_RPC_RUNTIME)

/*
 * Decoder object for RPC bdev_raid_remove_base_bdev
 */
static const struct spdk_json_object_decoder rpc_bdev_raid_remove_base_bdev_decoders[] = {
	{"name", 0, spdk_json_decode_string},
};

static void
rpc_bdev_raid_remove_base_bdev_done(void *ctx, int status)
{
	struct spdk_jsonrpc_request *request = ctx;

	if (status != 0) {
		spdk_jsonrpc_send_error_response_fmt(request, status, "Failed to remove base bdev from raid bdev");
		return;
	}

	spdk_jsonrpc_send_bool_response(request, true);
}

/*
 * brief:
 * bdev_raid_remove_base_bdev function is the RPC for removing base bdev from a raid bdev.
 * It takes base bdev name as input.
 * params:
 * request - pointer to json rpc request
 * params - pointer to request parameters
 * returns:
 * none
 */
static void
rpc_bdev_raid_remove_base_bdev(struct spdk_jsonrpc_request *request,
			       const struct spdk_json_val *params)
{
	struct spdk_bdev *bdev;
	char *name = NULL;
	int rc;

	if (spdk_json_decode_object(params, rpc_bdev_raid_remove_base_bdev_decoders,
				    SPDK_COUNTOF(rpc_bdev_raid_remove_base_bdev_decoders),
				    &name)) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
						 "spdk_json_decode_object failed");
		return;
	}

	bdev = spdk_bdev_get_by_name(name);
	if (bdev == NULL) {
		spdk_jsonrpc_send_error_response_fmt(request, -ENODEV, "base bdev %s is not found in config", name);
		goto cleanup;
	}

	rc = raid_bdev_remove_base_bdev(bdev, rpc_bdev_raid_remove_base_bdev_done, request);
	if (rc != 0) {
		rpc_bdev_raid_remove_base_bdev_done(request, rc);
	}

cleanup:
	free(name);
}
SPDK_RPC_REGISTER("bdev_raid_remove_base_bdev", rpc_bdev_raid_remove_base_bdev, SPDK_RPC_RUNTIME)
+13 −0
Original line number Diff line number Diff line
@@ -436,6 +436,19 @@ def bdev_raid_delete(client, name):
    return client.call('bdev_raid_delete', params)


def bdev_raid_remove_base_bdev(client, name):
    """Remove base bdev from existing raid bdev

    Args:
        name: base bdev name

    Returns:
        None
    """
    params = {'name': name}
    return client.call('bdev_raid_remove_base_bdev', params)


def bdev_aio_create(client, filename, name, block_size=None, readonly=False):
    """Construct a Linux AIO block device.

Loading