Skip to contentSkip to conversation

Add readonly support to replace BUG_ON phrase

RFC PATCH In review Miao Xie 5 participants 8 messages Nov 25, 2010 – Nov 30, 2010 Btrfs file system

lore
Share & tools
lore

Miao Xie

author
#0 lore raw

cover Add readonly support to replace BUG_ON phrase

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just return their error number to callers.

2. For others, We can force the filesystem readonly when it hits errors, which is what this patchset has done. Replaced BUG_ON() with the interface provided in this patchset, we will get error infomation via dmesg. Since btrfs is now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)
#1 lore raw

2010/11/25, Miao Xie <[email protected]>:

Quoted 4 lines

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

Yes, I agree.

Quoted 4 lines

1. For those errors which can be handled well by callers, we just return their
error number to callers.

It's a good idea.

Quoted 26 lines

2. For others, We can force the filesystem readonly when it hits errors, which
is what this patchset has done. Replaced BUG_ON() with the interface
provided
in this patchset, we will get error infomation via dmesg. Since btrfs is
now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100
++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Miao Xie
Quoted 17 lines · Miao Xie

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just return their error number to callers.

2. For others, We can force the filesystem readonly when it hits errors, which is what this patchset has done. Replaced BUG_ON() with the interface provided in this patchset, we will get error infomation via dmesg. Since btrfs is now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

Quoted 7 lines
---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)

Overall seems sane, but what about kernels that don't make these checks? I'm ok with "well sucks for them" as an answer, just want to make sure we've at least though about it.

Also I'm not sure marking the fs as broken is the right move here. Ext3/4 don't do this, they just mount read-only, as long as you can still unmount the filesystem everything comes out ok. Think of the case where we just get a spurious EIO, the fs should be fine the next time around, there's reason to force the user to run fsck in this case.

Thanks,

Josef

#3 lore raw
Quoted 2 lines · Josef Bacik
Quoted 1 line · Miao Xie

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant =

panic.

Quoted 1 line
Quoted 1 line

Meanwhile, they are very ugly and should be handled more propriately=

=2E

Quoted 4 lines
Quoted 4 lines

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just re=

turn their

Quoted 3 lines
Quoted 3 lines

error number to callers.

2. For others, We can force the filesystem readonly when it hits err=

ors, which

Quoted 1 line
Quoted 1 line

=C2=A0is what this patchset has done. Replaced BUG_ON() with the int=

erface provided

Quoted 1 line
Quoted 1 line

=C2=A0in this patchset, we will get error infomation via dmesg. Sinc=

e btrfs is now

Quoted 1 line
Quoted 1 line

readonly, we can save our data safely and umount it, then a btrfsck =

is

Quoted 3 lines
Quoted 3 lines

recommended.

By these ways, we can protect our filesystem from panic caused by th=

ose

Quoted 6 lines
Quoted 6 lines

BUG_ONs.

---
=C2=A0fs/btrfs/ctree.h =C2=A0 =C2=A0 =C2=A0 | =C2=A0 21 ++++++++++ =C2=A0fs/btrfs/disk-io.c =C2=A0 =C2=A0 | =C2=A0 23 +++++++++++ =C2=A0fs/btrfs/super.c =C2=A0 =C2=A0 =C2=A0 | =C2=A0100 ++++++++++++=

++++++++++++++++++++++++++++++++++-

Quoted 5 lines
Quoted 3 lines

=C2=A0fs/btrfs/transaction.c | =C2=A0 =C2=A07 +++ =C2=A04 files changed, 148 insertions(+), 3 deletions(-)

Overall seems sane, but what about kernels that don't make these chec=

ks? =C2=A0I'm ok

Quoted 1 line

with "well sucks for them" as an answer, just want to make sure we've=

at least

Quoted 3 lines

though about it.

Also I'm not sure marking the fs as broken is the right move here. =C2=

=A0Ext3/4 don't

Quoted 1 line

do this, they just mount read-only, as long as you can still unmount =

the

Quoted 1 line

filesystem everything comes out ok. =C2=A0Think of the case where we =

