Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm snapshot: suspend merging snapshot when doing exception handover

The "dm snapshot: suspend origin when doing exception handover" commit
fixed a exception store handover bug associated with pending exceptions
to the "snapshot-origin" target.

However, a similar problem exists in snapshot merging. When snapshot
merging is in progress, we use the target "snapshot-merge" instead of
"snapshot-origin". Consequently, during exception store handover, we
must find the snapshot-merge target and suspend its associated
mapped_device.

To avoid lockdep warnings, the target must be suspended and resumed
without holding _origins_lock.

Introduce a dm_hold() function that grabs a reference on a
mapped_device, but unlike dm_get(), it doesn't crash if the device has
the DMF_FREEING flag set, it returns an error in this case.

In snapshot_resume() we grab the reference to the origin device using
dm_hold() while holding _origins_lock (_origins_lock guarantees that the
device won't disappear). Then we release _origins_lock, suspend the
device and grab _origins_lock again.

NOTE to stable@ people:
When backporting to kernels 3.18 and older, use dm_internal_suspend and
dm_internal_resume instead of dm_internal_suspend_fast and
dm_internal_resume_fast.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org

authored by

Mikulas Patocka and committed by
Mike Snitzer
09ee96b2 b735fede

+43 -6
+29 -6
drivers/md/dm-snap.c
··· 1888 1888 static void snapshot_resume(struct dm_target *ti) 1889 1889 { 1890 1890 struct dm_snapshot *s = ti->private; 1891 - struct dm_snapshot *snap_src = NULL, *snap_dest = NULL; 1891 + struct dm_snapshot *snap_src = NULL, *snap_dest = NULL, *snap_merging = NULL; 1892 1892 struct dm_origin *o; 1893 1893 struct mapped_device *origin_md = NULL; 1894 + bool must_restart_merging = false; 1894 1895 1895 1896 down_read(&_origins_lock); 1896 1897 1897 1898 o = __lookup_dm_origin(s->origin->bdev); 1898 1899 if (o) 1899 1900 origin_md = dm_table_get_md(o->ti->table); 1901 + if (!origin_md) { 1902 + (void) __find_snapshots_sharing_cow(s, NULL, NULL, &snap_merging); 1903 + if (snap_merging) 1904 + origin_md = dm_table_get_md(snap_merging->ti->table); 1905 + } 1900 1906 if (origin_md == dm_table_get_md(ti->table)) 1901 1907 origin_md = NULL; 1908 + if (origin_md) { 1909 + if (dm_hold(origin_md)) 1910 + origin_md = NULL; 1911 + } 1902 1912 1903 - if (origin_md) 1913 + up_read(&_origins_lock); 1914 + 1915 + if (origin_md) { 1904 1916 dm_internal_suspend_fast(origin_md); 1917 + if (snap_merging && test_bit(RUNNING_MERGE, &snap_merging->state_bits)) { 1918 + must_restart_merging = true; 1919 + stop_merge(snap_merging); 1920 + } 1921 + } 1922 + 1923 + down_read(&_origins_lock); 1905 1924 1906 1925 (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL); 1907 1926 if (snap_src && snap_dest) { ··· 1931 1912 up_write(&snap_src->lock); 1932 1913 } 1933 1914 1934 - if (origin_md) 1935 - dm_internal_resume_fast(origin_md); 1936 - 1937 1915 up_read(&_origins_lock); 1916 + 1917 + if (origin_md) { 1918 + if (must_restart_merging) 1919 + start_merge(snap_merging); 1920 + dm_internal_resume_fast(origin_md); 1921 + dm_put(origin_md); 1922 + } 1938 1923 1939 1924 /* Now we have correct chunk size, reregister */ 1940 1925 reregister_snapshot(s); ··· 2383 2360 2384 2361 static struct target_type merge_target = { 2385 2362 .name = dm_snapshot_merge_target_name, 2386 - .version = {1, 2, 0}, 2363 + .version = {1, 3, 0}, 2387 2364 .module = THIS_MODULE, 2388 2365 .ctr = snapshot_ctr, 2389 2366 .dtr = snapshot_dtr,
+13
drivers/md/dm.c
··· 2616 2616 BUG_ON(test_bit(DMF_FREEING, &md->flags)); 2617 2617 } 2618 2618 2619 + int dm_hold(struct mapped_device *md) 2620 + { 2621 + spin_lock(&_minor_lock); 2622 + if (test_bit(DMF_FREEING, &md->flags)) { 2623 + spin_unlock(&_minor_lock); 2624 + return -EBUSY; 2625 + } 2626 + dm_get(md); 2627 + spin_unlock(&_minor_lock); 2628 + return 0; 2629 + } 2630 + EXPORT_SYMBOL_GPL(dm_hold); 2631 + 2619 2632 const char *dm_device_name(struct mapped_device *md) 2620 2633 { 2621 2634 return md->name;
+1
include/linux/device-mapper.h
··· 375 375 */ 376 376 struct mapped_device *dm_get_md(dev_t dev); 377 377 void dm_get(struct mapped_device *md); 378 + int dm_hold(struct mapped_device *md); 378 379 void dm_put(struct mapped_device *md); 379 380 380 381 /*