Revision b6b8a333

b/block.c
3044 3044
    return 0;
3045 3045
}
3046 3046

  
3047
typedef struct BdrvCoIsAllocatedData {
3047
typedef struct BdrvCoGetBlockStatusData {
3048 3048
    BlockDriverState *bs;
3049 3049
    BlockDriverState *base;
3050 3050
    int64_t sector_num;
3051 3051
    int nb_sectors;
3052 3052
    int *pnum;
3053
    int ret;
3053
    int64_t ret;
3054 3054
    bool done;
3055
} BdrvCoIsAllocatedData;
3055
} BdrvCoGetBlockStatusData;
3056 3056

  
3057 3057
/*
3058 3058
 * Returns true iff the specified sector is present in the disk image. Drivers
......
3069 3069
 * 'nb_sectors' is the max value 'pnum' should be set to.  If nb_sectors goes
3070 3070
 * beyond the end of the disk image it will be clamped.
3071 3071
 */
3072
static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
3073
                                             int64_t sector_num,
3074
                                             int nb_sectors, int *pnum)
3072
static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
3073
                                                     int64_t sector_num,
3074
                                                     int nb_sectors, int *pnum)
3075 3075
{
3076 3076
    int64_t length;
3077 3077
    int64_t n;
......
3091 3091
        nb_sectors = n;
3092 3092
    }
3093 3093

  
3094
    if (!bs->drv->bdrv_co_is_allocated) {
3094
    if (!bs->drv->bdrv_co_get_block_status) {
3095 3095
        *pnum = nb_sectors;
3096 3096
        return 1;
3097 3097
    }
3098 3098

  
3099
    return bs->drv->bdrv_co_is_allocated(bs, sector_num, nb_sectors, pnum);
3099
    return bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
3100 3100
}
3101 3101

  
3102
/* Coroutine wrapper for bdrv_is_allocated() */
3103
static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque)
3102
/* Coroutine wrapper for bdrv_get_block_status() */
3103
static void coroutine_fn bdrv_get_block_status_co_entry(void *opaque)
3104 3104
{
3105
    BdrvCoIsAllocatedData *data = opaque;
3105
    BdrvCoGetBlockStatusData *data = opaque;
3106 3106
    BlockDriverState *bs = data->bs;
3107 3107

  
3108
    data->ret = bdrv_co_is_allocated(bs, data->sector_num, data->nb_sectors,
3109
                                     data->pnum);
3108
    data->ret = bdrv_co_get_block_status(bs, data->sector_num, data->nb_sectors,
3109
                                         data->pnum);
3110 3110
    data->done = true;
3111 3111
}
3112 3112

  
3113 3113
/*
3114
 * Synchronous wrapper around bdrv_co_is_allocated().
3114
 * Synchronous wrapper around bdrv_co_get_block_status().
3115 3115
 *
3116
 * See bdrv_co_is_allocated() for details.
3116
 * See bdrv_co_get_block_status() for details.
3117 3117
 */
3118
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
3119
                      int *pnum)
3118
int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
3119
                              int nb_sectors, int *pnum)
