diff mbox

[PATCHv5,6/6] block/iscsi: check for oversized requests

Message ID 1414253919-3044-7-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Oct. 25, 2014, 4:18 p.m. UTC
Cancel oversized requests early. They would generate
an iSCSI protocol error anyway; after having transferred
possibly a lot of data over the wire.

Suggested-By: Max Reitz <mreitz@redhat.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Max Reitz Oct. 27, 2014, 8:35 a.m. UTC | #1
On 2014-10-25 at 18:18, Peter Lieven wrote:
> Cancel oversized requests early. They would generate
> an iSCSI protocol error anyway; after having transferred
> possibly a lot of data over the wire.
>
> Suggested-By: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>   block/iscsi.c |   12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 85131b7..8747fc3 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -367,6 +367,12 @@ static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,
>           return -EINVAL;
>       }
>   
> +    if (bs->bl.max_transfer_length && nb_sectors > bs->bl.max_transfer_length) {
> +        error_report("iSCSI Error: Write of %d sectors exceeds max_xfer_len "
> +                     "of %d sectors.", nb_sectors, bs->bl.max_transfer_length);
> +        return -EINVAL;
> +    }
> +
>       lba = sector_qemu2lun(sector_num, iscsilun);
>       num_sectors = sector_qemu2lun(nb_sectors, iscsilun);
>       iscsi_co_init_iscsitask(iscsilun, &iTask);
> @@ -534,6 +540,12 @@ static int coroutine_fn iscsi_co_readv(BlockDriverState *bs,
>           return -EINVAL;
>       }
>   
> +    if (bs->bl.max_transfer_length && nb_sectors > bs->bl.max_transfer_length) {
> +        error_report("iSCSI Error: Read of %d sectors exceeds max_xfer_len "
> +                     "of %d sectors.", nb_sectors, bs->bl.max_transfer_length);
> +        return -EINVAL;
> +    }
> +
>       if (iscsilun->lbprz && nb_sectors >= ISCSI_CHECKALLOC_THRES &&
>           !iscsi_allocationmap_is_allocated(iscsilun, sector_num, nb_sectors)) {
>           int64_t ret;

I think to remember someone telling me there should not be full stops at 
the end of error messages. I can cope with it, though.

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/block/iscsi.c b/block/iscsi.c
index 85131b7..8747fc3 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -367,6 +367,12 @@  static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,
         return -EINVAL;
     }
 
+    if (bs->bl.max_transfer_length && nb_sectors > bs->bl.max_transfer_length) {
+        error_report("iSCSI Error: Write of %d sectors exceeds max_xfer_len "
+                     "of %d sectors.", nb_sectors, bs->bl.max_transfer_length);
+        return -EINVAL;
+    }
+
     lba = sector_qemu2lun(sector_num, iscsilun);
     num_sectors = sector_qemu2lun(nb_sectors, iscsilun);
     iscsi_co_init_iscsitask(iscsilun, &iTask);
@@ -534,6 +540,12 @@  static int coroutine_fn iscsi_co_readv(BlockDriverState *bs,
         return -EINVAL;
     }
 
+    if (bs->bl.max_transfer_length && nb_sectors > bs->bl.max_transfer_length) {
+        error_report("iSCSI Error: Read of %d sectors exceeds max_xfer_len "
+                     "of %d sectors.", nb_sectors, bs->bl.max_transfer_length);
+        return -EINVAL;
+    }
+
     if (iscsilun->lbprz && nb_sectors >= ISCSI_CHECKALLOC_THRES &&
         !iscsi_allocationmap_is_allocated(iscsilun, sector_num, nb_sectors)) {
         int64_t ret;