quorum: Use qapi_enum_parse() in quorum_open()
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170822132255.23945-12-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, qemu_opt_get() factored out, commit message tweaked] Cc: Alberto Garcia <berto@igalia.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-9-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
f9509d1517
commit
8d5fb199fb
|
@ -22,6 +22,7 @@
|
||||||
#include "qapi/qmp/qjson.h"
|
#include "qapi/qmp/qjson.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
#include "qapi/qmp/qstring.h"
|
#include "qapi/qmp/qstring.h"
|
||||||
|
#include "qapi/util.h"
|
||||||
#include "qapi-event.h"
|
#include "qapi-event.h"
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
|
@ -867,30 +868,13 @@ static QemuOptsList quorum_runtime_opts = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int parse_read_pattern(const char *opt)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!opt) {
|
|
||||||
/* Set quorum as default */
|
|
||||||
return QUORUM_READ_PATTERN_QUORUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < QUORUM_READ_PATTERN__MAX; i++) {
|
|
||||||
if (!strcmp(opt, QuorumReadPattern_lookup[i])) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BDRVQuorumState *s = bs->opaque;
|
BDRVQuorumState *s = bs->opaque;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
QemuOpts *opts = NULL;
|
QemuOpts *opts = NULL;
|
||||||
|
const char *pattern_str;
|
||||||
bool *opened;
|
bool *opened;
|
||||||
int i;
|
int i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -925,7 +909,13 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = parse_read_pattern(qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN));
|
pattern_str = qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN);
|
||||||
|
if (!pattern_str) {
|
||||||
|
ret = QUORUM_READ_PATTERN_QUORUM;
|
||||||
|
} else {
|
||||||
|
ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str,
|
||||||
|
-EINVAL, NULL);
|
||||||
|
}
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg(&local_err, "Please set read-pattern as fifo or quorum");
|
error_setg(&local_err, "Please set read-pattern as fifo or quorum");
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
Loading…
Reference in New Issue