diff --git a/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.c b/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.c new file mode 100644 index 000000000000..eadd4f9bfe5e --- /dev/null +++ b/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.c @@ -0,0 +1,480 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/nbd.yaml */ +/* YNL-GEN user source */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#include +#include +#include "nbd-user.h" +#include "ynl.h" +#include + +#include + +/* Enums */ +static const char * const nbd_op_strmap[] = { + [NBD_CMD_CONNECT] = "connect", + [NBD_CMD_DISCONNECT] = "disconnect", + [NBD_CMD_RECONFIGURE] = "reconfigure", + [NBD_CMD_LINK_DEAD] = "link-dead", + [NBD_CMD_STATUS] = "status", +}; + +const char *nbd_op_str(int op) +{ + if (op < 0 || op >= (int)YNL_ARRAY_SIZE(nbd_op_strmap)) + return NULL; + return nbd_op_strmap[op]; +} + +/* Policies */ +const struct ynl_policy_attr nbd_sock_attrs_policy[NBD_SOCK_MAX + 1] = { + [NBD_SOCK_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, + [NBD_SOCK_FD] = { .name = "fd", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest nbd_sock_attrs_nest = { + .max_attr = NBD_SOCK_MAX, + .table = nbd_sock_attrs_policy, +}; + +const struct ynl_policy_attr nbd_device_attrs_policy[NBD_DEVICE_ATTR_MAX + 1] = { + [NBD_DEVICE_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, + [NBD_DEVICE_INDEX] = { .name = "index", .type = YNL_PT_U32, }, + [NBD_DEVICE_CONNECTED] = { .name = "connected", .type = YNL_PT_U8, }, +}; + +const struct ynl_policy_nest nbd_device_attrs_nest = { + .max_attr = NBD_DEVICE_ATTR_MAX, + .table = nbd_device_attrs_policy, +}; + +const struct ynl_policy_attr nbd_sock_item_attrs_policy[NBD_SOCK_ITEM_MAX + 1] = { + [NBD_SOCK_ITEM_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, + [NBD_SOCK_ITEM] = { .name = "item", .type = YNL_PT_NEST, .nest = &nbd_sock_attrs_nest, }, +}; + +const struct ynl_policy_nest nbd_sock_item_attrs_nest = { + .max_attr = NBD_SOCK_ITEM_MAX, + .table = nbd_sock_item_attrs_policy, +}; + +const struct ynl_policy_attr nbd_device_item_attrs_policy[NBD_DEVICE_ITEM_MAX + 1] = { + [NBD_DEVICE_ITEM_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, + [NBD_DEVICE_ITEM] = { .name = "item", .type = YNL_PT_NEST, .nest = &nbd_device_attrs_nest, }, +}; + +const struct ynl_policy_nest nbd_device_item_attrs_nest = { + .max_attr = NBD_DEVICE_ITEM_MAX, + .table = nbd_device_item_attrs_policy, +}; + +const struct ynl_policy_attr nbd_nbd_attrs_policy[NBD_ATTR_MAX + 1] = { + [NBD_ATTR_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, + [NBD_ATTR_INDEX] = { .name = "index", .type = YNL_PT_U32, }, + [NBD_ATTR_SIZE_BYTES] = { .name = "size-bytes", .type = YNL_PT_U64, }, + [NBD_ATTR_BLOCK_SIZE_BYTES] = { .name = "block-size-bytes", .type = YNL_PT_U64, }, + [NBD_ATTR_TIMEOUT] = { .name = "timeout", .type = YNL_PT_U64, }, + [NBD_ATTR_SERVER_FLAGS] = { .name = "server-flags", .type = YNL_PT_U64, }, + [NBD_ATTR_CLIENT_FLAGS] = { .name = "client-flags", .type = YNL_PT_U64, }, + [NBD_ATTR_SOCKETS] = { .name = "sockets", .type = YNL_PT_NEST, .nest = &nbd_sock_item_attrs_nest, }, + [NBD_ATTR_DEAD_CONN_TIMEOUT] = { .name = "dead-conn-timeout", .type = YNL_PT_U64, }, + [NBD_ATTR_DEVICE_LIST] = { .name = "device-list", .type = YNL_PT_NEST, .nest = &nbd_device_item_attrs_nest, }, + [NBD_ATTR_BACKEND_IDENTIFIER] = { .name = "backend-identifier", .type = YNL_PT_NUL_STR, }, +}; + +const struct ynl_policy_nest nbd_nbd_attrs_nest = { + .max_attr = NBD_ATTR_MAX, + .table = nbd_nbd_attrs_policy, +}; + +/* Common nested types */ +void nbd_sock_attrs_free(struct nbd_sock_attrs *obj) +{ +} + +int nbd_sock_attrs_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct nbd_sock_attrs *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.fd) + ynl_attr_put_u32(nlh, NBD_SOCK_FD, obj->fd); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +void nbd_device_attrs_free(struct nbd_device_attrs *obj) +{ +} + +int nbd_device_attrs_parse(struct ynl_parse_arg *yarg, + const struct nlattr *nested) +{ + struct nbd_device_attrs *dst = yarg->data; + const struct nlattr *attr; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == NBD_DEVICE_INDEX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.index = 1; + dst->index = ynl_attr_get_u32(attr); + } else if (type == NBD_DEVICE_CONNECTED) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.connected = 1; + dst->connected = ynl_attr_get_u8(attr); + } + } + + return 0; +} + +void nbd_sock_item_attrs_free(struct nbd_sock_item_attrs *obj) +{ + unsigned int i; + + for (i = 0; i < obj->_count.item; i++) + nbd_sock_attrs_free(&obj->item[i]); + free(obj->item); +} + +int nbd_sock_item_attrs_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct nbd_sock_item_attrs *obj) +{ + struct nlattr *nest; + unsigned int i; + + nest = ynl_attr_nest_start(nlh, attr_type); + for (i = 0; i < obj->_count.item; i++) + nbd_sock_attrs_put(nlh, NBD_SOCK_ITEM, &obj->item[i]); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +void nbd_device_item_attrs_free(struct nbd_device_item_attrs *obj) +{ + unsigned int i; + + for (i = 0; i < obj->_count.item; i++) + nbd_device_attrs_free(&obj->item[i]); + free(obj->item); +} + +int nbd_device_item_attrs_parse(struct ynl_parse_arg *yarg, + const struct nlattr *nested) +{ + struct nbd_device_item_attrs *dst = yarg->data; + const struct nlattr *attr; + struct ynl_parse_arg parg; + unsigned int n_item = 0; + int i; + + parg.ys = yarg->ys; + + if (dst->item) + return ynl_error_parse(yarg, "attribute already present (device-item-attrs.item)"); + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == NBD_DEVICE_ITEM) { + n_item++; + } + } + + if (n_item) { + dst->item = calloc(n_item, sizeof(*dst->item)); + dst->_count.item = n_item; + i = 0; + parg.rsp_policy = &nbd_device_attrs_nest; + ynl_attr_for_each_nested(attr, nested) { + if (ynl_attr_type(attr) == NBD_DEVICE_ITEM) { + parg.data = &dst->item[i]; + if (nbd_device_attrs_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + i++; + } + } + } + + return 0; +} + +/* ============== NBD_CMD_CONNECT ============== */ +/* NBD_CMD_CONNECT - do */ +void nbd_connect_req_free(struct nbd_connect_req *req) +{ + nbd_sock_item_attrs_free(&req->sockets); + free(req->backend_identifier); + free(req); +} + +void nbd_connect_rsp_free(struct nbd_connect_rsp *rsp) +{ + free(rsp); +} + +int nbd_connect_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct nbd_connect_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NBD_ATTR_INDEX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.index = 1; + dst->index = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct nbd_connect_rsp * +nbd_connect(struct ynl_sock *ys, struct nbd_connect_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nbd_connect_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NBD_CMD_CONNECT, 1); + ys->req_policy = &nbd_nbd_attrs_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &nbd_nbd_attrs_nest; + + if (req->_present.index) + ynl_attr_put_u32(nlh, NBD_ATTR_INDEX, req->index); + if (req->_present.size_bytes) + ynl_attr_put_u64(nlh, NBD_ATTR_SIZE_BYTES, req->size_bytes); + if (req->_present.block_size_bytes) + ynl_attr_put_u64(nlh, NBD_ATTR_BLOCK_SIZE_BYTES, req->block_size_bytes); + if (req->_present.timeout) + ynl_attr_put_u64(nlh, NBD_ATTR_TIMEOUT, req->timeout); + if (req->_present.server_flags) + ynl_attr_put_u64(nlh, NBD_ATTR_SERVER_FLAGS, req->server_flags); + if (req->_present.client_flags) + ynl_attr_put_u64(nlh, NBD_ATTR_CLIENT_FLAGS, req->client_flags); + if (req->_present.sockets) + nbd_sock_item_attrs_put(nlh, NBD_ATTR_SOCKETS, &req->sockets); + if (req->_present.dead_conn_timeout) + ynl_attr_put_u64(nlh, NBD_ATTR_DEAD_CONN_TIMEOUT, req->dead_conn_timeout); + if (req->_len.backend_identifier) + ynl_attr_put_str(nlh, NBD_ATTR_BACKEND_IDENTIFIER, req->backend_identifier); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = nbd_connect_rsp_parse; + yrs.rsp_cmd = NBD_CMD_CONNECT; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + nbd_connect_rsp_free(rsp); + return NULL; +} + +/* ============== NBD_CMD_DISCONNECT ============== */ +/* NBD_CMD_DISCONNECT - do */ +void nbd_disconnect_req_free(struct nbd_disconnect_req *req) +{ + free(req); +} + +int nbd_disconnect(struct ynl_sock *ys, struct nbd_disconnect_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NBD_CMD_DISCONNECT, 1); + ys->req_policy = &nbd_nbd_attrs_nest; + ys->req_hdr_len = ys->family->hdr_len; + + if (req->_present.index) + ynl_attr_put_u32(nlh, NBD_ATTR_INDEX, req->index); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== NBD_CMD_RECONFIGURE ============== */ +/* NBD_CMD_RECONFIGURE - do */ +void nbd_reconfigure_req_free(struct nbd_reconfigure_req *req) +{ + nbd_sock_item_attrs_free(&req->sockets); + free(req->backend_identifier); + free(req); +} + +int nbd_reconfigure(struct ynl_sock *ys, struct nbd_reconfigure_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NBD_CMD_RECONFIGURE, 1); + ys->req_policy = &nbd_nbd_attrs_nest; + ys->req_hdr_len = ys->family->hdr_len; + + if (req->_present.index) + ynl_attr_put_u32(nlh, NBD_ATTR_INDEX, req->index); + if (req->_present.size_bytes) + ynl_attr_put_u64(nlh, NBD_ATTR_SIZE_BYTES, req->size_bytes); + if (req->_present.block_size_bytes) + ynl_attr_put_u64(nlh, NBD_ATTR_BLOCK_SIZE_BYTES, req->block_size_bytes); + if (req->_present.timeout) + ynl_attr_put_u64(nlh, NBD_ATTR_TIMEOUT, req->timeout); + if (req->_present.client_flags) + ynl_attr_put_u64(nlh, NBD_ATTR_CLIENT_FLAGS, req->client_flags); + if (req->_present.sockets) + nbd_sock_item_attrs_put(nlh, NBD_ATTR_SOCKETS, &req->sockets); + if (req->_present.dead_conn_timeout) + ynl_attr_put_u64(nlh, NBD_ATTR_DEAD_CONN_TIMEOUT, req->dead_conn_timeout); + if (req->_len.backend_identifier) + ynl_attr_put_str(nlh, NBD_ATTR_BACKEND_IDENTIFIER, req->backend_identifier); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== NBD_CMD_STATUS ============== */ +/* NBD_CMD_STATUS - do */ +void nbd_status_req_free(struct nbd_status_req *req) +{ + free(req); +} + +void nbd_status_rsp_free(struct nbd_status_rsp *rsp) +{ + nbd_device_item_attrs_free(&rsp->device_list); + free(rsp); +} + +int nbd_status_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct nbd_status_rsp *dst; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + dst = yarg->data; + parg.ys = yarg->ys; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NBD_ATTR_DEVICE_LIST) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.device_list = 1; + + parg.rsp_policy = &nbd_device_item_attrs_nest; + parg.data = &dst->device_list; + if (nbd_device_item_attrs_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } + } + + return YNL_PARSE_CB_OK; +} + +struct nbd_status_rsp * +nbd_status(struct ynl_sock *ys, struct nbd_status_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nbd_status_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NBD_CMD_STATUS, 1); + ys->req_policy = &nbd_nbd_attrs_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &nbd_nbd_attrs_nest; + + if (req->_present.index) + ynl_attr_put_u32(nlh, NBD_ATTR_INDEX, req->index); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = nbd_status_rsp_parse; + yrs.rsp_cmd = NBD_CMD_STATUS; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + nbd_status_rsp_free(rsp); + return NULL; +} + +/* NBD_CMD_LINK_DEAD - event */ +int nbd_link_dead_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct nbd_link_dead_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NBD_ATTR_INDEX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.index = 1; + dst->index = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +void nbd_link_dead_free(struct nbd_link_dead *rsp) +{ + free(rsp); +} + +static const struct ynl_ntf_info nbd_ntf_info[] = { + [NBD_CMD_LINK_DEAD] = { + .alloc_sz = sizeof(struct nbd_link_dead), + .cb = nbd_link_dead_rsp_parse, + .policy = &nbd_nbd_attrs_nest, + .free = (void *)nbd_link_dead_free, + }, +}; + +const struct ynl_family ynl_nbd_family = { + .name = "nbd", + .hdr_len = sizeof(struct genlmsghdr), + .ntf_info = nbd_ntf_info, + .ntf_info_size = YNL_ARRAY_SIZE(nbd_ntf_info), +}; diff --git a/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.h b/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.h new file mode 100644 index 000000000000..da7f68f8b5b9 --- /dev/null +++ b/tmp/ynl_build-tmp.zs8uUN/new-code/nbd-user.h @@ -0,0 +1,379 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/nbd.yaml */ +/* YNL-GEN user header */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#ifndef _LINUX_NBD_GEN_H +#define _LINUX_NBD_GEN_H + +#include +#include +#include +#include + +struct ynl_sock; + +extern const struct ynl_family ynl_nbd_family; + +/* Enums */ +const char *nbd_op_str(int op); + +/* Common nested types */ +struct nbd_sock_attrs { + struct { + __u32 fd:1; + } _present; + + __u32 fd; +}; + +static inline struct nbd_sock_attrs *nbd_sock_attrs_alloc(unsigned int n) +{ + return calloc(n, sizeof(struct nbd_sock_attrs)); +} + +void nbd_sock_attrs_free(struct nbd_sock_attrs *obj); + +static inline void nbd_sock_attrs_set_fd(struct nbd_sock_attrs *obj, __u32 fd) +{ + obj->_present.fd = 1; + obj->fd = fd; +} + +struct nbd_device_attrs { + struct { + __u32 index:1; + __u32 connected:1; + } _present; + + __u32 index; + __u8 connected; +}; + +struct nbd_sock_item_attrs { + struct { + __u32 item; + } _count; + + struct nbd_sock_attrs *item; +}; + +struct nbd_device_item_attrs { + struct { + __u32 item; + } _count; + + struct nbd_device_attrs *item; +}; + +/* ============== NBD_CMD_CONNECT ============== */ +/* NBD_CMD_CONNECT - do */ +struct nbd_connect_req { + struct { + __u32 index:1; + __u32 size_bytes:1; + __u32 block_size_bytes:1; + __u32 timeout:1; + __u32 server_flags:1; + __u32 client_flags:1; + __u32 sockets:1; + __u32 dead_conn_timeout:1; + } _present; + struct { + __u32 backend_identifier; + } _len; + + __u32 index; + __u64 size_bytes; + __u64 block_size_bytes; + __u64 timeout; + __u64 server_flags; + __u64 client_flags; + struct nbd_sock_item_attrs sockets; + __u64 dead_conn_timeout; + char *backend_identifier; +}; + +static inline struct nbd_connect_req *nbd_connect_req_alloc(void) +{ + return calloc(1, sizeof(struct nbd_connect_req)); +} +void nbd_connect_req_free(struct nbd_connect_req *req); + +static inline void +nbd_connect_req_set_index(struct nbd_connect_req *req, __u32 index) +{ + req->_present.index = 1; + req->index = index; +} +static inline void +nbd_connect_req_set_size_bytes(struct nbd_connect_req *req, __u64 size_bytes) +{ + req->_present.size_bytes = 1; + req->size_bytes = size_bytes; +} +static inline void +nbd_connect_req_set_block_size_bytes(struct nbd_connect_req *req, + __u64 block_size_bytes) +{ + req->_present.block_size_bytes = 1; + req->block_size_bytes = block_size_bytes; +} +static inline void +nbd_connect_req_set_timeout(struct nbd_connect_req *req, __u64 timeout) +{ + req->_present.timeout = 1; + req->timeout = timeout; +} +static inline void +nbd_connect_req_set_server_flags(struct nbd_connect_req *req, + __u64 server_flags) +{ + req->_present.server_flags = 1; + req->server_flags = server_flags; +} +static inline void +nbd_connect_req_set_client_flags(struct nbd_connect_req *req, + __u64 client_flags) +{ + req->_present.client_flags = 1; + req->client_flags = client_flags; +} +static inline void +__nbd_connect_req_set_sockets_item(struct nbd_connect_req *req, + struct nbd_sock_attrs *item, + unsigned int n_item) +{ + unsigned int i; + + req->_present.sockets = 1; + for (i = 0; i < req->sockets._count.item; i++) + nbd_sock_attrs_free(&req->sockets.item[i]); + free(req->sockets.item); + req->sockets.item = item; + req->sockets._count.item = n_item; +} +static inline void +nbd_connect_req_set_dead_conn_timeout(struct nbd_connect_req *req, + __u64 dead_conn_timeout) +{ + req->_present.dead_conn_timeout = 1; + req->dead_conn_timeout = dead_conn_timeout; +} +static inline void +nbd_connect_req_set_backend_identifier(struct nbd_connect_req *req, + const char *backend_identifier) +{ + free(req->backend_identifier); + req->_len.backend_identifier = strlen(backend_identifier); + req->backend_identifier = malloc(req->_len.backend_identifier + 1); + memcpy(req->backend_identifier, backend_identifier, req->_len.backend_identifier); + req->backend_identifier[req->_len.backend_identifier] = 0; +} + +struct nbd_connect_rsp { + struct { + __u32 index:1; + } _present; + + __u32 index; +}; + +void nbd_connect_rsp_free(struct nbd_connect_rsp *rsp); + +/* + * See :file:`drivers/block/nbd.c`, :code:`nbd_genl_connect()` + */ +struct nbd_connect_rsp * +nbd_connect(struct ynl_sock *ys, struct nbd_connect_req *req); + +/* ============== NBD_CMD_DISCONNECT ============== */ +/* NBD_CMD_DISCONNECT - do */ +struct nbd_disconnect_req { + struct { + __u32 index:1; + } _present; + + __u32 index; +}; + +static inline struct nbd_disconnect_req *nbd_disconnect_req_alloc(void) +{ + return calloc(1, sizeof(struct nbd_disconnect_req)); +} +void nbd_disconnect_req_free(struct nbd_disconnect_req *req); + +static inline void +nbd_disconnect_req_set_index(struct nbd_disconnect_req *req, __u32 index) +{ + req->_present.index = 1; + req->index = index; +} + +/* + * See :file:`drivers/block/nbd.c`, :code:`nbd_genl_disconnect()` + */ +int nbd_disconnect(struct ynl_sock *ys, struct nbd_disconnect_req *req); + +/* ============== NBD_CMD_RECONFIGURE ============== */ +/* NBD_CMD_RECONFIGURE - do */ +struct nbd_reconfigure_req { + struct { + __u32 index:1; + __u32 size_bytes:1; + __u32 block_size_bytes:1; + __u32 timeout:1; + __u32 client_flags:1; + __u32 sockets:1; + __u32 dead_conn_timeout:1; + } _present; + struct { + __u32 backend_identifier; + } _len; + + __u32 index; + __u64 size_bytes; + __u64 block_size_bytes; + __u64 timeout; + __u64 client_flags; + struct nbd_sock_item_attrs sockets; + __u64 dead_conn_timeout; + char *backend_identifier; +}; + +static inline struct nbd_reconfigure_req *nbd_reconfigure_req_alloc(void) +{ + return calloc(1, sizeof(struct nbd_reconfigure_req)); +} +void nbd_reconfigure_req_free(struct nbd_reconfigure_req *req); + +static inline void +nbd_reconfigure_req_set_index(struct nbd_reconfigure_req *req, __u32 index) +{ + req->_present.index = 1; + req->index = index; +} +static inline void +nbd_reconfigure_req_set_size_bytes(struct nbd_reconfigure_req *req, + __u64 size_bytes) +{ + req->_present.size_bytes = 1; + req->size_bytes = size_bytes; +} +static inline void +nbd_reconfigure_req_set_block_size_bytes(struct nbd_reconfigure_req *req, + __u64 block_size_bytes) +{ + req->_present.block_size_bytes = 1; + req->block_size_bytes = block_size_bytes; +} +static inline void +nbd_reconfigure_req_set_timeout(struct nbd_reconfigure_req *req, __u64 timeout) +{ + req->_present.timeout = 1; + req->timeout = timeout; +} +static inline void +nbd_reconfigure_req_set_client_flags(struct nbd_reconfigure_req *req, + __u64 client_flags) +{ + req->_present.client_flags = 1; + req->client_flags = client_flags; +} +static inline void +__nbd_reconfigure_req_set_sockets_item(struct nbd_reconfigure_req *req, + struct nbd_sock_attrs *item, + unsigned int n_item) +{ + unsigned int i; + + req->_present.sockets = 1; + for (i = 0; i < req->sockets._count.item; i++) + nbd_sock_attrs_free(&req->sockets.item[i]); + free(req->sockets.item); + req->sockets.item = item; + req->sockets._count.item = n_item; +} +static inline void +nbd_reconfigure_req_set_dead_conn_timeout(struct nbd_reconfigure_req *req, + __u64 dead_conn_timeout) +{ + req->_present.dead_conn_timeout = 1; + req->dead_conn_timeout = dead_conn_timeout; +} +static inline void +nbd_reconfigure_req_set_backend_identifier(struct nbd_reconfigure_req *req, + const char *backend_identifier) +{ + free(req->backend_identifier); + req->_len.backend_identifier = strlen(backend_identifier); + req->backend_identifier = malloc(req->_len.backend_identifier + 1); + memcpy(req->backend_identifier, backend_identifier, req->_len.backend_identifier); + req->backend_identifier[req->_len.backend_identifier] = 0; +} + +/* + * See :file:`drivers/block/nbd.c`, :code:`nbd_genl_reconfigure()` + */ +int nbd_reconfigure(struct ynl_sock *ys, struct nbd_reconfigure_req *req); + +/* ============== NBD_CMD_STATUS ============== */ +/* NBD_CMD_STATUS - do */ +struct nbd_status_req { + struct { + __u32 index:1; + } _present; + + __u32 index; +}; + +static inline struct nbd_status_req *nbd_status_req_alloc(void) +{ + return calloc(1, sizeof(struct nbd_status_req)); +} +void nbd_status_req_free(struct nbd_status_req *req); + +static inline void +nbd_status_req_set_index(struct nbd_status_req *req, __u32 index) +{ + req->_present.index = 1; + req->index = index; +} + +struct nbd_status_rsp { + struct { + __u32 device_list:1; + } _present; + + struct nbd_device_item_attrs device_list; +}; + +void nbd_status_rsp_free(struct nbd_status_rsp *rsp); + +/* + * See :file:`drivers/block/nbd.c`, :code:`nbd_genl_status()` + */ +struct nbd_status_rsp * +nbd_status(struct ynl_sock *ys, struct nbd_status_req *req); + +/* NBD_CMD_LINK_DEAD - event */ +struct nbd_link_dead_rsp { + struct { + __u32 index:1; + } _present; + + __u32 index; +}; + +struct nbd_link_dead { + __u16 family; + __u8 cmd; + struct ynl_ntf_base_type *next; + void (*free)(struct nbd_link_dead *ntf); + struct nbd_link_dead_rsp obj __attribute__((aligned(8))); +}; + +void nbd_link_dead_free(struct nbd_link_dead *rsp); + +#endif /* _LINUX_NBD_GEN_H */