[sheepdog] [PATCH v3 09/44] block: Allow BDRV_REQ_FUA through blk_pwrite()

Denis V. Lunev den at openvz.org
Sat Apr 23 10:12:39 CEST 2016


On 04/23/2016 02:40 AM, Eric Blake wrote:
> We have several block drivers that understand BDRV_REQ_FUA,
> and emulate it in the block layer for the rest by a full flush.
> But without a way to actually request BDRV_REQ_FUA during a
> pass-through blk_pwrite(), FUA-aware block drivers like NBD are
> forced to repeat the emulation logic of a full flush regardless
> of whether the backend they are writing to could do it more
> efficiently.
>
> This patch just wires up a flags argument; a followup patch
> will actually make use of it in the NBD driver and in qemu-io.
>
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>   include/sysemu/block-backend.h |  3 ++-
>   block/block-backend.c          |  6 ++++--
>   block/crypto.c                 |  2 +-
>   block/parallels.c              |  2 +-
>   block/qcow.c                   |  8 ++++----
>   block/qcow2.c                  |  4 ++--
>   block/qed.c                    |  6 +++---
>   block/sheepdog.c               |  2 +-
>   block/vdi.c                    |  4 ++--
>   block/vhdx.c                   |  5 +++--
>   block/vmdk.c                   | 10 +++++-----
>   block/vpc.c                    | 10 +++++-----
>   hw/nvram/spapr_nvram.c         |  4 ++--
>   nbd/server.c                   |  2 +-
>   qemu-io-cmds.c                 |  2 +-
>   15 files changed, 37 insertions(+), 33 deletions(-)
>
> diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
> index c62b6fe..6991b26 100644
> --- a/include/sysemu/block-backend.h
> +++ b/include/sysemu/block-backend.h
> @@ -102,7 +102,8 @@ BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
>                                    int nb_sectors, BdrvRequestFlags flags,
>                                    BlockCompletionFunc *cb, void *opaque);
>   int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count);
> -int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count);
> +int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count,
> +               BdrvRequestFlags flags);
>   int64_t blk_getlength(BlockBackend *blk);
>   void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
>   int64_t blk_nb_sectors(BlockBackend *blk);
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 16c9d5e..4551865 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -955,9 +955,11 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
>       return count;
>   }
>
> -int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
> +int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count,
> +               BdrvRequestFlags flags)
>   {
> -    int ret = blk_prw(blk, offset, (void*) buf, count, blk_write_entry, 0);
> +    int ret = blk_prw(blk, offset, (void *) buf, count, blk_write_entry,
> +                      flags);
>       if (ret < 0) {
>           return ret;
>       }
> diff --git a/block/crypto.c b/block/crypto.c
> index 1903e84..32ba17c 100644
> --- a/block/crypto.c
> +++ b/block/crypto.c
> @@ -91,7 +91,7 @@ static ssize_t block_crypto_write_func(QCryptoBlock *block,
>       struct BlockCryptoCreateData *data = opaque;
>       ssize_t ret;
>
> -    ret = blk_pwrite(data->blk, offset, buf, buflen);
> +    ret = blk_pwrite(data->blk, offset, buf, buflen, 0);
>       if (ret < 0) {
>           error_setg_errno(errp, -ret, "Could not write encryption header");
>           return ret;
> diff --git a/block/parallels.c b/block/parallels.c
> index 324ed43..2d8bc87 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -512,7 +512,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
>       memset(tmp, 0, sizeof(tmp));
>       memcpy(tmp, &header, sizeof(header));
>
> -    ret = blk_pwrite(file, 0, tmp, BDRV_SECTOR_SIZE);
> +    ret = blk_pwrite(file, 0, tmp, BDRV_SECTOR_SIZE, 0);
>       if (ret < 0) {
>           goto exit;
>       }
> diff --git a/block/qcow.c b/block/qcow.c
> index 60ddb12..d6dc1b0 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -853,14 +853,14 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
>       }
>
>       /* write all the data */
> -    ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header));
> +    ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0);
>       if (ret != sizeof(header)) {
>           goto exit;
>       }
>
>       if (backing_file) {
>           ret = blk_pwrite(qcow_blk, sizeof(header),
> -            backing_file, backing_filename_len);
> +                         backing_file, backing_filename_len, 0);
>           if (ret != backing_filename_len) {
>               goto exit;
>           }
> @@ -869,8 +869,8 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
>       tmp = g_malloc0(BDRV_SECTOR_SIZE);
>       for (i = 0; i < ((sizeof(uint64_t)*l1_size + BDRV_SECTOR_SIZE - 1)/
>           BDRV_SECTOR_SIZE); i++) {
> -        ret = blk_pwrite(qcow_blk, header_size +
> -            BDRV_SECTOR_SIZE*i, tmp, BDRV_SECTOR_SIZE);
> +        ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
> +                         tmp, BDRV_SECTOR_SIZE, 0);
>           if (ret != BDRV_SECTOR_SIZE) {
>               g_free(tmp);
>               goto exit;
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 470734b..3090538 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2207,7 +2207,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
>               cpu_to_be64(QCOW2_COMPAT_LAZY_REFCOUNTS);
>       }
>
> -    ret = blk_pwrite(blk, 0, header, cluster_size);
> +    ret = blk_pwrite(blk, 0, header, cluster_size, 0);
>       g_free(header);
>       if (ret < 0) {
>           error_setg_errno(errp, -ret, "Could not write qcow2 header");
> @@ -2217,7 +2217,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
>       /* Write a refcount table with one refcount block */
>       refcount_table = g_malloc0(2 * cluster_size);
>       refcount_table[0] = cpu_to_be64(2 * cluster_size);
> -    ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size);
> +    ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size, 0);
>       g_free(refcount_table);
>
>       if (ret < 0) {
> diff --git a/block/qed.c b/block/qed.c
> index 0af5274..6cfd4c1 100644
> --- a/block/qed.c
> +++ b/block/qed.c
> @@ -601,18 +601,18 @@ static int qed_create(const char *filename, uint32_t cluster_size,
>       }
>
>       qed_header_cpu_to_le(&header, &le_header);
> -    ret = blk_pwrite(blk, 0, &le_header, sizeof(le_header));
> +    ret = blk_pwrite(blk, 0, &le_header, sizeof(le_header), 0);
>       if (ret < 0) {
>           goto out;
>       }
>       ret = blk_pwrite(blk, sizeof(le_header), backing_file,
> -                     header.backing_filename_size);
> +                     header.backing_filename_size, 0);
>       if (ret < 0) {
>           goto out;
>       }
>
>       l1_table = g_malloc0(l1_size);
> -    ret = blk_pwrite(blk, header.l1_table_offset, l1_table, l1_size);
> +    ret = blk_pwrite(blk, header.l1_table_offset, l1_table, l1_size, 0);
>       if (ret < 0) {
>           goto out;
>       }
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 33e0a33..625f876 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -1678,7 +1678,7 @@ static int sd_prealloc(const char *filename, Error **errp)
>           if (ret < 0) {
>               goto out;
>           }
> -        ret = blk_pwrite(blk, idx * buf_size, buf, buf_size);
> +        ret = blk_pwrite(blk, idx * buf_size, buf, buf_size, 0);
>           if (ret < 0) {
>               goto out;
>           }
> diff --git a/block/vdi.c b/block/vdi.c
> index 75d4819..12ab3a6 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -808,7 +808,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
>       vdi_header_print(&header);
>   #endif
>       vdi_header_to_le(&header);
> -    ret = blk_pwrite(blk, offset, &header, sizeof(header));
> +    ret = blk_pwrite(blk, offset, &header, sizeof(header), 0);
>       if (ret < 0) {
>           error_setg(errp, "Error writing header to %s", filename);
>           goto exit;
> @@ -829,7 +829,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
>                   bmap[i] = VDI_UNALLOCATED;
>               }
>           }
> -        ret = blk_pwrite(blk, offset, bmap, bmap_size);
> +        ret = blk_pwrite(blk, offset, bmap, bmap_size, 0);
>           if (ret < 0) {
>               error_setg(errp, "Error writing bmap to %s", filename);
>               goto exit;
> diff --git a/block/vhdx.c b/block/vhdx.c
> index 2b7b332..ec778fe 100644
> --- a/block/vhdx.c
> +++ b/block/vhdx.c
> @@ -1856,13 +1856,14 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
>       creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
>                                 &creator_items, NULL);
>       signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
> -    ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature));
> +    ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature),
> +                     0);
>       if (ret < 0) {
>           goto delete_and_exit;
>       }
>       if (creator) {
>           ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
> -                         creator, creator_items * sizeof(gunichar2));
> +                         creator, creator_items * sizeof(gunichar2), 0);
>           if (ret < 0) {
>               goto delete_and_exit;
>           }
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 45f9d3c..0cc2011 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -1728,12 +1728,12 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
>       header.check_bytes[3] = 0xa;
>
>       /* write all the data */
> -    ret = blk_pwrite(blk, 0, &magic, sizeof(magic));
> +    ret = blk_pwrite(blk, 0, &magic, sizeof(magic), 0);
>       if (ret < 0) {
>           error_setg(errp, QERR_IO_ERROR);
>           goto exit;
>       }
> -    ret = blk_pwrite(blk, sizeof(magic), &header, sizeof(header));
> +    ret = blk_pwrite(blk, sizeof(magic), &header, sizeof(header), 0);
>       if (ret < 0) {
>           error_setg(errp, QERR_IO_ERROR);
>           goto exit;
> @@ -1753,7 +1753,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
>           gd_buf[i] = cpu_to_le32(tmp);
>       }
>       ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
> -                     gd_buf, gd_buf_size);
> +                     gd_buf, gd_buf_size, 0);
>       if (ret < 0) {
>           error_setg(errp, QERR_IO_ERROR);
>           goto exit;
> @@ -1765,7 +1765,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
>           gd_buf[i] = cpu_to_le32(tmp);
>       }
>       ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE,
> -                     gd_buf, gd_buf_size);
> +                     gd_buf, gd_buf_size, 0);
>       if (ret < 0) {
>           error_setg(errp, QERR_IO_ERROR);
>           goto exit;
> @@ -2028,7 +2028,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
>
>       blk_set_allow_write_beyond_eof(new_blk, true);
>
> -    ret = blk_pwrite(new_blk, desc_offset, desc, desc_len);
> +    ret = blk_pwrite(new_blk, desc_offset, desc, desc_len, 0);
>       if (ret < 0) {
>           error_setg_errno(errp, -ret, "Could not write description");
>           goto exit;
> diff --git a/block/vpc.c b/block/vpc.c
> index 3e2ea69..a55a3e4 100644
> --- a/block/vpc.c
> +++ b/block/vpc.c
> @@ -783,13 +783,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
>       block_size = 0x200000;
>       num_bat_entries = (total_sectors + block_size / 512) / (block_size / 512);
>
> -    ret = blk_pwrite(blk, offset, buf, HEADER_SIZE);
> +    ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0);
>       if (ret < 0) {
>           goto fail;
>       }
>
>       offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
> -    ret = blk_pwrite(blk, offset, buf, HEADER_SIZE);
> +    ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0);
>       if (ret < 0) {
>           goto fail;
>       }
> @@ -799,7 +799,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
>
>       memset(buf, 0xFF, 512);
>       for (i = 0; i < (num_bat_entries * 4 + 511) / 512; i++) {
> -        ret = blk_pwrite(blk, offset, buf, 512);
> +        ret = blk_pwrite(blk, offset, buf, 512, 0);
>           if (ret < 0) {
>               goto fail;
>           }
> @@ -826,7 +826,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
>       /* Write the header */
>       offset = 512;
>
> -    ret = blk_pwrite(blk, offset, buf, 1024);
> +    ret = blk_pwrite(blk, offset, buf, 1024, 0);
>       if (ret < 0) {
>           goto fail;
>       }
> @@ -848,7 +848,7 @@ static int create_fixed_disk(BlockBackend *blk, uint8_t *buf,
>           return ret;
>       }
>
> -    ret = blk_pwrite(blk, total_size - HEADER_SIZE, buf, HEADER_SIZE);
> +    ret = blk_pwrite(blk, total_size - HEADER_SIZE, buf, HEADER_SIZE, 0);
>       if (ret < 0) {
>           return ret;
>       }
> diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
> index 802636e..019f25d 100644
> --- a/hw/nvram/spapr_nvram.c
> +++ b/hw/nvram/spapr_nvram.c
> @@ -124,7 +124,7 @@ static void rtas_nvram_store(PowerPCCPU *cpu, sPAPRMachineState *spapr,
>
>       alen = len;
>       if (nvram->blk) {
> -        alen = blk_pwrite(nvram->blk, offset, membuf, len);
> +        alen = blk_pwrite(nvram->blk, offset, membuf, len, 0);
>       }
>
>       assert(nvram->buf);
> @@ -190,7 +190,7 @@ static int spapr_nvram_post_load(void *opaque, int version_id)
>       sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(opaque);
>
>       if (nvram->blk) {
> -        int alen = blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size);
> +        int alen = blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0);
>
>           if (alen < 0) {
>               return alen;
> diff --git a/nbd/server.c b/nbd/server.c
> index aa252a4..9be0a99 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -1154,7 +1154,7 @@ static void nbd_trip(void *opaque)
>           TRACE("Writing to device");
>
>           ret = blk_pwrite(exp->blk, request.from + exp->dev_offset,
> -                        req->data, request.len);
> +                         req->data, request.len, 0);
>           if (ret < 0) {
>               LOG("writing to file failed");
>               reply.error = -ret;
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index e34f777..e26e543 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -474,7 +474,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
>           return -ERANGE;
>       }
>
> -    *total = blk_pwrite(blk, offset, (uint8_t *)buf, count);
> +    *total = blk_pwrite(blk, offset, (uint8_t *)buf, count, 0);
>       if (*total < 0) {
>           return *total;
>       }
Acked-by: Denis V. Lunev <den at openvz.org>


More information about the sheepdog mailing list