Revision 751c6a17 vl.c

b/vl.c
180 180
const char *bios_name = NULL;
181 181
/* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
182 182
   to store the VM snapshots */
183
DriveInfo drives_table[MAX_DRIVES+1];
184
int nb_drives;
183
struct drivelist drives = TAILQ_HEAD_INITIALIZER(drives);
185 184
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
186 185
static DisplayState *display_state;
187 186
DisplayType display_type = DT_DEFAULT;
......
1879 1878
    return -1;
1880 1879
}
1881 1880

  
1882
static int drive_get_free_idx(void)
1883
{
1884
    int index;
1885

  
1886
    for (index = 0; index < MAX_DRIVES; index++)
1887
        if (!drives_table[index].used) {
1888
            drives_table[index].used = 1;
1889
            return index;
1890
        }
1891

  
1892
    return -1;
1893
}
1894

  
1895 1881
int drive_add(const char *file, const char *fmt, ...)
1896 1882
{
1897 1883
    va_list ap;
......
1918 1904
    nb_drives_opt--;
1919 1905
}
1920 1906

  
1921
int drive_get_index(BlockInterfaceType type, int bus, int unit)
1907
DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
1922 1908
{
1923
    int index;
1909
    DriveInfo *dinfo;
1924 1910

  
1925 1911
    /* seek interface, bus and unit */
1926 1912

  
1927
    for (index = 0; index < MAX_DRIVES; index++)
1928
        if (drives_table[index].type == type &&
1929
	    drives_table[index].bus == bus &&
1930
	    drives_table[index].unit == unit &&
1931
	    drives_table[index].used)
1932
        return index;
1913
    TAILQ_FOREACH(dinfo, &drives, next) {
1914
        if (dinfo->type == type &&
1915
	    dinfo->bus == bus &&
1916
	    dinfo->unit == unit)
1917
            return dinfo;
1918
    }
1933 1919

  
1934
    return -1;
1920
    return NULL;
1935 1921
}
1936 1922

  
1937 1923
int drive_get_max_bus(BlockInterfaceType type)
1938 1924
{
1939 1925
    int max_bus;
1940
    int index;
1926
    DriveInfo *dinfo;
1941 1927

  
1942 1928
    max_bus = -1;
1943
    for (index = 0; index < nb_drives; index++) {
1944
        if(drives_table[index].type == type &&
1945
           drives_table[index].bus > max_bus)
1946
            max_bus = drives_table[index].bus;
1929
    TAILQ_FOREACH(dinfo, &drives, next) {
1930
        if(dinfo->type == type &&
1931
           dinfo->bus > max_bus)
1932
            max_bus = dinfo->bus;
1947 1933
    }
1948 1934
    return max_bus;
1949 1935
}
1950 1936

  
1951 1937
const char *drive_get_serial(BlockDriverState *bdrv)
1952 1938
{
1953
    int index;
1939
    DriveInfo *dinfo;
1954 1940

  
1955
    for (index = 0; index < nb_drives; index++)
1956
        if (drives_table[index].bdrv == bdrv)
1957
            return drives_table[index].serial;
1941
    TAILQ_FOREACH(dinfo, &drives, next) {
1942
        if (dinfo->bdrv == bdrv)
1943
            return dinfo->serial;
1944
    }
1958 1945

  
1959 1946
    return "\0";
1960 1947
}
1961 1948

  
1962 1949
BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv)
1963 1950
{
1964
    int index;
1951
    DriveInfo *dinfo;
1965 1952

  
1966
    for (index = 0; index < nb_drives; index++)
1967
        if (drives_table[index].bdrv == bdrv)
1968
            return drives_table[index].onerror;
1953
    TAILQ_FOREACH(dinfo, &drives, next) {
1954
        if (dinfo->bdrv == bdrv)
1955
            return dinfo->onerror;
1956
    }
1969 1957

  
1970 1958
    return BLOCK_ERR_STOP_ENOSPC;
1971 1959
}
......
1977 1965

  
1978 1966
void drive_uninit(BlockDriverState *bdrv)
1979 1967
{
1980
    int i;
1968
    DriveInfo *dinfo;
1981 1969

  
1982
    for (i = 0; i < MAX_DRIVES; i++)
1983
        if (drives_table[i].bdrv == bdrv) {
1984
            drives_table[i].bdrv = NULL;
1985
            drives_table[i].used = 0;
1986
            drive_remove(drives_table[i].drive_opt_idx);
1987
            nb_drives--;
1988
            break;
1989
        }
1970
    TAILQ_FOREACH(dinfo, &drives, next) {
1971
        if (dinfo->bdrv != bdrv)
1972
            continue;
1973
        drive_remove(dinfo->drive_opt_idx);
1974
        TAILQ_REMOVE(&drives, dinfo, next);
1975
        qemu_free(dinfo);
1976
        break;
1977
    }
1990 1978
}
1991 1979

  
1992
int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
1980
DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
1981
                      int *fatal_error)
