From patchwork Fri Jun 28 23:26:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 2802851 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7E9BABF4A1 for ; Fri, 28 Jun 2013 23:30:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD65920140 for ; Fri, 28 Jun 2013 23:30:49 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id ED64220204 for ; Fri, 28 Jun 2013 23:30:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5SNRm7A010620; Fri, 28 Jun 2013 19:27:49 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5SNQit1027037 for ; Fri, 28 Jun 2013 19:26:44 -0400 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5SNQhwY007313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Jun 2013 19:26:44 -0400 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r5SNQgLU006381; Fri, 28 Jun 2013 18:26:42 -0500 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r5SNQf0P006380; Fri, 28 Jun 2013 18:26:41 -0500 From: Benjamin Marzinski To: device-mapper development Date: Fri, 28 Jun 2013 18:26:21 -0500 Message-Id: <1372461981-6333-9-git-send-email-bmarzins@redhat.com> In-Reply-To: <1372461981-6333-1-git-send-email-bmarzins@redhat.com> References: <1372461981-6333-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 8/8] fix mutipath -W on empty wwids file X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When multipath tries to open the wwids file and finds it empty or missing, it writes the header to the file. When it tried to wipe the wwids from an empty or missing file, it didn't seek back to the start of the file after truncating it. This caused the the wwids file to have a patch of zeroed bytes at the start. This patch fixes this by always seeking back to the start of the file before rewriting the header. Signed-off-by: Benjamin Marzinski --- libmultipath/wwids.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 91b07a7..eca1799 100644 --- a/libmultipath/wwids.c +++ b/libmultipath/wwids.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "checkers.h" #include "vector.h" @@ -100,6 +101,11 @@ replace_wwids(vector mp) condlog(0, "cannot truncate wwids file : %s", strerror(errno)); goto out_file; } + if (lseek(fd, 0, SEEK_SET) < 0) { + condlog(0, "cannot seek to the start of the file : %s", + strerror(errno)); + goto out_file; + } len = strlen(WWIDS_FILE_HEADER); if (write_all(fd, WWIDS_FILE_HEADER, len) != len) { condlog(0, "Can't write wwid file header : %s",