Browse Source

fsdev: Error out when unsupported option is passed

Each fsdriver only supports a subset of the options that can be passed
to -fsdev. Unsupported options are simply ignored. This could cause the
user to erroneously think QEMU has a bug.

Enforce strict checking of supported options for all fsdrivers. This
shouldn't impact libvirt, since it doesn't know about the synth and
proxy fsdrivers.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
master
Greg Kurz 1 month ago
parent
commit
aee7f3ecd8
1 changed files with 71 additions and 3 deletions
  1. 71
    3
      fsdev/qemu-fsdev.c

+ 71
- 3
fsdev/qemu-fsdev.c View File

@@ -34,6 +34,7 @@
34 34
 typedef struct FsDriverTable {
35 35
     const char *name;
36 36
     FileOperations *ops;
37
+    const char **opts;
37 38
 } FsDriverTable;
38 39
 
39 40
 typedef struct FsDriverListEntry {
@@ -44,12 +45,75 @@ typedef struct FsDriverListEntry {
44 45
 static QTAILQ_HEAD(, FsDriverListEntry) fsdriver_entries =
45 46
     QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
46 47
 
48
+#define COMMON_FS_DRIVER_OPTIONS "id", "fsdriver", "readonly"
49
+
47 50
 static FsDriverTable FsDrivers[] = {
48
-    { .name = "local", .ops = &local_ops},
49
-    { .name = "synth", .ops = &synth_ops},
50
-    { .name = "proxy", .ops = &proxy_ops},
51
+    {
52
+        .name = "local",
53
+        .ops = &local_ops,
54
+        .opts = (const char * []) {
55
+            COMMON_FS_DRIVER_OPTIONS,
56
+            "security_model",
57
+            "path",
58
+            "writeout",
59
+            "fmode",
60
+            "dmode",
61
+            "throttling.bps-total",
62
+            "throttling.bps-read",
63
+            "throttling.bps-write",
64
+            "throttling.iops-total",
65
+            "throttling.iops-read",
66
+            "throttling.iops-write",
67
+            "throttling.bps-total-max",
68
+            "throttling.bps-read-max",
69
+            "throttling.bps-write-max",
70
+            "throttling.iops-total-max",
71
+            "throttling.iops-read-max",
72
+            "throttling.iops-write-max",
73
+            "throttling.bps-total-max-length",
74
+            "throttling.bps-read-max-length",
75
+            "throttling.bps-write-max-length",
76
+            "throttling.iops-total-max-length",
77
+            "throttling.iops-read-max-length",
78
+            "throttling.iops-write-max-length",
79
+            "throttling.iops-size",
80
+        },
81
+    },
82
+    {
83
+        .name = "synth",
84
+        .ops = &synth_ops,
85
+        .opts = (const char * []) {
86
+            COMMON_FS_DRIVER_OPTIONS,
87
+        },
88
+    },
89
+    {
90
+        .name = "proxy",
91
+        .ops = &proxy_ops,
92
+        .opts = (const char * []) {
93
+            COMMON_FS_DRIVER_OPTIONS,
94
+            "socket",
95
+            "sock_fd",
96
+            "writeout",
97
+        },
98
+    },
51 99
 };
52 100
 
101
+static int validate_opt(void *opaque, const char *name, const char *value,
102
+                        Error **errp)
103
+{
104
+    FsDriverTable *drv = opaque;
105
+    const char **opt;
106
+
107
+    for (opt = drv->opts; *opt; opt++) {
108
+        if (!strcmp(*opt, name)) {
109
+            return 0;
110
+        }
111
+    }
112
+
113
+    error_setg(errp, "'%s' is invalid for fsdriver '%s'", name, drv->name);
114
+    return -1;
115
+}
116
+
53 117
 int qemu_fsdev_add(QemuOpts *opts, Error **errp)
54 118
 {
55 119
     int i;
@@ -80,6 +144,10 @@ int qemu_fsdev_add(QemuOpts *opts, Error **errp)
80 144
         return -1;
81 145
     }
82 146
 
147
+    if (qemu_opt_foreach(opts, validate_opt, &FsDrivers[i], errp)) {
148
+        return -1;
149
+    }
150
+
83 151
     fsle = g_malloc0(sizeof(*fsle));
84 152
     fsle->fse.fsdev_id = g_strdup(fsdev_id);
85 153
     fsle->fse.ops = FsDrivers[i].ops;

Loading…
Cancel
Save