[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 77/85] block/file-posix: Preallocation for truncate
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 77/85] block/file-posix: Preallocation for truncate |
Date: |
Tue, 11 Jul 2017 18:08:06 +0200 |
By using raw_regular_truncate() in raw_truncate(), we can now easily
support preallocation.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/file-posix.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 59154ea..cfbb236 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1745,12 +1745,6 @@ static int raw_truncate(BlockDriverState *bs, int64_t
offset,
struct stat st;
int ret;
- if (prealloc != PREALLOC_MODE_OFF) {
- error_setg(errp, "Unsupported preallocation mode '%s'",
- PreallocMode_lookup[prealloc]);
- return -ENOTSUP;
- }
-
if (fstat(s->fd, &st)) {
ret = -errno;
error_setg_errno(errp, -ret, "Failed to fstat() the file");
@@ -1758,12 +1752,16 @@ static int raw_truncate(BlockDriverState *bs, int64_t
offset,
}
if (S_ISREG(st.st_mode)) {
- if (ftruncate(s->fd, offset) < 0) {
- ret = -errno;
- error_setg_errno(errp, -ret, "Failed to resize the file");
- return ret;
- }
- } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
+ return raw_regular_truncate(s->fd, offset, prealloc, errp);
+ }
+
+ if (prealloc != PREALLOC_MODE_OFF) {
+ error_setg(errp, "Preallocation mode '%s' unsupported for this "
+ "non-regular file", PreallocMode_lookup[prealloc]);
+ return -ENOTSUP;
+ }
+
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
if (offset > raw_getlength(bs)) {
error_setg(errp, "Cannot grow device files");
return -EINVAL;
--
2.9.4
- [Qemu-block] [PULL 68/85] qemu-iotests: support per-format golden output files, (continued)
- [Qemu-block] [PULL 68/85] qemu-iotests: support per-format golden output files, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 67/85] qemu-img: add measure subcommand, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 70/85] block: Add PreallocMode to BD.bdrv_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 69/85] iotests: add test 178 for qemu-img measure, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 71/85] block: Add PreallocMode to bdrv_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 72/85] block: Add PreallocMode to blk_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 73/85] qemu-img: Expose PreallocMode for resizing, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 74/85] block/file-posix: Small fixes in raw_create(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 75/85] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 76/85] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 77/85] block/file-posix: Preallocation for truncate,
Max Reitz <=
- [Qemu-block] [PULL 78/85] block/qcow2: Generalize preallocate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 79/85] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 80/85] block/qcow2: Metadata preallocation for truncate, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 81/85] block/qcow2: Add qcow2_refcount_area(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 82/85] block/qcow2: Rename "fail_block" to just "fail", Max Reitz, 2017/07/11
- [Qemu-block] [PULL 83/85] block/qcow2: falloc/full preallocating growth, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 84/85] iotests: Add preallocated resize test for raw, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 85/85] iotests: Add preallocated growth test for qcow2, Max Reitz, 2017/07/11
- Re: [Qemu-block] [Qemu-devel] [PULL 00/85] Block layer patches, Peter Maydell, 2017/07/13