From nobody Mon Apr 29 20:10:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1596880917; cv=none; d=zohomail.com; s=zohoarc; b=R+y6NUG7CgpQSvG+QU58t6i4foOIZkqp4F7UUUlnCSyl75kfAh0eyzE3EKLME9aGmFKeXYt5L0zQbYu88N+Bu3HomdBOaGzO6d9FU5HiYhOYgmFs82CtC8EJN/UhmvN4IO+HA2/QSKoEpaMrBj5dx+u9FJkZunhtF723+XNNURM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596880917; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=o0XiEk5OGDioT/6U5vWSP9x/sRQibzZ7gvUfe+meNEI=; b=jPXoM0idlQYQWYfsF6T0dBKwEs/NEMox1wGwxJs+6/C2+aBpqjA1GA74CGH6Xrt41XOIaVVZI/lituKmRR0+7mgb7Bv4/wmcRcCwV8NLJnIKXsa0c5fJWoK89CbS+HfqCqUvgZuWXGhnnx6z7CvxvUofYB1WQ24S8xd/hnajl2U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1596880917097146.27515054449157; Sat, 8 Aug 2020 03:01:57 -0700 (PDT) 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-4-GXFIOyYWPbewHuB9MQML0g-1; Sat, 08 Aug 2020 06:01:53 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 242DF79EC0; Sat, 8 Aug 2020 10:01:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DAFB60BEC; Sat, 8 Aug 2020 10:01:45 +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 4F717A5521; Sat, 8 Aug 2020 10:01:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 078A1bjX019898 for ; Sat, 8 Aug 2020 06:01:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 648BA207B2AB; Sat, 8 Aug 2020 10:01:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DFD9207B2B8 for ; Sat, 8 Aug 2020 10:01:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 533008E6980 for ; Sat, 8 Aug 2020 10:01:35 +0000 (UTC) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-vonYu1ylOB-iBEWWH7J11Q-1; Sat, 08 Aug 2020 06:01:31 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BC17791EE988413B348F for ; Sat, 8 Aug 2020 18:01:28 +0800 (CST) Received: from [127.0.0.1] (10.174.187.164) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Sat, 8 Aug 2020 18:01:23 +0800 X-MC-Unique: GXFIOyYWPbewHuB9MQML0g-1 X-MC-Unique: vonYu1ylOB-iBEWWH7J11Q-1 To: From: Hao Wang Subject: [PATCH] NVRAM: check NVRAM file size and recover from template Message-ID: Date: Sat, 8 Aug 2020 18:01:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 X-Originating-IP: [10.174.187.164] X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: "Chenzhendong \(alex\)" , zhengchuan , Zhanghailiang , yubihong 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.79 on 10.5.11.12 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 Content-Type: text/plain; charset="utf-8" From: Hao Wang Subject: [PATCH] NVRAM: check NVRAM file size and recover from template A corrupted nvram file (e.g. caused by last unsuccessful creation due to insufficient memory) can lead to boot or migration failure. Check the size of the existed nvram file when qemuPrepareNVRAM, and re-crea= te if the existed one is unhealthy. Signed-off-by: Hao Wang --- src/qemu/qemu_process.c | 54 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 126fabf5ef..42060bb36c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4376,6 +4376,48 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver, } +static bool +qemuIsNvramFileHealthy(virQEMUDriverConfigPtr cfg, + virDomainLoaderDefPtr loader) +{ + const char *masterNvramPath; + off_t nvramSize; + off_t masterSize; + + masterNvramPath =3D loader->templt; + if (!loader->templt) { + size_t i; + for (i =3D 0; i < cfg->nfirmwares; i++) { + if (STREQ(cfg->firmwares[i]->name, loader->path)) { + masterNvramPath =3D cfg->firmwares[i]->nvram; + break; + } + } + } + + if (!masterNvramPath) { + VIR_WARN("no nvram template is found; assume the nvram file is hea= lthy"); + return true; + } + + if ((nvramSize =3D virFileLength(loader->nvram, -1)) < 0 || + (masterSize =3D virFileLength(masterNvramPath, -1)) < 0) { + virReportSystemError(errno, + _("unable to get the size of '%s' or '%s'"), + loader->nvram, masterNvramPath); + return false; + } + + if (nvramSize !=3D masterSize) { + VIR_WARN("the size(%zd) of the nvram file is not equal to that of = the template %s", + nvramSize, masterNvramPath); + return false; + } + + return true; +} + + static int qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg, virDomainObjPtr vm) @@ -4388,9 +4430,19 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg, const char *master_nvram_path; ssize_t r; - if (!loader || !loader->nvram || virFileExists(loader->nvram)) + if (!loader || !loader->nvram) return 0; + if (virFileExists(loader->nvram)) { + if (qemuIsNvramFileHealthy(cfg, loader)) + return 0; + + ignore_value(virFileRemove(loader->nvram, -1, -1)); + VIR_WARN("the nvram file %s exists but may be corrupted! " + "Remove it and try to copy a new one from template.", + loader->nvram); + } + master_nvram_path =3D loader->templt; if (!loader->templt) { size_t i; -- 2.23.0