hw: improve multiboot module loading
PATCH 1/1 hw: improve multiboot module loading
Multiboot modules couldn't be loaded when there are spaces between the filename and ','. Those spaces can simply be killed.
Signed-off-by:
---
hw/multiboot.c +3 -0
@@ -267,6 +267,9 @@ int load_multiboot(void *fw_cfg,/* if a space comes after the module filename, treat everything after that as parameters */ target_phys_addr_t c =mb_add_cmdline (&mbs, initrd_filename); +/* Kill spaces at the beginning of the filename */ +while ( *initrd_filename ==' ' ) + initrd_filename++;if ((next_space =strchr (initrd_filename,' ' ))) *next_space ='\0' ;mb_debug ("multiboot loading module: %s\n" , initrd_filename);
Quoted 10 lines · On 07.04.2011, at 02:19, [email protected] wrote:
Multiboot modules couldn't be loaded when there are spaces between the filename and ','. Those spaces can simply be killed.
Signed-off-by:
---hw/multiboot.c +0
-0
hw/multiboot.c int load_multiboot(void *fw_cfg, · line 272
Quoted 6 lines
hw/multiboot.c +3
-0@@ -267,6 +267,9 @@ int load_multiboot(void *fw_cfg,/* if a space comes after the module filename, treat everything after that as parameters */ target_phys_addr_t c =mb_add_cmdline (&mbs, initrd_filename); +/* Kill spaces at the beginning of the filename */ +while ( *initrd_filename ==' ' ) + initrd_filename++;
Please make sure to follow the coding style. There shouldn't be whitespace between the (), but between while and ( and you need some extra braces :):
while (*initrd_filename == ' ') {
initrd_filename++;
}Otherwise, the patch looks good! Please resend a corrected version, so that it can be easily applied.
Alex
Here the version with the correct coding style.
hw/multiboot.c +5 -0
@@ -267,6 +267,11 @@ int load_multiboot(void *fw_cfg,/* if a space comes after the module filename, treat everything after that as parameters */ target_phys_addr_t c =mb_add_cmdline (&mbs, initrd_filename); +/* Kill spaces at the beginning of the filename */ +while (*initrd_filename ==' ' ) + { + initrd_filename++; + }if ((next_space =strchr (initrd_filename,' ' ))) *next_space ='\0' ;mb_debug ("multiboot loading module: %s\n" , initrd_filename);
Quoted 1 line · Ralf Ramsauer
Here the version with the correct coding style.
Phew - please keep the commit message intact. What we do to apply patches is that we simply directly take your patch into git using "git am". With a patch description like this, if anyone looks at "git blame" or "git log" later, will wonder what the rationale was behind the patch, as the description is basically missing.
Also, you need to put a line like this there:
I would actually simply resend a patch with proper patch description and fixed braces (see next comment), but I can't, because the first patch you sent was already missing your name after the Signed-off-by, basically making the patch a legal grey zone. So please, resend it again with proper patch description, proper Signed-off-by line and the brace thing fixed.
Alternatively, I could rewrite the patch myself. But that would obviously rob you off your name in the commit log (due to the missing Signed-off-by), which I bet you wouldn't want :). The fame is all yours after all.
hw/multiboot.c int load_multiboot(void *fw_cfg, · line 270
Quoted 9 lines
hw/multiboot.c +1
-0@@ -267,6 +267,11 @@ int load_multiboot(void *fw_cfg,/* if a space comes after the module filename, treat everything after that as parameters */ target_phys_addr_t c =mb_add_cmdline (&mbs, initrd_filename); +/* Kill spaces at the beginning of the filename */
Please move your code before the comment above. This way, it's
a) confusing to read
b) the $0 argument passed to the guest is wrong, as the virtual command line that shows up in the guest multiboot descriptor tables doesn't get the spaces removed.
hw/multiboot.c int load_multiboot(void *fw_cfg, · line 272
Quoted 2 lines
hw/multiboot.c +2
-0+while (*initrd_filename ==' ' ) + {
Please do the brace in the same line as the while. This way it's not following CODING_STYLE.
Also, I just realized that you did miss another small part that needs change. A few lines above, there is code to interpret the modules right before that as well:
if (initrd_filename) {
const char *r = initrd_filename;
mbs.mb_buf_size += strlen(r) + 1;
mbs.mb_mods_avail = 1;
while ((r = strchr(r, ','))) {
mbs.mb_mods_avail++;
r++;
}
mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail;
}This code would need some change as well, as now the mb_buf_size field is incorrect. It doesn't really hurt, but is bad style to not use the exact amount of memory we need to.
hw/multiboot.c int load_multiboot(void *fw_cfg, · line 277
Quoted 5 lines
hw/multiboot.c +2
-0+ initrd_filename++; + }if ((next_space =strchr (initrd_filename,' ' ))) *next_space ='\0' ;mb_debug ("multiboot loading module: %s\n" , initrd_filename);
I've also CC'ed Adam. He's been the most active person contributing to multiboot recently.
Alex
Quoted 14 lines · Alexander Graf
Also, I just realized that you did miss another small part that needs change. A few lines above, there is code to interpret the modules right before that as well:
if (initrd_filename) { const char *r = initrd_filename; mbs.mb_buf_size += strlen(r) + 1; mbs.mb_mods_avail = 1; while ((r = strchr(r, ','))) { mbs.mb_mods_avail++; r++; } mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail; }
Quoted 1 line
This code would need some change as well, as now the
mb_buf_sizefield is incorrect. It doesn't really hurt, but is bad style to not use the exact amount of memory we need to.
You're right, I didn't look at this section. But now i had a deeper look into the code, and I noticed the the mb_buf size seems to be incorrect anyway.
Look at this line:
mbs.mb_buf_size += strlen(r) + 1;
If I start qemu with the option -initrd "mod1 arg=bla, mod2 arg=foo, mod3 arg=bar", then r contains
"mod1 arg=bla, mod2 arg=foo, mod3 arg=bar", so the commas and spaces after the comma are counted for the size of the multiboot command line. Yes, this doesn't really hurt, but it's nevertheless not the exact amount of memory. I'll try to fix it.
--
Ralf
Quoted 19 lines · Ralf Ramsauer
Quoted 14 lines · Alexander Graf
Also, I just realized that you did miss another small part that needs change. A few lines above, there is code to interpret the modules right before that as well:
if (initrd_filename) { const char *r = initrd_filename; mbs.mb_buf_size += strlen(r) + 1; mbs.mb_mods_avail = 1; while ((r = strchr(r, ','))) { mbs.mb_mods_avail++; r++; } mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail; }Quoted 1 line
This code would need some change as well, as now the
mb_buf_sizefield is incorrect. It doesn't really hurt, but is bad style to not use the exact amount of memory we need to.You're right, I didn't look at this section. But now i had a deeper look into the code, and I noticed the the
mb_bufsize seems to be incorrect anyway.
Quoted 7 lines
Look at this line:
mbs.mb_buf_size += strlen(r) + 1;
If I start qemu with the option -initrd "mod1 arg=bla, mod2 arg=foo, mod3 arg=bar", then r contains
"mod1 arg=bla, mod2 arg=foo, mod3 arg=bar", so the commas and spaces after the comma are counted for the size of the multiboot command line. Yes, this doesn't really hurt, but it's nevertheless not the exact amount of memory. I'll try to fix it.
Good point. Thanks!
Alex
Hello again,
there's another problem with parsing the initrd string:
If you want to start qemu with ... -initrd "mod1 arg=foo,bar , mod2 arg=bar,foo" it won't work The string is separated at every comma, arguments containing a comma are misinterpreted.
So we'd think about another way delivering the arguments to load_multiboot.
-initrd is used passing multiboot modules, but multiboot modules aren't really initrd's
Multiboot modules are only loaded when qemu identifies the kernel as a Multiboot kernel. It would be much easier to pass the modules to qemu using a commandline argument like -multiboot. e.g.
qemu -kernel mymultibootkern -module "1.mod arg=bla" -module "2.mod arg=foo"
Well i didn't look at the global command line parsing of qemu, and i don't know how difficult it would be to realize this. Anyone ideas?
--
Ralf
Out of curiousity, why are you trying to kill spaces at all?
Why not just use a correct command-line to invoke QEMU?
Stefan
Quoted 5 lines · Stefan Hajnoczi
Out of curiousity, why are you trying to kill spaces at all?
Why not just use a correct command-line to invoke QEMU?
Stefan
Well it took me 2 days to find out why -initrd "module1, module2" didn't work. If there's a space after the comma you'll always get the error message "Failed to get image size". And if you want to pass a comma in a multiboot argument you've no way to do this. So -initrd"module1 settings=use_foo,use_bar" won't work!
--
Ralf
Quoted 10 lines · Ralf Ramsauer
Quoted 5 lines · Stefan Hajnoczi
Out of curiousity, why are you trying to kill spaces at all?
Why not just use a correct command-line to invoke QEMU?
Stefan
Well it took me 2 days to find out why -initrd "module1, module2" didn't work. If there's a space after the comma you'll always get the error message "Failed to get image size".
How about improving the error message?
Quoted 4 lines
And if you want to pass a comma in a multiboot argument you've no way to do this. So -initrd"module1 settings=use_foo,use_bar" won't work!
From what I can tell your patch does not change this.
Stefan
Quoted 6 lines · Stefan Hajnoczi
Quoted 4 lines · Ralf Ramsauer
Quoted 2 lines · Stefan Hajnoczi
Out of curiousity, why are you trying to kill spaces at all?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Why not just use a correct command-line to invoke QEMU?
Stefan
Well it took me 2 days to find out why -initrd "module1, module2" didn't work. If there's a space after the comma you'll always get the error message "Failed to get image size".
How about improving the error message?
I'll send a patch shortly fixing the message.
Quoted 4 lines
Quoted 4 lines
And if you want to pass a comma in a multiboot argument you've no way to do this. So -initrd"module1 settings=use_foo,use_bar" won't work!
From what I can tell your patch does not change this.
It should be possible to put commas on the mb command line. Do we want to escape commas?
Adam
Signature · 2 lines
Adam [email protected] Lackorzynski http://os.inf.tu-dresden.de/~adam/
Quoted 1 line · On Thu, 7 Apr 2011 10:19:01 am [email protected] wrote:
Signed-off-by:
Looks like something may be wrong with your git config
Brad
hw/multiboot.c int load_multiboot(void *fw_cfg, · line 272
Quoted 7 lines · On Thu, Apr 07, 2011 at 12:19:01AM -0000, [email protected] wrote:
hw/multiboot.c +3
-0@@ -267,6 +267,9 @@ int load_multiboot(void *fw_cfg,/* if a space comes after the module filename, treat everything after that as parameters */ target_phys_addr_t c =mb_add_cmdline (&mbs, initrd_filename); +/* Kill spaces at the beginning of the filename */ +while ( *initrd_filename ==' ' ) + initrd_filename++;
If we want to do this, shouldn't it be done before adding to the multiboot command-line? Otherwise the multiboot image also has to strip leading spaces.
Stefan
Leading spaces mustn't be stripped! The commandline could look like:
qemu -kernel kern -initrd "1.mod arg=foo arg2=bar, 2.mod arg=asdf" The problem is, that the string
"1.mod arg=foo arg2=bar, 2.mod arg=asdf"
is divided at the ','. So we have two string
"1.mod arg=foo arg2=bar" and
" 2.mod arg=asdf"
^ This space causes the error "Failed to get image size"
So just the spaces at the beginning of the file have to be stripped. Spaces at the end could be important for the commandline. E.g.
-initrd "1.mod arg=argwithmanyspaces , 2.mod"
--
Ralf
Quoted 6 lines
If we want to do this, shouldn't it be done before adding to the multiboot command-line? Otherwise the multiboot image also has to strip leading spaces.
Stefan