From nobody Sun Feb 8 17:33:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609935990; cv=none; d=zohomail.com; s=zohoarc; b=PLzwhPIZVQlnHmOkmHbnFJmsbP50aiVXgUwlwqepV+3LgOMA9mnlklu2sihfeLp3rcsKSho/IWA9C7zZ0WuYrLuNTBaRxAr7EOGmG8Bgh1If/uezg0m2+EeAwWbNHAs6ZPXa0EB7iaojPUQxY7IV1tvqjqbwjl6SyQhK11PPP1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609935990; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nUcRbyO/k3wJlKYwAsz2CC0sZ5WgdCl3TyKdApZAdeQ=; b=LJ336quumq6hfSPvgKcEVCIKkjAEIN+bHot6vFgnKqR3wZPuL6WxkPQs08WiqiAy0tdB81RvPdquTEVuEhaLEPia+2z3tBDMpIcStRa/4nrf93k4IizVkwFRMkKI2SH6TnJMXJUqxQ3zYcp49kzue53DnO06LrFNwfAAcFbnask= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609935990406277.34831511843106; Wed, 6 Jan 2021 04:26:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-mS_TcHygOoW0saJqoGJVuQ-1; Wed, 06 Jan 2021 07:26:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82B1D106F8C1; Wed, 6 Jan 2021 12:26:20 +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 56A4119D7D; Wed, 6 Jan 2021 12:26:20 +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 1E72A1809CAB; Wed, 6 Jan 2021 12:26:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 106CQ8Ow019033 for ; Wed, 6 Jan 2021 07:26:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5803760BE5; Wed, 6 Jan 2021 12:26:08 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.194.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8EC360BE2 for ; Wed, 6 Jan 2021 12:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609935989; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nUcRbyO/k3wJlKYwAsz2CC0sZ5WgdCl3TyKdApZAdeQ=; b=dMaesvVU/y7xErX6ASZcKn8blsC2wfP4MAwl9NCt06XcD0Vr2YYnjEuIMu8R0m5/98ZA7N Dzy1TV/IXt6dxgePeupNVo2PUX0nle43uAq6Z3eIpCZj/x9vS5ARGeBwPvPyGYEVZOgEYV 7svtf3hpOe8HSAjYYsNQFC4wnetMlY4= X-MC-Unique: mS_TcHygOoW0saJqoGJVuQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 4/9] util: move virStorageFileGetLVMKey to locking Date: Wed, 6 Jan 2021 13:25:55 +0100 Message-Id: <780aa25fad35177e51ecc6d20a1425eba21a7e6b.1609935558.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function doesn't take virStorageSource as argument and has nothing in common with virStorageSource or storage file. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 - src/locking/lock_driver_lockd.c | 68 ++++++++++++++++++++++++++++++++- src/util/virstoragefile.c | 62 ------------------------------ src/util/virstoragefile.h | 2 - 4 files changed, 67 insertions(+), 66 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b8fedc82d5..78d4e5ab30 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3135,7 +3135,6 @@ virStorageFileFeatureTypeToString; virStorageFileFormatTypeFromString; virStorageFileFormatTypeToString; virStorageFileGetBackingStoreStr; -virStorageFileGetLVMKey; virStorageFileGetMetadata; virStorageFileGetMetadataFromBuf; virStorageFileGetMetadataFromFD; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 15d9e5f076..d459c1668c 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -24,6 +24,7 @@ #include "lock_driver.h" #include "virconf.h" #include "viralloc.h" +#include "vircommand.h" #include "vircrypto.h" #include "virlog.h" #include "viruuid.h" @@ -455,6 +456,71 @@ static int virLockManagerLockDaemonNew(virLockManagerP= tr lock, } =20 =20 +#ifdef LVS +static int +virLockManagerGetLVMKey(const char *path, + char **key) +{ + /* + * # lvs --noheadings --unbuffered --nosuffix --options "uuid" LVNAME + * 06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky + */ + int status; + int ret =3D -1; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D virCommandNewArgList(LVS, "--noheadings", + "--unbuffered", "--nosuffix", + "--options", "uuid", path, + NULL + ); + *key =3D NULL; + + /* Run the program and capture its output */ + virCommandSetOutputBuffer(cmd, key); + if (virCommandRun(cmd, &status) < 0) + goto cleanup; + + /* Explicitly check status =3D=3D 0, rather than passing NULL + * to virCommandRun because we don't want to raise an actual + * error in this scenario, just return a NULL key. + */ + + if (status =3D=3D 0 && *key) { + char *nl; + char *tmp =3D *key; + + /* Find first non-space character */ + while (*tmp && g_ascii_isspace(*tmp)) + tmp++; + /* Kill leading spaces */ + if (tmp !=3D *key) + memmove(*key, tmp, strlen(tmp)+1); + + /* Kill trailing newline */ + if ((nl =3D strchr(*key, '\n'))) + *nl =3D '\0'; + } + + ret =3D 0; + + cleanup: + if (*key && STREQ(*key, "")) + VIR_FREE(*key); + + return ret; +} +#else +static int +virLockManagerGetLVMKey(const char *path, + char **key G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, _("Unable to get LVM key for %s"), path); + return -1; +} +#endif + + static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, unsigned int type, const char *name, @@ -494,7 +560,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, if (STRPREFIX(name, "/dev") && driver->lvmLockSpaceDir) { VIR_DEBUG("Trying to find an LVM UUID for %s", name); - if (virStorageFileGetLVMKey(name, &newName) < 0) + if (virLockManagerGetLVMKey(name, &newName) < 0) goto cleanup; =20 if (newName) { diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 119342d296..bc342cabe3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1251,68 +1251,6 @@ int virStorageFileIsClusterFS(const char *path) VIR_FILE_SHFS_CEPH); } =20 -#ifdef LVS -int virStorageFileGetLVMKey(const char *path, - char **key) -{ - /* - * # lvs --noheadings --unbuffered --nosuffix --options "uuid" LVNAME - * 06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky - */ - int status; - int ret =3D -1; - g_autoptr(virCommand) cmd =3D NULL; - - cmd =3D virCommandNewArgList(LVS, "--noheadings", - "--unbuffered", "--nosuffix", - "--options", "uuid", path, - NULL - ); - *key =3D NULL; - - /* Run the program and capture its output */ - virCommandSetOutputBuffer(cmd, key); - if (virCommandRun(cmd, &status) < 0) - goto cleanup; - - /* Explicitly check status =3D=3D 0, rather than passing NULL - * to virCommandRun because we don't want to raise an actual - * error in this scenario, just return a NULL key. - */ - - if (status =3D=3D 0 && *key) { - char *nl; - char *tmp =3D *key; - - /* Find first non-space character */ - while (*tmp && g_ascii_isspace(*tmp)) - tmp++; - /* Kill leading spaces */ - if (tmp !=3D *key) - memmove(*key, tmp, strlen(tmp)+1); - - /* Kill trailing newline */ - if ((nl =3D strchr(*key, '\n'))) - *nl =3D '\0'; - } - - ret =3D 0; - - cleanup: - if (*key && STREQ(*key, "")) - VIR_FREE(*key); - - return ret; -} -#else -int virStorageFileGetLVMKey(const char *path, - char **key G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, _("Unable to get LVM key for %s"), path); - return -1; -} -#endif - #ifdef WITH_UDEV /* virStorageFileGetSCSIKey * @path: Path to the SCSI device diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index cc9bd4875f..31feb22f26 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -428,8 +428,6 @@ int virStorageFileIsClusterFS(const char *path); bool virStorageIsFile(const char *path); bool virStorageIsRelative(const char *backing); =20 -int virStorageFileGetLVMKey(const char *path, - char **key); int virStorageFileGetSCSIKey(const char *path, char **key, bool ignoreError); --=20 2.29.2