From patchwork Thu Jun 22 23:45:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill O'Donnell X-Patchwork-Id: 9805409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F2F660234 for ; Thu, 22 Jun 2017 23:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70F402852C for ; Thu, 22 Jun 2017 23:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E58028662; Thu, 22 Jun 2017 23:45:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8FAF2852C for ; Thu, 22 Jun 2017 23:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753921AbdFVXph (ORCPT ); Thu, 22 Jun 2017 19:45:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36290 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753919AbdFVXpg (ORCPT ); Thu, 22 Jun 2017 19:45:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 457F1142889 for ; Thu, 22 Jun 2017 23:45:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 457F1142889 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=billodo@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 457F1142889 Received: from localhost.localdomain.com (ovpn-120-226.rdu2.redhat.com [10.10.120.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBCD177673 for ; Thu, 22 Jun 2017 23:45:35 +0000 (UTC) From: Bill O'Donnell To: linux-xfs@vger.kernel.org Subject: [PATCH v2] xfs_db: update sector size when type is set Date: Thu, 22 Jun 2017 18:45:35 -0500 Message-Id: <20170622234535.30942-1-billodo@redhat.com> In-Reply-To: <20170622193352.22346-1-billodo@redhat.com> References: <20170622193352.22346-1-billodo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 22 Jun 2017 23:45:36 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xfs_db doesn't take sector size into account when setting type. This can result in an errant crc. For example, with a sector size of 4096: xfs_db> agi 0 xfs_db> p crc crc = 0xab85043e (correct) xfs_db> daddr current daddr is 16 xfs_db> daddr 42 xfs_db> daddr 16 xfs_db> type agi Metadata CRC error detected at xfs_agi block 0x10/0x200 xfs_db> p crc crc = 0xab85043e (bad) When xfs_db sets the new daddr in daddr_f, it does so with one BBSIZE sector (512). Changing the type doesn't change the size of the current buffer in iocur_top, so the checksum is calculated on the wrong length for the type (when the actual sector size > BBSIZE (512)). For types with fields, reread the buffer to pick up the correct size for the new type when it gets set. Facilitate the reread by setting the cursor with set_cur(). Signed-off-by: Bill O'Donnell Reviewed-by: Carlos Maiolino --- v2: correction to argument 3 in call to set_cur: compute and pass basic block count; add comment regarding conditional call to set_cur. db/io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/io.c b/db/io.c index 9918a51..792cc0a 100644 --- a/db/io.c +++ b/db/io.c @@ -615,7 +615,13 @@ set_iocur_type( const typ_t *t) { struct xfs_buf *bp = iocur_top->bp; + int bb_count; + /* adjust cursor for types that contain fields */ + if (t->fields) { + bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0))); + set_cur(t, iocur_top->bb, bb_count, DB_RING_IGN, NULL); + } iocur_top->typ = t; /* verify the buffer if the type has one. */