diff options
author | Theodore Ts'o <tytso@mit.edu> | 2012-12-11 03:31:49 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-12-11 03:31:49 -0500 |
commit | bd9926e80330d43f15b710c2935fa41b792d56fd (patch) | |
tree | ccc30335831784996b7435d10df39ee14e92afad /fs | |
parent | 9a4c8019471386c6fb039ae9e30f5216b6b55a9e (diff) |
ext4: zero out inline data using memset() instead of empty_zero_page
Not all architectures (in particular, sparc64) have empty_zero_page.
So instead of copying from empty_zero_page, use memset to clear the
inline data by signalling to ext4_xattr_set_entry() via a magic
pointer value, EXT4_ZERO_ATTR_VALUE, which is defined by casting -1 to
a pointer.
This fixes a build failure on sparc64, and the memset() should be more
efficient than using memcpy() anyway.
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/inline.c | 2 | ||||
-rw-r--r-- | fs/ext4/xattr.c | 22 | ||||
-rw-r--r-- | fs/ext4/xattr.h | 1 |
3 files changed, 18 insertions, 7 deletions
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 53b2f65091dd..387c47c6cda9 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c | |||
@@ -268,7 +268,7 @@ static int ext4_create_inline_data(handle_t *handle, | |||
268 | goto out; | 268 | goto out; |
269 | 269 | ||
270 | if (len > EXT4_MIN_INLINE_DATA_SIZE) { | 270 | if (len > EXT4_MIN_INLINE_DATA_SIZE) { |
271 | value = (void *)empty_zero_page; | 271 | value = EXT4_ZERO_XATTR_VALUE; |
272 | len -= EXT4_MIN_INLINE_DATA_SIZE; | 272 | len -= EXT4_MIN_INLINE_DATA_SIZE; |
273 | } else { | 273 | } else { |
274 | value = ""; | 274 | value = ""; |
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 2251769a3c53..3a91ebc2b66f 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
@@ -628,9 +628,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s) | |||
628 | size. Just replace. */ | 628 | size. Just replace. */ |
629 | s->here->e_value_size = | 629 | s->here->e_value_size = |
630 | cpu_to_le32(i->value_len); | 630 | cpu_to_le32(i->value_len); |
631 | memset(val + size - EXT4_XATTR_PAD, 0, | 631 | if (i->value == EXT4_ZERO_XATTR_VALUE) { |
632 | EXT4_XATTR_PAD); /* Clear pad bytes. */ | 632 | memset(val, 0, size); |
633 | memcpy(val, i->value, i->value_len); | 633 | } else { |
634 | /* Clear pad bytes first. */ | ||
635 | memset(val + size - EXT4_XATTR_PAD, 0, | ||
636 | EXT4_XATTR_PAD); | ||
637 | memcpy(val, i->value, i->value_len); | ||
638 | } | ||
634 | return 0; | 639 | return 0; |
635 | } | 640 | } |
636 | 641 | ||
@@ -669,9 +674,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s) | |||
669 | size_t size = EXT4_XATTR_SIZE(i->value_len); | 674 | size_t size = EXT4_XATTR_SIZE(i->value_len); |
670 | void *val = s->base + min_offs - size; | 675 | void *val = s->base + min_offs - size; |
671 | s->here->e_value_offs = cpu_to_le16(min_offs - size); | 676 | s->here->e_value_offs = cpu_to_le16(min_offs - size); |
672 | memset(val + size - EXT4_XATTR_PAD, 0, | 677 | if (i->value == EXT4_ZERO_XATTR_VALUE) { |
673 | EXT4_XATTR_PAD); /* Clear the pad bytes. */ | 678 | memset(val, 0, size); |
674 | memcpy(val, i->value, i->value_len); | 679 | } else { |
680 | /* Clear the pad bytes first. */ | ||
681 | memset(val + size - EXT4_XATTR_PAD, 0, | ||
682 | EXT4_XATTR_PAD); | ||
683 | memcpy(val, i->value, i->value_len); | ||
684 | } | ||
675 | } | 685 | } |
676 | } | 686 | } |
677 | return 0; | 687 | return 0; |
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index 7b5513ed3b38..69eda787a96a 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h | |||
@@ -71,6 +71,7 @@ struct ext4_xattr_entry { | |||
71 | #define BFIRST(bh) ENTRY(BHDR(bh)+1) | 71 | #define BFIRST(bh) ENTRY(BHDR(bh)+1) |
72 | #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) | 72 | #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) |
73 | 73 | ||
74 | #define EXT4_ZERO_XATTR_VALUE ((void *)-1) | ||
74 | 75 | ||
75 | struct ext4_xattr_info { | 76 | struct ext4_xattr_info { |
76 | int name_index; | 77 | int name_index; |