just get a

Quoted 1 line

spurious EIO, the fs should be fine the next time around, there's rea=

son to

Quoted 2 lines

force the user to run fsck in this case.

Did you mean "there's no reason to"?

Also I guess you mean this in the case when there is no redundancy (single and raid0) as the other cases should recover from spurious EIO at run time.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 1 line · Mike Fedyk

On Mon, Nov 29, 2010 at 12:10 PM, Josef Bacik <[email protected]> wrot=

e:

Quoted 2 lines
Quoted 2 lines · Miao Xie
Quoted 1 line

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasan=

t panic.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Meanwhile, they are very ugly and should be handled more propriate=

ly.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just =

return their

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

error number to callers.

2. For others, We can force the filesystem readonly when it hits e=

rrors, which

Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0is what this patchset has done. Replaced BUG_ON() with the inte=

rface provided

Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0in this patchset, we will get error infomation via dmesg. Since=

btrfs is now

Quoted 1 line
Quoted 1 line
Quoted 1 line

readonly, we can save our data safely and umount it, then a btrfsc=

k is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

recommended.

By these ways, we can protect our filesystem from panic caused by =

those

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

BUG_ONs.

---
=A0fs/btrfs/ctree.h =A0 =A0 =A0 | =A0 21 ++++++++++ =A0fs/btrfs/disk-io.c =A0 =A0 | =A0 23 +++++++++++ =A0fs/btrfs/super.c =A0 =A0 =A0 | =A0100 +++++++++++++++++++++++++=

+++++++++++++++++++++-

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

=A0fs/btrfs/transaction.c | =A0 =A07 +++
=A04 files changed, 148 insertions(+), 3 deletions(-)

Overall seems sane, but what about kernels that don't make these ch=

ecks? =A0I'm ok

Quoted 1 line
Quoted 1 line

with "well sucks for them" as an answer, just want to make sure we'=

ve at least

Quoted 3 lines
Quoted 3 lines

though about it.

Also I'm not sure marking the fs as broken is the right move here. =

=A0Ext3/4 don't

Quoted 1 line
Quoted 1 line

do this, they just mount read-only, as long as you can still unmoun=

t the

Quoted 1 line
Quoted 1 line

filesystem everything comes out ok. =A0Think of the case where we j=

ust get a

Quoted 1 line
Quoted 1 line

spurious EIO, the fs should be fine the next time around, there's r=

eason to

Quoted 5 lines
Quoted 2 lines

force the user to run fsck in this case.

=20
Did you mean "there's no reason to"?

Right yes, thank you.
=20

Quoted 2 lines

Also I guess you mean this in the case when there is no redundancy (single and raid0) as the other cases should recover from spurious EI=

O

Quoted 1 line

at run time.

Right, I'm speaking of transient errors that don't really mean anything catastrophic. Thanks,

Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Josef Bacik
Quoted 26 lines · Josef Bacik
Quoted 17 lines · Miao Xie

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just return their error number to callers.

2. For others, We can force the filesystem readonly when it hits errors, which is what this patchset has done. Replaced BUG_ON() with the interface provided in this patchset, we will get error infomation via dmesg. Since btrfs is now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

Quoted 7 lines
---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)
Quoted 3 lines

Overall seems sane, but what about kernels that don't make these checks? I'm ok with "well sucks for them" as an answer, just want to make sure we've at least though about it.

You mean those code that does nothing on ret-checks?

IMO, if the code really needs ret-check, we should deal with them seriously, or just leave it alone. And this is a step-by-step job.

Quoted 7 lines

Also I'm not sure marking the fs as broken is the right move here. Ext3/4 don't do this, they just mount read-only, as long as you can still unmount the filesystem everything comes out ok. Think of the case where we just get a spurious EIO, the fs should be fine the next time around, there's reason to force the user to run fsck in this case.

Yes, I agree on this.
For spurious EIO, it mainly depends on coders, returning the errno to caller may work on bypassing fsck.

