Message ID | 20240111064208.2969599-2-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1266980dyi; Wed, 10 Jan 2024 22:42:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKBlAfuJoDo/aZcEaFZF5dDsj6TR7lhQHEBk0I0+ffyNkPQ1c8pm4qRRKckWGnIq3Nyg8T X-Received: by 2002:a17:903:2cc:b0:1d3:f285:ab4 with SMTP id s12-20020a17090302cc00b001d3f2850ab4mr974829plk.121.1704955372982; Wed, 10 Jan 2024 22:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704955372; cv=none; d=google.com; s=arc-20160816; b=wl56qH0Aa+JqRgfYZjTf7mk6TC2f4mWEIOU3Ak1WPJrabLGapCesaGA14AEPJaV3p8 LhUFQUZgVvGhJ0S3r2xeXx+xdp6vkBbNPrHx1MgujoHtPLcXDfR405SgCj7wjGlERA5e aiI/QbuPZhHsIcr5wI0z0ov0/EyBj+YVvVUmHp65cIqhCQPyJd3vMK51yjN258iQpgyN SFYPc8vz9gvAvT0gjbW/9GHd4us7jK9jdMmi9bWlIclNUqF58vcxLdxUMrOLI3dcBgJX P42HLgFpRRRXuPAd49kS7d8R6kFIl1Jzdgz9/19Hcx3eeYQfjRoUOFen87mVv87vlFev 0nnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=I7XXUYIr8Q9KF+4scUbYcSJk+NkBf5I8stoKQ5y70L8=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=oRyaThQ7DUa8/70V7JjS1e1/Iqf5yU01rTjRr6e8v8wd5QPy3uqoCSJS40rET5LOqY 8aIdyMmxbn/0wE9z1lt4pnc8oBRCJqtYDcDI7n28oHw01nLc7qLz3DcruZXR2Sa/KpV2 1TlreBmyK6HEyGFiTs4GZB9M+UmbkYNp3FXZIZaThX5zW64OQUoo0xIbJH95p+Wym0dh kimyrxVmDeMBXKFZnYXGOENinfOpqBC7GhPl21vxYqXr7Oa3svhjOU8R+sMqMg0QAqfV Ra/RejdtY8FLfaJ32xDPa3fFieSKZ8HIG1SEjwbhnq23VdlvvALysyS2ZqZ2NdnLGvXf Usaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKKjCjVP; spf=pass (google.com: domain of linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u8-20020a17090341c800b001d4b1c776c4si473888ple.376.2024.01.10.22.42.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 22:42:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKKjCjVP; spf=pass (google.com: domain of linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23105-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7A312288D1A for <ouuuleilei@gmail.com>; Thu, 11 Jan 2024 06:42:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DEE863D0; Thu, 11 Jan 2024 06:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DKKjCjVP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CF0F46B6 for <linux-kernel@vger.kernel.org>; Thu, 11 Jan 2024 06:42:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3183C43390; Thu, 11 Jan 2024 06:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704955337; bh=/uXMDvSOj4ElzaKYgiipftBm0qNMtUebJdjXyJwsNz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DKKjCjVPjWXCbOFCnOQfP0ek3Hvak8Z4Z3uLF1tVCIAxbItx0Vzqd05veQm/NExGD iOM8vgp+UBR/fVNGv64FMvCvbtO93CKnFzR75jMhwbaWIVT0GqmSKApPDlCBokfWst KzuO0i510CaClc/LAMhkdD2mzatL3DFFUYPoX/XZujTg9Af+1ItF6AB6dH7Gu0MehR wRq0DEQHJrERbJVZTwYp91rchogMv3z6LBvROIKClQ2YKm9tcj2bJ+MHjB8VjZPHKW RxQ7e9OywUM+31u6e4IQQDevQOzv0CpRhhzodicptp7ItZy1gwBERM3Saro06ty9Do UBqAEb0gaYFZg== From: Chao Yu <chao@kernel.org> To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org> Subject: [PATCH v4 2/6] f2fs: compress: fix to cover normal cluster write with cp_rwsem Date: Thu, 11 Jan 2024 14:42:04 +0800 Message-Id: <20240111064208.2969599-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240111064208.2969599-1-chao@kernel.org> References: <20240111064208.2969599-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787775284760086709 X-GMAIL-MSGID: 1787775284760086709 |
Series |
[v4,1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP
|
|
Commit Message
Chao Yu
Jan. 11, 2024, 6:42 a.m. UTC
When we overwrite compressed cluster w/ normal cluster, we should
not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data
will be corrupted if partial blocks were persisted before CP & SPOR,
due to cluster metadata wasn't updated atomically.
Fixes: 4c8ff7095bef ("f2fs: support data compression")
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/compress.c | 20 ++++++++++++++------
fs/f2fs/data.c | 3 ++-
2 files changed, 16 insertions(+), 7 deletions(-)
Comments
Reviewed-by: Daeho Jeong <daehojeong@google.com> On Wed, Jan 10, 2024 at 10:43 PM Chao Yu <chao@kernel.org> wrote: > > When we overwrite compressed cluster w/ normal cluster, we should > not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data > will be corrupted if partial blocks were persisted before CP & SPOR, > due to cluster metadata wasn't updated atomically. > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fs/f2fs/compress.c | 20 ++++++++++++++------ > fs/f2fs/data.c | 3 ++- > 2 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 9940b7886e5d..bf4cfab67aec 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1448,7 +1448,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > enum iostat_type io_type) > { > struct address_space *mapping = cc->inode->i_mapping; > - int _submitted, compr_blocks, ret, i; > + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); > + int _submitted, compr_blocks, ret = 0, i; > > compr_blocks = f2fs_compressed_blocks(cc); > > @@ -1463,6 +1464,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > if (compr_blocks < 0) > return compr_blocks; > > + /* overwrite compressed cluster w/ normal cluster */ > + if (compr_blocks > 0) > + f2fs_lock_op(sbi); > + > for (i = 0; i < cc->cluster_size; i++) { > if (!cc->rpages[i]) > continue; > @@ -1495,26 +1500,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > unlock_page(cc->rpages[i]); > ret = 0; > } else if (ret == -EAGAIN) { > + ret = 0; > /* > * for quota file, just redirty left pages to > * avoid deadlock caused by cluster update race > * from foreground operation. > */ > if (IS_NOQUOTA(cc->inode)) > - return 0; > - ret = 0; > + goto out; > f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); > goto retry_write; > } > - return ret; > + goto out; > } > > *submitted += _submitted; > } > > - f2fs_balance_fs(F2FS_M_SB(mapping), true); > +out: > + if (compr_blocks > 0) > + f2fs_unlock_op(sbi); > > - return 0; > + f2fs_balance_fs(sbi, true); > + return ret; > } > > int f2fs_write_multi_pages(struct compress_ctx *cc, > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index 81f9e2cc49e2..b171a9980f6a 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, > .encrypted_page = NULL, > .submitted = 0, > .compr_blocks = compr_blocks, > - .need_lock = LOCK_RETRY, > + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, > .post_read = f2fs_post_read_required(inode) ? 1 : 0, > .io_type = io_type, > .io_wbc = wbc, > @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, > if (err == -EAGAIN) { > err = f2fs_do_write_data_page(&fio); > if (err == -EAGAIN) { > + f2fs_bug_on(sbi, compr_blocks); > fio.need_lock = LOCK_REQ; > err = f2fs_do_write_data_page(&fio); > } > -- > 2.40.1 > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Cleaned up a bit: --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1443,13 +1443,14 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) } static int f2fs_write_raw_pages(struct compress_ctx *cc, - int *submitted, + int *submitted_p, struct writeback_control *wbc, enum iostat_type io_type) { struct address_space *mapping = cc->inode->i_mapping; struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); - int _submitted, compr_blocks, ret = 0, i; + int submitted, compr_blocks, i; + int ret = 0; compr_blocks = f2fs_compressed_blocks(cc); @@ -1492,7 +1493,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (!clear_page_dirty_for_io(cc->rpages[i])) goto continue_unlock; - ret = f2fs_write_single_data_page(cc->rpages[i], &_submitted, + ret = f2fs_write_single_data_page(cc->rpages[i], &submitted, NULL, NULL, wbc, io_type, compr_blocks, false); if (ret) { @@ -1514,7 +1515,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, goto out; } - *submitted += _submitted; + *submitted_p += submitted; } out: On 01/11, Chao Yu wrote: > When we overwrite compressed cluster w/ normal cluster, we should > not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data > will be corrupted if partial blocks were persisted before CP & SPOR, > due to cluster metadata wasn't updated atomically. > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fs/f2fs/compress.c | 20 ++++++++++++++------ > fs/f2fs/data.c | 3 ++- > 2 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 9940b7886e5d..bf4cfab67aec 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1448,7 +1448,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > enum iostat_type io_type) > { > struct address_space *mapping = cc->inode->i_mapping; > - int _submitted, compr_blocks, ret, i; > + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); > + int _submitted, compr_blocks, ret = 0, i; > > compr_blocks = f2fs_compressed_blocks(cc); > > @@ -1463,6 +1464,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > if (compr_blocks < 0) > return compr_blocks; > > + /* overwrite compressed cluster w/ normal cluster */ > + if (compr_blocks > 0) > + f2fs_lock_op(sbi); > + > for (i = 0; i < cc->cluster_size; i++) { > if (!cc->rpages[i]) > continue; > @@ -1495,26 +1500,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > unlock_page(cc->rpages[i]); > ret = 0; > } else if (ret == -EAGAIN) { > + ret = 0; > /* > * for quota file, just redirty left pages to > * avoid deadlock caused by cluster update race > * from foreground operation. > */ > if (IS_NOQUOTA(cc->inode)) > - return 0; > - ret = 0; > + goto out; > f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); > goto retry_write; > } > - return ret; > + goto out; > } > > *submitted += _submitted; > } > > - f2fs_balance_fs(F2FS_M_SB(mapping), true); > +out: > + if (compr_blocks > 0) > + f2fs_unlock_op(sbi); > > - return 0; > + f2fs_balance_fs(sbi, true); > + return ret; > } > > int f2fs_write_multi_pages(struct compress_ctx *cc, > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index 81f9e2cc49e2..b171a9980f6a 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, > .encrypted_page = NULL, > .submitted = 0, > .compr_blocks = compr_blocks, > - .need_lock = LOCK_RETRY, > + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, > .post_read = f2fs_post_read_required(inode) ? 1 : 0, > .io_type = io_type, > .io_wbc = wbc, > @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, > if (err == -EAGAIN) { > err = f2fs_do_write_data_page(&fio); > if (err == -EAGAIN) { > + f2fs_bug_on(sbi, compr_blocks); > fio.need_lock = LOCK_REQ; > err = f2fs_do_write_data_page(&fio); > } > -- > 2.40.1
Thanks, let me resend v5 w/ blow cleanups. On 2024/1/13 9:39, Jaegeuk Kim wrote: > Cleaned up a bit: > > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1443,13 +1443,14 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) > } > > static int f2fs_write_raw_pages(struct compress_ctx *cc, > - int *submitted, > + int *submitted_p, > struct writeback_control *wbc, > enum iostat_type io_type) > { > struct address_space *mapping = cc->inode->i_mapping; > struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); > - int _submitted, compr_blocks, ret = 0, i; > + int submitted, compr_blocks, i; > + int ret = 0; > > compr_blocks = f2fs_compressed_blocks(cc); > > @@ -1492,7 +1493,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > if (!clear_page_dirty_for_io(cc->rpages[i])) > goto continue_unlock; > > - ret = f2fs_write_single_data_page(cc->rpages[i], &_submitted, > + ret = f2fs_write_single_data_page(cc->rpages[i], &submitted, > NULL, NULL, wbc, io_type, > compr_blocks, false); > if (ret) { > @@ -1514,7 +1515,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, > goto out; > } > > - *submitted += _submitted; > + *submitted_p += submitted; > } > > out: > > On 01/11, Chao Yu wrote: >> When we overwrite compressed cluster w/ normal cluster, we should >> not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data >> will be corrupted if partial blocks were persisted before CP & SPOR, >> due to cluster metadata wasn't updated atomically. >> >> Fixes: 4c8ff7095bef ("f2fs: support data compression") >> Signed-off-by: Chao Yu <chao@kernel.org> >> --- >> fs/f2fs/compress.c | 20 ++++++++++++++------ >> fs/f2fs/data.c | 3 ++- >> 2 files changed, 16 insertions(+), 7 deletions(-) >> >> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c >> index 9940b7886e5d..bf4cfab67aec 100644 >> --- a/fs/f2fs/compress.c >> +++ b/fs/f2fs/compress.c >> @@ -1448,7 +1448,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, >> enum iostat_type io_type) >> { >> struct address_space *mapping = cc->inode->i_mapping; >> - int _submitted, compr_blocks, ret, i; >> + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); >> + int _submitted, compr_blocks, ret = 0, i; >> >> compr_blocks = f2fs_compressed_blocks(cc); >> >> @@ -1463,6 +1464,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, >> if (compr_blocks < 0) >> return compr_blocks; >> >> + /* overwrite compressed cluster w/ normal cluster */ >> + if (compr_blocks > 0) >> + f2fs_lock_op(sbi); >> + >> for (i = 0; i < cc->cluster_size; i++) { >> if (!cc->rpages[i]) >> continue; >> @@ -1495,26 +1500,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, >> unlock_page(cc->rpages[i]); >> ret = 0; >> } else if (ret == -EAGAIN) { >> + ret = 0; >> /* >> * for quota file, just redirty left pages to >> * avoid deadlock caused by cluster update race >> * from foreground operation. >> */ >> if (IS_NOQUOTA(cc->inode)) >> - return 0; >> - ret = 0; >> + goto out; >> f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); >> goto retry_write; >> } >> - return ret; >> + goto out; >> } >> >> *submitted += _submitted; >> } >> >> - f2fs_balance_fs(F2FS_M_SB(mapping), true); >> +out: >> + if (compr_blocks > 0) >> + f2fs_unlock_op(sbi); >> >> - return 0; >> + f2fs_balance_fs(sbi, true); >> + return ret; >> } >> >> int f2fs_write_multi_pages(struct compress_ctx *cc, >> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >> index 81f9e2cc49e2..b171a9980f6a 100644 >> --- a/fs/f2fs/data.c >> +++ b/fs/f2fs/data.c >> @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, >> .encrypted_page = NULL, >> .submitted = 0, >> .compr_blocks = compr_blocks, >> - .need_lock = LOCK_RETRY, >> + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, >> .post_read = f2fs_post_read_required(inode) ? 1 : 0, >> .io_type = io_type, >> .io_wbc = wbc, >> @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, >> if (err == -EAGAIN) { >> err = f2fs_do_write_data_page(&fio); >> if (err == -EAGAIN) { >> + f2fs_bug_on(sbi, compr_blocks); >> fio.need_lock = LOCK_REQ; >> err = f2fs_do_write_data_page(&fio); >> } >> -- >> 2.40.1
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 9940b7886e5d..bf4cfab67aec 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1448,7 +1448,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, enum iostat_type io_type) { struct address_space *mapping = cc->inode->i_mapping; - int _submitted, compr_blocks, ret, i; + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); + int _submitted, compr_blocks, ret = 0, i; compr_blocks = f2fs_compressed_blocks(cc); @@ -1463,6 +1464,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (compr_blocks < 0) return compr_blocks; + /* overwrite compressed cluster w/ normal cluster */ + if (compr_blocks > 0) + f2fs_lock_op(sbi); + for (i = 0; i < cc->cluster_size; i++) { if (!cc->rpages[i]) continue; @@ -1495,26 +1500,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, unlock_page(cc->rpages[i]); ret = 0; } else if (ret == -EAGAIN) { + ret = 0; /* * for quota file, just redirty left pages to * avoid deadlock caused by cluster update race * from foreground operation. */ if (IS_NOQUOTA(cc->inode)) - return 0; - ret = 0; + goto out; f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); goto retry_write; } - return ret; + goto out; } *submitted += _submitted; } - f2fs_balance_fs(F2FS_M_SB(mapping), true); +out: + if (compr_blocks > 0) + f2fs_unlock_op(sbi); - return 0; + f2fs_balance_fs(sbi, true); + return ret; } int f2fs_write_multi_pages(struct compress_ctx *cc, diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 81f9e2cc49e2..b171a9980f6a 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, .encrypted_page = NULL, .submitted = 0, .compr_blocks = compr_blocks, - .need_lock = LOCK_RETRY, + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, .post_read = f2fs_post_read_required(inode) ? 1 : 0, .io_type = io_type, .io_wbc = wbc, @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, if (err == -EAGAIN) { err = f2fs_do_write_data_page(&fio); if (err == -EAGAIN) { + f2fs_bug_on(sbi, compr_blocks); fio.need_lock = LOCK_REQ; err = f2fs_do_write_data_page(&fio); }