Never overwrite a QemuOpt
Rather than overwriting a QemuOpt, just add a new one to the tail and always do a reverse search for parameters to preserve the same behaviour. We use this order so that foreach() iterates over the opts in their original order. This will allow us handle options where multiple values for the same parameter is allowed - e.g. -net user,hostfwd= Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									5dc519ef92
								
							
						
					
					
						commit
						dc9ca4ba27
					
				| @ -483,7 +483,7 @@ struct QemuOpt { | ||||
| struct QemuOpts { | ||||
|     const char *id; | ||||
|     QemuOptsList *list; | ||||
|     QTAILQ_HEAD(, QemuOpt) head; | ||||
|     QTAILQ_HEAD(QemuOptHead, QemuOpt) head; | ||||
|     QTAILQ_ENTRY(QemuOpts) next; | ||||
| }; | ||||
| 
 | ||||
| @ -491,7 +491,7 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) | ||||
| { | ||||
|     QemuOpt *opt; | ||||
| 
 | ||||
|     QTAILQ_FOREACH(opt, &opts->head, next) { | ||||
|     QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { | ||||
|         if (strcmp(opt->name, name) != 0) | ||||
|             continue; | ||||
|         return opt; | ||||
| @ -565,36 +565,31 @@ static void qemu_opt_del(QemuOpt *opt) | ||||
| int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) | ||||
| { | ||||
|     QemuOpt *opt; | ||||
|     QemuOptDesc *desc = opts->list->desc; | ||||
|     int i; | ||||
| 
 | ||||
|     opt = qemu_opt_find(opts, name); | ||||
|     if (!opt) { | ||||
|         QemuOptDesc *desc = opts->list->desc; | ||||
|         int i; | ||||
| 
 | ||||
|         for (i = 0; desc[i].name != NULL; i++) { | ||||
|             if (strcmp(desc[i].name, name) == 0) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|         if (desc[i].name == NULL) { | ||||
|             if (i == 0) { | ||||
|                 /* empty list -> allow any */; | ||||
|             } else { | ||||
|                 fprintf(stderr, "option \"%s\" is not valid for %s\n", | ||||
|                         name, opts->list->name); | ||||
|                 return -1; | ||||
|             } | ||||
|         } | ||||
|         opt = qemu_mallocz(sizeof(*opt)); | ||||
|         opt->name = qemu_strdup(name); | ||||
|         opt->opts = opts; | ||||
|         QTAILQ_INSERT_TAIL(&opts->head, opt, next); | ||||
|         if (desc[i].name != NULL) { | ||||
|             opt->desc = desc+i; | ||||
|     for (i = 0; desc[i].name != NULL; i++) { | ||||
|         if (strcmp(desc[i].name, name) == 0) { | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|     qemu_free((/* !const */ char*)opt->str); | ||||
|     opt->str = NULL; | ||||
|     if (desc[i].name == NULL) { | ||||
|         if (i == 0) { | ||||
|             /* empty list -> allow any */; | ||||
|         } else { | ||||
|             fprintf(stderr, "option \"%s\" is not valid for %s\n", | ||||
|                     name, opts->list->name); | ||||
|             return -1; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     opt = qemu_mallocz(sizeof(*opt)); | ||||
|     opt->name = qemu_strdup(name); | ||||
|     opt->opts = opts; | ||||
|     QTAILQ_INSERT_TAIL(&opts->head, opt, next); | ||||
|     if (desc[i].name != NULL) { | ||||
|         opt->desc = desc+i; | ||||
|     } | ||||
|     if (value) { | ||||
|         opt->str = qemu_strdup(value); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Mark McLoughlin
						Mark McLoughlin