From nobody Wed May 8 23:10:24 2024 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.zoho.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 1490377770036504.58178438447726; Fri, 24 Mar 2017 10:49:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 95BBD8F889; Fri, 24 Mar 2017 17:49:29 +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 68CBC18136; Fri, 24 Mar 2017 17:49:29 +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 1F1AD18523C7; Fri, 24 Mar 2017 17:49:29 +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 v2OHmDhf008927 for ; Fri, 24 Mar 2017 13:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E3EC7E662; Fri, 24 Mar 2017 17:48:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E4A918407 for ; Fri, 24 Mar 2017 17:48:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 95BBD8F889 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 95BBD8F889 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 24 Mar 2017 13:48:08 -0400 Message-Id: <20170324174808.4920-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] logical: Need to overwrite/clear more than just first 512 bytes 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 24 Mar 2017 17:49:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1430679 As it turns out some file headers (e.g. ext4) may be larger/longer than the 512 bytes of zeros being written prior to a pvcreate, so let's write out 2048 bytes similar to how the pvcreate sources would peek at the first 4 sectors of the device. Make sure there is at enough bytes on the device to clear before doing doing the clear - just to be sure. Signed-off-by: John Ferlan --- src/storage/storage_backend_logical.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 29d63b1..9ca6fd4 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -93,7 +93,8 @@ static int virStorageBackendLogicalInitializeDevice(const char *path) { int fd =3D -1; - char zeros[PV_BLANK_SECTOR_SIZE] =3D {0}; + char zeros[4 * PV_BLANK_SECTOR_SIZE] =3D {0}; + off_t size; int ret =3D -1; virCommandPtr pvcmd =3D NULL; =20 @@ -107,6 +108,25 @@ virStorageBackendLogicalInitializeDevice(const char *p= ath) return -1; } =20 + if ((size =3D lseek(fd, 0, SEEK_END)) =3D=3D (off_t)-1) { + virReportSystemError(errno, + _("failed to seek to end of %s"), path); + goto cleanup; + } + + if (size < 4 * PV_BLANK_SECTOR_SIZE) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("cannot initialize '%s' detected size=3D'%lu' les= s " + "than minimum required=3D'%d"), + path, size, 4 * PV_BLANK_SECTOR_SIZE); + goto cleanup; + } + if ((size =3D lseek(fd, 0, SEEK_SET)) =3D=3D (off_t)-1) { + virReportSystemError(errno, + _("failed to seek to start of %s"), path); + goto cleanup; + } + if (safewrite(fd, zeros, sizeof(zeros)) < 0) { virReportSystemError(errno, _("cannot clear device header of '%s'"= ), path); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list