While I'm working on this readonly stuff, it is difficult to solve the potential deadlock when we write the super block to disk.
Since btrfs supports multi-device, before write-super, we must get the device lock "device_list_mutex" first, and this has puzzled me a lot.

BTW, I've tried another way to bypass deadlock. I made the write-super stuff into umount, which can make us free from deadlock, however, while testing this, it seemes that umount cannot work due to a ext3/4 jbd oops, I'm digging on this oops...

So, any ideas about free from deadlock?

Quoted 4 lines

Thanks,

Josef

#6 lore raw
Quoted 27 lines · liubo
Quoted 26 lines · Josef Bacik
Quoted 24 lines · Miao Xie

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just return their error number to callers.

2. For others, We can force the filesystem readonly when it hits errors, which is what this patchset has done. Replaced BUG_ON() with the interface provided in this patchset, we will get error infomation via dmesg. Since btrfs is now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)
Quoted 9 lines
Quoted 3 lines

Overall seems sane, but what about kernels that don't make these checks? I'm ok with "well sucks for them" as an answer, just want to make sure we've at least though about it.

You mean those code that does nothing on ret-checks?

IMO, if the code really needs ret-check, we should deal with them seriously, or just leave it alone. And this is a step-by-step job.

Sorry I mean for older kernels that don't know about these "hey your fs is screwed" flags. It seems like they'll just get ignored, are we sure thats what we want to happen? I'm fine with that, but if we don't want that to happen it may be good to have a incompat flag.

Quoted 8 lines
Quoted 7 lines

Also I'm not sure marking the fs as broken is the right move here. Ext3/4 don't do this, they just mount read-only, as long as you can still unmount the filesystem everything comes out ok. Think of the case where we just get a spurious EIO, the fs should be fine the next time around, there's reason to force the user to run fsck in this case.

Quoted 4 lines

Yes, I agree on this.
For spurious EIO, it mainly depends on coders, returning the errno to caller may work on bypassing fsck.

Right I'm worried about the flipping read only stuff being kicked by EIO, which happens with ext* and could happen with btrfs in the right cases. I'm not saying thats wrong, its what should happen, I'm just saying we need to be able to unmount the filesystem and mount it back up without needing to run an fsck in between.

Quoted 11 lines

While I'm working on this readonly stuff, it is difficult to solve the potential deadlock when we write the super block to disk.
Since btrfs supports multi-device, before write-super, we must get the device lock "device_list_mutex" first, and this has puzzled me a lot.

BTW, I've tried another way to bypass deadlock. I made the write-super stuff into umount, which can make us free from deadlock, however, while testing this, it seemes that umount cannot work due to a ext3/4 jbd oops, I'm digging on this oops...

So, any ideas about free from deadlock?

None :). The best thing I can think of is do like we're doing with the read only stuff and only write out the super right before we flip read only, and then make umount make sure that if we're mounted read only to not do anything.

Truth be told I hate this "mark the fs as broken" idea. We don't know if the error we got means the filesystem is broken (for example the EIO case). If we do hit actual corruption maybe it would be good, and in that case we should write out the super at the point we find that corruption and then flip read only and have that be the only time we have to worry about writing out the super.

So I guess that's 2 options

1) Ditch the "the fs is broken" flag. This makes things nice and simple since on-disk is already consistent, all we have to do is drop anything thats dirty and we're home free.

2) Keep the flag, but only worry about writing it out on a case by case basis. So we have a btrfs_corrupt_fs() function that writes out the super with the appropriate flag, and then flips the fs read only. Then we don't have to do anything special in the common paths, just the normal "hey is this fs read only?" things, so for all other cases we can just flip the fs read only and everything works.

I hope that makes sense, if not feel free to ignore me and just keep doing what you've been doing :). Thanks,

Josef

#7 lore raw
Quoted 32 lines · Josef Bacik
Quoted 31 lines · liubo
Quoted 25 lines · Josef Bacik
Quoted 17 lines · Miao Xie

Btrfs has a number of BUG_ON()s, which may lead btrfs to unpleasant panic. Meanwhile, they are very ugly and should be handled more propriately.