1993 1982
{
1994 1983
    char buf[128];
1995 1984
    char file[1024];
......
2008 1997
    int cache;
2009 1998
    int bdrv_flags, onerror;
2010 1999
    const char *devaddr;
2011
    int drives_table_idx;
2000
    DriveInfo *dinfo;
2012 2001
    char *str = arg->opt;
2013 2002
    static const char * const params[] = { "bus", "unit", "if", "index",
2014 2003
                                           "cyls", "heads", "secs", "trans",
......
2016 2005
                                           "cache", "format", "serial",
2017 2006
                                           "werror", "addr",
2018 2007
                                           NULL };
2008
    *fatal_error = 1;
2019 2009

  
2020 2010
    if (check_params(buf, sizeof(buf), params, str) < 0) {
2021 2011
         fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n",
2022 2012
                         buf, str);
2023
         return -1;
2013
         return NULL;
2024 2014
    }
2025 2015

  
2026 2016
    file[0] = 0;
......
2048 2038
        bus_id = strtol(buf, NULL, 0);
2049 2039
	if (bus_id < 0) {
2050 2040
	    fprintf(stderr, "qemu: '%s' invalid bus id\n", str);
2051
	    return -1;
2041
	    return NULL;
2052 2042
	}
2053 2043
    }
2054 2044

  
......
2056 2046
        unit_id = strtol(buf, NULL, 0);
2057 2047
	if (unit_id < 0) {
2058 2048
	    fprintf(stderr, "qemu: '%s' invalid unit id\n", str);
2059
	    return -1;
2049
	    return NULL;
2060 2050
	}
2061 2051
    }
2062 2052

  
......
2088 2078
            max_devs = 0;
2089 2079
	} else {
2090 2080
            fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf);
2091
            return -1;
2081
            return NULL;
2092 2082
	}
2093 2083
    }
2094 2084

  
......
2096 2086
        index = strtol(buf, NULL, 0);
2097 2087
	if (index < 0) {
2098 2088
	    fprintf(stderr, "qemu: '%s' invalid index\n", str);
2099
	    return -1;
2089
	    return NULL;
2100 2090
	}
2101 2091
    }
2102 2092

  
......
2115 2105
    if (cyls || heads || secs) {
2116 2106
        if (cyls < 1 || cyls > 16383) {
2117 2107
            fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str);
2118
	    return -1;
2108
	    return NULL;
2119 2109
	}
2120 2110
        if (heads < 1 || heads > 16) {
2121 2111
            fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str);
2122
	    return -1;
2112
	    return NULL;
2123 2113
	}
2124 2114
        if (secs < 1 || secs > 63) {
2125 2115
            fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str);
2126
	    return -1;
2116
	    return NULL;
2127 2117
	}
2128 2118
    }
2129 2119

  
......
2132 2122
            fprintf(stderr,
2133 2123
                    "qemu: '%s' trans must be used with cyls,heads and secs\n",
2134 2124
                    str);
