aboutsummaryrefslogtreecommitdiff
path: root/block/block-backend.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-03-08 16:39:49 +0100
committerKevin Wolf <kwolf@redhat.com>2016-03-14 16:46:43 +0100
commitc10c9d96158ce4d05f4325e64c0ce6a5fcd64b8b (patch)
tree537c41c94738b3f151725bbf6f637ce09d0f7d7f /block/block-backend.c
parent6340472c54529c5b703deec3ab0d6bdfe644f11e (diff)
block: Introduce blk_set_allow_write_beyond_eof()
We check that the guest can't write beyond the end of its disk, but for other internal users it can make sense to allow growing a file. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r--block/block-backend.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index ebdf78a11c..03e71b4368 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -50,6 +50,8 @@ struct BlockBackend {
bool iostatus_enabled;
BlockDeviceIoStatus iostatus;
+ bool allow_write_beyond_eof;
+
NotifierList remove_bs_notifiers, insert_bs_notifiers;
};
@@ -579,6 +581,11 @@ void blk_iostatus_set_err(BlockBackend *blk, int error)
}
}
+void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow)
+{
+ blk->allow_write_beyond_eof = allow;
+}
+
static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
size_t size)
{
@@ -592,17 +599,19 @@ static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
return -ENOMEDIUM;
}
- len = blk_getlength(blk);
- if (len < 0) {
- return len;
- }
-
if (offset < 0) {
return -EIO;
}
- if (offset > len || len - offset < size) {
- return -EIO;
+ if (!blk->allow_write_beyond_eof) {
+ len = blk_getlength(blk);
+ if (len < 0) {
+ return len;
+ }
+
+ if (offset > len || len - offset < size) {
+ return -EIO;
+ }
}
return 0;