Revision 205ef796

b/block.c
1453 1453
    return bs->device_name;
1454 1454
}
1455 1455

  
1456
void bdrv_flush(BlockDriverState *bs)
1456
int bdrv_flush(BlockDriverState *bs)
1457 1457
{
1458 1458
    if (bs->open_flags & BDRV_O_NO_FLUSH) {
1459
        return;
1459
        return 0;
1460
    }
1461

  
1462
    if (bs->drv && bs->drv->bdrv_flush) {
1463
        return bs->drv->bdrv_flush(bs);
1460 1464
    }
1461 1465

  
1462
    if (bs->drv && bs->drv->bdrv_flush)
1463
        bs->drv->bdrv_flush(bs);
1466
    /*
1467
     * Some block drivers always operate in either writethrough or unsafe mode
1468
     * and don't support bdrv_flush therefore. Usually qemu doesn't know how
1469
     * the server works (because the behaviour is hardcoded or depends on
1470
     * server-side configuration), so we can't ensure that everything is safe
1471
     * on disk. Returning an error doesn't work because that would break guests
1472
     * even if the server operates in writethrough mode.
1473
     *
1474
     * Let's hope the user knows what he's doing.
1475
     */
1476
    return 0;
1464 1477
}
1465 1478

  
1466 1479
void bdrv_flush_all(void)
b/block.h
142 142
        BlockDriverCompletionFunc *cb, void *opaque);
143 143

  
144 144
/* Ensure contents are flushed to disk.  */
145
void bdrv_flush(BlockDriverState *bs);
145
int bdrv_flush(BlockDriverState *bs);
146 146
void bdrv_flush_all(void);
147 147
void bdrv_close_all(void);
148 148

  
b/block/blkdebug.c
397 397
    }
398 398
}
399 399

  
400
static void blkdebug_flush(BlockDriverState *bs)
400
static int blkdebug_flush(BlockDriverState *bs)
401 401
{
402
    bdrv_flush(bs->file);
402
    return bdrv_flush(bs->file);
403 403
}
404 404

  
405 405
static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
b/block/blkverify.c
116 116
    s->test_file = NULL;
117 117
}
118 118

  
119
static void blkverify_flush(BlockDriverState *bs)
119
static int blkverify_flush(BlockDriverState *bs)
120 120
{
121 121
    BDRVBlkverifyState *s = bs->opaque;
122 122

  
123 123
    /* Only flush test file, the raw file is not important */
124
    bdrv_flush(s->test_file);
124
    return bdrv_flush(s->test_file);
125 125
}
126 126

  
127 127
static int64_t blkverify_getlength(BlockDriverState *bs)
b/block/cow.c
282 282
    return ret;
283 283
}
284 284

  
285
static void cow_flush(BlockDriverState *bs)
285
static int cow_flush(BlockDriverState *bs)
286 286
{
287
    bdrv_flush(bs->file);
287
    return bdrv_flush(bs->file);
288 288
}
289 289

  
290 290
static QEMUOptionParameter cow_create_options[] = {
b/block/qcow.c
910 910
    return 0;
911 911
}
912 912

  
913
static void qcow_flush(BlockDriverState *bs)
913
static int qcow_flush(BlockDriverState *bs)
914 914
{
915
    bdrv_flush(bs->file);
915
    return bdrv_flush(bs->file);
916 916
}
917 917

  
918 918
static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs,
b/block/qcow2.c
1148 1148
    return 0;
1149 1149
}
1150 1150

  
1151
static void qcow_flush(BlockDriverState *bs)
1151
static int qcow_flush(BlockDriverState *bs)
1152 1152
{
1153
    bdrv_flush(bs->file);
1153
    return bdrv_flush(bs->file);
1154 1154
}
1155 1155

  
1156 1156
static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs,
b/block/raw-posix.c
734 734
    return result;
735 735
}
736 736

  
737
static void raw_flush(BlockDriverState *bs)
737
static int raw_flush(BlockDriverState *bs)
738 738
{
739 739
    BDRVRawState *s = bs->opaque;
740
    qemu_fdatasync(s->fd);
740
    return qemu_fdatasync(s->fd);
741 741
}
742 742

  
743 743

  
b/block/raw-win32.c
150 150
static void raw_flush(BlockDriverState *bs)
151 151
{
152 152
    BDRVRawState *s = bs->opaque;
153
    FlushFileBuffers(s->hfile);
153
    int ret;
154

  
155
    ret = FlushFileBuffers(s->hfile);
156
    if (ret != 0) {
157
        return -EIO;
158
    }
159

  
160
    return 0;
154 161
}
155 162

  
156 163
static void raw_close(BlockDriverState *bs)
b/block/raw.c
39 39
{
40 40
}
41 41

  
42
static void raw_flush(BlockDriverState *bs)
42
static int raw_flush(BlockDriverState *bs)
43 43
{
44
    bdrv_flush(bs->file);
44
    return bdrv_flush(bs->file);
45 45
}
46 46

  
47 47
static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
b/block/vdi.c
900 900
{
901 901
}
902 902

  
903
static void vdi_flush(BlockDriverState *bs)
903
static int vdi_flush(BlockDriverState *bs)
904 904
{
905 905
    logout("\n");
906
    bdrv_flush(bs->file);
906
    return bdrv_flush(bs->file);
907 907
}
908 908

  
909 909

  
b/block/vmdk.c
823 823
    qemu_free(s->l2_cache);
824 824
}
825 825

  
826
static void vmdk_flush(BlockDriverState *bs)
826
static int vmdk_flush(BlockDriverState *bs)
827 827
{
828
    bdrv_flush(bs->file);
828
    return bdrv_flush(bs->file);
829 829
}
830 830

  
831 831

  
b/block_int.h
59 59
                      const uint8_t *buf, int nb_sectors);
60 60
    void (*bdrv_close)(BlockDriverState *bs);
61 61
    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
62
    void (*bdrv_flush)(BlockDriverState *bs);
62
    int (*bdrv_flush)(BlockDriverState *bs);
63 63
    int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
64 64
                             int nb_sectors, int *pnum);
65 65
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);

Also available in: Unified diff