qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block-backend: Add flags to blk_truncate()

Now that node level interface bdrv_truncate() supports passing request
flags to the block driver, expose this on the BlockBackend level, too.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200424125448.63318-4-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

+22 -21
+2 -1
block.c
··· 548 548 int64_t size; 549 549 int ret; 550 550 551 - ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, &local_err); 551 + ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0, 552 + &local_err); 552 553 if (ret < 0 && ret != -ENOTSUP) { 553 554 error_propagate(errp, local_err); 554 555 return ret;
+2 -2
block/block-backend.c
··· 2137 2137 } 2138 2138 2139 2139 int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, 2140 - PreallocMode prealloc, Error **errp) 2140 + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) 2141 2141 { 2142 2142 if (!blk_is_available(blk)) { 2143 2143 error_setg(errp, "No medium inserted"); 2144 2144 return -ENOMEDIUM; 2145 2145 } 2146 2146 2147 - return bdrv_truncate(blk->root, offset, exact, prealloc, 0, errp); 2147 + return bdrv_truncate(blk->root, offset, exact, prealloc, flags, errp); 2148 2148 } 2149 2149 2150 2150 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
+2 -2
block/commit.c
··· 133 133 } 134 134 135 135 if (base_len < len) { 136 - ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, NULL); 136 + ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL); 137 137 if (ret) { 138 138 goto out; 139 139 } ··· 458 458 * grow the backing file image if possible. If not possible, 459 459 * we must return an error */ 460 460 if (length > backing_length) { 461 - ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF, 461 + ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF, 0, 462 462 &local_err); 463 463 if (ret < 0) { 464 464 error_report_err(local_err);
+1 -1
block/crypto.c
··· 115 115 * which will be used by the crypto header 116 116 */ 117 117 return blk_truncate(data->blk, data->size + headerlen, false, 118 - data->prealloc, errp); 118 + data->prealloc, 0, errp); 119 119 } 120 120 121 121
+1 -1
block/mirror.c
··· 900 900 901 901 if (s->bdev_length > base_length) { 902 902 ret = blk_truncate(s->target, s->bdev_length, false, 903 - PREALLOC_MODE_OFF, NULL); 903 + PREALLOC_MODE_OFF, 0, NULL); 904 904 if (ret < 0) { 905 905 goto immediate_exit; 906 906 }
+2 -2
block/qcow2.c
··· 3511 3511 3512 3512 /* Okay, now that we have a valid image, let's give it the right size */ 3513 3513 ret = blk_truncate(blk, qcow2_opts->size, false, qcow2_opts->preallocation, 3514 - errp); 3514 + 0, errp); 3515 3515 if (ret < 0) { 3516 3516 error_prepend(errp, "Could not resize image: "); 3517 3517 goto out; ··· 5374 5374 * Amending image options should ensure that the image has 5375 5375 * exactly the given new values, so pass exact=true here. 5376 5376 */ 5377 - ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, errp); 5377 + ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, 0, errp); 5378 5378 blk_unref(blk); 5379 5379 if (ret < 0) { 5380 5380 return ret;
+1 -1
block/qed.c
··· 677 677 * The QED format associates file length with allocation status, 678 678 * so a new file (which is empty) must have a length of 0. 679 679 */ 680 - ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, errp); 680 + ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, 0, errp); 681 681 if (ret < 0) { 682 682 goto out; 683 683 }
+1 -1
block/vdi.c
··· 875 875 876 876 if (image_type == VDI_TYPE_STATIC) { 877 877 ret = blk_truncate(blk, offset + blocks * block_size, false, 878 - PREALLOC_MODE_OFF, errp); 878 + PREALLOC_MODE_OFF, 0, errp); 879 879 if (ret < 0) { 880 880 error_prepend(errp, "Failed to statically allocate file"); 881 881 goto exit;
+2 -2
block/vhdx.c
··· 1703 1703 /* All zeroes, so we can just extend the file - the end of the BAT 1704 1704 * is the furthest thing we have written yet */ 1705 1705 ret = blk_truncate(blk, data_file_offset, false, PREALLOC_MODE_OFF, 1706 - errp); 1706 + 0, errp); 1707 1707 if (ret < 0) { 1708 1708 goto exit; 1709 1709 } 1710 1710 } else if (type == VHDX_TYPE_FIXED) { 1711 1711 ret = blk_truncate(blk, data_file_offset + image_size, false, 1712 - PREALLOC_MODE_OFF, errp); 1712 + PREALLOC_MODE_OFF, 0, errp); 1713 1713 if (ret < 0) { 1714 1714 goto exit; 1715 1715 }
+3 -3
block/vmdk.c
··· 2118 2118 int gd_buf_size; 2119 2119 2120 2120 if (flat) { 2121 - ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, errp); 2121 + ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp); 2122 2122 goto exit; 2123 2123 } 2124 2124 magic = cpu_to_be32(VMDK4_MAGIC); ··· 2182 2182 } 2183 2183 2184 2184 ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false, 2185 - PREALLOC_MODE_OFF, errp); 2185 + PREALLOC_MODE_OFF, 0, errp); 2186 2186 if (ret < 0) { 2187 2187 goto exit; 2188 2188 } ··· 2523 2523 /* bdrv_pwrite write padding zeros to align to sector, we don't need that 2524 2524 * for description file */ 2525 2525 if (desc_offset == 0) { 2526 - ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, errp); 2526 + ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, 0, errp); 2527 2527 if (ret < 0) { 2528 2528 goto exit; 2529 2529 }
+1 -1
block/vpc.c
··· 898 898 /* Add footer to total size */ 899 899 total_size += HEADER_SIZE; 900 900 901 - ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, errp); 901 + ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp); 902 902 if (ret < 0) { 903 903 return ret; 904 904 }
+1 -1
blockdev.c
··· 2741 2741 } 2742 2742 2743 2743 bdrv_drained_begin(bs); 2744 - ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp); 2744 + ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, 0, errp); 2745 2745 bdrv_drained_end(bs); 2746 2746 2747 2747 out:
+1 -1
include/sysemu/block-backend.h
··· 237 237 int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf, 238 238 int bytes); 239 239 int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, 240 - PreallocMode prealloc, Error **errp); 240 + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); 241 241 int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes); 242 242 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, 243 243 int64_t pos, int size);
+1 -1
qemu-img.c
··· 3897 3897 * resizing, so pass @exact=true. It is of no use to report 3898 3898 * success when the image has not actually been resized. 3899 3899 */ 3900 - ret = blk_truncate(blk, total_size, true, prealloc, &err); 3900 + ret = blk_truncate(blk, total_size, true, prealloc, 0, &err); 3901 3901 if (!ret) { 3902 3902 qprintf(quiet, "Image resized.\n"); 3903 3903 } else {
+1 -1
qemu-io-cmds.c
··· 1715 1715 * exact=true. It is better to err on the "emit more errors" side 1716 1716 * than to be overly permissive. 1717 1717 */ 1718 - ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, &local_err); 1718 + ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, 0, &local_err); 1719 1719 if (ret < 0) { 1720 1720 error_report_err(local_err); 1721 1721 return ret;