Revision bb8bf76f

b/block.c
1515 1515
    return 1;
1516 1516
}
1517 1517

  
1518
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
1519
{
1520
    if (!bs->drv) {
1521
        return -ENOMEDIUM;
1522
    }
1523
    if (!bs->drv->bdrv_discard) {
1524
        return 0;
1525
    }
1526
    return bs->drv->bdrv_discard(bs, sector_num, nb_sectors);
1527
}
1528

  
1518 1529
/*
1519 1530
 * Returns true iff the specified sector is present in the disk image. Drivers
1520 1531
 * not implementing the functionality are assumed to not support backing files,
b/block.h
146 146
void bdrv_flush_all(void);
147 147
void bdrv_close_all(void);
148 148

  
149
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
149 150
int bdrv_has_zero_init(BlockDriverState *bs);
150 151
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
151 152
	int *pnum);
b/block/raw.c
65 65
   return 1; /* everything can be opened as raw image */
66 66
}
67 67

  
68
static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
69
{
70
    return bdrv_discard(bs->file, sector_num, nb_sectors);
71
}
72

  
68 73
static int raw_is_inserted(BlockDriverState *bs)
69 74
{
70 75
    return bdrv_is_inserted(bs->file);
......
130 135
    .bdrv_aio_readv     = raw_aio_readv,
131 136
    .bdrv_aio_writev    = raw_aio_writev,
132 137
    .bdrv_aio_flush     = raw_aio_flush,
138
    .bdrv_discard       = raw_discard,
133 139

  
134 140
    .bdrv_is_inserted   = raw_is_inserted,
135 141
    .bdrv_eject         = raw_eject,
b/block_int.h
72 72
        BlockDriverCompletionFunc *cb, void *opaque);
73 73
    BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
74 74
        BlockDriverCompletionFunc *cb, void *opaque);
75
    int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num,
76
                        int nb_sectors);
75 77

  
76 78
    int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs,
77 79
        int num_reqs);
......
227 229
    uint16_t min_io_size;
228 230
    uint32_t opt_io_size;
229 231
    int32_t bootindex;
232
    uint32_t discard_granularity;
230 233
} BlockConf;
231 234

  
232 235
static inline unsigned int get_physical_block_exp(BlockConf *conf)
......
250 253
                       _conf.physical_block_size, 512),                 \
251 254
    DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
252 255
    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
253
    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)         \
256
    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1),        \
257
    DEFINE_PROP_UINT32("discard_granularity", _state, \
258
                       _conf.discard_granularity, 0)
254 259

  
255 260
#endif /* BLOCK_INT_H */

Also available in: Unified diff