Return-Path: Received: from mx2.suse.de ([195.135.220.15]:37562 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752226AbdHPPlh (ORCPT ); Wed, 16 Aug 2017 11:41:37 -0400 From: Jan Kara To: Cc: Wang Shilong , Jan Kara Subject: [PATCH 09/27] quota: Do not acquire dqio_sem for dquot overwrites in v2 format Date: Wed, 16 Aug 2017 17:41:09 +0200 Message-Id: <20170816154127.7048-10-jack@suse.cz> In-Reply-To: <20170816154127.7048-1-jack@suse.cz> References: <20170816154127.7048-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: When dquot has space already allocated in a quota file, we just overwrite that place when writing dquot. So we don't need any protection against other modifications of quota file as these keep dquot in place. Signed-off-by: Jan Kara --- fs/quota/quota_v2.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c index 482733abe4ac..7a05b80f3b8c 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c @@ -300,12 +300,23 @@ static int v2_write_dquot(struct dquot *dquot) { struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); int ret; - - down_write(&dqopt->dqio_sem); + bool alloc = false; + + /* + * If space for dquot is already allocated, we don't need any + * protection as we'll only overwrite the place of dquot. We are + * still protected by concurrent writes of the same dquot by + * dquot->dq_lock. + */ + if (!dquot->dq_off) { + alloc = true; + down_write(&dqopt->dqio_sem); + } ret = qtree_write_dquot( sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); - up_write(&dqopt->dqio_sem); + if (alloc) + up_write(&dqopt->dqio_sem); return ret; } -- 2.12.3