android_kernel_google_msm/drivers/md
NeilBrown 0570dab32d md/raid10: don't clear bitmap bit when bad-block-list write fails.
commit c340702ca26a628832fade4f133d8160a55c29cc upstream.

When a write fails and a bad-block-list is present, we can
update the bad-block-list instead of writing the data.  If
this succeeds then it is OK clear the relevant bitmap-bit as
no further 'sync' of the block is needed.

However if writing the bad-block-list fails then we need to
treat the write as failed and particularly must not clear
the bitmap bit.  Otherwise the device can be re-added (after
any hardware connection issues are resolved) and because the
relevant bit in the bitmap is clear, that block will not be
resynced.  This leads to data corruption.

We already delay the final bio_endio() on the write until
the bad-block-list is written so that when the write
returns: either that data is safe, the bad-block record is
safe, or the fact that the device is faulty is safe.
However we *don't* delay the clearing of the bitmap, so the
bitmap bit can be recorded as cleared before we know if the
bad-block-list was written safely.

So: delay that until the write really is safe.
i.e. move the call to close_write() until just before
calling bio_endio(), and recheck the 'is array degraded'
status before making that call.

This bug goes back to v3.1 when bad-block-lists were
introduced, though it only affects arrays created with
mdadm-3.3 or later as only those have bad-block lists.

Backports will require at least
Commit: 95af587e95aa ("md/raid10: ensure device failure recorded before write request returns.")
as well.  I'll send that to 'stable' separately.

Note that of the two tests of R10BIO_WriteError that this
patch adds, the first is certain to fail and the second is
certain to succeed.  However doing it this way makes the
patch more obviously correct.  I will tidy the code up in a
future merge window.

Reported-by: Nate Dailey <nate.dailey@stratus.com>
Fixes: bd870a16c5 ("md/raid10:  Handle write errors by updating badblock log.")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
2016-04-27 18:55:21 +08:00
..
persistent-data dm btree remove: fix a bug when rebalancing nodes after removal 2016-03-21 09:17:58 +08:00
bitmap.c md/bitmap: fix calculation of 'chunks' - missing shift. 2012-05-04 17:03:18 +10:00
bitmap.h md/bitmap: fix calculation of 'chunks' - missing shift. 2012-05-04 17:03:18 +10:00
dm-bio-record.h
dm-bufio.c dm bufio: change __GFP_IO to __GFP_FS in shrinker callbacks 2015-02-02 17:05:16 +08:00
dm-bufio.h dm bufio: prefetch 2012-03-28 18:41:29 +01:00
dm-builtin.c dm sysfs: fix a module unload race 2014-02-20 10:45:32 -08:00
dm-crypt.c dm crypt: fix deadlock when async crypto algorithm returns -EBUSY 2015-09-18 09:20:30 +08:00
dm-delay.c dm delay: fix a possible deadlock due to shared workqueue 2013-12-20 07:34:20 -08:00
dm-exception-store.c dm exception store: fix init error path 2012-03-28 18:41:22 +01:00
dm-exception-store.h
dm-flakey.c dm: fix truncated status strings 2013-12-08 07:29:43 -08:00
dm-io.c dm io: deal with wandering queue limits when handling REQ_DISCARD and REQ_WRITE_SAME 2015-06-19 11:40:25 +08:00
dm-ioctl.c dm: fix truncated status strings 2013-12-08 07:29:43 -08:00
dm-kcopyd.c
dm-linear.c dm: fix truncated status strings 2013-12-08 07:29:43 -08:00
dm-log-userspace-base.c
dm-log-userspace-transfer.c dm log userspace: fix memory leak in dm_ulog_tfr_init failure path 2015-02-02 17:04:47 +08:00
dm-log-userspace-transfer.h
dm-log.c dm: reject trailing characters in sccanf input 2012-03-28 18:41:26 +01:00
dm-mpath.c dm mpath: fix race condition between multipath_dtr and pg_init_done 2014-06-07 16:02:05 -07:00
dm-mpath.h
dm-path-selector.c
dm-path-selector.h
dm-queue-length.c dm: reject trailing characters in sccanf input 2012-03-28 18:41:26 +01:00
dm-raid.c dm raid: ensure superblock's size matches device's logical block size 2015-02-02 17:05:17 +08:00
dm-raid1.c dm mirror: do not degrade the mirror on discard error 2015-06-19 11:40:16 +08:00
dm-region-hash.c dm raid1: fix crash with mirror recovery and discard 2012-07-29 08:04:21 -07:00
dm-round-robin.c dm: reject trailing characters in sccanf input 2012-03-28 18:41:26 +01:00
dm-service-time.c dm: reject trailing characters in sccanf input 2012-03-28 18:41:26 +01:00
dm-snap-persistent.c dm snapshot: fix data corruption 2013-11-04 04:23:42 -08:00
dm-snap-transient.c
dm-snap.c dm snapshot: fix a possible invalid memory access on unload 2015-06-19 11:40:17 +08:00
dm-stripe.c dm: fix truncated status strings 2013-12-08 07:29:43 -08:00
dm-sysfs.c dm sysfs: fix a module unload race 2014-02-20 10:45:32 -08:00
dm-table.c dm table: fail dm_table_create on dm_round_up overflow 2013-12-20 07:34:20 -08:00
dm-target.c
dm-thin-metadata.c dm thin: relax hard limit on the maximum size of a metadata device 2012-03-28 18:41:28 +01:00
dm-thin-metadata.h dm thin: relax hard limit on the maximum size of a metadata device 2012-03-28 18:41:28 +01:00
dm-thin.c dm thin: allocate the cell_sort_array dynamically 2016-03-21 09:17:41 +08:00
dm-uevent.c
dm-uevent.h
dm-verity.c dm: fix truncated status strings 2013-12-08 07:29:43 -08:00
dm-zero.c
dm.c dm: hold suspend_lock while suspending device during device deletion 2015-06-19 11:40:25 +08:00
dm.h dm sysfs: fix a module unload race 2014-02-20 10:45:32 -08:00
faulty.c md: tidy up rdev_for_each usage. 2012-03-19 12:46:39 +11:00
Kconfig scsi_dh: fix randconfig build error 2016-04-27 18:55:18 +08:00
linear.c md/linear: If md_integrity_register() fails, linear_run() must free the mem. 2012-04-02 09:48:37 +10:00
linear.h
Makefile dm sysfs: fix a module unload race 2014-02-20 10:45:32 -08:00
md.c md: flush ->event_work before stopping array. 2016-03-21 09:17:46 +08:00
md.h md/raid10: handle merge_bvec_fn in member devices. 2012-03-19 12:46:39 +11:00
multipath.c md: tidy up rdev_for_each usage. 2012-03-19 12:46:39 +11:00
multipath.h
raid0.c md/raid0: apply base queue limits *before* disk_stack_limits 2016-04-27 18:55:20 +08:00
raid0.h md: add proper merge_bvec handling to RAID0 and Linear. 2012-03-19 12:46:39 +11:00
raid1.c md/raid1: extend spinlock to protect raid1_end_read_request against inconsistencies 2016-03-21 09:17:50 +08:00
raid1.h
raid5.c md/raid5: don't record new size if resize_stripes fails. 2015-09-18 09:20:38 +08:00
raid5.h md/raid5: fix interaction of 'replace' and 'recovery'. 2013-08-04 16:26:00 +08:00
raid10.c md/raid10: don't clear bitmap bit when bad-block-list write fails. 2016-04-27 18:55:21 +08:00
raid10.h md/raid10: ensure device failure recorded before write request returns. 2016-04-27 18:55:21 +08:00