提交 45aba42f 编写于 作者: K Kevin Wolf 提交者: Anthony Liguori

qcow2: Split out guest cluster functions

qcow2-cluster.c contains all functions related to the management of guest
clusters, i.e. what the guest sees on its virtual disk. This code is about
mapping these guest clusters to host clusters in the image file using the
two-level lookup tables.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 f7d0fe02
......@@ -68,7 +68,7 @@ recurse-all: $(SUBDIR_RULES)
BLOCK_OBJS=cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
BLOCK_OBJS+=block/cow.o block/qcow.o aes.o block/vmdk.o block/cloop.o
BLOCK_OBJS+=block/dmg.o block/bochs.o block/vpc.o block/vvfat.o
BLOCK_OBJS+=block/qcow2.o block/qcow2-refcount.o
BLOCK_OBJS+=block/qcow2.o block/qcow2-refcount.o block/qcow2-cluster.o
BLOCK_OBJS+=block/parallels.o block/nbd.o
BLOCK_OBJS+=nbd.o block.o aio.o
......
此差异已折叠。
......@@ -389,6 +389,34 @@ void free_clusters(BlockDriverState *bs,
update_refcount(bs, offset, size, -1);
}
/*
* free_any_clusters
*
* free clusters according to its type: compressed or not
*
*/
void free_any_clusters(BlockDriverState *bs,
uint64_t cluster_offset, int nb_clusters)
{
BDRVQcowState *s = bs->opaque;
/* free the cluster */
if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
int nb_csectors;
nb_csectors = ((cluster_offset >> s->csize_shift) &
s->csize_mask) + 1;
free_clusters(bs, (cluster_offset & s->cluster_offset_mask) & ~511,
nb_csectors * 512);
return;
}
free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits);
return;
}
/*********************************************************/
......
此差异已折叠。
......@@ -124,7 +124,16 @@ typedef struct QCowCreateState {
int64_t refcount_block_offset;
} QCowCreateState;
static int size_to_clusters(BDRVQcowState *s, int64_t size)
/* XXX This could be private for qcow2-cluster.c */
typedef struct QCowL2Meta
{
uint64_t offset;
int n_start;
int nb_available;
int nb_clusters;
} QCowL2Meta;
static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
{
return (size + (s->cluster_size - 1)) >> s->cluster_bits;
}
......@@ -133,6 +142,8 @@ static int size_to_clusters(BDRVQcowState *s, int64_t size)
/* qcow2.c functions */
void l2_cache_reset(BlockDriverState *bs);
int backing_read1(BlockDriverState *bs,
int64_t sector_num, uint8_t *buf, int nb_sectors);
/* qcow2-refcount.c functions */
int refcount_init(BlockDriverState *bs);
......@@ -141,7 +152,9 @@ void refcount_close(BlockDriverState *bs);
int64_t alloc_clusters(BlockDriverState *bs, int64_t size);
int64_t alloc_bytes(BlockDriverState *bs, int size);
void free_clusters(BlockDriverState *bs,
int64_t offset, int64_t size);
int64_t offset, int64_t size);
void free_any_clusters(BlockDriverState *bs,
uint64_t cluster_offset, int nb_clusters);
void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size);
int update_snapshot_refcount(BlockDriverState *bs,
......@@ -151,4 +164,24 @@ int update_snapshot_refcount(BlockDriverState *bs,
int check_refcounts(BlockDriverState *bs);
/* qcow2-cluster.c functions */
int grow_l1_table(BlockDriverState *bs, int min_size);
int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
uint8_t *out_buf, const uint8_t *in_buf,
int nb_sectors, int enc,
const AES_KEY *key);
uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num);
uint64_t alloc_cluster_offset(BlockDriverState *bs,
uint64_t offset,
int n_start, int n_end,
int *num, QCowL2Meta *m);
uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs,
uint64_t offset,
int compressed_size);
int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
QCowL2Meta *m);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册