Commit 983a1600 authored by Eric Blake's avatar Eric Blake Committed by Kevin Wolf
Browse files

block: Switch blk_*write_zeroes() to byte interface



Sector-based blk_write() should die; convert the one-off
variant blk_write_zeroes() to use an offset/count interface
instead.  Likewise for blk_co_write_zeroes() and
blk_aio_write_zeroes().

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent b7d17f9f
Loading
Loading
Loading
Loading
+11 −22
Original line number Diff line number Diff line
@@ -814,10 +814,10 @@ int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
                  blk_write_entry, 0);
}

int blk_write_zeroes(BlockBackend *blk, int64_t sector_num,
                     int nb_sectors, BdrvRequestFlags flags)
int blk_write_zeroes(BlockBackend *blk, int64_t offset,
                     int count, BdrvRequestFlags flags)
{
    return blk_rw(blk, sector_num, NULL, nb_sectors, blk_write_entry,
    return blk_prw(blk, offset, NULL, count, blk_write_entry,
                   flags | BDRV_REQ_ZERO_WRITE);
}

@@ -930,18 +930,12 @@ static void blk_aio_write_entry(void *opaque)
    blk_aio_complete(acb);
}

BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
                                 int nb_sectors, BdrvRequestFlags flags,
BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t offset,
                                 int count, BdrvRequestFlags flags,
                                 BlockCompletionFunc *cb, void *opaque)
{
    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
        return blk_abort_aio_request(blk, cb, opaque, -EINVAL);
    }

    return blk_aio_prwv(blk, sector_num << BDRV_SECTOR_BITS,
                        nb_sectors << BDRV_SECTOR_BITS, NULL,
                        blk_aio_write_entry, flags | BDRV_REQ_ZERO_WRITE,
                        cb, opaque);
    return blk_aio_prwv(blk, offset, count, NULL, blk_aio_write_entry,
                        flags | BDRV_REQ_ZERO_WRITE, cb, opaque);
}

int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
@@ -1444,15 +1438,10 @@ void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
    return qemu_aio_get(aiocb_info, blk_bs(blk), cb, opaque);
}

int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t sector_num,
                                     int nb_sectors, BdrvRequestFlags flags)
int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t offset,
                                     int count, BdrvRequestFlags flags)
{
    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
        return -EINVAL;
    }

    return blk_co_pwritev(blk, sector_num << BDRV_SECTOR_BITS,
                          nb_sectors << BDRV_SECTOR_BITS, NULL,
    return blk_co_pwritev(blk, offset, count, NULL,
                          flags | BDRV_REQ_ZERO_WRITE);
}

+2 −1
Original line number Diff line number Diff line
@@ -516,7 +516,8 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
    if (ret < 0) {
        goto exit;
    }
    ret = blk_write_zeroes(file, 1, bat_sectors - 1, 0);
    ret = blk_write_zeroes(file, BDRV_SECTOR_SIZE,
                           (bat_sectors - 1) << BDRV_SECTOR_BITS, 0);
    if (ret < 0) {
        goto exit;
    }
+2 −2
Original line number Diff line number Diff line
@@ -1781,8 +1781,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
                         nb_sectors * s->qdev.blocksize,
                        BLOCK_ACCT_WRITE);
        r->req.aiocb = blk_aio_write_zeroes(s->qdev.conf.blk,
                                r->req.cmd.lba * (s->qdev.blocksize / 512),
                                nb_sectors * (s->qdev.blocksize / 512),
                                r->req.cmd.lba * s->qdev.blocksize,
                                nb_sectors * s->qdev.blocksize,
                                flags, scsi_aio_complete, r);
        return;
    }
+6 −6
Original line number Diff line number Diff line
@@ -96,10 +96,10 @@ int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
                          int count);
int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
              int nb_sectors);
int blk_write_zeroes(BlockBackend *blk, int64_t sector_num,
                     int nb_sectors, BdrvRequestFlags flags);
BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
                                 int nb_sectors, BdrvRequestFlags flags,
int blk_write_zeroes(BlockBackend *blk, int64_t offset,
                     int count, BdrvRequestFlags flags);
BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t offset,
                                 int count, 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,
@@ -179,8 +179,8 @@ int blk_get_open_flags_from_root_state(BlockBackend *blk);

void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
                  BlockCompletionFunc *cb, void *opaque);
int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t sector_num,
                                     int nb_sectors, BdrvRequestFlags flags);
int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t offset,
                                     int count, BdrvRequestFlags flags);
int blk_write_compressed(BlockBackend *blk, int64_t sector_num,
                         const uint8_t *buf, int nb_sectors);
int blk_truncate(BlockBackend *blk, int64_t offset);
+2 −1
Original line number Diff line number Diff line
@@ -1589,7 +1589,8 @@ static int convert_write(ImgConvertState *s, int64_t sector_num, int nb_sectors,
            if (s->has_zero_init) {
                break;
            }
            ret = blk_write_zeroes(s->target, sector_num, n, 0);
            ret = blk_write_zeroes(s->target, sector_num << BDRV_SECTOR_BITS,
                                   n << BDRV_SECTOR_BITS, 0);
            if (ret < 0) {
                return ret;
            }
Loading