3120 3120
{
3121 3121
    Coroutine *co;
3122
    BdrvCoIsAllocatedData data = {
3122
    BdrvCoGetBlockStatusData data = {
3123 3123
        .bs = bs,
3124 3124
        .sector_num = sector_num,
3125 3125
        .nb_sectors = nb_sectors,
......
3129 3129

  
3130 3130
    if (qemu_in_coroutine()) {
3131 3131
        /* Fast-path if already in coroutine context */
3132
        bdrv_is_allocated_co_entry(&data);
3132
        bdrv_get_block_status_co_entry(&data);
3133 3133
    } else {
3134
        co = qemu_coroutine_create(bdrv_is_allocated_co_entry);
3134
        co = qemu_coroutine_create(bdrv_get_block_status_co_entry);
3135 3135
        qemu_coroutine_enter(co, &data);
3136 3136
        while (!data.done) {
3137 3137
            qemu_aio_wait();
......
3140 3140
    return data.ret;
3141 3141
}
3142 3142

  
3143
int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num,
3144
                                   int nb_sectors, int *pnum)
3145
{
3146
    return bdrv_get_block_status(bs, sector_num, nb_sectors, pnum);
3147
}
3148

  
3143 3149
/*
3144 3150
 * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP]
3145 3151
 *
b/block/cow.c
188 188
    return changed;
189 189
}
190 190

  
191
static int64_t coroutine_fn cow_co_get_block_status(BlockDriverState *bs,
192
        int64_t sector_num, int nb_sectors, int *num_same)
193
{
194
    return cow_co_is_allocated(bs, sector_num, nb_sectors, num_same);
195
}
196

  
191 197
static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num,
192 198
        int nb_sectors)
193 199
{
......
371 377

  
372 378
    .bdrv_read              = cow_co_read,
373 379
    .bdrv_write             = cow_co_write,
374
    .bdrv_co_is_allocated   = cow_co_is_allocated,
380
    .bdrv_co_get_block_status   = cow_co_get_block_status,
375 381

  
376 382
    .create_options = cow_create_options,
377 383
};
b/block/qcow.c
395 395
    return cluster_offset;
396 396
}
397 397

  
398
static int coroutine_fn qcow_co_is_allocated(BlockDriverState *bs,
398
static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs,
399 399
        int64_t sector_num, int nb_sectors, int *pnum)
400 400
{
401 401
    BDRVQcowState *s = bs->opaque;
......
896 896

  
897 897
    .bdrv_co_readv          = qcow_co_readv,
898 898
    .bdrv_co_writev         = qcow_co_writev,
899
    .bdrv_co_is_allocated   = qcow_co_is_allocated,
899
    .bdrv_co_get_block_status   = qcow_co_get_block_status,
900 900

  
901 901
    .bdrv_set_key           = qcow_set_key,
902 902
    .bdrv_make_empty        = qcow_make_empty,
b/block/qcow2.c
688 688
    return 0;
689 689
}
690 690

  
691
static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs,
691
static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
692 692
        int64_t sector_num, int nb_sectors, int *pnum)
693 693
{
694 694
    BDRVQcowState *s = bs->opaque;
......
1866 1866
    .bdrv_reopen_prepare  = qcow2_reopen_prepare,
1867 1867
    .bdrv_create        = qcow2_create,
1868 1868
    .bdrv_has_zero_init = bdrv_has_zero_init_1,
1869
    .bdrv_co_is_allocated = qcow2_co_is_allocated,
1869
    .bdrv_co_get_block_status = qcow2_co_get_block_status,
1870 1870
    .bdrv_set_key       = qcow2_set_key,
1871 1871
    .bdrv_make_empty    = qcow2_make_empty,
1872 1872

  
b/block/qed.c
667 667
    }
668 668
}
669 669

  
670
static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs,
670
static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,
671 671
                                                 int64_t sector_num,
672 672
                                                 int nb_sectors, int *pnum)
673 673
{
......
1575 1575
    .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
1576 1576
    .bdrv_create              = bdrv_qed_create,
1577 1577
    .bdrv_has_zero_init       = bdrv_has_zero_init_1,
1578
    .bdrv_co_is_allocated     = bdrv_qed_co_is_allocated,
1578
    .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
1579 1579
    .bdrv_make_empty          = bdrv_qed_make_empty,
1580 1580
    .bdrv_aio_readv           = bdrv_qed_aio_readv,
1581 1581
    .bdrv_aio_writev          = bdrv_qed_aio_writev,
b/block/raw-posix.c
1084 1084
 * 'nb_sectors' is the max value 'pnum' should be set to.  If nb_sectors goes
1085 1085
 * beyond the end of the disk image it will be clamped.
1086 1086
 */
1087
static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
1087
static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
1088 1088
                                            int64_t sector_num,
1089 1089
                                            int nb_sectors, int *pnum)
1090 1090
{
......
1200 1200
    .bdrv_close = raw_close,
1201 1201
    .bdrv_create = raw_create,
1202 1202
    .bdrv_has_zero_init = bdrv_has_zero_init_1,
1203
    .bdrv_co_is_allocated = raw_co_is_allocated,
1203
    .bdrv_co_get_block_status = raw_co_get_block_status,
1204 1204

  
1205 1205
    .bdrv_aio_readv = raw_aio_readv,
1206 1206
    .bdrv_aio_writev = raw_aio_writev,
b/block/raw_bsd.c
58 58
    return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
59 59
}
60 60

  
61
static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
62
                                            int64_t sector_num, int nb_sectors,
63
                                            int *pnum)
61
static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
62
                                            int64_t sector_num,
63
                                            int nb_sectors, int *pnum)
64 64
{
65
    return bdrv_is_allocated(bs->file, sector_num, nb_sectors, pnum);
65
    return bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum);
66 66
}
67 67

  
68 68
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
......
164 164
    .bdrv_co_writev       = &raw_co_writev,
165 165
    .bdrv_co_write_zeroes = &raw_co_write_zeroes,
166 166
    .bdrv_co_discard      = &raw_co_discard,
167
    .bdrv_co_is_allocated = &raw_co_is_allocated,
167
    .bdrv_co_get_block_status = &raw_co_get_block_status,
168 168
    .bdrv_truncate        = &raw_truncate,
169 169
    .bdrv_getlength       = &raw_getlength,
170 170
    .bdrv_get_info        = &raw_get_info,
b/block/sheepdog.c
2270 2270
    return acb->ret;
2271 2271
}
2272 2272

  
2273
static coroutine_fn int
2274
sd_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
2275
                   int *pnum)
2273
static coroutine_fn int64_t
2274
sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
2275
                       int *pnum)
