All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] ocfs2: add security EA support v4
@ 2008-10-27  8:29 Tiger Yang
  2008-10-27  8:43 ` Tao Ma
  0 siblings, 1 reply; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:29 UTC (permalink / raw)
  To: ocfs2-devel

Hi,
I split the previous support security EA patch into four patches for 
review. Them besed on joel's xattr-28 branch and tao's patch "Merge 
xattr set transaction".

1: move new_inode out of the transaction.
2: add ocfs2_xattr_set_handle.
3: add security xattr APIs
4: add init_security in mknod.

Best regards,
tiger

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] ocfs2: add security EA support v4
@ 2008-10-27  8:36 Tiger Yang
  2008-10-27  8:42 ` [Ocfs2-devel] [PATCH 1/4] ocfs2: move new_inode out of the transaction Tiger Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:36 UTC (permalink / raw)
  To: ocfs2-devel

Hi,
I split the previous support security EA patch into four patches for 
review. Them besed on joel's xattr-28 branch and tao's patch "Merge 
xattr set transaction".

1: move new_inode out of the transaction.
2: add ocfs2_xattr_set_handle.
3: add security xattr APIs
4: add init_security in mknod.

Best regards,
tiger

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] [PATCH 1/4] ocfs2: move new_inode out of the transaction
  2008-10-27  8:36 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
@ 2008-10-27  8:42 ` Tiger Yang
  2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 2/4] ocfs2: add ocfs2_xattr_set_handle Tiger Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:42 UTC (permalink / raw)
  To: ocfs2-devel

we need know the security xattr size before start transaction,
so mov new_inode out of mknod_unlock and populate i_mode to
get the exact security xattr size.

Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
---
 fs/ocfs2/namei.c |   53 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index f4967e6..dd4ee52 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -71,7 +71,7 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 			      struct buffer_head **new_fe_bh,
 			      struct buffer_head *parent_fe_bh,
 			      handle_t *handle,
-			      struct inode **ret_inode,
+			      struct inode *inode,
 			      struct ocfs2_alloc_context *inode_ac);
 
 static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
@@ -186,6 +186,21 @@ bail:
 	return ret;
 }
 
+static inline struct inode *ocfs2_make_init_inode(struct inode *dir, int mode)
+{
+	struct inode *inode;
+
+	/*
+	 * move new_inode out of the transanction and populate i_mode
+	 * to get exact security xattr size.
+	 */
+	inode = new_inode(dir->i_sb);
+	if (!IS_ERR(inode))
+		inode->i_mode = mode;
+
+	return inode;
+}
+
 static int ocfs2_mknod(struct inode *dir,
 		       struct dentry *dentry,
 		       int mode,
@@ -250,6 +265,13 @@ static int ocfs2_mknod(struct inode *dir,
 		goto leave;
 	}
 
+	inode = ocfs2_make_init_inode(dir, mode);
+	if (IS_ERR(inode)) {
+		status = PTR_ERR(inode);
+		mlog(ML_ERROR, "new_inode failed!\n");
+		goto leave;
+	}
+
 	/* Reserve a cluster if creating an extent based directory. */
 	if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
 		status = ocfs2_reserve_clusters(osb, 1, &data_ac);
@@ -271,7 +293,7 @@ static int ocfs2_mknod(struct inode *dir,
 	/* do the real work now. */
 	status = ocfs2_mknod_locked(osb, dir, dentry, mode, dev,
 				    &new_fe_bh, parent_fe_bh, handle,
-				    &inode, inode_ac);
+				    inode, inode_ac);
 	if (status < 0) {
 		mlog_errno(status);
 		goto leave;
@@ -353,7 +375,7 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 			      struct buffer_head **new_fe_bh,
 			      struct buffer_head *parent_fe_bh,
 			      handle_t *handle,
-			      struct inode **ret_inode,
+			      struct inode *inode,
 			      struct ocfs2_alloc_context *inode_ac)
 {
 	int status = 0;
@@ -361,14 +383,12 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 	struct ocfs2_extent_list *fel;
 	u64 fe_blkno = 0;
 	u16 suballoc_bit;
-	struct inode *inode = NULL;
 
 	mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
 		   (unsigned long)dev, dentry->d_name.len,
 		   dentry->d_name.name);
 
 	*new_fe_bh = NULL;
-	*ret_inode = NULL;
 
 	status = ocfs2_claim_new_inode(osb, handle, inode_ac, &suballoc_bit,
 				       &fe_blkno);
@@ -377,13 +397,6 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 		goto leave;
 	}
 
-	inode = new_inode(dir->i_sb);
-	if (!inode) {
-		status = -ENOMEM;
-		mlog(ML_ERROR, "new_inode failed!\n");
-		goto leave;
-	}
-
 	/* populate as many fields early on as possible - many of
 	 * these are used by the support functions here and in
 	 * callers. */
@@ -393,7 +406,6 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 		inode->i_nlink = 2;
 	else
 		inode->i_nlink = 1;
-	inode->i_mode = mode;
 	spin_lock(&osb->osb_lock);
 	inode->i_generation = osb->s_next_generation++;
 	spin_unlock(&osb->osb_lock);
@@ -483,18 +495,12 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 
 	status = 0; /* error in ocfs2_create_new_inode_locks is not
 		     * critical */
-
-	*ret_inode = inode;
 leave:
 	if (status < 0) {
 		if (*new_fe_bh) {
 			brelse(*new_fe_bh);
 			*new_fe_bh = NULL;
 		}
-		if (inode) {
-			clear_nlink(inode);
-			iput(inode);
-		}
 	}
 
 	mlog_exit(status);
@@ -1552,6 +1558,13 @@ static int ocfs2_symlink(struct inode *dir,
 		}
 	}
 
+	inode = ocfs2_make_init_inode(dir, (S_IFLNK | S_IRWXUGO));
+	if (IS_ERR(inode)) {
+		status = PTR_ERR(inode);
+		mlog(ML_ERROR, "new_inode failed!\n");
+		goto bail;
+	}
+
 	handle = ocfs2_start_trans(osb, credits);
 	if (IS_ERR(handle)) {
 		status = PTR_ERR(handle);
@@ -1563,7 +1576,7 @@ static int ocfs2_symlink(struct inode *dir,
 	status = ocfs2_mknod_locked(osb, dir, dentry,
 				    S_IFLNK | S_IRWXUGO, 0,
 				    &new_fe_bh, parent_fe_bh, handle,
-				    &inode, inode_ac);
+				    inode, inode_ac);
 	if (status < 0) {
 		mlog_errno(status);
 		goto bail;
-- 
1.5.4.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] [PATCH 2/4] ocfs2: add ocfs2_xattr_set_handle
  2008-10-27  8:36 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
  2008-10-27  8:42 ` [Ocfs2-devel] [PATCH 1/4] ocfs2: move new_inode out of the transaction Tiger Yang
