diff options
author | Tiger Yang <tiger.yang@oracle.com> | 2008-11-13 22:16:41 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2009-01-05 11:34:20 -0500 |
commit | 534eadddc1de8754a227202c0e747af4973f82ce (patch) | |
tree | e044976da3644f020ed1da420211cc433dbc0a92 /fs/ocfs2/xattr.c | |
parent | 923f7f3102b80403152e05aee3d55ecfce240440 (diff) |
ocfs2: add ocfs2_init_security in during file create
Security attributes must be set when creating a new inode.
We do this in three steps.
- First, get security xattr's name and value by security_operation
- Calculate and reserve the meta data and clusters needed by this security
xattr before starting transaction
- Finally, we set it before add_entry
Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/xattr.c')
-rw-r--r-- | fs/ocfs2/xattr.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index db03162914c..2cab0d6615f 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -81,6 +81,9 @@ struct ocfs2_xattr_set_ctxt { | |||
81 | 81 | ||
82 | #define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root)) | 82 | #define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root)) |
83 | #define OCFS2_XATTR_INLINE_SIZE 80 | 83 | #define OCFS2_XATTR_INLINE_SIZE 80 |
84 | #define OCFS2_XATTR_FREE_IN_IBODY (OCFS2_MIN_XATTR_INLINE_SIZE \ | ||
85 | - sizeof(struct ocfs2_xattr_header) \ | ||
86 | - sizeof(__u32)) | ||
84 | 87 | ||
85 | static struct ocfs2_xattr_def_value_root def_xv = { | 88 | static struct ocfs2_xattr_def_value_root def_xv = { |
86 | .xv.xr_list.l_count = cpu_to_le16(1), | 89 | .xv.xr_list.l_count = cpu_to_le16(1), |
@@ -343,6 +346,52 @@ static void ocfs2_xattr_hash_entry(struct inode *inode, | |||
343 | return; | 346 | return; |
344 | } | 347 | } |
345 | 348 | ||
349 | static int ocfs2_xattr_entry_real_size(int name_len, size_t value_len) | ||
350 | { | ||
351 | int size = 0; | ||
352 | |||
353 | if (value_len <= OCFS2_XATTR_INLINE_SIZE) | ||
354 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(value_len); | ||
355 | else | ||
356 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
357 | size += sizeof(struct ocfs2_xattr_entry); | ||
358 | |||
359 | return size; | ||
360 | } | ||
361 | |||
362 | int ocfs2_calc_security_init(struct inode *dir, | ||
363 | struct ocfs2_security_xattr_info *si, | ||
364 | int *want_clusters, | ||
365 | int *xattr_credits, | ||
366 | struct ocfs2_alloc_context **xattr_ac) | ||
367 | { | ||
368 | int ret = 0; | ||
369 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); | ||
370 | int s_size = ocfs2_xattr_entry_real_size(strlen(si->name), | ||
371 | si->value_len); | ||
372 | |||
373 | /* | ||
374 | * The max space of security xattr taken inline is | ||
375 | * 256(name) + 80(value) + 16(entry) = 352 bytes, | ||
376 | * So reserve one metadata block for it is ok. | ||
377 | */ | ||
378 | if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE || | ||
379 | s_size > OCFS2_XATTR_FREE_IN_IBODY) { | ||
380 | ret = ocfs2_reserve_new_metadata_blocks(osb, 1, xattr_ac); | ||
381 | if (ret) { | ||
382 | mlog_errno(ret); | ||
383 | return ret; | ||
384 | } | ||
385 | *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS; | ||
386 | } | ||
387 | |||
388 | /* reserve clusters for xattr value which will be set in B tree*/ | ||
389 | if (si->value_len > OCFS2_XATTR_INLINE_SIZE) | ||
390 | *want_clusters += ocfs2_clusters_for_bytes(dir->i_sb, | ||
391 | si->value_len); | ||
392 | return ret; | ||
393 | } | ||
394 | |||
346 | static int ocfs2_xattr_extend_allocation(struct inode *inode, | 395 | static int ocfs2_xattr_extend_allocation(struct inode *inode, |
347 | u32 clusters_to_add, | 396 | u32 clusters_to_add, |
348 | struct buffer_head *xattr_bh, | 397 | struct buffer_head *xattr_bh, |
@@ -5016,6 +5065,27 @@ static int ocfs2_xattr_security_set(struct inode *inode, const char *name, | |||
5016 | size, flags); | 5065 | size, flags); |
5017 | } | 5066 | } |
5018 | 5067 | ||
5068 | int ocfs2_init_security_get(struct inode *inode, | ||
5069 | struct inode *dir, | ||
5070 | struct ocfs2_security_xattr_info *si) | ||
5071 | { | ||
5072 | return security_inode_init_security(inode, dir, &si->name, &si->value, | ||
5073 | &si->value_len); | ||
5074 | } | ||
5075 | |||
5076 | int ocfs2_init_security_set(handle_t *handle, | ||
5077 | struct inode *inode, | ||
5078 | struct buffer_head *di_bh, | ||
5079 | struct ocfs2_security_xattr_info *si, | ||
5080 | struct ocfs2_alloc_context *xattr_ac, | ||
5081 | struct ocfs2_alloc_context *data_ac) | ||
5082 | { | ||
5083 | return ocfs2_xattr_set_handle(handle, inode, di_bh, | ||
5084 | OCFS2_XATTR_INDEX_SECURITY, | ||
5085 | si->name, si->value, si->value_len, 0, | ||
5086 | xattr_ac, data_ac); | ||
5087 | } | ||
5088 | |||
5019 | struct xattr_handler ocfs2_xattr_security_handler = { | 5089 | struct xattr_handler ocfs2_xattr_security_handler = { |
5020 | .prefix = XATTR_SECURITY_PREFIX, | 5090 | .prefix = XATTR_SECURITY_PREFIX, |
5021 | .list = ocfs2_xattr_security_list, | 5091 | .list = ocfs2_xattr_security_list, |