Skip to contentSkip to conversation

lib/tst_device.c: Make sure all loop deivces fot test are detached

PATCH New Xiao Yang 2 participants 5 messages Sep 12, 2018 – Sep 13, 2018 Library code

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 lib/tst_device.c: Make sure all loop deivces fot test are detached

Running statx05 by runltp without -b option every time attached a loop device but didn't detach it, as below:
------------------------------------------------------------------
...
tst_device.c:230: INFO: Using test device LTP_DEV='/dev/loop0' tst_device.c:268: INFO: Skipping $LTP_DEV size 256MB, requested size 512MB tst_device.c:83: INFO: Found free device '/dev/loop1'
tst_mkfs.c:83: INFO: Formatting /dev/loop1 with ext4 opts='' extra opts='-O encrypt'
...
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop1 0 0 0 0 /tmp/ltp-gsrcFAkGpZ/Wka3bp/test_dev.img (deleted) 0
------------------------------------------------------------------

runltp created a block device with default 256M size by attaching a free loop device and set LTP_DEV variable, but statx05 needed a 512M block device, so tst_acquire_device__() in setup skipped the $LTP_DEV device and created another block device with 512M size by attaching another free loop device. Unfortunately, tst_release_device() in cleanup cannot detach the 512M block device due to the defined LTP_DEV.

We should just skip the detach in tst_release_device() when LTP_DEV variable is set and device_acquired flag is not set.

---
 lib/tst_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_device.c +1 -1
