Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1851457pxb; Tue, 26 Oct 2021 17:49:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHMgFX+FMqD1SWTHf7kkj9HprkAs57KLbq8TKNZMfAO4f7lIbZW6cgQSXzT/tbDKC3uoW+ X-Received: by 2002:a17:90a:7607:: with SMTP id s7mr2369994pjk.59.1635295763421; Tue, 26 Oct 2021 17:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635295763; cv=none; d=google.com; s=arc-20160816; b=NzPZh7F6uQmGAh7IN+PSrnfhp4ofmGVeBBXFCluSWTQdU/96ebB/S5tN3Mk71d3TAM yC5Q+p5BhoZ61OAyy4YVXPM1kZWSKUBotCnnmr9KtCPpAkKUKzC6HX1Gd0m1DcChCI8N DGqPiaNh1tQHTayAULNXuhVT1zCSQAKw0wK5RMqhoOINSbJmZ3BNWQLOAc1/Ss92nZeX f8fgBmsRWoaL6mCIHOqsNNX0PUAARsfHpjKTh5rJlJrqNxvLfSDDnKkFMw4JDCbMX6WW VmG24PJOOOSSoWNKbKfbPY6bpjORYGt6a/Z1uAOpzFdBdSK91P5dY9y/JTpCQksGPiQU JkSA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=IjeT8cKFVkmsNvbWpOOmmiH68Y2cE+w6uPiAlQbq6cM=; b=thbTazNfRU5+mcDbqN6MHfh9T0GCeEJNbPyJheq+99yky9vbvGCeNFtVAVyUJak/kJ mrx6xsSd94tddhHxoyw5P7Lq/9oXVxTGEpDgb9htCc71k0cBHnt0z9xVWMEgNEhTkPFm 1tCVmOdzM1xEnSAHTIapyB0itXA43T7tgpaE8pskkHbSx9ajOGuISvZO49sr+x8NUbf0 W3YZlWEVoThTmX+5qH1rv7rSC/LQyTzIwWBajeaWR53TmxiHQQ8cPYbJNsWguayRnxlS leFeEb3sObjkIBHqZorpwn/yKXfSlHKvgwCKvdUrc/eQnc4zIPE6CbjyXhyzBWZf74Um JCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=txkLAxFs; 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 136si31082875pgb.534.2021.10.26.17.48.57; Tue, 26 Oct 2021 17:49:23 -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=txkLAxFs; 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 S237487AbhJZQop (ORCPT + 99 others); Tue, 26 Oct 2021 12:44:45 -0400 Received: from relaydlg-01.paragon-software.com ([81.5.88.159]:54317 "EHLO relaydlg-01.paragon-software.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234249AbhJZQoo (ORCPT ); Tue, 26 Oct 2021 12:44:44 -0400 Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relaydlg-01.paragon-software.com (Postfix) with ESMTPS id D398B82240; Tue, 26 Oct 2021 19:42:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1635266536; bh=IjeT8cKFVkmsNvbWpOOmmiH68Y2cE+w6uPiAlQbq6cM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=txkLAxFs1VhwsuwNiJzEeG4W7uxz274rgMMgag8jUCeokgxKhfxvY0l+U+oyiK0BE oFi4MqV8OPOUUnJoSzea2LL2vzdbNfVDGKfTUIdSl88TOb1MZ5EYet1Qf+jGuEtcWr 0fzwiaTvi1ktXE6AEJqclehZZNkuNLzKeuI4ZnZA= Received: from [192.168.211.149] (192.168.211.149) 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; Tue, 26 Oct 2021 19:42:16 +0300 Message-ID: Date: Tue, 26 Oct 2021 19:42:15 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: [PATCH 4/4] fs/ntfs3: Optimize locking in ntfs_save_wsl_perm Content-Language: en-US From: Konstantin Komarov To: CC: , , References: In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.211.149] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Right now in ntfs_save_wsl_perm we lock/unlock 4 times. This commit fixes this situation. We add "locked" argument to ntfs_set_ea. Suggested-by: Kari Argillander Signed-off-by: Konstantin Komarov --- fs/ntfs3/xattr.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 157b70aecb4f..6d8b1cd7681d 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -259,7 +259,7 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len, static noinline int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, const void *value, - size_t val_size, int flags) + size_t val_size, int flags, bool locked) { struct ntfs_inode *ni = ntfs_i(inode); struct ntfs_sb_info *sbi = ni->mi.sbi; @@ -278,7 +278,8 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, u64 new_sz; void *p; - ni_lock(ni); + if (!locked) + ni_lock(ni); run_init(&ea_run); @@ -467,7 +468,8 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, mark_inode_dirty(&ni->vfs_inode); out: - ni_unlock(ni); + if (!locked) + ni_unlock(ni); run_close(&ea_run); kfree(ea_all); @@ -595,7 +597,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, flags = 0; } - err = ntfs_set_ea(inode, name, name_len, value, size, flags); + err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0); if (err == -ENODATA && !size) err = 0; /* Removing non existed xattr. */ if (!err) @@ -989,7 +991,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, } #endif /* Deal with NTFS extended attribute. */ - err = ntfs_set_ea(inode, name, name_len, value, size, flags); + err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0); out: inode->i_ctime = current_time(inode); @@ -1007,35 +1009,37 @@ int ntfs_save_wsl_perm(struct inode *inode) { int err; __le32 value; + struct ntfs_inode *ni = ntfs_i(inode); - /* TODO: refactor this, so we don't lock 4 times in ntfs_set_ea */ + ni_lock(ni); value = cpu_to_le32(i_uid_read(inode)); err = ntfs_set_ea(inode, "$LXUID", sizeof("$LXUID") - 1, &value, - sizeof(value), 0); + sizeof(value), 0, true); /* true == already locked. */ if (err) goto out; value = cpu_to_le32(i_gid_read(inode)); err = ntfs_set_ea(inode, "$LXGID", sizeof("$LXGID") - 1, &value, - sizeof(value), 0); + sizeof(value), 0, true); if (err) goto out; value = cpu_to_le32(inode->i_mode); err = ntfs_set_ea(inode, "$LXMOD", sizeof("$LXMOD") - 1, &value, - sizeof(value), 0); + sizeof(value), 0, true); if (err) goto out; if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { value = cpu_to_le32(inode->i_rdev); err = ntfs_set_ea(inode, "$LXDEV", sizeof("$LXDEV") - 1, &value, - sizeof(value), 0); + sizeof(value), 0, true); if (err) goto out; } out: + ni_unlock(ni); /* In case of error should we delete all WSL xattr? */ return err; } -- 2.33.0