From patchwork Thu Nov 1 01:54:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 991794 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.alibaba.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42lpFm5gLNz9sD4 for ; Thu, 1 Nov 2018 12:55:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbeKAK4p (ORCPT ); Thu, 1 Nov 2018 06:56:45 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:59042 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725978AbeKAK4p (ORCPT ); Thu, 1 Nov 2018 06:56:45 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R261e4; CH=green; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01f04389; MF=bo.liu@linux.alibaba.com; NM=1; PH=DS; RN=1; SR=0; TI=SMTPD_---0TC.GqMw_1541037274; Received: from localhost(mailfrom:bo.liu@linux.alibaba.com fp:SMTPD_---0TC.GqMw_1541037274) by smtp.aliyun-inc.com(127.0.0.1); Thu, 01 Nov 2018 09:54:35 +0800 From: Liu Bo To: Subject: [PATCH] Ext4: fix ENOSPC when both quota and dioread_nolock are enabled Date: Thu, 1 Nov 2018 09:54:29 +0800 Message-Id: <1541037269-96483-1-git-send-email-bo.liu@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org With dioread_nolock, unwritten extents are converted in IO completion, and these extents may be merged with siblings. ext4_writepages() has reserved a handle to hold 2 credits for inode update and extent update and the handle will be used in IO completion as we can't start journal after clearing PageWriteback (due to locking rules). However, if quota is enabled, the following enospc situation could happen, ext4_convert_unwritten_extents ext4_ext_try_to_merge ext4_ext_try_to_merge_up ext4_journal_extend(handle, 2) # extend 2 credits for # bitmap/group_desc ext4_free_blocks() dquot_free_block // use 3 credits for 3 quota types // use 1 credit for inode update # update bitmap block # update group desc block # either of two updates may hit enospc # as ->h_buffer_credits has been consumed out. In ext4_ext_try_to_merge(), per-inode extent tree may be collasped into inode and ext4_free_blocks() will then free the unneeded blocks, but with quota being enabled, there aren't enough credits to process updates and we end up with -ENOSPC. As this is a corner case, instead of adding credits in ext4_writepages(), this just extends more credits for quota when doing merge-up. Fixes: ecb94f5fdf4b (ext4: collapse a single extent tree block into the inode if possible) CC: stable@vger.kernel.org # v3.6-rc1+ Signed-off-by: Liu Bo --- fs/ext4/extents.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 240b6dea5441..ff2498355e3c 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1812,6 +1812,7 @@ static void ext4_ext_try_to_merge_up(handle_t *handle, size_t s; unsigned max_root = ext4_ext_space_root(inode, 0); ext4_fsblk_t blk; + int credits = 2; if ((path[0].p_depth != 1) || (le16_to_cpu(path[0].p_hdr->eh_entries) != 1) || @@ -1820,10 +1821,12 @@ static void ext4_ext_try_to_merge_up(handle_t *handle, /* * We need to modify the block allocation bitmap and the block - * group descriptor to release the extent tree block. If we + * group descriptor to release the extent tree block. If + * quota is enabled, updates on quota are also needed. If we * can't get the journal credits, give up. */ - if (ext4_journal_extend(handle, 2)) + credits += EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); + if (ext4_journal_extend(handle, credits)) return; /*