Skip to contentSkip to conversation

Mounting UBIFS readonly - is it really readonly?

DISCUSSION Sergei Zhirikov 2 participants 6 messages Jul 27, 2010 – Aug 23, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi,

I hope someone can help me to resolve the following mystery.

I'm using UBIFS as the root filesystem always mounted readonly. The kernel boot parameters are:
console=ttyS0,115200 ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs ro loglevel=6

As you can see, there is "ro", which causes UBIFS to be initially mounted readonly. And later it is *never* remounted read-write. Everything seems to work as expected (I get "Read-only file system" error upon a write attempt) except one thing. Somehow the modification time of /dev/console is updated every time the system boots. Note: I'm not talking about the /dev/console located inside the /dev mount (which is tmpfs and is obvously writable), I'm talking about the /dev/console located on the root file system and accessed (probably by init) before /dev is mounted. I'm really puzzled. How is this possible? The root filesystem has been readonly all the time and still the timestamp is somehow updated. Does anyone have an idea what might be going on there?

I'm using kernel 2.6.33.6 and classic sysvinit-2.86.

Thanks and regards,
Sergei.

#1 lore raw
Quoted 20 lines · Sergei Zhirikov

I hope someone can help me to resolve the following mystery.

I'm using UBIFS as the root filesystem always mounted readonly. The kernel boot parameters are:
console=ttyS0,115200 ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs ro loglevel=6

As you can see, there is "ro", which causes UBIFS to be initially mounted readonly. And later it is *never* remounted read-write. Everything seems to work as expected (I get "Read-only file system" error upon a write attempt) except one thing. Somehow the modification time of /dev/console is updated every time the system boots. Note: I'm not talking about the /dev/console located inside the /dev mount (which is tmpfs and is obvously writable), I'm talking about the /dev/console located on the root file system and accessed (probably by init) before /dev is mounted. I'm really puzzled. How is this possible? The root filesystem has been readonly all the time and still the timestamp is somehow updated. Does anyone have an idea what might be going on there?

Quoted 1 line

I'm using kernel 2.6.33.6 and classic sysvinit-2.86.

Hi,

very brief comment as I have not time now, sorry. Try to hack UBIFS and add prints to the following functions:

ubifs_remount_rw()
mount_ubifs(), print if 'mounted_read_only != 0'

this way you will check whether UBIFS is really always RO.

Also, add a print to 'ubifs_write_inode()' to make sure no inodes are ever written. Actually, there is already a 'dbg_gen()' print, just turn it into

printk(KERN_CRIT "inode %lu, mode %#x, nlink %u\n",
inode->i_ino, (int)inode->i_mode, inode->i_nlink);

Also, add a print in 'ubifs_iget()' and print the timestamp there. Do this after 'ubifs_tnc_lookup()'. Print timestamp there. You can even find out inode number for /dev/console, and print this only for this inode number.

This way you will see what is actually going on in UBIFS and prove that there is an UBIFS bug, if there is.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#2 lore raw
In reply to Sergei Zhirikov
Quoted 4 lines · Sergei Zhirikov

As you can see, there is "ro", which causes UBIFS to be initially mounted readonly. And later it is *never* remounted read-write. Everything seems to work as expected (I get "Read-only file system" error upon a write attempt) except one thing. Somehow the modification

Quoted 8 lines

time of /dev/console is updated every time the system boots. Note: I'm not talking about the /dev/console located inside the /dev mount (which is tmpfs and is obvously writable), I'm talking about the /dev/console located on the root file system and accessed (probably by init) before /dev is mounted. I'm really puzzled. How is this possible? The root filesystem has been readonly all the time and still the timestamp is somehow updated. Does anyone have an idea what might be going on there?

Did you solve the issue, I'm just curious.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#3 lore raw
Quoted 14 lines · Artem Bityutskiy
Quoted 4 lines · Sergei Zhirikov

As you can see, there is "ro", which causes UBIFS to be initially mounted readonly. And later it is *never* remounted read-write. Everything seems to work as expected (I get "Read-only file system" error upon a write attempt) except one thing. Somehow the modification

Quoted 8 lines

time of /dev/console is updated every time the system boots. Note: I'm not talking about the /dev/console located inside the /dev mount (which is tmpfs and is obvously writable), I'm talking about the /dev/console located on the root file system and accessed (probably by init) before /dev is mounted. I'm really puzzled. How is this possible? The root filesystem has been readonly all the time and still the timestamp is somehow updated. Does anyone have an idea what might be going on there?

Quoted 1 line

