[virtio-9p] Qemu 9p commandline options validity checks

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
This commit is contained in:
Harsh Prateek Bora 2010-10-18 15:36:36 +05:30 committed by Anthony Liguori
parent 70fc55ebe4
commit 9f506893a4
2 changed files with 33 additions and 19 deletions

View File

@ -29,35 +29,47 @@ int qemu_fsdev_add(QemuOpts *opts)
{ {
struct FsTypeListEntry *fsle; struct FsTypeListEntry *fsle;
int i; int i;
const char *fsdev_id = qemu_opts_id(opts);
const char *fstype = qemu_opt_get(opts, "fstype");
const char *path = qemu_opt_get(opts, "path");
const char *sec_model = qemu_opt_get(opts, "security_model");
if (qemu_opts_id(opts) == NULL) { if (!fsdev_id) {
fprintf(stderr, "fsdev: No id specified\n"); fprintf(stderr, "fsdev: No id specified\n");
return -1; return -1;
} }
for (i = 0; i < ARRAY_SIZE(FsTypes); i++) { if (fstype) {
if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) { for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
break; if (strcmp(FsTypes[i].name, fstype) == 0) {
break;
}
} }
}
if (i == ARRAY_SIZE(FsTypes)) { if (i == ARRAY_SIZE(FsTypes)) {
fprintf(stderr, "fsdev: fstype %s not found\n", fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
qemu_opt_get(opts, "fstype")); return -1;
}
} else {
fprintf(stderr, "fsdev: No fstype specified\n");
return -1; return -1;
} }
if (qemu_opt_get(opts, "security_model") == NULL) { if (!sec_model) {
fprintf(stderr, "fsdev: No security_model specified.\n"); fprintf(stderr, "fsdev: No security_model specified.\n");
return -1; return -1;
} }
if (!path) {
fprintf(stderr, "fsdev: No path specified.\n");
return -1;
}
fsle = qemu_malloc(sizeof(*fsle)); fsle = qemu_malloc(sizeof(*fsle));
fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts)); fsle->fse.fsdev_id = qemu_strdup(fsdev_id);
fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path")); fsle->fse.path = qemu_strdup(path);
fsle->fse.security_model = qemu_strdup(qemu_opt_get(opts, fsle->fse.security_model = qemu_strdup(sec_model);
"security_model"));
fsle->fse.ops = FsTypes[i].ops; fsle->fse.ops = FsTypes[i].ops;
QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next); QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
@ -67,11 +79,13 @@ int qemu_fsdev_add(QemuOpts *opts)
FsTypeEntry *get_fsdev_fsentry(char *id) FsTypeEntry *get_fsdev_fsentry(char *id)
{ {
struct FsTypeListEntry *fsle; if (id) {
struct FsTypeListEntry *fsle;
QTAILQ_FOREACH(fsle, &fstype_entries, next) { QTAILQ_FOREACH(fsle, &fstype_entries, next) {
if (strcmp(fsle->fse.fsdev_id, id) == 0) { if (strcmp(fsle->fse.fsdev_id, id) == 0) {
return &fsle->fse; return &fsle->fse;
}
} }
} }
return NULL; return NULL;

View File

@ -3697,8 +3697,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
if (!fse) { if (!fse) {
/* We don't have a fsdev identified by fsdev_id */ /* We don't have a fsdev identified by fsdev_id */
fprintf(stderr, "Virtio-9p device couldn't find fsdev " fprintf(stderr, "Virtio-9p device couldn't find fsdev with the "
"with the id %s\n", conf->fsdev_id); "id = %s\n", conf->fsdev_id ? conf->fsdev_id : "NULL");
exit(1); exit(1);
} }