From patchwork Sun Jul 15 08:17:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Bityutskiy X-Patchwork-Id: 171050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0BD332C00D1 for ; Sun, 15 Jul 2012 18:32:03 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SqK7g-0002VZ-95; Sun, 15 Jul 2012 08:24:12 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SqK7P-0002VL-Lc for linux-mtd@lists.infradead.org; Sun, 15 Jul 2012 08:24:03 +0000 Received: by lbbgg6 with SMTP id gg6so6571786lbb.36 for ; Sun, 15 Jul 2012 01:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=W5AbQlBb12GTUqulJVIdVoGm1RsQRuu1KhsDOMJY/Ec=; b=rTw7yi6LF3FgutAmIechuNk5HyVEa6Lkuja0ED+Y2XU1nfYua7NJ6cQpG/pSodIFOV Sxmnf3ICPKEOdch8diC0Ej2m9dT+byE1eoBOUDc2d0CnpraKijd6S4TTXanEKNkcEeWv Lp80YyBxGEZN8pTzdTx5+EuQhtWbm9sA18fzp8cdFuBLSWIit/DRRj6JokDJj2VYv+ud zLA212QHS2wWvJA5SrErNWqoEjipB0BtCAkbrHE1BaOm3RJWkiAELjM7pp34pRXJRBnH 1YCEfihqzo5NyDz8SL6YDg+U+F39znlBfRPiFNxycUXDnzRGFZ7URrQTHI52/B+0afX0 Zeug== Received: by 10.112.36.130 with SMTP id q2mr3367826lbj.44.1342340567486; Sun, 15 Jul 2012 01:22:47 -0700 (PDT) Received: from localhost.localdomain (212-226-66-125-nat.elisa-mobile.fi. [212.226.66.125]) by mx.google.com with ESMTPS id p2sm2763654lbj.4.2012.07.15.01.22.45 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 15 Jul 2012 01:22:46 -0700 (PDT) From: Artem Bityutskiy To: James Nute , Iwo Mergler Subject: [PATCH] UBIFS: fix a bug in empty space fix-up Date: Sun, 15 Jul 2012 11:17:17 +0300 Message-Id: <1342340237-29656-1-git-send-email-dedekind1@gmail.com> X-Mailer: git-send-email 1.7.7.6 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedekind1[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.177 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (dedekind1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Ben Gardiner , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Artem Bityutskiy UBIFS has a feature called "empty space fix-up" which is a quirk to work-around limitations of dumb flasher programs. Namely, of those flashers that are unable to skip NAND pages full of 0xFFs while flashing, resulting in empty space at the end of half-filled eraseblocks to be unusable for UBIFS. This feature is relatively new (introduced in v3.0). The fix-up routine (fixup_free_space()) is executed only once at the very first mount if the superblock has the 'space_fixup' flag set (can be done with -F option of mkfs.ubifs). It basically reads all the UBIFS data and metadata and writes it back to the same LEB. The routine assumes the image is pristine and does not have anything in the journal. There was a bug in 'fixup_free_space()' where it fixed up the log incorrectly. All but one LEB of the log of a pristine file-system are empty. And one contains just a commit start node. And 'fixup_free_space()' just unmapped this LEB, which resulted in wiping the commit start node. As a result, some users were unable to mount the file-system next time with the following symptom: UBIFS error (pid 1): replay_log_leb: first log node at LEB 3:0 is not CS node UBIFS error (pid 1): replay_log_leb: log error detected while replaying the log at LEB 3:0 The root-cause of this bug was that 'fixup_free_space()' wrongly assumed that the beginning of empty space in the log head (c->lhead_offs) was known on mount. However, it is not the case - it was always 0. UBIFS does not store in it the master node and finds out by scanning the log on every mount. The fix is simple - just pass commit start node size instead of 0 to 'fixup_leb()'. Signed-off-by: Artem Bityutskiy Cc: stable@vger.kernel.org [v3.0+] Reported-by: Iwo Mergler Reported-by: James Nute --- fs/ubifs/sb.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index ef3d1ba..49382e7 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c @@ -718,8 +718,9 @@ static int fixup_free_space(struct ubifs_info *c) lnum = ubifs_next_log_lnum(c, lnum); } - /* Fixup the current log head */ - err = fixup_leb(c, c->lhead_lnum, c->lhead_offs); + /* Fixup the log head contains the only a CS node at the beginning */ + err = fixup_leb(c, c->lhead_lnum, + ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size)); if (err) goto out;