UBI_READWRITE constraint when opening volumes to rename
Ezequiel Garcia
ezequiel.garcia at free-electrons.com
Thu Oct 9 03:25:46 PDT 2014
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;
--
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
More information about the linux-mtd
mailing list