From patchwork Sun Sep 6 17:40:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 7131371 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DB2869F32B for ; Sun, 6 Sep 2015 09:52:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EE97C207CF for ; Sun, 6 Sep 2015 09:52:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68559207CD for ; Sun, 6 Sep 2015 09:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751905AbbIFJwe (ORCPT ); Sun, 6 Sep 2015 05:52:34 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:60119 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293AbbIFJwd (ORCPT ); Sun, 6 Sep 2015 05:52:33 -0400 Received: from 172.24.1.51 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.51]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUL16263; Sun, 06 Sep 2015 17:52:27 +0800 (CST) Received: from localhost.localdomain (10.110.52.67) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 17:51:44 +0800 From: Sheng Yong To: , , CC: , , Subject: [RFC PATCH v2 1/3] UBIFS: xattr: add generic helper functions for set/get xattr Date: Sun, 6 Sep 2015 17:40:19 +0000 Message-ID: <1441561221-18899-2-git-send-email-shengyong1@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441561221-18899-1-git-send-email-shengyong1@huawei.com> References: <1441561221-18899-1-git-send-email-shengyong1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.52.67] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ACL depends on xattr. In order to setting and getting ACL value, generic functions for setting and getting xattr are needed. Signed-off-by: Sheng Yong --- fs/ubifs/ubifs.h | 4 ++++ fs/ubifs/xattr.c | 51 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index de75902..62aa1a5 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -1754,6 +1754,10 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat); /* xattr.c */ +int ubifs_do_setxattr(struct inode *inode, const char *name, + const void *value, size_t size, int flags); +ssize_t ubifs_do_getxattr(struct inode *inode, const char *name, + void *value, size_t size); int ubifs_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags); ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index fd65b3f..6534b98 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c @@ -299,25 +299,21 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum) return ERR_PTR(-EINVAL); } -static int setxattr(struct inode *host, const char *name, const void *value, - size_t size, int flags) +int ubifs_do_setxattr(struct inode *host, const char *name, + const void *value, size_t size, int flags) { struct inode *inode; struct ubifs_info *c = host->i_sb->s_fs_info; struct qstr nm = QSTR_INIT(name, strlen(name)); struct ubifs_dent_node *xent; union ubifs_key key; - int err, type; + int err; ubifs_assert(mutex_is_locked(&host->i_mutex)); if (size > UBIFS_MAX_INO_DATA) return -ERANGE; - type = check_namespace(&nm); - if (type < 0) - return type; - xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); if (!xent) return -ENOMEM; @@ -363,16 +359,23 @@ out_free: int ubifs_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) { + struct qstr nm = QSTR_INIT(name, strlen(name)); + int type; + dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd", name, d_inode(dentry)->i_ino, dentry, size); - return setxattr(d_inode(dentry), name, value, size, flags); + type = check_namespace(&nm); + if (type < 0) + return type; + + return ubifs_do_setxattr(d_inode(dentry), name, value, size, flags); } -ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, - size_t size) +ssize_t ubifs_do_getxattr(struct inode *host, const char *name, + void *buf, size_t size) { - struct inode *inode, *host = d_inode(dentry); + struct inode *inode; struct ubifs_info *c = host->i_sb->s_fs_info; struct qstr nm = QSTR_INIT(name, strlen(name)); struct ubifs_inode *ui; @@ -380,13 +383,6 @@ ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, union ubifs_key key; int err; - dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name, - host->i_ino, dentry, size); - - err = check_namespace(&nm); - if (err < 0) - return err; - xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); if (!xent) return -ENOMEM; @@ -429,6 +425,22 @@ out_unlock: return err; } +ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, + void *value, size_t size) +{ + struct qstr nm = QSTR_INIT(name, strlen(name)); + int type; + + dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name, + d_inode(dentry)->i_ino, dentry, size); + + type = check_namespace(&nm); + if (type < 0) + return type; + + return ubifs_do_getxattr(d_inode(dentry), name, value, size); +} + ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size) { union ubifs_key key; @@ -638,7 +650,8 @@ static int init_xattrs(struct inode *inode, const struct xattr *xattr_array, } strcpy(name, XATTR_SECURITY_PREFIX); strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name); - err = setxattr(inode, name, xattr->value, xattr->value_len, 0); + err = ubifs_do_setxattr(inode, name, xattr->value, + xattr->value_len, 0); kfree(name); if (err < 0) break;