From patchwork Fri Mar 1 04:34:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10834437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D58B1399 for ; Fri, 1 Mar 2019 04:35:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D6B72F1C1 for ; Fri, 1 Mar 2019 04:35:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 718D42F1DB; Fri, 1 Mar 2019 04:35:17 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 0A3DD2EDDF for ; Fri, 1 Mar 2019 04:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbfCAEfM (ORCPT ); Thu, 28 Feb 2019 23:35:12 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:45226 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728065AbfCAEfK (ORCPT ); Thu, 28 Feb 2019 23:35:10 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x214YM1d006610 for ; Fri, 1 Mar 2019 04:35:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=lDSlTJXwyisHqx7Xq3uf/hG1BqPb6y6q4oNPQG2oxmM=; b=ysaFMIQSrqI48N8voE18hJBmN0C3jgDj/LaSFQRTPDqJFUUzNiZhGLBRddeY1aYqwNB8 j9VhTs/1U7nwxBKg5nQ2D9q7xBQNM8r4dkrzgxbNH0hciLTyRQpFrdmKMgjjDrydZ4vr bMAFGBWMS4EkxN281GiTjuLLy6CY2YEk9arGlKR8hK70LcEveQZ3EyQB/+bkb6/ZH1rg davEsBCam2peU5rzfssl3lwCFbJ6g+Gzshy8syBC/C2Y18PGr/nSsCQH7oaHaLOvRQC0 ZrejVhmWaVxLTexPakHiwythMShyApICEZuSYti46UXqSNTaxmHzl/dPJe6fEhSJbACj 5Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qtxts53q6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 01 Mar 2019 04:35:08 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x214Z8JX023629 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 1 Mar 2019 04:35:08 GMT Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x214Z74s011480 for ; Fri, 1 Mar 2019 04:35:07 GMT Received: from tpasj.wifi.oracle.com (/192.188.170.109) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 28 Feb 2019 20:35:06 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v5 6/9] btrfs: start transaction in btrfs_set_acl Date: Fri, 1 Mar 2019 12:34:52 +0800 Message-Id: <1551414895-22925-7-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551414895-22925-1-git-send-email-anand.jain@oracle.com> References: <1551414895-22925-1-git-send-email-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9181 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903010029 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The main motivation is to avoid NULL for the trans argument reaching btrfs_set_xattr(). This patch does the following in btrfs_set_acl(). Create transaction and handle the inode changes update, (copies code from btrfs_setxattr() as in the original, which needs a fix). Rename __btrfs_set_acl to do_set_acl as this is a helper function. Fix a c-code style, expand function declaration to max length 80 char. Signed-off-by: Anand Jain --- v5: change log update. Use BUG_ON instead of ASSERT. v4: born fs/btrfs/acl.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 5810463dc6d2..2b9c3394fc34 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c @@ -11,10 +11,12 @@ #include #include #include +#include #include "ctree.h" #include "btrfs_inode.h" #include "xattr.h" +#include "transaction.h" struct posix_acl *btrfs_get_acl(struct inode *inode, int type) { @@ -52,8 +54,8 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int type) return acl; } -static int __btrfs_set_acl(struct btrfs_trans_handle *trans, - struct inode *inode, struct posix_acl *acl, int type) +static int do_set_acl(struct btrfs_trans_handle *trans, struct inode *inode, + struct posix_acl *acl, int type) { int ret, size = 0; const char *name; @@ -107,20 +109,36 @@ int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) { int ret; umode_t old_mode = inode->i_mode; + struct btrfs_trans_handle *trans; + struct btrfs_root *root = BTRFS_I(inode)->root; if (type == ACL_TYPE_ACCESS && acl) { ret = posix_acl_update_mode(inode, &inode->i_mode, &acl); if (ret) return ret; } - ret = __btrfs_set_acl(NULL, inode, acl, type); - if (ret) + + trans = btrfs_start_transaction(root, 2); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + ret = do_set_acl(trans, inode, acl, type); + if (ret) { inode->i_mode = old_mode; + } else { + inode_inc_iversion(inode); + inode->i_ctime = current_time(inode); + set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags); + ret = btrfs_update_inode(trans, root, inode); + BUG_ON(ret); + } + + btrfs_end_transaction(trans); return ret; } -int btrfs_init_acl(struct btrfs_trans_handle *trans, - struct inode *inode, struct inode *dir) +int btrfs_init_acl(struct btrfs_trans_handle *trans, struct inode *inode, + struct inode *dir) { struct posix_acl *default_acl, *acl; int ret = 0; @@ -134,15 +152,13 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans, return ret; if (default_acl) { - ret = __btrfs_set_acl(trans, inode, default_acl, - ACL_TYPE_DEFAULT); + ret = do_set_acl(trans, inode, default_acl, ACL_TYPE_DEFAULT); posix_acl_release(default_acl); } if (acl) { if (!ret) - ret = __btrfs_set_acl(trans, inode, acl, - ACL_TYPE_ACCESS); + ret = do_set_acl(trans, inode, acl, ACL_TYPE_ACCESS); posix_acl_release(acl); }