Skip to content

Commit

Permalink
block: Implement .bdrv_has_zero_init_truncate()
Browse files Browse the repository at this point in the history
We need to implement .bdrv_has_zero_init_truncate() for every block
driver that supports truncation and has a .bdrv_has_zero_init()
implementation.

Implement it the same way each driver implements .bdrv_has_zero_init().
This is at least not any more unsafe than what we had before.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190724171239.8764-5-mreitz@redhat.com
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
  • Loading branch information
XanClic committed Aug 19, 2019
1 parent ceaca56 commit 1dcaf52
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions block/file-posix.c
Expand Up @@ -2938,6 +2938,7 @@ BlockDriver bdrv_file = {
.bdrv_co_create = raw_co_create,
.bdrv_co_create_opts = raw_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,
.bdrv_co_block_status = raw_co_block_status,
.bdrv_co_invalidate_cache = raw_co_invalidate_cache,
.bdrv_co_pwrite_zeroes = raw_co_pwrite_zeroes,
Expand Down
1 change: 1 addition & 0 deletions block/file-win32.c
Expand Up @@ -635,6 +635,7 @@ BlockDriver bdrv_file = {
.bdrv_close = raw_close,
.bdrv_co_create_opts = raw_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,

.bdrv_aio_preadv = raw_aio_preadv,
.bdrv_aio_pwritev = raw_aio_pwritev,
Expand Down
4 changes: 4 additions & 0 deletions block/gluster.c
Expand Up @@ -1567,6 +1567,7 @@ static BlockDriver bdrv_gluster = {
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
.bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_pdiscard = qemu_gluster_co_pdiscard,
#endif
Expand Down Expand Up @@ -1598,6 +1599,7 @@ static BlockDriver bdrv_gluster_tcp = {
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
.bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_pdiscard = qemu_gluster_co_pdiscard,
#endif
Expand Down Expand Up @@ -1629,6 +1631,7 @@ static BlockDriver bdrv_gluster_unix = {
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
.bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_pdiscard = qemu_gluster_co_pdiscard,
#endif
Expand Down Expand Up @@ -1666,6 +1669,7 @@ static BlockDriver bdrv_gluster_rdma = {
.bdrv_co_writev = qemu_gluster_co_writev,
.bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk,
.bdrv_has_zero_init = qemu_gluster_has_zero_init,
.bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init,
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_co_pdiscard = qemu_gluster_co_pdiscard,
#endif
Expand Down
1 change: 1 addition & 0 deletions block/nfs.c
Expand Up @@ -863,6 +863,7 @@ static BlockDriver bdrv_nfs = {
.create_opts = &nfs_create_opts,

.bdrv_has_zero_init = nfs_has_zero_init,
.bdrv_has_zero_init_truncate = nfs_has_zero_init,
.bdrv_get_allocated_file_size = nfs_get_allocated_file_size,
.bdrv_co_truncate = nfs_file_co_truncate,

Expand Down
1 change: 1 addition & 0 deletions block/qcow2.c
Expand Up @@ -5188,6 +5188,7 @@ BlockDriver bdrv_qcow2 = {
.bdrv_co_create_opts = qcow2_co_create_opts,
.bdrv_co_create = qcow2_co_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,
.bdrv_co_block_status = qcow2_co_block_status,

.bdrv_co_preadv = qcow2_co_preadv,
Expand Down
1 change: 1 addition & 0 deletions block/qed.c
Expand Up @@ -1669,6 +1669,7 @@ static BlockDriver bdrv_qed = {
.bdrv_co_create = bdrv_qed_co_create,
.bdrv_co_create_opts = bdrv_qed_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,
.bdrv_co_block_status = bdrv_qed_co_block_status,
.bdrv_co_readv = bdrv_qed_co_readv,
.bdrv_co_writev = bdrv_qed_co_writev,
Expand Down
6 changes: 6 additions & 0 deletions block/raw-format.c
Expand Up @@ -413,6 +413,11 @@ static int raw_has_zero_init(BlockDriverState *bs)
return bdrv_has_zero_init(bs->file->bs);
}

static int raw_has_zero_init_truncate(BlockDriverState *bs)
{
return bdrv_has_zero_init_truncate(bs->file->bs);
}

static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
Error **errp)
{
Expand Down Expand Up @@ -572,6 +577,7 @@ BlockDriver bdrv_raw = {
.bdrv_co_ioctl = &raw_co_ioctl,
.create_opts = &raw_create_opts,
.bdrv_has_zero_init = &raw_has_zero_init,
.bdrv_has_zero_init_truncate = &raw_has_zero_init_truncate,
.strong_runtime_opts = raw_strong_runtime_opts,
.mutable_opts = mutable_opts,
};
Expand Down
1 change: 1 addition & 0 deletions block/rbd.c
Expand Up @@ -1288,6 +1288,7 @@ static BlockDriver bdrv_rbd = {
.bdrv_co_create = qemu_rbd_co_create,
.bdrv_co_create_opts = qemu_rbd_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,
.bdrv_get_info = qemu_rbd_getinfo,
.create_opts = &qemu_rbd_create_opts,
.bdrv_getlength = qemu_rbd_getlength,
Expand Down
1 change: 1 addition & 0 deletions block/sheepdog.c
Expand Up @@ -3229,6 +3229,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_co_create = sd_co_create,
.bdrv_co_create_opts = sd_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_has_zero_init_truncate = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
.bdrv_co_truncate = sd_co_truncate,
Expand Down
1 change: 1 addition & 0 deletions block/ssh.c
Expand Up @@ -1390,6 +1390,7 @@ static BlockDriver bdrv_ssh = {
.bdrv_co_create_opts = ssh_co_create_opts,
.bdrv_close = ssh_close,
.bdrv_has_zero_init = ssh_has_zero_init,
.bdrv_has_zero_init_truncate = ssh_has_zero_init,
.bdrv_co_readv = ssh_co_readv,
.bdrv_co_writev = ssh_co_writev,
.bdrv_getlength = ssh_getlength,
Expand Down

0 comments on commit 1dcaf52

Please sign in to comment.