Skip to contentSkip to conversation

md device is read only mode

DISCUSSION Piergiorgio Sartor 2 participants 4 messages Jul 5, 2012 – Jul 9, 2012 MD RAID

lore
Share & tools
lore
#0 lore raw

Hi all,

following the comment of Neil about the fact that an md device, in r/o mode, will BUG() in case of write attempt, I would like to ask for some more information on the topic.

The problem is the following, mounting a filesystem in r/o does not, correctly, prevent writes to the underlying device.

Now, assuming a filesystem is mounted r/w over an md device, being r/w too, it is pretty clear that switching the md device to r/o will create problems.

What if the md device is started in r/o mode and than, later, the filesystem is mounted *without* specifying r/o mode?

The filesystem might try to write to the device, but it will not work, of course.
Does this will cause a BUG() in md?

Because using a r/o memory card, there are no problems, the mount recognize the device is r/o and it sets the filesystems r/o too.
I do not know if it anyway tries to write to the r/o device, ignoring the errors reported.

I would say that, if md BUG() in any case, it could be a bug... :-)

Any comments?

Thanks,

bye,

Signature · 1 line
piergiorgio
#1 lore raw
Quoted 10 lines · On Thu, 5 Jul 2012 19:27:48 +0200 Piergiorgio Sartor…

Hi all,

following the comment of Neil about the fact that an md device, in r/o mode, will BUG() in case of write attempt, I would like to ask for some more information on the topic.

The problem is the following, mounting a filesystem in r/o does not, correctly, prevent writes to the underlying device.

This is only half the story.
If the mount command requests read-only, the filesystem may still write to the device.
However if the device is marked read-only then the filesystem should not write to the disk - if it finds that it needs to, it should fail the mount request.
I believe that filesystems behave correctly in this manner, though there could still be bugs lurking.

Quoted 4 lines

Now, assuming a filesystem is mounted r/w over an md device, being r/w too, it is pretty clear that switching the md device to r/o will create problems.

Not quite. When the filesystem is mounted, md will refuse to switch the device to read-only, so that scenario is not possible.

Quoted 4 lines

What if the md device is started in r/o mode and than, later, the filesystem is mounted *without* specifying r/o mode?

The mount system call will notice that the device is read-only, and will make assume the read-only mount option.

Quoted 4 lines

The filesystem might try to write to the device, but it will not work, of course.
Does this will cause a BUG() in md?

Only if there are bugs.

Quoted 7 lines

Because using a r/o memory card, there are no problems, the mount recognize the device is r/o and it sets the filesystems r/o too.
I do not know if it anyway tries to write to the r/o device, ignoring the errors reported.

Quoted 9 lines

I would say that, if md BUG() in any case, it could be a bug... :-)

Any comments?

Thanks,

bye,

NeilBrown

#2 lore raw

Hi Neil,

please see one comment below.

On Mon, Jul 09, 2012 at 11:40:22AM +1000, NeilBrown wrote:
[...]

Quoted 2 lines

The mount system call will notice that the device is read-only, and will make assume the read-only mount option.

OK, so it should work as expected.

The story was this.
After fixing the RAID-5 superblock problem, we wanted to see if the filesystem was still OK. So we started the RAID in r/o mode (so to avoid any possible further damage from mount) and then mounted the filesystem (actually, now that I think of it, there was an LVM layer in the middle). This mount caused a kernel error report (I do not know if BUG() or else).

Is there any explanation for that?

Thanks,

bye,

Signature · 1 line
piergiorgio
#3 lore raw
Quoted 21 lines · On Mon, 9 Jul 2012 19:34:07 +0200 Piergiorgio Sartor…

Hi Neil,

please see one comment below.

On Mon, Jul 09, 2012 at 11:40:22AM +1000, NeilBrown wrote:
[...]

Quoted 2 lines

The mount system call will notice that the device is read-only, and will make assume the read-only mount option.

OK, so it should work as expected.

The story was this.
After fixing the RAID-5 superblock problem, we wanted to see if the filesystem was still OK. So we started the RAID in r/o mode (so to avoid any possible further damage from mount) and then mounted the filesystem (actually, now that I think of it, there was an LVM layer in the middle). This mount caused a kernel error report (I do not know if BUG() or else).

Quoted 1 line

Is there any explanation for that?

Probably LVM isn't detecting that the underlying device is readonly and so forcing the upper device to be readonly.
md doesn't do this either - it should.

NeilBrown