Fix code style
This commit is contained in:
+15
-27
@@ -36,13 +36,10 @@
|
|||||||
|
|
||||||
#include <linux/nbd-netlink.h>
|
#include <linux/nbd-netlink.h>
|
||||||
|
|
||||||
#define fail(...) \
|
#define fail(...) { fprintf(stderr, __VA_ARGS__); exit(1); }
|
||||||
do { \
|
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
|
||||||
exit(1); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
struct netlink_ctx {
|
struct netlink_ctx
|
||||||
|
{
|
||||||
struct nl_sock *sk;
|
struct nl_sock *sk;
|
||||||
int driver_id;
|
int driver_id;
|
||||||
};
|
};
|
||||||
@@ -112,11 +109,8 @@ static int netlink_status_cb(struct nl_msg *sk_msg, void *devnum)
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int netlink_configure(const int *sockfd, int sock_size,
|
static int netlink_configure(const int *sockfd, int sock_size, int dev_num, uint64_t size,
|
||||||
int dev_num, uint64_t size,
|
uint64_t blocksize, uint64_t flags, uint64_t cflags, uint64_t timeout, uint64_t conn_timeout)
|
||||||
uint64_t blocksize, uint64_t flags,
|
|
||||||
uint64_t cflags, uint64_t timeout,
|
|
||||||
uint64_t conn_timeout)
|
|
||||||
{
|
{
|
||||||
struct netlink_ctx ctx;
|
struct netlink_ctx ctx;
|
||||||
struct nlattr *msg_attr, *msg_opt_attr;
|
struct nlattr *msg_attr, *msg_opt_attr;
|
||||||
@@ -133,7 +127,7 @@ static int netlink_configure(const int *sockfd, int sock_size,
|
|||||||
if (!msg)
|
if (!msg)
|
||||||
{
|
{
|
||||||
netlink_sock_free(&ctx);
|
netlink_sock_free(&ctx);
|
||||||
fail("Failed to allocate netlking message\n");
|
fail("Failed to allocate netlink message\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, ctx.driver_id, 0, 0, NBD_CMD_CONNECT, 0);
|
genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, ctx.driver_id, 0, 0, NBD_CMD_CONNECT, 0);
|
||||||
@@ -180,7 +174,7 @@ static int netlink_configure(const int *sockfd, int sock_size,
|
|||||||
|
|
||||||
nla_nest_end(msg, msg_attr);
|
nla_nest_end(msg, msg_attr);
|
||||||
|
|
||||||
if((err = nl_send_sync(ctx.sk, msg)) < 0)
|
if ((err = nl_send_sync(ctx.sk, msg)) < 0)
|
||||||
{
|
{
|
||||||
netlink_sock_free(&ctx);
|
netlink_sock_free(&ctx);
|
||||||
return err;
|
return err;
|
||||||
@@ -208,7 +202,7 @@ static void netlink_disconnect(uint32_t dev_num)
|
|||||||
if (!msg)
|
if (!msg)
|
||||||
{
|
{
|
||||||
netlink_sock_free(&ctx);
|
netlink_sock_free(&ctx);
|
||||||
fail("Failed to allocate netlking message\n");
|
fail("Failed to allocate netlink message\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, ctx.driver_id, 0, 0, NBD_CMD_DISCONNECT, 0);
|
genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, ctx.driver_id, 0, 0, NBD_CMD_DISCONNECT, 0);
|
||||||
@@ -234,19 +228,14 @@ nla_put_failure:
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static int netlink_configure(const int *sockfd, int sock_size,
|
static int netlink_configure(const int *sockfd, int sock_size, int dev_num, uint64_t size,
|
||||||
int dev_num, uint64_t size,
|
uint64_t blocksize, uint64_t flags, uint64_t cflags, uint64_t timeout, uint64_t conn_timeout)
|
||||||
uint64_t blocksize, uint64_t flags,
|
|
||||||
uint64_t cflags, uint64_t timeout,
|
|
||||||
uint64_t conn_timeout)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "netlink is not supported\n");
|
fprintf(stderr, "netlink is not supported\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void netlink_disconnect(uint32_t dev_num)
|
static void netlink_disconnect(uint32_t dev_num)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "netlink is not supported\n");
|
fprintf(stderr, "netlink is not supported\n");
|
||||||
@@ -396,7 +385,7 @@ public:
|
|||||||
" is returned after no I/O is performed on device.\n"
|
" is returned after no I/O is performed on device.\n"
|
||||||
" By default is not set.\n"
|
" By default is not set.\n"
|
||||||
" --nbd_destroy_on_disconnect 1\n"
|
" --nbd_destroy_on_disconnect 1\n"
|
||||||
" Delete the nbd device on disconnect\n."
|
" Delete the nbd device on disconnect.\n"
|
||||||
" --nbd_disconnect_on_close 1\n"
|
" --nbd_disconnect_on_close 1\n"
|
||||||
" Disconnect the nbd device on close by last opener.\n"
|
" Disconnect the nbd device on close by last opener.\n"
|
||||||
" --nbd_ro 1\n"
|
" --nbd_ro 1\n"
|
||||||
@@ -560,13 +549,12 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int err = netlink_configure(sockfd + 1, 1, devnum, device_size, 4096, flags, cflags, nbd_timeout, nbd_lease);
|
int err = netlink_configure(sockfd + 1, 1, devnum, device_size, 4096, flags, cflags, nbd_timeout, nbd_lease);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
if (err == -NLE_BUSY) {
|
{
|
||||||
|
if (err == -NLE_BUSY)
|
||||||
errno = EBUSY;
|
errno = EBUSY;
|
||||||
} else {
|
else
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
}
|
|
||||||
|
|
||||||
perror("netlink_configure");
|
perror("netlink_configure");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user