From patchwork Wed Aug 16 15:41:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9904075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4072860231 for ; Wed, 16 Aug 2017 15:42:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 329FB28984 for ; Wed, 16 Aug 2017 15:42:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27C9C28A0A; Wed, 16 Aug 2017 15:42:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5CA528984 for ; Wed, 16 Aug 2017 15:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752204AbdHPPm0 (ORCPT ); Wed, 16 Aug 2017 11:42:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:37541 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752202AbdHPPlh (ORCPT ); Wed, 16 Aug 2017 11:41:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0C202AE8E; Wed, 16 Aug 2017 15:41:35 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 665381E341A; Wed, 16 Aug 2017 17:41:32 +0200 (CEST) From: Jan Kara To: Cc: Wang Shilong , Jan Kara Subject: [PATCH 08/27] quota: Push dqio_sem down to ->write_dqblk() Date: Wed, 16 Aug 2017 17:41:08 +0200 Message-Id: <20170816154127.7048-9-jack@suse.cz> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170816154127.7048-1-jack@suse.cz> References: <20170816154127.7048-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Push down acquisition of dqio_sem into ->write_dqblk() callback. It will allow quota formats to decide whether they need it or not. Signed-off-by: Jan Kara Reviewed-by: Andreas Dilger --- fs/quota/dquot.c | 10 ++++------ fs/quota/quota_v1.c | 3 +++ fs/quota/quota_v2.c | 10 +++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 70b9a6afe5a8..562f5978488f 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -412,14 +412,14 @@ int dquot_acquire(struct dquot *dquot) set_bit(DQ_READ_B, &dquot->dq_flags); /* Instantiate dquot if needed */ if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { - down_write(&dqopt->dqio_sem); ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); /* Write the info if needed */ if (info_dirty(&dqopt->info[dquot->dq_id.type])) { + down_write(&dqopt->dqio_sem); ret2 = dqopt->ops[dquot->dq_id.type]->write_file_info( dquot->dq_sb, dquot->dq_id.type); + up_write(&dqopt->dqio_sem); } - up_write(&dqopt->dqio_sem); if (ret < 0) goto out_iolock; if (ret2 < 0) { @@ -456,11 +456,9 @@ int dquot_commit(struct dquot *dquot) spin_unlock(&dq_list_lock); /* Inactive dquot can be only if there was error during read/init * => we have better not writing it */ - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { - down_write(&dqopt->dqio_sem); + if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); - up_write(&dqopt->dqio_sem); - } else + else ret = -EIO; out_lock: mutex_unlock(&dquot->dq_lock); diff --git a/fs/quota/quota_v1.c b/fs/quota/quota_v1.c index 12d69cda57cc..94cceb76b9a3 100644 --- a/fs/quota/quota_v1.c +++ b/fs/quota/quota_v1.c @@ -83,7 +83,9 @@ static int v1_commit_dqblk(struct dquot *dquot) short type = dquot->dq_id.type; ssize_t ret; struct v1_disk_dqblk dqblk; + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); + down_write(&dqopt->dqio_sem); v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb); if (((type == USRQUOTA) && uid_eq(dquot->dq_id.uid, GLOBAL_ROOT_UID)) || ((type == GRPQUOTA) && gid_eq(dquot->dq_id.gid, GLOBAL_ROOT_GID))) { @@ -97,6 +99,7 @@ static int v1_commit_dqblk(struct dquot *dquot) ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(from_kqid(&init_user_ns, dquot->dq_id))); + up_write(&dqopt->dqio_sem); if (ret != sizeof(struct v1_disk_dqblk)) { quota_error(dquot->dq_sb, "dquota write failed"); if (ret >= 0) diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c index b2cd34f6b3da..482733abe4ac 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c @@ -298,7 +298,15 @@ static int v2_read_dquot(struct dquot *dquot) static int v2_write_dquot(struct dquot *dquot) { - return qtree_write_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); + int ret; + + 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); + return ret; } static int v2_release_dquot(struct dquot *dquot)