Browse Source

Add RDMA options to the QEMU driver

allow-etcd-address-option
Vitaliy Filippov 5 months ago
parent
commit
6a6fd6544d
  1. 26
      src/qemu_driver.c
  2. 12
      src/qemu_proxy.cpp
  3. 3
      src/qemu_proxy.h

26
src/qemu_driver.c

@ -47,6 +47,10 @@ typedef struct VitastorClient
uint64_t pool;
uint64_t size;
long readonly;
char *rdma_device;
int rdma_port_num;
int rdma_gid_index;
int rdma_mtu;
QemuMutex mutex;
} VitastorClient;
@ -95,7 +99,7 @@ static void qemu_rbd_unescape(char *src)
}
// vitastor[:key=value]*
// vitastor:etcd_host=127.0.0.1:inode=1:pool=1
// vitastor:etcd_host=127.0.0.1:inode=1:pool=1[:rdma_gid_index=3]
static void vitastor_parse_filename(const char *filename, QDict *options, Error **errp)
{
const char *start;
@ -123,7 +127,12 @@ static void vitastor_parse_filename(const char *filename, QDict *options, Error
qemu_rbd_unescape(name);
value = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(value);
if (!strcmp(name, "inode") || !strcmp(name, "pool") || !strcmp(name, "size"))
if (!strcmp(name, "inode") ||
!strcmp(name, "pool") ||
!strcmp(name, "size") ||
!strcmp(name, "rdma_port_num") ||
!strcmp(name, "rdma_gid_index") ||
!strcmp(name, "rdma_mtu"))
{
unsigned long long num_val;
if (parse_uint_full(value, &num_val, 0))
@ -191,7 +200,14 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
qemu_mutex_init(&client->mutex);
client->etcd_host = g_strdup(qdict_get_try_str(options, "etcd_host"));
client->etcd_prefix = g_strdup(qdict_get_try_str(options, "etcd_prefix"));
client->proxy = vitastor_proxy_create(bdrv_get_aio_context(bs), client->etcd_host, client->etcd_prefix);
client->rdma_device = g_strdup(qdict_get_try_str(options, "rdma_device"));
client->rdma_port_num = qdict_get_int(options, "rdma_port_num");
client->rdma_gid_index = qdict_get_int(options, "rdma_gid_index");
client->rdma_mtu = qdict_get_int(options, "rdma_mtu");
client->proxy = vitastor_proxy_create(
bdrv_get_aio_context(bs), client->etcd_host, client->etcd_prefix,
client->rdma_device, client->rdma_port_num, client->rdma_gid_index, client->rdma_mtu
);
client->image = g_strdup(qdict_get_try_str(options, "image"));
client->readonly = (flags & BDRV_O_RDWR) ? 1 : 0;
if (client->image)
@ -241,6 +257,10 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
}
bs->total_sectors = client->size / BDRV_SECTOR_SIZE;
//client->aio_context = bdrv_get_aio_context(bs);
qdict_del(options, "rdma_mtu");
qdict_del(options, "rdma_gid_index");
qdict_del(options, "rdma_port_num");
qdict_del(options, "rdma_device");
qdict_del(options, "etcd_host");
qdict_del(options, "etcd_prefix");
qdict_del(options, "image");

12
src/qemu_proxy.cpp

@ -34,12 +34,17 @@ public:
cluster_client_t *cli;
AioContext *ctx;
QemuProxy(AioContext *ctx, const char *etcd_host, const char *etcd_prefix)
QemuProxy(AioContext *ctx, const char *etcd_host, const char *etcd_prefix,
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
{
this->ctx = ctx;
json11::Json cfg = json11::Json::object {
{ "etcd_address", std::string(etcd_host) },
{ "etcd_prefix", std::string(etcd_prefix ? etcd_prefix : "/vitastor") },
{ "rdma_device", std::string(rdma_device ? rdma_device : "") },
{ "rdma_port_num", rdma_port_num },
{ "rdma_gid_index", rdma_gid_index },
{ "rdma_mtu", rdma_mtu },
};
tfd = new timerfd_manager_t([this](int fd, bool wr, std::function<void(int, int)> callback) { set_fd_handler(fd, wr, callback); });
cli = new cluster_client_t(NULL, tfd, cfg);
@ -80,9 +85,10 @@ public:
extern "C" {
void* vitastor_proxy_create(AioContext *ctx, const char *etcd_host, const char *etcd_prefix)
void* vitastor_proxy_create(AioContext *ctx, const char *etcd_host, const char *etcd_prefix,
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
{
QemuProxy *p = new QemuProxy(ctx, etcd_host, etcd_prefix);
QemuProxy *p = new QemuProxy(ctx, etcd_host, etcd_prefix, rdma_device, rdma_port_num, rdma_gid_index, rdma_mtu);
return p;
}

3
src/qemu_proxy.h

@ -16,7 +16,8 @@ extern "C" {
// Our exports
typedef void VitastorIOHandler(long retval, void *opaque);
void* vitastor_proxy_create(AioContext *ctx, const char *etcd_host, const char *etcd_prefix);
void* vitastor_proxy_create(AioContext *ctx, const char *etcd_host, const char *etcd_prefix,
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu);
void vitastor_proxy_destroy(void *client);
void vitastor_proxy_rw(int write, void *client, uint64_t inode, uint64_t offset, uint64_t len,
struct iovec *iov, int iovcnt, VitastorIOHandler cb, void *opaque);

Loading…
Cancel
Save