block.c (d109f80af3ad5c64c8c30e7ab21f2e342b5e9a8d) block.c (98764152ad8ec9fa4e7bb6d8e10f8a7a7ce273d7)
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

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

3187 int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
3188{
3189 trace_bdrv_co_copy_on_readv(bs, sector_num, nb_sectors);
3190
3191 return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov,
3192 BDRV_REQ_COPY_ON_READ);
3193}
3194
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

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

3187 int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
3188{
3189 trace_bdrv_co_copy_on_readv(bs, sector_num, nb_sectors);
3190
3191 return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov,
3192 BDRV_REQ_COPY_ON_READ);
3193}
3194
3195/* if no limit is specified in the BlockLimits use a default
3196 * of 32768 512-byte sectors (16 MiB) per request.
3197 */
3198#define MAX_WRITE_ZEROES_DEFAULT 32768
3195#define MAX_WRITE_ZEROES_BOUNCE_BUFFER 32768
3199
3200static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
3201 int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
3202{
3203 BlockDriver *drv = bs->drv;
3204 QEMUIOVector qiov;
3205 struct iovec iov = {0};
3206 int ret = 0;
3207
3208 int max_write_zeroes = bs->bl.max_write_zeroes ?
3196
3197static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
3198 int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
3199{
3200 BlockDriver *drv = bs->drv;
3201 QEMUIOVector qiov;
3202 struct iovec iov = {0};
3203 int ret = 0;
3204
3205 int max_write_zeroes = bs->bl.max_write_zeroes ?
3209 bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT;
3206 bs->bl.max_write_zeroes : INT_MAX;
3210
3211 while (nb_sectors > 0 && !ret) {
3212 int num = nb_sectors;
3213
3214 /* Align request. Block drivers can expect the "bulk" of the request
3215 * to be aligned.
3216 */
3217 if (bs->bl.write_zeroes_alignment

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

3237 /* First try the efficient write zeroes operation */
3238 if (drv->bdrv_co_write_zeroes) {
3239 ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags);
3240 }
3241
3242 if (ret == -ENOTSUP) {
3243 /* Fall back to bounce buffer if write zeroes is unsupported */
3244 int max_xfer_len = MIN_NON_ZERO(bs->bl.max_transfer_length,
3207
3208 while (nb_sectors > 0 && !ret) {
3209 int num = nb_sectors;
3210
3211 /* Align request. Block drivers can expect the "bulk" of the request
3212 * to be aligned.
3213 */
3214 if (bs->bl.write_zeroes_alignment

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

3234 /* First try the efficient write zeroes operation */
3235 if (drv->bdrv_co_write_zeroes) {
3236 ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags);
3237 }
3238
3239 if (ret == -ENOTSUP) {
3240 /* Fall back to bounce buffer if write zeroes is unsupported */
3241 int max_xfer_len = MIN_NON_ZERO(bs->bl.max_transfer_length,
3245 MAX_WRITE_ZEROES_DEFAULT);
3242 MAX_WRITE_ZEROES_BOUNCE_BUFFER);
3246 num = MIN(num, max_xfer_len);
3247 iov.iov_len = num * BDRV_SECTOR_SIZE;
3248 if (iov.iov_base == NULL) {
3249 iov.iov_base = qemu_try_blockalign(bs, num * BDRV_SECTOR_SIZE);
3250 if (iov.iov_base == NULL) {
3251 ret = -ENOMEM;
3252 goto fail;
3253 }

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

5092} DiscardCo;
5093static void coroutine_fn bdrv_discard_co_entry(void *opaque)
5094{
5095 DiscardCo *rwco = opaque;
5096
5097 rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
5098}
5099
3243 num = MIN(num, max_xfer_len);
3244 iov.iov_len = num * BDRV_SECTOR_SIZE;
3245 if (iov.iov_base == NULL) {
3246 iov.iov_base = qemu_try_blockalign(bs, num * BDRV_SECTOR_SIZE);
3247 if (iov.iov_base == NULL) {
3248 ret = -ENOMEM;
3249 goto fail;
3250 }

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

5089} DiscardCo;
5090static void coroutine_fn bdrv_discard_co_entry(void *opaque)
5091{
5092 DiscardCo *rwco = opaque;
5093
5094 rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
5095}
5096
5100/* if no limit is specified in the BlockLimits use a default
5101 * of 32768 512-byte sectors (16 MiB) per request.
5102 */
5103#define MAX_DISCARD_DEFAULT 32768
5104
5105int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
5106 int nb_sectors)
5107{
5108 int max_discard;
5109
5110 if (!bs->drv) {
5111 return -ENOMEDIUM;
5112 } else if (bdrv_check_request(bs, sector_num, nb_sectors)) {

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

5121 if (!(bs->open_flags & BDRV_O_UNMAP)) {
5122 return 0;
5123 }
5124
5125 if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
5126 return 0;
5127 }
5128
5097int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
5098 int nb_sectors)
5099{
5100 int max_discard;
5101
5102 if (!bs->drv) {
5103 return -ENOMEDIUM;
5104 } else if (bdrv_check_request(bs, sector_num, nb_sectors)) {

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

5113 if (!(bs->open_flags & BDRV_O_UNMAP)) {
5114 return 0;
5115 }
5116
5117 if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
5118 return 0;
5119 }
5120
5129 max_discard = bs->bl.max_discard ? bs->bl.max_discard : MAX_DISCARD_DEFAULT;
5121 max_discard = bs->bl.max_discard ? bs->bl.max_discard : INT_MAX;
5130 while (nb_sectors > 0) {
5131 int ret;
5132 int num = nb_sectors;
5133
5134 /* align request */
5135 if (bs->bl.discard_alignment &&
5136 num >= bs->bl.discard_alignment &&
5137 sector_num % bs->bl.discard_alignment) {

--- 1000 unchanged lines hidden ---
5122 while (nb_sectors > 0) {
5123 int ret;
5124 int num = nb_sectors;
5125
5126 /* align request */
5127 if (bs->bl.discard_alignment &&
5128 num >= bs->bl.discard_alignment &&
5129 sector_num % bs->bl.discard_alignment) {

--- 1000 unchanged lines hidden ---