linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Akilesh Kailash <akailash@google.com>,
	Mike Snitzer <snitzer@redhat.com>
Subject: [PATCH 4.19 09/43] dm snapshot: flush merged data before committing metadata
Date: Mon, 18 Jan 2021 12:34:32 +0100	[thread overview]
Message-ID: <20210118113335.395586843@linuxfoundation.org> (raw)
In-Reply-To: <20210118113334.966227881@linuxfoundation.org>

From: Akilesh Kailash <akailash@google.com>

commit fcc42338375a1e67b8568dbb558f8b784d0f3b01 upstream.

If the origin device has a volatile write-back cache and the following
events occur:

1: After finishing merge operation of one set of exceptions,
   merge_callback() is invoked.
2: Update the metadata in COW device tracking the merge completion.
   This update to COW device is flushed cleanly.
3: System crashes and the origin device's cache where the recent
   merge was completed has not been flushed.

During the next cycle when we read the metadata from the COW device,
we will skip reading those metadata whose merge was completed in
step (1). This will lead to data loss/corruption.

To address this, flush the origin device post merge IO before
updating the metadata.

Cc: stable@vger.kernel.org
Signed-off-by: Akilesh Kailash <akailash@google.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/md/dm-snap.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -137,6 +137,11 @@ struct dm_snapshot {
 	 * for them to be committed.
 	 */
 	struct bio_list bios_queued_during_merge;
+
+	/*
+	 * Flush data after merge.
+	 */
+	struct bio flush_bio;
 };
 
 /*
@@ -1061,6 +1066,17 @@ shut:
 
 static void error_bios(struct bio *bio);
 
+static int flush_data(struct dm_snapshot *s)
+{
+	struct bio *flush_bio = &s->flush_bio;
+
+	bio_reset(flush_bio);
+	bio_set_dev(flush_bio, s->origin->bdev);
+	flush_bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
+
+	return submit_bio_wait(flush_bio);
+}
+
 static void merge_callback(int read_err, unsigned long write_err, void *context)
 {
 	struct dm_snapshot *s = context;
@@ -1074,6 +1090,11 @@ static void merge_callback(int read_err,
 		goto shut;
 	}
 
+	if (flush_data(s) < 0) {
+		DMERR("Flush after merge failed: shutting down merge");
+		goto shut;
+	}
+
 	if (s->store->type->commit_merge(s->store,
 					 s->num_merging_chunks) < 0) {
 		DMERR("Write error in exception store: shutting down merge");
@@ -1198,6 +1219,7 @@ static int snapshot_ctr(struct dm_target
 	s->first_merging_chunk = 0;
 	s->num_merging_chunks = 0;
 	bio_list_init(&s->bios_queued_during_merge);
+	bio_init(&s->flush_bio, NULL, 0);
 
 	/* Allocate hash table for COW data */
 	if (init_hash_tables(s)) {
@@ -1391,6 +1413,8 @@ static void snapshot_dtr(struct dm_targe
 
 	mutex_destroy(&s->lock);
 
+	bio_uninit(&s->flush_bio);
+
 	dm_put_device(ti, s->cow);
 
 	dm_put_device(ti, s->origin);



  parent reply	other threads:[~2021-01-18 19:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 11:34 [PATCH 4.19 00/43] 4.19.169-rc1 review Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 01/43] ASoC: dapm: remove widget from dirty list on free Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 02/43] x86/hyperv: check cpu mask after interrupt has been disabled Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 03/43] tracing/kprobes: Do the notrace functions check without kprobes on ftrace Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 04/43] MIPS: boot: Fix unaligned access with CONFIG_MIPS_RAW_APPENDED_DTB Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 05/43] MIPS: Fix malformed NT_FILE and NT_SIGINFO in 32bit coredumps Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 06/43] MIPS: relocatable: fix possible boot hangup with KASLR enabled Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 07/43] ACPI: scan: Harden acpi_device_add() against device ID overflows Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 08/43] mm/hugetlb: fix potential missing huge page size info Greg Kroah-Hartman
2021-01-18 11:34 ` Greg Kroah-Hartman [this message]
2021-01-18 11:34 ` [PATCH 4.19 10/43] dm integrity: fix the maximum number of arguments Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 11/43] r8152: Add Lenovo Powered USB-C Travel Hub Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 12/43] ext4: fix bug for rename with RENAME_WHITEOUT Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 13/43] ARC: build: remove non-existing bootpImage from KBUILD_IMAGE Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 14/43] ARC: build: add uImage.lzma to the top-level target Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 15/43] ARC: build: add boot_targets to PHONY Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 16/43] btrfs: fix transaction leak and crash after RO remount caused by qgroup rescan Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 17/43] ethernet: ucc_geth: fix definition and size of ucc_geth_tx_global_pram Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 18/43] bfq: Fix computation of shallow depth Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 19/43] arch/arc: add copy_user_page() to <asm/page.h> to fix build error on ARC Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 20/43] misdn: dsp: select CONFIG_BITREVERSE Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 21/43] net: ethernet: fs_enet: Add missing MODULE_LICENSE Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 22/43] ACPI: scan: add stub acpi_create_platform_device() for !CONFIG_ACPI Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 23/43] drm/msm: Call msm_init_vram before binding the gpu Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 24/43] ARM: picoxcell: fix missing interrupt-parent properties Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 25/43] ima: Remove __init annotation from ima_pcrread() Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 26/43] dump_common_audit_data(): fix racy accesses to ->d_name Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 27/43] ASoC: meson: axg-tdm-interface: fix loopback Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 28/43] ASoC: Intel: fix error code cnl_set_dsp_D0() Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 29/43] NFS4: Fix use-after-free in trace_event_raw_event_nfs4_set_lock Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 30/43] pNFS: Mark layout for return if return-on-close was not sent Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 31/43] NFS/pNFS: Fix a leak of the layout plh_outstanding counter Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 32/43] NFS: nfs_igrab_and_active must first reference the superblock Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 33/43] ext4: fix superblock checksum failure when setting password salt Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 34/43] RDMA/usnic: Fix memleak in find_free_vf_and_create_qp_grp Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 35/43] RDMA/mlx5: Fix wrong free of blue flame register on error Greg Kroah-Hartman
2021-01-18 11:34 ` [PATCH 4.19 36/43] mm, slub: consider rest of partial list if acquire_slab() fails Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 37/43] net: sunrpc: interpret the return value of kstrtou32 correctly Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 38/43] dm: eliminate potential source of excessive kernel log noise Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 39/43] ALSA: firewire-tascam: Fix integer overflow in midi_port_work() Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 40/43] ALSA: fireface: Fix integer overflow in transmit_midi_msg() Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 41/43] netfilter: conntrack: fix reading nf_conntrack_buckets Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 42/43] netfilter: nf_nat: Fix memleak in nf_nat_init Greg Kroah-Hartman
2021-01-18 11:35 ` [PATCH 4.19 43/43] kbuild: enforce -Werror=return-type Greg Kroah-Hartman
2021-01-18 14:40 ` [PATCH 4.19 00/43] 4.19.169-rc1 review Naresh Kamboju
2021-01-18 15:24   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118113335.395586843@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akailash@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).