Skip to contentSkip to conversation

syscalls/ioctl_loop05: Ensure do zero offset in kernel always

PATCH New Yang Xu 2 participants 7 messages May 8, 2020 – May 12, 2020

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));

if (TST_RET == 0) {
	tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
        SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}

return;
---------------------------------------
this case will broke when using i parameter,
ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed: EINVAL (22)

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
 testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +3 -2
index 6cf701f47..a103aaa94 100644
@@ -5,7 +5,7 @@
  *
  * This is a basic ioctl test about loopdevice.
  *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live
  * loop device dio mode. It needs the backing file also supports
  * dio mode and the lo_offset is aligned with the logical block size.
  *
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
 	if (TST_RET == 0) {
 		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
 		SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-		return;
+		goto zero_offset;
 	}
 	if (TST_ERR == EINVAL)
 		tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
 	else
 		tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");
 
+zero_offset:
 	loopinfo.lo_offset = 0;
 	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
 }
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Quoted 26 lines · Yang Xu

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));

if (TST_RET == 0) {
	tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
         SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}

return;
---------------------------------------
this case will broke when using i parameter,
ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed: EINVAL (22)

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
  testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644

testcases/kernel/syscalls/ioctl/ioctl_loop05.c line 8

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -5,7 +5,7 @@
   *
   * This is a basic ioctl test about loopdevice.
   *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

What does the line changes?

Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -1
   * loop device dio mode. It needs the backing file also supports
   * dio mode and the lo_offset is aligned with the logical block size.
   *
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
  	if (TST_RET == 0) {
  		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
  		SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-		return;

testcases/kernel/syscalls/ioctl/ioctl_loop05.c static void verify_ioctl_loop(void) · line 97

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +2 -0
+		goto zero_offset;
  	}
  	if (TST_ERR == EINVAL)
  		tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
  	else
  		tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");
 
+zero_offset:
  	loopinfo.lo_offset = 0;
  	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Thanks,
Xiao Yang

Quoted 1 line
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
  }
author
#2 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Hi Xiao

Quoted 36 lines · Yang Xu
Quoted 28 lines

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
if (TST_RET == 0) {
????tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly"); ???????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}
return;
---------------------------------------
this case will broke when using i parameter, ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed:
EINVAL (22)

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
? testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++-- ? 1 file changed, 3 insertions(+), 2 deletions(-)

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644
@@ -5,7 +5,7 @@
Quoted 5 lines

?? *
?? * This is a basic ioctl test about loopdevice.
?? *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

Quoted 1 line

What does the line changes?

just a typo, updata->update

Quoted 18 lines
Quoted 18 lines

?? * loop device dio mode. It needs the backing file also supports ?? * dio mode and the lo_offset is aligned with the logical block size. ?? *

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
 ????? if (TST_RET == 0) {
 ????????? tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
 ????????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-??????? return;
+??????? goto zero_offset;
 ????? }
 ????? if (TST_ERR == EINVAL)

????????? tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
????? else
????????? tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");

Quoted 9 lines
Quoted 4 lines

+zero_offset:
????? loopinfo.lo_offset = 0;
????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Yes. IMO, at the beginning or end, they all work well.

Quoted 5 lines

Thanks,
Xiao Yang

Quoted 1 line

? }

#3 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Quoted 17 lines · Yang Xu

Hi Xiao

Quoted 14 lines · Yang Xu
Quoted 13 lines

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));

if (TST_RET == 0) {
    tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
         SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}

return;
---------------------------------------
this case will broke when using i parameter, ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed:
EINVAL (22)

Hi Xu,

Sorry for the late reply.

Without modifying code, we can also fall into this branch by running ioctl_loop05 under btrfs, so could we simple the description of issue?

Quoted 22 lines
Quoted 22 lines
Quoted 15 lines

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
  testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644

testcases/kernel/syscalls/ioctl/ioctl_loop05.c line 8

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -5,7 +5,7 @@
   *
   * This is a basic ioctl test about loopdevice.
   *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

