Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp245221ybi; Wed, 29 May 2019 20:32:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqypsW7e4LzeFjb7svv+28Nga2USSVf8qcDhRf2d3uN9PJElSB4/9m4J4oD8aMagBpB4wwb0 X-Received: by 2002:a63:1844:: with SMTP id 4mr1603090pgy.402.1559187163953; Wed, 29 May 2019 20:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559187163; cv=none; d=google.com; s=arc-20160816; b=cbH49s/mm8swEPOLBd8OCsImXczK5QRhfFUHsGxAadGDiXBRKZn1ztlXuxpoxJjI4U vaxry4flKR/5hEh2MkN4/6dm/AC74EUMl+CVubt8Xp4/01j0Z37ie9FIanrIDlAm3Iqz EtnsylEI8Ld/rtUjoy4vwT5zDEZQ1ln6zG3WmCla0hS8i+kUSlWEcppqF/pZHr4CNzBx gQ07QHbZ8BRkAACL4Y00PvERruc0wS+VQ0wTFfVL2YVAPjIZvZsUbK+6eA5AQsAOIV3v V7cRJ15bZNkgHH24IaIg8goFiLuuBUOGZJk+1CBm/uDAMC7hzw/GLR5qa5ryXzSIz8z7 VM3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iGTayCgKTQz10LVkHrX5BCWOpOWJZqTR67mxAcyb5Fs=; b=zmRp31PyKOPqR6uRzaCS+nyGfn2lVdic2c//zznVrnwFfRpfouJz020J+qUiZGezqC Uh8SXq5EGE0jyy0q2lM1yp/myO8i3duO0OzOR2SFMevfaUt31xGsuvC8k7lV137mWSDo +oFuh+034k6FjU1w22vxPrlDqmE3N0LQP/JGTxoKHgTPjAEETFSxtvx8JUs+sSXEOrVy NaDxvHJT5BZfE4eCeiZH36WPctUwpbIRNV4QrDATchG3A+5iiZgJc/bfifVv6ivlE1qL wy4ByhVCw0ap6ZkIEnSQ8ynvpDvfGxjYvbCBe/3rFhWM7v95AuKS/nsEul2EzooPpRVJ /T3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qOPnTp4w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si1633656pjs.96.2019.05.29.20.32.27; Wed, 29 May 2019 20:32:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qOPnTp4w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732877AbfE3DbV (ORCPT + 99 others); Wed, 29 May 2019 23:31:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:49556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727454AbfE3DbT (ORCPT ); Wed, 29 May 2019 23:31:19 -0400 Received: from localhost (unknown [104.132.1.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7D92F24ACF; Thu, 30 May 2019 03:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559187078; bh=DdLwdqSSRhtuBrsjGhPCyUJFVKGv7nEHu7Igw3L85AA=; h=From:To:Cc:Subject:Date:From; b=qOPnTp4wTIEUEgwFxPgxGDlYe0bp9jjcwifpoEewmo9nhl5CbzBbXeNPeOLbWZwgP xRBtOHDqjT3pbeKuSFzP87NG3XXWsl//H92kK+5/B4o6bzUaSFe2VNgQMFra6mqoyP MstvJkJn99vIkhVNQLHGRV2YMuI4fzMkmpKQuhzQ= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH] f2fs: add a rw_sem to cover quota flag changes Date: Wed, 29 May 2019 20:31:15 -0700 Message-Id: <20190530033115.16853-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org thread 1: thread 2: writeback checkpoint set QUOTA_NEED_FLUSH clear QUOTA_NEED_FLUSH f2fs_dquot_commit dquot_commit clear_dquot_dirty f2fs_quota_sync dquot_writeback_dquots nothing to commit commit_dqblk quota_write f2fs_quota_write waiting for f2fs_lock_op() pass __need_flush_quota (no F2FS_DIRTY_QDATA) -> up-to-date quota is not written Signed-off-by: Jaegeuk Kim --- fs/f2fs/checkpoint.c | 26 ++++++++++++++++---------- fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 27 ++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 89825261d474..cf3b15c963d2 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1131,17 +1131,23 @@ static void __prepare_cp_block(struct f2fs_sb_info *sbi) static bool __need_flush_quota(struct f2fs_sb_info *sbi) { + bool ret = false; + + down_write(&sbi->quota_sem); if (!is_journalled_quota(sbi)) - return false; - if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) - return false; - if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) - return false; - if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH)) - return true; - if (get_pages(sbi, F2FS_DIRTY_QDATA)) - return true; - return false; + ret = false; + else if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) + ret = false; + else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) + ret = false; + else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH)) + ret = true; + else if (get_pages(sbi, F2FS_DIRTY_QDATA)) + ret = true; + else + ret = false; + up_write(&sbi->quota_sem); + return ret; } /* diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9b3d9977cd1e..692c0922f5b2 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1250,6 +1250,7 @@ struct f2fs_sb_info { block_t unusable_block_count; /* # of blocks saved by last cp */ unsigned int nquota_files; /* # of quota sysfile */ + struct rw_semaphore quota_sem; /* blocking cp for flags */ /* # of pages, see count_type */ atomic_t nr_pages[NR_COUNT_TYPE]; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 912e2619d581..5ddf5e97ee60 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1944,7 +1944,10 @@ int f2fs_quota_sync(struct super_block *sb, int type) int cnt; int ret; + down_read(&sbi->quota_sem); ret = dquot_writeback_dquots(sb, type); + up_read(&sbi->quota_sem); + if (ret) goto out; @@ -2074,32 +2077,40 @@ static void f2fs_truncate_quota_inode_pages(struct super_block *sb) static int f2fs_dquot_commit(struct dquot *dquot) { + struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); int ret; + down_read(&sbi->quota_sem); ret = dquot_commit(dquot); if (ret < 0) - set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR); + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); + up_read(&sbi->quota_sem); return ret; } static int f2fs_dquot_acquire(struct dquot *dquot) { + struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); int ret; + down_read(&sbi->quota_sem); ret = dquot_acquire(dquot); if (ret < 0) - set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR); - + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); + up_read(&sbi->quota_sem); return ret; } static int f2fs_dquot_release(struct dquot *dquot) { + struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); int ret; + down_read(&sbi->quota_sem); ret = dquot_release(dquot); if (ret < 0) - set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR); + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); + up_read(&sbi->quota_sem); return ret; } @@ -2109,22 +2120,27 @@ static int f2fs_dquot_mark_dquot_dirty(struct dquot *dquot) struct f2fs_sb_info *sbi = F2FS_SB(sb); int ret; + down_read(&sbi->quota_sem); ret = dquot_mark_dquot_dirty(dquot); /* if we are using journalled quota */ if (is_journalled_quota(sbi)) set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); + up_read(&sbi->quota_sem); return ret; } static int f2fs_dquot_commit_info(struct super_block *sb, int type) { + struct f2fs_sb_info *sbi = F2FS_SB(sb); int ret; + down_read(&sbi->quota_sem); ret = dquot_commit_info(sb, type); if (ret < 0) - set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); + up_read(&sbi->quota_sem); return ret; } @@ -3233,6 +3249,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) } init_rwsem(&sbi->cp_rwsem); + init_rwsem(&sbi->quota_sem); init_waitqueue_head(&sbi->cp_wait); init_sb_info(sbi); -- 2.19.0.605.g01d371f741-goog