* [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images
@ 2007-08-08 18:24 Jorge Lucángeli Obes
[not found] ` <59abf66e0708081252of2948d7we85c9084bad245d4@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Jorge Lucángeli Obes @ 2007-08-08 18:24 UTC (permalink / raw)
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
[-- Attachment #1: Type: text/plain, Size: 3220 bytes --]
This patch makes QEMU check for command line options stored in qcow2 images.
Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
Signed-off-by: Jorge Lucángeli Obes <t4m5yn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
diff --git a/qemu/vl.c b/qemu/vl.c
index 4ad39f1..1d28794 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -184,6 +184,11 @@ int time_drift_fix = 0;
const char *cpu_vendor_string;
/***********************************************************/
+/* Image annotation support */
+
+char *img_get_annot(char *filename);
+
+/***********************************************************/
/* x86 ISA bus support */
target_phys_addr_t isa_mem_base = 0;
@@ -6917,6 +6922,13 @@ int main(int argc, char **argv)
char usb_devices[MAX_USB_CMDLINE][128];
int usb_devices_index;
int fds[2];
+ char *tmpannot;
+ char annot[1024];
+ int done = 0;
+ unsigned int nbtoks = 0;
+ char *tok;
+ BlockDriver *drv;
+ BlockDriverState *bs;
saved_argc = argc;
saved_argv = argv;
@@ -7000,6 +7012,58 @@ int main(int argc, char **argv)
nb_nics = 0;
/* default mac address of the first network interface */
+ bdrv_init();
+
+ drv = bdrv_find_format("qcow2");
+
+ if (argc > 1 && argv[1][0] != '-') {
+ bs = bdrv_new("");
+ if (!bs) {
+ fprintf(stderr, "Not enough memory");
+ exit(1);
+ }
+ if (bdrv_open2(bs, argv[1], 0, drv) < 0) {
+ fprintf(stderr, "Could not open '%s'", argv[1]);
+ bdrv_delete(bs);
+ exit(1);
+ }
+
+ tmpannot = bdrv_get_annot(bs, "commandline_args");
+ if (tmpannot) {
+ pstrcpy(annot, 1024, tmpannot);
+
+ do {
+ tok = strtok(nbtoks == 0? tmpannot : NULL, " ");
+
+ if (tok != NULL)
+ nbtoks++;
+ else
+ done = 1;
+ } while (!done);
+
+ free(tmpannot);
+
+ if (nbtoks > 0) {
+ char **argvprime = malloc((nbtoks + argc) * sizeof(char*));
+
+ for (i = 0; i < argc; i++)
+ argvprime[i] = argv[i];
+
+ for (i = 0; i < nbtoks; i++)
+ argvprime[i + argc] = strtok(i == 0? annot : NULL, " ");
+
+ argv = argvprime;
+ argc = argc + nbtoks;
+
+ for (i = 0; i < nbtoks + 2; i++)
+ printf("argv[%d] = %s\n", i, argv[i]);
+
+ }
+ }
+
+ bdrv_delete(bs);
+ }
+
optind = 1;
for(;;) {
if (optind >= argc)
@@ -7558,7 +7622,6 @@ int main(int argc, char **argv)
#endif
/* we always create the cdrom drive, even if no disk is there */
- bdrv_init();
if (cdrom_index >= 0) {
bs_table[cdrom_index] = bdrv_new("cdrom");
bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
@@ -7764,5 +7827,8 @@ int main(int argc, char **argv)
main_loop();
quit_timers();
+
+ /* was reassigned above so it needs free()ing */
+ free(argv);
return 0;
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: qemu.patch --]
[-- Type: text/x-patch; name=qemu.patch; charset=ANSI_X3.4-1968, Size: 3096 bytes --]
This patch makes QEMU check for command line options stored in qcow2 images.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Jorge Lucángeli Obes <t4m5yn@gmail.com>
---
diff --git a/qemu/vl.c b/qemu/vl.c
index 4ad39f1..1d28794 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -184,6 +184,11 @@ int time_drift_fix = 0;
const char *cpu_vendor_string;
/***********************************************************/
+/* Image annotation support */
+
+char *img_get_annot(char *filename);
+
+/***********************************************************/
/* x86 ISA bus support */
target_phys_addr_t isa_mem_base = 0;
@@ -6917,6 +6922,13 @@ int main(int argc, char **argv)
char usb_devices[MAX_USB_CMDLINE][128];
int usb_devices_index;
int fds[2];
+ char *tmpannot;
+ char annot[1024];
+ int done = 0;
+ unsigned int nbtoks = 0;
+ char *tok;
+ BlockDriver *drv;
+ BlockDriverState *bs;
saved_argc = argc;
saved_argv = argv;
@@ -7000,6 +7012,58 @@ int main(int argc, char **argv)
nb_nics = 0;
/* default mac address of the first network interface */
+ bdrv_init();
+
+ drv = bdrv_find_format("qcow2");
+
+ if (argc > 1 && argv[1][0] != '-') {
+ bs = bdrv_new("");
+ if (!bs) {
+ fprintf(stderr, "Not enough memory");
+ exit(1);
+ }
+ if (bdrv_open2(bs, argv[1], 0, drv) < 0) {
+ fprintf(stderr, "Could not open '%s'", argv[1]);
+ bdrv_delete(bs);
+ exit(1);
+ }
+
+ tmpannot = bdrv_get_annot(bs, "commandline_args");
+ if (tmpannot) {
+ pstrcpy(annot, 1024, tmpannot);
+
+ do {
+ tok = strtok(nbtoks == 0? tmpannot : NULL, " ");
+
+ if (tok != NULL)
+ nbtoks++;
+ else
+ done = 1;
+ } while (!done);
+
+ free(tmpannot);
+
+ if (nbtoks > 0) {
+ char **argvprime = malloc((nbtoks + argc) * sizeof(char*));
+
+ for (i = 0; i < argc; i++)
+ argvprime[i] = argv[i];
+
+ for (i = 0; i < nbtoks; i++)
+ argvprime[i + argc] = strtok(i == 0? annot : NULL, " ");
+
+ argv = argvprime;
+ argc = argc + nbtoks;
+
+ for (i = 0; i < nbtoks + 2; i++)
+ printf("argv[%d] = %s\n", i, argv[i]);
+
+ }
+ }
+
+ bdrv_delete(bs);
+ }
+
optind = 1;
for(;;) {
if (optind >= argc)
@@ -7558,7 +7622,6 @@ int main(int argc, char **argv)
#endif
/* we always create the cdrom drive, even if no disk is there */
- bdrv_init();
if (cdrom_index >= 0) {
bs_table[cdrom_index] = bdrv_new("cdrom");
bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
@@ -7764,5 +7827,8 @@ int main(int argc, char **argv)
main_loop();
quit_timers();
+
+ /* was reassigned above so it needs free()ing */
+ free(argv);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images
[not found] ` <1186874268.11306.1.camel@squirrel>
@ 2007-08-13 5:34 ` Jorge Lucángeli Obes
[not found] ` <59abf66e0708122234u6fe7a27bwa08f92252951879a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Jorge Lucángeli Obes @ 2007-08-13 5:34 UTC (permalink / raw)
To: qemu-devel-qX2TKyscuCcdnm+yROfE0A,
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
On 8/11/07, Anthony Liguori <anthony-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org> wrote:
> On Sat, 2007-08-11 at 22:28 +0100, Philip Boulain wrote:
> > This works, so long as qemu disregards "-read-args-from-image" unless it's
> > being called as an interpreter. Otherwise, you've put the lock and the key in
> > the same place. :)
>
> Yes. This is exactly what I think the behavior ought to be.
Ack.
> > (Side thought: presumably, we're assuming that the in-file and on-command-line
> > arguments are unioned, ideally with the latter taking precidence if mutually
> > exclusive.)
>
> Yup, I was thinking the same thing too. Once the KVM wiki comes back
> online I'll write something up on a wiki page.
Great, that was also my idea. Anyone interested in taking a stab at
this one? I will try and start getting it done this week.
Cheers,
Jorge
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images
[not found] ` <59abf66e0708122234u6fe7a27bwa08f92252951879a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-08-13 15:15 ` Anthony Liguori
0 siblings, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2007-08-13 15:15 UTC (permalink / raw)
To: Jorge Lucángeli Obes
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
qemu-devel-qX2TKyscuCcdnm+yROfE0A
On Mon, 2007-08-13 at 02:34 -0300, Jorge Lucángeli Obes wrote:
> On 8/11/07, Anthony Liguori <anthony@codemonkey.ws> wrote:
> > On Sat, 2007-08-11 at 22:28 +0100, Philip Boulain wrote:
> > > This works, so long as qemu disregards "-read-args-from-image" unless it's
> > > being called as an interpreter. Otherwise, you've put the lock and the key in
> > > the same place. :)
> >
> > Yes. This is exactly what I think the behavior ought to be.
>
> Ack.
>
> > > (Side thought: presumably, we're assuming that the in-file and on-command-line
> > > arguments are unioned, ideally with the latter taking precidence if mutually
> > > exclusive.)
> >
> > Yup, I was thinking the same thing too. Once the KVM wiki comes back
> > online I'll write something up on a wiki page.
>
> Great, that was also my idea. Anyone interested in taking a stab at
> this one? I will try and start getting it done this week.
http://kvm.qumranet.com/kvmwiki/Specs/StoringCommandLineInImage
Although it could use some more editing.
Regards,
Anthony Liguori
> Cheers,
> Jorge
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> kvm-devel mailing list
> kvm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-13 15:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-08 18:24 [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images Jorge Lucángeli Obes
[not found] ` <59abf66e0708081252of2948d7we85c9084bad245d4@mail.gmail.com>
[not found] ` <fb249edb0708111011x5abd6a3ehb4a0d3876c2a91c8@mail.gmail.com>
[not found] ` <46BDFA90.4070400@ecs.soton.ac.uk>
[not found] ` <46BE138D.7000500@codemonkey.ws>
[not found] ` <46BE29F9.9050904@ecs.soton.ac.uk>
[not found] ` <1186874268.11306.1.camel@squirrel>
2007-08-13 5:34 ` [Qemu-devel] " Jorge Lucángeli Obes
[not found] ` <59abf66e0708122234u6fe7a27bwa08f92252951879a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-08-13 15:15 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox