f2fs: clean up xattr operation
1. don't allocate redundant memory in read_all_xattrs. 2. introduce RESERVED_XATTR_SIZE for cleanup. Signed-off-by: Chao Yu <yuchao0@huawei.com> Reviewed-by: Kinglong Mee <kinglongmee@gmail.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
afc8c720de
commit
b92a302245
2 changed files with 13 additions and 15 deletions
|
@ -297,15 +297,13 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
|
||||||
void *cur_addr, *txattr_addr, *last_addr = NULL;
|
void *cur_addr, *txattr_addr, *last_addr = NULL;
|
||||||
nid_t xnid = F2FS_I(inode)->i_xattr_nid;
|
nid_t xnid = F2FS_I(inode)->i_xattr_nid;
|
||||||
unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
|
unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
|
||||||
unsigned int inline_size = 0;
|
unsigned int inline_size = inline_xattr_size(inode);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
inline_size = inline_xattr_size(inode);
|
|
||||||
|
|
||||||
if (!size && !inline_size)
|
if (!size && !inline_size)
|
||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
|
|
||||||
txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
|
txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
|
||||||
GFP_F2FS_ZERO);
|
GFP_F2FS_ZERO);
|
||||||
if (!txattr_addr)
|
if (!txattr_addr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -375,13 +373,14 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
|
||||||
{
|
{
|
||||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||||
struct f2fs_xattr_header *header;
|
struct f2fs_xattr_header *header;
|
||||||
size_t size = PAGE_SIZE, inline_size = 0;
|
nid_t xnid = F2FS_I(inode)->i_xattr_nid;
|
||||||
|
unsigned int size = VALID_XATTR_BLOCK_SIZE;
|
||||||
|
unsigned int inline_size = inline_xattr_size(inode);
|
||||||
void *txattr_addr;
|
void *txattr_addr;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
inline_size = inline_xattr_size(inode);
|
txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
|
||||||
|
GFP_F2FS_ZERO);
|
||||||
txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
|
|
||||||
if (!txattr_addr)
|
if (!txattr_addr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -405,19 +404,19 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read from xattr node block */
|
/* read from xattr node block */
|
||||||
if (F2FS_I(inode)->i_xattr_nid) {
|
if (xnid) {
|
||||||
struct page *xpage;
|
struct page *xpage;
|
||||||
void *xattr_addr;
|
void *xattr_addr;
|
||||||
|
|
||||||
/* The inode already has an extended attribute block. */
|
/* The inode already has an extended attribute block. */
|
||||||
xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid);
|
xpage = get_node_page(sbi, xnid);
|
||||||
if (IS_ERR(xpage)) {
|
if (IS_ERR(xpage)) {
|
||||||
err = PTR_ERR(xpage);
|
err = PTR_ERR(xpage);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
xattr_addr = page_address(xpage);
|
xattr_addr = page_address(xpage);
|
||||||
memcpy(txattr_addr + inline_size, xattr_addr, PAGE_SIZE);
|
memcpy(txattr_addr + inline_size, xattr_addr, size);
|
||||||
f2fs_put_page(xpage, 1);
|
f2fs_put_page(xpage, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,14 +438,12 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize,
|
||||||
void *txattr_addr, struct page *ipage)
|
void *txattr_addr, struct page *ipage)
|
||||||
{
|
{
|
||||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||||
size_t inline_size = 0;
|
size_t inline_size = inline_xattr_size(inode);
|
||||||
void *xattr_addr;
|
void *xattr_addr;
|
||||||
struct page *xpage;
|
struct page *xpage;
|
||||||
nid_t new_nid = 0;
|
nid_t new_nid = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
inline_size = inline_xattr_size(inode);
|
|
||||||
|
|
||||||
if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
|
if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
|
||||||
if (!alloc_nid(sbi, &new_nid))
|
if (!alloc_nid(sbi, &new_nid))
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
|
@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
|
||||||
!IS_XATTR_LAST_ENTRY(entry);\
|
!IS_XATTR_LAST_ENTRY(entry);\
|
||||||
entry = XATTR_NEXT_ENTRY(entry))
|
entry = XATTR_NEXT_ENTRY(entry))
|
||||||
#define MAX_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
|
#define MAX_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
|
||||||
#define VALID_XATTR_BLOCK_SIZE (MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
|
#define RESERVED_XATTR_SIZE (sizeof(__u32))
|
||||||
|
#define VALID_XATTR_BLOCK_SIZE (MAX_XATTR_BLOCK_SIZE - RESERVED_XATTR_SIZE)
|
||||||
#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
|
#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
|
||||||
VALID_XATTR_BLOCK_SIZE)
|
VALID_XATTR_BLOCK_SIZE)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue