From nobody Tue Jul 14 21:22:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1783352498; cv=none; d=zohomail.com; s=zohoarc; b=lgYFxUAlHPJO86qawBnhjOIPuPY5r9f5bY13IMdMPEUWwHcOfPxAvMkT95EYcCqDgtn85lH98up1P4HD7cBdBk6AhRXKkXocPITFNiNx8quX/kmYmshnrCSebSoYcnJBXfmkCykTRfWFhjRd4RO7rvD3P5RLPhge8hQhYw+MNmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783352498; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=veT1jn1ACl+qFAq2n6/MOdpSHDuB/TavI66XvVgHlYM=; b=Et1I30jI38ddoj1DOyMS4gHMhSCiq/31gUdIXZGUS4Mba5kP/LD3M/3ZalnPCFu890MfLa4BU9XmY3CSO4mzpokJ49E4dwxwIrFNxO9BVS88nq1CQo947A1FY8H6zMBkUWeXFG1NXyBSb+gAiNOXpEY9cquOeZL4BE9TUgOhQlw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1783352498189850.0443854581836; Mon, 6 Jul 2026 08:41:38 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 10BD041BEC; Mon, 6 Jul 2026 11:41:37 -0400 (EDT) Received: from [172.19.199.7] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id D6E9A41DF1; Mon, 6 Jul 2026 11:39:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 93CA4417CA; Mon, 6 Jul 2026 11:38:56 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A523441BEC for ; Mon, 6 Jul 2026 11:38:52 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-5PaoIyfQO3y157wngabjHg-1; Mon, 06 Jul 2026 11:38:51 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 43BF418009F0 for ; Mon, 6 Jul 2026 15:38:50 +0000 (UTC) Received: from polon.redhat.com (unknown [10.44.33.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 56334195609E; Mon, 6 Jul 2026 15:38:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783352332; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=veT1jn1ACl+qFAq2n6/MOdpSHDuB/TavI66XvVgHlYM=; b=VjNafvZz0hV+y9Mlh8ukzQYc6I72xPt8pQJMIcewlfl4YlC9niRhcSPYKicwLxMQkcDthi xyFbP5X8DIxARgSyjyDFyA46d7X6WHu/m4epfFteOTEU55a5Xa2MkzBp8EvLkDYNxilexY ZWDY1vSQZhE5T/zws+YV8MbVs/1OzWE= X-MC-Unique: 5PaoIyfQO3y157wngabjHg-1 X-Mimecast-MFC-AGG-ID: 5PaoIyfQO3y157wngabjHg_1783352330 To: devel@lists.libvirt.org Subject: [PATCH v2 1/1] lxc: fix problem with truncation of long path used for file backing block device Date: Mon, 6 Jul 2026 17:15:31 +0200 Message-ID: <5b9f93f97969d4f30675e35fa9151c022b30fe07.1783350930.git.rsmigiel@redhat.com> In-Reply-To: <20260706153841.356404-1-rsmigiel@redhat.com> References: <20260706153841.356404-1-rsmigiel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: sLSPA2D9_Ufk3j8wGuEL2IMp3BGeZagdjKxL-IIm0Vw_1783352330 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YJ5K4ARV43RE4DP3XFSG2UNMAZMYBRMO X-Message-ID-Hash: YJ5K4ARV43RE4DP3XFSG2UNMAZMYBRMO X-MailFrom: rsmigiel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Radoslaw Smigielski X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Rados=C5=82aw_=C5=9Amigielski_via_Devel?= Reply-To: rsmigiel@redhat.com X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1783352501300158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Radoslaw Smigielski LXC domains using a file-backed filesystem with the loop driver fail to start when the backing file path is longer than LO_NAME_SIZE (64 bytes, 63 characters plus NUL). When file path was truncated by virStrcpy(), it caused virFileLoopDeviceAssociate() to fail and reported a misleading virReportSystemError(errno, ...), so users saw below error: "Unable to set backing file ...: Success" or ENOENT even when the file exists. Example of XML that failed before this change: This is how losetup output looks like with the new unique identifier visible in last REF column: [root@rvm08m-1 radek]# losetup -l -O +REF NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE = DIO LOG-SEC REF /dev/loop1 0 0 1 0 /var/tmp/looooooooooooo[...]oooo= ooooooooooooong.raw 0 512 libvirt-69d62093-b691-46a4-81ab-39db6cead5= a8-fs2 /dev/loop0 0 0 1 0 /var/tmp/short.raw = 0 512 libvirt-69d62093-b691-46a4-81ab-39db6cead5= a8-fs1 Kernel only stores a short name in LOOP_GET_STATUS64.lo_file_name. While the backing file of a block device is still opened by full path, and not by lo_file_name. So the Linux kernel only uses lo_file_name as an informational metadata identifier. To avoid collisions when long paths are truncated a new unique identifier is generated in format: "libvirt-$UUID-$DEVALIAS" and assigned to loName. Additionally, the fatal error on string truncation has been removed and replaced with a warning message. Fixes: https://gitlab.com/libvirt/libvirt/-/work_items/63 Signed-off-by: Radoslaw Smigielski --- src/lxc/lxc_controller.c | 27 ++++++++++++++++++++------- src/util/virfile.c | 19 ++++++++++++++----- src/util/virfile.h | 1 + 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f7776534e8a5..ca8720774c1f 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -53,6 +53,7 @@ #include "virnetdevveth.h" #include "viralloc.h" #include "virfile.h" +#include "viruuid.h" #include "virgdbus.h" #include "virpidfile.h" #include "virhostcpu.h" @@ -452,12 +453,18 @@ static int virLXCControllerValidateConsoles(virLXCCon= troller *ctrl) } =20 =20 -static int virLXCControllerSetupLoopDeviceFS(virDomainFSDef *fs) +static int virLXCControllerSetupLoopDeviceFS(virDomainDef *def, + virDomainFSDef *fs) { int lofd; - char *loname =3D NULL; + g_autofree char *loname =3D NULL; + g_autofree char *loDeviceName =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(def->uuid, uuidstr); + loDeviceName =3D g_strdup_printf("libvirt-%s-%s", uuidstr, fs->info.al= ias); =20 - if ((lofd =3D virFileLoopDeviceAssociate(fs->src->path, &loname)) < 0) + if ((lofd =3D virFileLoopDeviceAssociate(fs->src->path, loDeviceName, = &loname)) < 0) return -1; =20 VIR_DEBUG("Changing fs %s to use type=3Dblock for dev %s", @@ -474,13 +481,19 @@ static int virLXCControllerSetupLoopDeviceFS(virDomai= nFSDef *fs) } =20 =20 -static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDef *disk) +static int virLXCControllerSetupLoopDeviceDisk(virDomainDef *def, + virDomainDiskDef *disk) { int lofd; g_autofree char *loname =3D NULL; + g_autofree char *loDeviceName =3D NULL; const char *src =3D virDomainDiskGetSource(disk); + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(def->uuid, uuidstr); + loDeviceName =3D g_strdup_printf("libvirt-%s-%s", uuidstr, disk->info.= alias); =20 - if ((lofd =3D virFileLoopDeviceAssociate(src, &loname)) < 0) + if ((lofd =3D virFileLoopDeviceAssociate(src, loDeviceName, &loname)) = < 0) return -1; =20 VIR_DEBUG("Changing disk %s to use type=3Dblock for dev %s", @@ -630,7 +643,7 @@ static int virLXCControllerSetupLoopDevices(virLXCContr= oller *ctrl) return -1; } =20 - fd =3D virLXCControllerSetupLoopDeviceFS(fs); + fd =3D virLXCControllerSetupLoopDeviceFS(ctrl->def, fs); if (fd < 0) return -1; =20 @@ -685,7 +698,7 @@ static int virLXCControllerSetupLoopDevices(virLXCContr= oller *ctrl) * don't want to go into the auto-probing * business for security reasons */ - fd =3D virLXCControllerSetupLoopDeviceDisk(disk); + fd =3D virLXCControllerSetupLoopDeviceDisk(ctrl->def, disk); if (fd < 0) return -1; =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index a0c6cb804862..6eb9ea1c893a 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -982,6 +982,7 @@ static int virFileLoopDeviceOpen(char **dev_name) } =20 int virFileLoopDeviceAssociate(const char *file, + const char *loName, char **dev) { int lofd =3D -1; @@ -989,6 +990,8 @@ int virFileLoopDeviceAssociate(const char *file, struct loop_info64 lo =3D { 0 }; g_autofree char *loname =3D NULL; int ret =3D -1; + /* use provided loName if available, otherwise fallback to the file pa= th. */ + const char *name_to_use =3D loName ? loName : file; =20 if ((lofd =3D virFileLoopDeviceOpen(&loname)) < 0) return -1; @@ -996,10 +999,16 @@ int virFileLoopDeviceAssociate(const char *file, lo.lo_flags =3D LO_FLAGS_AUTOCLEAR; =20 /* Set backing file name for LOOP_GET_STATUS64 queries */ - if (virStrcpy((char *) lo.lo_file_name, file, LO_NAME_SIZE) < 0) { - virReportSystemError(errno, - _("Unable to set backing file %1$s"), file); - goto cleanup; + if (virStrcpy((char *) lo.lo_file_name, name_to_use, LO_NAME_SIZE) < 0= ) { + if (loName) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Generated loop device name '%1$s' exceeds ma= ximum limit"), + loName); + goto cleanup; + } + /* If the raw file path is what truncated, it's safe to just log a= debug + * message since the kernel doesn't use lo_file_name for actual I/= O. */ + VIR_DEBUG("Loop backing file path '%s' truncated in loop metadata"= , file); } =20 if ((fsfd =3D open(file, O_RDWR)) < 0) { @@ -1036,7 +1045,6 @@ int virFileLoopDeviceAssociate(const char *file, return lofd; } =20 - # define SYSFS_BLOCK_DIR "/sys/block" # define NBD_DRIVER "nbd" =20 @@ -1160,6 +1168,7 @@ int virFileNBDDeviceAssociate(const char *file, #else /* __linux__ */ =20 int virFileLoopDeviceAssociate(const char *file, + const char *loName G_GNUC_UNUSED, char **dev G_GNUC_UNUSED) { virReportSystemError(ENOSYS, diff --git a/src/util/virfile.h b/src/util/virfile.h index 8c9ad5989818..b5eb4e727548 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -151,6 +151,7 @@ int virFileUpdatePerm(const char *path, mode_t mode_add); =20 int virFileLoopDeviceAssociate(const char *file, + const char *loName, char **dev); =20 int virFileNBDDeviceAssociate(const char *file, --=20 2.54.0