2135
            return -1;
2125
            return NULL;
2136 2126
        }
2137 2127
        if (!strcmp(buf, "none"))
2138 2128
            translation = BIOS_ATA_TRANSLATION_NONE;
......
2142 2132
            translation = BIOS_ATA_TRANSLATION_AUTO;
2143 2133
	else {
2144 2134
            fprintf(stderr, "qemu: '%s' invalid translation type\n", str);
2145
	    return -1;
2135
	    return NULL;
2146 2136
	}
2147 2137
    }
2148 2138

  
......
2153 2143
            if (cyls || secs || heads) {
2154 2144
                fprintf(stderr,
2155 2145
                        "qemu: '%s' invalid physical CHS format\n", str);
2156
	        return -1;
2146
	        return NULL;
2157 2147
            }
2158 2148
	    media = MEDIA_CDROM;
2159 2149
	} else {
2160 2150
	    fprintf(stderr, "qemu: '%s' invalid media\n", str);
2161
	    return -1;
2151
	    return NULL;
2162 2152
	}
2163 2153
    }
2164 2154

  
......
2169 2159
	    snapshot = 0;
2170 2160
	else {
2171 2161
	    fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str);
2172
	    return -1;
2162
	    return NULL;
2173 2163
	}
2174 2164
    }
2175 2165

  
......
2182 2172
            cache = 2;
2183 2173
        else {
2184 2174
           fprintf(stderr, "qemu: invalid cache option\n");
2185
           return -1;
2175
           return NULL;
2186 2176
        }
2187 2177
    }
2188 2178

  
......
2191 2181
            fprintf(stderr, "qemu: Supported formats:");
2192 2182
            bdrv_iterate_format(bdrv_format_print, NULL);
2193 2183
            fprintf(stderr, "\n");
2194
	    return -1;
2184
	    return NULL;
2195 2185
        }
2196 2186
        drv = bdrv_find_format(buf);
2197 2187
        if (!drv) {
2198 2188
            fprintf(stderr, "qemu: '%s' invalid format\n", buf);
2199
            return -1;
2189
            return NULL;
2200 2190
        }
2201 2191
    }
2202 2192

  
......
2212 2202
    if (get_param_value(buf, sizeof(serial), "werror", str)) {
2213 2203
        if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
2214 2204
            fprintf(stderr, "werror is no supported by this format\n");
2215
            return -1;
2205
            return NULL;
2216 2206
        }
2217 2207
        if (!strcmp(buf, "ignore"))
2218 2208
            onerror = BLOCK_ERR_IGNORE;
......
2224 2214
            onerror = BLOCK_ERR_REPORT;
2225 2215
        else {
2226 2216
            fprintf(stderr, "qemu: '%s' invalid write error action\n", buf);
2227
            return -1;
2217
            return NULL;
2228 2218
        }
2229 2219
    }
2230 2220

  
......
2232 2222
    if (get_param_value(buf, sizeof(buf), "addr", str)) {
2233 2223
        if (type != IF_VIRTIO) {
2234 2224
            fprintf(stderr, "addr is not supported by in '%s'\n", str);
2235
            return -1;
2225
            return NULL;
2236 2226
        }
2237 2227
        devaddr = strdup(buf);
2238 2228
    }
......
2243 2233
        if (bus_id != 0 || unit_id != -1) {
2244 2234
            fprintf(stderr,
2245 2235
                    "qemu: '%s' index cannot be used with bus and unit\n", str);
2246
            return -1;
2236
            return NULL;
2247 2237
        }
2248 2238
        if (max_devs == 0)
