All of lore.kernel.org
 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, Ashish Samant <ashish.samant@oracle.com>,
	Junxiao Bi <junxiao.bi@oracle.com>,
	Joseph Qi <jiangqi903@gmail.com>,
	Mark Fasheh <mfasheh@versity.com>,
	Joel Becker <jlbec@evilplan.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.4 10/40] ocfs2: fstrim: Fix start offset of first cluster group during fstrim
Date: Mon,  6 Nov 2017 10:44:45 +0100	[thread overview]
Message-ID: <20171106094501.760927195@linuxfoundation.org> (raw)
In-Reply-To: <20171106094501.346859822@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Ashish Samant <ashish.samant@oracle.com>

commit 105ddc93f06ebe3e553f58563d11ed63dbcd59f0 upstream.

The first cluster group descriptor is not stored at the start of the
group but at an offset from the start.  We need to take this into
account while doing fstrim on the first cluster group.  Otherwise we
will wrongly start fstrim a few blocks after the desired start block and
the range can cross over into the next cluster group and zero out the
group descriptor there.  This can cause filesytem corruption that cannot
be fixed by fsck.

Link: http://lkml.kernel.org/r/1507835579-7308-1-git-send-email-ashish.samant@oracle.com
Signed-off-by: Ashish Samant <ashish.samant@oracle.com>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com>
Reviewed-by: Joseph Qi <jiangqi903@gmail.com>
Cc: Mark Fasheh <mfasheh@versity.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/ocfs2/alloc.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -7270,13 +7270,24 @@ out:
 
 static int ocfs2_trim_extent(struct super_block *sb,
 			     struct ocfs2_group_desc *gd,
-			     u32 start, u32 count)
+			     u64 group, u32 start, u32 count)
 {
 	u64 discard, bcount;
+	struct ocfs2_super *osb = OCFS2_SB(sb);
 
 	bcount = ocfs2_clusters_to_blocks(sb, count);
-	discard = le64_to_cpu(gd->bg_blkno) +
-			ocfs2_clusters_to_blocks(sb, start);
+	discard = ocfs2_clusters_to_blocks(sb, start);
+
+	/*
+	 * For the first cluster group, the gd->bg_blkno is not at the start
+	 * of the group, but at an offset from the start. If we add it while
+	 * calculating discard for first group, we will wrongly start fstrim a
+	 * few blocks after the desried start block and the range can cross
+	 * over into the next cluster group. So, add it only if this is not
+	 * the first cluster group.
+	 */
+	if (group != osb->first_cluster_group_blkno)
+		discard += le64_to_cpu(gd->bg_blkno);
 
 	trace_ocfs2_trim_extent(sb, (unsigned long long)discard, bcount);
 
@@ -7284,7 +7295,7 @@ static int ocfs2_trim_extent(struct supe
 }
 
 static int ocfs2_trim_group(struct super_block *sb,
-			    struct ocfs2_group_desc *gd,
+			    struct ocfs2_group_desc *gd, u64 group,
 			    u32 start, u32 max, u32 minbits)
 {
 	int ret = 0, count = 0, next;
@@ -7303,7 +7314,7 @@ static int ocfs2_trim_group(struct super
 		next = ocfs2_find_next_bit(bitmap, max, start);
 
 		if ((next - start) >= minbits) {
-			ret = ocfs2_trim_extent(sb, gd,
+			ret = ocfs2_trim_extent(sb, gd, group,
 						start, next - start);
 			if (ret < 0) {
 				mlog_errno(ret);
@@ -7401,7 +7412,8 @@ int ocfs2_trim_fs(struct super_block *sb
 		}
 
 		gd = (struct ocfs2_group_desc *)gd_bh->b_data;
-		cnt = ocfs2_trim_group(sb, gd, first_bit, last_bit, minlen);
+		cnt = ocfs2_trim_group(sb, gd, group,
+				       first_bit, last_bit, minlen);
 		brelse(gd_bh);
 		gd_bh = NULL;
 		if (cnt < 0) {

  parent reply	other threads:[~2017-11-06  9:49 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-06  9:44 [PATCH 4.4 00/40] 4.4.97-stable review Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 01/40] ALSA: timer: Add missing mutex lock for compat ioctls Greg Kroah-Hartman
2017-11-06  9:44   ` Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 02/40] ALSA: seq: Fix nested rwsem annotation for lockdep splat Greg Kroah-Hartman
2017-11-06  9:44   ` Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 03/40] cifs: check MaxPathNameComponentLength != 0 before using it Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 04/40] KEYS: return full count in keyring_read() if buffer is too small Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 05/40] KEYS: fix out-of-bounds read during ASN.1 parsing Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 06/40] ASoC: adau17x1: Workaround for noise bug in ADC Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 07/40] arm64: ensure __dump_instr() checks addr_limit Greg Kroah-Hartman
2017-11-13 19:05   ` Ben Hutchings
2017-11-14 13:52     ` Catalin Marinas
2017-11-14 13:52       ` Catalin Marinas
2017-11-14 16:18       ` Mark Rutland
2017-11-19 10:29         ` Greg Kroah-Hartman
2017-11-19 10:29           ` Greg Kroah-Hartman
2017-11-20 11:26           ` Mark Rutland
2017-11-21 16:55             ` Greg Kroah-Hartman
2017-11-15 13:28     ` Ben Hutchings
2017-11-15 13:36       ` Ben Hutchings
2017-11-06  9:44 ` [PATCH 4.4 08/40] ARM: dts: mvebu: pl310-cache disable double-linefill Greg Kroah-Hartman
2017-11-07 23:06   ` Sebastian Gottschall
2017-11-08  8:44     ` Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 09/40] ARM: 8715/1: add a private asm/unaligned.h Greg Kroah-Hartman
2017-11-06  9:44 ` Greg Kroah-Hartman [this message]
2017-11-06  9:44 ` [PATCH 4.4 11/40] perf tools: Fix build failure on perl script context Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 12/40] drm/msm: Fix potential buffer overflow issue Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 13/40] drm/msm: fix an integer overflow test Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 14/40] tracing/samples: Fix creation and deletion of simple_thread_fn creation Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 15/40] Fix tracing sample code warning Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 16/40] PM / wakeirq: report a wakeup_event on dedicated wekup irq Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 17/40] mmc: s3cmci: include linux/interrupt.h for tasklet_struct Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 18/40] ARM: pxa: Dont rely on public mmc header to include leds.h Greg Kroah-Hartman
2017-11-06  9:44   ` Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 19/40] mfd: ab8500-sysctrl: Handle probe deferral Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 20/40] mfd: axp20x: Fix axp288 PEK_DBR and PEK_DBF irqs being swapped Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 21/40] staging: rtl8712u: Fix endian settings for structs describing network packets Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 22/40] ext4: fix stripe-unaligned allocations Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 23/40] ext4: do not use stripe_width if it is not set Greg Kroah-Hartman
2017-11-06  9:44 ` [PATCH 4.4 24/40] i2c: riic: correctly finish transfers Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 26/40] perf tools: Only increase index if perf_evsel__new_idx() succeeds Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 27/40] cx231xx: Fix I2C on Internal Master 3 Bus Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 28/40] drm/msm/dsi: Set msm_dsi->encoders before initializing bridge Greg Kroah-Hartman
2017-11-07  4:32   ` Archit Taneja
2017-11-07 10:35     ` Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 29/40] xen/manage: correct return value check on xenbus_scanf() Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 30/40] scsi: aacraid: Process Error for response I/O Greg Kroah-Hartman
2017-11-06  9:45   ` Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 31/40] platform/x86: intel_mid_thermal: Fix module autoload Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 32/40] staging: lustre: llite: dont invoke direct_IO for the EOF case Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 33/40] staging: lustre: hsm: stack overrun in hai_dump_data_field Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 34/40] staging: lustre: ptlrpc: skip lock if export failed Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 35/40] exynos4-is: fimc-is: Unmap region obtained by of_iomap() Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 36/40] mei: return error on notification request to a disconnected client Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 37/40] s390/dasd: check for device error pointer within state change interrupts Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 38/40] bt8xx: fix memory leak Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 39/40] xen: dont print error message in case of missing Xenstore entry Greg Kroah-Hartman
2017-11-06  9:45 ` [PATCH 4.4 40/40] staging: r8712u: Fix Sparse warning in rtl871x_xmit.c Greg Kroah-Hartman
2017-11-06 21:17 ` [PATCH 4.4 00/40] 4.4.97-stable review Guenter Roeck
2017-11-06 23:26 ` Shuah Khan
2017-11-07 22:55 ` Tom Gall
2017-11-08  9:22   ` 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=20171106094501.760927195@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=ashish.samant@oracle.com \
    --cc=jiangqi903@gmail.com \
    --cc=jlbec@evilplan.org \
    --cc=junxiao.bi@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfasheh@versity.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.