Commit 9dfd7c7a00dd700de36ca58005a7cb3934a62efb
Committed by
Anthony Liguori
1 parent
e27c88fe
switch -drive to QemuOpts.
Demo QemuOpts in action ;) Implementing a alternative way to specify the filename should be just a few lines of code now once we decided how the cmd line syntax should look like. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
3 changed files
with
178 additions
and
156 deletions
hw/device-hotplug.c
| @@ -28,19 +28,19 @@ | @@ -28,19 +28,19 @@ | ||
| 28 | #include "block_int.h" | 28 | #include "block_int.h" |
| 29 | #include "sysemu.h" | 29 | #include "sysemu.h" |
| 30 | 30 | ||
| 31 | -DriveInfo *add_init_drive(const char *opts) | 31 | +DriveInfo *add_init_drive(const char *optstr) |
| 32 | { | 32 | { |
| 33 | int fatal_error; | 33 | int fatal_error; |
| 34 | DriveInfo *dinfo; | 34 | DriveInfo *dinfo; |
| 35 | - DriveOpt *dopt; | 35 | + QemuOpts *opts; |
| 36 | 36 | ||
| 37 | - dopt = drive_add(NULL, "%s", opts); | ||
| 38 | - if (!dopt) | 37 | + opts = drive_add(NULL, "%s", optstr); |
| 38 | + if (!opts) | ||
| 39 | return NULL; | 39 | return NULL; |
| 40 | 40 | ||
| 41 | - dinfo = drive_init(dopt, 0, current_machine, &fatal_error); | 41 | + dinfo = drive_init(opts, current_machine, &fatal_error); |
| 42 | if (!dinfo) { | 42 | if (!dinfo) { |
| 43 | - drive_remove(dopt); | 43 | + qemu_opts_del(opts); |
| 44 | return NULL; | 44 | return NULL; |
| 45 | } | 45 | } |
| 46 | 46 |
sysemu.h
| @@ -160,12 +160,6 @@ typedef enum { | @@ -160,12 +160,6 @@ typedef enum { | ||
| 160 | 160 | ||
| 161 | #define BLOCK_SERIAL_STRLEN 20 | 161 | #define BLOCK_SERIAL_STRLEN 20 |
| 162 | 162 | ||
| 163 | -typedef struct DriveOpt { | ||
| 164 | - const char *file; | ||
| 165 | - char opt[1024]; | ||
| 166 | - TAILQ_ENTRY(DriveOpt) next; | ||
| 167 | -} DriveOpt; | ||
| 168 | - | ||
| 169 | typedef struct DriveInfo { | 163 | typedef struct DriveInfo { |
| 170 | BlockDriverState *bdrv; | 164 | BlockDriverState *bdrv; |
| 171 | char *id; | 165 | char *id; |
| @@ -173,7 +167,7 @@ typedef struct DriveInfo { | @@ -173,7 +167,7 @@ typedef struct DriveInfo { | ||
| 173 | BlockInterfaceType type; | 167 | BlockInterfaceType type; |
| 174 | int bus; | 168 | int bus; |
| 175 | int unit; | 169 | int unit; |
| 176 | - DriveOpt *opt; | 170 | + QemuOpts *opts; |
| 177 | BlockInterfaceErrorAction onerror; | 171 | BlockInterfaceErrorAction onerror; |
| 178 | char serial[BLOCK_SERIAL_STRLEN + 1]; | 172 | char serial[BLOCK_SERIAL_STRLEN + 1]; |
| 179 | TAILQ_ENTRY(DriveInfo) next; | 173 | TAILQ_ENTRY(DriveInfo) next; |
| @@ -190,15 +184,13 @@ extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); | @@ -190,15 +184,13 @@ extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); | ||
| 190 | extern DriveInfo *drive_get_by_id(char *id); | 184 | extern DriveInfo *drive_get_by_id(char *id); |
| 191 | extern int drive_get_max_bus(BlockInterfaceType type); | 185 | extern int drive_get_max_bus(BlockInterfaceType type); |
| 192 | extern void drive_uninit(BlockDriverState *bdrv); | 186 | extern void drive_uninit(BlockDriverState *bdrv); |
| 193 | -extern void drive_remove(DriveOpt *opt); | ||
| 194 | extern const char *drive_get_serial(BlockDriverState *bdrv); | 187 | extern const char *drive_get_serial(BlockDriverState *bdrv); |
| 195 | extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); | 188 | extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); |
| 196 | 189 | ||
| 197 | BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); | 190 | BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); |
| 198 | 191 | ||
| 199 | -extern DriveOpt *drive_add(const char *file, const char *fmt, ...); | ||
| 200 | -extern DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *machine, | ||
| 201 | - int *fatal_error); | 192 | +extern QemuOpts *drive_add(const char *file, const char *fmt, ...); |
| 193 | +extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error); | ||
| 202 | 194 | ||
| 203 | /* acpi */ | 195 | /* acpi */ |
| 204 | typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state); | 196 | typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state); |
vl.c
| @@ -1800,27 +1800,94 @@ static int bt_parse(const char *opt) | @@ -1800,27 +1800,94 @@ static int bt_parse(const char *opt) | ||
| 1800 | #define MTD_ALIAS "if=mtd" | 1800 | #define MTD_ALIAS "if=mtd" |
| 1801 | #define SD_ALIAS "index=0,if=sd" | 1801 | #define SD_ALIAS "index=0,if=sd" |
| 1802 | 1802 | ||
| 1803 | -DriveOpt *drive_add(const char *file, const char *fmt, ...) | 1803 | +static QemuOptsList drive_opt_list = { |
| 1804 | + .name = "drive", | ||
| 1805 | + .head = TAILQ_HEAD_INITIALIZER(drive_opt_list.head), | ||
| 1806 | + .desc = { | ||
| 1807 | + { | ||
| 1808 | + .name = "bus", | ||
| 1809 | + .type = QEMU_OPT_NUMBER, | ||
| 1810 | + .help = "bus number", | ||
| 1811 | + },{ | ||
| 1812 | + .name = "unit", | ||
| 1813 | + .type = QEMU_OPT_NUMBER, | ||
| 1814 | + .help = "unit number (i.e. lun for scsi)", | ||
| 1815 | + },{ | ||
| 1816 | + .name = "if", | ||
| 1817 | + .type = QEMU_OPT_STRING, | ||
| 1818 | + .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | ||
| 1819 | + },{ | ||
| 1820 | + .name = "index", | ||
| 1821 | + .type = QEMU_OPT_NUMBER, | ||
| 1822 | + },{ | ||
| 1823 | + .name = "cyls", | ||
| 1824 | + .type = QEMU_OPT_NUMBER, | ||
| 1825 | + .help = "number of cylinders (ide disk geometry)", | ||
| 1826 | + },{ | ||
| 1827 | + .name = "heads", | ||
| 1828 | + .type = QEMU_OPT_NUMBER, | ||
| 1829 | + .help = "number of heads (ide disk geometry)", | ||
| 1830 | + },{ | ||
| 1831 | + .name = "secs", | ||
| 1832 | + .type = QEMU_OPT_NUMBER, | ||
| 1833 | + .help = "number of sectors (ide disk geometry)", | ||
| 1834 | + },{ | ||
| 1835 | + .name = "trans", | ||
| 1836 | + .type = QEMU_OPT_STRING, | ||
| 1837 | + .help = "chs translation (auto, lba. none)", | ||
| 1838 | + },{ | ||
| 1839 | + .name = "media", | ||
| 1840 | + .type = QEMU_OPT_STRING, | ||
| 1841 | + .help = "media type (disk, cdrom)", | ||
| 1842 | + },{ | ||
| 1843 | + .name = "snapshot", | ||
| 1844 | + .type = QEMU_OPT_BOOL, | ||
| 1845 | + },{ | ||
| 1846 | + .name = "file", | ||
| 1847 | + .type = QEMU_OPT_STRING, | ||
| 1848 | + .help = "disk image", | ||
| 1849 | + },{ | ||
| 1850 | + .name = "cache", | ||
| 1851 | + .type = QEMU_OPT_STRING, | ||
| 1852 | + .help = "host cache usage (none, writeback, writethrough)", | ||
| 1853 | + },{ | ||
| 1854 | + .name = "format", | ||
| 1855 | + .type = QEMU_OPT_STRING, | ||
| 1856 | + .help = "disk format (raw, qcow2, ...)", | ||
| 1857 | + },{ | ||
| 1858 | + .name = "serial", | ||
| 1859 | + .type = QEMU_OPT_STRING, | ||
| 1860 | + },{ | ||
| 1861 | + .name = "werror", | ||
| 1862 | + .type = QEMU_OPT_STRING, | ||
| 1863 | + },{ | ||
| 1864 | + .name = "addr", | ||
| 1865 | + .type = QEMU_OPT_STRING, | ||
| 1866 | + .help = "pci address (virtio only)", | ||
| 1867 | + }, | ||
| 1868 | + { /* end if list */ } | ||
| 1869 | + }, | ||
| 1870 | +}; | ||
| 1871 | + | ||
| 1872 | +QemuOpts *drive_add(const char *file, const char *fmt, ...) | ||
| 1804 | { | 1873 | { |
| 1805 | va_list ap; | 1874 | va_list ap; |
| 1806 | - DriveOpt *dopt; | 1875 | + char optstr[1024]; |
| 1876 | + QemuOpts *opts; | ||
| 1807 | 1877 | ||
| 1808 | - dopt = qemu_mallocz(sizeof(*dopt)); | ||
| 1809 | - | ||
| 1810 | - dopt->file = file; | ||
| 1811 | va_start(ap, fmt); | 1878 | va_start(ap, fmt); |
| 1812 | - vsnprintf(dopt->opt, | ||
| 1813 | - sizeof(dopt->opt), fmt, ap); | 1879 | + vsnprintf(optstr, sizeof(optstr), fmt, ap); |
| 1814 | va_end(ap); | 1880 | va_end(ap); |
| 1815 | 1881 | ||
| 1816 | - TAILQ_INSERT_TAIL(&driveopts, dopt, next); | ||
| 1817 | - return dopt; | ||
| 1818 | -} | ||
| 1819 | - | ||
| 1820 | -void drive_remove(DriveOpt *dopt) | ||
| 1821 | -{ | ||
| 1822 | - TAILQ_REMOVE(&driveopts, dopt, next); | ||
| 1823 | - qemu_free(dopt); | 1882 | + opts = qemu_opts_parse(&drive_opt_list, optstr, NULL); |
| 1883 | + if (!opts) { | ||
| 1884 | + fprintf(stderr, "%s: huh? duplicate? (%s)\n", | ||
| 1885 | + __FUNCTION__, optstr); | ||
| 1886 | + return NULL; | ||
| 1887 | + } | ||
| 1888 | + if (file) | ||
| 1889 | + qemu_opt_set(opts, "file", file); | ||
| 1890 | + return opts; | ||
| 1824 | } | 1891 | } |
| 1825 | 1892 | ||
| 1826 | DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) | 1893 | DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) |
| @@ -1901,20 +1968,20 @@ void drive_uninit(BlockDriverState *bdrv) | @@ -1901,20 +1968,20 @@ void drive_uninit(BlockDriverState *bdrv) | ||
| 1901 | TAILQ_FOREACH(dinfo, &drives, next) { | 1968 | TAILQ_FOREACH(dinfo, &drives, next) { |
| 1902 | if (dinfo->bdrv != bdrv) | 1969 | if (dinfo->bdrv != bdrv) |
| 1903 | continue; | 1970 | continue; |
| 1904 | - drive_remove(dinfo->opt); | 1971 | + qemu_opts_del(dinfo->opts); |
| 1905 | TAILQ_REMOVE(&drives, dinfo, next); | 1972 | TAILQ_REMOVE(&drives, dinfo, next); |
| 1906 | qemu_free(dinfo); | 1973 | qemu_free(dinfo); |
| 1907 | break; | 1974 | break; |
| 1908 | } | 1975 | } |
| 1909 | } | 1976 | } |
| 1910 | 1977 | ||
| 1911 | -DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | 1978 | +DriveInfo *drive_init(QemuOpts *opts, void *opaque, |
| 1912 | int *fatal_error) | 1979 | int *fatal_error) |
| 1913 | { | 1980 | { |
| 1914 | - char buf[128]; | ||
| 1915 | - char file[1024]; | 1981 | + const char *buf; |
| 1982 | + const char *file = NULL; | ||
| 1916 | char devname[128]; | 1983 | char devname[128]; |
| 1917 | - char serial[21]; | 1984 | + const char *serial; |
| 1918 | const char *mediastr = ""; | 1985 | const char *mediastr = ""; |
| 1919 | BlockInterfaceType type; | 1986 | BlockInterfaceType type; |
| 1920 | enum { MEDIA_DISK, MEDIA_CDROM } media; | 1987 | enum { MEDIA_DISK, MEDIA_CDROM } media; |
| @@ -1928,27 +1995,11 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -1928,27 +1995,11 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 1928 | int bdrv_flags, onerror; | 1995 | int bdrv_flags, onerror; |
| 1929 | const char *devaddr; | 1996 | const char *devaddr; |
| 1930 | DriveInfo *dinfo; | 1997 | DriveInfo *dinfo; |
| 1931 | - char *str = arg->opt; | ||
| 1932 | - static const char * const params[] = { "bus", "unit", "if", "index", | ||
| 1933 | - "cyls", "heads", "secs", "trans", | ||
| 1934 | - "media", "snapshot", "file", | ||
| 1935 | - "cache", "format", "serial", | ||
| 1936 | - "werror", "addr", "id", | ||
| 1937 | - NULL }; | ||
| 1938 | - *fatal_error = 1; | 1998 | + int snapshot = 0; |
| 1939 | 1999 | ||
| 1940 | - if (check_params(buf, sizeof(buf), params, str) < 0) { | ||
| 1941 | - fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", | ||
| 1942 | - buf, str); | ||
| 1943 | - return NULL; | ||
| 1944 | - } | 2000 | + *fatal_error = 1; |
| 1945 | 2001 | ||
| 1946 | - file[0] = 0; | ||
| 1947 | - cyls = heads = secs = 0; | ||
| 1948 | - bus_id = 0; | ||
| 1949 | - unit_id = -1; | ||
| 1950 | translation = BIOS_ATA_TRANSLATION_AUTO; | 2002 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 1951 | - index = -1; | ||
| 1952 | cache = 1; | 2003 | cache = 1; |
| 1953 | 2004 | ||
| 1954 | if (machine->use_scsi) { | 2005 | if (machine->use_scsi) { |
| @@ -1963,24 +2014,20 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -1963,24 +2014,20 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 1963 | media = MEDIA_DISK; | 2014 | media = MEDIA_DISK; |
| 1964 | 2015 | ||
| 1965 | /* extract parameters */ | 2016 | /* extract parameters */ |
| 2017 | + bus_id = qemu_opt_get_number(opts, "bus", 0); | ||
| 2018 | + unit_id = qemu_opt_get_number(opts, "unit", -1); | ||
| 2019 | + index = qemu_opt_get_number(opts, "index", -1); | ||
| 1966 | 2020 | ||
| 1967 | - if (get_param_value(buf, sizeof(buf), "bus", str)) { | ||
| 1968 | - bus_id = strtol(buf, NULL, 0); | ||
| 1969 | - if (bus_id < 0) { | ||
| 1970 | - fprintf(stderr, "qemu: '%s' invalid bus id\n", str); | ||
| 1971 | - return NULL; | ||
| 1972 | - } | ||
| 1973 | - } | 2021 | + cyls = qemu_opt_get_number(opts, "cyls", 0); |
| 2022 | + heads = qemu_opt_get_number(opts, "heads", 0); | ||
| 2023 | + secs = qemu_opt_get_number(opts, "secs", 0); | ||
| 1974 | 2024 | ||
| 1975 | - if (get_param_value(buf, sizeof(buf), "unit", str)) { | ||
| 1976 | - unit_id = strtol(buf, NULL, 0); | ||
| 1977 | - if (unit_id < 0) { | ||
| 1978 | - fprintf(stderr, "qemu: '%s' invalid unit id\n", str); | ||
| 1979 | - return NULL; | ||
| 1980 | - } | ||
| 1981 | - } | 2025 | + snapshot = qemu_opt_get_bool(opts, "snapshot", 0); |
| 1982 | 2026 | ||
| 1983 | - if (get_param_value(buf, sizeof(buf), "if", str)) { | 2027 | + file = qemu_opt_get(opts, "file"); |
| 2028 | + serial = qemu_opt_get(opts, "serial"); | ||
| 2029 | + | ||
| 2030 | + if ((buf = qemu_opt_get(opts, "if")) != NULL) { | ||
| 1984 | pstrcpy(devname, sizeof(devname), buf); | 2031 | pstrcpy(devname, sizeof(devname), buf); |
| 1985 | if (!strcmp(buf, "ide")) { | 2032 | if (!strcmp(buf, "ide")) { |
| 1986 | type = IF_IDE; | 2033 | type = IF_IDE; |
| @@ -2007,51 +2054,31 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2007,51 +2054,31 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2007 | type = IF_XEN; | 2054 | type = IF_XEN; |
| 2008 | max_devs = 0; | 2055 | max_devs = 0; |
| 2009 | } else { | 2056 | } else { |
| 2010 | - fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf); | 2057 | + fprintf(stderr, "qemu: unsupported bus type '%s'\n", buf); |
| 2011 | return NULL; | 2058 | return NULL; |
| 2012 | } | 2059 | } |
| 2013 | } | 2060 | } |
| 2014 | 2061 | ||
| 2015 | - if (get_param_value(buf, sizeof(buf), "index", str)) { | ||
| 2016 | - index = strtol(buf, NULL, 0); | ||
| 2017 | - if (index < 0) { | ||
| 2018 | - fprintf(stderr, "qemu: '%s' invalid index\n", str); | ||
| 2019 | - return NULL; | ||
| 2020 | - } | ||
| 2021 | - } | ||
| 2022 | - | ||
| 2023 | - if (get_param_value(buf, sizeof(buf), "cyls", str)) { | ||
| 2024 | - cyls = strtol(buf, NULL, 0); | ||
| 2025 | - } | ||
| 2026 | - | ||
| 2027 | - if (get_param_value(buf, sizeof(buf), "heads", str)) { | ||
| 2028 | - heads = strtol(buf, NULL, 0); | ||
| 2029 | - } | ||
| 2030 | - | ||
| 2031 | - if (get_param_value(buf, sizeof(buf), "secs", str)) { | ||
| 2032 | - secs = strtol(buf, NULL, 0); | ||
| 2033 | - } | ||
| 2034 | - | ||
| 2035 | if (cyls || heads || secs) { | 2062 | if (cyls || heads || secs) { |
| 2036 | if (cyls < 1 || cyls > 16383) { | 2063 | if (cyls < 1 || cyls > 16383) { |
| 2037 | - fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str); | 2064 | + fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", buf); |
| 2038 | return NULL; | 2065 | return NULL; |
| 2039 | } | 2066 | } |
| 2040 | if (heads < 1 || heads > 16) { | 2067 | if (heads < 1 || heads > 16) { |
| 2041 | - fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str); | 2068 | + fprintf(stderr, "qemu: '%s' invalid physical heads number\n", buf); |
| 2042 | return NULL; | 2069 | return NULL; |
| 2043 | } | 2070 | } |
| 2044 | if (secs < 1 || secs > 63) { | 2071 | if (secs < 1 || secs > 63) { |
| 2045 | - fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str); | 2072 | + fprintf(stderr, "qemu: '%s' invalid physical secs number\n", buf); |
| 2046 | return NULL; | 2073 | return NULL; |
| 2047 | } | 2074 | } |
| 2048 | } | 2075 | } |
| 2049 | 2076 | ||
| 2050 | - if (get_param_value(buf, sizeof(buf), "trans", str)) { | 2077 | + if ((buf = qemu_opt_get(opts, "trans")) != NULL) { |
| 2051 | if (!cyls) { | 2078 | if (!cyls) { |
| 2052 | fprintf(stderr, | 2079 | fprintf(stderr, |
| 2053 | "qemu: '%s' trans must be used with cyls,heads and secs\n", | 2080 | "qemu: '%s' trans must be used with cyls,heads and secs\n", |
| 2054 | - str); | 2081 | + buf); |
| 2055 | return NULL; | 2082 | return NULL; |
| 2056 | } | 2083 | } |
| 2057 | if (!strcmp(buf, "none")) | 2084 | if (!strcmp(buf, "none")) |
| @@ -2061,39 +2088,28 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2061,39 +2088,28 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2061 | else if (!strcmp(buf, "auto")) | 2088 | else if (!strcmp(buf, "auto")) |
| 2062 | translation = BIOS_ATA_TRANSLATION_AUTO; | 2089 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2063 | else { | 2090 | else { |
| 2064 | - fprintf(stderr, "qemu: '%s' invalid translation type\n", str); | 2091 | + fprintf(stderr, "qemu: '%s' invalid translation type\n", buf); |
| 2065 | return NULL; | 2092 | return NULL; |
| 2066 | } | 2093 | } |
| 2067 | } | 2094 | } |
| 2068 | 2095 | ||
| 2069 | - if (get_param_value(buf, sizeof(buf), "media", str)) { | 2096 | + if ((buf = qemu_opt_get(opts, "media")) != NULL) { |
| 2070 | if (!strcmp(buf, "disk")) { | 2097 | if (!strcmp(buf, "disk")) { |
| 2071 | media = MEDIA_DISK; | 2098 | media = MEDIA_DISK; |
| 2072 | } else if (!strcmp(buf, "cdrom")) { | 2099 | } else if (!strcmp(buf, "cdrom")) { |
| 2073 | if (cyls || secs || heads) { | 2100 | if (cyls || secs || heads) { |
| 2074 | fprintf(stderr, | 2101 | fprintf(stderr, |
| 2075 | - "qemu: '%s' invalid physical CHS format\n", str); | 2102 | + "qemu: '%s' invalid physical CHS format\n", buf); |
| 2076 | return NULL; | 2103 | return NULL; |
| 2077 | } | 2104 | } |
| 2078 | media = MEDIA_CDROM; | 2105 | media = MEDIA_CDROM; |
| 2079 | } else { | 2106 | } else { |
| 2080 | - fprintf(stderr, "qemu: '%s' invalid media\n", str); | ||
| 2081 | - return NULL; | ||
| 2082 | - } | ||
| 2083 | - } | ||
| 2084 | - | ||
| 2085 | - if (get_param_value(buf, sizeof(buf), "snapshot", str)) { | ||
| 2086 | - if (!strcmp(buf, "on")) | ||
| 2087 | - snapshot = 1; | ||
| 2088 | - else if (!strcmp(buf, "off")) | ||
| 2089 | - snapshot = 0; | ||
| 2090 | - else { | ||
| 2091 | - fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str); | 2107 | + fprintf(stderr, "qemu: '%s' invalid media\n", buf); |
| 2092 | return NULL; | 2108 | return NULL; |
| 2093 | } | 2109 | } |
| 2094 | } | 2110 | } |
| 2095 | 2111 | ||
| 2096 | - if (get_param_value(buf, sizeof(buf), "cache", str)) { | 2112 | + if ((buf = qemu_opt_get(opts, "cache")) != NULL) { |
| 2097 | if (!strcmp(buf, "off") || !strcmp(buf, "none")) | 2113 | if (!strcmp(buf, "off") || !strcmp(buf, "none")) |
| 2098 | cache = 0; | 2114 | cache = 0; |
| 2099 | else if (!strcmp(buf, "writethrough")) | 2115 | else if (!strcmp(buf, "writethrough")) |
| @@ -2106,7 +2122,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2106,7 +2122,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2106 | } | 2122 | } |
| 2107 | } | 2123 | } |
| 2108 | 2124 | ||
| 2109 | - if (get_param_value(buf, sizeof(buf), "format", str)) { | 2125 | + if ((buf = qemu_opt_get(opts, "format")) != NULL) { |
| 2110 | if (strcmp(buf, "?") == 0) { | 2126 | if (strcmp(buf, "?") == 0) { |
| 2111 | fprintf(stderr, "qemu: Supported formats:"); | 2127 | fprintf(stderr, "qemu: Supported formats:"); |
| 2112 | bdrv_iterate_format(bdrv_format_print, NULL); | 2128 | bdrv_iterate_format(bdrv_format_print, NULL); |
| @@ -2120,16 +2136,8 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2120,16 +2136,8 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2120 | } | 2136 | } |
| 2121 | } | 2137 | } |
| 2122 | 2138 | ||
| 2123 | - if (arg->file == NULL) | ||
| 2124 | - get_param_value(file, sizeof(file), "file", str); | ||
| 2125 | - else | ||
| 2126 | - pstrcpy(file, sizeof(file), arg->file); | ||
| 2127 | - | ||
| 2128 | - if (!get_param_value(serial, sizeof(serial), "serial", str)) | ||
| 2129 | - memset(serial, 0, sizeof(serial)); | ||
| 2130 | - | ||
| 2131 | onerror = BLOCK_ERR_STOP_ENOSPC; | 2139 | onerror = BLOCK_ERR_STOP_ENOSPC; |
| 2132 | - if (get_param_value(buf, sizeof(serial), "werror", str)) { | 2140 | + if ((buf = qemu_opt_get(opts, "werror")) != NULL) { |
| 2133 | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { | 2141 | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { |
| 2134 | fprintf(stderr, "werror is no supported by this format\n"); | 2142 | fprintf(stderr, "werror is no supported by this format\n"); |
| 2135 | return NULL; | 2143 | return NULL; |
| @@ -2148,13 +2156,11 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2148,13 +2156,11 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2148 | } | 2156 | } |
| 2149 | } | 2157 | } |
| 2150 | 2158 | ||
| 2151 | - devaddr = NULL; | ||
| 2152 | - if (get_param_value(buf, sizeof(buf), "addr", str)) { | 2159 | + if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) { |
| 2153 | if (type != IF_VIRTIO) { | 2160 | if (type != IF_VIRTIO) { |
| 2154 | - fprintf(stderr, "addr is not supported by in '%s'\n", str); | 2161 | + fprintf(stderr, "addr is not supported\n"); |
| 2155 | return NULL; | 2162 | return NULL; |
| 2156 | } | 2163 | } |
| 2157 | - devaddr = strdup(buf); | ||
| 2158 | } | 2164 | } |
| 2159 | 2165 | ||
| 2160 | /* compute bus and unit according index */ | 2166 | /* compute bus and unit according index */ |
| @@ -2162,7 +2168,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2162,7 +2168,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2162 | if (index != -1) { | 2168 | if (index != -1) { |
| 2163 | if (bus_id != 0 || unit_id != -1) { | 2169 | if (bus_id != 0 || unit_id != -1) { |
| 2164 | fprintf(stderr, | 2170 | fprintf(stderr, |
| 2165 | - "qemu: '%s' index cannot be used with bus and unit\n", str); | 2171 | + "qemu: index cannot be used with bus and unit\n"); |
| 2166 | return NULL; | 2172 | return NULL; |
| 2167 | } | 2173 | } |
| 2168 | if (max_devs == 0) | 2174 | if (max_devs == 0) |
| @@ -2193,8 +2199,8 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2193,8 +2199,8 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2193 | /* check unit id */ | 2199 | /* check unit id */ |
| 2194 | 2200 | ||
| 2195 | if (max_devs && unit_id >= max_devs) { | 2201 | if (max_devs && unit_id >= max_devs) { |
| 2196 | - fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n", | ||
| 2197 | - str, unit_id, max_devs - 1); | 2202 | + fprintf(stderr, "qemu: unit %d too big (max is %d)\n", |
| 2203 | + unit_id, max_devs - 1); | ||
| 2198 | return NULL; | 2204 | return NULL; |
| 2199 | } | 2205 | } |
| 2200 | 2206 | ||
| @@ -2210,26 +2216,29 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2210,26 +2216,29 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2210 | /* init */ | 2216 | /* init */ |
| 2211 | 2217 | ||
| 2212 | dinfo = qemu_mallocz(sizeof(*dinfo)); | 2218 | dinfo = qemu_mallocz(sizeof(*dinfo)); |
| 2213 | - if (!get_param_value(buf, sizeof(buf), "id", str)) { | 2219 | + if ((buf = qemu_opt_get(opts, "id")) != NULL) { |
| 2220 | + dinfo->id = qemu_strdup(buf); | ||
| 2221 | + } else { | ||
| 2214 | /* no id supplied -> create one */ | 2222 | /* no id supplied -> create one */ |
| 2223 | + dinfo->id = qemu_mallocz(32); | ||
| 2215 | if (type == IF_IDE || type == IF_SCSI) | 2224 | if (type == IF_IDE || type == IF_SCSI) |
| 2216 | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; | 2225 | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; |
| 2217 | if (max_devs) | 2226 | if (max_devs) |
| 2218 | - snprintf(buf, sizeof(buf), "%s%i%s%i", | 2227 | + snprintf(dinfo->id, 32, "%s%i%s%i", |
| 2219 | devname, bus_id, mediastr, unit_id); | 2228 | devname, bus_id, mediastr, unit_id); |
| 2220 | else | 2229 | else |
| 2221 | - snprintf(buf, sizeof(buf), "%s%s%i", | 2230 | + snprintf(dinfo->id, 32, "%s%s%i", |
| 2222 | devname, mediastr, unit_id); | 2231 | devname, mediastr, unit_id); |
| 2223 | } | 2232 | } |
| 2224 | - dinfo->id = qemu_strdup(buf); | ||
| 2225 | dinfo->bdrv = bdrv_new(dinfo->id); | 2233 | dinfo->bdrv = bdrv_new(dinfo->id); |
| 2226 | dinfo->devaddr = devaddr; | 2234 | dinfo->devaddr = devaddr; |
| 2227 | dinfo->type = type; | 2235 | dinfo->type = type; |
| 2228 | dinfo->bus = bus_id; | 2236 | dinfo->bus = bus_id; |
| 2229 | dinfo->unit = unit_id; | 2237 | dinfo->unit = unit_id; |
| 2230 | dinfo->onerror = onerror; | 2238 | dinfo->onerror = onerror; |
| 2231 | - dinfo->opt = arg; | ||
| 2232 | - strncpy(dinfo->serial, serial, sizeof(serial)); | 2239 | + dinfo->opts = opts; |
| 2240 | + if (serial) | ||
| 2241 | + strncpy(dinfo->serial, serial, sizeof(serial)); | ||
| 2233 | TAILQ_INSERT_TAIL(&drives, dinfo, next); | 2242 | TAILQ_INSERT_TAIL(&drives, dinfo, next); |
| 2234 | 2243 | ||
| 2235 | switch(type) { | 2244 | switch(type) { |
| @@ -2261,7 +2270,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2261,7 +2270,7 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2261 | case IF_COUNT: | 2270 | case IF_COUNT: |
| 2262 | abort(); | 2271 | abort(); |
| 2263 | } | 2272 | } |
| 2264 | - if (!file[0]) { | 2273 | + if (!file) { |
| 2265 | *fatal_error = 0; | 2274 | *fatal_error = 0; |
| 2266 | return NULL; | 2275 | return NULL; |
| 2267 | } | 2276 | } |
| @@ -2285,6 +2294,26 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | @@ -2285,6 +2294,26 @@ DriveInfo *drive_init(DriveOpt *arg, int snapshot, void *opaque, | ||
| 2285 | return dinfo; | 2294 | return dinfo; |
| 2286 | } | 2295 | } |
| 2287 | 2296 | ||
| 2297 | +static int drive_init_func(QemuOpts *opts, void *opaque) | ||
| 2298 | +{ | ||
| 2299 | + QEMUMachine *machine = opaque; | ||
| 2300 | + int fatal_error = 0; | ||
| 2301 | + | ||
| 2302 | + if (drive_init(opts, machine, &fatal_error) == NULL) { | ||
| 2303 | + if (fatal_error) | ||
| 2304 | + return 1; | ||
| 2305 | + } | ||
| 2306 | + return 0; | ||
| 2307 | +} | ||
| 2308 | + | ||
| 2309 | +static int drive_enable_snapshot(QemuOpts *opts, void *opaque) | ||
| 2310 | +{ | ||
| 2311 | + if (NULL == qemu_opt_get(opts, "snapshot")) { | ||
| 2312 | + qemu_opt_set(opts, "snapshot", "on"); | ||
| 2313 | + } | ||
| 2314 | + return 0; | ||
| 2315 | +} | ||
| 2316 | + | ||
| 2288 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) | 2317 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
| 2289 | { | 2318 | { |
| 2290 | boot_set_handler = func; | 2319 | boot_set_handler = func; |
| @@ -4815,7 +4844,7 @@ int main(int argc, char **argv, char **envp) | @@ -4815,7 +4844,7 @@ int main(int argc, char **argv, char **envp) | ||
| 4815 | int cyls, heads, secs, translation; | 4844 | int cyls, heads, secs, translation; |
| 4816 | const char *net_clients[MAX_NET_CLIENTS]; | 4845 | const char *net_clients[MAX_NET_CLIENTS]; |
| 4817 | int nb_net_clients; | 4846 | int nb_net_clients; |
| 4818 | - DriveOpt *dopt, *hda_opt = NULL; | 4847 | + QemuOpts *hda_opts = NULL; |
| 4819 | int optind; | 4848 | int optind; |
| 4820 | const char *r, *optarg; | 4849 | const char *r, *optarg; |
| 4821 | CharDriverState *monitor_hd = NULL; | 4850 | CharDriverState *monitor_hd = NULL; |
| @@ -4923,7 +4952,7 @@ int main(int argc, char **argv, char **envp) | @@ -4923,7 +4952,7 @@ int main(int argc, char **argv, char **envp) | ||
| 4923 | break; | 4952 | break; |
| 4924 | r = argv[optind]; | 4953 | r = argv[optind]; |
| 4925 | if (r[0] != '-') { | 4954 | if (r[0] != '-') { |
| 4926 | - hda_opt = drive_add(argv[optind++], HD_ALIAS, 0); | 4955 | + hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); |
| 4927 | } else { | 4956 | } else { |
| 4928 | const QEMUOption *popt; | 4957 | const QEMUOption *popt; |
| 4929 | 4958 | ||
| @@ -4987,9 +5016,9 @@ int main(int argc, char **argv, char **envp) | @@ -4987,9 +5016,9 @@ int main(int argc, char **argv, char **envp) | ||
| 4987 | break; | 5016 | break; |
| 4988 | case QEMU_OPTION_hda: | 5017 | case QEMU_OPTION_hda: |
| 4989 | if (cyls == 0) | 5018 | if (cyls == 0) |
| 4990 | - hda_opt = drive_add(optarg, HD_ALIAS, 0); | 5019 | + hda_opts = drive_add(optarg, HD_ALIAS, 0); |
| 4991 | else | 5020 | else |
| 4992 | - hda_opt = drive_add(optarg, HD_ALIAS | 5021 | + hda_opts = drive_add(optarg, HD_ALIAS |
| 4993 | ",cyls=%d,heads=%d,secs=%d%s", | 5022 | ",cyls=%d,heads=%d,secs=%d%s", |
| 4994 | 0, cyls, heads, secs, | 5023 | 0, cyls, heads, secs, |
| 4995 | translation == BIOS_ATA_TRANSLATION_LBA ? | 5024 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| @@ -5051,15 +5080,19 @@ int main(int argc, char **argv, char **envp) | @@ -5051,15 +5080,19 @@ int main(int argc, char **argv, char **envp) | ||
| 5051 | fprintf(stderr, "qemu: invalid physical CHS format\n"); | 5080 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
| 5052 | exit(1); | 5081 | exit(1); |
| 5053 | } | 5082 | } |
| 5054 | - if (hda_opt != NULL) | ||
| 5055 | - snprintf(hda_opt->opt, | ||
| 5056 | - sizeof(hda_opt->opt), | ||
| 5057 | - HD_ALIAS ",cyls=%d,heads=%d,secs=%d%s", | ||
| 5058 | - 0, cyls, heads, secs, | ||
| 5059 | - translation == BIOS_ATA_TRANSLATION_LBA ? | ||
| 5060 | - ",trans=lba" : | ||
| 5061 | - translation == BIOS_ATA_TRANSLATION_NONE ? | ||
| 5062 | - ",trans=none" : ""); | 5083 | + if (hda_opts != NULL) { |
| 5084 | + char num[16]; | ||
| 5085 | + snprintf(num, sizeof(num), "%d", cyls); | ||
| 5086 | + qemu_opt_set(hda_opts, "cyls", num); | ||
| 5087 | + snprintf(num, sizeof(num), "%d", heads); | ||
| 5088 | + qemu_opt_set(hda_opts, "heads", num); | ||
| 5089 | + snprintf(num, sizeof(num), "%d", secs); | ||
| 5090 | + qemu_opt_set(hda_opts, "secs", num); | ||
| 5091 | + if (translation == BIOS_ATA_TRANSLATION_LBA) | ||
| 5092 | + qemu_opt_set(hda_opts, "trans", "lba"); | ||
| 5093 | + if (translation == BIOS_ATA_TRANSLATION_NONE) | ||
| 5094 | + qemu_opt_set(hda_opts, "trans", "none"); | ||
| 5095 | + } | ||
| 5063 | } | 5096 | } |
| 5064 | break; | 5097 | break; |
| 5065 | case QEMU_OPTION_numa: | 5098 | case QEMU_OPTION_numa: |
| @@ -5771,13 +5804,10 @@ int main(int argc, char **argv, char **envp) | @@ -5771,13 +5804,10 @@ int main(int argc, char **argv, char **envp) | ||
| 5771 | drive_add(NULL, SD_ALIAS); | 5804 | drive_add(NULL, SD_ALIAS); |
| 5772 | 5805 | ||
| 5773 | /* open the virtual block devices */ | 5806 | /* open the virtual block devices */ |
| 5774 | - | ||
| 5775 | - TAILQ_FOREACH(dopt, &driveopts, next) { | ||
| 5776 | - int fatal_error; | ||
| 5777 | - if (drive_init(dopt, snapshot, machine, &fatal_error) == NULL) | ||
| 5778 | - if (fatal_error) | ||
| 5779 | - exit(1); | ||
| 5780 | - } | 5807 | + if (snapshot) |
| 5808 | + qemu_opts_foreach(&drive_opt_list, drive_enable_snapshot, NULL, 0); | ||
| 5809 | + if (qemu_opts_foreach(&drive_opt_list, drive_init_func, machine, 1) != 0) | ||
| 5810 | + exit(1); | ||
| 5781 | 5811 | ||
| 5782 | register_savevm("timer", 0, 2, timer_save, timer_load, NULL); | 5812 | register_savevm("timer", 0, 2, timer_save, timer_load, NULL); |
| 5783 | register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL); | 5813 | register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL); |