2249 2239
        {
......
2261 2251

  
2262 2252
    if (unit_id == -1) {
2263 2253
       unit_id = 0;
2264
       while (drive_get_index(type, bus_id, unit_id) != -1) {
2254
       while (drive_get(type, bus_id, unit_id) != NULL) {
2265 2255
           unit_id++;
2266 2256
           if (max_devs && unit_id >= max_devs) {
2267 2257
               unit_id -= max_devs;
......
2275 2265
    if (max_devs && unit_id >= max_devs) {
2276 2266
        fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n",
2277 2267
                        str, unit_id, max_devs - 1);
2278
        return -1;
2268
        return NULL;
2279 2269
    }
2280 2270

  
2281 2271
    /*
2282 2272
     * ignore multiple definitions
2283 2273
     */
2284 2274

  
2285
    if (drive_get_index(type, bus_id, unit_id) != -1)
2286
        return -2;
2275
    if (drive_get(type, bus_id, unit_id) != NULL) {
2276
        *fatal_error = 0;
2277
        return NULL;
2278
    }
2287 2279

  
2288 2280
    /* init */
2289 2281

  
......
2296 2288
        snprintf(buf, sizeof(buf), "%s%s%i",
2297 2289
                 devname, mediastr, unit_id);
2298 2290
    bdrv = bdrv_new(buf);
2299
    drives_table_idx = drive_get_free_idx();
2300
    drives_table[drives_table_idx].bdrv = bdrv;
2301
    drives_table[drives_table_idx].devaddr = devaddr;
2302
    drives_table[drives_table_idx].type = type;
2303
    drives_table[drives_table_idx].bus = bus_id;
2304
    drives_table[drives_table_idx].unit = unit_id;
2305
    drives_table[drives_table_idx].onerror = onerror;
2306
    drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt;
2307
    strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial));
2308
    nb_drives++;
2291
    dinfo = qemu_mallocz(sizeof(*dinfo));
2292
    dinfo->bdrv = bdrv;
2293
    dinfo->devaddr = devaddr;
2294
    dinfo->type = type;
2295
    dinfo->bus = bus_id;
2296
    dinfo->unit = unit_id;
2297
    dinfo->onerror = onerror;
2298
    dinfo->drive_opt_idx = arg - drives_opt;
2299
    strncpy(dinfo->serial, serial, sizeof(serial));
2300
    TAILQ_INSERT_TAIL(&drives, dinfo, next);
2309 2301

  
2310 2302
    switch(type) {
2311 2303
    case IF_IDE:
......
2336 2328
    case IF_COUNT:
2337 2329
        abort();
2338 2330
    }
2339
    if (!file[0])
2340
        return -2;
2331
    if (!file[0]) {
2332
        *fatal_error = 0;
2333
        return NULL;
2334
    }
2341 2335
    bdrv_flags = 0;
2342 2336
    if (snapshot) {
2343 2337
        bdrv_flags |= BDRV_O_SNAPSHOT;
......
2350 2344
    if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
2351 2345
        fprintf(stderr, "qemu: could not open disk image %s\n",
2352 2346
                        file);
2353
        return -1;
2347
        return NULL;
2354 2348
    }
2355 2349
    if (bdrv_key_required(bdrv))
2356 2350
        autostart = 0;
2357
    return drives_table_idx;
2351
    *fatal_error = 0;
2352
    return dinfo;
2358 2353
}
2359 2354

  
2360 2355
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
......
4981 4976
    }
4982 4977

  
4983 4978
    nb_net_clients = 0;
4984
    nb_drives = 0;
4985 4979
    nb_drives_opt = 0;
4986 4980
    nb_numa_nodes = 0;
4987 4981
    hda_index = -1;
......
5854 5848

  
5855 5849
    /* open the virtual block devices */
5856 5850

  
5857
    for(i = 0; i < nb_drives_opt; i++)
5858
        if (drive_init(&drives_opt[i], snapshot, machine) == -1)
5859
	    exit(1);
5851
    for(i = 0; i < nb_drives_opt; i++) {
5852
        int fatal_error;
5853
        if (drive_init(&drives_opt[i], snapshot, machine, &fatal_error) == NULL)
5854
            if (fatal_error)
5855
                exit(1);
5856
    }
5860 5857

  
5861 5858
    register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
5862 5859
    register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);

Also available in: Unified diff