From patchwork Thu Aug 27 00:28:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allison Henderson X-Patchwork-Id: 11739751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBADD14E5 for ; Thu, 27 Aug 2020 00:29:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C45B92087D for ; Thu, 27 Aug 2020 00:29:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="G27XBczK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbgH0A3Y (ORCPT ); Wed, 26 Aug 2020 20:29:24 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:54712 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726856AbgH0A3X (ORCPT ); Wed, 26 Aug 2020 20:29:23 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 07R0TMAN022240 for ; Thu, 27 Aug 2020 00:29:22 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-2020-01-29; bh=NGa1uyYUgvphfBpZhe9ce+wATInmrWY+QUkb6KgxlBo=; b=G27XBczKIkAfSnPp9HKvyCBoTcTwMgglajRelHKw5ZzTBhxibdxFieGsKxjaBFk8DLOG 9OIaW93wVcsQgvMBiYF3DRWwfX6Oeg4xMsUHYWV7AVeW76DQzuMkSBUo+3cmQ7RMF9bE llN8m/oKNqKapyK5bqCf0oQ4moJ1+8cZJDUjF6v7MtVNXB35W8Lb44Gntz1BkaxB4hKd l13Zu57FSa94WWUKQ31nGNZk3Wy/N5GecP2xoN5qEoLnJuUSIyztmlvJdK6RfPtRij6R UzmOZpvlVc3RyAtFk0hDtaTm5bvIYS8O6VRieWQLrFEzsBGMhL8r/Tps1+EXjKa/0Hkc Mg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 335gw859e7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 27 Aug 2020 00:29:22 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 07R0AHIw121723 for ; Thu, 27 Aug 2020 00:29:21 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 333rubkgcb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 27 Aug 2020 00:29:21 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 07R0TKeG016976 for ; Thu, 27 Aug 2020 00:29:21 GMT Received: from localhost.localdomain (/67.1.244.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 26 Aug 2020 17:29:20 -0700 From: Allison Collins To: linux-xfs@vger.kernel.org Subject: [PATCH v12 27/32] xfsprogs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Date: Wed, 26 Aug 2020 17:28:51 -0700 Message-Id: <20200827002856.1131-28-allison.henderson@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200827002856.1131-1-allison.henderson@oracle.com> References: <20200827002856.1131-1-allison.henderson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9725 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=1 spamscore=0 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008270000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9725 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 lowpriorityscore=0 mlxscore=0 phishscore=0 bulkscore=0 impostorscore=0 adultscore=0 malwarescore=0 clxscore=1015 spamscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008270001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org These routines to set up and start a new deferred attribute operations. These functions are meant to be called by any routine needing to initiate a deferred attribute operation as opposed to the existing inline operations. New helper function xfs_attr_item_init also added. Signed-off-by: Allison Henderson Signed-off-by: Allison Collins --- libxfs/xfs_attr.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_attr.h | 7 +++++ 2 files changed, 97 insertions(+) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 43688ad..ed25894 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -643,6 +643,96 @@ out_trans_cancel: goto out_unlock; } +STATIC int +xfs_attr_item_init( + struct xfs_inode *dp, /* inode for attr operation */ + struct xfs_trans *tp, /* transaction for attr op */ + const unsigned char *name, /* attr name */ + unsigned int namelen, /* attr namelen */ + unsigned int flags, /* attr flags */ + const unsigned char *value, /* attr value */ + unsigned int valuelen, /* attr value len */ + unsigned int op_flags, /* op flag (set or remove) */ + struct xfs_attr_item **attr) /* new xfs_attr_item */ +{ + + struct xfs_attr_item *new; + char *name_value; + + /* + * All set operations must have a name but not necessarily a value. + */ + if (!namelen) { + ASSERT(0); + return -EINVAL; + } + + new = kmem_alloc_large(XFS_ATTR_ITEM_SIZEOF(namelen, valuelen), + KM_NOFS); + name_value = ((char *)new) + sizeof(struct xfs_attr_item); + memset(new, 0, XFS_ATTR_ITEM_SIZEOF(namelen, valuelen)); + new->xattri_ip = dp; + new->xattri_op_flags = op_flags; + new->xattri_name_len = namelen; + new->xattri_value_len = valuelen; + new->xattri_flags = flags; + memcpy(&name_value[0], name, namelen); + new->xattri_name = name_value; + new->xattri_value = name_value + namelen; + + if (valuelen > 0) + memcpy(&name_value[namelen], value, valuelen); + + *attr = new; + return 0; +} + +/* Sets an attribute for an inode as a deferred operation */ +int +xfs_attr_set_deferred( + struct xfs_inode *dp, + struct xfs_trans *tp, + const unsigned char *name, + unsigned int namelen, + unsigned int flags, + const unsigned char *value, + unsigned int valuelen) +{ + struct xfs_attr_item *new; + int error = 0; + + error = xfs_attr_item_init(dp, tp, name, namelen, flags, value, + valuelen, XFS_ATTR_OP_FLAGS_SET, &new); + if (error) + return error; + + xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); + + return 0; +} + +/* Removes an attribute for an inode as a deferred operation */ +int +xfs_attr_remove_deferred( + struct xfs_inode *dp, + struct xfs_trans *tp, + const unsigned char *name, + unsigned int namelen, + unsigned int flags) +{ + + struct xfs_attr_item *new; + + int error = xfs_attr_item_init(dp, tp, name, namelen, flags, NULL, 0, + XFS_ATTR_OP_FLAGS_REMOVE, &new); + if (error) + return error; + + xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); + + return 0; +} + /*======================================================================== * External routines when attribute list is inside the inode *========================================================================*/ diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 23b8308..4643b3f 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -328,5 +328,12 @@ bool xfs_attr_namecheck(const void *name, size_t length); void xfs_delattr_context_init(struct xfs_delattr_context *dac, struct xfs_da_args *args); int xfs_attr_calc_size(struct xfs_da_args *args, int *local); +int xfs_attr_set_deferred(struct xfs_inode *dp, struct xfs_trans *tp, + const unsigned char *name, unsigned int namelen, + unsigned int flags, const unsigned char *value, + unsigned int valuelen); +int xfs_attr_remove_deferred(struct xfs_inode *dp, struct xfs_trans *tp, + const unsigned char *name, unsigned int namelen, + unsigned int flags); #endif /* __XFS_ATTR_H__ */