2276 2276
{
2277 2277
    BDRVSheepdogState *s = bs->opaque;
2278 2278
    SheepdogInode *inode = &s->inode;
......
2338 2338
    .bdrv_co_writev = sd_co_writev,
2339 2339
    .bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
2340 2340
    .bdrv_co_discard = sd_co_discard,
2341
    .bdrv_co_is_allocated = sd_co_is_allocated,
2341
    .bdrv_co_get_block_status = sd_co_get_block_status,
2342 2342

  
2343 2343
    .bdrv_snapshot_create   = sd_snapshot_create,
2344 2344
    .bdrv_snapshot_goto     = sd_snapshot_goto,
......
2366 2366
    .bdrv_co_writev = sd_co_writev,
2367 2367
    .bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
2368 2368
    .bdrv_co_discard = sd_co_discard,
2369
    .bdrv_co_is_allocated = sd_co_is_allocated,
2369
    .bdrv_co_get_block_status = sd_co_get_block_status,
2370 2370

  
2371 2371
    .bdrv_snapshot_create   = sd_snapshot_create,
2372 2372
    .bdrv_snapshot_goto     = sd_snapshot_goto,
......
2394 2394
    .bdrv_co_writev = sd_co_writev,
2395 2395
    .bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
2396 2396
    .bdrv_co_discard = sd_co_discard,
2397
    .bdrv_co_is_allocated = sd_co_is_allocated,
2397
    .bdrv_co_get_block_status = sd_co_get_block_status,
2398 2398

  
2399 2399
    .bdrv_snapshot_create   = sd_snapshot_create,
2400 2400
    .bdrv_snapshot_goto     = sd_snapshot_goto,
b/block/vdi.c
470 470
    return 0;
471 471
}
472 472

  
473
static int coroutine_fn vdi_co_is_allocated(BlockDriverState *bs,
473
static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs,
474 474
        int64_t sector_num, int nb_sectors, int *pnum)
475 475
{
476 476
    /* TODO: Check for too large sector_num (in bdrv_is_allocated or here). */
......
780 780
    .bdrv_reopen_prepare = vdi_reopen_prepare,
781 781
    .bdrv_create = vdi_create,
782 782
    .bdrv_has_zero_init = bdrv_has_zero_init_1,
783
    .bdrv_co_is_allocated = vdi_co_is_allocated,
783
    .bdrv_co_get_block_status = vdi_co_get_block_status,
784 784
    .bdrv_make_empty = vdi_make_empty,
785 785

  
786 786
    .bdrv_read = vdi_co_read,
b/block/vmdk.c
1042 1042
    return NULL;
1043 1043
}
1044 1044

  
1045
static int coroutine_fn vmdk_co_is_allocated(BlockDriverState *bs,
1045
static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
1046 1046
        int64_t sector_num, int nb_sectors, int *pnum)
1047 1047
{
1048 1048
    BDRVVmdkState *s = bs->opaque;
......
1837 1837
    .bdrv_close                   = vmdk_close,
1838 1838
    .bdrv_create                  = vmdk_create,
1839 1839
    .bdrv_co_flush_to_disk        = vmdk_co_flush,
1840
    .bdrv_co_is_allocated         = vmdk_co_is_allocated,
1840
    .bdrv_co_get_block_status     = vmdk_co_get_block_status,
1841 1841
    .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
1842 1842
    .bdrv_has_zero_init           = vmdk_has_zero_init,
1843 1843

  
b/block/vvfat.c
2874 2874
    return ret;
2875 2875
}
2876 2876

  
2877
static int coroutine_fn vvfat_co_is_allocated(BlockDriverState *bs,
2877
static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs,
2878 2878
	int64_t sector_num, int nb_sectors, int* n)
2879 2879
{
2880 2880
    BDRVVVFATState* s = bs->opaque;
......
2984 2984

  
2985 2985
    .bdrv_read              = vvfat_co_read,
2986 2986
    .bdrv_write             = vvfat_co_write,
2987
    .bdrv_co_is_allocated   = vvfat_co_is_allocated,
2987
    .bdrv_co_get_block_status = vvfat_co_get_block_status,
2988 2988
};
2989 2989

  
2990 2990
static void bdrv_vvfat_init(void)
b/include/block/block.h
269 269
int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
270 270
int bdrv_has_zero_init_1(BlockDriverState *bs);
271 271
int bdrv_has_zero_init(BlockDriverState *bs);
272
int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
273
                              int nb_sectors, int *pnum);
272 274
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
273 275
                      int *pnum);
274 276
int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
b/include/block/block_int.h
118 118
        int64_t sector_num, int nb_sectors);
119 119
    int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
120 120
        int64_t sector_num, int nb_sectors);
121
    int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs,
121
    int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
122 122
        int64_t sector_num, int nb_sectors, int *pnum);
123 123

  
124 124
    /*

Also available in: Unified diff