On Tue, 2008-01-08 at 12:12 +0530, Amit Shah wrote:
> > BIOS-provided physical RAM map:
> >  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
> >  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
> >  BIOS-e820: 00000000000e8000 - 0000000000100000 (reserved)
> >  BIOS-e820: 0000000000100000 - 00000000fffbd000 (usable)
> >  BIOS-e820: 00000000fffbd000 - 00000000ffff0000 (reserved)
> >
> > Note that this is with '-m 1G'!!  It looks to me like one of those
> 
> And there lies the problem. qemu doesn't understand suffixes like 'G'.
> If you 
> pass -m 1024, you'll boot just fine.
> 
> This is really annoying of qemu (it should either accept that input
> properly 
> or bail out); a patch is welcome!

OK.  Here's a function stolen blatantly from the kernel.  Seems to work
OK for me for:

        -m 1234
        -m 1234M
        -m 1G
        -m 99G

diff -ru orig/qemu-0.9.1/vl.c qemu-0.9.1/vl.c
--- orig/qemu-0.9.1/vl.c        2008-01-06 11:38:42.000000000 -0800
+++ qemu-0.9.1/vl.c     2008-01-08 11:23:29.000000000 -0800
@@ -8052,6 +8052,47 @@
 }
 #endif
 
+/**
+ *     memparse - parse a string with mem suffixes into a number of bytes
+ *     @ptr: Where parse begins
+ *
+ *     Parses a string into a number.  The number stored at @ptr is
+ *     potentially suffixed with %M (for megabytes, or 1048576 bytes)
+ *     or %G (for gigabytes, or 1073741824).  If the number is
+ *     suffixed with M or G, then the return value is the number
+ *     multiplied by one megabyte or one gigabyte, respectively. No
+ *     suffix implies megabytes.
+ */
+
+unsigned long long memparse (const char *ptr)
+{
+       char *endptr;
+       unsigned long ret = strtoull(ptr, &endptr, 0);
+
+       switch (*endptr) {
+       case 'G':
+       case 'g':
+               ret <<= 10;
+       case 'M':
+       case 'm':
+               ret <<= 20;
+               break;
+       default:
+               /* for backward compatibility; qemu has
+                * traditionally taken this in plain MB */
+               ret <<= 20;
+               break;
+       }
+       if (ret <= 0)
+               help(1);
+       if (ret > PHYS_RAM_MAX_SIZE) {
+               fprintf(stderr, "qemu: at most %d MB RAM can be simulated\n",
+                       PHYS_RAM_MAX_SIZE / (1024 * 1024));
+               exit(1);
+       }
+       return ret;
+}
+
 #define MAX_NET_CLIENTS 32
 
 int main(int argc, char **argv)
@@ -8402,14 +8443,7 @@
                 help(0);
                 break;
             case QEMU_OPTION_m:
-                ram_size = atoi(optarg) * 1024 * 1024;
-                if (ram_size <= 0)
-                    help(1);
-                if (ram_size > PHYS_RAM_MAX_SIZE) {
-                    fprintf(stderr, "qemu: at most %d MB RAM can be 
simulated\n",
-                            PHYS_RAM_MAX_SIZE / (1024 * 1024));
-                    exit(1);
-                }
+                ram_size = memparse(optarg);
                 break;
             case QEMU_OPTION_d:
                 {
@@ -8664,6 +8698,7 @@
             }
         }
     }
+    fprintf(stderr, "qemu: using %d MB RAM\n", ram_size>>20);
 
 #ifndef _WIN32
     if (daemonize && !nographic && vnc_display == NULL) {


-- Dave


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to