@ 2008-10-27  8:43 ` Tiger Yang
  2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 3/4] ocfs2: add security xattr support Tiger Yang
  2008-10-27  8:44 ` [Ocfs2-devel] [PATCH 4/4] ocfs2: add init_security in mknod Tiger Yang
  3 siblings, 0 replies; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:43 UTC (permalink / raw)
  To: ocfs2-devel

This function used to set xattr in a started transaction.

Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
---
 fs/ocfs2/xattr.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/xattr.h |    4 +++
 2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 20ddf50..3567182 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -2065,6 +2065,77 @@ out:
 	return ret;
 }
 
+int ocfs2_xattr_set_handle(handle_t *handle,
+			   struct inode *inode,
+			   struct buffer_head *di_bh,
+			   int name_index,
+			   const char *name,
+			   const void *value,
+			   size_t value_len,
+			   int flags,
+			   struct ocfs2_alloc_context *meta_ac,
+			   struct ocfs2_alloc_context *data_ac)
+{
+	struct ocfs2_dinode *di;
+	u16 i, blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
+	int ret, credits;
+
+	struct ocfs2_xattr_info xi = {
+		.name_index = name_index,
+		.name = name,
+		.value = value,
+		.value_len = value_len,
+	};
+
+	struct ocfs2_xattr_search xis = {
+		.not_found = -ENODATA,
+	};
+
+	struct ocfs2_xattr_search xbs = {
+		.not_found = -ENODATA,
+	};
+
+	struct ocfs2_xattr_set_ctxt ctxt = {
+		.meta_ac = meta_ac,
+		.data_ac = data_ac,
+	};
+
+	if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
+		return -EOPNOTSUPP;
+
+	xis.inode_bh = xbs.inode_bh = di_bh;
+	di = (struct ocfs2_dinode *)di_bh->b_data;
+
+	down_write(&OCFS2_I(inode)->ip_xattr_sem);
+
+	ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis);
+	if (ret)
+		goto cleanup;
+	if (xis.not_found) {
+		ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs);
+		if (ret)
+			goto cleanup;
+	}
+
+	credits = ocfs2_calc_xattr_set_credits(inode, &xi, &xis, &xbs);
+	ret = ocfs2_extend_trans(handle, credits);
+	if (ret) {
+		mlog_errno(ret);
+		goto cleanup;
+	}
+
+	ret = __ocfs2_xattr_set_handle(inode, handle, di, &xi,
+				       &xis, &xbs, &ctxt);
+
+cleanup:
+	up_write(&OCFS2_I(inode)->ip_xattr_sem);
+	brelse(xbs.xattr_bh);
+	for (i = 0; i < blk_per_bucket; i++)
+		brelse(xbs.bucket.bhs[i]);
+
+	return ret;
+}
+
 /*
  * ocfs2_xattr_set()
  *
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h
index 1d8314c..8fbdc16 100644
--- a/fs/ocfs2/xattr.h
+++ b/fs/ocfs2/xattr.h
@@ -37,6 +37,10 @@ extern struct xattr_handler *ocfs2_xattr_handlers[];
 ssize_t ocfs2_listxattr(struct dentry *, char *, size_t);
 int ocfs2_xattr_set(struct inode *, int, const char *, const void *,
 		    size_t, int);
+int ocfs2_xattr_set_handle(handle_t *, struct inode *, struct buffer_head *,
+			   int, const char *, const void *, size_t, int,
+			   struct ocfs2_alloc_context *,
+			   struct ocfs2_alloc_context *);
 int ocfs2_xattr_remove(struct inode *, struct buffer_head *);
 
 #endif /* OCFS2_XATTR_H */
