From nobody Thu May 15 13:26:59 2025 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.zohomail.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 1508510473897941.0118644259552; Fri, 20 Oct 2017 07:41:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA48F4DB97; Fri, 20 Oct 2017 13:49:30 +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 941AF600C0; Fri, 20 Oct 2017 13:49:30 +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 56A9D1800C87; Fri, 20 Oct 2017 13:49:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9KDm1Qn020294 for ; Fri, 20 Oct 2017 09:48:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id D328B5D761; Fri, 20 Oct 2017 13:48:01 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 301685D762; Fri, 20 Oct 2017 13:48:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA48F4DB97 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 20 Oct 2017 15:47:28 +0200 Message-Id: <5b3db5c0410bd513a8260ff843067e34563f62b4.1508507145.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 03/12] storage: Extract error reporting for broken chains 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 20 Oct 2017 13:49:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Simplify reporting the error if backing chain is broken for further callers by extracting it into a separate function. Reviewed-by: John Ferlan --- src/storage/storage_source.c | 47 +++++++++++++++++++++++++++++++---------= ---- src/storage/storage_source.h | 4 ++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index cced5308c..4586ef4ad 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -404,6 +404,38 @@ virStorageFileChown(const virStorageSource *src, } +/** + * virStorageFileReportBrokenChain: + * + * @errcode: errno when accessing @src + * @src: inaccessible file in the backing chain of @parent + * @parent: root virStorageSource being checked + * + * Reports the correct error message if @src is missing in the backing cha= in + * for @parent. + */ +void +virStorageFileReportBrokenChain(int errcode, + virStorageSourcePtr src, + virStorageSourcePtr parent) +{ + unsigned int access_user =3D src->drv->uid; + unsigned int access_group =3D src->drv->gid; + + if (src =3D=3D parent) { + virReportSystemError(errcode, + _("Cannot access storage file '%s' " + "(as uid:%u, gid:%u)"), + src->path, access_user, access_group); + } else { + virReportSystemError(errcode, + _("Cannot access backing file '%s' " + "of storage file '%s' (as uid:%u, gid:%u)"), + src->path, parent->path, access_user, access_= group); + } +} + + /* Recursive workhorse for virStorageFileGetMetadata. */ static int virStorageFileGetMetadataRecurse(virStorageSourcePtr src, @@ -433,20 +465,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr s= rc, return -1; if (virStorageFileAccess(src, F_OK) < 0) { - if (src =3D=3D parent) { - virReportSystemError(errno, - _("Cannot access storage file '%s' " - "(as uid:%u, gid:%u)"), - src->path, (unsigned int)uid, - (unsigned int)gid); - } else { - virReportSystemError(errno, - _("Cannot access backing file '%s' " - "of storage file '%s' (as uid:%u, gid:%= u)"), - src->path, parent->path, - (unsigned int)uid, (unsigned int)gid); - } - + virStorageFileReportBrokenChain(errno, src, parent); goto cleanup; } diff --git a/src/storage/storage_source.h b/src/storage/storage_source.h index 320ea3cab..0640c138e 100644 --- a/src/storage/storage_source.h +++ b/src/storage/storage_source.h @@ -52,4 +52,8 @@ int virStorageFileGetMetadata(virStorageSourcePtr src, char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src) ATTRIBUTE_NONNULL(1); +void virStorageFileReportBrokenChain(int errcode, + virStorageSourcePtr src, + virStorageSourcePtr parent); + #endif /* __VIR_STORAGE_SOURCE_H__ */ --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list