Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp697998pxb; Thu, 23 Sep 2021 08:51:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1j9jNA/wCv2lNFp4yKO4BUuPYrjaEVRNMZc16PpZ1ZEZui6ubFH9ztfABjpxcpzOHu3vL X-Received: by 2002:a05:6e02:dce:: with SMTP id l14mr4339612ilj.272.1632412288755; Thu, 23 Sep 2021 08:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632412288; cv=none; d=google.com; s=arc-20160816; b=XVwNbDNdvmbye69qXKpe2Fr2hPOAlsds2BIdOhDTNitsATZHoygq+V5ZQLgrc5pivO U295K6k8gz8Ih5ktkyR0Gk8rU4xGNQaQ5cW4VapVxFnke1Rwy5IgnaqmoRyF7E2Mwksa ER2vQNq8pG1s1agucQEDMVPwjCSzZUhaht9bZ9kE6q+x0pYT2XpBlGkTy3yUSPWcd5oh Fyrg/WNWMXMfb+jRSP0v4hgaDAAXHkGwWnHnqsNrIZlprMhwOcIETBxjPYYRUJjYYQOw L54qiYM9GYkLLvf+18rOPldL9kpwmUTCjAi+QRLy70KrxhVRON+WZ50P5OcOii9e1293 XKKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:cc :references:to:from:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=64yVPSdrcbCCQvDugxsNeN4BcIkj+7UISpaWRZ3MTYk=; b=PStlTloRdeaRGN7WFNHyKCMD2eN9hYnOaw65t5asXDaNYZfy8tpkiVEzPJ2HBjRxNP NRLrhuiAzXvTWXBEB5NcMWwxUxF5fnkV0+K77eLw4f72hNPYcPTXzpKiz7j+VbgoQhcQ 7Jr3NB/sW+8mbnX6lD3bD6VJBwqZ2VMaL/fBigdCnoCK2SW9TVYrPPXV2BGRuIIZzUGX FBtVOD8HwFjIVewMlyrL4qNksZJXebfOXGBbcmWTp7YY6Xy/qd1HUszPWa9PQfalMdor pBVibvKOepc5zfOWMWV1OH85h/QsNhHNZPla6a+eMnl4A+U1qWISWaPjgY99C/AFOGi5 nYhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ubtpVUPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si6528217ioh.48.2021.09.23.08.51.16; Thu, 23 Sep 2021 08:51:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ubtpVUPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242351AbhIWPvY (ORCPT + 99 others); Thu, 23 Sep 2021 11:51:24 -0400 Received: from relayfre-01.paragon-software.com ([176.12.100.13]:35780 "EHLO relayfre-01.paragon-software.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242242AbhIWPvF (ORCPT ); Thu, 23 Sep 2021 11:51:05 -0400 Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id BDD691D40; Thu, 23 Sep 2021 18:42:06 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1632411726; bh=64yVPSdrcbCCQvDugxsNeN4BcIkj+7UISpaWRZ3MTYk=; h=Date:Subject:From:To:References:CC:In-Reply-To; b=ubtpVUPbJCTRVd1hTLcWDm/NzaFv7XfabViYqqtt6NpYey+uGXU4XB/a6Ob39unZP qemVFPYQBVnGWB84Cg3ULOsPiJC49p/g1zJn7XrDMQBmTtz3K293SmA4CQFrmu2bIa RPvB0cPQqAby2vVX0xo8cKGwNvhGIgpz7DtjlfZA= Received: from [192.168.211.73] (192.168.211.73) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 23 Sep 2021 18:42:06 +0300 Message-ID: Date: Thu, 23 Sep 2021 18:42:05 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: [PATCH v2 2/6] fs/ntfs3: Move ni_lock_dir and ni_unlock into ntfs_create_inode Content-Language: en-US From: Konstantin Komarov To: References: CC: , In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.211.73] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now ntfs3 locks mutex for smaller time. Theoretically in successful cases those locks aren't needed at all. But proving the same for error cases is difficult. So instead of removing them we just move them. Signed-off-by: Konstantin Komarov --- fs/ntfs3/inode.c | 17 ++++++++++++++--- fs/ntfs3/namei.c | 20 -------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index d51bf4018835..7dd162f6a7e2 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1198,9 +1198,13 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, struct REPARSE_DATA_BUFFER *rp = NULL; bool rp_inserted = false; + ni_lock_dir(dir_ni); + dir_root = indx_get_root(&dir_ni->dir, dir_ni, NULL, NULL); - if (!dir_root) - return ERR_PTR(-EINVAL); + if (!dir_root) { + err = -EINVAL; + goto out1; + } if (S_ISDIR(mode)) { /* Use parent's directory attributes. */ @@ -1549,6 +1553,9 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, if (err) goto out6; + /* Unlock parent directory before ntfs_init_acl. */ + ni_unlock(dir_ni); + inode->i_generation = le16_to_cpu(rec->seq); dir->i_mtime = dir->i_ctime = inode->i_atime; @@ -1605,8 +1612,10 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, out7: /* Undo 'indx_insert_entry'. */ + ni_lock_dir(dir_ni); indx_delete_entry(&dir_ni->dir, dir_ni, new_de + 1, le16_to_cpu(new_de->key_size), sbi); + /* ni_unlock(dir_ni); will be called later. */ out6: if (rp_inserted) ntfs_remove_reparse(sbi, IO_REPARSE_TAG_SYMLINK, &new_de->ref); @@ -1630,8 +1639,10 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, kfree(rp); out1: - if (err) + if (err) { + ni_unlock(dir_ni); return ERR_PTR(err); + } unlock_new_inode(inode); diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 1c475da4e19d..bc741213ad84 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -95,16 +95,11 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry, static int ntfs_create(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { - struct ntfs_inode *ni = ntfs_i(dir); struct inode *inode; - ni_lock_dir(ni); - inode = ntfs_create_inode(mnt_userns, dir, dentry, NULL, S_IFREG | mode, 0, NULL, 0, NULL); - ni_unlock(ni); - return IS_ERR(inode) ? PTR_ERR(inode) : 0; } @@ -116,16 +111,11 @@ static int ntfs_create(struct user_namespace *mnt_userns, struct inode *dir, static int ntfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev) { - struct ntfs_inode *ni = ntfs_i(dir); struct inode *inode; - ni_lock_dir(ni); - inode = ntfs_create_inode(mnt_userns, dir, dentry, NULL, mode, rdev, NULL, 0, NULL); - ni_unlock(ni); - return IS_ERR(inode) ? PTR_ERR(inode) : 0; } @@ -196,15 +186,10 @@ static int ntfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, { u32 size = strlen(symname); struct inode *inode; - struct ntfs_inode *ni = ntfs_i(dir); - - ni_lock_dir(ni); inode = ntfs_create_inode(mnt_userns, dir, dentry, NULL, S_IFLNK | 0777, 0, symname, size, NULL); - ni_unlock(ni); - return IS_ERR(inode) ? PTR_ERR(inode) : 0; } @@ -215,15 +200,10 @@ static int ntfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode) { struct inode *inode; - struct ntfs_inode *ni = ntfs_i(dir); - - ni_lock_dir(ni); inode = ntfs_create_inode(mnt_userns, dir, dentry, NULL, S_IFDIR | mode, 0, NULL, 0, NULL); - ni_unlock(ni); - return IS_ERR(inode) ? PTR_ERR(inode) : 0; } -- 2.33.0