block.c (80ccf93b884a2edab5ec62634758e942bba81b7c) block.c (621f058940ea9f1ef3d8774ef3203544f1228df1)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 66 unchanged lines hidden (view full) ---

75static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
76 int64_t sector_num,
77 QEMUIOVector *qiov,
78 int nb_sectors,
79 BlockDriverCompletionFunc *cb,
80 void *opaque,
81 bool is_write);
82static void coroutine_fn bdrv_co_do_rw(void *opaque);
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 66 unchanged lines hidden (view full) ---

75static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
76 int64_t sector_num,
77 QEMUIOVector *qiov,
78 int nb_sectors,
79 BlockDriverCompletionFunc *cb,
80 void *opaque,
81 bool is_write);
82static void coroutine_fn bdrv_co_do_rw(void *opaque);
83static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
84 int64_t sector_num, int nb_sectors);
83
84static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
85 bool is_write, double elapsed_time, uint64_t *wait);
86static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
87 double elapsed_time, uint64_t *wait);
88static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
89 bool is_write, int64_t *wait);
90

--- 1612 unchanged lines hidden (view full) ---

1703 ret = drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors,
1704 &bounce_qiov);
1705 if (ret < 0) {
1706 goto err;
1707 }
1708
1709 if (drv->bdrv_co_write_zeroes &&
1710 buffer_is_zero(bounce_buffer, iov.iov_len)) {
85
86static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
87 bool is_write, double elapsed_time, uint64_t *wait);
88static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
89 double elapsed_time, uint64_t *wait);
90static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
91 bool is_write, int64_t *wait);
92

--- 1612 unchanged lines hidden (view full) ---

1705 ret = drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors,
1706 &bounce_qiov);
1707 if (ret < 0) {
1708 goto err;
1709 }
1710
1711 if (drv->bdrv_co_write_zeroes &&
1712 buffer_is_zero(bounce_buffer, iov.iov_len)) {
1711 ret = drv->bdrv_co_write_zeroes(bs, cluster_sector_num,
1712 cluster_nb_sectors);
1713 ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num,
1714 cluster_nb_sectors);
1713 } else {
1714 ret = drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors,
1715 &bounce_qiov);
1716 }
1717
1718 if (ret < 0) {
1719 /* It might be okay to ignore write errors for guest requests. If this
1720 * is a deliberate copy-on-read then we don't want to ignore the error.

--- 93 unchanged lines hidden (view full) ---

1814static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
1815 int64_t sector_num, int nb_sectors)
1816{
1817 BlockDriver *drv = bs->drv;
1818 QEMUIOVector qiov;
1819 struct iovec iov;
1820 int ret;
1821
1715 } else {
1716 ret = drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors,
1717 &bounce_qiov);
1718 }
1719
1720 if (ret < 0) {
1721 /* It might be okay to ignore write errors for guest requests. If this
1722 * is a deliberate copy-on-read then we don't want to ignore the error.

--- 93 unchanged lines hidden (view full) ---

1816static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
1817 int64_t sector_num, int nb_sectors)
1818{
1819 BlockDriver *drv = bs->drv;
1820 QEMUIOVector qiov;
1821 struct iovec iov;
1822 int ret;
1823
1824 /* TODO Emulate only part of misaligned requests instead of letting block
1825 * drivers return -ENOTSUP and emulate everything */
1826
1822 /* First try the efficient write zeroes operation */
1823 if (drv->bdrv_co_write_zeroes) {
1827 /* First try the efficient write zeroes operation */
1828 if (drv->bdrv_co_write_zeroes) {
1824 return drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
1829 ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
1830 if (ret != -ENOTSUP) {
1831 return ret;
1832 }
1825 }
1826
1827 /* Fall back to bounce buffer if write zeroes is unsupported */
1828 iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
1829 iov.iov_base = qemu_blockalign(bs, iov.iov_len);
1830 memset(iov.iov_base, 0, iov.iov_len);
1831 qemu_iovec_init_external(&qiov, &iov, 1);
1832

--- 2308 unchanged lines hidden ---
1833 }
1834
1835 /* Fall back to bounce buffer if write zeroes is unsupported */
1836 iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
1837 iov.iov_base = qemu_blockalign(bs, iov.iov_len);
1838 memset(iov.iov_base, 0, iov.iov_len);
1839 qemu_iovec_init_external(&qiov, &iov, 1);
1840

--- 2308 unchanged lines hidden ---