aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-06-11 21:34:08 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-06-11 21:34:08 +0100
commit05fedeef835c3c889e5d2e44f8abb11dcfcadefc (patch)
tree8dbcf074dec8246cb542e68f6b84c7abf5176e50
parent706808585a49bfd266e00b1c7723b6e1b0f4ff35 (diff)
parenta491af471bf8f1188b2665f54d109065d4591e45 (diff)
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging
* remotes/qmp-unstable/queue/qmp: json-parser: drop superfluous assignment for token variable readline: Clear screen on form feed. monitor: Add delvm and loadvm argument completion monitor: Add host_net_remove arguments completion readline: Make completion strings always unique monitor: Add host_net_add device argument completion net: Export valid host network devices list monitor: Add migrate_set_capability completion monitor: Add watchdog_action argument completion monitor: Add ringbuf_write and ringbuf_read argument completion dump: simplify get_len_buf_out() dump: hoist lzo_init() from get_len_buf_out() to dump_init() dump: select header bitness based on ELF class, not ELF architecture dump: eliminate DumpState.page_size ("guest's page size") dump: eliminate DumpState.page_shift ("guest's page shift") dump: simplify write_start_flat_header() dump: fill in the flat header signature more pleasingly to the eye Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--dump.c142
-rw-r--r--hmp-commands.hx10
-rw-r--r--hmp.h11
-rw-r--r--include/net/net.h1
-rw-r--r--include/sysemu/char.h3
-rw-r--r--include/sysemu/dump.h8
-rw-r--r--monitor.c176
-rw-r--r--net/net.c34
-rw-r--r--qemu-char.c2
-rw-r--r--qobject/json-parser.c15
-rw-r--r--util/readline.c15
11 files changed, 301 insertions, 116 deletions
diff --git a/dump.c b/dump.c
index e56b7cfc25..97d2c8dcef 100644
--- a/dump.c
+++ b/dump.c
@@ -90,8 +90,6 @@ typedef struct DumpState {
uint8_t *note_buf; /* buffer for notes */
size_t note_buf_offset; /* the writing place in note_buf */
uint32_t nr_cpus; /* number of guest's cpu */
- size_t page_size; /* guest's page size */
- uint32_t page_shift; /* guest's page shift */
uint64_t max_mapnr; /* the biggest guest's phys-mem's number */
size_t len_dump_bitmap; /* the size of the place used to store
dump_bitmap in vmcore */
@@ -711,27 +709,25 @@ static int create_vmcore(DumpState *s)
static int write_start_flat_header(int fd)
{
- uint8_t *buf;
- MakedumpfileHeader mh;
+ MakedumpfileHeader *mh;
int ret = 0;
- memset(&mh, 0, sizeof(mh));
- strncpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
- strlen(MAKEDUMPFILE_SIGNATURE));
+ QEMU_BUILD_BUG_ON(sizeof *mh > MAX_SIZE_MDF_HEADER);
+ mh = g_malloc0(MAX_SIZE_MDF_HEADER);
- mh.type = cpu_to_be64(TYPE_FLAT_HEADER);
- mh.version = cpu_to_be64(VERSION_FLAT_HEADER);
+ memcpy(mh->signature, MAKEDUMPFILE_SIGNATURE,
+ MIN(sizeof mh->signature, sizeof MAKEDUMPFILE_SIGNATURE));
- buf = g_malloc0(MAX_SIZE_MDF_HEADER);
- memcpy(buf, &mh, sizeof(mh));
+ mh->type = cpu_to_be64(TYPE_FLAT_HEADER);
+ mh->version = cpu_to_be64(VERSION_FLAT_HEADER);
size_t written_size;
- written_size = qemu_write_full(fd, buf, MAX_SIZE_MDF_HEADER);
+ written_size = qemu_write_full(fd, mh, MAX_SIZE_MDF_HEADER);
if (written_size != MAX_SIZE_MDF_HEADER) {
ret = -1;
}
- g_free(buf);
+ g_free(mh);
return ret;
}
@@ -808,7 +804,7 @@ static int create_header32(DumpState *s)
strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
dh->header_version = cpu_convert_to_target32(6, endian);
- block_size = s->page_size;
+ block_size = TARGET_PAGE_SIZE;
dh->block_size = cpu_convert_to_target32(block_size, endian);
sub_hdr_size = sizeof(struct KdumpSubHeader32) + s->note_size;
sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
@@ -915,7 +911,7 @@ static int create_header64(DumpState *s)
strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
dh->header_version = cpu_convert_to_target32(6, endian);
- block_size = s->page_size;
+ block_size = TARGET_PAGE_SIZE;
dh->block_size = cpu_convert_to_target32(block_size, endian);
sub_hdr_size = sizeof(struct KdumpSubHeader64) + s->note_size;
sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
@@ -1004,7 +1000,7 @@ out:
static int write_dump_header(DumpState *s)
{
- if (s->dump_info.d_machine == EM_386) {
+ if (s->dump_info.d_class == ELFCLASS32) {
return create_header32(s);
} else {
return create_header64(s);
@@ -1086,9 +1082,9 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
if (!block) {
block = QTAILQ_FIRST(&s->guest_phys_blocks.head);
*blockptr = block;
- assert(block->target_start % s->page_size == 0);
- assert(block->target_end % s->page_size == 0);
- *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
+ assert((block->target_start & ~TARGET_PAGE_MASK) == 0);
+ assert((block->target_end & ~TARGET_PAGE_MASK) == 0);
+ *pfnptr = paddr_to_pfn(block->target_start);
if (bufptr) {
*bufptr = block->host_addr;
}
@@ -1096,10 +1092,10 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
}
*pfnptr = *pfnptr + 1;
- addr = pfn_to_paddr(*pfnptr, s->page_shift);
+ addr = pfn_to_paddr(*pfnptr);
if ((addr >= block->target_start) &&
- (addr + s->page_size <= block->target_end)) {
+ (addr + TARGET_PAGE_SIZE <= block->target_end)) {
buf = block->host_addr + (addr - block->target_start);
} else {
/* the next page is in the next block */
@@ -1108,9 +1104,9 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
if (!block) {
return false;
}
- assert(block->target_start % s->page_size == 0);
- assert(block->target_end % s->page_size == 0);
- *pfnptr = paddr_to_pfn(block->target_start, s->page_shift);
+ assert((block->target_start & ~TARGET_PAGE_MASK) == 0);
+ assert((block->target_end & ~TARGET_PAGE_MASK) == 0);
+ *pfnptr = paddr_to_pfn(block->target_start);
buf = block->host_addr;
}
@@ -1224,42 +1220,24 @@ static void free_data_cache(DataCache *data_cache)
static size_t get_len_buf_out(size_t page_size, uint32_t flag_compress)
{
- size_t len_buf_out_zlib, len_buf_out_lzo, len_buf_out_snappy;
- size_t len_buf_out;
-
- /* init buf_out */
- len_buf_out_zlib = len_buf_out_lzo = len_buf_out_snappy = 0;
-
- /* buf size for zlib */
- len_buf_out_zlib = compressBound(page_size);
-
- /* buf size for lzo */
-#ifdef CONFIG_LZO
- if (flag_compress & DUMP_DH_COMPRESSED_LZO) {
- if (lzo_init() != LZO_E_OK) {
- /* return 0 to indicate lzo is unavailable */
- return 0;
- }
- }
-
- /*
- * LZO will expand incompressible data by a little amount. please check the
- * following URL to see the expansion calculation:
- * http://www.oberhumer.com/opensource/lzo/lzofaq.php
- */
- len_buf_out_lzo = page_size + page_size / 16 + 64 + 3;
-#endif
+ switch (flag_compress) {
+ case DUMP_DH_COMPRESSED_ZLIB:
+ return compressBound(page_size);
+
+ case DUMP_DH_COMPRESSED_LZO:
+ /*
+ * LZO will expand incompressible data by a little amount. Please check
+ * the following URL to see the expansion calculation:
+ * http://www.oberhumer.com/opensource/lzo/lzofaq.php
+ */
+ return page_size + page_size / 16 + 64 + 3;
#ifdef CONFIG_SNAPPY
- /* buf size for snappy */
- len_buf_out_snappy = snappy_max_compressed_length(page_size);
+ case DUMP_DH_COMPRESSED_SNAPPY:
+ return snappy_max_compressed_length(page_size);
#endif
-
- /* get the biggest that can store all kinds of compressed page */
- len_buf_out = MAX(len_buf_out_zlib,
- MAX(len_buf_out_lzo, len_buf_out_snappy));
-
- return len_buf_out;
+ }
+ return 0;
}
/*
@@ -1294,11 +1272,8 @@ static int write_dump_pages(DumpState *s)
prepare_data_cache(&page_data, s, offset_data);
/* prepare buffer to store compressed data */
- len_buf_out = get_len_buf_out(s->page_size, s->flag_compress);
- if (len_buf_out == 0) {
- dump_error(s, "dump: failed to get length of output buffer.\n");
- goto out;
- }
+ len_buf_out = get_len_buf_out(TARGET_PAGE_SIZE, s->flag_compress);
+ assert(len_buf_out != 0);
#ifdef CONFIG_LZO
wrkmem = g_malloc(LZO1X_1_MEM_COMPRESS);
@@ -1310,19 +1285,19 @@ static int write_dump_pages(DumpState *s)
* init zero page's page_desc and page_data, because every zero page
* uses the same page_data
*/
- pd_zero.size = cpu_convert_to_target32(s->page_size, endian);
+ pd_zero.size = cpu_convert_to_target32(TARGET_PAGE_SIZE, endian);
pd_zero.flags = cpu_convert_to_target32(0, endian);
pd_zero.offset = cpu_convert_to_target64(offset_data, endian);
pd_zero.page_flags = cpu_convert_to_target64(0, endian);
- buf = g_malloc0(s->page_size);
- ret = write_cache(&page_data, buf, s->page_size, false);
+ buf = g_malloc0(TARGET_PAGE_SIZE);
+ ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
g_free(buf);
if (ret < 0) {
dump_error(s, "dump: failed to write page data(zero page).\n");
goto out;
}
- offset_data += s->page_size;
+ offset_data += TARGET_PAGE_SIZE;
/*
* dump memory to vmcore page by page. zero page will all be resided in the
@@ -1330,7 +1305,7 @@ static int write_dump_pages(DumpState *s)
*/
while (get_next_page(&block_iter, &pfn_iter, &buf, s)) {
/* check zero page */
- if (is_zero_page(buf, s->page_size)) {
+ if (is_zero_page(buf, TARGET_PAGE_SIZE)) {
ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
false);
if (ret < 0) {
@@ -1351,8 +1326,9 @@ static int write_dump_pages(DumpState *s)
*/
size_out = len_buf_out;
if ((s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) &&
- (compress2(buf_out, (uLongf *)&size_out, buf, s->page_size,
- Z_BEST_SPEED) == Z_OK) && (size_out < s->page_size)) {
+ (compress2(buf_out, (uLongf *)&size_out, buf,
+ TARGET_PAGE_SIZE, Z_BEST_SPEED) == Z_OK) &&
+ (size_out < TARGET_PAGE_SIZE)) {
pd.flags = cpu_convert_to_target32(DUMP_DH_COMPRESSED_ZLIB,
endian);
pd.size = cpu_convert_to_target32(size_out, endian);
@@ -1364,9 +1340,9 @@ static int write_dump_pages(DumpState *s)
}
#ifdef CONFIG_LZO
} else if ((s->flag_compress & DUMP_DH_COMPRESSED_LZO) &&
- (lzo1x_1_compress(buf, s->page_size, buf_out,
+ (lzo1x_1_compress(buf, TARGET_PAGE_SIZE, buf_out,
(lzo_uint *)&size_out, wrkmem) == LZO_E_OK) &&
- (size_out < s->page_size)) {
+ (size_out < TARGET_PAGE_SIZE)) {
pd.flags = cpu_convert_to_target32(DUMP_DH_COMPRESSED_LZO,
endian);
pd.size = cpu_convert_to_target32(size_out, endian);
@@ -1379,9 +1355,9 @@ static int write_dump_pages(DumpState *s)
#endif
#ifdef CONFIG_SNAPPY
} else if ((s->flag_compress & DUMP_DH_COMPRESSED_SNAPPY) &&
- (snappy_compress((char *)buf, s->page_size,
+ (snappy_compress((char *)buf, TARGET_PAGE_SIZE,
(char *)buf_out, &size_out) == SNAPPY_OK) &&
- (size_out < s->page_size)) {
+ (size_out < TARGET_PAGE_SIZE)) {
pd.flags = cpu_convert_to_target32(
DUMP_DH_COMPRESSED_SNAPPY, endian);
pd.size = cpu_convert_to_target32(size_out, endian);
@@ -1395,13 +1371,13 @@ static int write_dump_pages(DumpState *s)
} else {
/*
* fall back to save in plaintext, size_out should be
- * assigned to s->page_size
+ * assigned TARGET_PAGE_SIZE
*/
pd.flags = cpu_convert_to_target32(0, endian);
- size_out = s->page_size;
+ size_out = TARGET_PAGE_SIZE;
pd.size = cpu_convert_to_target32(size_out, endian);
- ret = write_cache(&page_data, buf, s->page_size, false);
+ ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
if (ret < 0) {
dump_error(s, "dump: failed to write page data.\n");
goto out;
@@ -1536,7 +1512,7 @@ static void get_max_mapnr(DumpState *s)
GuestPhysBlock *last_block;
last_block = QTAILQ_LAST(&s->guest_phys_blocks.head, GuestPhysBlockHead);
- s->max_mapnr = paddr_to_pfn(last_block->target_end, s->page_shift);
+ s->max_mapnr = paddr_to_pfn(last_block->target_end);
}
static int dump_init(DumpState *s, int fd, bool has_format,
@@ -1613,14 +1589,12 @@ static int dump_init(DumpState *s, int fd, bool has_format,
}
s->nr_cpus = nr_cpus;
- s->page_size = TARGET_PAGE_SIZE;
- s->page_shift = ffs(s->page_size) - 1;
get_max_mapnr(s);
uint64_t tmp;
- tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), s->page_size);
- s->len_dump_bitmap = tmp * s->page_size;
+ tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), TARGET_PAGE_SIZE);
+ s->len_dump_bitmap = tmp * TARGET_PAGE_SIZE;
/* init for kdump-compressed format */
if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
@@ -1630,6 +1604,12 @@ static int dump_init(DumpState *s, int fd, bool has_format,
break;
case DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO:
+#ifdef CONFIG_LZO
+ if (lzo_init() != LZO_E_OK) {
+ error_setg(errp, "failed to initialize the LZO library");
+ goto cleanup;
+ }
+#endif
s->flag_compress = DUMP_DH_COMPRESSED_LZO;
break;
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 2e462c04aa..5f1a677b85 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -335,6 +335,7 @@ ETEXI
.params = "tag|id",
.help = "restore a VM snapshot from its tag or id",
.mhandler.cmd = do_loadvm,
+ .command_completion = loadvm_completion,
},
STEXI
@@ -350,6 +351,7 @@ ETEXI
.params = "tag|id",
.help = "delete a VM snapshot from its tag or id",
.mhandler.cmd = do_delvm,
+ .command_completion = delvm_completion,
},
STEXI
@@ -852,6 +854,7 @@ ETEXI
.params = "device data",
.help = "Write to a ring buffer character device",
.mhandler.cmd = hmp_ringbuf_write,
+ .command_completion = ringbuf_write_completion,
},
STEXI
@@ -868,6 +871,7 @@ ETEXI
.params = "device size",
.help = "Read from a ring buffer character device",
.mhandler.cmd = hmp_ringbuf_read,
+ .command_completion = ringbuf_write_completion,
},
STEXI
@@ -973,6 +977,7 @@ ETEXI
.params = "capability state",
.help = "Enable/Disable the usage of a capability for migration",
.mhandler.cmd = hmp_migrate_set_capability,
+ .command_completion = migrate_set_capability_completion,
},
STEXI
@@ -1206,9 +1211,10 @@ ETEXI
{
.name = "host_net_add",
.args_type = "device:s,opts:s?",
- .params = "tap|user|socket|vde|netmap|dump [options]",
+ .params = "tap|user|socket|vde|netmap|bridge|dump [options]",
.help = "add host VLAN client",
.mhandler.cmd = net_host_device_add,
+ .command_completion = host_net_add_completion,
},
STEXI
@@ -1223,6 +1229,7 @@ ETEXI
.params = "vlan_id name",
.help = "remove host VLAN client",
.mhandler.cmd = net_host_device_remove,
+ .command_completion = host_net_remove_completion,
},
STEXI
@@ -1357,6 +1364,7 @@ ETEXI
.params = "[reset|shutdown|poweroff|pause|debug|none]",
.help = "change watchdog action",
.mhandler.cmd = do_watchdog_action,
+ .command_completion = watchdog_action_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index aba59e95f0..2d9b0a2b0b 100644
--- a/hmp.h
+++ b/hmp.h
@@ -103,5 +103,16 @@ void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
+void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
+void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
+void watchdog_action_completion(ReadLineState *rs, int nb_args,
+ const char *str);
+void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
+ const char *str);
+void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void host_net_remove_completion(ReadLineState *rs, int nb_args,
+ const char *str);
+void delvm_completion(ReadLineState *rs, int nb_args, const char *str);
+void loadvm_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/include/net/net.h b/include/net/net.h
index 8166345a13..8b189da5ee 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -177,6 +177,7 @@ struct NICInfo {
extern int nb_nics;
extern NICInfo nd_table[MAX_NICS];
extern int default_net;
+extern const char *host_net_devices[];
/* from net.c */
extern const char *legacy_tftp_prefix;
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index b81a6ff185..7f5eeb38b0 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -286,9 +286,8 @@ void qemu_chr_add_handlers(CharDriverState *s,
void qemu_chr_be_generic_open(CharDriverState *s);
void qemu_chr_accept_input(CharDriverState *s);
int qemu_chr_add_client(CharDriverState *s, int fd);
-void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
-void qemu_chr_info(Monitor *mon, QObject **ret_data);
CharDriverState *qemu_chr_find(const char *name);
+bool chr_is_ringbuf(const CharDriverState *chr);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index efab7a32f3..12af557b55 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -22,10 +22,10 @@
#define ARCH_PFN_OFFSET (0)
-#define paddr_to_pfn(X, page_shift) \
- (((unsigned long long)(X) >> (page_shift)) - ARCH_PFN_OFFSET)
-#define pfn_to_paddr(X, page_shift) \
- (((unsigned long long)(X) + ARCH_PFN_OFFSET) << (page_shift))
+#define paddr_to_pfn(X) \
+ (((unsigned long long)(X) >> TARGET_PAGE_BITS) - ARCH_PFN_OFFSET)
+#define pfn_to_paddr(X) \
+ (((unsigned long long)(X) + ARCH_PFN_OFFSET) << TARGET_PAGE_BITS)
/*
* flag for compressed format
diff --git a/monitor.c b/monitor.c
index 0565816910..ee9390f659 100644
--- a/monitor.c
+++ b/monitor.c
@@ -70,6 +70,7 @@
#include "qmp-commands.h"
#include "hmp.h"
#include "qemu/thread.h"
+#include "block/qapi.h"
/* for pic/irq_info */
#if defined(TARGET_SPARC)
@@ -4412,6 +4413,45 @@ void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_ChardevInfoList(start);
}
+static void ringbuf_completion(ReadLineState *rs, const char *str)
+{
+ size_t len;
+ ChardevInfoList *list, *start;
+
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+
+ start = list = qmp_query_chardev(NULL);
+ while (list) {
+ ChardevInfo *chr_info = list->value;
+
+ if (!strncmp(chr_info->label, str, len)) {
+ CharDriverState *chr = qemu_chr_find(chr_info->label);
+ if (chr && chr_is_ringbuf(chr)) {
+ readline_add_completion(rs, chr_info->label);
+ }
+ }
+ list = list->next;
+ }
+ qapi_free_ChardevInfoList(start);
+}
+
+void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ if (nb_args != 2) {
+ return;
+ }
+ ringbuf_completion(rs, str);
+}
+
+void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ if (nb_args != 2) {
+ return;
+ }
+ ringbuf_completion(rs, str);
+}
+
void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
size_t len;
@@ -4520,6 +4560,142 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
}
}
+void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ if (nb_args != 2) {
+ return;
+ }
+ readline_set_completion_index(rs, strlen(str));
+ add_completion_option(rs, str, "reset");
+ add_completion_option(rs, str, "shutdown");
+ add_completion_option(rs, str, "poweroff");
+ add_completion_option(rs, str, "pause");
+ add_completion_option(rs, str, "debug");
+ add_completion_option(rs, str, "none");
+}
+
+void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
+ const char *str)
+{
+ size_t len;
+
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ if (nb_args == 2) {
+ int i;
+ for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+ const char *name = MigrationCapability_lookup[i];
+ if (!strncmp(str, name, len)) {
+ readline_add_completion(rs, name);
+ }
+ }
+ } else if (nb_args == 3) {
+ add_completion_option(rs, str, "on");
+ add_completion_option(rs, str, "off");
+ }
+}
+
+void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ int i;
+ size_t len;
+ if (nb_args != 2) {
+ return;
+ }
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ for (i = 0; host_net_devices[i]; i++) {
+ if (!strncmp(host_net_devices[i], str, len)) {
+ readline_add_completion(rs, host_net_devices[i]);
+ }
+ }
+}
+
+void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ NetClientState *ncs[255];
+ int count, i, len;
+
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ if (nb_args == 2) {
+ count = qemu_find_net_clients_except(NULL, ncs,
+ NET_CLIENT_OPTIONS_KIND_NONE, 255);
+ for (i = 0; i < count; i++) {
+ int id;
+ char name[16];
+
+ if (net_hub_id_for_client(ncs[i], &id)) {
+ continue;
+ }
+ snprintf(name, sizeof(name), "%d", id);
+ if (!strncmp(str, name, len)) {
+ readline_add_completion(rs, name);
+ }
+ }
+ return;
+ } else if (nb_args == 3) {
+ count = qemu_find_net_clients_except(NULL, ncs,
+ NET_CLIENT_OPTIONS_KIND_NIC, 255);
+ for (i = 0; i < count; i++) {
+ const char *name;
+
+ name = ncs[i]->name;
+ if (!strncmp(str, name, len)) {
+ readline_add_completion(rs, name);
+ }
+ }
+ return;
+ }
+}
+
+static void vm_completion(ReadLineState *rs, const char *str)
+{
+ size_t len;
+ BlockDriverState *bs = NULL;
+
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ while ((bs = bdrv_next(bs))) {
+ SnapshotInfoList *snapshots, *snapshot;
+
+ if (!bdrv_can_snapshot(bs)) {
+ continue;
+ }
+ if (bdrv_query_snapshot_info_list(bs, &snapshots, NULL)) {
+ continue;
+ }
+ snapshot = snapshots;
+ while (snapshot) {
+ char *completion = snapshot->value->name;
+ if (!strncmp(str, completion, len)) {
+ readline_add_completion(rs, completion);
+ }
+ completion = snapshot->value->id;
+ if (!strncmp(str, completion, len)) {
+ readline_add_completion(rs, completion);
+ }
+ snapshot = snapshot->next;
+ }
+ qapi_free_SnapshotInfoList(snapshots);
+ }
+
+}
+
+void delvm_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ if (nb_args == 2) {
+ vm_completion(rs, str);
+ }
+}
+
+void loadvm_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ if (nb_args == 2) {
+ vm_completion(rs, str);
+ }
+}
+
static void monitor_find_completion_by_table(Monitor *mon,
const mon_cmd_t *cmd_table,
char **args,
diff --git a/net/net.c b/net/net.c
index 0ff2e40f35..6344160403 100644
--- a/net/net.c
+++ b/net/net.c
@@ -49,6 +49,22 @@
static QTAILQ_HEAD(, NetClientState) net_clients;
+const char *host_net_devices[] = {
+ "tap",
+ "socket",
+ "dump",
+#ifdef CONFIG_NET_BRIDGE
+ "bridge",
+#endif
+#ifdef CONFIG_SLIRP
+ "user",
+#endif
+#ifdef CONFIG_VDE
+ "vde",
+#endif
+ NULL,
+};
+
int default_net = 1;
/***********************************************************/
@@ -897,21 +913,11 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
static int net_host_check_device(const char *device)
{
int i;
- const char *valid_param_list[] = { "tap", "socket", "dump"
-#ifdef CONFIG_NET_BRIDGE
- , "bridge"
-#endif
-#ifdef CONFIG_SLIRP
- ,"user"
-#endif
-#ifdef CONFIG_VDE
- ,"vde"
-#endif
- };
- for (i = 0; i < ARRAY_SIZE(valid_param_list); i++) {
- if (!strncmp(valid_param_list[i], device,
- strlen(valid_param_list[i])))
+ for (i = 0; host_net_devices[i]; i++) {
+ if (!strncmp(host_net_devices[i], device,
+ strlen(host_net_devices[i]))) {
return 1;
+ }
}
return 0;
diff --git a/qemu-char.c b/qemu-char.c
index 17b476edf0..4c04bbc24e 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2849,7 +2849,7 @@ fail:
return NULL;
}
-static bool chr_is_ringbuf(const CharDriverState *chr)
+bool chr_is_ringbuf(const CharDriverState *chr)
{
return chr->chr_write == ringbuf_chr_write;
}
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index e46c26448e..4288267bd3 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -423,7 +423,6 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
if (!token_is_operator(token, '{')) {
goto out;
}
- token = NULL;
dict = qdict_new();
@@ -449,7 +448,6 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
parse_error(ctxt, token, "expected separator in dict");
goto out;
}
- token = NULL;
if (parse_pair(ctxt, dict, ap) == -1) {
goto out;
@@ -461,10 +459,8 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
goto out;
}
}
- token = NULL;
} else {
- token = parser_context_pop_token(ctxt);
- token = NULL;
+ (void)parser_context_pop_token(ctxt);
}
return QOBJECT(dict);
@@ -487,10 +483,8 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
}
if (!token_is_operator(token, '[')) {
- token = NULL;
goto out;
}
- token = NULL;
list = qlist_new();
@@ -523,8 +517,6 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
goto out;
}
- token = NULL;
-
obj = parse_value(ctxt, ap);
if (obj == NULL) {
parse_error(ctxt, token, "expecting value");
@@ -539,11 +531,8 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
goto out;
}
}
-
- token = NULL;
} else {
- token = parser_context_pop_token(ctxt);
- token = NULL;
+ (void)parser_context_pop_token(ctxt);
}
return QOBJECT(list);
diff --git a/util/readline.c b/util/readline.c
index 8baec55509..cc1302ac0a 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -263,6 +263,12 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
void readline_add_completion(ReadLineState *rs, const char *str)
{
if (rs->nb_completions < READLINE_MAX_COMPLETIONS) {
+ int i;
+ for (i = 0; i < rs->nb_completions; i++) {
+ if (!strcmp(rs->completions[i], str)) {
+ return;
+ }
+ }
rs->completions[rs->nb_completions++] = g_strdup(str);
}
}
@@ -345,6 +351,12 @@ static void readline_completion(ReadLineState *rs)
}
}
+static void readline_clear_screen(ReadLineState *rs)
+{
+ rs->printf_func(rs->opaque, "\033[2J\033[1;1H");
+ readline_show_prompt(rs);
+}
+
/* return true if command handled */
void readline_handle_byte(ReadLineState *rs, int ch)
{
@@ -363,6 +375,9 @@ void readline_handle_byte(ReadLineState *rs, int ch)
case 9:
readline_completion(rs);
break;
+ case 12:
+ readline_clear_screen(rs);
+ break;
case 10:
case 13:
rs->cmd_buf[rs->cmd_buf_size] = '\0';