From patchwork Thu Oct 9 10:25:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 397984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 02AC01400BB for ; Thu, 9 Oct 2014 21:29:21 +1100 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XcAwZ-0003rn-I0; Thu, 09 Oct 2014 10:27:35 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XcAwX-0003pE-2i for linux-mtd@lists.infradead.org; Thu, 09 Oct 2014 10:27:33 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id E31D77EE; Thu, 9 Oct 2014 12:27:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [190.2.108.156]) by mail.free-electrons.com (Postfix) with ESMTPSA id DE5DB7A8; Thu, 9 Oct 2014 12:27:09 +0200 (CEST) Date: Thu, 9 Oct 2014 07:25:46 -0300 From: Ezequiel Garcia To: Andrew Murray Subject: Re: UBI_READWRITE constraint when opening volumes to rename Message-ID: <20141009102546.GA2755@arch.hh.imgtec.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.22 (2013-10-16) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141009_032733_280106_20CF3729 X-CRM114-Status: GOOD ( 17.78 ) X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Richard Weinberger , linux-mtd@lists.infradead.org, dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On 07 Oct 03:31 PM, Andrew Murray wrote: > Hello, > > I'd like to be able to safely rename a UBI volume that contains a > mounted UBIFS volume. > > This allows for firmware upgrade via the following steps: > > - ubimkvol rootfs_new > - ubiupdatevol rootfs_new > - ubirename rootfs rootfs_old rootfs_new rootfs > - reboot > - ubirmvol rootfs_old > > Such an approach makes upgrade of a root filesystem simple as there is > no need to unmount the root filesystem. I believe this question has > been asked before on this mailing list > (http://lists.infradead.org/pipermail/linux-mtd/2012-February/039743.html). > > This process isn't possible at the moment as 'rename_volumes' opens > the UBI volume with UBI_READWRITE. Unfortunately UBIFS always opens > UBI with UBI_READWRITE regardless to if the user mounts as read-only. How about making UBIFS honour the read-only mount flag? A quick look to fs/ubifs/io.c shows that UBIFS will show an error message if a LEB erase/write operation is attempted on a read-only mounted or read-only media. So, hopefully, this is reasonable (the patch is completely untested!): diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 106bf20..ce445ce 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -1998,11 +1998,16 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) { struct ubifs_info *c = sb->s_fs_info; struct inode *root; - int err; + int err, mode; + + /* + * Re-open the UBI device in read-write mode, or keep it read-only if + * explicitly requested. + */ + mode = (sb->s_flags & MS_RDONLY) ? UBI_READONLY : UBI_READWRITE; c->vfs_sb = sb; - /* Re-open the UBI device in read-write mode */ - c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); + c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, mode); if (IS_ERR(c->ubi)) { err = PTR_ERR(c->ubi); goto out;