QemuOpts: Convert qemu_opt_set_number() to Error, fix its use
Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
		
							parent
							
								
									cccb7967bd
								
							
						
					
					
						commit
						39101f2511
					
				
							
								
								
									
										6
									
								
								block.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								block.c
									
									
									
									
									
								
							@ -1364,7 +1364,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    opts = qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0,
 | 
					    opts = qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0,
 | 
				
			||||||
                            &error_abort);
 | 
					                            &error_abort);
 | 
				
			||||||
    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
 | 
					    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size, &error_abort);
 | 
				
			||||||
    ret = bdrv_create(&bdrv_qcow2, tmp_filename, opts, &local_err);
 | 
					    ret = bdrv_create(&bdrv_qcow2, tmp_filename, opts, &local_err);
 | 
				
			||||||
    qemu_opts_del(opts);
 | 
					    qemu_opts_del(opts);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
@ -5649,7 +5649,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* Create parameter list with default values */
 | 
					    /* Create parameter list with default values */
 | 
				
			||||||
    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
 | 
					    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
 | 
				
			||||||
    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
 | 
					    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Parse -o options */
 | 
					    /* Parse -o options */
 | 
				
			||||||
    if (options) {
 | 
					    if (options) {
 | 
				
			||||||
@ -5731,7 +5731,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
 | 
				
			|||||||
                goto out;
 | 
					                goto out;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
 | 
					            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abort);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            bdrv_unref(bs);
 | 
					            bdrv_unref(bs);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -215,7 +215,8 @@ static void nbd_config(BDRVNBDState *s, QDict *options, char **export,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!qemu_opt_get(s->socket_opts, "port")) {
 | 
					    if (!qemu_opt_get(s->socket_opts, "port")) {
 | 
				
			||||||
        qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT);
 | 
					        qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT,
 | 
				
			||||||
 | 
					                            &error_abort);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *export = g_strdup(qdict_get_try_str(options, "export"));
 | 
					    *export = g_strdup(qdict_get_try_str(options, "export"));
 | 
				
			||||||
 | 
				
			|||||||
@ -1858,7 +1858,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 | 
				
			|||||||
        meta_size += nreftablee * sizeof(uint64_t);
 | 
					        meta_size += nreftablee * sizeof(uint64_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
 | 
					        qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
 | 
				
			||||||
                            aligned_total_size + meta_size);
 | 
					                            aligned_total_size + meta_size, &error_abort);
 | 
				
			||||||
        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc]);
 | 
					        qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2924,7 +2924,8 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
 | 
					    opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
 | 
				
			||||||
    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
 | 
					    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512,
 | 
				
			||||||
 | 
					                        &error_abort);
 | 
				
			||||||
    qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
 | 
					    qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
 | 
					    ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
 | 
				
			||||||
 | 
				
			|||||||
@ -99,7 +99,8 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
 | 
				
			|||||||
                      Error **errp);
 | 
					                      Error **errp);
 | 
				
			||||||
void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
 | 
					void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
 | 
				
			||||||
                       Error **errp);
 | 
					                       Error **errp);
 | 
				
			||||||
int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val);
 | 
					void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
 | 
				
			||||||
 | 
					                         Error **errp);
 | 
				
			||||||
typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
 | 
					typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
 | 
				
			||||||
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 | 
					int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 | 
				
			||||||
                     int abort_on_failure);
 | 
					                     int abort_on_failure);
 | 
				
			||||||
 | 
				
			|||||||
