Commit 62b3b171 authored by paul luse's avatar paul luse Committed by Jim Harris
Browse files

module/compress: add new parm to RPC for create compress vol



To specify the desired logical block size. Must be 4K or 512.
If no block size is provided a default of 0 means to use the
underlying bdev block size. For cases where something other
than 4K or 512 is desired, format the underlying device
accordingly and don't specify a logical block size on creation
of the compress vol.

Signed-off-by: default avatarpaul luse <paul.e.luse@intel.com>
Change-Id: I58b71e210cfa77b3237c0c454585c734e2e22aea
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3177


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 03fe6a77
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ static struct rte_comp_xform g_decomp_xform = {
static void vbdev_compress_examine(struct spdk_bdev *bdev);
static void vbdev_compress_claim(struct vbdev_compress *comp_bdev);
static void vbdev_compress_queue_io(struct spdk_bdev_io *bdev_io);
struct vbdev_compress *_prepare_for_load_init(struct spdk_bdev *bdev);
struct vbdev_compress *_prepare_for_load_init(struct spdk_bdev *bdev, uint32_t lb_size);
static void vbdev_compress_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io);
static void comp_bdev_ch_destroy_cb(void *io_device, void *ctx_buf);
static void vbdev_compress_delete_done(void *cb_arg, int bdeverrno);
@@ -1284,7 +1284,7 @@ vbdev_compress_base_bdev_hotremove_cb(void *ctx)
 * information for reducelib to init or load.
 */
struct vbdev_compress *
_prepare_for_load_init(struct spdk_bdev *bdev)
_prepare_for_load_init(struct spdk_bdev *bdev, uint32_t lb_size)
{
	struct vbdev_compress *meta_ctx;

@@ -1306,7 +1306,12 @@ _prepare_for_load_init(struct spdk_bdev *bdev)
	meta_ctx->backing_dev.blockcnt = bdev->blockcnt;

	meta_ctx->params.chunk_size = CHUNK_SIZE;
	if (lb_size == 0) {
		meta_ctx->params.logical_block_size = bdev->blocklen;
	} else {
		meta_ctx->params.logical_block_size = lb_size;
	}

	meta_ctx->params.backing_io_unit_size = BACKING_IO_SZ;
	return meta_ctx;
}
@@ -1334,12 +1339,12 @@ _set_pmd(struct vbdev_compress *comp_dev)

/* Call reducelib to initialize a new volume */
static int
vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path)
vbdev_init_reduce(struct spdk_bdev *bdev, const char *pm_path, uint32_t lb_size)
{
	struct vbdev_compress *meta_ctx;
	int rc;

	meta_ctx = _prepare_for_load_init(bdev);
	meta_ctx = _prepare_for_load_init(bdev, lb_size);
	if (meta_ctx == NULL) {
		return -EINVAL;
	}
@@ -1471,7 +1476,7 @@ comp_bdev_ch_destroy_cb(void *io_device, void *ctx_buf)

/* RPC entry point for compression vbdev creation. */
int
create_compress_bdev(const char *bdev_name, const char *pm_path)
create_compress_bdev(const char *bdev_name, const char *pm_path, uint32_t lb_size)
{
	struct spdk_bdev *bdev;

@@ -1480,7 +1485,12 @@ create_compress_bdev(const char *bdev_name, const char *pm_path)
		return -ENODEV;
	}

	return vbdev_init_reduce(bdev, pm_path);;
	if ((lb_size != 0) && (lb_size != LB_SIZE_4K) && (lb_size != LB_SIZE_512B)) {
		SPDK_ERRLOG("Logical block size must be 512 or 4096\n");
		return -EINVAL;
	}

	return vbdev_init_reduce(bdev, pm_path, lb_size);
}

