From nobody Sun May 19 03:54:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1662639969; cv=none; d=zohomail.com; s=zohoarc; b=FWvISwKySyNg2/z9liUpAGEIxhRwU6TmcnT7IvrlnDpEzlGEOHk/hLSNDINBtdMWlWgUWEb+fz+VJ6P1q8Sb+vfEbLXd547qIB2W1xgZiArXjA6KR0RSBznZWVHbD7yMa0NPuIvnNFv72LZl0WphnXVVx28kMjO5g1qQHm57mCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662639969; 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=2+0+kaPSnYwtKYr25rFL9P/ZTLbree7A3dOE1mrkypw=; b=nN/5WaIJHUNzaI8MnD9+eivlsO1k7KJsGyEr82KNg5L5qN/PwuDhookPtoYPF/rjV8FTtpRraiQkug/KMBKbnH77a+4PFb4+8AJv6iXAMJT9jQpzUIAJXE7MBVGVBEunLN66Y7nmC1nqoA4dK0pQmhY75WQiZ1adEw2QYWONeEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 166263996909610.98165474017162; Thu, 8 Sep 2022 05:26:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-nxsEsQsdNTOoh1RRqs3pmA-1; Thu, 08 Sep 2022 08:25:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 948D93C10257; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D3E114152E3; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6D7F41946A44; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C22091946A44 for ; Thu, 8 Sep 2022 12:25:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B60D22166B29; Thu, 8 Sep 2022 12:25:07 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D1912166B26 for ; Thu, 8 Sep 2022 12:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662639968; 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=2+0+kaPSnYwtKYr25rFL9P/ZTLbree7A3dOE1mrkypw=; b=TIx7mG2I8Gps/KAFpyR1tZ9JbohNn5ySzB7XtpDtj3lL1ewcK3NEqsTCoGoiMF8SdL8pd0 oef4jtzgc1yCXl+DtgJfLBLd68SRmGXD1Ss2hOWJBrudWRargSazHRcQUcr0o8On/3MVtu tq5VAzOiOeBHNaferXyQCDmiRR3Bazg= X-MC-Unique: nxsEsQsdNTOoh1RRqs3pmA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] lxc: virLXCProcessReadLogOutput: Automatically close FD Date: Thu, 8 Sep 2022 14:25:00 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662639970928100001 Content-Type: text/plain; charset="utf-8" Switch to 'VIR_AUTOCLOSE' to simplify cleanup. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_process.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index fe5cab3df6..39dcf53c67 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1076,8 +1076,7 @@ virLXCProcessReadLogOutput(virDomainObj *vm, char *buf, size_t buflen) { - int fd =3D -1; - int ret; + VIR_AUTOCLOSE fd =3D -1; if ((fd =3D open(logfile, O_RDONLY)) < 0) { virReportSystemError(errno, @@ -1090,17 +1089,10 @@ virLXCProcessReadLogOutput(virDomainObj *vm, virReportSystemError(errno, _("Unable to seek log file %s to %llu"), logfile, (unsigned long long)pos); - VIR_FORCE_CLOSE(fd); return -1; } - ret =3D virLXCProcessReadLogOutputData(vm, - fd, - buf, - buflen); - - VIR_FORCE_CLOSE(fd); - return ret; + return virLXCProcessReadLogOutputData(vm, fd, buf, buflen); } --=20 2.37.1 From nobody Sun May 19 03:54:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1662639938; cv=none; d=zohomail.com; s=zohoarc; b=d95x1fWNP/anoRCVnjvEWvgA55qhZD5p10FON9VEngb8BF8s0ztZh5OJf3Hlt5FytEFcqH8VCeHV20w+G28Q+BpIVuvh0o7nSziq4GrzDsoSKxji+hl9LnShfhmW6JyjWuNGb1LZqe+xE/hYu/IEepQr8x04utcfiaflmFoClrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662639938; 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=Aub3hE60pC3vjnyPG8KaZZXqcRl0u+hX9ZR5sh0tGYg=; b=MbWVMdij+7KYZD99lijKcSuBTKytNgK9HPLOeHBS2GYNK6nNWHFi1DgxaOwBego7O6zbAZB47CLH3LlwMYPZTYrEnHf7Ih9zavwChRKhVjlSRYkQWwr7LZjFuflQ3dyCLChnAdQWrnYzle9WC+dHily7tSIQNxs14t/ByMlyQV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662639938383390.1254182420064; Thu, 8 Sep 2022 05:25:38 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-yJCvgnPON4KWPF8i8lVE-A-1; Thu, 08 Sep 2022 08:25:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41733294EDE4; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2150A945DB; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E1AFD1946A4A; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B32F01946A41 for ; Thu, 8 Sep 2022 12:25:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A893C2166B2B; Thu, 8 Sep 2022 12:25:08 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id F40062166B29 for ; Thu, 8 Sep 2022 12:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662639937; 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=Aub3hE60pC3vjnyPG8KaZZXqcRl0u+hX9ZR5sh0tGYg=; b=XGiE5lB2A0IF3z3Wfh6LIaZNkCJTBG1Ao8aD5MKb1eVjLaONDs08YsFPLaAOLn3PDyRt4d XJabBfyl3EofAhCVSACU+srqVufFSt+Lsal1WnmpWNmIEXm1uXlZYj0rd/zbRgztQzoYXB akr5i4c8JIyYTiGbKV14g3q937vn9A8= X-MC-Unique: yJCvgnPON4KWPF8i8lVE-A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] lxc: process: Rework reading errors from the log file Date: Thu, 8 Sep 2022 14:25:01 +0200 Message-Id: <84ca109e44d079f9fc6f03dc948b94f0a7a1df80.1662639767.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662639938689100004 Content-Type: text/plain; charset="utf-8" Introduce 'virLXCProcessReportStartupLogError' which simplifies the error handling on startup of the LXC process when reading of the error log is needed. This function has unusual return value semantics but it helps to make the callers simpler. This patch also removes 2 1k stack'd buffers from virLXCProcessStart. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_process.c | 90 ++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 39dcf53c67..2a753ae1da 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1096,6 +1096,43 @@ virLXCProcessReadLogOutput(virDomainObj *vm, } +/** + * virLXCProcessReportStartupLogError: + * @vm: domain object + * @logfile: path to the VM logfile + * @pos: position in @logfile to look for errors + * + * Looks for the error message from the LXC container process. + * Returns: + * -1: - When reading of error message failed. Reports appropriate error + * - When successfully read a non-empty error message. Reports an erro= r with + * the following message + * 'guest failed to start: ' with the error from the log appended + * + * 0: - When reading the error was successful but the error log was empty. + */ +static int +virLXCProcessReportStartupLogError(virDomainObj *vm, + char *logfile, + off_t pos) +{ + size_t buflen =3D 1024; + g_autofree char *errbuf =3D g_new0(char, buflen); + int rc; + + if ((rc =3D virLXCProcessReadLogOutput(vm, logfile, pos, errbuf, bufle= n)) < 0) + return -1; + + if (rc =3D=3D 0) + return 0; + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("guest failed to start: %s"), errbuf); + + return -1; +} + + static int virLXCProcessEnsureRootFS(virDomainObj *vm) { @@ -1151,7 +1188,6 @@ int virLXCProcessStart(virLXCDriver * driver, g_auto(GStrv) veths =3D NULL; int handshakefds[4] =3D { -1, -1, -1, -1 }; /* two pipes */ off_t pos =3D -1; - char ebuf[1024]; g_autofree char *timestamp =3D NULL; int nsInheritFDs[VIR_LXC_DOMAIN_NAMESPACE_LAST]; g_autoptr(virCommand) cmd =3D NULL; @@ -1368,28 +1404,28 @@ int virLXCProcessStart(virLXCDriver * driver, goto cleanup; if (status !=3D 0) { - if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, - sizeof(ebuf)) <=3D 0) { - if (WIFEXITED(status)) - g_snprintf(ebuf, sizeof(ebuf), _("unexpected exit status %= d"), + if (virLXCProcessReportStartupLogError(vm, logfile, pos) < 0) + goto cleanup; + + /* In case there isn't an error in the logs report one based on th= e exit status */ + if (WIFEXITED(status)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("guest failed to start: unexpected exit statu= s %d"), WEXITSTATUS(status)); - else - g_snprintf(ebuf, sizeof(ebuf), "%s", _("terminated abnorma= lly")); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("guest failed to start: terminated abnormally= ")); } - virReportError(VIR_ERR_INTERNAL_ERROR, - _("guest failed to start: %s"), ebuf); goto cleanup; } /* It has started running, so get its pid */ if ((r =3D virPidFileReadPath(pidfile, &vm->pid)) < 0) { - if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, sizeof(ebuf= )) > 0) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("guest failed to start: %s"), ebuf); - else - virReportSystemError(-r, - _("Failed to read pid file %s"), - pidfile); + if (virLXCProcessReportStartupLogError(vm, logfile, pos) < 0) + goto cleanup; + + /* In case there isn't an error in the logs report that we failed = to read the pidfile */ + virReportSystemError(-r, _("Failed to read pid file %s"), pidfile); goto cleanup; } @@ -1422,13 +1458,7 @@ int virLXCProcessStart(virLXCDriver * driver, /* The first synchronization point is when the controller creates CGro= ups. */ if (lxcContainerWaitForContinue(handshakefds[0]) < 0) { - char out[1024]; - - if (!(virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) < 0)= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("guest failed to start: %s"), out); - } - + virLXCProcessReportStartupLogError(vm, logfile, pos); goto cleanup; } @@ -1461,13 +1491,7 @@ int virLXCProcessStart(virLXCDriver * driver, /* The second synchronization point is when the controller finished * creating the container. */ if (lxcContainerWaitForContinue(handshakefds[0]) < 0) { - char out[1024]; - - if (!(virLXCProcessReadLogOutput(vm, logfile, pos, out, 1024) < 0)= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("guest failed to start: %s"), out); - } - + virLXCProcessReportStartupLogError(vm, logfile, pos); goto cleanup; } @@ -1476,11 +1500,7 @@ int virLXCProcessStart(virLXCDriver * driver, /* Intentionally overwrite the real monitor error message, * since a better one is almost always found in the logs */ - if (virLXCProcessReadLogOutput(vm, logfile, pos, ebuf, sizeof(ebuf= )) > 0) { - virResetLastError(); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("guest failed to start: %s"), ebuf); - } + virLXCProcessReportStartupLogError(vm, logfile, pos); goto cleanup; } --=20 2.37.1 From nobody Sun May 19 03:54:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1662639943; cv=none; d=zohomail.com; s=zohoarc; b=MFHs8kQa28cmAPkzVkTlhfLloug7UKIkxECDbGsI8hanJqlgHjtDbRymckStR1vZlLjpjZRim8gVyXk9BOxJnpB5r+YRQ0A1XBD4eyKn5Fx6AvkpaO5IfjlIGSR1XVsI1PH2g2EdMQoFGMEKXSBfBwfA7xbJuE94M8WcmGsptdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662639943; 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=k6jXgMvM3Yemb8PVJ5b+jUZLY5ELhDaLJrJhwU5nPnY=; b=bp8FZf71UA0UYum2n4oOwjs7QdgoybI39kNYyZZkuwRJAIxAt7tIZHFctOLNjjCtyHIA4VDN01bcsdZRflFPdnU87eg++jlPCvooYxIWeR2ygaS5x+S6ZJC63+Uh155MZPL4ikW5m0fmXvJiR6McW2Q7KgGiQ4OPLvPAMOgLLsU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662639943097181.00030660357606; Thu, 8 Sep 2022 05:25:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-81-3vXeBvNPPjeMmAvxwUCezQ-1; Thu, 08 Sep 2022 08:25:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F2E6901852; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55DB114152EC; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 340D31946A53; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 99F031946A59 for ; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7AAF72166B2B; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED51A2166B26 for ; Thu, 8 Sep 2022 12:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662639942; 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=k6jXgMvM3Yemb8PVJ5b+jUZLY5ELhDaLJrJhwU5nPnY=; b=gMRIyJXb9Xn31vOjImTzEhj2yVvuxJ4h3Erz2VLMl0UimKqOjXgTpPE2z9hZ6XF1VAuC4m bT83YojUHmIxJmt8xsupxez8ikU3OxhV+7UdZAESNAxY9GyJTAr1LjsVYq+KF6Ce2zKwI/ ZhW+2ndpJBva6rGLBelubZYPP7AS+Nw= X-MC-Unique: 3vXeBvNPPjeMmAvxwUCezQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] util: netdev: Dynamically allocate 'struct nlattr' in virNetDevSwitchdevFeature Date: Thu, 8 Sep 2022 14:25:02 +0200 Message-Id: <4f0b64eaaa93df6b48d905ff2e9eef739e6b8e85.1662639767.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662639944713100001 Content-Type: text/plain; charset="utf-8" At time of writing DEVLINK_ATTR_MAX equals to 176, thus the stack'd size of the pointer array is almost 1.4kiB. Allocate it dynamically. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virnetdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 6c6f6dee42..66cfc5d781 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3210,7 +3210,7 @@ virNetDevSwitchdevFeature(const char *ifname, struct nl_msg *nl_msg =3D NULL; g_autofree struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; - struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; + g_autofree struct nlattr **tb =3D g_new0(struct nlattr *, DEVLINK_ATTR= _MAX + 1); g_autoptr(virPCIDevice) pci_device_ptr =3D NULL; struct genlmsghdr gmsgh =3D { .cmd =3D DEVLINK_CMD_ESWITCH_GET, --=20 2.37.1 From nobody Sun May 19 03:54:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1662639936; cv=none; d=zohomail.com; s=zohoarc; b=PgD1MiZkO+uPEbNfFO5ANaNmxMlLKNyttqgSsJzgz9151shaWi7be+xqJ/ugYhRlZe1B5fYp5hGtbQv6TIJ3ziuXbBZpCdS2MbtB2eSAo7BcjoIZKXcs9d4oIr2hiQgAIxwnC5oe4FzrpY+k+r0sYQFKpA5/Z9NRvuLPaxwwCzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662639936; 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=Ogm0iHgWxRfoOF8kvYPyud+fKbgE1OP5qbC+cEfxW0o=; b=YHrG0mQkz6B9YigLrl8q0itVCr01rHU8Xqau2S/PbnzV05HOk3J+NJNAFZ5TYcFbF0CgiSlo6z9Za69A3jbLsHfP/tt9cKgpLn9/XL5zlzGQf+9jW+Xp9MvledUVYKviisQWDtvdgBVS/pWoBYsbmzJ53JuqlT2mT+YPMIjJHKo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662639936616873.890409928153; Thu, 8 Sep 2022 05:25:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-255-fds6RMx7OdmVAFny_k1VnA-1; Thu, 08 Sep 2022 08:25:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A2E013804534; Thu, 8 Sep 2022 12:25:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DB5A403A9DD; Thu, 8 Sep 2022 12:25:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 834721946A49; Thu, 8 Sep 2022 12:25:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9B0051946A53 for ; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7CD1D2166B2C; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3F882166B31 for ; Thu, 8 Sep 2022 12:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662639935; 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=Ogm0iHgWxRfoOF8kvYPyud+fKbgE1OP5qbC+cEfxW0o=; b=DU6je4uw+7AJwIFZHaiFNb6vZ7PAP2CCJoi4q1JvjEnNZsCjrRMBU9adPNUxmS2Xr1bYth NZbrA6nmFB+Y6qlnp2mRP4QhYno/zbbHGX6ktVdDm9CBOj+7LtZSS73lqMq3cBQxpHjCVY O6aHiwfTr9aFCGCfGxqZdMORUwY9mVY= X-MC-Unique: fds6RMx7OdmVAFny_k1VnA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] remote: dispatch: Allocate 'virDomainDef' in ACL helpers dynamically Date: Thu, 8 Sep 2022 14:25:03 +0200 Message-Id: <8ca4893a137cd25b9d5a3ba7117c376233ee1545.1662639767.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662639938657100002 Content-Type: text/plain; charset="utf-8" At time of this patch struct 'virDomainDef' has 1736 bytes. Allocate it dynamically to keep the stack frame size in reasonable values. This patch also fixes remoteRelayDomainQemuMonitorEventCheckACL, where we didn't clear the stack'd variable prior to use. Fortunately for now the code didn't look at anything else than what the code overwrote. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/remote/remote_daemon_dispatch.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index dc5790f077..4f42cdc610 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -154,22 +154,21 @@ static bool remoteRelayDomainEventCheckACL(virNetServerClient *client, virConnectPtr conn, virDomainPtr dom) { - virDomainDef def; + g_autofree virDomainDef *def =3D g_new0(virDomainDef, 1); g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; /* For now, we just create a virDomainDef with enough contents to * satisfy what viraccessdriverpolkit.c references. This is a bit * fragile, but I don't know of anything better. */ - memset(&def, 0, sizeof(def)); - def.name =3D dom->name; - memcpy(def.uuid, dom->uuid, VIR_UUID_BUFLEN); + def->name =3D dom->name; + memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN); if (!(identity =3D virNetServerClientGetIdentity(client))) goto cleanup; if (virIdentitySetCurrent(identity) < 0) goto cleanup; - ret =3D virConnectDomainEventRegisterAnyCheckACL(conn, &def); + ret =3D virConnectDomainEventRegisterAnyCheckACL(conn, def); cleanup: ignore_value(virIdentitySetCurrent(NULL)); @@ -284,21 +283,21 @@ static bool remoteRelayDomainQemuMonitorEventCheckACL(virNetServerClient *client, virConnectPtr conn, virDomainPtr= dom) { - virDomainDef def; + g_autofree virDomainDef *def =3D g_new0(virDomainDef, 1); g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; /* For now, we just create a virDomainDef with enough contents to * satisfy what viraccessdriverpolkit.c references. This is a bit * fragile, but I don't know of anything better. */ - def.name =3D dom->name; - memcpy(def.uuid, dom->uuid, VIR_UUID_BUFLEN); + def->name =3D dom->name; + memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN); if (!(identity =3D virNetServerClientGetIdentity(client))) goto cleanup; if (virIdentitySetCurrent(identity) < 0) goto cleanup; - ret =3D virConnectDomainQemuMonitorEventRegisterCheckACL(conn, &def); + ret =3D virConnectDomainQemuMonitorEventRegisterCheckACL(conn, def); cleanup: ignore_value(virIdentitySetCurrent(NULL)); --=20 2.37.1 From nobody Sun May 19 03:54:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1662639938; cv=none; d=zohomail.com; s=zohoarc; b=diZdVcgcFSsQWteTU76oB8EjXSPmW3mRR2v+kz3LlfyTaQQfIXJjyP64OP07JPeo4O6wby11P2YOnPzoUDmz2hy7ojm3AUCilwCIWhf/5DPwfsb5ORg9/m0j8r1P647EzqVvk5Z60C0i5RY4ZoLwrmqcilmMcmLyqOAHoSGspys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662639938; 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=lNbwq4zPA0tlrZgF4X7Za0fYPvswqTJNar5gNNPMuTM=; b=nLk3yn3kNu9+tQ7I5UuHMMux7eP8MfwO2kAvWIeDsNvsJD1EylkdyKYhhkfUGt3M1+INFok8i466NDhwe4jyQbOZFmy+alYOG/u+5IGYGC581SIDAlGaH89AELKlf9XYJjfqfrbuzStNSnEg/1fhcoPYFuCNGz+/IrF1eRu3nQ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1662639938284330.2393289284237; Thu, 8 Sep 2022 05:25:38 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-674-1X7S8wSZMhut2Cq_ajkzzQ-1; Thu, 08 Sep 2022 08:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0943181881D; Thu, 8 Sep 2022 12:25:12 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD40740E7F29; Thu, 8 Sep 2022 12:25:12 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C2B5E1946A58; Thu, 8 Sep 2022 12:25:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C95981946A59 for ; Thu, 8 Sep 2022 12:25:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AEE332166B2D; Thu, 8 Sep 2022 12:25:11 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29B762166B26 for ; Thu, 8 Sep 2022 12:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662639937; 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=lNbwq4zPA0tlrZgF4X7Za0fYPvswqTJNar5gNNPMuTM=; b=WL50HMt+XFCtjEBjDpuoGt1mGfjQVEPErAklUTwaWHRpfVK/lRSbqKTwFq7pYte9RE38QX J+CKHt/aM3gh2iIII4PrawFYpcgavDcxTOuapVTRsDXSyofgUdpdb7/WBPj4iYN5rfi7IE XHUiB6soHrQvF8Xspg0RDB5HYXTJ8Ag= X-MC-Unique: 1X7S8wSZMhut2Cq_ajkzzQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] build: Decrease maximum stack frame size to 2048 Date: Thu, 8 Sep 2022 14:25:04 +0200 Message-Id: <42116d29814b9d72bf2cd3996e101d0c90271f7a.1662639767.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662639938647100001 Content-Type: text/plain; charset="utf-8" After recent cleanups we can now restrict the maximum stack frame size to 2k. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index ed9f4b3f70..9d3703a321 100644 --- a/meson.build +++ b/meson.build @@ -226,7 +226,7 @@ alloc_max =3D run_command( ) # sanitizer instrumentation may enlarge stack frames -stack_frame_size =3D get_option('b_sanitize') =3D=3D 'none' ? 4096 : 32768 +stack_frame_size =3D get_option('b_sanitize') =3D=3D 'none' ? 2048 : 32768 # array_bounds=3D2 check triggers false positive on some GCC # versions when using sanitizers. Seen on Fedora 34 with --=20 2.37.1