qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Jorge Lucángeli Obes" <t4m5yn@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images
Date: Wed, 8 Aug 2007 16:52:58 -0300	[thread overview]
Message-ID: <59abf66e0708081252of2948d7we85c9084bad245d4@mail.gmail.com> (raw)
In-Reply-To: <59abf66e0708081124g14901b01i841b70d17ae1e097@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3170 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;
 }

[-- 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;
 }

       reply	other threads:[~2007-08-08 19:53 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <59abf66e0708081124g14901b01i841b70d17ae1e097@mail.gmail.com>
2007-08-08 19:52 ` Jorge Lucángeli Obes [this message]
2007-08-08 20:24   ` [Qemu-devel] [PATCH 4/4][RFC] Add logic to QEMU to read command line options from qcow2 images Daniel P. Berrange
2007-08-09 14:54     ` Anthony Liguori
2007-08-09 15:07       ` Daniel P. Berrange
2007-08-09 20:16       ` Avi Kivity
2007-08-09 20:25         ` Anthony Liguori
2007-08-09 20:30           ` Avi Kivity
2007-08-09 20:32             ` Anthony Liguori
2007-08-09 20:39               ` Avi Kivity
2007-08-09 20:44               ` Brian Wheeler
2007-08-09 20:49                 ` Anthony Liguori
2007-08-10  3:51                 ` dmc
2007-08-10 13:26                   ` Carlos A. M. dos Santos
2007-08-09 20:55         ` Brian Wheeler
2007-08-10  0:48           ` Anthony Liguori
2007-08-11 17:11   ` andrzej zaborowski
2007-08-11 18:06     ` Philip Boulain
2007-08-11 19:08       ` Christian Brunschen
2007-08-11 19:53         ` Anthony Liguori
2007-08-11 19:52       ` Anthony Liguori
2007-08-11 21:28         ` Philip Boulain
2007-08-11 23:17           ` Anthony Liguori
2007-08-13  5:34             ` Jorge Lucángeli Obes
2007-08-13 15:15               ` [kvm-devel] " Anthony Liguori
2007-08-11 19:49     ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59abf66e0708081252of2948d7we85c9084bad245d4@mail.gmail.com \
    --to=t4m5yn@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).