Did you solve the issue, I'm just curious.

I think you can use inotify to verify whether the FS is ever changed?

http://en.wikipedia.org/wiki/Inotify

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#4 lore raw
Quoted 31 lines

From: Artem Bityutskiy <[email protected]>
Subject: Re: Mounting UBIFS readonly - is it really readonly?
To: "Sergei Zhirikov" <[email protected]>
Cc: [email protected]
Date: Monday, August 23, 2010, 2:41 PM

Quoted 1 line · Artem Bityutskiy

On Tue, 2010-07-27 at 21:05 +0200, Sergei Zhirikov

Quoted 1 line · wrote:
Quoted 1 line

As you can see, there is "ro", which causes UBIFS

to be initially

Quoted 1 line
Quoted 1 line

mounted readonly. And later it is *never*

remounted read-write.

Quoted 1 line
Quoted 1 line

Everything seems to work as expected (I get

"Read-only file system"

Quoted 1 line
Quoted 1 line

error upon a write attempt) except one thing.

Somehow the modification

Quoted 1 line
Quoted 1 line

time of /dev/console is updated every time the

system boots. Note: I'm

Quoted 1 line
Quoted 1 line

not talking about the /dev/console located inside

the /dev mount

Quoted 1 line
Quoted 1 line

(which is tmpfs and is obvously writable), I'm

talking about

Quoted 1 line
Quoted 1 line

the /dev/console located on the root file system

and accessed

Quoted 1 line
Quoted 1 line

(probably by init) before /dev is mounted. I'm

really puzzled. How is

Quoted 1 line
Quoted 1 line

this possible? The root filesystem has been

readonly all the time and

Quoted 1 line
Quoted 1 line

still the timestamp is somehow updated. Does

anyone have an idea what

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

might be going on there?

Did you solve the issue, I'm just curious.

I think you can use inotify to verify whether the FS is ever changed?

http://en.wikipedia.org/wiki/Inotify

I made the changes you suggested earlier to see if/when something is written and the results were quite unexpected. Just as I assumed, UBIFS remains mounted read-only all the time. But contrary to what I expected, none of the functions related to writing is ever called. Nevertheless, the timestamp still changes.

I have also managed to reproduce the issue without involving system reboot. If I create a device node equivalent to /dev/console (major 5, minor 1) in any directory (on the root UBIFS) and then remount the FS read-only, the timestamp of the device node keeps changing upon any write operation to the device. The same thing happens when I try /dev/tty (major 5, minor 0), but with /dev/null (1,3) or /dev/zero (1,5) the timestamp does not change.

I'm now even more puzzled than I was in the beginning. It looks like the VFS decides to update the timestamp for some reason, but does not pass that change to UBIFS (perhaps, because it knows the latter is read-only). So the updated timestamp exists only cached in memory and is never actually written to the FS. I haven't tried to verify that theory yet (which shouldn't be difficult).

--
Sergei.

#5 lore raw
Quoted 6 lines · Sergei Zhirikov

I made the changes you suggested earlier to see if/when something is written and the results were quite unexpected. Just as I assumed, UBIFS remains mounted read-only all the time. But contrary to what I expected, none of the functions related to writing is ever called. Nevertheless, the timestamp still changes.

Quoted 7 lines

I have also managed to reproduce the issue without involving system reboot. If I create a device node equivalent to /dev/console (major 5, minor 1) in any directory (on the root UBIFS) and then remount the FS read-only, the timestamp of the device node keeps changing upon any write operation to the device. The same thing happens when I try /dev/tty (major 5, minor 0), but with /dev/null (1,3) or /dev/zero (1,5) the timestamp does not change.

This suggests this is not VFS but tty-specific.

Quoted 6 lines

I'm now even more puzzled than I was in the beginning. It looks like the VFS decides to update the timestamp for some reason, but does not pass that change to UBIFS (perhaps, because it knows the latter is read-only). So the updated timestamp exists only cached in memory and is never actually written to the FS. I haven't tried to verify that theory yet (which shouldn't be difficult).

It's late here and I'm heading to the bed, but while passing by my computer I've quickly took a look and I can see the following in drivers/char/tty_io.c:

tty_write() cales do_tty_write() which changes mtime:

inode->i_mtime = current_fs_time(inode->i_sb);

So it looks like this is a feature - ever write to /dev/console changes mtime. It looks like [amc]time for device nodes are not always FS inode times, but they may belong to the _driver_ which is represented by the character device. I guess tty is just very special and this might be just legacy stuff.

I might be mistaking though, good night :-)

Artem.