diff --git a/qemu-options.hx b/qemu-options.hx
index cf811c552e..e6320e18f2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1542,7 +1542,7 @@ DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
     "-virtfs proxy,mount_tag=tag,socket=socket[,id=id][,writeout=immediate][,readonly]\n"
     "-virtfs proxy,mount_tag=tag,sock_fd=sock_fd[,id=id][,writeout=immediate][,readonly]\n"
     "-virtfs synth,mount_tag=tag[,id=id][,readonly]\n",
-    QEMU_ARCH_ALL)
+    QEMU_ARCH_ALL, parse_virtfs)
 
 SRST
 ``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]``
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 6a0a49c7c7..a868acd37c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1737,6 +1737,87 @@ static int parse_net_client(const QEMUOption *popt, const char* optarg)
     return 0;
 }
 
+static int parse_virtfs(const QEMUOption *popt, const char* optarg)
+{
+    QemuOptsList *olist;
+    QemuOpts *fsdev;
+    QemuOpts *device;
+    QemuOpts *opts;
+    const char *writeout, *sock_fd, *socket, *path, *security_model,
+               *multidevs;
+
+    olist = qemu_find_opts("virtfs");
+    if (!olist) {
+        error_report("virtfs support is disabled");
+        exit(1);
+    }
+    opts = qemu_opts_parse_noisily(olist, optarg, true);
+    if (!opts) {
+        exit(1);
+    }
+
+    if (qemu_opt_get(opts, "fsdriver") == NULL ||
+        qemu_opt_get(opts, "mount_tag") == NULL) {
+        error_report("Usage: -virtfs fsdriver,mount_tag=tag");
+        exit(1);
+    }
+    fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
+                             qemu_opts_id(opts) ?:
+                             qemu_opt_get(opts, "mount_tag"),
+                             1, NULL);
+    if (!fsdev) {
+        error_report("duplicate or invalid fsdev id: %s",
+                     qemu_opt_get(opts, "mount_tag"));
+        exit(1);
+    }
+
+    writeout = qemu_opt_get(opts, "writeout");
+    if (writeout) {
+#ifdef CONFIG_SYNC_FILE_RANGE
+        qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
+#else
+        error_report("writeout=immediate not supported "
+                     "on this platform");
+        exit(1);
+#endif
+    }
+    qemu_opt_set(fsdev, "fsdriver",
+                 qemu_opt_get(opts, "fsdriver"), &error_abort);
+    path = qemu_opt_get(opts, "path");
+    if (path) {
+        qemu_opt_set(fsdev, "path", path, &error_abort);
+    }
+    security_model = qemu_opt_get(opts, "security_model");
+    if (security_model) {
+        qemu_opt_set(fsdev, "security_model", security_model,
+                     &error_abort);
+    }
+    socket = qemu_opt_get(opts, "socket");
+    if (socket) {
+        qemu_opt_set(fsdev, "socket", socket, &error_abort);
+    }
+    sock_fd = qemu_opt_get(opts, "sock_fd");
+    if (sock_fd) {
+        qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
+    }
+
+    qemu_opt_set_bool(fsdev, "readonly",
+                      qemu_opt_get_bool(opts, "readonly", 0),
+                      &error_abort);
+    multidevs = qemu_opt_get(opts, "multidevs");
+    if (multidevs) {
+        qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
+    }
+    device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
+                              &error_abort);
+    qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
+    qemu_opt_set(device, "fsdev",
+                 qemu_opts_id(fsdev), &error_abort);
+    qemu_opt_set(device, "mount_tag",
+                 qemu_opt_get(opts, "mount_tag"), &error_abort);
+    return 0;
+}
+
 static const QEMUOption qemu_options[] = {
     { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
 #define QEMU_OPTIONS_GENERATE_OPTIONS
@@ -3293,83 +3374,6 @@ void qemu_init(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
-            case QEMU_OPTION_virtfs: {
-                QemuOpts *fsdev;
-                QemuOpts *device;
-                const char *writeout, *sock_fd, *socket, *path, *security_model,
-                           *multidevs;
-
-                olist = qemu_find_opts("virtfs");
-                if (!olist) {
-                    error_report("virtfs support is disabled");
-                    exit(1);
-                }
-                opts = qemu_opts_parse_noisily(olist, optarg, true);
-                if (!opts) {
-                    exit(1);
-                }
-
-                if (qemu_opt_get(opts, "fsdriver") == NULL ||
-                    qemu_opt_get(opts, "mount_tag") == NULL) {
-                    error_report("Usage: -virtfs fsdriver,mount_tag=tag");
-                    exit(1);
-                }
-                fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
-                                         qemu_opts_id(opts) ?:
-                                         qemu_opt_get(opts, "mount_tag"),
-                                         1, NULL);
-                if (!fsdev) {
-                    error_report("duplicate or invalid fsdev id: %s",
-                                 qemu_opt_get(opts, "mount_tag"));
-                    exit(1);
-                }
-
-                writeout = qemu_opt_get(opts, "writeout");
-                if (writeout) {
-#ifdef CONFIG_SYNC_FILE_RANGE
-                    qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
-#else
-                    error_report("writeout=immediate not supported "
-                                 "on this platform");
-                    exit(1);
-#endif
-                }
-                qemu_opt_set(fsdev, "fsdriver",
-                             qemu_opt_get(opts, "fsdriver"), &error_abort);
-                path = qemu_opt_get(opts, "path");
-                if (path) {
-                    qemu_opt_set(fsdev, "path", path, &error_abort);
-                }
-                security_model = qemu_opt_get(opts, "security_model");
-                if (security_model) {
-                    qemu_opt_set(fsdev, "security_model", security_model,
-                                 &error_abort);
-                }
-                socket = qemu_opt_get(opts, "socket");
-                if (socket) {
-                    qemu_opt_set(fsdev, "socket", socket, &error_abort);
-                }
-                sock_fd = qemu_opt_get(opts, "sock_fd");
-                if (sock_fd) {
-                    qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
-                }
-
-                qemu_opt_set_bool(fsdev, "readonly",
-                                  qemu_opt_get_bool(opts, "readonly", 0),
-                                  &error_abort);
-                multidevs = qemu_opt_get(opts, "multidevs");
-                if (multidevs) {
-                    qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
-                }
-                device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
-                                          &error_abort);
-                qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
-                qemu_opt_set(device, "fsdev",
-                             qemu_opts_id(fsdev), &error_abort);
-                qemu_opt_set(device, "mount_tag",
-                             qemu_opt_get(opts, "mount_tag"), &error_abort);
-                break;
-            }
             case QEMU_OPTION_serial:
                 add_device_config(DEV_SERIAL, optarg);
                 default_serial = 0;
