Revision f0aa7a8b

b/monitor.c
2274 2274

  
2275 2275
    vm_stop(0);
2276 2276

  
2277
    if (load_vmstate(name) >= 0 && saved_vm_running)
2277
    if (load_vmstate(name) == 0 && saved_vm_running) {
2278 2278
        vm_start();
2279
    }
2279 2280
}
2280 2281

  
2281 2282
int monitor_get_fd(Monitor *mon, const char *fdname)
b/savevm.c
1894 1894

  
1895 1895
int load_vmstate(const char *name)
1896 1896
{
1897
    BlockDriverState *bs, *bs1;
1897
    BlockDriverState *bs, *bs_vm_state;
1898 1898
    QEMUSnapshotInfo sn;
1899 1899
    QEMUFile *f;
1900 1900
    int ret;
1901 1901

  
1902
    /* Verify if there is a device that doesn't support snapshots and is writable */
1902
    bs_vm_state = bdrv_snapshots();
1903
    if (!bs_vm_state) {
1904
        error_report("No block device supports snapshots");
1905
        return -ENOTSUP;
1906
    }
1907

  
1908
    /* Don't even try to load empty VM states */
1909
    ret = bdrv_snapshot_find(bs_vm_state, &sn, name);
1910
    if (ret < 0) {
1911
        return ret;
1912
    } else if (sn.vm_state_size == 0) {
1913
        return -EINVAL;
1914
    }
1915

  
1916
    /* Verify if there is any device that doesn't support snapshots and is
1917
    writable and check if the requested snapshot is available too. */
1903 1918
    bs = NULL;
1904 1919
    while ((bs = bdrv_next(bs))) {
1905 1920

  
......
1912 1927
                               bdrv_get_device_name(bs));
1913 1928
            return -ENOTSUP;
1914 1929
        }
1915
    }
1916 1930

  
1917
    bs = bdrv_snapshots();
1918
    if (!bs) {
1919
        error_report("No block device supports snapshots");
1920
        return -EINVAL;
1931
        ret = bdrv_snapshot_find(bs, &sn, name);
1932
        if (ret < 0) {
1933
            error_report("Device '%s' does not have the requested snapshot '%s'",
1934
                           bdrv_get_device_name(bs), name);
1935
            return ret;
1936
        }
1921 1937
    }
1922 1938

  
1923 1939
    /* Flush all IO requests so they don't interfere with the new state.  */
1924 1940
    qemu_aio_flush();
1925 1941

  
1926
    bs1 = NULL;
1927
    while ((bs1 = bdrv_next(bs1))) {
1928
        if (bdrv_can_snapshot(bs1)) {
1929
            ret = bdrv_snapshot_goto(bs1, name);
1942
    bs = NULL;
1943
    while ((bs = bdrv_next(bs))) {
1944
        if (bdrv_can_snapshot(bs)) {
1945
            ret = bdrv_snapshot_goto(bs, name);
1930 1946
            if (ret < 0) {
1931
                switch(ret) {
1932
                case -ENOTSUP:
1933
                    error_report("%sSnapshots not supported on device '%s'",
1934
                                 bs != bs1 ? "Warning: " : "",
1935
                                 bdrv_get_device_name(bs1));
1936
                    break;
1937
                case -ENOENT:
1938
                    error_report("%sCould not find snapshot '%s' on device '%s'",
1939
                                 bs != bs1 ? "Warning: " : "",
1940
                                 name, bdrv_get_device_name(bs1));
1941
                    break;
1942
                default:
1943
                    error_report("%sError %d while activating snapshot on '%s'",
1944
                                 bs != bs1 ? "Warning: " : "",
1945
                                 ret, bdrv_get_device_name(bs1));
1946
                    break;
1947
                }
1948
                /* fatal on snapshot block device */
1949
                if (bs == bs1)
1950
                    return 0;
1947
                error_report("Error %d while activating snapshot '%s' on '%s'",
1948
                             ret, name, bdrv_get_device_name(bs));
1949
                return ret;
1951 1950
            }
1952 1951
        }
1953 1952
    }
1954 1953

  
1955
    /* Don't even try to load empty VM states */
1956
    ret = bdrv_snapshot_find(bs, &sn, name);
1957
    if ((ret >= 0) && (sn.vm_state_size == 0))
1958
        return -EINVAL;
1959

  
1960 1954
    /* restore the VM state */
1961
    f = qemu_fopen_bdrv(bs, 0);
1955
    f = qemu_fopen_bdrv(bs_vm_state, 0);
1962 1956
    if (!f) {
1963 1957
        error_report("Could not open VM state file");
1964 1958
        return -EINVAL;
1965 1959
    }
1960

  
1966 1961
    ret = qemu_loadvm_state(f);
1962

  
1967 1963
    qemu_fclose(f);
1968 1964
    if (ret < 0) {
1969 1965
        error_report("Error %d while loading VM state", ret);
1970 1966
        return ret;
1971 1967
    }
1968

  
1972 1969
    return 0;
1973 1970
}
1974 1971

  

Also available in: Unified diff