-- 
1.5.4.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] [PATCH 3/4] ocfs2: add security xattr support
  2008-10-27  8:36 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
  2008-10-27  8:42 ` [Ocfs2-devel] [PATCH 1/4] ocfs2: move new_inode out of the transaction Tiger Yang
  2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 2/4] ocfs2: add ocfs2_xattr_set_handle Tiger Yang
@ 2008-10-27  8:43 ` Tiger Yang
  2008-10-27  8:44 ` [Ocfs2-devel] [PATCH 4/4] ocfs2: add init_security in mknod Tiger Yang
  3 siblings, 0 replies; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:43 UTC (permalink / raw)
  To: ocfs2-devel

This patch add security xattr set/get/list APIs to
support security xattr in ocfs2.

Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
---
 fs/ocfs2/xattr.c |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/ocfs2/xattr.h |   10 +++++++
 2 files changed, 86 insertions(+), 1 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 3567182..eb543bc 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/string.h>
+#include <linux/security.h>
 
 #define MLOG_MASK_PREFIX ML_XATTR
 #include <cluster/masklog.h>
@@ -72,7 +73,6 @@ struct ocfs2_xattr_set_ctxt {
 };
 
 #define OCFS2_XATTR_ROOT_SIZE	(sizeof(struct ocfs2_xattr_def_value_root))
-#define OCFS2_XATTR_INLINE_SIZE	80
 
 static struct ocfs2_xattr_def_value_root def_xv = {
 	.xv.xr_list.l_count = cpu_to_le16(1),
@@ -81,12 +81,14 @@ static struct ocfs2_xattr_def_value_root def_xv = {
 struct xattr_handler *ocfs2_xattr_handlers[] = {
 	&ocfs2_xattr_user_handler,
 	&ocfs2_xattr_trusted_handler,
+	&ocfs2_xattr_security_handler,
 	NULL
 };
 
 static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = {
 	[OCFS2_XATTR_INDEX_USER]	= &ocfs2_xattr_user_handler,
 	[OCFS2_XATTR_INDEX_TRUSTED]	= &ocfs2_xattr_trusted_handler,
+	[OCFS2_XATTR_INDEX_SECURITY]	= &ocfs2_xattr_security_handler,
 };
 
 struct ocfs2_xattr_info {
@@ -4982,6 +4984,79 @@ out:
 }
 
 /*
+ * 'security' attributes support
+ */
+static size_t ocfs2_xattr_security_list(struct inode *inode, char *list,
+					size_t list_size, const char *name,
+					size_t name_len)
+{
+	const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const size_t total_len = prefix_len + name_len + 1;
+
+	if (list && total_len <= list_size) {
+		memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
+		memcpy(list + prefix_len, name, name_len);
+		list[prefix_len + name_len] = '\0';
+	}
+	return total_len;
+}
+
+static int ocfs2_xattr_security_get(struct inode *inode, const char *name,
+				    void *buffer, size_t size)
+{
+	if (strcmp(name, "") == 0)
+		return -EINVAL;
+	return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name,
+			       buffer, size);
+}
+
+static int ocfs2_xattr_security_set(struct inode *inode, const char *name,
+				    const void *value, size_t size, int flags)
+{
+	if (strcmp(name, "") == 0)
+		return -EINVAL;
+
+	return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value,
+			       size, flags);
+}
+
+int ocfs2_init_security_get(struct inode *inode,
+			    struct inode *dir,
+			    char **name,
+			    void **value,
+			    size_t *len)
+{
+	int ret;
+
+	ret = security_inode_init_security(inode, dir, name, value, len);
+	if (ret == -EOPNOTSUPP)
+		return 0;
+	return ret;
+}
+
+int ocfs2_init_security_set(handle_t *handle,
+			    struct inode *inode,
+			    struct buffer_head *di_bh,
+			    char *name,
+			    void *value,
+			    size_t len,
+			    struct ocfs2_alloc_context *xattr_ac,
+			    struct ocfs2_alloc_context *data_ac)
+{
+	return ocfs2_xattr_set_handle(handle, inode, di_bh,
+				     OCFS2_XATTR_INDEX_SECURITY,
+				     name, value, len, 0,
+				     xattr_ac, data_ac);
+}
+
+struct xattr_handler ocfs2_xattr_security_handler = {
+	.prefix	= XATTR_SECURITY_PREFIX,
+	.list	= ocfs2_xattr_security_list,
+	.get	= ocfs2_xattr_security_get,
+	.set	= ocfs2_xattr_security_set,
+};
+
+/*
  * 'trusted' attributes support
  */
 static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list,
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h
index 8fbdc16..8aaf858 100644
--- a/fs/ocfs2/xattr.h
+++ b/fs/ocfs2/xattr.h
@@ -21,6 +21,8 @@
 #include <linux/init.h>
 #include <linux/xattr.h>
 
+#define OCFS2_XATTR_INLINE_SIZE	80
+
 enum ocfs2_xattr_type {
 	OCFS2_XATTR_INDEX_USER = 1,
 	OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS,
@@ -32,6 +34,7 @@ enum ocfs2_xattr_type {
 
 extern struct xattr_handler ocfs2_xattr_user_handler;
 extern struct xattr_handler ocfs2_xattr_trusted_handler;
+extern struct xattr_handler ocfs2_xattr_security_handler;
 extern struct xattr_handler *ocfs2_xattr_handlers[];
 
 ssize_t ocfs2_listxattr(struct dentry *, char *, size_t);
@@ -42,5 +45,12 @@ int ocfs2_xattr_set_handle(handle_t *, struct inode *, struct buffer_head *,
 			   struct ocfs2_alloc_context *,
 			   struct ocfs2_alloc_context *);
 int ocfs2_xattr_remove(struct inode *, struct buffer_head *);
+int ocfs2_init_security_get(struct inode *, struct inode *,
+			    char **, void **, size_t *);
+int ocfs2_init_security_set(handle_t *, struct inode *,
+			    struct buffer_head *,
+			    char *, void *, size_t,
+			    struct ocfs2_alloc_context *,
+			    struct ocfs2_alloc_context *);
 
 #endif /* OCFS2_XATTR_H */
-- 
1.5.4.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] ocfs2: add security EA support v4
  2008-10-27  8:29 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
@ 2008-10-27  8:43 ` Tao Ma
  0 siblings, 0 replies; 7+ messages in thread