Quoted 2 lines
Quoted 1 line

What does the line changes?

just a typo, updata->update

Sorry for missing the typo.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
   * loop device dio mode. It needs the backing file also supports
   * dio mode and the lo_offset is aligned with the logical block size.
   *
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
      if (TST_RET == 0) {
          tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
          SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-        return;
+        goto zero_offset;
      }
      if (TST_ERR == EINVAL)
          tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as
 expected");
      else
          tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed
 expected EINVAL got");
 
Quoted 9 lines
Quoted 4 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -0
+zero_offset:
      loopinfo.lo_offset = 0;

TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo),
TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Quoted 1 line

Yes. IMO, at the beginning or end, they all work well.

Agreed, but it seems simpler to clear resouce at the beginning of verify_ioctl_loop(), like this:
-----------------------------------

(quoted diff) +0 -0

b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c index 6cf701f47..6c9ea2802 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
...
@@ -57,6 +57,7 @@ static void verify_ioctl_loop(void)

         struct loop_info loopinfo;

         memset(&loopinfo, 0, sizeof(loopinfo));

+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo),
TST_RETVAL_EQ0);

         tst_res(TINFO, "Without setting lo_offset or sizelimit");
         SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);

@@ -91,9 +92,6 @@ static void verify_ioctl_loop(void)
tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as
expected");
else
tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed
expected EINVAL got");
-
- loopinfo.lo_offset = 0;
- TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo),
TST_RETVAL_EQ0);
-----------------------------------

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 5 lines

Thanks,
Xiao Yang

Quoted 1 line
  }

.

author
#4 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Hi Xiao

Quoted 18 lines · Yang Xu
Quoted 17 lines

Hi Xiao

Quoted 14 lines · Yang Xu
Quoted 13 lines

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
if (TST_RET == 0) {
??? tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly"); ???????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}
return;
---------------------------------------
this case will broke when using i parameter, ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed:
EINVAL (22)

Quoted 6 lines

Hi Xu,

Sorry for the late reply.

Without modifying code, we can also fall into this branch by running ioctl_loop05 under btrfs, so could we simple the description of issue?

"make sure zero offset in kernel at the begginning of the test to avoid unknown error when using -i parameter". How about this?

Quoted 76 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
? testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++-- ? 1 file changed, 3 insertions(+), 2 deletions(-)

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644
@@ -5,7 +5,7 @@
Quoted 5 lines

?? *
?? * This is a basic ioctl test about loopdevice.
?? *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

Quoted 2 lines
Quoted 1 line

What does the line changes?

just a typo, updata->update

Sorry for missing the typo.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines

?? * loop device dio mode. It needs the backing file also supports ?? * dio mode and the lo_offset is aligned with the logical block size. ?? *

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
 ????? if (TST_RET == 0) {
 ????????? tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
 ????????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-??????? return;
+??????? goto zero_offset;
 ????? }
 ????? if (TST_ERR == EINVAL)

????????? tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
????? else
????????? tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");

Quoted 9 lines
Quoted 4 lines

+zero_offset:
????? loopinfo.lo_offset = 0;
????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Quoted 1 line

Yes. IMO, at the beginning or end, they all work well.

Agreed, but it seems simpler to clear resouce at the beginning of verify_ioctl_loop(), like this:
-----------------------------------

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -0
index 6cf701f47..6c9ea2802 100644
...
@@ -57,6 +57,7 @@ static void verify_ioctl_loop(void)
 ??????? struct loop_info loopinfo;
 
 ??????? memset(&loopinfo, 0, sizeof(loopinfo));
+?????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), 
 TST_RETVAL_EQ0);
 
 ??????? tst_res(TINFO, "Without setting lo_offset or sizelimit");

??????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);

