diff mbox

[V2] block/iscsi: restore compatiblity with libiscsi 1.9.0

Message ID 1435313881-19366-1-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven June 26, 2015, 10:18 a.m. UTC
RHEL7 and others are stuck with libiscsi 1.9.0 since there
unfortunately was an ABI breakage after that release.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
v1->v2: - do not use reserved macro names [Paolo]
        - change text in qemu-options.hx to "libiscsi 1.15.0 or greater"

 block/iscsi.c   |   32 +++++++++++++++++++++++++++-----
 configure       |    6 +++---
 qemu-options.hx |    3 ++-
 3 files changed, 32 insertions(+), 9 deletions(-)

Comments

Paolo Bonzini June 26, 2015, 11:18 a.m. UTC | #1
On 26/06/2015 12:18, Peter Lieven wrote:
> RHEL7 and others are stuck with libiscsi 1.9.0 since there
> unfortunately was an ABI breakage after that release.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v1->v2: - do not use reserved macro names [Paolo]
>         - change text in qemu-options.hx to "libiscsi 1.15.0 or greater"
> 
>  block/iscsi.c   |   32 +++++++++++++++++++++++++++-----
>  configure       |    6 +++---
>  qemu-options.hx |    3 ++-
>  3 files changed, 32 insertions(+), 9 deletions(-)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index f19a56a..fd4a66e 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -168,6 +168,19 @@ static inline unsigned exp_random(double mean)
>      return -mean * log((double)rand() / RAND_MAX);
>  }
>  
> +/* SCSI_STATUS_TASK_SET_FULL and SCSI_STATUS_TIMEOUT were introduced
> + * in libiscsi 1.10.0 as part of an enum. The LIBISCSI_API_VERSION
> + * macro was introduced in 1.11.0. So use the API_VERSION macro as
> + * a hint that the macros are defined and define them ourselves
> + * otherwise to keep the required libiscsi version at 1.9.0 */
> +#if !defined(LIBISCSI_API_VERSION)
> +#define QEMU_SCSI_STATUS_TASK_SET_FULL  0x28
> +#define QEMU_SCSI_STATUS_TIMEOUT        0x0f000002
> +#else
> +#define QEMU_SCSI_STATUS_TASK_SET_FULL  SCSI_STATUS_TASK_SET_FULL
> +#define QEMU_SCSI_STATUS_TIMEOUT        SCSI_STATUS_TIMEOUT
> +#endif
> +
>  static void
>  iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
>                          void *command_data, void *opaque)
> @@ -188,11 +201,12 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
>                  iTask->do_retry = 1;
>                  goto out;
>              }
> -            if (status == SCSI_STATUS_BUSY || status == SCSI_STATUS_TIMEOUT ||
> -                status == SCSI_STATUS_TASK_SET_FULL) {
> +            if (status == SCSI_STATUS_BUSY ||
> +                status == QEMU_SCSI_STATUS_TIMEOUT ||
> +                status == QEMU_SCSI_STATUS_TASK_SET_FULL) {
>                  unsigned retry_time =
>                      exp_random(iscsi_retry_times[iTask->retries - 1]);
> -                if (status == SCSI_STATUS_TIMEOUT) {
> +                if (status == QEMU_SCSI_STATUS_TIMEOUT) {
>                      /* make sure the request is rescheduled AFTER the
>                       * reconnect is initiated */
>                      retry_time = EVENT_INTERVAL * 2;
> @@ -1358,7 +1372,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
>      QemuOpts *opts;
>      Error *local_err = NULL;
>      const char *filename;
> -    int i, ret = 0;
> +    int i, ret = 0, timeout = 0;
>  
>      opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
>      qemu_opts_absorb_qdict(opts, options, &local_err);
> @@ -1428,7 +1442,15 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
>          goto out;
>      }
>  
> -    iscsi_set_timeout(iscsi, parse_timeout(iscsi_url->target));
> +    /* timeout handling is broken in libiscsi before 1.15.0 */
> +    timeout = parse_timeout(iscsi_url->target);
> +#if defined(LIBISCSI_API_VERSION) && LIBISCSI_API_VERSION >= 20150621
> +    iscsi_set_timeout(iscsi, timeout);
> +#else
> +    if (timeout) {
> +        error_report("iSCSI: ignoring timeout value for libiscsi <1.15.0");
> +    }
> +#endif
>  
>      if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
>          error_setg(errp, "iSCSI: Failed to connect to LUN : %s",
> diff --git a/configure b/configure
> index 2ed9db2..222694f 100755
> --- a/configure
> +++ b/configure
> @@ -3660,15 +3660,15 @@ if compile_prog "" "" ; then
>  fi
>  
>  ##########################################
> -# Do we have libiscsi >= 1.10.0
> +# Do we have libiscsi >= 1.9.0
>  if test "$libiscsi" != "no" ; then
> -  if $pkg_config --atleast-version=1.10.0 libiscsi; then
> +  if $pkg_config --atleast-version=1.9.0 libiscsi; then
>      libiscsi="yes"
>      libiscsi_cflags=$($pkg_config --cflags libiscsi)
>      libiscsi_libs=$($pkg_config --libs libiscsi)
>    else
>      if test "$libiscsi" = "yes" ; then
> -      feature_not_found "libiscsi" "Install libiscsi >= 1.10.0"
> +      feature_not_found "libiscsi" "Install libiscsi >= 1.9.0"
>      fi
>      libiscsi="no"
>    fi
> diff --git a/qemu-options.hx b/qemu-options.hx
> index ca37481..389cf64 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2293,7 +2293,8 @@ line or a configuration file.
>  
>  Since version Qemu 2.4 it is possible to specify a iSCSI request timeout to detect
>  stalled requests and force a reestablishment of the session. The timeout
> -is specified in seconds. The default is 0 which means no timeout.
> +is specified in seconds. The default is 0 which means no timeout. Libiscsi
> +1.15.0 or greater is required for this feature.
>  
>  Example (without authentication):
>  @example
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Stefan Hajnoczi June 29, 2015, 3:50 p.m. UTC | #2
On Fri, Jun 26, 2015 at 12:18:01PM +0200, Peter Lieven wrote:
> RHEL7 and others are stuck with libiscsi 1.9.0 since there
> unfortunately was an ABI breakage after that release.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v1->v2: - do not use reserved macro names [Paolo]
>         - change text in qemu-options.hx to "libiscsi 1.15.0 or greater"
> 
>  block/iscsi.c   |   32 +++++++++++++++++++++++++++-----
>  configure       |    6 +++---
>  qemu-options.hx |    3 ++-
>  3 files changed, 32 insertions(+), 9 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan
diff mbox

Patch

diff --git a/block/iscsi.c b/block/iscsi.c
index f19a56a..fd4a66e 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -168,6 +168,19 @@  static inline unsigned exp_random(double mean)
     return -mean * log((double)rand() / RAND_MAX);
 }
 
+/* SCSI_STATUS_TASK_SET_FULL and SCSI_STATUS_TIMEOUT were introduced
+ * in libiscsi 1.10.0 as part of an enum. The LIBISCSI_API_VERSION
+ * macro was introduced in 1.11.0. So use the API_VERSION macro as
+ * a hint that the macros are defined and define them ourselves
+ * otherwise to keep the required libiscsi version at 1.9.0 */
+#if !defined(LIBISCSI_API_VERSION)
+#define QEMU_SCSI_STATUS_TASK_SET_FULL  0x28
+#define QEMU_SCSI_STATUS_TIMEOUT        0x0f000002
+#else
+#define QEMU_SCSI_STATUS_TASK_SET_FULL  SCSI_STATUS_TASK_SET_FULL
+#define QEMU_SCSI_STATUS_TIMEOUT        SCSI_STATUS_TIMEOUT
+#endif
+
 static void
 iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
                         void *command_data, void *opaque)
@@ -188,11 +201,12 @@  iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
                 iTask->do_retry = 1;
                 goto out;
             }
-            if (status == SCSI_STATUS_BUSY || status == SCSI_STATUS_TIMEOUT ||
-                status == SCSI_STATUS_TASK_SET_FULL) {
+            if (status == SCSI_STATUS_BUSY ||
+                status == QEMU_SCSI_STATUS_TIMEOUT ||
+                status == QEMU_SCSI_STATUS_TASK_SET_FULL) {
                 unsigned retry_time =
                     exp_random(iscsi_retry_times[iTask->retries - 1]);
-                if (status == SCSI_STATUS_TIMEOUT) {
+                if (status == QEMU_SCSI_STATUS_TIMEOUT) {
                     /* make sure the request is rescheduled AFTER the
                      * reconnect is initiated */
                     retry_time = EVENT_INTERVAL * 2;
@@ -1358,7 +1372,7 @@  static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     const char *filename;
-    int i, ret = 0;
+    int i, ret = 0, timeout = 0;
 
     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
     qemu_opts_absorb_qdict(opts, options, &local_err);
@@ -1428,7 +1442,15 @@  static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         goto out;
     }
 
-    iscsi_set_timeout(iscsi, parse_timeout(iscsi_url->target));
+    /* timeout handling is broken in libiscsi before 1.15.0 */
+    timeout = parse_timeout(iscsi_url->target);
+#if defined(LIBISCSI_API_VERSION) && LIBISCSI_API_VERSION >= 20150621
+    iscsi_set_timeout(iscsi, timeout);
+#else
+    if (timeout) {
+        error_report("iSCSI: ignoring timeout value for libiscsi <1.15.0");
+    }
+#endif
 
     if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
         error_setg(errp, "iSCSI: Failed to connect to LUN : %s",
diff --git a/configure b/configure
index 2ed9db2..222694f 100755
--- a/configure
+++ b/configure
@@ -3660,15 +3660,15 @@  if compile_prog "" "" ; then
 fi
 
 ##########################################
-# Do we have libiscsi >= 1.10.0
+# Do we have libiscsi >= 1.9.0
 if test "$libiscsi" != "no" ; then
-  if $pkg_config --atleast-version=1.10.0 libiscsi; then
+  if $pkg_config --atleast-version=1.9.0 libiscsi; then
     libiscsi="yes"
     libiscsi_cflags=$($pkg_config --cflags libiscsi)
     libiscsi_libs=$($pkg_config --libs libiscsi)
   else
     if test "$libiscsi" = "yes" ; then
-      feature_not_found "libiscsi" "Install libiscsi >= 1.10.0"
+      feature_not_found "libiscsi" "Install libiscsi >= 1.9.0"
     fi
     libiscsi="no"
   fi
diff --git a/qemu-options.hx b/qemu-options.hx
index ca37481..389cf64 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2293,7 +2293,8 @@  line or a configuration file.
 
 Since version Qemu 2.4 it is possible to specify a iSCSI request timeout to detect
 stalled requests and force a reestablishment of the session. The timeout
-is specified in seconds. The default is 0 which means no timeout.
+is specified in seconds. The default is 0 which means no timeout. Libiscsi
+1.15.0 or greater is required for this feature.
 
 Example (without authentication):
 @example