xattr: add rpc_bdev_lvol_get_xattr
Longhorn 6604 Signed-off-by: Derek Su <derek.su@suse.com>
This commit is contained in:
parent
0cae9b9296
commit
4142a43052
@ -274,6 +274,18 @@ void
|
||||
spdk_lvol_set_xattr(struct spdk_lvol *lvol, const char *name, const char *value,
|
||||
spdk_lvol_op_complete cb_fn, void *cb_arg);
|
||||
|
||||
/**
|
||||
* Get lvol's xattr.
|
||||
*
|
||||
* \param lvol Handle to lvol.
|
||||
* \param name Xattr name.
|
||||
* \param value Xattr value.
|
||||
* \param value_len Xattr value length.
|
||||
*/
|
||||
int
|
||||
spdk_lvol_get_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
const void **value, size_t *value_len);
|
||||
|
||||
/**
|
||||
* \brief Returns if it is possible to delete an lvol (i.e. lvol is not a snapshot that have at least one clone).
|
||||
* \param lvol Handle to lvol
|
||||
|
@ -1585,6 +1585,15 @@ spdk_lvol_set_xattr(struct spdk_lvol *lvol, const char *name, const char *value,
|
||||
spdk_blob_sync_md(blob, lvol_set_xattr_cb, req);
|
||||
}
|
||||
|
||||
int
|
||||
spdk_lvol_get_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
const void **value, size_t *value_len)
|
||||
{
|
||||
struct spdk_blob *blob = lvol->blob;
|
||||
|
||||
return spdk_blob_get_xattr_value(blob, name, value, value_len);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
||||
{
|
||||
|
@ -1389,6 +1389,13 @@ vbdev_lvol_set_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
spdk_lvol_set_xattr(lvol, name, value, _vbdev_lvol_set_xattr_cb, req);
|
||||
}
|
||||
|
||||
int
|
||||
vbdev_lvol_get_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
const void **value, size_t *value_len)
|
||||
{
|
||||
return spdk_lvol_get_xattr(lvol, name, value, value_len);
|
||||
}
|
||||
|
||||
static void
|
||||
_vbdev_lvol_resize_cb(void *cb_arg, int lvolerrno)
|
||||
{
|
||||
|
@ -80,6 +80,16 @@ void vbdev_lvol_rename(struct spdk_lvol *lvol, const char *new_lvol_name,
|
||||
void vbdev_lvol_set_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
const char *value, spdk_lvol_op_complete cb_fn, void *cb_arg);
|
||||
|
||||
/**
|
||||
* \brief Get lvol's xattr
|
||||
* \param lvol Handle to lvol
|
||||
* \param name Xattr name
|
||||
* \param value Xattr value
|
||||
* \param value_len Xattr value length
|
||||
*/
|
||||
int vbdev_lvol_get_xattr(struct spdk_lvol *lvol, const char *name,
|
||||
const void **value, size_t *value_len);
|
||||
|
||||
/**
|
||||
* Destroy a logical volume
|
||||
* \param lvol Handle to lvol
|
||||
|
@ -701,7 +701,6 @@ cleanup:
|
||||
|
||||
SPDK_RPC_REGISTER("bdev_lvol_rename", rpc_bdev_lvol_rename, SPDK_RPC_RUNTIME)
|
||||
|
||||
|
||||
struct rpc_bdev_lvol_set_xattr {
|
||||
char *name;
|
||||
char *xattr_name;
|
||||
@ -780,6 +779,75 @@ cleanup:
|
||||
|
||||
SPDK_RPC_REGISTER("bdev_lvol_set_xattr", rpc_bdev_lvol_set_xattr, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_bdev_lvol_get_xattr {
|
||||
char *name;
|
||||
char *xattr_name;
|
||||
};
|
||||
|
||||
static void
|
||||
free_rpc_bdev_lvol_get_xattr(struct rpc_bdev_lvol_get_xattr *req)
|
||||
{
|
||||
free(req->name);
|
||||
free(req->xattr_name);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_bdev_lvol_get_xattr_decoders[] = {
|
||||
{"name", offsetof(struct rpc_bdev_lvol_get_xattr, name), spdk_json_decode_string},
|
||||
{"xattr_name", offsetof(struct rpc_bdev_lvol_get_xattr, xattr_name), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
static void
|
||||
rpc_bdev_lvol_get_xattr(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_bdev_lvol_get_xattr req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_bdev *bdev;
|
||||
struct spdk_lvol *lvol;
|
||||
const void *xattr_value;
|
||||
size_t xattr_value_len;
|
||||
int rc;
|
||||
|
||||
SPDK_INFOLOG(lvol_rpc, "Getting lvol xattr\n");
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_bdev_lvol_get_xattr_decoders,
|
||||
SPDK_COUNTOF(rpc_bdev_lvol_get_xattr_decoders),
|
||||
&req)) {
|
||||
SPDK_INFOLOG(lvol_rpc, "spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
bdev = spdk_bdev_get_by_name(req.name);
|
||||
if (bdev == NULL) {
|
||||
SPDK_ERRLOG("bdev '%s' does not exist\n", req.name);
|
||||
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
lvol = vbdev_lvol_get_from_bdev(bdev);
|
||||
if (lvol == NULL) {
|
||||
SPDK_ERRLOG("lvol does not exist\n");
|
||||
spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = vbdev_lvol_get_xattr(lvol, req.xattr_name, &xattr_value, &xattr_value_len);
|
||||
if (rc != 0) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
spdk_strerror(-rc));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
spdk_json_write_string(w, (const char *)xattr_value);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
cleanup:
|
||||
free_rpc_bdev_lvol_get_xattr(&req);
|
||||
}
|
||||
|
||||
SPDK_RPC_REGISTER("bdev_lvol_get_xattr", rpc_bdev_lvol_get_xattr, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_bdev_lvol_inflate {
|
||||
char *name;
|
||||
|
@ -177,6 +177,20 @@ def bdev_lvol_set_xattr(client, name, xattr_name, xattr_value):
|
||||
return client.call('bdev_lvol_set_xattr', params)
|
||||
|
||||
|
||||
def bdev_lvol_get_xattr(client, name, xattr_name):
|
||||
"""Get extended attribute on a logical volume.
|
||||
|
||||
Args:
|
||||
name: name of logical volume
|
||||
xattr_name: name of extended attribute
|
||||
"""
|
||||
params = {
|
||||
'name': name,
|
||||
'xattr_name': xattr_name,
|
||||
}
|
||||
return client.call('bdev_lvol_get_xattr', params)
|
||||
|
||||
|
||||
def bdev_lvol_resize(client, name, size_in_mib):
|
||||
"""Resize a logical volume.
|
||||
|
||||
|
@ -2011,6 +2011,16 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
p.add_argument('xattr_value', help='xattr value')
|
||||
p.set_defaults(func=bdev_lvol_set_xattr)
|
||||
|
||||
def bdev_lvol_get_xattr(args):
|
||||
print_dict(rpc.lvol.bdev_lvol_get_xattr(args.client,
|
||||
name=args.name,
|
||||
xattr_name=args.xattr_name))
|
||||
|
||||
p = subparsers.add_parser('bdev_lvol_get_xattr', help='Get xattr for lvol bdev')
|
||||
p.add_argument('name', help='lvol bdev name')
|
||||
p.add_argument('xattr_name', help='xattr name')
|
||||
p.set_defaults(func=bdev_lvol_get_xattr)
|
||||
|
||||
def bdev_lvol_inflate(args):
|
||||
rpc.lvol.bdev_lvol_inflate(args.client,
|
||||
name=args.name)
|
||||
|
Loading…
Reference in New Issue
Block a user