testcases/kernel/syscalls/ioctl/ioctl_loop05.c static void verify_ioctl_loop(void)

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -4
@@ -91,9 +92,6 @@ static void verify_ioctl_loop(void)
 ??????????????? tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as 
 expected");
 ??????? else
 ??????????????? tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed 
 expected EINVAL got");
-
-?????? loopinfo.lo_offset = 0;
-?????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), 
 TST_RETVAL_EQ0);
-----------------------------------

Yes.

Quoted 11 lines

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 5 lines

Thanks,
Xiao Yang

Quoted 1 line

? }

.

#5 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Quoted 27 lines · Yang Xu

Hi Xiao

Quoted 24 lines · Yang Xu
Quoted 17 lines

Hi Xiao

Quoted 14 lines · Yang Xu
Quoted 13 lines

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));

if (TST_RET == 0) {
    tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
         SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}

return;
---------------------------------------
this case will broke when using i parameter, ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed:
EINVAL (22)

Hi Xu,

Sorry for the late reply.

Without modifying code, we can also fall into this branch by running ioctl_loop05 under btrfs, so could we simple the description of issue?

Hi Xu,

Sorry for the wrong comment.
The debug code is needed, running ioctl_loop05 under btrfs can fall into this branch but doesn't break because btrfs ignores the offset.

Quoted 2 lines

"make sure zero offset in kernel at the begginning of the test to avoid unknown error when using -i parameter". How about this?

Is "in kernel" necessary? Other than that the description looks good.

Thanks,
Xiao Yang

Quoted 101 lines
Quoted 77 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
  testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644

testcases/kernel/syscalls/ioctl/ioctl_loop05.c line 8

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -5,7 +5,7 @@
   *
   * This is a basic ioctl test about loopdevice.
   *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

Quoted 2 lines
Quoted 1 line

What does the line changes?

just a typo, updata->update

Sorry for missing the typo.

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
   * loop device dio mode. It needs the backing file also supports
   * dio mode and the lo_offset is aligned with the logical block

size.
*

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
      if (TST_RET == 0) {
          tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
          SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-        return;
+        goto zero_offset;
      }
      if (TST_ERR == EINVAL)
          tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as
 expected");
      else
          tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed
 expected EINVAL got");
 
Quoted 9 lines
Quoted 4 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -0
+zero_offset:
      loopinfo.lo_offset = 0;

TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo),
TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Quoted 1 line

Yes. IMO, at the beginning or end, they all work well.

Agreed, but it seems simpler to clear resouce at the beginning of verify_ioctl_loop(), like this:
-----------------------------------

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -0
index 6cf701f47..6c9ea2802 100644
...
@@ -57,6 +57,7 @@ static void verify_ioctl_loop(void)
        struct loop_info loopinfo;
 
        memset(&loopinfo, 0, sizeof(loopinfo));
+       TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo),
 TST_RETVAL_EQ0);
 
        tst_res(TINFO, "Without setting lo_offset or sizelimit");
        SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);

testcases/kernel/syscalls/ioctl/ioctl_loop05.c static void verify_ioctl_loop(void)

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -4
@@ -91,9 +92,6 @@ static void verify_ioctl_loop(void)
                tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as
 expected");
        else
                tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed
 expected EINVAL got");
-
-       loopinfo.lo_offset = 0;
-       TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo),
 TST_RETVAL_EQ0);
-----------------------------------

Yes.

Quoted 11 lines

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 5 lines

Thanks,
Xiao Yang

Quoted 1 line
  }

.

.

author
#6 lore raw

PATCH 1/1 syscalls/ioctl_loop05: Ensure do zero offset in kernel always

Hi Xiao

Quoted 30 lines · Yang Xu
Quoted 27 lines

Hi Xiao

Quoted 24 lines · Yang Xu
Quoted 17 lines

Hi Xiao

Quoted 14 lines · Yang Xu
Quoted 13 lines

Currently, we use return instead of zero_offset. I debug this code (early return, ext4 filesystem)as below:
---------------------------------------
TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
if (TST_RET == 0) {
??? tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded unexpectedly"); ???????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
}
return;
---------------------------------------
this case will broke when using i parameter, ioctl_loop05.c:62: BROK: ioctl(3,LOOP_SET_DIRECT_IO,...) failed:
EINVAL (22)

Hi Xu,

Sorry for the late reply.

Without modifying code, we can also fall into this branch by running ioctl_loop05 under btrfs, so could we simple the description of issue?

Hi Xu,

Quoted 7 lines

Sorry for the wrong comment.
The debug code is needed, running ioctl_loop05 under btrfs can fall into this branch but doesn't break because btrfs ignores the offset.

Quoted 2 lines

"make sure zero offset in kernel at the begginning of the test to avoid unknown error when using -i parameter". How about this?

Is "in kernel" necessary?? Other than that the description looks good.

I think it is necessary because it wants to set zero status in kernel loop info struct but not userspace loopinfo struct(In userspace, we have zero loopinfo struct). so "in kernel" is more clear.
"make sure set zero offset in kernel loopinfo struct at the beginning of the test to avoid unknown error when using -i parameter "

Best Regards
Yang Xu

Quoted 105 lines

Thanks,
Xiao Yang

Quoted 101 lines
Quoted 79 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines

It seems the last test affected this test, so I think we should use goto instead of return. Also including a typo, updata->update.

---
? testcases/kernel/syscalls/ioctl/ioctl_loop05.c | 5 +++-- ? 1 file changed, 3 insertions(+), 2 deletions(-)

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
index 6cf701f47..a103aaa94 100644
@@ -5,7 +5,7 @@
Quoted 5 lines

?? *
?? * This is a basic ioctl test about loopdevice.
?? *
- * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * It is designed to test LOOP_SET_DIRECT_IO can update a live

Hi Xu,

Quoted 2 lines
Quoted 1 line

What does the line changes?

just a typo, updata->update

Sorry for missing the typo.

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines

?? * loop device dio mode. It needs the backing file also supports ?? * dio mode and the lo_offset is aligned with the logical block size.
?? *

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -1
@@ -85,13 +85,14 @@ static void verify_ioctl_loop(void)
 ????? if (TST_RET == 0) {
 ????????? tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
 ????????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
-??????? return;
+??????? goto zero_offset;
 ????? }
 ????? if (TST_ERR == EINVAL)

????????? tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
????? else
????????? tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");

Quoted 9 lines
Quoted 4 lines

+zero_offset:
????? loopinfo.lo_offset = 0;
????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);

You have cleared the struct loopinfo at the beginning of verify_ioctl_loop(), so could we just drop loopinfo.lo_offset = 0 and move 'TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS,&loopinfo), TST_RETVAL_EQ0);' to the beginning?

Quoted 1 line

Yes. IMO, at the beginning or end, they all work well.

Agreed, but it seems simpler to clear resouce at the beginning of verify_ioctl_loop(), like this:
-----------------------------------

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +1 -0
index 6cf701f47..6c9ea2802 100644
...
@@ -57,6 +57,7 @@ static void verify_ioctl_loop(void)
 ??????? struct loop_info loopinfo;
 
 ??????? memset(&loopinfo, 0, sizeof(loopinfo));
+?????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo),
 TST_RETVAL_EQ0);
 
 ??????? tst_res(TINFO, "Without setting lo_offset or sizelimit");

??????? SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);

testcases/kernel/syscalls/ioctl/ioctl_loop05.c +0 -0
@@ -91,9 +92,6 @@ static void verify_ioctl_loop(void)

??????????????? tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");

Quoted 8 lines

??????? else
??????????????? tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");
-
-?????? loopinfo.lo_offset = 0;
-?????? TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
-----------------------------------

Yes.

Quoted 11 lines

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 5 lines

Thanks,
Xiao Yang

Quoted 1 line

? }

.

.