diff mbox

virtfs: allow a device id to be specified in the -virtfs option

Message ID 8a28dca8b6a0b0528763388f80f3bd06c492494a.1322150640.git.chris@arachsys.com
State New
Headers show

Commit Message

Chris Webb Nov. 24, 2011, 4:04 p.m. UTC
When using a virtfs root filesystem, the mount_tag needs to be set to
/dev/root. This can be done long-hand as

  -fsdev local,id=root,path=/path/to/rootfs,...
  -device virtio-9p-pci,fsdev=root,mount_tag=/dev/root

but the -virtfs shortcut cannot be used as it hard-codes the device identifier
to match the mount_tag, and device identifiers may not contain '/':

  $ qemu-system-x86_64 -virtfs local,path=/foo,mount_tag=/dev/root,security_model=passthrough
  qemu-system-x86_64: -virtfs local,path=/foo,mount_tag=/dev/root,security_model=passthrough: Parameter 'id' expects an identifier
  Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
  duplicate fsdev id: /dev/root

To support this case using -virtfs, we allow the device identifier to be
specified explicitly when the mount_tag is not suitable:

  -virtfs local,id=root,path=/path/to/rootfs,mount_tag=/dev/root,...

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 qemu-options.hx |    4 ++--
 vl.c            |   16 +++++++++++-----
 2 files changed, 13 insertions(+), 7 deletions(-)

Comments

Peter Maydell Nov. 24, 2011, 4:41 p.m. UTC | #1
On 24 November 2011 16:04, Chris Webb <chris@arachsys.com> wrote:
> +                if (qemu_opts_id(opts)) {
> +                  fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
> +                                           qemu_opts_id(opts), 1);
> +                } else {
> +                  fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
> +                                           qemu_opt_get(opts, "mount_tag"), 1);
> +                }

The indentation here looks wrong. (scripts/checkpatch.pl will catch
this kind of thing for you).

-- PMM
Chris Webb Nov. 24, 2011, 5:08 p.m. UTC | #2
Peter Maydell <peter.maydell@linaro.org> writes:

> On 24 November 2011 16:04, Chris Webb <chris@arachsys.com> wrote:
> > + ?? ?? ?? ?? ?? ?? ?? ??if (qemu_opts_id(opts)) {
> > + ?? ?? ?? ?? ?? ?? ?? ?? ??fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
> > + ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? qemu_opts_id(opts), 1);
> > + ?? ?? ?? ?? ?? ?? ?? ??} else {
> > + ?? ?? ?? ?? ?? ?? ?? ?? ??fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
> > + ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? qemu_opt_get(opts, "mount_tag"), 1);
> > + ?? ?? ?? ?? ?? ?? ?? ??}
> 
> The indentation here looks wrong. (scripts/checkpatch.pl will catch
> this kind of thing for you).

You're quite right; resent a fixed version.

Cheers,

Chris.
diff mbox

Patch

diff --git a/qemu-options.hx b/qemu-options.hx
index 681eaf1..865e3a2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -588,13 +588,13 @@  DEFHEADING()
 DEFHEADING(Virtual File system pass-through options:)
 
 DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
-    "-virtfs local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n"
+    "-virtfs local[,id=id],path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n"
     "        [,writeout=immediate][,readonly]\n",
     QEMU_ARCH_ALL)
 
 STEXI
 
-@item -virtfs @var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}][,readonly]
+@item -virtfs @var{fsdriver}[,id=@var{id}],path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}][,readonly]
 @findex -virtfs
 
 The general form of a Virtual File system pass-through options are:
diff --git a/vl.c b/vl.c
index f5afed4..b17af09 100644
--- a/vl.c
+++ b/vl.c
@@ -2689,10 +2689,17 @@  int main(int argc, char **argv, char **envp)
                             "mount_tag=tag.\n");
                     exit(1);
                 }
-                fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
-                                         qemu_opt_get(opts, "mount_tag"), 1);
+
+                if (qemu_opts_id(opts)) {
+                  fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
+                                           qemu_opts_id(opts), 1);
+                } else {
+                  fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
+                                           qemu_opt_get(opts, "mount_tag"), 1);
+                }
+
                 if (!fsdev) {
-                    fprintf(stderr, "duplicate fsdev id: %s\n",
+                    fprintf(stderr, "duplicate or invalid fsdev id: %s\n",
                             qemu_opt_get(opts, "mount_tag"));
                     exit(1);
                 }
@@ -2716,8 +2723,7 @@  int main(int argc, char **argv, char **envp)
                                 qemu_opt_get_bool(opts, "readonly", 0));
                 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
                 qemu_opt_set(device, "driver", "virtio-9p-pci");
-                qemu_opt_set(device, "fsdev",
-                             qemu_opt_get(opts, "mount_tag"));
+                qemu_opt_set(device, "fsdev", qemu_opts_id(fsdev));
                 qemu_opt_set(device, "mount_tag",
                              qemu_opt_get(opts, "mount_tag"));
                 break;