From nobody Thu May 2 13:58:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1492590779929910.2148311579431; Wed, 19 Apr 2017 01:32:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7B9B3DBC8; Wed, 19 Apr 2017 08:32:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 286BD51DF1; Wed, 19 Apr 2017 08:32:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8ECDB18523C5; Wed, 19 Apr 2017 08:32:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3J8Wspg009900 for ; Wed, 19 Apr 2017 04:32:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 457927ADBF; Wed, 19 Apr 2017 08:32:54 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C38D97ADA4 for ; Wed, 19 Apr 2017 08:32:52 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id CF0231004A1; Wed, 19 Apr 2017 10:32:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A7B9B3DBC8 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A7B9B3DBC8 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 19 Apr 2017 10:32:49 +0200 Message-Id: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] locking: Add support for sanlock_strerror X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 19 Apr 2017 08:32:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The recently added sanlock_strerror function can be used to translate sanlock's numeric errors into human readable strings. https://bugzilla.redhat.com/show_bug.cgi?id=3D1409511 Signed-off-by: Jiri Denemark --- m4/virt-sanlock.m4 | 7 ++ src/locking/lock_driver_sanlock.c | 154 ++++++++++++++++++++++++++--------= ---- 2 files changed, 115 insertions(+), 46 deletions(-) diff --git a/m4/virt-sanlock.m4 b/m4/virt-sanlock.m4 index e4476cae4..00de7980e 100644 --- a/m4/virt-sanlock.m4 +++ b/m4/virt-sanlock.m4 @@ -61,6 +61,13 @@ AC_DEFUN([LIBVIRT_CHECK_SANLOCK],[ [whether sanlock supports sanlock_write_lockspace]) fi =20 + AC_CHECK_LIB([sanlock_client], [sanlock_strerror], + [sanlock_strerror=3Dyes], [sanlock_strerror=3Dno]) + if test "x$sanlock_strerror" =3D "xyes" ; then + AC_DEFINE_UNQUOTED([HAVE_SANLOCK_STRERROR], 1, + [whether sanlock supports sanlock_strerror]) + fi + CPPFLAGS=3D"$old_cppflags" LIBS=3D"$old_libs" fi diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 280219f72..b5e69c472 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -97,6 +97,25 @@ struct _virLockManagerSanlockPrivate { bool registered; }; =20 + +static bool +ATTRIBUTE_NONNULL(2) +virLockManagerSanlockError(int err, + char **message) +{ + if (err <=3D -200) { +#if HAVE_SANLOCK_STRERROR + ignore_value(VIR_STRDUP_QUIET(*message, sanlock_strerror(err))); +#else + ignore_value(virAsprintfQuiet(message, _("sanlock error %d"), err)= ); +#endif + return true; + } else { + return false; + } +} + + /* * sanlock plugin for the libvirt virLockManager API */ @@ -263,14 +282,17 @@ virLockManagerSanlockSetupLockspace(virLockManagerSan= lockDriverPtr driver) } =20 if ((rv =3D sanlock_align(&ls.host_id_disk)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to query sector size %s: erro= r %d"), - path, rv); - else + _("Unable to query sector size %s: %s"), + path, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to query sector size %s= "), path); + } goto error_unlink; } =20 @@ -292,14 +314,17 @@ virLockManagerSanlockSetupLockspace(virLockManagerSan= lockDriverPtr driver) } =20 if ((rv =3D virLockManagerSanlockInitLockspace(driver, &ls) < = 0)) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to initialize lockspace %s: e= rror %d"), - path, rv); - else + _("Unable to initialize lockspace %s: %= s"), + path, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to initialize lockspace= %s"), path); + } goto error_unlink; } VIR_DEBUG("Lockspace %s has been initialized", path); @@ -362,14 +387,17 @@ virLockManagerSanlockSetupLockspace(virLockManagerSan= lockDriverPtr driver) goto retry; } if (-rv !=3D EEXIST) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to add lockspace %s: error %d"), - path, rv); - else + _("Unable to add lockspace %s: %s"), + path, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to add lockspace %s"), path); + } goto error; } else { VIR_DEBUG("Lockspace %s is already registered", path); @@ -694,14 +722,17 @@ virLockManagerSanlockCreateLease(virLockManagerSanloc= kDriverPtr driver, } =20 if ((rv =3D sanlock_align(&res->disks[0])) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to query sector size %s: erro= r %d"), - res->disks[0].path, rv); - else + _("Unable to query sector size %s: %s"), + res->disks[0].path, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to query sector size %s= "), res->disks[0].path); + } goto error_unlink; } =20 @@ -723,14 +754,17 @@ virLockManagerSanlockCreateLease(virLockManagerSanloc= kDriverPtr driver, } =20 if ((rv =3D sanlock_init(NULL, res, 0, 0)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to initialize lease %s: error= %d"), - res->disks[0].path, rv); - else + _("Unable to initialize lease %s: %s"), + res->disks[0].path, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to initialize lease %s"= ), res->disks[0].path); + } goto error_unlink; } VIR_DEBUG("Lease %s has been initialized", res->disks[0].path); @@ -867,10 +901,12 @@ virLockManagerSanlockRegisterKillscript(int sock, } =20 if ((rv =3D sanlock_killpath(sock, 0, path, args)) < 0) { - if (rv <=3D -200) { + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to register lock failure action:" - " error %d"), rv); + _("Failed to register lock failure action: %s"), + NULLSTR(err)); + VIR_FREE(err); } else { virReportSystemError(-rv, "%s", _("Failed to register lock failure" @@ -934,13 +970,16 @@ static int virLockManagerSanlockAcquire(virLockManage= rPtr lock, if (priv->vm_pid =3D=3D getpid()) { VIR_DEBUG("Register sanlock %d", flags); if ((sock =3D sanlock_register()) < 0) { - if (sock <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(sock, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to open socket to sanlock daemon:= error %d"), - sock); - else + _("Failed to open socket to sanlock daemon:= %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-sock, "%s", _("Failed to open socket to sanlock d= aemon")); + } goto error; } =20 @@ -971,14 +1010,17 @@ static int virLockManagerSanlockAcquire(virLockManag= erPtr lock, if ((rv =3D sanlock_state_to_args((char *)state, &res_count, &res_args)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse lock state %s: error %d"= ), - state, rv); - else + _("Unable to parse lock state %s: %s"), + state, NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, _("Unable to parse lock state %s"), state); + } goto error; } res_free =3D true; @@ -992,12 +1034,16 @@ static int virLockManagerSanlockAcquire(virLockManag= erPtr lock, if ((rv =3D sanlock_acquire(sock, priv->vm_pid, 0, priv->res_count, priv->res_args, opt)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_RESOURCE_BUSY, - _("Failed to acquire lock: error %d"), rv); - else + _("Failed to acquire lock: %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, "%s", _("Failed to acquire lock")); + } goto error; } } @@ -1016,12 +1062,16 @@ static int virLockManagerSanlockAcquire(virLockMana= gerPtr lock, =20 if (flags & VIR_LOCK_MANAGER_ACQUIRE_RESTRICT) { if ((rv =3D sanlock_restrict(sock, SANLK_RESTRICT_ALL)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to restrict process: error %d"), = rv); - else + _("Failed to restrict process: %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, "%s", _("Failed to restrict process")); + } goto error; } } @@ -1068,12 +1118,16 @@ static int virLockManagerSanlockRelease(virLockMana= gerPtr lock, =20 if (state) { if ((rv =3D sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state= )) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to inquire lock: error %d"), rv); - else + _("Failed to inquire lock: %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, "%s", _("Failed to inquire lock")); + } return -1; } =20 @@ -1083,12 +1137,16 @@ static int virLockManagerSanlockRelease(virLockMana= gerPtr lock, =20 if ((rv =3D sanlock_release(-1, priv->vm_pid, 0, res_count, priv->res_args)) < 0) { - if (rv <=3D -200) + char *err =3D NULL; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to release lock: error %d"), rv); - else + _("Failed to release lock: %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, "%s", _("Failed to release lock")); + } return -1; } =20 @@ -1118,12 +1176,16 @@ static int virLockManagerSanlockInquire(virLockMana= gerPtr lock, } =20 if ((rv =3D sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state)) <= 0) { - if (rv <=3D -200) + char *err; + if (virLockManagerSanlockError(rv, &err)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to inquire lock: error %d"), rv); - else + _("Failed to inquire lock: %s"), + NULLSTR(err)); + VIR_FREE(err); + } else { virReportSystemError(-rv, "%s", _("Failed to inquire lock")); + } return -1; } =20 --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list