Skip to contentSkip to conversation

dm-raid: Do not call BUG() in __rdev_sectors()

PATCH RESEND In review Hannes Reinecke 4 participants 5 messages Jun 28, 2017 – Jun 30, 2017 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 dm-raid: Do not call BUG() in __rdev_sectors()

__rdev_sectors() might be called for an invalid/non-existing RAID set during raid_ctr(), which is perfectly fine and no reason to panic.

---
 drivers/md/dm-raid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +2 -1
index 7d89322..9bbb596 100644
@@ -1571,7 +1571,8 @@ static sector_t __rdev_sectors(struct raid_set *rs)
 			return rdev->sectors;
 	}
 
-	BUG(); /* Constructor ensures we got some. */
+	/* No valid raid devices */
+	return 0;
 }
 
 /* Calculate the sectors per device and per array used for @rs */
Signature · 1 line
1.8.5.6
#1 lore raw
Quoted 26 lines · Hannes Reinecke

__rdev_sectors() might be called for an invalid/non-existing RAID set during raid_ctr(), which is perfectly fine and no reason to panic.

---
 drivers/md/dm-raid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +2 -1
index 7d89322..9bbb596 100644
@@ -1571,7 +1571,8 @@ static sector_t __rdev_sectors(struct raid_set *rs)
 			return rdev->sectors;
 	}
 
-	BUG(); /* Constructor ensures we got some. */
+	/* No valid raid devices */
+	return 0;
 }
 
 /* Calculate the sectors per device and per array used for @rs */
Signature · 1 line
1.8.5.6

The use of BUG() is certainly suspect. BUG() is very rarely the right answer.

But I don't think returning 0 makes sense for all __rdev_sectors() callers, e.g.: rs_setup_recovery()

__rdev_sectors() could easily be made to check if ti->error is passed as a non-NULL pointer.. if so set *error, return 0, have ctr check for 0, and gracefully fail ctr by returning the ti->error that __rdev_sectors() set. If the error pointer passed to __rdev_sectors() is NULL, resort to BUG() still? Would really like to avoid BUG().. but I'll defer to Heinz on what might be a better response.

Alternatively, you could look to see where "Constructor ensures we got some." and fix the fact that it clearly isn't ensuring as much for your case?

Mike

#2 lore raw
In reply to Hannes Reinecke

Hi Hannes,

thanks for your patch.

BUG() is intentional there to catch what I've already fixed with patch

"[dm-devel] [PATCH] dm raid: fix oops on upgrading to extended superblock format"

on 06/23/2017.

IOW: returning 0 is never right and would hide bugs like that one fixed.

Heinz

Quoted 23 lines · Hannes Reinecke

__rdev_sectors() might be called for an invalid/non-existing RAID set during raid_ctr(), which is perfectly fine and no reason to panic.

---
  drivers/md/dm-raid.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +2 -1
index 7d89322..9bbb596 100644
@@ -1571,7 +1571,8 @@ static sector_t __rdev_sectors(struct raid_set *rs)
  			return rdev->sectors;
  	}
 
-	BUG(); /* Constructor ensures we got some. */
+	/* No valid raid devices */
+	return 0;
  }
 
  /* Calculate the sectors per device and per array used for @rs */
#3 lore raw
Quoted 5 lines · Heinz Mauelshagen

Hi Hannes,

thanks for your patch.

Quoted 8 lines

BUG() is intentional there to catch what I've already fixed with patch

"[dm-devel] [PATCH] dm raid: fix oops on upgrading to extended superblock format"

on 06/23/2017.

IOW: returning 0 is never right and would hide bugs like that one fixed.

OTOH panicing systems to catch errors which could've been mitigted is never right as well. Not a single time. Never. BUG() and BUG_ON() are not for error handling.

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#4 lore raw
Quoted 10 lines · Johannes Thumshirn
Quoted 9 lines · Heinz Mauelshagen

Hi Hannes,

thanks for your patch.

BUG() is intentional there to catch what I've already fixed with patch

"[dm-devel] [PATCH] dm raid: fix oops on upgrading to extended superblock format"

Quoted 6 lines
Quoted 3 lines

on 06/23/2017.

IOW: returning 0 is never right and would hide bugs like that one fixed.

OTOH panicing systems to catch errors which could've been mitigted is never right as well. Not a single time. Never. BUG() and BUG_ON() are not for error handling.

Point taken. We'll change that.

Quoted 1 line