* [Qemu-devel] [PATCH 3/4][RFC] Add qemu-img option to store command line options into qcow2 images
[not found] <59abf66e0708081123u64c67205n7723a6f01e0b29a9@mail.gmail.com>
@ 2007-08-08 19:52 ` Jorge Lucángeli Obes
0 siblings, 0 replies; only message in thread
From: Jorge Lucángeli Obes @ 2007-08-08 19:52 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 3274 bytes --]
This patch adds a new qemu-img option to store
command line arguments in qcow2 snapshots.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Jorge Lucángeli Obes <t4m5yn@gmail.com>
---
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);
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: qemu-img.patch --]
[-- Type: text/x-patch; name=qemu-img.patch; charset=ANSI_X3.4-1968, Size: 3175 bytes --]
This patch adds a new qemu-img option to store
command line arguments in qcow2 snapshots.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Jorge Lucángeli Obes <t4m5yn@gmail.com>
---
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);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-08-08 19:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <59abf66e0708081123u64c67205n7723a6f01e0b29a9@mail.gmail.com>
2007-08-08 19:52 ` [Qemu-devel] [PATCH 3/4][RFC] Add qemu-img option to store command line options into qcow2 images Jorge Lucángeli Obes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).