[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 13/25] nbd: Enforce sector alignment
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH 13/25] nbd: Enforce sector alignment |
Date: |
Wed, 25 Feb 2015 13:08:26 -0500 |
Operations on NBDs must be aligned to BDRV_SECTOR_SIZE. Enforce this.
Signed-off-by: Max Reitz <address@hidden>
---
nbd.c | 21 +++++++++++++++++++++
qemu-nbd.c | 4 ++++
2 files changed, 25 insertions(+)
diff --git a/nbd.c b/nbd.c
index 1cd7757..5764fd1 100644
--- a/nbd.c
+++ b/nbd.c
@@ -990,6 +990,13 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t
dev_offset, off_t size,
{
NBDEjectNotifier *n;
NBDExport *exp = g_malloc0(sizeof(NBDExport));
+
+ if (dev_offset % BDRV_SECTOR_SIZE) {
+ error_setg(errp, "NBD export offset must be a multiple of %i",
+ (int)BDRV_SECTOR_SIZE);
+ goto fail;
+ }
+
exp->refcount = 1;
QTAILQ_INIT(&exp->clients);
exp->blk = blk;
@@ -1257,6 +1264,20 @@ static void nbd_trip(void *opaque)
goto invalid_request;
}
+ if (command == NBD_CMD_READ ||
+ command == NBD_CMD_WRITE ||
+ command == NBD_CMD_TRIM)
+ {
+ if (request.from % BDRV_SECTOR_SIZE) {
+ goto invalid_request;
+ }
+ assert(!((request.from + exp->dev_offset) % BDRV_SECTOR_SIZE));
+
+ if (request.len % BDRV_SECTOR_SIZE) {
+ goto invalid_request;
+ }
+ }
+
switch (command) {
case NBD_CMD_READ:
TRACE("Request type is READ");
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 511857e..cc13664 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -535,6 +535,10 @@ int main(int argc, char **argv)
if (errno) {
err(EXIT_FAILURE, "Invalid offset `%s'", optarg);
}
+ if (dev_offset % BDRV_SECTOR_SIZE) {
+ errx(EXIT_FAILURE, "Offset must be a multiple of %i",
+ (int)BDRV_SECTOR_SIZE);
+ }
break;
case 'l':
if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) {
--
2.1.0
- [Qemu-block] [PATCH 05/25] nbd: Avoid generic -EINVAL, (continued)
- [Qemu-block] [PATCH 05/25] nbd: Avoid generic -EINVAL, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 09/25] qemu-nbd: fork() can fail, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 06/25] nbd: Pass return value from nbd_handle_list(), Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 08/25] nbd: Handle blk_getlength() failure, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 04/25] nbd: Fix response to invalid requests, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 10/25] nbd: Fix potential signed overflow issues, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 01/25] util/uri: Add overflow check to rfc3986_parse_port, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 14/25] coroutine: Add co_yield_timeout(), Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 15/25] coroutine-io: Return -errno in case of error, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 07/25] nbd: Add "failed to open export" error message, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 13/25] nbd: Enforce sector alignment,
Max Reitz <=
- [Qemu-block] [PATCH 12/25] nbd: Set block size to BDRV_SECTOR_SIZE, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 11/25] qemu-nbd: Fix and improve input verification, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 22/25] iotests: Add _timeout function, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 20/25] block/nbd: Comment on discard/flush silently failing, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 16/25] coroutine-io: Add I/O functions with timeout, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 23/25] iotests: Add test for invalid qemu-nbd parameters, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 21/25] nbd: Drop unexpected data for NBD_OPT_LIST, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 25/25] iotests: Add test for a non-existing NBD export, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 19/25] nbd: Fix interpretation of the export flags, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 18/25] nbd: Fix nbd_receive_options(), Max Reitz, 2015/02/25