From: Tao Ma @ 2008-10-27  8:43 UTC (permalink / raw)
  To: ocfs2-devel

Hi tiger,
	I am still working on the patch of "merge xattr set transaction" 
according to Joel's review advice, but I will not modify the interface. 
So feel free to use it.

Regards,
Tao

Tiger Yang wrote:
> Hi,
> I split the previous support security EA patch into four patches for 
> review. Them besed on joel's xattr-28 branch and tao's patch "Merge 
> xattr set transaction".
> 
> 1: move new_inode out of the transaction.
> 2: add ocfs2_xattr_set_handle.
> 3: add security xattr APIs
> 4: add init_security in mknod.
> 
> Best regards,
> tiger
> 
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Ocfs2-devel] [PATCH 4/4] ocfs2: add init_security in mknod
  2008-10-27  8:36 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
                   ` (2 preceding siblings ...)
  2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 3/4] ocfs2: add security xattr support Tiger Yang
@ 2008-10-27  8:44 ` Tiger Yang
  3 siblings, 0 replies; 7+ messages in thread
From: Tiger Yang @ 2008-10-27  8:44 UTC (permalink / raw)
  To: ocfs2-devel

we must set security xattr when creating a new inode.
first, calculate and reserve the meta data and clusters
needed by security xattr, then set it before add_entry.

Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
---
 fs/ocfs2/namei.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index dd4ee52..30d6441 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -186,6 +186,28 @@ bail:
 	return ret;
 }
 
