From patchwork Fri Jun 19 11:01:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 28910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 7879FB725E for ; Fri, 19 Jun 2009 21:06:04 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MHbqu-0002mm-NX; Fri, 19 Jun 2009 11:01:48 +0000 Received: from mail-qy0-f179.google.com ([209.85.221.179]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MHbql-0002PP-8F for linux-mtd@lists.infradead.org; Fri, 19 Jun 2009 11:01:46 +0000 Received: by qyk9 with SMTP id 9so2481481qyk.28 for ; Fri, 19 Jun 2009 04:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=nI4xx9ZRlja/j+XuV7oByliIypoA6dJ7cLHEAgoUr5E=; b=YAp6W/8ihhQuNQx1AN/PYuOtQpkvGcH0c5r/Q6aEI87yxVrcN9XGIGN+wkOI1n/fiM Sbqfq7rY4+vdnqzNLVb9QJHgqAss3ahfYXH74hKjEr0rtrQNGyoBAp03dBCj3bZIEDBv o5TmOldw3vE2Ho1rzrWPr26SCWolvU4gUAdts= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; b=czgMEfEifkn4VTj8abnByya6q5sKlwh1P1Xae9NYDUrcY+5OGr8ttKVJSGrV/7w6lw EafOqcV0kwBvfSZ8G0z80a50w/gK2JwNDdA4nuTBZUcNGDc2Cw48WZh9V6shpJanAcgd wN/U2k/32/m8WFoKNEr1IL+Uqj7gTbB1Qnw+c= MIME-Version: 1.0 Received: by 10.229.97.14 with SMTP id j14mr486292qcn.102.1245409298022; Fri, 19 Jun 2009 04:01:38 -0700 (PDT) Date: Fri, 19 Jun 2009 16:31:38 +0530 X-Google-Sender-Auth: 0fcf5b034a55cace Message-ID: <6b5362aa0906190401l51bcf28bg44b9a7a9f49aa773@mail.gmail.com> Subject: [PATCH] [UBI] Volume table update fix From: Brijesh Singh To: dedekind@infradead.org X-Spam-Score: 0.0 (/) Cc: linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi, This patch fixes the consistency problem during volume update. UBI writes two copies of vtbl during volume update. If the first copy was successfully written, and second copy fails, UBI returns failure. But UBI recovers updated vtbl during next mount. So it should have returned success. It should go to read only mode to avoid further failures. Signed-off-by: Brijesh Singh diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 1afc61e..c776037 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c @@ -84,7 +84,7 @@ static struct ubi_vtbl_record empty_vtbl_record; int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, struct ubi_vtbl_record *vtbl_rec) { - int i, err; + int copy, err, err1; uint32_t crc; struct ubi_volume *layout_vol; @@ -99,19 +99,41 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, } memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); - for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { - err = ubi_eba_unmap_leb(ubi, layout_vol, i); + for (copy = 0; copy < UBI_LAYOUT_VOLUME_EBS; copy++) { + err = ubi_eba_unmap_leb(ubi, layout_vol, copy); if (err) - return err; + goto out_error; - err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, + err = ubi_eba_write_leb(ubi, layout_vol, copy, ubi->vtbl, 0, ubi->vtbl_size, UBI_LONGTERM); if (err) - return err; + goto out_error; } paranoid_vtbl_check(ubi); return 0; + +out_error: + /* If first copy was written,volume creation is successful. + * But switch to read only mode as we have only one copy. + * If first copy itself was not written, older version is in copy 2. + * Unmap first copy and call wl_flush. + * Volume creating is unsuccessful. + */ + ubi_err("Error writing volume table copy #%d", copy+1); + err1 = ubi_eba_unmap_leb(ubi, layout_vol, copy); + if (!err1) { + ubi_wl_flush(ubi); + /* Don't bother about error in flush + * We are going read only any ways + */ + } + ubi_ro_mode(ubi); + ubi_msg("Try detaching and attaching UBI again"); + if (copy > 0) + return 0; + else + return err; } /**