Pass options correctly to not override /etc/vitastor/vitastor.conf
parent
72aa2fd819
commit
f6f35f4127
|
@ -50,6 +50,11 @@ void etcd_state_client_t::etcd_txn(json11::Json txn, int timeout, std::function<
|
||||||
|
|
||||||
void etcd_state_client_t::etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback)
|
void etcd_state_client_t::etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback)
|
||||||
{
|
{
|
||||||
|
if (!etcd_addresses.size())
|
||||||
|
{
|
||||||
|
fprintf(stderr, "etcd_address is missing in Vitastor configuration\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
std::string etcd_address = etcd_addresses[rand() % etcd_addresses.size()];
|
std::string etcd_address = etcd_addresses[rand() % etcd_addresses.size()];
|
||||||
std::string etcd_api_path;
|
std::string etcd_api_path;
|
||||||
int pos = etcd_address.find('/');
|
int pos = etcd_address.find('/');
|
||||||
|
@ -122,6 +127,11 @@ void etcd_state_client_t::parse_config(const json11::Json & config)
|
||||||
|
|
||||||
void etcd_state_client_t::start_etcd_watcher()
|
void etcd_state_client_t::start_etcd_watcher()
|
||||||
{
|
{
|
||||||
|
if (!etcd_addresses.size())
|
||||||
|
{
|
||||||
|
fprintf(stderr, "etcd_address is missing in Vitastor configuration\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
std::string etcd_address = etcd_addresses[rand() % etcd_addresses.size()];
|
std::string etcd_address = etcd_addresses[rand() % etcd_addresses.size()];
|
||||||
std::string etcd_api_path;
|
std::string etcd_api_path;
|
||||||
int pos = etcd_address.find('/');
|
int pos = etcd_address.find('/');
|
||||||
|
|
|
@ -45,6 +45,7 @@ struct sec_data
|
||||||
struct sec_options
|
struct sec_options
|
||||||
{
|
{
|
||||||
int __pad;
|
int __pad;
|
||||||
|
char *config_path = NULL;
|
||||||
char *etcd_host = NULL;
|
char *etcd_host = NULL;
|
||||||
char *etcd_prefix = NULL;
|
char *etcd_prefix = NULL;
|
||||||
char *image = NULL;
|
char *image = NULL;
|
||||||
|
@ -60,6 +61,15 @@ struct sec_options
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct fio_option options[] = {
|
static struct fio_option options[] = {
|
||||||
|
{
|
||||||
|
.name = "conf",
|
||||||
|
.lname = "Vitastor config path",
|
||||||
|
.type = FIO_OPT_STR_STORE,
|
||||||
|
.off1 = offsetof(struct sec_options, config_path),
|
||||||
|
.help = "Vitastor config path",
|
||||||
|
.category = FIO_OPT_C_ENGINE,
|
||||||
|
.group = FIO_OPT_G_FILENAME,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "etcd",
|
.name = "etcd",
|
||||||
.lname = "etcd address",
|
.lname = "etcd address",
|
||||||
|
@ -131,7 +141,7 @@ static struct fio_option options[] = {
|
||||||
.type = FIO_OPT_BOOL,
|
.type = FIO_OPT_BOOL,
|
||||||
.off1 = offsetof(struct sec_options, use_rdma),
|
.off1 = offsetof(struct sec_options, use_rdma),
|
||||||
.help = "Use RDMA",
|
.help = "Use RDMA",
|
||||||
.def = "0",
|
.def = "-1",
|
||||||
.category = FIO_OPT_C_ENGINE,
|
.category = FIO_OPT_C_ENGINE,
|
||||||
.group = FIO_OPT_G_FILENAME,
|
.group = FIO_OPT_G_FILENAME,
|
||||||
},
|
},
|
||||||
|
@ -184,12 +194,6 @@ static int sec_setup(struct thread_data *td)
|
||||||
sec_options *o = (sec_options*)td->eo;
|
sec_options *o = (sec_options*)td->eo;
|
||||||
sec_data *bsd;
|
sec_data *bsd;
|
||||||
|
|
||||||
if (!o->etcd_host)
|
|
||||||
{
|
|
||||||
td_verror(td, EINVAL, "etcd address is missing");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bsd = new sec_data;
|
bsd = new sec_data;
|
||||||
if (!bsd)
|
if (!bsd)
|
||||||
{
|
{
|
||||||
|
@ -205,16 +209,26 @@ static int sec_setup(struct thread_data *td)
|
||||||
td->o.open_files++;
|
td->o.open_files++;
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json cfg = json11::Json::object {
|
json11::Json::object cfg;
|
||||||
{ "etcd_address", std::string(o->etcd_host) },
|
if (o->config_path)
|
||||||
{ "etcd_prefix", std::string(o->etcd_prefix ? o->etcd_prefix : "/vitastor") },
|
cfg["config_path"] = std::string(o->config_path);
|
||||||
{ "log_level", o->cluster_log },
|
if (o->etcd_host)
|
||||||
{ "use_rdma", o->use_rdma },
|
cfg["etcd_address"] = std::string(o->etcd_host);
|
||||||
{ "rdma_device", std::string(o->rdma_device ? o->rdma_device : "") },
|
if (o->etcd_prefix)
|
||||||
{ "rdma_port_num", o->rdma_port_num },
|
cfg["etcd_prefix"] = std::string(o->etcd_prefix);
|
||||||
{ "rdma_gid_index", o->rdma_gid_index },
|
if (o->rdma_device)
|
||||||
{ "rdma_mtu", o->rdma_mtu },
|
cfg["rdma_device"] = std::string(o->rdma_device);
|
||||||
};
|
if (o->rdma_port_num)
|
||||||
|
cfg["rdma_port_num"] = o->rdma_port_num;
|
||||||
|
if (o->rdma_gid_index)
|
||||||
|
cfg["rdma_gid_index"] = o->rdma_gid_index;
|
||||||
|
if (o->rdma_mtu)
|
||||||
|
cfg["rdma_mtu"] = o->rdma_mtu;
|
||||||
|
if (o->cluster_log)
|
||||||
|
cfg["log_level"] = o->cluster_log;
|
||||||
|
if (o->use_rdma != -1)
|
||||||
|
cfg["use_rdma"] = o->use_rdma;
|
||||||
|
json11::Json cfg_json(cfg);
|
||||||
|
|
||||||
if (!o->image)
|
if (!o->image)
|
||||||
{
|
{
|
||||||
|
@ -239,7 +253,7 @@ static int sec_setup(struct thread_data *td)
|
||||||
}
|
}
|
||||||
bsd->ringloop = new ring_loop_t(512);
|
bsd->ringloop = new ring_loop_t(512);
|
||||||
bsd->epmgr = new epoll_manager_t(bsd->ringloop);
|
bsd->epmgr = new epoll_manager_t(bsd->ringloop);
|
||||||
bsd->cli = new cluster_client_t(bsd->ringloop, bsd->epmgr->tfd, cfg);
|
bsd->cli = new cluster_client_t(bsd->ringloop, bsd->epmgr->tfd, cfg_json);
|
||||||
if (o->image)
|
if (o->image)
|
||||||
{
|
{
|
||||||
while (!bsd->cli->is_ready())
|
while (!bsd->cli->is_ready())
|
||||||
|
|
|
@ -116,7 +116,7 @@ public:
|
||||||
"Vitastor NBD proxy\n"
|
"Vitastor NBD proxy\n"
|
||||||
"(c) Vitaliy Filippov, 2020-2021 (VNPL-1.1)\n\n"
|
"(c) Vitaliy Filippov, 2020-2021 (VNPL-1.1)\n\n"
|
||||||
"USAGE:\n"
|
"USAGE:\n"
|
||||||
" %s map --etcd_address <etcd_address> (--image <image> | --pool <pool> --inode <inode> --size <size in bytes>)\n"
|
" %s map [--etcd_address <etcd_address>] (--image <image> | --pool <pool> --inode <inode> --size <size in bytes>)\n"
|
||||||
" %s unmap /dev/nbd0\n"
|
" %s unmap /dev/nbd0\n"
|
||||||
" %s list [--json]\n",
|
" %s list [--json]\n",
|
||||||
exe_name, exe_name, exe_name
|
exe_name, exe_name, exe_name
|
||||||
|
@ -146,11 +146,6 @@ public:
|
||||||
void start(json11::Json cfg)
|
void start(json11::Json cfg)
|
||||||
{
|
{
|
||||||
// Check options
|
// Check options
|
||||||
if (cfg["etcd_address"].string_value() == "")
|
|
||||||
{
|
|
||||||
fprintf(stderr, "etcd_address is missing\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (cfg["image"].string_value() != "")
|
if (cfg["image"].string_value() != "")
|
||||||
{
|
{
|
||||||
// Use image name
|
// Use image name
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef struct VitastorClient
|
||||||
{
|
{
|
||||||
void *proxy;
|
void *proxy;
|
||||||
void *watch;
|
void *watch;
|
||||||
|
char *config_path;
|
||||||
char *etcd_host;
|
char *etcd_host;
|
||||||
char *etcd_prefix;
|
char *etcd_prefix;
|
||||||
char *image;
|
char *image;
|
||||||
|
@ -99,7 +100,8 @@ static void qemu_rbd_unescape(char *src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// vitastor[:key=value]*
|
// vitastor[:key=value]*
|
||||||
// vitastor:etcd_host=127.0.0.1:inode=1:pool=1[:rdma_gid_index=3]
|
// vitastor[:etcd_host=127.0.0.1]:inode=1:pool=1[:rdma_gid_index=3]
|
||||||
|
// vitastor:config_path=/etc/vitastor/vitastor.conf:image=testimg
|
||||||
static void vitastor_parse_filename(const char *filename, QDict *options, Error **errp)
|
static void vitastor_parse_filename(const char *filename, QDict *options, Error **errp)
|
||||||
{
|
{
|
||||||
const char *start;
|
const char *start;
|
||||||
|
@ -166,11 +168,6 @@ static void vitastor_parse_filename(const char *filename, QDict *options, Error
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!qdict_get_str(options, "etcd_host"))
|
|
||||||
{
|
|
||||||
error_setg(errp, "etcd_host is missing");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
|
@ -198,6 +195,7 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
|
||||||
VitastorClient *client = bs->opaque;
|
VitastorClient *client = bs->opaque;
|
||||||
int64_t ret = 0;
|
int64_t ret = 0;
|
||||||
qemu_mutex_init(&client->mutex);
|
qemu_mutex_init(&client->mutex);
|
||||||
|
client->config_path = g_strdup(qdict_get_try_str(options, "config_path"));
|
||||||
client->etcd_host = g_strdup(qdict_get_try_str(options, "etcd_host"));
|
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->etcd_prefix = g_strdup(qdict_get_try_str(options, "etcd_prefix"));
|
||||||
client->rdma_device = g_strdup(qdict_get_try_str(options, "rdma_device"));
|
client->rdma_device = g_strdup(qdict_get_try_str(options, "rdma_device"));
|
||||||
|
@ -205,7 +203,7 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
|
||||||
client->rdma_gid_index = qdict_get_int(options, "rdma_gid_index");
|
client->rdma_gid_index = qdict_get_int(options, "rdma_gid_index");
|
||||||
client->rdma_mtu = qdict_get_int(options, "rdma_mtu");
|
client->rdma_mtu = qdict_get_int(options, "rdma_mtu");
|
||||||
client->proxy = vitastor_proxy_create(
|
client->proxy = vitastor_proxy_create(
|
||||||
bdrv_get_aio_context(bs), client->etcd_host, client->etcd_prefix,
|
bdrv_get_aio_context(bs), client->config_path, client->etcd_host, client->etcd_prefix,
|
||||||
client->rdma_device, client->rdma_port_num, client->rdma_gid_index, client->rdma_mtu
|
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->image = g_strdup(qdict_get_try_str(options, "image"));
|
||||||
|
@ -261,6 +259,7 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
|
||||||
qdict_del(options, "rdma_gid_index");
|
qdict_del(options, "rdma_gid_index");
|
||||||
qdict_del(options, "rdma_port_num");
|
qdict_del(options, "rdma_port_num");
|
||||||
qdict_del(options, "rdma_device");
|
qdict_del(options, "rdma_device");
|
||||||
|
qdict_del(options, "config_path");
|
||||||
qdict_del(options, "etcd_host");
|
qdict_del(options, "etcd_host");
|
||||||
qdict_del(options, "etcd_prefix");
|
qdict_del(options, "etcd_prefix");
|
||||||
qdict_del(options, "image");
|
qdict_del(options, "image");
|
||||||
|
@ -275,7 +274,10 @@ static void vitastor_close(BlockDriverState *bs)
|
||||||
VitastorClient *client = bs->opaque;
|
VitastorClient *client = bs->opaque;
|
||||||
vitastor_proxy_destroy(client->proxy);
|
vitastor_proxy_destroy(client->proxy);
|
||||||
qemu_mutex_destroy(&client->mutex);
|
qemu_mutex_destroy(&client->mutex);
|
||||||
g_free(client->etcd_host);
|
if (client->config_path)
|
||||||
|
g_free(client->config_path);
|
||||||
|
if (client->etcd_host)
|
||||||
|
g_free(client->etcd_host);
|
||||||
if (client->etcd_prefix)
|
if (client->etcd_prefix)
|
||||||
g_free(client->etcd_prefix);
|
g_free(client->etcd_prefix);
|
||||||
if (client->image)
|
if (client->image)
|
||||||
|
@ -498,6 +500,7 @@ static QEMUOptionParameter vitastor_create_opts[] = {
|
||||||
static const char *vitastor_strong_runtime_opts[] = {
|
static const char *vitastor_strong_runtime_opts[] = {
|
||||||
"inode",
|
"inode",
|
||||||
"pool",
|
"pool",
|
||||||
|
"config_path",
|
||||||
"etcd_host",
|
"etcd_host",
|
||||||
"etcd_prefix",
|
"etcd_prefix",
|
||||||
|
|
||||||
|
|
|
@ -34,20 +34,28 @@ public:
|
||||||
cluster_client_t *cli;
|
cluster_client_t *cli;
|
||||||
AioContext *ctx;
|
AioContext *ctx;
|
||||||
|
|
||||||
QemuProxy(AioContext *ctx, const char *etcd_host, const char *etcd_prefix,
|
QemuProxy(AioContext *ctx, const char *config_path, const char *etcd_host, const char *etcd_prefix,
|
||||||
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
|
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
|
||||||
{
|
{
|
||||||
this->ctx = ctx;
|
this->ctx = ctx;
|
||||||
json11::Json cfg = json11::Json::object {
|
json11::Json::object cfg;
|
||||||
{ "etcd_address", std::string(etcd_host) },
|
if (config_path)
|
||||||
{ "etcd_prefix", std::string(etcd_prefix ? etcd_prefix : "/vitastor") },
|
cfg["config_path"] = std::string(config_path);
|
||||||
{ "rdma_device", std::string(rdma_device ? rdma_device : "") },
|
if (etcd_host)
|
||||||
{ "rdma_port_num", rdma_port_num },
|
cfg["etcd_address"] = std::string(etcd_host);
|
||||||
{ "rdma_gid_index", rdma_gid_index },
|
if (etcd_prefix)
|
||||||
{ "rdma_mtu", rdma_mtu },
|
cfg["etcd_prefix"] = std::string(etcd_prefix);
|
||||||
};
|
if (rdma_device)
|
||||||
|
cfg["rdma_device"] = std::string(rdma_device);
|
||||||
|
if (rdma_port_num)
|
||||||
|
cfg["rdma_port_num"] = rdma_port_num;
|
||||||
|
if (rdma_gid_index)
|
||||||
|
cfg["rdma_gid_index"] = rdma_gid_index;
|
||||||
|
if (rdma_mtu)
|
||||||
|
cfg["rdma_mtu"] = rdma_mtu;
|
||||||
|
json11::Json cfg_json(cfg);
|
||||||
tfd = new timerfd_manager_t([this](int fd, bool wr, std::function<void(int, int)> callback) { set_fd_handler(fd, wr, callback); });
|
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);
|
cli = new cluster_client_t(NULL, tfd, cfg_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
~QemuProxy()
|
~QemuProxy()
|
||||||
|
@ -85,10 +93,10 @@ public:
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void* vitastor_proxy_create(AioContext *ctx, const char *etcd_host, const char *etcd_prefix,
|
void* vitastor_proxy_create(AioContext *ctx, const char *config_path, const char *etcd_host, const char *etcd_prefix,
|
||||||
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
|
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu)
|
||||||
{
|
{
|
||||||
QemuProxy *p = new QemuProxy(ctx, etcd_host, etcd_prefix, rdma_device, rdma_port_num, rdma_gid_index, rdma_mtu);
|
QemuProxy *p = new QemuProxy(ctx, config_path, etcd_host, etcd_prefix, rdma_device, rdma_port_num, rdma_gid_index, rdma_mtu);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ extern "C" {
|
||||||
|
|
||||||
// Our exports
|
// Our exports
|
||||||
typedef void VitastorIOHandler(long retval, void *opaque);
|
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 *config_path, const char *etcd_host, const char *etcd_prefix,
|
||||||
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu);
|
const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu);
|
||||||
void vitastor_proxy_destroy(void *client);
|
void vitastor_proxy_destroy(void *client);
|
||||||
void vitastor_proxy_rw(int write, void *client, uint64_t inode, uint64_t offset, uint64_t len,
|
void vitastor_proxy_rw(int write, void *client, uint64_t inode, uint64_t offset, uint64_t len,
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
"Vitastor inode removal tool\n"
|
"Vitastor inode removal tool\n"
|
||||||
"(c) Vitaliy Filippov, 2020 (VNPL-1.1)\n\n"
|
"(c) Vitaliy Filippov, 2020 (VNPL-1.1)\n\n"
|
||||||
"USAGE:\n"
|
"USAGE:\n"
|
||||||
" %s --etcd_address <etcd_address> --pool <pool> --inode <inode> [--wait-list]\n",
|
" %s [--etcd_address <etcd_address>] --pool <pool> --inode <inode> [--wait-list]\n",
|
||||||
exe_name
|
exe_name
|
||||||
);
|
);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -95,11 +95,6 @@ public:
|
||||||
|
|
||||||
void run(json11::Json cfg)
|
void run(json11::Json cfg)
|
||||||
{
|
{
|
||||||
if (cfg["etcd_address"].string_value() == "")
|
|
||||||
{
|
|
||||||
fprintf(stderr, "etcd_address is missing\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
inode = cfg["inode"].uint64_value();
|
inode = cfg["inode"].uint64_value();
|
||||||
pool_id = cfg["pool"].uint64_value();
|
pool_id = cfg["pool"].uint64_value();
|
||||||
if (pool_id)
|
if (pool_id)
|
||||||
|
|
Loading…
Reference in New Issue