qemu-img: pass current cmd info into command handlers

This info will be used to generate --help output.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250531171609.197078-5-mjt@tls.msk.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Michael Tokarev 2025-05-31 20:15:46 +03:00 committed by Kevin Wolf
parent fef5f1d4aa
commit 80415af893

View file

@ -60,7 +60,7 @@
typedef struct img_cmd_t {
const char *name;
int (*handler)(int argc, char **argv);
int (*handler)(const struct img_cmd_t *ccmd, int argc, char **argv);
} img_cmd_t;
enum {
@ -514,7 +514,7 @@ static int64_t cvtnum(const char *name, const char *value)
return cvtnum_full(name, value, 0, INT64_MAX);
}
static int img_create(int argc, char **argv)
static int img_create(const img_cmd_t *ccmd, int argc, char **argv)
{
int c;
int64_t img_size = -1;
@ -719,7 +719,7 @@ static int collect_image_check(BlockDriverState *bs,
* 3 - Check completed, image has leaked clusters, but is good otherwise
* 63 - Checks are not supported by the image format
*/
static int img_check(int argc, char **argv)
static int img_check(const img_cmd_t *ccmd, int argc, char **argv)
{
int c, ret;
OutputFormat output_format = OFORMAT_HUMAN;
@ -951,7 +951,7 @@ static void run_block_job(BlockJob *job, Error **errp)
}
}
static int img_commit(int argc, char **argv)
static int img_commit(const img_cmd_t *ccmd, int argc, char **argv)
{
int c, ret, flags;
const char *filename, *fmt, *cache, *base;
@ -1358,7 +1358,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset,
* 1 - Images differ
* >1 - Error occurred
*/
static int img_compare(int argc, char **argv)
static int img_compare(const img_cmd_t *ccmd, int argc, char **argv)
{
const char *fmt1 = NULL, *fmt2 = NULL, *cache, *filename1, *filename2;
BlockBackend *blk1, *blk2;
@ -2234,7 +2234,7 @@ static void set_rate_limit(BlockBackend *blk, int64_t rate_limit)
blk_set_io_limits(blk, &cfg);
}
static int img_convert(int argc, char **argv)
static int img_convert(const img_cmd_t *ccmd, int argc, char **argv)
{
int c, bs_i, flags, src_flags = BDRV_O_NO_SHARE;
const char *fmt = NULL, *out_fmt = NULL, *cache = "unsafe",
@ -3002,7 +3002,7 @@ err:
return NULL;
}
static int img_info(int argc, char **argv)
static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
{
int c;
OutputFormat output_format = OFORMAT_HUMAN;
@ -3227,7 +3227,7 @@ static inline bool entry_mergeable(const MapEntry *curr, const MapEntry *next)
return true;
}
static int img_map(int argc, char **argv)
static int img_map(const img_cmd_t *ccmd, int argc, char **argv)
{
int c;
OutputFormat output_format = OFORMAT_HUMAN;
@ -3376,7 +3376,7 @@ out:
#define SNAPSHOT_APPLY 3
#define SNAPSHOT_DELETE 4
static int img_snapshot(int argc, char **argv)
static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv)
{
BlockBackend *blk;
BlockDriverState *bs;
@ -3536,7 +3536,7 @@ static int img_snapshot(int argc, char **argv)
return 0;
}
static int img_rebase(int argc, char **argv)
static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv)
{
BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL;
uint8_t *buf_old = NULL;
@ -4030,7 +4030,7 @@ out:
return 0;
}
static int img_resize(int argc, char **argv)
static int img_resize(const img_cmd_t *ccmd, int argc, char **argv)
{
Error *err = NULL;
int c, ret, relative;
@ -4243,7 +4243,7 @@ static int print_amend_option_help(const char *format)
return 0;
}
static int img_amend(int argc, char **argv)
static int img_amend(const img_cmd_t *ccmd, int argc, char **argv)
{
Error *err = NULL;
int c, ret = 0;
@ -4511,7 +4511,7 @@ static void bench_cb(void *opaque, int ret)
}
}
static int img_bench(int argc, char **argv)
static int img_bench(const img_cmd_t *ccmd, int argc, char **argv)
{
int c, ret = 0;
const char *fmt = NULL, *filename;
@ -4781,7 +4781,7 @@ typedef struct ImgBitmapAction {
QSIMPLEQ_ENTRY(ImgBitmapAction) next;
} ImgBitmapAction;
static int img_bitmap(int argc, char **argv)
static int img_bitmap(const img_cmd_t *ccmd, int argc, char **argv)
{
Error *err = NULL;
int c, ret = 1;
@ -5081,7 +5081,7 @@ static int img_dd_skip(const char *arg,
return 0;
}
static int img_dd(int argc, char **argv)
static int img_dd(const img_cmd_t *ccmd, int argc, char **argv)
{
int ret = 0;
char *arg = NULL;
@ -5349,7 +5349,7 @@ static void dump_json_block_measure_info(BlockMeasureInfo *info)
g_string_free(str, true);
}
static int img_measure(int argc, char **argv)
static int img_measure(const img_cmd_t *ccmd, int argc, char **argv)
{
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
@ -5616,7 +5616,7 @@ int main(int argc, char **argv)
argc -= optind;
qemu_reset_optind();
argv[0] = argv0;
return cmd->handler(argc, argv);
return cmd->handler(cmd, argc, argv);
}
}