+static void ocfs2_calc_xattr_init(struct inode *dir,
+				  int security_len,
+				  int *want_clusters,
+				  struct ocfs2_alloc_context **xattr_ac)
+{
+	struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
+
+	/*
+	 * reserve one metadata block for xattrs if we couldn't get
+	 * xattr inline (blocksize = 512).
+	 */
+	if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE)
+		ocfs2_reserve_new_metadata_blocks(osb, 1, xattr_ac);
+
+	/* reserve clusters for xattr value which will be set in B tree*/
+	if (security_len > OCFS2_XATTR_INLINE_SIZE)
+		*want_clusters += ocfs2_clusters_for_bytes(dir->i_sb,
+							   security_len);
+
+	return;
+}
+
 static inline struct inode *ocfs2_make_init_inode(struct inode *dir, int mode)
 {
 	struct inode *inode;
@@ -215,7 +237,12 @@ static int ocfs2_mknod(struct inode *dir,
 	struct buffer_head *de_bh = NULL;
 	struct inode *inode = NULL;
 	struct ocfs2_alloc_context *inode_ac = NULL;
+	struct ocfs2_alloc_context *xattr_ac = NULL;
 	struct ocfs2_alloc_context *data_ac = NULL;
+	int want_clusters = 0;
+	size_t security_len = 0;
+	void *security_value = NULL;
+	char *security_name = NULL;
 
 	mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
 		   (unsigned long)dev, dentry->d_name.len,
@@ -272,14 +299,26 @@ static int ocfs2_mknod(struct inode *dir,
 		goto leave;
 	}
 
+	/* get security xattr */
+	status = ocfs2_init_security_get(inode, dir, &security_name,
+					 &security_value, &security_len);
+	if (status < 0) {
+		mlog_errno(status);
+		goto leave;
+	}
+
+	/* calculate meta data/clusters for setting security xattr */
+	ocfs2_calc_xattr_init(dir, security_len, &want_clusters, &xattr_ac);
+
 	/* Reserve a cluster if creating an extent based directory. */
-	if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
-		status = ocfs2_reserve_clusters(osb, 1, &data_ac);
-		if (status < 0) {
-			if (status != -ENOSPC)
-				mlog_errno(status);
-			goto leave;
-		}
+	if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb))
+		want_clusters += 1;
+
+	status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac);
+	if (status < 0) {
+		if (status != -ENOSPC)
+			mlog_errno(status);
+		goto leave;
 	}
 
 	handle = ocfs2_start_trans(osb, OCFS2_MKNOD_CREDITS);
@@ -322,6 +361,15 @@ static int ocfs2_mknod(struct inode *dir,
 		inc_nlink(dir);
 	}
 
+	status = ocfs2_init_security_set(handle, inode, new_fe_bh,
+					 security_name, security_value,
+					 security_len,
+					 xattr_ac, data_ac);
+	if (status < 0) {
+		mlog_errno(status);
+		goto leave;
+	}
+
 	status = ocfs2_add_entry(handle, dentry, inode,
 				 OCFS2_I(inode)->ip_blkno, parent_fe_bh,
 				 de_bh);
@@ -353,6 +401,8 @@ leave:
 	brelse(new_fe_bh);
 	brelse(de_bh);
 	brelse(parent_fe_bh);
+	kfree(security_value);
+	kfree(security_name);
 
 	if ((status < 0) && inode)
 		iput(inode);
@@ -360,6 +410,9 @@ leave:
 	if (inode_ac)
 		ocfs2_free_alloc_context(inode_ac);
 
+	if (xattr_ac)
+		ocfs2_free_alloc_context(xattr_ac);
+
 	if (data_ac)
 		ocfs2_free_alloc_context(data_ac);
 
-- 
1.5.4.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-10-27  8:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-27  8:36 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
2008-10-27  8:42 ` [Ocfs2-devel] [PATCH 1/4] ocfs2: move new_inode out of the transaction Tiger Yang
2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 2/4] ocfs2: add ocfs2_xattr_set_handle Tiger Yang
2008-10-27  8:43 ` [Ocfs2-devel] [PATCH 3/4] ocfs2: add security xattr support Tiger Yang
2008-10-27  8:44 ` [Ocfs2-devel] [PATCH 4/4] ocfs2: add init_security in mknod Tiger Yang
  -- strict thread matches above, loose matches on Subject: below --
2008-10-27  8:29 [Ocfs2-devel] ocfs2: add security EA support v4 Tiger Yang
2008-10-27  8:43 ` Tao Ma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.