src/attr_replace_test: limit size of extended attribute value
PATCH 1/1 src/attr_replace_test: limit size of extended attribute value
The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.
--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)
src/attr_replace_test.c +3 -0
@@ -9,6 +9,7 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <linux/limits.h> #define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +45,8 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); +if (size >XATTR_SIZE_MAX ) + size =XATTR_SIZE_MAX ; value =malloc (size);if (!value)fail ("Failed to allocate memory\n" );
Quoted 24 lines · Luis Henriques
The maximum size for extended attribute values is 65536 (
XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning-E2BIG.Cc Darrick J. Wong <[email protected]>Signed-off-by Luis Henriques <[email protected]>--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)src/attr_replace_test.c +1
-0@@ -9,6 +9,7 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <linux/limits.h> #define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \
src/attr_replace_test.c int main(int argc, char *argv[]) · line 49
Quoted 5 lines
src/attr_replace_test.c +2
-0@@ -44,6 +45,8 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); +if (size >XATTR_SIZE_MAX ) + size =XATTR_SIZE_MAX ;
nit: size = max(size, XATTRS_SIZE_MAX);
Quoted 4 lines
src/attr_replace_test.c +0
-0value =malloc (size);if (!value)fail ("Failed to allocate memory\n" );
Quoted 22 lines · Nikolay Borisov
Quoted 21 lines · Luis Henriques
The maximum size for extended attribute values is 65536 (
XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning-E2BIG.Cc Darrick J. Wong <[email protected]>Signed-off-by Luis Henriques <[email protected]>--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)src/attr_replace_test.c +1
-0@@ -9,6 +9,7 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <linux/limits.h>
Quoted 10 lines
src/attr_replace_test.c int main(int argc, char *argv[]) · line 49
Quoted 8 lines
src/attr_replace_test.c +2
-0#define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \@@ -44,6 +45,8 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); +if (size >XATTR_SIZE_MAX ) + size =XATTR_SIZE_MAX ;nit: size =
max(size, XATTRS_SIZE_MAX);
Thanks, Nikolay. But I can't find the definition of such macro or function. I believe it's only available in kernel, right? Also, you probably meant min() ;-)
Cheers,
Signature · 1 line
Luis
Quoted 35 lines · Luis Henriques
Quoted 22 lines · Nikolay Borisov
Quoted 21 lines · Luis Henriques
The maximum size for extended attribute values is 65536 (
XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning-E2BIG.Cc Darrick J. Wong <[email protected]>Signed-off-by Luis Henriques <[email protected]>--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)src/attr_replace_test.c +1
-0@@ -9,6 +9,7 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <linux/limits.h> Quoted 10 lines
src/attr_replace_test.c int main(int argc, char *argv[]) · line 49
Quoted 8 lines
src/attr_replace_test.c +2
-0#define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \@@ -44,6 +45,8 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); +if (size >XATTR_SIZE_MAX ) + size =XATTR_SIZE_MAX ;nit: size =
max(size, XATTRS_SIZE_MAX);
Quoted 3 lines
Thanks, Nikolay. But I can't find the definition of such macro or function. I believe it's only available in kernel, right? Also, you probably meant
min();-)
Yeah, re min, but it seems there is a MIN/MAX macros provided in <sys/param.h>. Anyway, as mentioned initially this is a minor point :) .
Quoted 3 lines
Cheers,
PATCH v2 1/1 src/attr_replace_test: limit size of extended attribute value
The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning -E2BIG.
--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)
src/attr_replace_test.c +3 -0
@@ -9,6 +9,8 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <sys/param.h> +#include <linux/limits.h> #define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \
@@ -44,6 +46,7 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); + size =MIN (size,XATTR_SIZE_MAX ); value =malloc (size);if (!value)fail ("Failed to allocate memory\n" );
Quoted 7 lines · Luis Henriques
The maximum size for extended attribute values is 65536 (
XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning-E2BIG.Cc Darrick J. Wong <[email protected]>Signed-off-by Luis Henriques <[email protected]>
Looks ok,
--D
Quoted 25 lines
--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)src/attr_replace_test.c +3
-0@@ -9,6 +9,8 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <sys/param.h> +#include <linux/limits.h> #define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \@@ -44,6 +46,7 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); + size =MIN (size,XATTR_SIZE_MAX ); value =malloc (size);if (!value)fail ("Failed to allocate memory\n" );
Quoted 24 lines · Luis Henriques
The maximum size for extended attribute values is 65536 (
XATTR_SIZE_MAX). Since there are filesystems that can set blksize to really big values (CephFS for example has a default of 4M), it's easy to have this test failing with fsetxattr returning-E2BIG.Cc Darrick J. Wong <[email protected]>Signed-off-by Luis Henriques <[email protected]>--- src/attr_replace_test.c | 3 +++ 1 file changed, 3 insertions(+)src/attr_replace_test.c +1
-0@@ -9,6 +9,7 @@#include <sys/types.h> #include <sys/xattr.h> #include <sys/stat.h> +#include <linux/limits.h> #define die () do { perror(""); \ fprintf(stderr, "error at line %d\n", __LINE__); \
src/attr_replace_test.c int main(int argc, char *argv[]) · line 49
Quoted 5 lines
src/attr_replace_test.c +2
-0@@ -44,6 +45,8 @@ int main(int argc, char *argv[]) size = sbuf.st_blksize *3 /4 ;if (!size)fail ("Invalid st_blksize(%ld)\n" , sbuf.st_blksize); +if (size >XATTR_SIZE_MAX ) + size =XATTR_SIZE_MAX ;
Looks good to me (this or the min()/MIN()/whatever version),
--D
Quoted 3 lines
src/attr_replace_test.c +0
-0value =malloc (size);if (!value)fail ("Failed to allocate memory\n" );