Commit f402693d06f32e746c6153e459c5fb064fa02741

Authored by Mike Snitzer
Committed by Alasdair G Kergon
1 parent 36be50515f

dm thin: fix table output when pool target disables discard passdown internally

When the thin pool target clears the discard_passdown parameter
internally, it incorrectly changes the table line reported to userspace.
This breaks dumb string comparisons on these table lines in generic
userspace device-mapper library code and leads to tables being reloaded
repeatedly when nothing is actually meant to be changing.

This patch corrects this by no longer changing the table line when
discard passdown was disabled.

We can still tell when discard passdown is overridden by looking for the
message "Discard unsupported by data device (sdX): Disabling discard passdown."

This automatic detection is also moved from the 'load' to the 'resume'
so that it is re-evaluated should the properties of underlying devices
change.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

Showing 1 changed file with 17 additions and 15 deletions Side-by-side Diff

drivers/md/dm-thin.c
... ... @@ -1632,6 +1632,21 @@
1632 1632 pool->low_water_blocks = pt->low_water_blocks;
1633 1633 pool->pf = pt->pf;
1634 1634  
  1635 + /*
  1636 + * If discard_passdown was enabled verify that the data device
  1637 + * supports discards. Disable discard_passdown if not; otherwise
  1638 + * -EOPNOTSUPP will be returned.
  1639 + */
  1640 + if (pt->pf.discard_passdown) {
  1641 + struct request_queue *q = bdev_get_queue(pt->data_dev->bdev);
  1642 + if (!q || !blk_queue_discard(q)) {
  1643 + char buf[BDEVNAME_SIZE];
  1644 + DMWARN("Discard unsupported by data device (%s): Disabling discard passdown.",
  1645 + bdevname(pt->data_dev->bdev, buf));
  1646 + pool->pf.discard_passdown = 0;
  1647 + }
  1648 + }
  1649 +
1635 1650 return 0;
1636 1651 }
1637 1652  
... ... @@ -1988,19 +2003,6 @@
1988 2003 goto out_flags_changed;
1989 2004 }
1990 2005  
1991   - /*
1992   - * If discard_passdown was enabled verify that the data device
1993   - * supports discards. Disable discard_passdown if not; otherwise
1994   - * -EOPNOTSUPP will be returned.
1995   - */
1996   - if (pf.discard_passdown) {
1997   - struct request_queue *q = bdev_get_queue(data_dev->bdev);
1998   - if (!q || !blk_queue_discard(q)) {
1999   - DMWARN("Discard unsupported by data device: Disabling discard passdown.");
2000   - pf.discard_passdown = 0;
2001   - }
2002   - }
2003   -
2004 2006 pt->pool = pool;
2005 2007 pt->ti = ti;
2006 2008 pt->metadata_dev = metadata_dev;
... ... @@ -2385,7 +2387,7 @@
2385 2387 (unsigned long long)pt->low_water_blocks);
2386 2388  
2387 2389 count = !pool->pf.zero_new_blocks + !pool->pf.discard_enabled +
2388   - !pool->pf.discard_passdown;
  2390 + !pt->pf.discard_passdown;
2389 2391 DMEMIT("%u ", count);
2390 2392  
2391 2393 if (!pool->pf.zero_new_blocks)
... ... @@ -2394,7 +2396,7 @@
2394 2396 if (!pool->pf.discard_enabled)
2395 2397 DMEMIT("ignore_discard ");
2396 2398  
2397   - if (!pool->pf.discard_passdown)
  2399 + if (!pt->pf.discard_passdown)
2398 2400 DMEMIT("no_discard_passdown ");
2399 2401  
2400 2402 break;