[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 for-2.10 08/16] block/file-posix: Preallocation f
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v2 for-2.10 08/16] block/file-posix: Preallocation for truncate |
Date: |
Mon, 3 Apr 2017 18:09:28 +0200 |
By using raw_regular_truncate() in raw_truncate(), we can now easily
support preallocation.
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 d99ca3d6e8..0131dd8c99 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1528,12 +1528,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");
@@ -1541,12 +1535,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.12.1
- [Qemu-devel] [PATCH v2 for-2.10 00/16] block: Preallocated truncate, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 01/16] block: Add PreallocMode to BD.bdrv_truncate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 03/16] block: Add PreallocMode to blk_truncate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 02/16] block: Add PreallocMode to bdrv_truncate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 04/16] qemu-img: Expose PreallocMode for resizing, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 05/16] block/file-posix: Small fixes in raw_create(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 08/16] block/file-posix: Preallocation for truncate,
Max Reitz <=
- [Qemu-devel] [PATCH v2 for-2.10 06/16] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 09/16] block/qcow2: Generalize preallocate(), Max Reitz, 2017/04/03