diff mbox

[14/27] vhost-user-scsi: assert() in iscsi_add_lun()

Message ID 20170823162004.27337-15-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Aug. 23, 2017, 4:19 p.m. UTC
Instead of a preliminary check, add an assert to the function that has
the pre-condition.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 23, 2017, 5:56 p.m. UTC | #1
On 08/23/2017 01:19 PM, Marc-André Lureau wrote:
> Instead of a preliminary check, add an assert to the function that has
> the pre-condition.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   contrib/vhost-user-scsi/vhost-user-scsi.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index b40009e234..988417393f 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -255,6 +255,7 @@ static int iscsi_add_lun(iscsi_lun_t *lun, char *iscsi_uri)
>   
>       assert(lun);
>       assert(iscsi_uri);
> +    assert(!lun->iscsi_ctx);
>   
>       iscsi_ctx = iscsi_create_context(VUS_ISCSI_INITIATOR);
>       if (!iscsi_ctx) {
> @@ -664,11 +665,6 @@ static int vdev_scsi_add_iscsi_lun(vhost_scsi_dev_t *vdev_scsi,
>       assert(iscsi_uri);
>       assert(lun < VUS_MAX_LUNS);
>   
> -    if (vdev_scsi->luns[lun].iscsi_ctx) {
> -        PERR("Lun %d already configured", lun);
> -        return -1;
> -    }

the error message is lost :/

anyway:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> -
>       if (iscsi_add_lun(&vdev_scsi->luns[lun], iscsi_uri) != 0) {
>           return -1;
>       }
>
diff mbox

Patch

diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index b40009e234..988417393f 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -255,6 +255,7 @@  static int iscsi_add_lun(iscsi_lun_t *lun, char *iscsi_uri)
 
     assert(lun);
     assert(iscsi_uri);
+    assert(!lun->iscsi_ctx);
 
     iscsi_ctx = iscsi_create_context(VUS_ISCSI_INITIATOR);
     if (!iscsi_ctx) {
@@ -664,11 +665,6 @@  static int vdev_scsi_add_iscsi_lun(vhost_scsi_dev_t *vdev_scsi,
     assert(iscsi_uri);
     assert(lun < VUS_MAX_LUNS);
 
-    if (vdev_scsi->luns[lun].iscsi_ctx) {
-        PERR("Lun %d already configured", lun);
-        return -1;
-    }
-
     if (iscsi_add_lun(&vdev_scsi->luns[lun], iscsi_uri) != 0) {
         return -1;
     }