There are mainly two ways to deal with these BUG_ON()s.

1. For those errors which can be handled well by callers, we just return their error number to callers.

2. For others, We can force the filesystem readonly when it hits errors, which is what this patchset has done. Replaced BUG_ON() with the interface provided in this patchset, we will get error infomation via dmesg. Since btrfs is now
readonly, we can save our data safely and umount it, then a btrfsck is recommended.

By these ways, we can protect our filesystem from panic caused by those BUG_ONs.

Quoted 7 lines
---
 fs/btrfs/ctree.h       |   21 ++++++++++
 fs/btrfs/disk-io.c     |   23 +++++++++++
 fs/btrfs/super.c       |  100 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/transaction.c |    7 +++
 4 files changed, 148 insertions(+), 3 deletions(-)
Quoted 3 lines

Overall seems sane, but what about kernels that don't make these checks? I'm ok with "well sucks for them" as an answer, just want to make sure we've at least though about it.

You mean those code that does nothing on ret-checks?

Quoted 9 lines
Quoted 3 lines

IMO, if the code really needs ret-check, we should deal with them seriously, or just leave it alone. And this is a step-by-step job.

Sorry I mean for older kernels that don't know about these "hey your fs is screwed" flags. It seems like they'll just get ignored, are we sure thats what we want to happen? I'm fine with that, but if we don't want that to happen it may be good to have a incompat flag.

Ohh, got it, thanks for pointing it out. Will do it later.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

Also I'm not sure marking the fs as broken is the right move here. Ext3/4 don't do this, they just mount read-only, as long as you can still unmount the filesystem everything comes out ok. Think of the case where we just get a spurious EIO, the fs should be fine the next time around, there's reason to force the user to run fsck in this case.

Yes, I agree on this.
For spurious EIO, it mainly depends on coders, returning the errno to caller may work on bypassing fsck.

Quoted 6 lines

Right I'm worried about the flipping read only stuff being kicked by EIO, which happens with ext* and could happen with btrfs in the right cases. I'm not saying thats wrong, its what should happen, I'm just saying we need to be able to unmount the filesystem and mount it back up without needing to run an fsck in between.

hm, this really makes sense.

Since it is difficult to tell whether a fake corruption it is, what about just implementing readonly stuff like this and making it more friendly to EIO in future?

Quoted 28 lines
Quoted 11 lines

While I'm working on this readonly stuff, it is difficult to solve the potential deadlock when we write the super block to disk.
Since btrfs supports multi-device, before write-super, we must get the device lock "device_list_mutex" first, and this has puzzled me a lot.

BTW, I've tried another way to bypass deadlock. I made the write-super stuff into umount, which can make us free from deadlock, however, while testing this, it seemes that umount cannot work due to a ext3/4 jbd oops, I'm digging on this oops...

So, any ideas about free from deadlock?

None :). The best thing I can think of is do like we're doing with the read only stuff and only write out the super right before we flip read only, and then make umount make sure that if we're mounted read only to not do anything.

Truth be told I hate this "mark the fs as broken" idea. We don't know if the error we got means the filesystem is broken (for example the EIO case). If we do hit actual corruption maybe it would be good, and in that case we should write out the super at the point we find that corruption and then flip read only and have that be the only time we have to worry about writing out the super.

So I guess that's 2 options

1) Ditch the "the fs is broken" flag. This makes things nice and simple since on-disk is already consistent, all we have to do is drop anything thats dirty and we're home free.

Quoted 7 lines

2) Keep the flag, but only worry about writing it out on a case by case basis. So we have a btrfs_corrupt_fs() function that writes out the super with the appropriate flag, and then flips the fs read only. Then we don't have to do anything special in the common paths, just the normal "hey is this fs read only?" things, so for all other cases we can just flip the fs read only and everything works.

The 2) is what I have just done. :)

Quoted 3 lines

I hope that makes sense, if not feel free to ignore me and just keep doing what you've been doing :). Thanks,

They are very helpful.

Thanks,
Liu Bo

Quoted 6 lines

Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html