@ -1550,7 +1550,8 @@ static int img_convert(int argc, char **argv)
 | 
				
			|||||||
            goto out;
 | 
					            goto out;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
 | 
					        qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512,
 | 
				
			||||||
 | 
					                            &error_abort);
 | 
				
			||||||
        ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
 | 
					        ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
 | 
				
			||||||
        if (ret < 0) {
 | 
					        if (ret < 0) {
 | 
				
			||||||
            goto out;
 | 
					            goto out;
 | 
				
			||||||
 | 
				
			|||||||
@ -215,10 +215,10 @@ static void test_qemu_opt_get_bool(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void test_qemu_opt_get_number(void)
 | 
					static void test_qemu_opt_get_number(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    Error *err = NULL;
 | 
				
			||||||
    QemuOptsList *list;
 | 
					    QemuOptsList *list;
 | 
				
			||||||
    QemuOpts *opts;
 | 
					    QemuOpts *opts;
 | 
				
			||||||
    uint64_t opt;
 | 
					    uint64_t opt;
 | 
				
			||||||
    int ret;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    list = qemu_find_opts("opts_list_01");
 | 
					    list = qemu_find_opts("opts_list_01");
 | 
				
			||||||
    g_assert(list != NULL);
 | 
					    g_assert(list != NULL);
 | 
				
			||||||
@ -238,16 +238,16 @@ static void test_qemu_opt_get_number(void)
 | 
				
			|||||||
    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
					    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
				
			||||||
    g_assert(opt == 5);
 | 
					    g_assert(opt == 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = qemu_opt_set_number(opts, "number1", 10);
 | 
					    qemu_opt_set_number(opts, "number1", 10, &err);
 | 
				
			||||||
    g_assert(ret == 0);
 | 
					    g_assert(!err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* now we have set number1, should know about it */
 | 
					    /* now we have set number1, should know about it */
 | 
				
			||||||
    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
					    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
				
			||||||
    g_assert(opt == 10);
 | 
					    g_assert(opt == 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* having reset it, the returned should be the reset one not defval */
 | 
					    /* having reset it, the returned should be the reset one not defval */
 | 
				
			||||||
    ret = qemu_opt_set_number(opts, "number1", 15);
 | 
					    qemu_opt_set_number(opts, "number1", 15, &err);
 | 
				
			||||||
    g_assert(ret == 0);
 | 
					    g_assert(!err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
					    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
				
			||||||
    g_assert(opt == 15);
 | 
					    g_assert(opt == 15);
 | 
				
			||||||
@ -349,10 +349,10 @@ static void test_qemu_opt_unset(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void test_qemu_opts_reset(void)
 | 
					static void test_qemu_opts_reset(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    Error *err = NULL;
 | 
				
			||||||
    QemuOptsList *list;
 | 
					    QemuOptsList *list;
 | 
				
			||||||
    QemuOpts *opts;
 | 
					    QemuOpts *opts;
 | 
				
			||||||
    uint64_t opt;
 | 
					    uint64_t opt;
 | 
				
			||||||
    int ret;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    list = qemu_find_opts("opts_list_01");
 | 
					    list = qemu_find_opts("opts_list_01");
 | 
				
			||||||
    g_assert(list != NULL);
 | 
					    g_assert(list != NULL);
 | 
				
			||||||
@ -372,8 +372,8 @@ static void test_qemu_opts_reset(void)
 | 
				
			|||||||
    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
					    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
				
			||||||
    g_assert(opt == 5);
 | 
					    g_assert(opt == 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = qemu_opt_set_number(opts, "number1", 10);
 | 
					    qemu_opt_set_number(opts, "number1", 10, &err);
 | 
				
			||||||
    g_assert(ret == 0);
 | 
					    g_assert(!err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* now we have set number1, should know about it */
 | 
					    /* now we have set number1, should know about it */
 | 
				
			||||||
    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
					    opt = qemu_opt_get_number(opts, "number1", 5);
 | 
				
			||||||
 | 
				
			|||||||
@ -589,7 +589,8 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
 | 
				
			|||||||
    QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 | 
					    QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 | 
					void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
 | 
				
			||||||
 | 
					                         Error **errp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QemuOpt *opt;
 | 
					    QemuOpt *opt;
 | 
				
			||||||
    const QemuOptDesc *desc = opts->list->desc;
 | 
					    const QemuOptDesc *desc = opts->list->desc;
 | 
				
			||||||
@ -597,9 +598,9 @@ int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 | 
				
			|||||||
    opt = g_malloc0(sizeof(*opt));
 | 
					    opt = g_malloc0(sizeof(*opt));
 | 
				
			||||||
    opt->desc = find_desc_by_name(desc, name);
 | 
					    opt->desc = find_desc_by_name(desc, name);
 | 
				
			||||||
    if (!opt->desc && !opts_accepts_any(opts)) {
 | 
					    if (!opt->desc && !opts_accepts_any(opts)) {
 | 
				
			||||||
        qerror_report(QERR_INVALID_PARAMETER, name);
 | 
					        error_set(errp, QERR_INVALID_PARAMETER, name);
 | 
				
			||||||
        g_free(opt);
 | 
					        g_free(opt);
 | 
				
			||||||
        return -1;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    opt->name = g_strdup(name);
 | 
					    opt->name = g_strdup(name);
 | 
				
			||||||
@ -607,8 +608,6 @@ int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 | 
				
			|||||||
    opt->value.uint = val;
 | 
					    opt->value.uint = val;
 | 
				
			||||||
    opt->str = g_strdup_printf("%" PRId64, val);
 | 
					    opt->str = g_strdup_printf("%" PRId64, val);
 | 
				
			||||||
    QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 | 
					    QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 | 
					int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								vl.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								vl.c
									
									
									
									
									
								
							@ -2684,7 +2684,7 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* store value for the future use */
 | 
					    /* store value for the future use */
 | 
				
			||||||
    qemu_opt_set_number(opts, "size", ram_size);
 | 
					    qemu_opt_set_number(opts, "size", ram_size, &error_abort);
 | 
				
			||||||
    *maxram_size = ram_size;
 | 
					    *maxram_size = ram_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    maxmem_str = qemu_opt_get(opts, "maxmem");
 | 
					    maxmem_str = qemu_opt_get(opts, "maxmem");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user