This patch adds a new qemu-img option to store command line arguments in qcow2 snapshots. Signed-off-by: Laurent Vivier Signed-off-by: Jorge Lucángeli Obes --- diff --git a/qemu/qemu-img.c b/qemu/qemu-img.c index a259546..afa1fcc 100644 --- a/qemu/qemu-img.c +++ b/qemu/qemu-img.c @@ -98,6 +98,7 @@ void help(void) "QEMU disk image utility\n" "\n" "Command syntax:\n" + " cmdline filename \"command_line\" (qcow2 format only)\n" " create [-e] [-b base_image] [-f fmt] filename [size]\n" " commit [-f fmt] filename\n" " convert [-c] [-e] [-f fmt] filename [-O output_fmt] output_filename\n" @@ -105,6 +106,8 @@ void help(void) "\n" "Command parameters:\n" " 'filename' is a disk image filename\n" + " 'command_line' is a list of command line options to be stored in the image,\n" + " an empty string clears the stored command line options\n" " 'base_image' is the read-only disk image which is used as base for a copy on\n" " write image; the copy on write image only stores the modified data\n" " 'fmt' is the disk image format. It is guessed automatically in most cases\n" @@ -317,6 +320,33 @@ static int img_create(int argc, char **argv) return 0; } +static int img_cmdline(int argc, char **argv) +{ + char *filename; + char *annotation; + + BlockDriverState *bs; + + char *aname = "commandline_args"; + + if (argc != 4) + help(); + + filename = argv[2]; + annotation = argv[3]; + + bs = bdrv_new_open(filename, "qcow2"); + if (!bs) + error("Could not open qcow2 image '%s'", filename); + + if (bdrv_set_annot(bs, aname, (const char *)annotation) < 0) { + error("Could not store command line options into '%s'", filename); + } + + bdrv_delete(bs); + return 0; +} + static int img_commit(int argc, char **argv) { int c, ret; @@ -577,11 +607,19 @@ static void dump_snapshots(BlockDriverState *bs) nb_sns = bdrv_snapshot_list(bs, &sn_tab); if (nb_sns <= 0) return; - printf("Snapshot list:\n"); + + printf("\nAnnotations:\n"); + for (i = 0; i < nb_sns; i++) { + sn = &sn_tab[i]; + if (bdrv_snapshot_annotated(sn)) + printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn)); + } + printf("\nSnapshot list:\n"); printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL)); for(i = 0; i < nb_sns; i++) { sn = &sn_tab[i]; - printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn)); + if (!bdrv_snapshot_annotated(sn)) + printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn)); } qemu_free(sn_tab); } @@ -673,7 +711,9 @@ int main(int argc, char **argv) help(); cmd = argv[1]; optind++; - if (!strcmp(cmd, "create")) { + if (!strcmp(cmd, "cmdline")) { + img_cmdline(argc, argv); + } else if (!strcmp(cmd, "create")) { img_create(argc, argv); } else if (!strcmp(cmd, "commit")) { img_commit(argc, argv);