Skip to contentSkip to conversation

f2fs: copy all valid xattr data includes the last zero

PATCH In review Kinglong Mee 3 participants 10 messages Mar 18, 2017 – Mar 23, 2017 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: copy all valid xattr data includes the last zero

It's better coping all valid xattr data includes the last zero.

---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/xattr.c +2 -2
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
+	unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
 	unsigned int inline_size = 0;
 	int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
-	size_t size = PAGE_SIZE, inline_size = 0;
+	size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
 	void *txattr_addr;
 	int err;
 
fs/f2fs/xattr.h +2 -2
index d5a9492..629c8ae 100644
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE	(PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE	(MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)		XATTR_ALIGN(inline_xattr_size(i) +	\
-						VALID_XATTR_BLOCK_SIZE)
+				MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
 #define MAX_VALUE_LEN(i)	(MIN_OFFSET(i) -			\
 				sizeof(struct f2fs_xattr_header) -	\
Signature · 6 lines
2.9.3


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer
#1 lore raw

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 47 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/xattr.c +2 -2
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
+	unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
 	unsigned int inline_size = 0;
 	int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
-	size_t size = PAGE_SIZE, inline_size = 0;
+	size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
 	void *txattr_addr;
 	int err;
 
fs/f2fs/xattr.h +2 -2
index d5a9492..629c8ae 100644
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE	(PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE	(MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)		XATTR_ALIGN(inline_xattr_size(i) +	\
-						VALID_XATTR_BLOCK_SIZE)
+				MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
 #define MAX_VALUE_LEN(i)	(MIN_OFFSET(i) -			\
 				sizeof(struct f2fs_xattr_header) -	\
Signature · 1 line
2.9.3

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#2 lore raw
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 9 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct page *ipage, · line 331

Quoted 9 lines
fs/f2fs/xattr.c +1 -1
+	unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
 	unsigned int inline_size = 0;
 	int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
-	size_t size = PAGE_SIZE, inline_size = 0;

Yes, it's larger.
It's for consistent with the above.

thanks,
Kinglong Mee

Quoted 18 lines
Quoted 18 lines
fs/f2fs/xattr.c +1 -0
+	size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
 	void *txattr_addr;
 	int err;
 
fs/f2fs/xattr.h +2 -2
index d5a9492..629c8ae 100644
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE	(PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE	(MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)		XATTR_ALIGN(inline_xattr_size(i) +	\
-						VALID_XATTR_BLOCK_SIZE)
+				MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
Quoted 5 lines
Quoted 4 lines
fs/f2fs/xattr.h +0 -0
 #define MAX_VALUE_LEN(i)	(MIN_OFFSET(i) -			\
 				sizeof(struct f2fs_xattr_header) -	\
Signature · 1 line
2.9.3

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#3 lore raw
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

The below kzalloc() will make it zero. Any problem?

Thanks,

Quoted 13 lines
Quoted 9 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct page *ipage, · line 331

Quoted 9 lines
fs/f2fs/xattr.c +1 -1
+	unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
 	unsigned int inline_size = 0;
 	int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
-	size_t size = PAGE_SIZE, inline_size = 0;

Yes, it's larger.
It's for consistent with the above.

Quoted 26 lines

thanks,
Kinglong Mee

Quoted 23 lines
Quoted 22 lines
fs/f2fs/xattr.c +1 -0
+	size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
 	void *txattr_addr;
 	int err;
 
fs/f2fs/xattr.h +2 -2
index d5a9492..629c8ae 100644
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE	(PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE	(MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)		XATTR_ALIGN(inline_xattr_size(i) +	\
-						VALID_XATTR_BLOCK_SIZE)
+				MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
 #define MAX_VALUE_LEN(i)	(MIN_OFFSET(i) -			\
 				sizeof(struct f2fs_xattr_header) -	\
Signature · 1 line
2.9.3

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#4 lore raw
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +0 -0
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct

page *ipage,
void *cur_addr, *txattr_addr, *last_addr = NULL; nid_t xnid = F2FS_I(inode)->i_xattr_nid; 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;

- inline_size = inline_xattr_size(inode);
-
if (!size && !inline_size)
return -ENODATA;

- txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+ txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
GFP_F2FS_ZERO);
if (!txattr_addr)
return -ENOMEM;
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
+ unsigned int inline_size = inline_xattr_size(inode);
void *txattr_addr;
int err;

- inline_size = inline_xattr_size(inode);
-
- txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+ txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+ GFP_F2FS_ZERO);
if (!txattr_addr)
return -ENOMEM;

@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
}

/* read from xattr node block */
- if (F2FS_I(inode)->i_xattr_nid) {
+ if (xnid) {
struct page *xpage;
void *xattr_addr;

/* 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)) {
err = PTR_ERR(xpage);
goto fail;
}

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);
}

@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize,
void *txattr_addr, struct page *ipage)
{
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;
struct page *xpage;
nid_t new_nid = 0;
int err;

- inline_size = inline_xattr_size(inode);
-
if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
if (!alloc_nid(sbi, &new_nid))
return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize,
}

xattr_addr = page_address(xpage);
- memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);
+ memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
set_page_dirty(xpage);
f2fs_put_page(xpage, 1);

fs/f2fs/xattr.h +2 -1
index d5a94928c116..1e7db8d0806e 100644
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 
Signature · 1 line
2.8.2.295.g3f1c1d0
Quoted 51 lines

Thanks,

Quoted 13 lines
Quoted 9 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct page *ipage, · line 331

Quoted 9 lines
fs/f2fs/xattr.c +1 -1
+	unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
 	unsigned int inline_size = 0;
 	int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
-	size_t size = PAGE_SIZE, inline_size = 0;

Yes, it's larger.
It's for consistent with the above.

Quoted 26 lines

thanks,
Kinglong Mee

Quoted 23 lines
Quoted 22 lines
fs/f2fs/xattr.c +1 -0
+	size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
 	void *txattr_addr;
 	int err;
 
fs/f2fs/xattr.h +2 -2
index d5a9492..629c8ae 100644
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE	(PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE	(MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)		XATTR_ALIGN(inline_xattr_size(i) +	\
-						VALID_XATTR_BLOCK_SIZE)
+				MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
 #define MAX_VALUE_LEN(i)	(MIN_OFFSET(i) -			\
 				sizeof(struct f2fs_xattr_header) -	\
Signature · 1 line
2.9.3

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#5 lore raw
Quoted 73 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +2 -4
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct
 page *ipage,
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
 	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;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (!size && !inline_size)
 		return -ENODATA;
 
-	txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
 							GFP_F2FS_ZERO);
 	if (!txattr_addr)
fs/f2fs/xattr.c +0 -0
 		return -ENOMEM;

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct · line 331

Quoted 7 lines
fs/f2fs/xattr.c +2 -1
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in inline xattr space while adding new xattr entry.

unsigned int size = VALID_XATTR_BLOCK_SIZE;

Thanks,

Quoted 68 lines
fs/f2fs/xattr.c +7 -9
+	unsigned int inline_size = inline_xattr_size(inode);
 	void *txattr_addr;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
-	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+							GFP_F2FS_ZERO);
 	if (!txattr_addr)
 		return -ENOMEM;
@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 	}
 
 	/* read from xattr node block */
-	if (F2FS_I(inode)->i_xattr_nid) {
+	if (xnid) {
 		struct page *xpage;
 		void *xattr_addr;
 
 		/* 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)) {
 			err = PTR_ERR(xpage);
 			goto fail;
 		}
 
 		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);
 	}
@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 				void *txattr_addr, struct page *ipage)
 {
 	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;
 	struct page *xpage;
 	nid_t new_nid = 0;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
 		if (!alloc_nid(sbi, &new_nid))
fs/f2fs/xattr.c +1 -1
 			return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 	}
 
 	xattr_addr = page_address(xpage);
-	memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);
+	memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
 	set_page_dirty(xpage);
 	f2fs_put_page(xpage, 1);
fs/f2fs/xattr.h +0 -0
index d5a94928c116..1e7db8d0806e 100644

fs/f2fs/xattr.h struct f2fs_xattr_entry { · line 80

Quoted 9 lines
fs/f2fs/xattr.h +2 -1
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author Reviewed-by
#6 lore raw
Quoted 85 lines · Chao Yu
Quoted 73 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +2 -4
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct
 page *ipage,
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
 	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;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (!size && !inline_size)
 		return -ENODATA;
 
-	txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
 							GFP_F2FS_ZERO);
 	if (!txattr_addr)
fs/f2fs/xattr.c +0 -0
 		return -ENOMEM;

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct · line 331

Quoted 7 lines
fs/f2fs/xattr.c +2 -1
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in inline xattr space while adding new xattr entry.

Quoted 1 line

unsigned int size = VALID_XATTR_BLOCK_SIZE;

It's better that mine.

Thanks,
Kinglong Mee

Quoted 66 lines

Thanks,

Quoted 63 lines
fs/f2fs/xattr.c +7 -9
+	unsigned int inline_size = inline_xattr_size(inode);
 	void *txattr_addr;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
-	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+							GFP_F2FS_ZERO);
 	if (!txattr_addr)
 		return -ENOMEM;
@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 	}
 
 	/* read from xattr node block */
-	if (F2FS_I(inode)->i_xattr_nid) {
+	if (xnid) {
 		struct page *xpage;
 		void *xattr_addr;
 
 		/* 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)) {
 			err = PTR_ERR(xpage);
 			goto fail;
 		}
 
 		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);
 	}
@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 				void *txattr_addr, struct page *ipage)
 {
 	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;
 	struct page *xpage;
 	nid_t new_nid = 0;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
 		if (!alloc_nid(sbi, &new_nid))
fs/f2fs/xattr.c +1 -1
 			return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 	}
 
 	xattr_addr = page_address(xpage);
-	memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);
+	memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
 	set_page_dirty(xpage);
 	f2fs_put_page(xpage, 1);
Quoted 16 lines
Quoted 5 lines
fs/f2fs/xattr.h +0 -0
index d5a94928c116..1e7db8d0806e 100644

fs/f2fs/xattr.h struct f2fs_xattr_entry { · line 80

Quoted 9 lines
fs/f2fs/xattr.h +2 -1
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#7 lore raw
In reply to Chao Yu
Quoted 68 lines · Chao Yu
Quoted 67 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +1 -3
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct
 page *ipage,
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
 	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;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (!size && !inline_size)
 		return -ENODATA;
 
Quoted 16 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct · line 331

Quoted 13 lines
fs/f2fs/xattr.c +1 -1
-	txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
 							GFP_F2FS_ZERO);
 	if (!txattr_addr)
fs/f2fs/xattr.c +2 -1
 		return -ENOMEM;
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in inline xattr space while adding new xattr entry.

Do you mean any race condition? It seems setxattr is covered by i_mutex, but listxattr does not. But, given xnid, i_xattr_nid won't be used below, so it looks fine to go with xnid check.

Thanks,

Quoted 68 lines

unsigned int size = VALID_XATTR_BLOCK_SIZE;

Thanks,

Quoted 63 lines
fs/f2fs/xattr.c +7 -9
+	unsigned int inline_size = inline_xattr_size(inode);
 	void *txattr_addr;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
-	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+							GFP_F2FS_ZERO);
 	if (!txattr_addr)
 		return -ENOMEM;
@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 	}
 
 	/* read from xattr node block */
-	if (F2FS_I(inode)->i_xattr_nid) {
+	if (xnid) {
 		struct page *xpage;
 		void *xattr_addr;
 
 		/* 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)) {
 			err = PTR_ERR(xpage);
 			goto fail;
 		}
 
 		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);
 	}
@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 				void *txattr_addr, struct page *ipage)
 {
 	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;
 	struct page *xpage;
 	nid_t new_nid = 0;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
 		if (!alloc_nid(sbi, &new_nid))
fs/f2fs/xattr.c +1 -1
 			return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 	}
 
 	xattr_addr = page_address(xpage);
-	memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);
+	memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
 	set_page_dirty(xpage);
 	f2fs_put_page(xpage, 1);
Quoted 14 lines
Quoted 5 lines
fs/f2fs/xattr.h +0 -0
index d5a94928c116..1e7db8d0806e 100644

fs/f2fs/xattr.h struct f2fs_xattr_entry { · line 80

Quoted 9 lines
fs/f2fs/xattr.h +2 -1
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#8 lore raw
Quoted 86 lines · Jaegeuk Kim
Quoted 68 lines · Chao Yu
Quoted 67 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +1 -3
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct
 page *ipage,
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
 	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;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (!size && !inline_size)
 		return -ENODATA;
 
Quoted 16 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct · line 331

Quoted 13 lines
fs/f2fs/xattr.c +1 -1
-	txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
 							GFP_F2FS_ZERO);
 	if (!txattr_addr)
fs/f2fs/xattr.c +2 -1
 		return -ENOMEM;
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in inline xattr space while adding new xattr entry.

Quoted 3 lines

Do you mean any race condition? It seems setxattr is covered by i_mutex, but listxattr does not. But, given xnid, i_xattr_nid won't be used below, so it looks fine to go with xnid check.

To cover below case

- __f2fs_setxattr
- read_all_xattrs
- write_all_xattrs
- new_node_page
- memcpy

Quoted 65 lines

Thanks,

Quoted 62 lines

unsigned int size = VALID_XATTR_BLOCK_SIZE;

Thanks,

Quoted 57 lines
fs/f2fs/xattr.c +7 -9
+	unsigned int inline_size = inline_xattr_size(inode);
 	void *txattr_addr;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
-	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+							GFP_F2FS_ZERO);
 	if (!txattr_addr)
 		return -ENOMEM;
@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 	}
 
 	/* read from xattr node block */
-	if (F2FS_I(inode)->i_xattr_nid) {
+	if (xnid) {
 		struct page *xpage;
 		void *xattr_addr;
 
 		/* 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)) {
 			err = PTR_ERR(xpage);
 			goto fail;
 		}
 
 		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);
 	}
@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 				void *txattr_addr, struct page *ipage)
 {
 	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;
 	struct page *xpage;
 	nid_t new_nid = 0;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
 		if (!alloc_nid(sbi, &new_nid))
fs/f2fs/xattr.c +0 -0
 			return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 	}
 
Quoted 2 lines
Quoted 2 lines

fs/f2fs/xattr.c static inline int write_all_xattrs(struct inode *inode, · line 458

Quoted 2 lines
fs/f2fs/xattr.c +0 -1
 	xattr_addr = page_address(xpage);
-	memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);

And this needs to be kept to avoid remain random data in newly allocated xattr node page.

Thanks,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/xattr.c +1 -0
+	memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
 	set_page_dirty(xpage);
 	f2fs_put_page(xpage, 1);
Quoted 17 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/xattr.h +0 -0
index d5a94928c116..1e7db8d0806e 100644
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
Quoted 8 lines

fs/f2fs/xattr.h struct f2fs_xattr_entry { · line 80

Quoted 8 lines
fs/f2fs/xattr.h +2 -1
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#9 lore raw
Quoted 91 lines · Chao Yu
Quoted 86 lines · Jaegeuk Kim
Quoted 68 lines · Chao Yu
Quoted 67 lines · Chao Yu
Quoted 32 lines · Jaegeuk Kim
Quoted 19 lines · Kinglong Mee
Quoted 18 lines · Jaegeuk Kim

Hi Kinglong,

Quoted 1 line · Kinglong Mee

It's better coping all valid xattr data includes the last zero.

Why do we need this?

The size of txattr_addr would be larger than the space we need.

Thanks,

Quoted 7 lines
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines
Quoted 9 lines

fs/f2fs/xattr.c static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · line 252

Quoted 9 lines
fs/f2fs/xattr.c +0 -1
index aff7619..41785c9 100644
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-	unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

Quoted 1 line

The below kzalloc() will make it zero. Any problem?

There is no problem without this change, but anyway, IMO, it needs to do cleanup as it can provider better readability making allocated size and copied size be consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.

And since during allocation we have initialize memory with zero, so I prefer to not copy extra reserved xattr space.

Jaegeuk, Kinglong, how about changing like below:

---
 fs/f2fs/xattr.c | 27 ++++++++++++---------------
 fs/f2fs/xattr.h |  3 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)
fs/f2fs/xattr.c +1 -3
index aff7619e3f96..308b06664068 100644
@@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, struct
 page *ipage,
 	void *cur_addr, *txattr_addr, *last_addr = NULL;
 	nid_t xnid = F2FS_I(inode)->i_xattr_nid;
 	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;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (!size && !inline_size)
 		return -ENODATA;
 
Quoted 16 lines

fs/f2fs/xattr.c static int read_all_xattrs(struct inode *inode, struct · line 331

Quoted 13 lines
fs/f2fs/xattr.c +1 -1
-	txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
 							GFP_F2FS_ZERO);
 	if (!txattr_addr)
fs/f2fs/xattr.c +2 -1
 		return -ENOMEM;
@@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	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 = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in inline xattr space while adding new xattr entry.

Quoted 3 lines

Do you mean any race condition? It seems setxattr is covered by i_mutex, but listxattr does not. But, given xnid, i_xattr_nid won't be used below, so it looks fine to go with xnid check.

Quoted 7 lines

To cover below case

- __f2fs_setxattr
- read_all_xattrs
- write_all_xattrs
- new_node_page
- memcpy

Oh, I see. This happened in your change.

Thanks,

Quoted 66 lines
Quoted 66 lines

Thanks,

Quoted 62 lines

unsigned int size = VALID_XATTR_BLOCK_SIZE;

Thanks,

Quoted 57 lines
fs/f2fs/xattr.c +7 -9
+	unsigned int inline_size = inline_xattr_size(inode);
 	void *txattr_addr;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
-	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
+	txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
+							GFP_F2FS_ZERO);
 	if (!txattr_addr)
 		return -ENOMEM;
@@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
 page *ipage,
 	}
 
 	/* read from xattr node block */
-	if (F2FS_I(inode)->i_xattr_nid) {
+	if (xnid) {
 		struct page *xpage;
 		void *xattr_addr;
 
 		/* 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)) {
 			err = PTR_ERR(xpage);
 			goto fail;
 		}
 
 		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);
 	}
@@ -392,14 +391,12 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 				void *txattr_addr, struct page *ipage)
 {
 	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;
 	struct page *xpage;
 	nid_t new_nid = 0;
 	int err;
 
-	inline_size = inline_xattr_size(inode);
-
 	if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
 		if (!alloc_nid(sbi, &new_nid))
fs/f2fs/xattr.c +0 -0
 			return -ENOSPC;
@@ -454,7 +451,7 @@ static inline int write_all_xattrs(struct inode *inode,
 __u32 hsize,
 	}
 
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines

fs/f2fs/xattr.c static inline int write_all_xattrs(struct inode *inode, · line 458

Quoted 2 lines
fs/f2fs/xattr.c +0 -1
 	xattr_addr = page_address(xpage);
-	memcpy(xattr_addr, txattr_addr + inline_size, MAX_XATTR_BLOCK_SIZE);

And this needs to be kept to avoid remain random data in newly allocated xattr node page.

Thanks,

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/xattr.c +1 -0
+	memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE);
 	set_page_dirty(xpage);
 	f2fs_put_page(xpage, 1);
Quoted 14 lines
Quoted 5 lines
fs/f2fs/xattr.h +0 -0
index d5a94928c116..1e7db8d0806e 100644

fs/f2fs/xattr.h struct f2fs_xattr_entry { · line 80

Quoted 9 lines
fs/f2fs/xattr.h +2 -1
@@ -73,7 +73,8 @@ struct f2fs_xattr_entry {
 				!IS_XATTR_LAST_ENTRY(entry);\
 				entry = XATTR_NEXT_ENTRY(entry))
 #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) +	\
 						VALID_XATTR_BLOCK_SIZE)
 

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot