syscalls/fallocate[4, 5]: Fix failure when using old mkfs.btrfs
PATCH 1/1 syscalls/fallocate[4, 5]: Fix failure when using old mkfs.btrfs
We always got the following error when using mkfs.btrfs(v0.20-rc1) on RHEL6.9GA.
---------------------------------------------------------------------------
...
tst_mkfs.c:83: INFO: Formatting /dev/loop0 with btrfs opts='' extra opts='' error checking /dev/loop0 mount status
tst_mkfs.c:94: BROK: mkfs.btrfs:1: tst_test.c failed with 693
---------------------------------------------------------------------------
After just calling LOOP_SET_FD to set up loopdev, newer mkfs.btrfs can get associated filename by backing_file successfully. However older one cannot get associated filename by LOOP_GET_STATUS which is replaced by backing_file since btrfs-progs v3.12. So we call LOOP_SET_FD and LOOP_SET_STATUS to set up loopdev when using all kinds of mkfs.btrfs.
The backing_file was produced in kernel(since v2.6.37):
'ee86273062cb("loop: add some basic read-only sysfs attributes")'
The backing_file began to be used by mkfs.btrfs on btrfs_progs(v3.12):
'abdb0ced0123("Btrfs-progs: fix resolving of loop devices")'
--- lib/tst_device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
lib/tst_device.c +16 -0
@@ -134,6 +134,7 @@ static int find_free_loopdev(void)static int attach_device (const char *dev,const char *file) {int dev_fd, file_fd; +struct loop_info loopinfo; dev_fd =open (dev,O_RDWR );if (dev_fd <0 ) {
@@ -156,6 +157,21 @@ static int attach_device(const char *dev, const char *file)return 1 ; } +/* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get +* associated filename, so we need to set up the device by calling +* LOOP_SET_FD and LOOP_SET_STATUS. +*/ +memset (&loopinfo,0 ,sizeof (loopinfo)); +strcpy ((char *)loopinfo.lo_name, file); + +if (ioctl (dev_fd,LOOP_SET_STATUS , &loopinfo)) { +close (dev_fd); +close (file_fd); +tst_resm (TWARN |TERRNO , +"ioctl(%s, LOOP_SET_STATUS, %s) failed" , dev, file); +return 1 ; + } +close (dev_fd);close (file_fd);return 0 ;
Signature · 1 line
1.8.3.1
PATCH 1/1 syscalls/fallocate[4, 5]: Fix failure when using old mkfs.btrfs
Hi!
Quoted 8 lines
static int
attach_device(const char *dev, const char *file){lib/tst_device.c +1
-0int dev_fd, file_fd; +struct loop_info loopinfo; dev_fd =open (dev,O_RDWR );if (dev_fd <0 ) {
lib/tst_device.c static int attach_device(const char *dev, const char *file) · line 165
Quoted 9 lines
lib/tst_device.c +6
-0@@ -156,6 +157,21 @@ static int attach_device(const char *dev, const char *file)return 1 ; } +/* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get +* associated filename, so we need to set up the device by calling +* LOOP_SET_FD and LOOP_SET_STATUS. +*/ +memset (&loopinfo,0 ,sizeof (loopinfo)); +strcpy ((char *)loopinfo.lo_name, file);
^
Why the cast here, as far as I can tell the lo_name is just array of chars which should be char * pointer compatible.
lib/tst_device.c static int attach_device(const char *dev, const char *file) · line 177
Quoted 11 lines
lib/tst_device.c +8
-0+if (ioctl (dev_fd,LOOP_SET_STATUS , &loopinfo)) { +close (dev_fd); +close (file_fd); +tst_resm (TWARN |TERRNO , +"ioctl(%s, LOOP_SET_STATUS, %s) failed" , dev, file); +return 1 ; + } +close (dev_fd);close (file_fd);return 0 ;
Otherwise it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 lib/tst_device.c: Fix failure when using old mkfs.btrfs
We always got the following error when using mkfs.btrfs(v0.20-rc1) on RHEL6.9GA. For example:
---------------------------------------------------------------------------
./fallocate04
...
tst_mkfs.c:83: INFO: Formatting /dev/loop0 with btrfs opts='' extra opts='' error checking /dev/loop0 mount status
tst_mkfs.c:94: BROK: mkfs.btrfs:1: tst_test.c failed with 693
---------------------------------------------------------------------------
After just calling LOOP_SET_FD to set up loopdev, newer mkfs.btrfs can get associated filename by backing_file successfully. However older one cannot get associated filename by LOOP_GET_STATUS which is replaced by backing_file since btrfs-progs v3.12. So we call LOOP_SET_FD and LOOP_SET_STATUS to set up loopdev when using all kinds of mkfs.btrfs.
The backing_file was produced in kernel(since v2.6.37):
'ee86273062cb("loop: add some basic read-only sysfs attributes")'
The backing_file began to be used by mkfs.btrfs on btrfs_progs(v3.12):
'abdb0ced0123("Btrfs-progs: fix resolving of loop devices")'
--- lib/tst_device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
lib/tst_device.c +16 -0
@@ -134,6 +134,7 @@ static int find_free_loopdev(void)static int attach_device (const char *dev,const char *file) {int dev_fd, file_fd; +struct loop_info loopinfo; dev_fd =open (dev,O_RDWR );if (dev_fd <0 ) {
@@ -156,6 +157,21 @@ static int attach_device(const char *dev, const char *file)return 1 ; } +/* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get +* associated filename, so we need to set up the device by calling +* LOOP_SET_FD and LOOP_SET_STATUS. +*/ +memset (&loopinfo,0 ,sizeof (loopinfo)); +strcpy (loopinfo.lo_name, file); + +if (ioctl (dev_fd,LOOP_SET_STATUS , &loopinfo)) { +close (dev_fd); +close (file_fd); +tst_resm (TWARN |TERRNO , +"ioctl(%s, LOOP_SET_STATUS, %s) failed" , dev, file); +return 1 ; + } +close (dev_fd);close (file_fd);return 0 ;
Signature · 1 line
1.8.3.1
PATCH v2 1/1 lib/tst_device.c: Fix failure when using old mkfs.btrfs
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]