[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 65/69] block: Evaluate @exact in protocol drivers
From: |
Max Reitz |
Subject: |
[PULL 65/69] block: Evaluate @exact in protocol drivers |
Date: |
Mon, 28 Oct 2019 13:14:57 +0100 |
We have two protocol drivers that return success when trying to shrink a
block device even though they cannot shrink it. This behavior is now
only allowed with exact=false, so they should return an error with
exact=true.
Signed-off-by: Max Reitz <address@hidden>
Message-id: address@hidden
Reviewed-by: Maxim Levitsky <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block/file-posix.c | 8 +++++++-
block/iscsi.c | 7 ++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index a3e8a8aa70..e0ea1a7446 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2033,6 +2033,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverState
*bs, int64_t offset,
}
if (S_ISREG(st.st_mode)) {
+ /* Always resizes to the exact @offset */
return raw_regular_truncate(bs, s->fd, offset, prealloc, errp);
}
@@ -2043,7 +2044,12 @@ static int coroutine_fn raw_co_truncate(BlockDriverState
*bs, int64_t offset,
}
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
- if (offset > raw_getlength(bs)) {
+ int64_t cur_length = raw_getlength(bs);
+
+ if (offset != cur_length && exact) {
+ error_setg(errp, "Cannot resize device files");
+ return -ENOTSUP;
+ } else if (offset > cur_length) {
error_setg(errp, "Cannot grow device files");
return -EINVAL;
}
diff --git a/block/iscsi.c b/block/iscsi.c
index 677946cf09..2aea7e3f13 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -2127,6 +2127,7 @@ static int coroutine_fn
iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
Error **errp)
{
IscsiLun *iscsilun = bs->opaque;
+ int64_t cur_length;
Error *local_err = NULL;
if (prealloc != PREALLOC_MODE_OFF) {
@@ -2146,7 +2147,11 @@ static int coroutine_fn
iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
return -EIO;
}
- if (offset > iscsi_getlength(bs)) {
+ cur_length = iscsi_getlength(bs);
+ if (offset != cur_length && exact) {
+ error_setg(errp, "Cannot resize iSCSI devices");
+ return -ENOTSUP;
+ } else if (offset > cur_length) {
error_setg(errp, "Cannot grow iSCSI devices");
return -EINVAL;
}
--
2.21.0
- [PULL 62/69] block/cor: Drop cor_co_truncate(), (continued)
- [PULL 62/69] block/cor: Drop cor_co_truncate(), Max Reitz, 2019/10/28
- [PULL 59/69] iotests: Add peek_file* functions, Max Reitz, 2019/10/28
- [PULL 52/69] qcow2: Separate qcow2_check_read_snapshot_table(), Max Reitz, 2019/10/28
- [PULL 54/69] qcow2: Fix broken snapshot table entries, Max Reitz, 2019/10/28
- [PULL 57/69] qcow2: Repair snapshot table with too many entries, Max Reitz, 2019/10/28
- [PULL 55/69] qcow2: Keep track of the snapshot table length, Max Reitz, 2019/10/28
- [PULL 58/69] qcow2: Fix v3 snapshot table entry compliancy, Max Reitz, 2019/10/28
- [PULL 61/69] block: Handle filter truncation like native impl., Max Reitz, 2019/10/28
- [PULL 63/69] block: Do not truncate file node when formatting, Max Reitz, 2019/10/28
- [PULL 56/69] qcow2: Fix overly long snapshot tables, Max Reitz, 2019/10/28
- [PULL 65/69] block: Evaluate @exact in protocol drivers,
Max Reitz <=
- [PULL 60/69] iotests: Test qcow2's snapshot table handling, Max Reitz, 2019/10/28
- [PULL 64/69] block: Add @exact parameter to bdrv_co_truncate(), Max Reitz, 2019/10/28
- [PULL 67/69] block: Pass truncate exact=true where reasonable, Max Reitz, 2019/10/28
- [PULL 66/69] block: Let format drivers pass @exact, Max Reitz, 2019/10/28
- [PULL 69/69] qemu-iotests: restrict 264 to qcow2 only, Max Reitz, 2019/10/28
- [PULL 68/69] Revert "qemu-img: Check post-truncation size", Max Reitz, 2019/10/28
- Re: [PULL 00/69] Block patches for softfreeze, Peter Maydell, 2019/10/28