本文整理汇总了C++中qemu_opts_create函数的典型用法代码示例。如果您正苦于以下问题:C++ qemu_opts_create函数的具体用法?C++ qemu_opts_create怎么用?C++ qemu_opts_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qemu_opts_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qemu_config_parse
int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
{
char line[1024], group[64], id[64], arg[64], value[1024];
Location loc;
QemuOptsList *list = NULL;
QemuOpts *opts = NULL;
int res = -1, lno = 0;
loc_push_none(&loc);
while (fgets(line, sizeof(line), fp) != NULL) {
loc_set_file(fname, ++lno);
if (line[0] == '\n') {
/* skip empty lines */
continue;
}
if (line[0] == '#') {
/* comment */
continue;
}
if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
/* group with id */
list = find_list(lists, group);
if (list == NULL)
goto out;
opts = qemu_opts_create(list, id, 1);
continue;
}
if (sscanf(line, "[%63[^]]]", group) == 1) {
/* group without id */
list = find_list(lists, group);
if (list == NULL)
goto out;
opts = qemu_opts_create(list, NULL, 0);
continue;
}
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
/* arg = value */
if (opts == NULL) {
error_report("no group defined");
goto out;
}
if (qemu_opt_set(opts, arg, value) != 0) {
goto out;
}
continue;
}
error_report("parse error");
goto out;
}
if (ferror(fp)) {
error_report("error reading file");
goto out;
}
res = 0;
out:
loc_pop(&loc);
return res;
}
示例2: qemu_config_parse
int qemu_config_parse(FILE *fp)
{
char line[1024], group[64], id[64], arg[64], value[1024];
QemuOptsList *list = NULL;
QemuOpts *opts = NULL;
while (fgets(line, sizeof(line), fp) != NULL) {
if (line[0] == '\n') {
/* skip empty lines */
continue;
}
if (line[0] == '#') {
/* comment */
continue;
}
if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
/* group with id */
list = find_list(group);
if (list == NULL)
return -1;
opts = qemu_opts_create(list, id, 1);
continue;
}
if (sscanf(line, "[%63[^]]]", group) == 1) {
/* group without id */
list = find_list(group);
if (list == NULL)
return -1;
opts = qemu_opts_create(list, NULL, 0);
continue;
}
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
/* arg = value */
if (opts == NULL) {
fprintf(stderr, "no group defined\n");
return -1;
}
if (qemu_opt_set(opts, arg, value) != 0) {
fprintf(stderr, "failed to set \"%s\" for %s\n",
arg, group);
return -1;
}
continue;
}
fprintf(stderr, "parse error: %s\n", line);
return -1;
}
return 0;
}
示例3: char_ringbuf_test
static void char_ringbuf_test(void)
{
QemuOpts *opts;
Chardev *chr;
CharBackend be;
char *data;
int ret;
opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
1, &error_abort);
qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
qemu_opt_set(opts, "size", "5", &error_abort);
chr = qemu_chr_new_from_opts(opts, NULL);
g_assert_null(chr);
qemu_opts_del(opts);
opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
1, &error_abort);
qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
qemu_opt_set(opts, "size", "2", &error_abort);
chr = qemu_chr_new_from_opts(opts, &error_abort);
g_assert_nonnull(chr);
qemu_opts_del(opts);
qemu_chr_fe_init(&be, chr, &error_abort);
ret = qemu_chr_fe_write(&be, (void *)"buff", 4);
g_assert_cmpint(ret, ==, 4);
data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
g_assert_cmpstr(data, ==, "ff");
g_free(data);
data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
g_assert_cmpstr(data, ==, "");
g_free(data);
qemu_chr_fe_deinit(&be, true);
/* check alias */
opts = qemu_opts_create(qemu_find_opts("chardev"), "memory-label",
1, &error_abort);
qemu_opt_set(opts, "backend", "memory", &error_abort);
qemu_opt_set(opts, "size", "2", &error_abort);
chr = qemu_chr_new_from_opts(opts, NULL);
g_assert_nonnull(chr);
object_unparent(OBJECT(chr));
qemu_opts_del(opts);
}
示例4: inet_listen
int inet_listen(const char *str, char *ostr, int olen,
int socktype, int port_offset, Error **errp)
{
QemuOpts *opts;
char *optstr;
int sock = -1;
InetSocketAddress *addr;
addr = inet_parse(str, errp);
if (addr != NULL) {
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
inet_addr_to_opts(opts, addr);
qapi_free_InetSocketAddress(addr);
sock = inet_listen_opts(opts, port_offset, errp);
if (sock != -1 && ostr) {
optstr = strchr(str, ',');
if (qemu_opt_get_bool(opts, "ipv6", 0)) {
snprintf(ostr, olen, "[%s]:%s%s",
qemu_opt_get(opts, "host"),
qemu_opt_get(opts, "port"),
optstr ? optstr : "");
} else {
snprintf(ostr, olen, "%s:%s%s",
qemu_opt_get(opts, "host"),
qemu_opt_get(opts, "port"),
optstr ? optstr : "");
}
}
qemu_opts_del(opts);
}
return sock;
}
示例5: inet_listen
int inet_listen(const char *str, char *ostr, int olen,
int socktype, int port_offset)
{
QemuOpts *opts;
char *optstr;
int sock = -1;
opts = qemu_opts_create(&dummy_opts, NULL, 0);
if (inet_parse(opts, str) == 0) {
sock = inet_listen_opts(opts, port_offset);
if (sock != -1 && ostr) {
optstr = strchr(str, ',');
if (qemu_opt_get_bool(opts, "ipv6", 0)) {
snprintf(ostr, olen, "[%s]:%s%s",
qemu_opt_get(opts, "host"),
qemu_opt_get(opts, "port"),
optstr ? optstr : "");
} else {
snprintf(ostr, olen, "%s:%s%s",
qemu_opt_get(opts, "host"),
qemu_opt_get(opts, "port"),
optstr ? optstr : "");
}
}
}
qemu_opts_del(opts);
return sock;
}
示例6: socket_connect
int socket_connect(SocketAddress *addr, Error **errp,
NonBlockingConnectHandler *callback, void *opaque)
{
QemuOpts *opts;
int fd;
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
switch (addr->kind) {
case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, addr->inet);
fd = inet_connect_opts(opts, errp, callback, opaque);
break;
case SOCKET_ADDRESS_KIND_UNIX:
qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_connect_opts(opts, errp, callback, opaque);
break;
case SOCKET_ADDRESS_KIND_FD:
fd = monitor_get_fd(cur_mon, addr->fd->str, errp);
if (fd >= 0 && callback) {
qemu_set_nonblock(fd);
callback(fd, NULL, opaque);
}
break;
default:
abort();
}
qemu_opts_del(opts);
return fd;
}
示例7: test_qemu_opts_create
static void test_qemu_opts_create(void)
{
QemuOptsList *list;
QemuOpts *opts;
list = qemu_find_opts("opts_list_01");
g_assert(list != NULL);
g_assert(QTAILQ_EMPTY(&list->head));
g_assert_cmpstr(list->name, ==, "opts_list_01");
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
/* create the opts */
opts = qemu_opts_create(list, NULL, 0, &error_abort);
g_assert(opts != NULL);
g_assert(!QTAILQ_EMPTY(&list->head));
/* now we've create the opts, must find it */
opts = qemu_opts_find(list, NULL);
g_assert(opts != NULL);
qemu_opts_del(opts);
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
}
示例8: unix_listen
/* compatibility wrapper */
int unix_listen(const char *str, char *ostr, int olen)
{
QemuOpts *opts;
char *path, *optstr;
int sock, len;
opts = qemu_opts_create(&dummy_opts, NULL, 0);
optstr = strchr(str, ',');
if (optstr) {
len = optstr - str;
if (len) {
path = qemu_malloc(len+1);
snprintf(path, len+1, "%.*s", len, str);
qemu_opt_set(opts, "path", path);
qemu_free(path);
}
} else {
qemu_opt_set(opts, "path", str);
}
sock = unix_listen_opts(opts);
if (sock != -1 && ostr)
snprintf(ostr, olen, "%s%s", qemu_opt_get(opts, "path"), optstr ? optstr : "");
qemu_opts_del(opts);
return sock;
}
示例9: socket_listen
int socket_listen(SocketAddress *addr, Error **errp)
{
QemuOpts *opts;
int fd;
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
switch (addr->kind) {
case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, addr->inet);
fd = inet_listen_opts(opts, 0, errp);
break;
case SOCKET_ADDRESS_KIND_UNIX:
qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_listen_opts(opts, errp);
break;
case SOCKET_ADDRESS_KIND_FD:
fd = monitor_get_fd(cur_mon, addr->fd->str, errp);
break;
default:
abort();
}
qemu_opts_del(opts);
return fd;
}
示例10: qemu_archipelago_open
static int qemu_archipelago_open(BlockDriverState *bs,
QDict *options,
int bdrv_flags,
Error **errp)
{
int ret = 0;
const char *volume, *segment_name;
QemuOpts *opts;
Error *local_err = NULL;
BDRVArchipelagoState *s = bs->opaque;
opts = qemu_opts_create(&archipelago_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto err_exit;
}
s->mportno = qemu_opt_get_number(opts, ARCHIPELAGO_OPT_MPORT,
ARCHIPELAGO_DFL_MPORT);
s->vportno = qemu_opt_get_number(opts, ARCHIPELAGO_OPT_VPORT,
ARCHIPELAGO_DFL_VPORT);
segment_name = qemu_opt_get(opts, ARCHIPELAGO_OPT_SEGMENT);
if (segment_name == NULL) {
s->segment_name = g_strdup("archipelago");
} else {
s->segment_name = g_strdup(segment_name);
}
volume = qemu_opt_get(opts, ARCHIPELAGO_OPT_VOLUME);
if (volume == NULL) {
error_setg(errp, "archipelago block driver requires the 'volume'"
" option");
ret = -EINVAL;
goto err_exit;
}
s->volname = g_strdup(volume);
/* Initialize XSEG, join shared memory segment */
ret = qemu_archipelago_init(s);
if (ret < 0) {
error_setg(errp, "cannot initialize XSEG and join shared "
"memory segment");
goto err_exit;
}
qemu_opts_del(opts);
return 0;
err_exit:
g_free(s->volname);
g_free(s->segment_name);
qemu_opts_del(opts);
return ret;
}
示例11: test_qemu_opt_get_size
static void test_qemu_opt_get_size(void)
{
QemuOptsList *list;
QemuOpts *opts;
uint64_t opt;
QDict *dict;
list = qemu_find_opts("opts_list_02");
g_assert(list != NULL);
g_assert(QTAILQ_EMPTY(&list->head));
g_assert_cmpstr(list->name, ==, "opts_list_02");
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
/* create the opts */
opts = qemu_opts_create(list, NULL, 0, &error_abort);
g_assert(opts != NULL);
g_assert(!QTAILQ_EMPTY(&list->head));
/* haven't set anything to size1 yet, so defval should be returned */
opt = qemu_opt_get_size(opts, "size1", 5);
g_assert(opt == 5);
dict = qdict_new();
g_assert(dict != NULL);
qdict_put(dict, "size1", qstring_from_str("10"));
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
/* now we have set size1, should know about it */
opt = qemu_opt_get_size(opts, "size1", 5);
g_assert(opt == 10);
/* reset value */
qdict_put(dict, "size1", qstring_from_str("15"));
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
/* test the reset value */
opt = qemu_opt_get_size(opts, "size1", 5);
g_assert(opt == 15);
qdict_del(dict, "size1");
g_free(dict);
qemu_opts_del(opts);
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
}
示例12: snprintf
static USBDevice *usb_msd_init(const char *filename)
{
static int nr=0;
char id[8];
QemuOpts *opts;
DriveInfo *dinfo;
USBDevice *dev;
int fatal_error;
const char *p1;
char fmt[32];
/* parse -usbdevice disk: syntax into drive opts */
snprintf(id, sizeof(id), "usb%d", nr++);
opts = qemu_opts_create(&qemu_drive_opts, id, 0);
p1 = strchr(filename, ':');
if (p1++) {
const char *p2;
if (strstart(filename, "format=", &p2)) {
int len = MIN(p1 - p2, sizeof(fmt));
pstrcpy(fmt, len, p2);
qemu_opt_set(opts, "format", fmt);
} else if (*filename != ':') {
printf("unrecognized USB mass-storage option %s\n", filename);
return NULL;
}
filename = p1;
}
if (!*filename) {
printf("block device specification needed\n");
return NULL;
}
qemu_opt_set(opts, "file", filename);
qemu_opt_set(opts, "if", "none");
/* create host drive */
dinfo = drive_init(opts, NULL, &fatal_error);
if (!dinfo) {
qemu_opts_del(opts);
return NULL;
}
/* create guest device */
dev = usb_create(NULL /* FIXME */, "usb-storage");
if (!dev) {
return NULL;
}
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
if (qdev_init(&dev->qdev) < 0)
return NULL;
return dev;
}
示例13: unix_connect
int unix_connect(const char *path, Error **errp)
{
QemuOpts *opts;
int sock;
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
qemu_opt_set(opts, "path", path, &error_abort);
sock = unix_connect_opts(opts, errp, NULL, NULL);
qemu_opts_del(opts);
return sock;
}
示例14: block_crypto_open_generic
static int block_crypto_open_generic(QCryptoBlockFormat format,
QemuOptsList *opts_spec,
BlockDriverState *bs,
QDict *options,
int flags,
Error **errp)
{
BlockCrypto *crypto = bs->opaque;
QemuOpts *opts = NULL;
Error *local_err = NULL;
int ret = -EINVAL;
QCryptoBlockOpenOptions *open_opts = NULL;
unsigned int cflags = 0;
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto cleanup;
}
open_opts = block_crypto_open_opts_init(format, opts, errp);
if (!open_opts) {
goto cleanup;
}
if (flags & BDRV_O_NO_IO) {
cflags |= QCRYPTO_BLOCK_OPEN_NO_IO;
}
crypto->block = qcrypto_block_open(open_opts,
block_crypto_read_func,
bs,
cflags,
errp);
if (!crypto->block) {
ret = -EIO;
goto cleanup;
}
bs->encrypted = true;
bs->valid_key = true;
ret = 0;
cleanup:
qapi_free_QCryptoBlockOpenOptions(open_opts);
return ret;
}
示例15: inet_connect
int inet_connect(const char *str, int socktype)
{
QemuOpts *opts;
int sock = -1;
opts = qemu_opts_create(&dummy_opts, NULL, 0);
if (inet_parse(opts, str) == 0)
sock = inet_connect_opts(opts);
qemu_opts_del(opts);
return sock;
}