index 463743443..23c99dba2 100644
@@ -313,7 +313,7 @@ int tst_release_device(const char *dev)
 {
 	int ret;
 
-	if (getenv("LTP_DEV"))
+	if (getenv("LTP_DEV") && !device_acquired)
 		return 0;
 
 	/*
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 lib/tst_device.c: Make sure all loop deivces fot test are detached

Hi!

Quoted 13 lines

Running statx05 by runltp without -b option every time attached a loop device but didn't detach it, as below:
------------------------------------------------------------------
...
tst_device.c:230: INFO: Using test device LTP_DEV='/dev/loop0' tst_device.c:268: INFO: Skipping $LTP_DEV size 256MB, requested size 512MB tst_device.c:83: INFO: Found free device '/dev/loop1'
tst_mkfs.c:83: INFO: Formatting /dev/loop1 with ext4 opts='' extra opts='-O encrypt'
...
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop1 0 0 0 0 /tmp/ltp-gsrcFAkGpZ/Wka3bp/test_dev.img (deleted) 0
------------------------------------------------------------------

Quoted 6 lines

runltp created a block device with default 256M size by attaching a free loop device and set LTP_DEV variable, but statx05 needed a 512M block device, so tst_acquire_device__() in setup skipped the $LTP_DEV device and created another block device with 512M size by attaching another free loop device. Unfortunately, tst_release_device() in cleanup cannot detach the 512M block device due to the defined LTP_DEV.

Btw his has been fixed for statx since:

commit e583eacf3c9781116c19dec4c7e8c0aa4ed01ed5

Author: Cyril Hrubis <[email protected]>
Date:   Tue Sep 11 17:27:43 2018 +0200

syscalls/statx05: Fix test on ppc64le

But yes apart from that the test library is still broken.

Quoted 13 lines

We should just skip the detach in tst_release_device() when LTP_DEV variable is set and device_acquired flag is not set.

---
 lib/tst_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_device.c +0 -0
index 463743443..23c99dba2 100644

lib/tst_device.c int tst_release_device(const char *dev) · line 317

Quoted 6 lines
lib/tst_device.c +1 -1
@@ -313,7 +313,7 @@ int tst_release_device(const char *dev)
 {
 	int ret;
 
-	if (getenv("LTP_DEV"))
+	if (getenv("LTP_DEV") && !device_acquired)
 		return 0;

I guess that this really should be just:

	if (!device_acquired)
		return 0;

I will double check and test it later today.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 lib/tst_device.c: Make sure all loop deivces fot test are detached

Quoted 47 lines · Cyril Hrubis

Hi!

Quoted 13 lines

Running statx05 by runltp without -b option every time attached a loop device but didn't detach it, as below:
------------------------------------------------------------------
...
tst_device.c:230: INFO: Using test device LTP_DEV='/dev/loop0' tst_device.c:268: INFO: Skipping $LTP_DEV size 256MB, requested size 512MB tst_device.c:83: INFO: Found free device '/dev/loop1'
tst_mkfs.c:83: INFO: Formatting /dev/loop1 with ext4 opts='' extra opts='-O encrypt'
...
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop1 0 0 0 0 /tmp/ltp-gsrcFAkGpZ/Wka3bp/test_dev.img (deleted) 0
------------------------------------------------------------------

Quoted 6 lines

runltp created a block device with default 256M size by attaching a free loop device and set LTP_DEV variable, but statx05 needed a 512M block device, so tst_acquire_device__() in setup skipped the $LTP_DEV device and created another block device with 512M size by attaching another free loop device. Unfortunately, tst_release_device() in cleanup cannot detach the 512M block device due to the defined LTP_DEV.

Btw his has been fixed for statx since:

commit e583eacf3c9781116c19dec4c7e8c0aa4ed01ed5

Author: Cyril Hrubis<[email protected]>
Date:   Tue Sep 11 17:27:43 2018 +0200

syscalls/statx05: Fix test on ppc64le

But yes apart from that the test library is still broken.

Quoted 16 lines

We should just skip the detach in tst_release_device() when LTP_DEV variable is set and device_acquired flag is not set.

---
  lib/tst_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_device.c +0 -0
index 463743443..23c99dba2 100644
@@ -313,7 +313,7 @@ int tst_release_device(const char *dev)
  {
  	int ret;
 
Quoted 7 lines

lib/tst_device.c int tst_release_device(const char *dev) · line 317

Quoted 3 lines
lib/tst_device.c +1 -1
-	if (getenv("LTP_DEV"))
+	if (getenv("LTP_DEV")&&  !device_acquired)
  		return 0;

I guess that this really should be just:

	if (!device_acquired)
		return 0;

Hi Cyril,

Thanks for yor review.
It seems better to me, and i will send the v2 patch.

Thanks,
Xiao Yang

Quoted 2 lines

I will double check and test it later today.

author
#3 lore raw

PATCH v2 1/1 lib/tst_device.c: Make sure all loop deivces fot test are detached

In reply to Cyril Hrubis

Before commit e583eac in LTP, running statx05 by runltp without -b option every time attached a loop device but didn't detach it, as below:
------------------------------------------------------------------
...
tst_device.c:230: INFO: Using test device LTP_DEV='/dev/loop0' tst_device.c:268: INFO: Skipping $LTP_DEV size 256MB, requested size 512MB tst_device.c:83: INFO: Found free device '/dev/loop1'
tst_mkfs.c:83: INFO: Formatting /dev/loop1 with ext4 opts='' extra opts='-O encrypt'
...
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop1 0 0 0 0 /tmp/ltp-gsrcFAkGpZ/Wka3bp/test_dev.img (deleted) 0
------------------------------------------------------------------

This issue has been fixed for statx since commit e583eac in LTP, but the test library is still broken.

runltp without -b option creates a block device with default 256M size by attaching a free loop device and sets LTP_DEV variable, and if some tests need a 512M(bigger than 256M) block device by specifying .dev_min_size, tst_acquire_device__() in setup will skip the $LTP_DEV device and create another block device with 512M size by attaching another free loop device. Unfortunately, tst_release_device() in cleanup will not detach the 512M block device due to the defined LTP_DEV.

We should just skip the detach in tst_release_device() when device_acquired flag is not set.

---
 lib/tst_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_device.c +1 -1
index 4637434431..fd4e277c78 100644
@@ -313,7 +313,7 @@ int tst_release_device(const char *dev)
 {
 	int ret;
 
-	if (getenv("LTP_DEV"))
+	if (!device_acquired)
 		return 0;
 
 	/*
Signature · 1 line
2.17.0
#4 lore raw

PATCH v2 1/1 lib/tst_device.c: Make sure all loop deivces fot test are detached

Hi!
Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]