提交 bd9926e8 编写于 作者: T Theodore Ts'o

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: NTao Ma <boyu.mt@taobao.com>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 9a4c8019
...@@ -268,7 +268,7 @@ static int ext4_create_inline_data(handle_t *handle, ...@@ -268,7 +268,7 @@ static int ext4_create_inline_data(handle_t *handle,
goto out; goto out;
if (len > EXT4_MIN_INLINE_DATA_SIZE) { if (len > EXT4_MIN_INLINE_DATA_SIZE) {
value = (void *)empty_zero_page; value = EXT4_ZERO_XATTR_VALUE;
len -= EXT4_MIN_INLINE_DATA_SIZE; len -= EXT4_MIN_INLINE_DATA_SIZE;
} else { } else {
value = ""; value = "";
......
...@@ -628,9 +628,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s) ...@@ -628,9 +628,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
size. Just replace. */ size. Just replace. */
s->here->e_value_size = s->here->e_value_size =
cpu_to_le32(i->value_len); cpu_to_le32(i->value_len);
memset(val + size - EXT4_XATTR_PAD, 0, if (i->value == EXT4_ZERO_XATTR_VALUE) {
EXT4_XATTR_PAD); /* Clear pad bytes. */ memset(val, 0, size);
memcpy(val, i->value, i->value_len); } else {
/* Clear pad bytes first. */
memset(val + size - EXT4_XATTR_PAD, 0,
EXT4_XATTR_PAD);
memcpy(val, i->value, i->value_len);
}
return 0; return 0;
} }
...@@ -669,9 +674,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s) ...@@ -669,9 +674,14 @@ ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
size_t size = EXT4_XATTR_SIZE(i->value_len); size_t size = EXT4_XATTR_SIZE(i->value_len);
void *val = s->base + min_offs - size; void *val = s->base + min_offs - size;
s->here->e_value_offs = cpu_to_le16(min_offs - size); s->here->e_value_offs = cpu_to_le16(min_offs - size);
memset(val + size - EXT4_XATTR_PAD, 0, if (i->value == EXT4_ZERO_XATTR_VALUE) {
EXT4_XATTR_PAD); /* Clear the pad bytes. */ memset(val, 0, size);
memcpy(val, i->value, i->value_len); } else {
/* Clear the pad bytes first. */
memset(val + size - EXT4_XATTR_PAD, 0,
EXT4_XATTR_PAD);
memcpy(val, i->value, i->value_len);
}
} }
} }
return 0; return 0;
......
...@@ -71,6 +71,7 @@ struct ext4_xattr_entry { ...@@ -71,6 +71,7 @@ struct ext4_xattr_entry {
#define BFIRST(bh) ENTRY(BHDR(bh)+1) #define BFIRST(bh) ENTRY(BHDR(bh)+1)
#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
#define EXT4_ZERO_XATTR_VALUE ((void *)-1)
struct ext4_xattr_info { struct ext4_xattr_info {
int name_index; int name_index;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册