/* On init, just init the compress drivers. All metadata is stored on disk. */
@@ -1822,7 +1832,7 @@ vbdev_compress_examine(struct spdk_bdev *bdev)
		return;
	}

	meta_ctx = _prepare_for_load_init(bdev);
	meta_ctx = _prepare_for_load_init(bdev, 0);
	if (meta_ctx == NULL) {
		spdk_bdev_module_examine_done(&compress_if);
		return;
+5 −1
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@

#include "spdk/bdev.h"

#define LB_SIZE_4K	0x1000UL
#define LB_SIZE_512B	0x200UL

/**
 * Get the first compression bdev.
 *
@@ -85,9 +88,10 @@ typedef void (*spdk_delete_compress_complete)(void *cb_arg, int bdeverrno);
 *
 * \param bdev_name Bdev on which compression bdev will be created.
 * \param pm_path Path to persistent memory.
 * \param lb_size Logical block size for the compressed volume in bytes. Must be 4K or 512.
 * \return 0 on success, other on failure.
 */
int create_compress_bdev(const char *bdev_name, const char *pm_path);
int create_compress_bdev(const char *bdev_name, const char *pm_path, uint32_t lb_size);

/**
 * Delete compress bdev.
+4 −2
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ SPDK_RPC_REGISTER_ALIAS_DEPRECATED(compress_set_pmd, set_compress_pmd)
struct rpc_construct_compress {
	char *base_bdev_name;
	char *pm_path;
	uint32_t lb_size;
};

/* Free the allocated memory resource after the RPC handling. */
@@ -163,6 +164,7 @@ free_rpc_construct_compress(struct rpc_construct_compress *r)
static const struct spdk_json_object_decoder rpc_construct_compress_decoders[] = {
	{"base_bdev_name", offsetof(struct rpc_construct_compress, base_bdev_name), spdk_json_decode_string},
	{"pm_path", offsetof(struct rpc_construct_compress, pm_path), spdk_json_decode_string},
	{"lb_size", offsetof(struct rpc_construct_compress, lb_size), spdk_json_decode_uint32},
};

/* Decode the parameters for this RPC method and properly construct the compress
@@ -181,12 +183,12 @@ rpc_bdev_compress_create(struct spdk_jsonrpc_request *request,
				    SPDK_COUNTOF(rpc_construct_compress_decoders),
				    &req)) {
		SPDK_DEBUGLOG(SPDK_LOG_VBDEV_COMPRESS, "spdk_json_decode_object failed\n");
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
						 "spdk_json_decode_object failed");
		goto cleanup;
	}

	rc = create_compress_bdev(req.base_bdev_name, req.pm_path);
	rc = create_compress_bdev(req.base_bdev_name, req.pm_path, req.lb_size);
	if (rc != 0) {
		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
		goto cleanup;
+3 −1
Original line number Diff line number Diff line
@@ -177,12 +177,14 @@ if __name__ == "__main__":
    def bdev_compress_create(args):
        print_json(rpc.bdev.bdev_compress_create(args.client,
                                                 base_bdev_name=args.base_bdev_name,
                                                 pm_path=args.pm_path))
                                                 pm_path=args.pm_path,
                                                 lb_size=args.lb_size))

    p = subparsers.add_parser('bdev_compress_create', aliases=['construct_compress_bdev'],
                              help='Add a compress vbdev')
    p.add_argument('-b', '--base_bdev_name', help="Name of the base bdev")
    p.add_argument('-p', '--pm_path', help="Path to persistent memory")
    p.add_argument('-l', '--lb_size', help="Compressed vol logical block size (optional, if used must be 512 or 4096)", type=int, default=0)
    p.set_defaults(func=bdev_compress_create)

    def bdev_compress_delete(args):
+3 −2
Original line number Diff line number Diff line
@@ -23,17 +23,18 @@ def bdev_set_options(client, bdev_io_pool_size=None, bdev_io_cache_size=None, bd


@deprecated_alias('construct_compress_bdev')
def bdev_compress_create(client, base_bdev_name, pm_path):
def bdev_compress_create(client, base_bdev_name, pm_path, lb_size):
    """Construct a compress virtual block device.

    Args:
        base_bdev_name: name of the underlying base bdev
        pm_path: path to persistent memory
        lb_size: logical block size for the compressed vol in bytes.  Must be 4K or 512.

    Returns:
        Name of created virtual block device.
    """
    params = {'base_bdev_name': base_bdev_name, 'pm_path': pm_path}
    params = {'base_bdev_name': base_bdev_name, 'pm_path': pm_path, 'lb_size': lb_size}

    return client.call('bdev_compress_create', params)

Loading