[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 26/38] block: add discard support
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 26/38] block: add discard support |
Date: |
Fri, 17 Dec 2010 18:44:41 +0100 |
From: Christoph Hellwig <address@hidden>
Add a new bdrv_discard method to free blocks in a mapping image, and a new
drive property to set the granularity for these discard. If no discard
granularity support is set discard support is disabled.
Signed-off-by: Christoph Hellwig <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 11 +++++++++++
block.h | 1 +
block/raw.c | 6 ++++++
block_int.h | 7 ++++++-
4 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/block.c b/block.c
index fe07d0b..9b5e9e1 100644
--- a/block.c
+++ b/block.c
@@ -1515,6 +1515,17 @@ int bdrv_has_zero_init(BlockDriverState *bs)
return 1;
}
+int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
+{
+ if (!bs->drv) {
+ return -ENOMEDIUM;
+ }
+ if (!bs->drv->bdrv_discard) {
+ return 0;
+ }
+ return bs->drv->bdrv_discard(bs, sector_num, nb_sectors);
+}
+
/*
* Returns true iff the specified sector is present in the disk image. Drivers
* not implementing the functionality are assumed to not support backing files,
diff --git a/block.h b/block.h
index b812172..f923add 100644
--- a/block.h
+++ b/block.h
@@ -146,6 +146,7 @@ int bdrv_flush(BlockDriverState *bs);
void bdrv_flush_all(void);
void bdrv_close_all(void);
+int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
int bdrv_has_zero_init(BlockDriverState *bs);
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
int *pnum);
diff --git a/block/raw.c b/block/raw.c
index 1980deb..b0f72d6 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -65,6 +65,11 @@ static int raw_probe(const uint8_t *buf, int buf_size, const
char *filename)
return 1; /* everything can be opened as raw image */
}
+static int raw_discard(BlockDriverState *bs, int64_t sector_num, int
nb_sectors)
+{
+ return bdrv_discard(bs->file, sector_num, nb_sectors);
+}
+
static int raw_is_inserted(BlockDriverState *bs)
{
return bdrv_is_inserted(bs->file);
@@ -130,6 +135,7 @@ static BlockDriver bdrv_raw = {
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
.bdrv_aio_flush = raw_aio_flush,
+ .bdrv_discard = raw_discard,
.bdrv_is_inserted = raw_is_inserted,
.bdrv_eject = raw_eject,
diff --git a/block_int.h b/block_int.h
index 6b3b098..eb5cd42 100644
--- a/block_int.h
+++ b/block_int.h
@@ -72,6 +72,8 @@ struct BlockDriver {
BlockDriverCompletionFunc *cb, void *opaque);
BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque);
+ int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors);
int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs,
int num_reqs);
@@ -227,6 +229,7 @@ typedef struct BlockConf {
uint16_t min_io_size;
uint32_t opt_io_size;
int32_t bootindex;
+ uint32_t discard_granularity;
} BlockConf;
static inline unsigned int get_physical_block_exp(BlockConf *conf)
@@ -250,6 +253,8 @@ static inline unsigned int get_physical_block_exp(BlockConf
*conf)
_conf.physical_block_size, 512), \
DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
- DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) \
+ DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \
+ DEFINE_PROP_UINT32("discard_granularity", _state, \
+ _conf.discard_granularity, 0)
#endif /* BLOCK_INT_H */
--
1.7.2.3
- [Qemu-devel] [PATCH 32/38] qed: Add QEMU Enhanced Disk image format, (continued)
- [Qemu-devel] [PATCH 32/38] qed: Add QEMU Enhanced Disk image format, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 38/38] docs: Fix missing carets in QED specification, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 27/38] scsi-disk: support WRITE SAME (16) with unmap bit, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 23/38] qemu.img.c: Use error_report() instead of own error() implementation, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 36/38] block/qcow2.c: rename qcow_ functions to qcow2_, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 29/38] raw-posix: add discard support, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 35/38] qed: Consistency check support, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 34/38] qed: Read/write support, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 37/38] Add proper -errno error return values to qcow2_open(), Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 15/38] config: add ahci for pci capable machines, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 26/38] block: add discard support,
Kevin Wolf <=
- [Qemu-devel] [PATCH 33/38] qed: Table, L2 cache, and cluster functions, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 24/38] Remove NULL checks for bdrv_new return value, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 22/38] bdrv_img_create() use proper errno return values, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 13/38] ahci: add ahci emulation, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 12/38] pci: add ich9 pci id, Kevin Wolf, 2010/12/17
- [Qemu-devel] [PATCH 08/38] ide: Split out BMDMA code from ATA core, Kevin Wolf, 2010/12/17
- [Qemu-devel] Re: [PULL 00/38] Block patches, Anthony Liguori, 2010/12/17