Skip to contentSkip to conversation

add loop ioctl test

PATCH Superseded Yang Xu 4 participants 58 messages Apr 2, 2020 – Apr 28, 2020 Library code

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

cover add loop ioctl test

This is a set of test for the loop ioctl.

Yang Xu (10):
lapi: Add a configure check and fallback for loop ioctl and flag syscalls/ioctl:add common c file for loop ioctl syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN
test
syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test syscalls/ioctl_loop07: Add dio with logic block size error test syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test

 configure.ac                                  |   1 +
 include/lapi/loop.h                           |  35 +++++
 runtest/syscalls                              |  10 +-
 testcases/kernel/syscalls/ioctl/.gitignore    |   8 +
 testcases/kernel/syscalls/ioctl/Makefile      |   3 +
 .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 +++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop02.c      | 148 ++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop03.c      |  76 +++++++++
 .../kernel/syscalls/ioctl/ioctl_loop04.c      |  97 ++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 120 ++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop06.c      |  90 +++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop07.c      |  85 ++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop08.c      |  96 ++++++++++++
 .../syscalls/ioctl/ioctl_loop_support.c       |  74 +++++++++
 .../syscalls/ioctl/ioctl_loop_support.h       |  14 ++
 15 files changed, 983 insertions(+), 1 deletion(-)
 create mode 100644 include/lapi/loop.h
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop03.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop04.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop06.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop08.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

---
 configure.ac        |  1 +
 include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 include/lapi/loop.h
configure.ac +1 -0
index e1069b57e..e088cb564 100644
@@ -50,6 +50,7 @@ AC_CHECK_HEADERS([ \
     linux/if_ether.h \
     linux/if_packet.h \
     linux/keyctl.h \
+    linux/loop.h \
     linux/mempolicy.h \
     linux/module.h \
     linux/netlink.h \
include/lapi/loop.h new file +35 -0
new file mode 100644
index 000000000..bc6d9950d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
Signature · 1 line
2.23.0
#2 lore raw

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

Hi!

Quoted 11 lines
---
 configure.ac        |  1 +
 include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 include/lapi/loop.h
configure.ac +0 -0
index e1069b57e..e088cb564 100644

configure.ac AC_CHECK_HEADERS([ \ · line 53

Quoted 4 lines
configure.ac +1 -0
@@ -50,6 +50,7 @@ AC_CHECK_HEADERS([ \
     linux/if_ether.h \
     linux/if_packet.h \
     linux/keyctl.h \
+    linux/loop.h \

I do wonder if there is actually a distrbution without the linux/loop.h header, have you seen one?

Quoted 52 lines
configure.ac +0 -0
     linux/mempolicy.h \
     linux/module.h \
     linux/netlink.h \
include/lapi/loop.h new file +35 -0
new file mode 100644
index 000000000..bc6d9950d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

Hi Cyril

Thanks for your review.

Quoted 7 lines

Hi!

Quoted 6 lines
---
  configure.ac        |  1 +
  include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
  2 files changed, 36 insertions(+)

create mode 100644 include/lapi/loop.h

Quoted 13 lines

configure.ac AC_CHECK_HEADERS([ \ · line 53

Quoted 9 lines
configure.ac +1 -0
index e1069b57e..e088cb564 100644
@@ -50,6 +50,7 @@ AC_CHECK_HEADERS([ \
      linux/if_ether.h \
      linux/if_packet.h \
      linux/keyctl.h \
+    linux/loop.h \

I do wonder if there is actually a distrbution without the linux/loop.h header, have you seen one?

No, I don't see this distribution. We can remove this.

Quoted 53 lines
Quoted 52 lines
configure.ac +0 -0
      linux/mempolicy.h \
      linux/module.h \
      linux/netlink.h \
include/lapi/loop.h new file +35 -0
new file mode 100644
index 000000000..bc6d9950d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

In reply to Yang Xu

Hi,

Quoted 25 lines · Yang Xu
---
 configure.ac        |  1 +
 include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 include/lapi/loop.h
configure.ac +1 -0
index e1069b57e..e088cb564 100644
@@ -50,6 +50,7 @@ AC_CHECK_HEADERS([ \
     linux/if_ether.h \
     linux/if_packet.h \
     linux/keyctl.h \
+    linux/loop.h \
     linux/mempolicy.h \
     linux/module.h \
     linux/netlink.h \
include/lapi/loop.h new file +0 -0
new file mode 100644
index 000000000..bc6d9950d

include/lapi/loop.h line 3

Quoted 3 lines
include/lapi/loop.h new file +3 -0
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.

Here's a little legal issue for LTP: "GPL" and "All rights reserved" are mutually exclusive. Those two lines are effectively saying that your code is both open-source and proprietary at the same time. Please pick one, or the other. It can't be both.

Quoted 33 lines
include/lapi/loop.h new file +32 -0
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#5 lore raw

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

Hi!

Quoted 8 lines

include/lapi/loop.h line 3

Quoted 3 lines
include/lapi/loop.h new file +3 -0
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.

Here's a little legal issue for LTP: "GPL" and "All rights reserved" are mutually exclusive. Those two lines are effectively saying that your code is both open-source and proprietary at the same time. Please pick one, or the other. It can't be both.

Actually the "All rights reserved" should not have any legal effects. The Buenos Aires Convention required that text for estabilishing copyright which you would have needed before you could license your work under GPL. However it's long obsolete now and has no legal effect as far as I can tell.

Btw "All rights reserved" is part of the BSD MIT license because of these reasons.

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

PATCH 1/10 lapi: Add a configure check and fallback for loop ioctl and flag

In reply to Martin Doucha

Hi Martin

Quoted 28 lines

Hi,

Quoted 25 lines · Yang Xu
---
  configure.ac        |  1 +
  include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
  2 files changed, 36 insertions(+)

create mode 100644 include/lapi/loop.h

configure.ac +1 -0
index e1069b57e..e088cb564 100644
@@ -50,6 +50,7 @@ AC_CHECK_HEADERS([ \
      linux/if_ether.h \
      linux/if_packet.h \
      linux/keyctl.h \
+    linux/loop.h \
      linux/mempolicy.h \
      linux/module.h \
      linux/netlink.h \
include/lapi/loop.h new file +0 -0
new file mode 100644
index 000000000..bc6d9950d
@@ -0,0 +1,35 @@
Quoted 8 lines

include/lapi/loop.h line 3

Quoted 3 lines
include/lapi/loop.h new file +3 -0
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.

Here's a little legal issue for LTP: "GPL" and "All rights reserved" are mutually exclusive. Those two lines are effectively saying that your code is both open-source and proprietary at the same time. Please pick one, or the other. It can't be both.

I never think this is a problem before. ltp has some cases also using this style. Also, xfstests have many cases like this. Even kernel, it also has the two line. Is it a problem?

Best Regards
Yang Xu

Quoted 36 lines
Quoted 34 lines
include/lapi/loop.h new file +32 -0
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
author
#7 lore raw

PATCH 2/10 syscalls/ioctl:add common c file for loop ioctl

In reply to Yang Xu
---
 testcases/kernel/syscalls/ioctl/Makefile      |  3 +
 .../syscalls/ioctl/ioctl_loop_support.c       | 74 +++++++++++++++++++
 .../syscalls/ioctl/ioctl_loop_support.h       | 14 ++++
 3 files changed, 91 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h
testcases/kernel/syscalls/ioctl/Makefile +3 -0
index c2ff6c8e7..05a75d1b4 100644
@@ -7,6 +7,9 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		+= test_ioctl
 
+MAKE_TARGETS            := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/ioctl_loop[0-9]*.c))
+$(MAKE_TARGETS): %: ioctl_loop_support.o
+
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= ioctl02
 endif
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +74 -0

74 lines not on this page · raw message

testcases/kernel/syscalls/ioctl/ioctl_loop_support.h new file +14 -0
new file mode 100644
index 000000000..44445af8a
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef IOCTL_LOOP_H
+#define IOCTL_lOOP_H
+#include <linux/loop.h>
+void check_sys_value(char *path, int setvalue);
+void check_sys_string(char *path, char *setmessage);
+void safe_set_status(int dev_fd, struct loop_info loopinfo);
+void safe_set_status64(int dev_fd, struct loop_info64 loopinfo);
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message);
+#endif
Signature · 1 line
2.23.0
#8 lore raw

PATCH 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi!

Quoted 14 lines
---
 testcases/kernel/syscalls/ioctl/Makefile      |  3 +
 .../syscalls/ioctl/ioctl_loop_support.c       | 74 +++++++++++++++++++
 .../syscalls/ioctl/ioctl_loop_support.h       | 14 ++++
 3 files changed, 91 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h
testcases/kernel/syscalls/ioctl/Makefile +0 -0
index c2ff6c8e7..05a75d1b4 100644

testcases/kernel/syscalls/ioctl/Makefile include $(top_srcdir)/include/mk/testcases.mk · line 11

Quoted 5 lines
testcases/kernel/syscalls/ioctl/Makefile +2 -0
@@ -7,6 +7,9 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		+= test_ioctl
 
+MAKE_TARGETS            := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/ioctl_loop[0-9]*.c))
+$(MAKE_TARGETS): %: ioctl_loop_support.o

I guess that we should use anything else than MAKE_TARGETS because changing that variable will disable rest of the ioctl tests from build right?

As this only expresses dependency on the object file we should use any variable name that is not used by the test library itself.

Quoted 45 lines
testcases/kernel/syscalls/ioctl/Makefile +0 -0
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= ioctl02
 endif
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +36 -0
new file mode 100644
index 000000000..4099bd364
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+	int getvalue;
+
+	SAFE_FILE_SCANF(path, "%d", &getvalue);
+	if (setvalue == getvalue)
+		tst_res(TPASS, "%s value is %d", path, setvalue);
+	else
+		tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue);
+}
+
+void check_sys_string(char *path, char *setmessage)
+{
+	char getmessage[1024];
+
+	SAFE_FILE_SCANF(path, "%s", getmessage);
+	if (strcmp(setmessage, getmessage))
+		tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage);
+	else
+		tst_res(TPASS, "%s string is %s", path, getmessage);
+}
+
+void safe_set_status(int dev_fd, struct loop_info loopinfo)
+{
+	int sleep_us = 4096;
+	int ret = 0;
+

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 46

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +10 -0
+	/*
+	 * It may have dirty page, so loop dirver may get EAGAIN error
+	 * when we use different offset or sizelimit.
+	 */
+	ret = ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo);
+	while (ret != 0 && errno == EAGAIN && sleep_us < 100000) {
+		ret = ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo);
+		usleep(sleep_us);
+		sleep_us *= 2;
+	}

TBROK here if we failed to set the status?

Also we should use the TST_RETRY_FUNC() instead because that one uses the timeout multiplier environment variable.

Quoted 7 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +7 -0
+}
+
+void safe_set_status64(int dev_fd, struct loop_info64 loopinfo)
+{
+	int sleep_us = 4096;
+	int ret = 0;
+

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 63

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +10 -0
+	/*
+	 * It may have dirty page, so loop dirver may get EAGAIN error
+	 * when we use different offset or sizelimit.
+	 */
+	ret = ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo);
+	while (ret != 0 && errno == EAGAIN && sleep_us < 100000) {
+		ret = ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo);
+		usleep(sleep_us);
+		sleep_us *= 2;
+	}

Here as well.

Quoted 39 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +11 -0
+}
+
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message)
+{
+	int ret = 0;
+
+	ret = ioctl(dev_fd, ioctl_flag, value);
+	if (ret && errno == EINVAL)
+		tst_brk(TCONF, "Current environment doesn't support this flag(%s)",
+				message);
+}
testcases/kernel/syscalls/ioctl/ioctl_loop_support.h new file +14 -0
new file mode 100644
index 000000000..44445af8a
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef IOCTL_LOOP_H
+#define IOCTL_lOOP_H
+#include <linux/loop.h>
+void check_sys_value(char *path, int setvalue);
+void check_sys_string(char *path, char *setmessage);
+void safe_set_status(int dev_fd, struct loop_info loopinfo);
+void safe_set_status64(int dev_fd, struct loop_info64 loopinfo);
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message);
+#endif
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#9 lore raw

PATCH 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 16 lines

Hi!

Quoted 15 lines
---
  testcases/kernel/syscalls/ioctl/Makefile      |  3 +
  .../syscalls/ioctl/ioctl_loop_support.c       | 74 +++++++++++++++++++
  .../syscalls/ioctl/ioctl_loop_support.h       | 14 ++++
  3 files changed, 91 insertions(+)

create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h

testcases/kernel/syscalls/ioctl/Makefile +0 -0
index c2ff6c8e7..05a75d1b4 100644
@@ -7,6 +7,9 @@ include $(top_srcdir)/include/mk/testcases.mk
 
Quoted 9 lines

testcases/kernel/syscalls/ioctl/Makefile include $(top_srcdir)/include/mk/testcases.mk · line 11

Quoted 4 lines
testcases/kernel/syscalls/ioctl/Makefile +2 -0
  INSTALL_TARGETS		+= test_ioctl
 
+MAKE_TARGETS            := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/ioctl_loop[0-9]*.c))
+$(MAKE_TARGETS): %: ioctl_loop_support.o

I guess that we should use anything else than MAKE_TARGETS because changing that variable will disable rest of the ioctl tests from build right?

Yes, you are right.

Quoted 2 lines

As this only expresses dependency on the object file we should use any variable name that is not used by the test library itself.

I think the following code maybe ok.
+FILTER_OUT_MAKE_TARGETS := ioctl_loop_support
+
+LOOP_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard
$(abs_srcdir)/ioctl_loop*[0-9].c))
+$(LOOP_TARGETS): %: ioctl_loop_support.o

Quoted 50 lines
Quoted 50 lines
testcases/kernel/syscalls/ioctl/Makefile +0 -0
  ifeq ($(ANDROID),1)
  FILTER_OUT_MAKE_TARGETS	+= ioctl02
  endif
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +40 -0
new file mode 100644
index 000000000..4099bd364
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+	int getvalue;
+
+	SAFE_FILE_SCANF(path, "%d", &getvalue);
+	if (setvalue == getvalue)
+		tst_res(TPASS, "%s value is %d", path, setvalue);
+	else
+		tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue);
+}
+
+void check_sys_string(char *path, char *setmessage)
+{
+	char getmessage[1024];
+
+	SAFE_FILE_SCANF(path, "%s", getmessage);
+	if (strcmp(setmessage, getmessage))
+		tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage);
+	else
+		tst_res(TPASS, "%s string is %s", path, getmessage);
+}
+
+void safe_set_status(int dev_fd, struct loop_info loopinfo)
+{
+	int sleep_us = 4096;
+	int ret = 0;
+
+	/*
+	 * It may have dirty page, so loop dirver may get EAGAIN error
+	 * when we use different offset or sizelimit.
+	 */
Quoted 8 lines

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 46

Quoted 6 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +6 -0
+	ret = ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo);
+	while (ret != 0 && errno == EAGAIN && sleep_us < 100000) {
+		ret = ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo);
+		usleep(sleep_us);
+		sleep_us *= 2;
+	}

TBROK here if we failed to set the status?

Yes.

Quoted 3 lines

Also we should use the TST_RETRY_FUNC() instead because that one uses the timeout multiplier environment variable.

Ok, I will use TST_RETRY_FUNC macro.

Quoted 62 lines
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +7 -0
+}
+
+void safe_set_status64(int dev_fd, struct loop_info64 loopinfo)
+{
+	int sleep_us = 4096;
+	int ret = 0;
+

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 63

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +10 -0
+	/*
+	 * It may have dirty page, so loop dirver may get EAGAIN error
+	 * when we use different offset or sizelimit.
+	 */
+	ret = ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo);
+	while (ret != 0 && errno == EAGAIN && sleep_us < 100000) {
+		ret = ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo);
+		usleep(sleep_us);
+		sleep_us *= 2;
+	}

Here as well.

Quoted 39 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +11 -0
+}
+
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message)
+{
+	int ret = 0;
+
+	ret = ioctl(dev_fd, ioctl_flag, value);
+	if (ret && errno == EINVAL)
+		tst_brk(TCONF, "Current environment doesn't support this flag(%s)",
+				message);
+}
testcases/kernel/syscalls/ioctl/ioctl_loop_support.h new file +14 -0
new file mode 100644
index 000000000..44445af8a
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef IOCTL_LOOP_H
+#define IOCTL_lOOP_H
+#include <linux/loop.h>
+void check_sys_value(char *path, int setvalue);
+void check_sys_string(char *path, char *setmessage);
+void safe_set_status(int dev_fd, struct loop_info loopinfo);
+void safe_set_status64(int dev_fd, struct loop_info64 loopinfo);
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message);
+#endif
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#10 lore raw

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

In reply to Yang Xu

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---
 runtest/syscalls                              |   3 +-
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 ++++++++++++++++++
 3 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
runtest/syscalls +2 -1
index 777f0ac6a..7fd67450e 100644
@@ -524,10 +524,11 @@ ioctl03      ioctl03
 ioctl04      ioctl04
 ioctl05      ioctl05
 ioctl06      ioctl06
-
 ioctl07      ioctl07
 ioctl08      ioctl08
 
+ioctl_loop01 ioctl_loop01
+
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
 ioctl_ns03 ioctl_ns03
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@
 /ioctl06
 /ioctl07
 /ioctl08
+/ioctl_loop01
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +127 -0

127 lines not on this page · raw message

Signature · 1 line
2.23.0
#11 lore raw

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

Hi!

Quoted 94 lines

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---
 runtest/syscalls                              |   3 +-
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 ++++++++++++++++++
 3 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
runtest/syscalls +2 -1
index 777f0ac6a..7fd67450e 100644
@@ -524,10 +524,11 @@ ioctl03      ioctl03
 ioctl04      ioctl04
 ioctl05      ioctl05
 ioctl06      ioctl06
-
 ioctl07      ioctl07
 ioctl08      ioctl08
 
+ioctl_loop01 ioctl_loop01
+
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
 ioctl_ns03 ioctl_ns03
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@
 /ioctl06
 /ioctl07
 /ioctl08
+/ioctl_loop01
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +44 -0
new file mode 100644
index 000000000..e806e0443
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
+ * directory and also get lo_flags by using LOOP_GET_STATUS.
+ *
+ * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
+ * But we also check whether we can scan partition table correctly ie check
+ * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], backing_path[1024], backing_file_path[1024];
+static int dev_num, attach_flag, dev_fd;
+/*
+ *In drivers/block/loop.c code, set status function doesn't handle
+ *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly
+ *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY.
+ */
+#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)
+#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
+
+static char partscan_path[1024], autoclear_path[1024];
+static char loop_partpath[1026], sys_loop_partpath[1026];
+
+static void verify_ioctl_loop(void)
+{
+	int ret;
+	struct loop_info loopinfo, loopinfoget;
+
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 54

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +10 -0
+	check_sys_value(partscan_path, 0);
+	check_sys_value(autoclear_path, 0);
+	check_sys_string(backing_path, backing_file_path);
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	memset(&loopinfo, 0, sizeof(loopinfoget));
+
+	loopinfo.lo_flags = set_flags;
+	SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);

I guess that it would be safer to memset() the loopinfo_get here, also if we zero the structure we may as well reuse the loopinfo here as well.

Quoted 28 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +28 -0
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+	if (loopinfoget.lo_flags & ~get_flags)
+		tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags);
+	else
+		tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);
+
+	ret = access(loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", loop_partpath);
+
+	ret = access(sys_loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", sys_loop_partpath);
+
+	check_sys_value(partscan_path, 1);
+	check_sys_value(autoclear_path, 1);
+
+	SAFE_CLOSE(dev_fd);
+	tst_detach_device(dev_path);
+	attach_flag = 0;
+}
+
+static void setup(void)

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 93

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +10 -0
+{
+	const char *const cmd_dd[] = {"dd", "if=/dev/zero", "of=test.img", "bs=1M", "count=10", NULL};
+	const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+						"primary", "ext4", "1M", "10M", NULL};
+
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	SAFE_CMD(cmd_dd, NULL, NULL);

Why not tst_fill_file("test.img", 0, 1024 * 1024, 10); ?

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 94

Quoted 1 line
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +1 -0
+	SAFE_CMD(cmd_parted, NULL, NULL);

I wonder if we can avoid dependency on parted by having a look at the changes in the image after the call to parted and writing a few bytes ourselves instead.

Quoted 40 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +32 -0
+	sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
+	sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
+	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
+	sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
+	sprintf(loop_partpath, "%sp1", dev_path);
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_cmds = (const char *const []) {
+		"dd",
+		"parted",
+		NULL
+	},
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	},
+	.needs_tmpdir = 1,
+};
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#12 lore raw

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

Hi Cyril

Quoted 100 lines

Hi!

Quoted 99 lines

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---
  runtest/syscalls                              |   3 +-
  testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
  .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 ++++++++++++++++++
  3 files changed, 130 insertions(+), 1 deletion(-)

create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c

runtest/syscalls +2 -1
index 777f0ac6a..7fd67450e 100644
@@ -524,10 +524,11 @@ ioctl03      ioctl03
  ioctl04      ioctl04
  ioctl05      ioctl05
  ioctl06      ioctl06
-
  ioctl07      ioctl07
  ioctl08      ioctl08
 
+ioctl_loop01 ioctl_loop01
+
  ioctl_ns01 ioctl_ns01
  ioctl_ns02 ioctl_ns02
  ioctl_ns03 ioctl_ns03
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@
  /ioctl06
  /ioctl07
  /ioctl08
+/ioctl_loop01
  /ioctl_ns01
  /ioctl_ns02
  /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +49 -0
new file mode 100644
index 000000000..e806e0443
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
+ * directory and also get lo_flags by using LOOP_GET_STATUS.
+ *
+ * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
+ * But we also check whether we can scan partition table correctly ie check
+ * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], backing_path[1024], backing_file_path[1024];
+static int dev_num, attach_flag, dev_fd;
+/*
+ *In drivers/block/loop.c code, set status function doesn't handle
+ *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly
+ *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY.
+ */
+#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)
+#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
+
+static char partscan_path[1024], autoclear_path[1024];
+static char loop_partpath[1026], sys_loop_partpath[1026];
+
+static void verify_ioctl_loop(void)
+{
+	int ret;
+	struct loop_info loopinfo, loopinfoget;
+
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+
+	check_sys_value(partscan_path, 0);
+	check_sys_value(autoclear_path, 0);
+	check_sys_string(backing_path, backing_file_path);
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
Quoted 9 lines

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 54

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +5 -0
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	memset(&loopinfo, 0, sizeof(loopinfoget));
+
+	loopinfo.lo_flags = set_flags;
+	SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);

I guess that it would be safer to memset() the loopinfo_get here, also if we zero the structure we may as well reuse the loopinfo here as well.

of coure, I will add memset in here.

Quoted 32 lines
Quoted 32 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +32 -0
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+	if (loopinfoget.lo_flags & ~get_flags)
+		tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags);
+	else
+		tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);
+
+	ret = access(loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", loop_partpath);
+
+	ret = access(sys_loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", sys_loop_partpath);
+
+	check_sys_value(partscan_path, 1);
+	check_sys_value(autoclear_path, 1);
+
+	SAFE_CLOSE(dev_fd);
+	tst_detach_device(dev_path);
+	attach_flag = 0;
+}
+
+static void setup(void)
+{
+	const char *const cmd_dd[] = {"dd", "if=/dev/zero", "of=test.img", "bs=1M", "count=10", NULL};
+	const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+						"primary", "ext4", "1M", "10M", NULL};
Quoted 9 lines

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 93

Quoted 6 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +6 -0
+
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	SAFE_CMD(cmd_dd, NULL, NULL);

Why not tst_fill_file("test.img", 0, 1024 * 1024, 10); ?

I will try this.

Quoted 5 lines

testcases/kernel/syscalls/ioctl/ioctl_loop01.c line 94

Quoted 1 line
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +1 -0
+	SAFE_CMD(cmd_parted, NULL, NULL);

I wonder if we can avoid dependency on parted by having a look at the changes in the image after the call to parted and writing a few bytes ourselves instead.

I will see kernel code to figure out this, if no other good way, we can split this check into a new single test. it can make this case less couping.

Quoted 42 lines
Quoted 41 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +32 -0
+	sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
+	sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
+	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
+	sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
+	sprintf(loop_partpath, "%sp1", dev_path);
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_cmds = (const char *const []) {
+		"dd",
+		"parted",
+		NULL
+	},
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	},
+	.needs_tmpdir = 1,
+};
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#13 lore raw

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

Hi Cyril

Quoted 168 lines

Hi Cyril

Quoted 107 lines

Hi!

Quoted 106 lines

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---

? runtest/syscalls????????????????????????????? |?? 3 +-
? testcases/kernel/syscalls/ioctl/.gitignore??? |?? 1 +
? .../kernel/syscalls/ioctl/ioctl_loop01.c????? | 127 ++++++++++++++++++

? 3 files changed, 130 insertions(+), 1 deletion(-)
? create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c

runtest/syscalls +0 -0
index 777f0ac6a..7fd67450e 100644
@@ -524,10 +524,11 @@ ioctl03????? ioctl03

? ioctl04????? ioctl04
? ioctl05????? ioctl05
? ioctl06????? ioctl06
-
? ioctl07????? ioctl07
? ioctl08????? ioctl08

runtest/syscalls +2 -0
+ioctl_loop01 ioctl_loop01
+

? ioctl_ns01 ioctl_ns01
? ioctl_ns02 ioctl_ns02
? ioctl_ns03 ioctl_ns03

testcases/kernel/syscalls/ioctl/.gitignore +0 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@

? /ioctl06
? /ioctl07
? /ioctl08
+/ioctl_loop01
? /ioctl_ns01
? /ioctl_ns02
? /ioctl_ns03

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +7 -0
new file mode 100644
index 000000000..e806e0443
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN 

flag.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
+ * directory and also get lo_flags by using LOOP_GET_STATUS.
+ *
+ * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
+ * But we also check whether we can scan partition table correctly ie check
+ * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
+ */

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +9 -0
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], backing_path[1024], 

backing_file_path[1024];

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +7 -0
+static int dev_num, attach_flag, dev_fd;
+/*
+ *In drivers/block/loop.c code, set status function doesn't handle
+ *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly
+ *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY.
+ */
+#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | 

LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +18 -0
+#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
+
+static char partscan_path[1024], autoclear_path[1024];
+static char loop_partpath[1026], sys_loop_partpath[1026];
+
+static void verify_ioctl_loop(void)
+{
+??? int ret;
+??? struct loop_info loopinfo, loopinfoget;
+
+??? tst_attach_device(dev_path, "test.img");
+??? attach_flag = 1;
+
+??? check_sys_value(partscan_path, 0);
+??? check_sys_value(autoclear_path, 0);
+??? check_sys_string(backing_path, backing_file_path);
+
+??? dev_fd = SAFE_OPEN(dev_path, O_RDWR);
Quoted 9 lines
Quoted 5 lines

+??? memset(&loopinfo, 0, sizeof(loopinfo)); +??? memset(&loopinfo, 0, sizeof(loopinfoget)); +
+??? loopinfo.lo_flags = set_flags;
+??? SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);

I guess that it would be safer to memset() the loopinfo_get here, also if we zero the structure we may as well reuse the loopinfo here as well.

of coure, I will add memset in here.

Quoted 36 lines
Quoted 36 lines

+??? SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); +
+??? if (loopinfoget.lo_flags & ~get_flags) +??????? tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags);
+??? else
+??????? tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +24 -0
+
+??? ret = access(loop_partpath, F_OK);
+??? if (ret == 0)
+??????? tst_res(TPASS, "access %s succeeds", loop_partpath);
+??? else
+??????? tst_res(TFAIL, "access %s fails", loop_partpath);
+
+??? ret = access(sys_loop_partpath, F_OK);
+??? if (ret == 0)
+??????? tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
+??? else
+??????? tst_res(TFAIL, "access %s fails", sys_loop_partpath);
+
+??? check_sys_value(partscan_path, 1);
+??? check_sys_value(autoclear_path, 1);
+
+??? SAFE_CLOSE(dev_fd);
+??? tst_detach_device(dev_path);
+??? attach_flag = 0;
+}
+
+static void setup(void)
+{
+??? const char *const cmd_dd[] = {"dd", "if=/dev/zero", 

"of=test.img", "bs=1M", "count=10", NULL};
+??? const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+??????????????????????? "primary", "ext4", "1M", "10M", NULL};

Quoted 9 lines

testcases/kernel/syscalls/ioctl/ioctl_loop01.c

Quoted 6 lines
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +6 -0
+
+??? dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+??? if (dev_num < 0)
+??????? tst_brk(TBROK, "Failed to find free loop device");
+
+??? SAFE_CMD(cmd_dd, NULL, NULL);

Why not tst_fill_file("test.img", 0, 1024 * 1024, 10); ?

I will try this.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+??? SAFE_CMD(cmd_parted, NULL, NULL);

I wonder if we can avoid dependency on parted by having a look at the changes in the image after the call to parted and writing a few bytes ourselves instead.

I will see kernel code to figure out this, if no other good way, we can split this check into a new single test. it can make this case less couping.

Sorry for misunderstanding,. I prefer to add a parted test.img(10K is ok on my environment) into ltp or add a flag to skip this check(/dev/loop0p1) when parted command is not available. What do you think about the two ways?

Best Regards
Yang Xu

Quoted 48 lines
Quoted 45 lines
Quoted 44 lines

+??? sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num); +??? sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
+??? sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+??? sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
+??? sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir()); +??? sprintf(loop_partpath, "%sp1", dev_path);

testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +26 -0
+}
+
+static void cleanup(void)
+{
+??? if (dev_fd > 0)
+??????? SAFE_CLOSE(dev_fd);
+??? if (attach_flag)
+??????? tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+??? .setup = setup,
+??? .cleanup = cleanup,
+??? .test_all = verify_ioctl_loop,
+??? .needs_root = 1,
+??? .needs_cmds = (const char *const []) {
+??????? "dd",
+??????? "parted",
+??????? NULL
+??? },
+??? .needs_drivers = (const char *const []) {
+??????? "loop",
+??????? NULL
+??? },
+??? .needs_tmpdir = 1,
+};
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

Hi!

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

I wonder if we can avoid dependency on parted by having a look at the changes in the image after the call to parted and writing a few bytes ourselves instead.

I will see kernel code to figure out this, if no other good way, we can split this check into a new single test. it can make this case less couping.

Sorry for misunderstanding,. I prefer to add a parted test.img(10K is ok on my environment) into ltp or add a flag to skip this check(/dev/loop0p1) when parted command is not available. What do you think about the two ways?

I it couldn't be easily done without parted then it's fine if the test depends on it.

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

PATCH v2 1/10 lapi/loop.h: Add fallback for loop ioctl and flag

---
 include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 include/lapi/loop.h
include/lapi/loop.h new file +35 -0
new file mode 100644
index 000000000..bc6d9950d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
Signature · 1 line
2.23.0
author
#16 lore raw

PATCH v2 1/10 lapi/loop.h: Add fallback for loop ioctl and flag

Hi All

Quoted 12 lines
---
  include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++
  1 file changed, 35 insertions(+)

create mode 100644 include/lapi/loop.h

include/lapi/loop.h new file +0 -0
new file mode 100644
index 000000000..bc6d9950d

include/lapi/loop.h line 10

Quoted 10 lines
include/lapi/loop.h new file +10 -0
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef LAPI_LOOP_H
+#define LAPI_LOOP_H
+
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H

Sorry, this should be removed.

Quoted 26 lines
include/lapi/loop.h new file +25 -0
+# include <linux/loop.h>
+#endif
+
+#ifndef LO_FLAGS_PARTSCAN
+# define LO_FLAGS_PARTSCAN 8
+#endif
+
+#ifndef LO_FLAGS_DIRECT_IO
+# define LO_FLAGS_DIRECT_IO 16
+#endif
+
+#ifndef LOOP_SET_CAPACITY
+# define LOOP_SET_CAPACITY 0x4C07
+#endif
+
+#ifndef LOOP_SET_DIRECT_IO
+# define LOOP_SET_DIRECT_IO 0x4C08
+#endif
+
+#ifndef LOOP_SET_BLOCK_SIZE
+# define LOOP_SET_BLOCK_SIZE 0x4C09
+#endif
+
+#endif
+
author
#17 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

In reply to Yang Xu
---
 testcases/kernel/syscalls/ioctl/Makefile      |  5 +++
 .../syscalls/ioctl/ioctl_loop_support.c       | 40 +++++++++++++++++++
 .../syscalls/ioctl/ioctl_loop_support.h       | 12 ++++++
 3 files changed, 57 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h
testcases/kernel/syscalls/ioctl/Makefile +5 -0
index c2ff6c8e7..7bdc7daf0 100644
@@ -7,6 +7,11 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		+= test_ioctl
 
+FILTER_OUT_MAKE_TARGETS += ioctl_loop_support
+
+LOOP_TARGETS            := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/ioctl_loop[0-9]*.c))
+$(LOOP_TARGETS): %: ioctl_loop_support.o
+
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= ioctl02
 endif
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +40 -0
new file mode 100644
index 000000000..75c7b1b9a
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+	int getvalue;
+
+	SAFE_FILE_SCANF(path, "%d", &getvalue);
+	if (setvalue == getvalue)
+		tst_res(TPASS, "%s value is %d", path, setvalue);
+	else
+		tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue);
+}
+
+void check_sys_string(char *path, char *setmessage)
+{
+	char getmessage[1024];
+
+	SAFE_FILE_SCANF(path, "%s", getmessage);
+	if (strcmp(setmessage, getmessage))
+		tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage);
+	else
+		tst_res(TPASS, "%s string is %s", path, getmessage);
+}
+
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message)
+{
+	int ret = 0;
+
+	ret = ioctl(dev_fd, ioctl_flag, value);
+	if (ret && errno == EINVAL)
+		tst_brk(TCONF, "Current environment doesn't support this flag(%s)",
+				message);
+}
testcases/kernel/syscalls/ioctl/ioctl_loop_support.h new file +12 -0
new file mode 100644
index 000000000..ade64e82e
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#ifndef IOCTL_LOOP_H
+#define IOCTL_lOOP_H
+#include <linux/loop.h>
+void check_sys_value(char *path, int setvalue);
+void check_sys_string(char *path, char *setmessage);
+void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message);
+#endif
Signature · 1 line
2.23.0
#18 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi!

Quoted 19 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +19 -0
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+	int getvalue;
+
+	SAFE_FILE_SCANF(path, "%d", &getvalue);
+	if (setvalue == getvalue)
+		tst_res(TPASS, "%s value is %d", path, setvalue);
+	else
+		tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue);
+}
+

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 30

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +10 -0
+void check_sys_string(char *path, char *setmessage)
+{
+	char getmessage[1024];
+
+	SAFE_FILE_SCANF(path, "%s", getmessage);
+	if (strcmp(setmessage, getmessage))
+		tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage);
+	else
+		tst_res(TPASS, "%s string is %s", path, getmessage);
+}

In the end I've renamed and moved these functions into the test library because the functionality is generic enough and I doubt that these tests would be the only one using it.

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

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 26 lines

Hi!

Quoted 25 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +25 -0
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+	int getvalue;
+
+	SAFE_FILE_SCANF(path, "%d", &getvalue);
+	if (setvalue == getvalue)
+		tst_res(TPASS, "%s value is %d", path, setvalue);
+	else
+		tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue);
+}
+
+void check_sys_string(char *path, char *setmessage)
+{
+	char getmessage[1024];
+
+	SAFE_FILE_SCANF(path, "%s", getmessage);
+	if (strcmp(setmessage, getmessage))
Quoted 8 lines

testcases/kernel/syscalls/ioctl/ioctl_loop_support.c line 30

Quoted 4 lines
testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file +4 -0
+		tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage);
+	else
+		tst_res(TPASS, "%s string is %s", path, getmessage);
+}

In the end I've renamed and moved these functions into the test library because the functionality is generic enough and I doubt that these tests would be the only one using it.

That's great. I remember prctl cases use this function. Also, in some cap cases, it needs bitwise operators(I only know prctl08.c). Maybe we can add TST_ASSERT_BITWISE?

Quoted 1 line
author
#20 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 39 lines

Hi Cyril

Quoted 28 lines

Hi!

Quoted 27 lines
(quoted diff) +17 -0
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+#define TST_NO_DEFAULT_MAIN
+#include "ioctl_loop_support.h"
+#include "tst_test.h"
+
+void check_sys_value(char *path, int setvalue)
+{
+??? int getvalue;
+
+??? SAFE_FILE_SCANF(path, "%d", &getvalue);
+??? if (setvalue == getvalue)
+??????? tst_res(TPASS, "%s value is %d", path, setvalue);
+??? else
+??????? tst_res(TFAIL, "%s value expected %d got %d", path, 

setvalue, getvalue);

(quoted diff) +9 -0
+}
+
+void check_sys_string(char *path, char *setmessage)
+{
+??? char getmessage[1024];
+
+??? SAFE_FILE_SCANF(path, "%s", getmessage);
+??? if (strcmp(setmessage, getmessage))
+??????? tst_res(TFAIL, "%s expected %s got %s", path, setmessage, 
Quoted 8 lines
Quoted 4 lines

getmessage);
+??? else
+??????? tst_res(TPASS, "%s string is %s", path, getmessage); +}

In the end I've renamed and moved these functions into the test library because the functionality is generic enough and I doubt that these tests would be the only one using it.

Quoted 3 lines

That's great.? I remember prctl cases use this function. Also, in some cap cases, it needs bitwise operators(I only know prctl08.c). Maybe we can add TST_ASSERT_BITWISE?

This situation is rarely seen. I want to add two functions such as TST_ASSERT_FILE_STR/INT to compare file field string with expected string. So, I can use this api for prctl NoNewPrivs and Seccomp field in /proc/[pid]/status. What do you think about this?

lib/tst_assert.c +0 -0
@@ -22,6 +22,20 @@ void tst_assert_int(const char *file, const int 

lineno, const char *path, int va

         tst_res_(file, lineno, TFAIL, "%s != %d got %d", path, val, 

sys_val);
}

+void tst_assert_file_int(const char *file, const int lineno, const char *path, const char *buf, int val)
+{
+ int sys_val;
+
+ SAFE_FILE_LINES_SCANF(path, buf, &sys_val);
+
+ if (val == sys_val) {
+ tst_res_(file, lineno, TPASS, "%s %s field = %d", path,
buf, sys_val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s %s field != %d got %d", path,
buf, val, sys_val);
+}
+
void tst_assert_str(const char *file, const int lineno, const char
*path, const char *val)

  {
         char sys_val[1024];

@@ -34,3 +48,17 @@ void tst_assert_str(const char *file, const int lineno, const char *path, const

         tst_res_(file, lineno, TFAIL, "%s != '%s' got '%s'", path, val, 

sys_val);
}
+
+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)
+{
+ char sys_val[1024];
+
+ SAFE_FILE_LINES_SCANF(path, buf, sys_val);
+
+ if (!strcmp(val, sys_val)) {
+ tst_res_(file, lineno, TPASS, "%s %s field = %s", path,
buf, sys_val);
+ return;
+ }
+
+ tst_res_(file, lineno, TFAIL, "%s %s field != %s got %s", path,
buf, val, sys_val);
+}

Best Regards
Yang Xu

Quoted 1 line
Quoted 1 line
#21 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi!

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

Also I'm not sure that it's a good idea to pass the fmt to this function. I guess that it would be better to pass a prefix string such as "foo=" and to append the "%s" in this function. That way we could also encode the buffer length to the fmt string as well, in that case we would append "%1024s".

Quoted 9 lines
(quoted diff) +2 -0
+       if (!strcmp(val, sys_val)) {
+               tst_res_(file, lineno, TPASS, "%s %s field = %s", path, 

buf, sys_val);

(quoted diff) +4 -0
+               return;
+       }
+
+       tst_res_(file, lineno, TFAIL, "%s %s field != %s got %s", path, 

buf, val, sys_val);
+}

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

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 10 lines

Hi!

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

I don't understand the meaning of adding filename and line parameter(If fail, it will report tst_assert.c: 29). Do you want to report the correct parsed filename when failed?

If so, I think lineno is meaningless and it also overides the place of the code meet problem . I prefer to add some path info in safe_file_ops.c.

Quoted 7 lines

Also I'm not sure that it's a good idea to pass the fmt to this function. I guess that it would be better to pass a prefix string such as "foo=" and to append the "%s" in this function. That way we could also encode the buffer length to the fmt string as well, in that case we would append "%1024s".

Yes, it is a better way.

ps: I will send a patch about this api.

Best Regards
Yang Xu

Quoted 12 lines
Quoted 9 lines
(quoted diff) +2 -0
+       if (!strcmp(val, sys_val)) {
+               tst_res_(file, lineno, TPASS, "%s %s field = %s", path,

buf, sys_val);

(quoted diff) +4 -0
+               return;
+       }
+
+       tst_res_(file, lineno, TFAIL, "%s %s field != %s got %s", path,

buf, val, sys_val);
+}

#23 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi!

Quoted 9 lines
Quoted 9 lines

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

Quoted 6 lines

I don't understand the meaning of adding filename and line parameter(If fail, it will report tst_assert.c: 29). Do you want to report the correct parsed filename when failed?

If so, I think lineno is meaningless and it also overides the place of the code meet problem . I prefer to add some path info in safe_file_ops.c.

What I want is to show the test source filename and line on failure, for that we have to pass the lineno and file to the file_lines_scanf() function. I think that it makes much more sense to print the line in a test where the problem has happened rather than some location in the library code.

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

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 14 lines

Hi!

Quoted 13 lines
Quoted 9 lines

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

I don't understand the meaning of adding filename and line parameter(If fail, it will report tst_assert.c: 29). Do you want to report the correct parsed filename when failed?

Quoted 8 lines
Quoted 2 lines

If so, I think lineno is meaningless and it also overides the place of the code meet problem . I prefer to add some path info in safe_file_ops.c.

What I want is to show the test source filename and line on failure, for that we have to pass the lineno and file to the file_lines_scanf() function. I think that it makes much more sense to print the line in a test where the problem has happened rather than some location in the library code.

Oh, I see. ie TST_ASSERT_INT, modify ioctl_loop01.c TST_ASSERT_INT(__FILE__, __LINE__, partscan_path, 0);
if partscan_path doesn't exist, it will report error as below:
safe_file_ops.c:142: BROK: Failed to open FILE '/sys/block/loop0/loop1/partscan' for reading at ioctl_loop01.c:46:
ENOENT (2)

--- a/lib/tst_assert.c
+++ b/lib/tst_assert.c
-void tst_assert_int(const char *file, const int lineno, const char *path, int val)
+void tst_assert_int(const char *file, const int lineno, const char *source_path,
+ const int source_pos, const char *path, int val)

  {
         int sys_val;

- SAFE_FILE_SCANF(path, "%d", &sys_val);
+ safe_file_scanf(source_path, source_pos, NULL, path, "%d", &sys_val

include/tst_assert.h +2 -2
index 913fff1b5..03e57bbd9 100644
@@ -7,8 +7,8 @@
  #ifndef TST_ASSERT_H__
  #define TST_ASSERT_H__
 
-#define TST_ASSERT_INT(path, val) \
-       tst_assert_int(__FILE__, __LINE__, path, val)
+#define TST_ASSERT_INT(source_path, source_pos, path, val) \
+       tst_assert_int(__FILE__, __LINE__, source_path, source_pos, 

path, val)

/*
* Asserts that integer value stored in file pointed by path equals to the
@@ -16,6 +16,7 @@
* values in sysfs, procfs, etc.
*/
void tst_assert_int(const char *file, const int lineno,
+ const char *source_path, const int source_pos,

                     const char *path, int val);
  #define TST_ASSERT_FILE_INT(path, buf, val)
Quoted 1 line
#25 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi!

Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

I don't understand the meaning of adding filename and line parameter(If fail, it will report tst_assert.c: 29). Do you want to report the correct parsed filename when failed?

Quoted 8 lines
Quoted 2 lines

If so, I think lineno is meaningless and it also overides the place of the code meet problem . I prefer to add some path info in safe_file_ops.c.

What I want is to show the test source filename and line on failure, for that we have to pass the lineno and file to the file_lines_scanf() function. I think that it makes much more sense to print the line in a test where the problem has happened rather than some location in the library code.

Quoted 6 lines

Oh, I see. ie TST_ASSERT_INT, modify ioctl_loop01.c TST_ASSERT_INT(__FILE__, __LINE__, partscan_path, 0);
if partscan_path doesn't exist, it will report error as below:
safe_file_ops.c:142: BROK: Failed to open FILE '/sys/block/loop0/loop1/partscan' for reading at ioctl_loop01.c:46:
ENOENT (2)

I still think that we are not on the same page.

The macros are to be used from tests, such as TST_ASSERT_INT() these macros call the corresponding functions with __FILE__ and __LINE__, in this case tst_assert_int(). From that point on anything that is called from inside of the tst_assert_int() function should pass down the file and lineno so that we get the filename and lineno from the line the call has been called in the test.

So if we do TST_ASSERT_INT() in the test, we call tst_brk_() and pass the file and lineno so that we get the correct test line in case of a failure.

And for the same reason if we are going to get an value from a file from inside of the assert function we have to call the safe_file_scanf() and pass down the file and lineno so that if the call fails the test filename and the line on which the call originated in the test is printed.

Is it clear now?

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

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

Hi Cyril

Quoted 43 lines

Hi!

Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

Review

Quoted 6 lines

+void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *buf, const char *val)

(quoted diff) +4 -0
+{
+       char sys_val[1024];
+
+       SAFE_FILE_LINES_SCANF(path, buf, sys_val);

We should call the file_lines_scanf() here and pass the filename and lineno that this functions takes as parameter instead.

I don't understand the meaning of adding filename and line parameter(If fail, it will report tst_assert.c: 29). Do you want to report the correct parsed filename when failed?

Quoted 8 lines
Quoted 2 lines

If so, I think lineno is meaningless and it also overides the place of the code meet problem . I prefer to add some path info in safe_file_ops.c.

What I want is to show the test source filename and line on failure, for that we have to pass the lineno and file to the file_lines_scanf() function. I think that it makes much more sense to print the line in a test where the problem has happened rather than some location in the library code.

Quoted 6 lines

Oh, I see. ie TST_ASSERT_INT, modify ioctl_loop01.c TST_ASSERT_INT(__FILE__, __LINE__, partscan_path, 0);
if partscan_path doesn't exist, it will report error as below:
safe_file_ops.c:142: BROK: Failed to open FILE '/sys/block/loop0/loop1/partscan' for reading at ioctl_loop01.c:46:
ENOENT (2)

I still think that we are not on the same page.

The macros are to be used from tests, such as TST_ASSERT_INT() these macros call the corresponding functions with __FILE__ and __LINE__, in this case tst_assert_int(). From that point on anything that is called from inside of the tst_assert_int() function should pass down the file and lineno so that we get the filename and lineno from the line the call has been called in the test.

So if we do TST_ASSERT_INT() in the test, we call tst_brk_() and pass the file and lineno so that we get the correct test line in case of a failure.

Quoted 7 lines

And for the same reason if we are going to get an value from a file from inside of the assert function we have to call the safe_file_scanf() and pass down the file and lineno so that if the call fails the test filename and the line on which the call originated in the test is printed.

Is it clear now?

OK. I guess I only need to use safe_file_scanf(file, lineno, NULL, path, "%d", &sys_val) in tst_assert_int function as you suggested at the beginning.

Quoted 1 line
#27 lore raw

PATCH v2 2/10 syscalls/ioctl:add common c file for loop ioctl

In reply to Yang Xu

Hi!

Quoted 6 lines
Quoted 3 lines

In the end I've renamed and moved these functions into the test library because the functionality is generic enough and I doubt that these tests would be the only one using it.

That's great. I remember prctl cases use this function. Also, in some cap cases, it needs bitwise operators(I only know prctl08.c). Maybe we can add TST_ASSERT_BITWISE?

I guess that we would need to pass to numbers to the bitwise operation, one would be mask for which bits should be used for the comparsion and one with the actual bits. Which tests would need that? I looked at capset and capget tests but there does not seem to any bitwise checks on values on proc or sys files.

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

PATCH v2 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

In reply to Yang Xu

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---
 runtest/syscalls                              |   3 +-
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop01.c      | 140 ++++++++++++++++++
 3 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
runtest/syscalls +2 -1
index 44254d7da..8d1ce0c9a 100644
@@ -525,10 +525,11 @@ ioctl03      ioctl03
 ioctl04      ioctl04
 ioctl05      ioctl05
 ioctl06      ioctl06
-
 ioctl07      ioctl07
 ioctl08      ioctl08
 
+ioctl_loop01 ioctl_loop01
+
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
 ioctl_ns03 ioctl_ns03
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@
 /ioctl06
 /ioctl07
 /ioctl08
+/ioctl_loop01
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#29 lore raw

PATCH v2 4/10 syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test

In reply to Yang Xu

For LOOP_CHANGE_FD, this operation is possible only if the loop device is read-only and the new backing store is the same size and type as the old backing store.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop02.c      | 150 ++++++++++++++++++
 3 files changed, 152 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c
runtest/syscalls +1 -0
index 8d1ce0c9a..80005227d 100644
@@ -529,6 +529,7 @@ ioctl07      ioctl07
 ioctl08      ioctl08
 
 ioctl_loop01 ioctl_loop01
+ioctl_loop02 ioctl_loop02
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 4cfef2839..534c4ab34 100644
@@ -7,6 +7,7 @@
 /ioctl07
 /ioctl08
 /ioctl_loop01
+/ioctl_loop02
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#30 lore raw

PATCH v2 5/10 syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode

In reply to Yang Xu

It is designed to test LOOP_CHANGE_FD can not succeed(get EINAL error) when loop_dev is not read only.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop03.c      | 76 +++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop03.c
runtest/syscalls +1 -0
index 80005227d..46d877fa3 100644
@@ -530,6 +530,7 @@ ioctl08      ioctl08
 
 ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
+ioctl_loop03 ioctl_loop03
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 534c4ab34..1501c2779 100644
@@ -8,6 +8,7 @@
 /ioctl08
 /ioctl_loop01
 /ioctl_loop02
+/ioctl_loop03
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop03.c new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.23.0
#31 lore raw

PATCH v2 5/10 syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode

Hi!
I did a minor fixes, typo correction and code simplifications and pushed first three tests, thanks.

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

PATCH v2 6/10 syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test

In reply to Yang Xu

LOOP_SET_CAPACITY can update a live loop device size when we change the size of the underlying backing file. Also check sys value.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop04.c      | 97 +++++++++++++++++++
 3 files changed, 99 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop04.c
runtest/syscalls +1 -0
index 46d877fa3..51ad8ff69 100644
@@ -531,6 +531,7 @@ ioctl08      ioctl08
 ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
+ioctl_loop04 ioctl_loop04
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 1501c2779..039a5251c 100644
@@ -9,6 +9,7 @@
 /ioctl_loop01
 /ioctl_loop02
 /ioctl_loop03
+/ioctl_loop04
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop04.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#33 lore raw

PATCH v2 7/10 syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test

In reply to Yang Xu

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(getting by BLKSSZGET ioctl).

It was introduced into kernel since 4.10
commit ab1cb278bc70 ("block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO").

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 125 ++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c
runtest/syscalls +1 -0
index 51ad8ff69..8b120b43a 100644
@@ -532,6 +532,7 @@ ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
+ioctl_loop05 ioctl_loop05
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 039a5251c..f484d98d6 100644
@@ -10,6 +10,7 @@
 /ioctl_loop02
 /ioctl_loop03
 /ioctl_loop04
+/ioctl_loop05
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#34 lore raw

PATCH v2 8/10 syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test

In reply to Yang Xu
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop06.c      | 90 +++++++++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop06.c
runtest/syscalls +1 -0
index 8b120b43a..e9b0a8f60 100644
@@ -533,6 +533,7 @@ ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
+ioctl_loop06 ioctl_loop06
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index f484d98d6..ec19b4901 100644
@@ -11,6 +11,7 @@
 /ioctl_loop03
 /ioctl_loop04
 /ioctl_loop05
+/ioctl_loop06
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop06.c new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.23.0
#35 lore raw

PATCH v2 8/10 syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test

Hi!
Pushed, next three tests with minor changes, thanks.

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

PATCH v2 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

In reply to Yang Xu

This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE and LOOP_SET_DIRECT_IO. When logical blocksize is 1024, set dio with 512 offset will fail.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop07.c      | 85 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c
runtest/syscalls +1 -0
index e9b0a8f60..f83561724 100644
@@ -534,6 +534,7 @@ ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
 ioctl_loop06 ioctl_loop06
+ioctl_loop07 ioctl_loop07
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index ec19b4901..3a3d49adc 100644
@@ -12,6 +12,7 @@
 /ioctl_loop04
 /ioctl_loop05
 /ioctl_loop06
+/ioctl_loop07
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop07.c new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.23.0
#37 lore raw

PATCH v2 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

Hi!
This test fails for me, i.e. the attempt to enabe direct IO succeeds. I will have to have a closer look later on.

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

PATCH v2 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

Hi Cyril

Quoted 3 lines

Hi!
This test fails for me, i.e. the attempt to enabe direct IO succeeds. I will have to have a closer look later on.

Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop driver has changed its logic. I am trying.

ps: when run ioctl_loop01.c, I also met another problem that /dev/loop0p1 and the corresponding sys file doesn't existed. dmesg report error "loop_reread_partitions: partition scan of loop0 () failed (rc=-16)". Also trying .

Quoted 1 line
author
#39 lore raw

PATCH v2 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

Hi Cyril

Quoted 8 lines

Hi Cyril

Quoted 3 lines

Hi!
This test fails for me, i.e. the attempt to enabe direct IO succeeds. I will have to have a closer look later on.

Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop driver has changed its logic. I am trying.

I write this test on fedora31(tmp directory use tmpfs), so I got a pseudo pass when setting dio.

I misunderstood the meaning of the comment in the kernel. kernel commet as below:
"We support direct I/O only if lo_offset is aligned with the logical I/O size of backing device, and the logical block size of loop is bigger than the backing device's and the loop needn't transform transfer."

sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev); //get block size from backing device
dio_align = sb_bsize - 1;

I use logic block size of loop(1024 > 512) , so this test pass.

Now, I think this test is meaningless and we can remove this.

Best Regards
Yang Xu

Quoted 6 lines

ps: when run ioctl_loop01.c, I also met another problem that /dev/loop0p1 and? the corresponding sys file doesn't existed. dmesg report error "loop_reread_partitions: partition scan of loop0 () failed (rc=-16)". Also trying .

Quoted 1 line
author
#40 lore raw

PATCH v2 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

Hi Cyril

Quoted 25 lines

Hi Cyril

Quoted 8 lines

Hi Cyril

Quoted 3 lines

Hi!
This test fails for me, i.e. the attempt to enabe direct IO succeeds. I will have to have a closer look later on.

Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop driver has changed its logic. I am trying.

I write this test on fedora31(tmp directory use tmpfs), so I got a pseudo pass when setting dio.

I misunderstood the meaning of the comment in the kernel. kernel commet as below:
"We support direct I/O only if lo_offset is aligned with the logical I/O size of backing device, and the logical block size of loop is bigger than the backing device's and the loop needn't transform transfer."

sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev);? //get block size from backing device
dio_align = sb_bsize - 1;

Quoted 11 lines

I use logic block size of loop(1024 > 512) , so this test pass.

Now, I think this test is meaningless and we can remove this.

Best Regards
Yang Xu

Quoted 5 lines

ps: when run ioctl_loop01.c, I also met another problem that /dev/loop0p1 and? the corresponding sys file doesn't existed. dmesg report error "loop_reread_partitions: partition scan of loop0 () failed (rc=-16)". Also trying .

Kernel commit d3ef55362("block: fix busy device checking in blk_drop_partitions") and commit cb6b771b05("block: fix busy device checking in blk_drop_partitions again") introduced this failure(ioctl_loop01, EBUSY error). more info see[1]

[1]https://lkml.org/lkml/2020/4/23/380

Quoted 1 line
Quoted 1 line
Quoted 1 line
author
#41 lore raw

v2 cover add loop ioctl test

In reply to Yang Xu

This is a set of test for the loop ioctl.

v1->v2:
1. remove linux/loop.h detection
2. use TST_RETRY_FUNC instead of safe_set_status
3. modify makefile
4. free tmpdir
5. use BLKSSZGET ioctl() to get logical block size

Yang Xu (10):
lapi/loop.h: Add fallback for loop ioctl and flag syscalls/ioctl:add common c file for loop ioctl syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN
test
syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test syscalls/ioctl_loop07: Add dio with logic block size error test syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test

 include/lapi/loop.h                           |  35 ++++
 runtest/syscalls                              |  10 +-
 testcases/kernel/syscalls/ioctl/.gitignore    |   8 +
 testcases/kernel/syscalls/ioctl/Makefile      |   5 +
 .../kernel/syscalls/ioctl/ioctl_loop01.c      | 140 ++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop02.c      | 150 ++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop03.c      |  76 +++++++++
 .../kernel/syscalls/ioctl/ioctl_loop04.c      |  97 +++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 125 +++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop06.c      |  90 +++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop07.c      |  85 ++++++++++
 .../kernel/syscalls/ioctl/ioctl_loop08.c      |  96 +++++++++++
 .../syscalls/ioctl/ioctl_loop_support.c       |  40 +++++
 .../syscalls/ioctl/ioctl_loop_support.h       |  12 ++
 14 files changed, 968 insertions(+), 1 deletion(-)
 create mode 100644 include/lapi/loop.h
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop03.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop04.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop06.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop08.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h
Signature · 1 line
2.23.0
author
#42 lore raw

PATCH v2 10/10 syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test

In reply to Yang Xu

Test its lo_sizelimit field. If lo_sizelimit is 0, it means max available. If sizelimit is less than loop_size, loopsize will be truncated.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop08.c      | 96 +++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop08.c
runtest/syscalls +1 -0
index f83561724..d77c191d2 100644
@@ -535,6 +535,7 @@ ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
 ioctl_loop06 ioctl_loop06
 ioctl_loop07 ioctl_loop07
+ioctl_loop08 ioctl_loop08
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 3a3d49adc..97134aa0b 100644
@@ -13,6 +13,7 @@
 /ioctl_loop05
 /ioctl_loop06
 /ioctl_loop07
+/ioctl_loop08
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop08.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.23.0
#43 lore raw

PATCH v2 10/10 syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test

Hi!
I've renamed the test to ioctl_loop07 and pushed, thanks.

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

PATCH v2 1/10 lapi/loop.h: Add fallback for loop ioctl and flag

In reply to Yang Xu

Hi!

include/lapi/loop.h line 12

Quoted 4 lines
include/lapi/loop.h new file +4 -0
+#include <linux/types.h>
+#ifdef HAVE_LINUX_LOOP_H
+# include <linux/loop.h>
+#endif

I've removed this ifdef and pushed, thanks.

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

PATCH 3/10 syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test

In reply to Yang Xu

Hi Christoph

Recently, this test[1](has merged into ltp master) failed on kernel 5.7.0-rc2. I found your kernel patch
d3ef55362("block: fix busy device checking in blk_drop_partitions") and commit cb6b771b05("block: fix busy device checking in blk_drop_partitions again") introduced this failure.

dmesg as below:
"loop_reread_partitions: partition scan of loop0 () failed (rc=-16)"

It look likes we use bd_dev->bd_openers instead of bd_dev->bd_super in blk_drop_partitions after your patch. When running this test, the bd_opener is equal to 3(I don't figure out the reason).
I don't know how to fix this(do special judement for loopdev by using MAJOR((bdev->bd_dev) ?) or should I modify test code? Please give me some advise.

[1]https://github.com/linux-test-project/ltp/commit/4f3ff1f323cbe4ae4dc6542e940902dca1280e9d

Best Regards
Yang Xu

Quoted 178 lines

For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS.

For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.

---
  runtest/syscalls                              |   3 +-
  testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
  .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 ++++++++++++++++++
  3 files changed, 130 insertions(+), 1 deletion(-)

create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c

runtest/syscalls +2 -1
index 777f0ac6a..7fd67450e 100644
@@ -524,10 +524,11 @@ ioctl03      ioctl03
  ioctl04      ioctl04
  ioctl05      ioctl05
  ioctl06      ioctl06
-
  ioctl07      ioctl07
  ioctl08      ioctl08
 
+ioctl_loop01 ioctl_loop01
+
  ioctl_ns01 ioctl_ns01
  ioctl_ns02 ioctl_ns02
  ioctl_ns03 ioctl_ns03
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 97fbb9681..4cfef2839 100644
@@ -6,6 +6,7 @@
  /ioctl06
  /ioctl07
  /ioctl08
+/ioctl_loop01
  /ioctl_ns01
  /ioctl_ns02
  /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file +127 -0
new file mode 100644
index 000000000..e806e0443
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
+ *
+ * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
+ * directory and also get lo_flags by using LOOP_GET_STATUS.
+ *
+ * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
+ * But we also check whether we can scan partition table correctly ie check
+ * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], backing_path[1024], backing_file_path[1024];
+static int dev_num, attach_flag, dev_fd;
+/*
+ *In drivers/block/loop.c code, set status function doesn't handle
+ *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly
+ *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY.
+ */
+#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)
+#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
+
+static char partscan_path[1024], autoclear_path[1024];
+static char loop_partpath[1026], sys_loop_partpath[1026];
+
+static void verify_ioctl_loop(void)
+{
+	int ret;
+	struct loop_info loopinfo, loopinfoget;
+
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+
+	check_sys_value(partscan_path, 0);
+	check_sys_value(autoclear_path, 0);
+	check_sys_string(backing_path, backing_file_path);
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	memset(&loopinfo, 0, sizeof(loopinfoget));
+
+	loopinfo.lo_flags = set_flags;
+	SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);
+
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+	if (loopinfoget.lo_flags & ~get_flags)
+		tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags);
+	else
+		tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);
+
+	ret = access(loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", loop_partpath);
+
+	ret = access(sys_loop_partpath, F_OK);
+	if (ret == 0)
+		tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
+	else
+		tst_res(TFAIL, "access %s fails", sys_loop_partpath);
+
+	check_sys_value(partscan_path, 1);
+	check_sys_value(autoclear_path, 1);
+
+	SAFE_CLOSE(dev_fd);
+	tst_detach_device(dev_path);
+	attach_flag = 0;
+}
+
+static void setup(void)
+{
+	const char *const cmd_dd[] = {"dd", "if=/dev/zero", "of=test.img", "bs=1M", "count=10", NULL};
+	const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+						"primary", "ext4", "1M", "10M", NULL};
+
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	SAFE_CMD(cmd_dd, NULL, NULL);
+	SAFE_CMD(cmd_parted, NULL, NULL);
+
+	sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
+	sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
+	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
+	sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
+	sprintf(loop_partpath, "%sp1", dev_path);
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_cmds = (const char *const []) {
+		"dd",
+		"parted",
+		NULL
+	},
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	},
+	.needs_tmpdir = 1,
+};
author
#46 lore raw

PATCH 4/10 syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test

In reply to Yang Xu

For LOOP_CHANGE_FD, this operation is possible only if the loop device is read-only and the new backing store is the same size and type as the old backing store.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop02.c      | 148 ++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c
runtest/syscalls +1 -0
index 7fd67450e..719953497 100644
@@ -528,6 +528,7 @@ ioctl07      ioctl07
 ioctl08      ioctl08
 
 ioctl_loop01 ioctl_loop01
+ioctl_loop02 ioctl_loop02
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 4cfef2839..534c4ab34 100644
@@ -7,6 +7,7 @@
 /ioctl07
 /ioctl08
 /ioctl_loop01
+/ioctl_loop02
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
2.23.0
#47 lore raw

PATCH 4/10 syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test

Hi!

Quoted 59 lines

For LOOP_CHANGE_FD, this operation is possible only if the loop device is read-only and the new backing store is the same size and type as the old backing store.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop02.c      | 148 ++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c
runtest/syscalls +1 -0
index 7fd67450e..719953497 100644
@@ -528,6 +528,7 @@ ioctl07      ioctl07
 ioctl08      ioctl08
 
 ioctl_loop01 ioctl_loop01
+ioctl_loop02 ioctl_loop02
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 4cfef2839..534c4ab34 100644
@@ -7,6 +7,7 @@
 /ioctl07
 /ioctl08
 /ioctl_loop01
+/ioctl_loop02
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +17 -0
new file mode 100644
index 000000000..ba3636aa9
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LO_FLAGS_READ_ONLY(similar as losetup -r)
+ * and LOOP_CHANGE_FD.
+ *
+ * For LOOP_CHANGE_FD, this operation is possible only if the loop device
+ * is read-only and the new backing store is the same size and type as the
+ * old backing store.
+ */
+
+#include <stdio.h>
+#include <unistd.h>

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 27

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +10 -0
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static int file_fd, file_change_fd, file_fd_invalid;
+static char backing_path[1024], backing_file_path[1024], backing_file_change_path[1024];
+static int attach_flag, dev_fd, file_fd;
+static char loop_ro_path[1024], dev_path[1024];
+static void attach_device(char *);

Just move the function here, there is no point in having the helper function after the test function.

Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +8 -0
+static void verify_ioctl_loop(void)
+{
+	struct loop_info loopinfoget;
+
+	attach_device("test.img");
+	attach_flag = 1;
+
+	check_sys_value(loop_ro_path, 1);

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 46

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +10 -0
+	check_sys_string(backing_path, backing_file_path);
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	file_change_fd = SAFE_OPEN("test1.img", O_RDWR);
+	file_fd_invalid = SAFE_OPEN("test2.img", O_RDWR);
+
+	memset(&loopinfoget, 0, sizeof(loopinfoget));
+	/*
+	 *In drivers/block/loop.c code, set status function doesn't handle
+	 *LO_FLAGS_READ_ONLY flag and ignore it. Only loop_set_fd with rondonly
                                                                       ^
								       readonly

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 47

Quoted 2 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +2 -0
+	 *mode, lo_flags will include LO_FLAGS_READ_ONLY.
+	 */

Also it's customary to add a space between the asterisk and the comment text.

Quoted 62 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +62 -0
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+	if (loopinfoget.lo_flags & ~LO_FLAGS_READ_ONLY)
+		tst_res(TFAIL, "lo_flags has unexpected %d flag", loopinfoget.lo_flags);
+	else
+		tst_res(TPASS, "lo_flags only has default LO_FLAGS_READ_ONLY flag");
+
+	TEST(write(dev_fd, "xx", 2));
+	if (TST_RET != -1)
+		tst_res(TFAIL, "write succeed unexpectedly");
+	else
+		tst_res(TPASS | TTERRNO, "Can not write data in RO mode");
+
+	TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_change_fd));
+	if (TST_RET) {
+		tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed");
+	} else {
+		tst_res(TPASS, "LOOP_CHANGE_FD succeeded");
+		check_sys_value(loop_ro_path, 1);
+		check_sys_string(backing_path, backing_file_change_path);
+	}
+
+	TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd_invalid));
+	if (TST_RET) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected");
+		else
+			tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got");
+	} else {
+		tst_res(TFAIL, "LOOP_CHANGE_FD succeeded");
+	}
+
+	SAFE_CLOSE(dev_fd);
+	SAFE_CLOSE(file_change_fd);
+	SAFE_CLOSE(file_fd_invalid);
+	tst_detach_device(dev_path);
+	attach_flag = 0;
+}
+
+/*
+ * This function is different from tst_attach_dev lib/tst_device.c.
+ * It only opens file_path with O_RDONLY mode before loop_set_fd.
+ * So we can generate LO_FLAGS_READ_ONLY flag.
+ */
+static void attach_device(char *img)
+{
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	file_fd = SAFE_OPEN(img, O_RDONLY);
+
+	SAFE_IOCTL(dev_fd, LOOP_SET_FD, file_fd);
+
+	SAFE_CLOSE(dev_fd);
+	SAFE_CLOSE(file_fd);
+}
+
+static void setup(void)
+{
+	int dev_num;
+
+	char *tmpdir = tst_get_tmpdir();
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 121

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +10 -0
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	tst_fill_file("test.img", 0, 1024, 10);
+	tst_fill_file("test1.img", 0, 1024, 10);
+	tst_fill_file("test2.img", 0, 2048, 20);
+
+	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+	sprintf(backing_file_path, "%s/test.img", tmpdir);
+	sprintf(backing_file_change_path, "%s/test1.img", tmpdir);
+	sprintf(loop_ro_path, "/sys/block/loop%d/ro", dev_num);

We should free the tmpdir here.

Quoted 27 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +27 -0
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (file_fd > 0)
+		SAFE_CLOSE(file_fd);
+	if (file_change_fd > 0)
+		SAFE_CLOSE(file_change_fd);
+	if (file_fd_invalid > 0)
+		SAFE_CLOSE(file_fd_invalid);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	}
+};
Signature · 2 lines
Cyril Hrubis
[email protected]
#48 lore raw

PATCH 4/10 syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test

Hi Cyril

Quoted 65 lines

Hi!

Quoted 64 lines

For LOOP_CHANGE_FD, this operation is possible only if the loop device is read-only and the new backing store is the same size and type as the old backing store.

---
  runtest/syscalls                              |   1 +
  testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
  .../kernel/syscalls/ioctl/ioctl_loop02.c      | 148 ++++++++++++++++++
  3 files changed, 150 insertions(+)

create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c

runtest/syscalls +1 -0
index 7fd67450e..719953497 100644
@@ -528,6 +528,7 @@ ioctl07      ioctl07
  ioctl08      ioctl08
 
  ioctl_loop01 ioctl_loop01
+ioctl_loop02 ioctl_loop02
 
  ioctl_ns01 ioctl_ns01
  ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 4cfef2839..534c4ab34 100644
@@ -7,6 +7,7 @@
  /ioctl07
  /ioctl08
  /ioctl_loop01
+/ioctl_loop02
  /ioctl_ns01
  /ioctl_ns02
  /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +22 -0
new file mode 100644
index 000000000..ba3636aa9
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LO_FLAGS_READ_ONLY(similar as losetup -r)
+ * and LOOP_CHANGE_FD.
+ *
+ * For LOOP_CHANGE_FD, this operation is possible only if the loop device
+ * is read-only and the new backing store is the same size and type as the
+ * old backing store.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
Quoted 9 lines

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 27

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +5 -0
+static int file_fd, file_change_fd, file_fd_invalid;
+static char backing_path[1024], backing_file_path[1024], backing_file_change_path[1024];
+static int attach_flag, dev_fd, file_fd;
+static char loop_ro_path[1024], dev_path[1024];
+static void attach_device(char *);

Just move the function here, there is no point in having the helper function after the test function.

OK.

Quoted 20 lines
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +8 -0
+static void verify_ioctl_loop(void)
+{
+	struct loop_info loopinfoget;
+
+	attach_device("test.img");
+	attach_flag = 1;
+
+	check_sys_value(loop_ro_path, 1);

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 46

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +10 -0
+	check_sys_string(backing_path, backing_file_path);
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	file_change_fd = SAFE_OPEN("test1.img", O_RDWR);
+	file_fd_invalid = SAFE_OPEN("test2.img", O_RDWR);
+
+	memset(&loopinfoget, 0, sizeof(loopinfoget));
+	/*
+	 *In drivers/block/loop.c code, set status function doesn't handle
+	 *LO_FLAGS_READ_ONLY flag and ignore it. Only loop_set_fd with rondonly
                                                                        ^
								       readonly
Quoted 6 lines

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 47

Quoted 2 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +2 -0
+	 *mode, lo_flags will include LO_FLAGS_READ_ONLY.
+	 */

Also it's customary to add a space between the asterisk and the comment text.

OK.

Quoted 66 lines
Quoted 66 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +66 -0
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+
+	if (loopinfoget.lo_flags & ~LO_FLAGS_READ_ONLY)
+		tst_res(TFAIL, "lo_flags has unexpected %d flag", loopinfoget.lo_flags);
+	else
+		tst_res(TPASS, "lo_flags only has default LO_FLAGS_READ_ONLY flag");
+
+	TEST(write(dev_fd, "xx", 2));
+	if (TST_RET != -1)
+		tst_res(TFAIL, "write succeed unexpectedly");
+	else
+		tst_res(TPASS | TTERRNO, "Can not write data in RO mode");
+
+	TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_change_fd));
+	if (TST_RET) {
+		tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed");
+	} else {
+		tst_res(TPASS, "LOOP_CHANGE_FD succeeded");
+		check_sys_value(loop_ro_path, 1);
+		check_sys_string(backing_path, backing_file_change_path);
+	}
+
+	TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd_invalid));
+	if (TST_RET) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected");
+		else
+			tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got");
+	} else {
+		tst_res(TFAIL, "LOOP_CHANGE_FD succeeded");
+	}
+
+	SAFE_CLOSE(dev_fd);
+	SAFE_CLOSE(file_change_fd);
+	SAFE_CLOSE(file_fd_invalid);
+	tst_detach_device(dev_path);
+	attach_flag = 0;
+}
+
+/*
+ * This function is different from tst_attach_dev lib/tst_device.c.
+ * It only opens file_path with O_RDONLY mode before loop_set_fd.
+ * So we can generate LO_FLAGS_READ_ONLY flag.
+ */
+static void attach_device(char *img)
+{
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	file_fd = SAFE_OPEN(img, O_RDONLY);
+
+	SAFE_IOCTL(dev_fd, LOOP_SET_FD, file_fd);
+
+	SAFE_CLOSE(dev_fd);
+	SAFE_CLOSE(file_fd);
+}
+
+static void setup(void)
+{
+	int dev_num;
+
+	char *tmpdir = tst_get_tmpdir();
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	tst_fill_file("test.img", 0, 1024, 10);
+	tst_fill_file("test1.img", 0, 1024, 10);
Quoted 8 lines

testcases/kernel/syscalls/ioctl/ioctl_loop02.c line 121

Quoted 6 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +6 -0
+	tst_fill_file("test2.img", 0, 2048, 20);
+
+	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
+	sprintf(backing_file_path, "%s/test.img", tmpdir);
+	sprintf(backing_file_change_path, "%s/test1.img", tmpdir);
+	sprintf(loop_ro_path, "/sys/block/loop%d/ro", dev_num);

We should free the tmpdir here.

Yes, sorry for forgetting this.

Quoted 29 lines
Quoted 28 lines
testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file +27 -0
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (file_fd > 0)
+		SAFE_CLOSE(file_fd);
+	if (file_change_fd > 0)
+		SAFE_CLOSE(file_change_fd);
+	if (file_fd_invalid > 0)
+		SAFE_CLOSE(file_fd_invalid);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	}
+};
author
#49 lore raw

PATCH 5/10 syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode

In reply to Yang Xu

It is designed to test LOOP_CHANGE_FD can not succeed(get EINAL error) when loop_dev is not read only.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop03.c      | 76 +++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop03.c
runtest/syscalls +1 -0
index 719953497..a4591dd62 100644
@@ -529,6 +529,7 @@ ioctl08      ioctl08
 
 ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
+ioctl_loop03 ioctl_loop03
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 534c4ab34..1501c2779 100644
@@ -8,6 +8,7 @@
 /ioctl08
 /ioctl_loop01
 /ioctl_loop02
+/ioctl_loop03
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop03.c new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#50 lore raw

PATCH 6/10 syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test

In reply to Yang Xu

LOOP_SET_CAPACITY can update a live loop device size when we change the size of the underlying backing file. Also check sys value.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop04.c      | 97 +++++++++++++++++++
 3 files changed, 99 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop04.c
runtest/syscalls +1 -0
index a4591dd62..6e8d71d44 100644
@@ -530,6 +530,7 @@ ioctl08      ioctl08
 ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
+ioctl_loop04 ioctl_loop04
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 1501c2779..039a5251c 100644
@@ -9,6 +9,7 @@
 /ioctl_loop01
 /ioctl_loop02
 /ioctl_loop03
+/ioctl_loop04
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop04.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#51 lore raw

PATCH 7/10 syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test

In reply to Yang Xu

LOOP_SET_DIRECT_IO can updata a live loop device dio mode. It needs the backing file also supports dio mode and the lo_offset is aligned with the logical I/O size.

It was introduced into kernel since 4.10
commit ab1cb278bc70 ("block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO").

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 120 ++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c
runtest/syscalls +1 -0
index 6e8d71d44..9644588f3 100644
@@ -531,6 +531,7 @@ ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
+ioctl_loop05 ioctl_loop05
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 039a5251c..f484d98d6 100644
@@ -10,6 +10,7 @@
 /ioctl_loop02
 /ioctl_loop03
 /ioctl_loop04
+/ioctl_loop05
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.23.0
#52 lore raw

PATCH 7/10 syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test

Hi!

Quoted 91 lines

LOOP_SET_DIRECT_IO can updata a live loop device dio mode. It needs the backing file also supports dio mode and the lo_offset is aligned with the logical I/O size.

It was introduced into kernel since 4.10
commit ab1cb278bc70 ("block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO").

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 120 ++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c
runtest/syscalls +1 -0
index 6e8d71d44..9644588f3 100644
@@ -531,6 +531,7 @@ ioctl_loop01 ioctl_loop01
 ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
+ioctl_loop05 ioctl_loop05
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 039a5251c..f484d98d6 100644
@@ -10,6 +10,7 @@
 /ioctl_loop02
 /ioctl_loop03
 /ioctl_loop04
+/ioctl_loop05
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +46 -0
new file mode 100644
index 000000000..43bad6c18
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * loop device dio mode. It need the backing file also supports
+ * dio mode and the lo_offset is aligned with the logical I/O size.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+#define DIO_MESSAGE "In dio mode"
+#define NON_DIO_MESSAGE "In non dio mode"
+
+static char dev_path[1024], sys_loop_diopath[1024];
+static int dev_num, dev_fd, attach_flag;
+
+static void check_dio_value(int flag)
+{
+	struct loop_info loopinfoget;
+
+	memset(&loopinfoget, 0, sizeof(loopinfoget));
+
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+	tst_res(TINFO, "%s", flag ? DIO_MESSAGE : NON_DIO_MESSAGE);
+
+	if (loopinfoget.lo_flags & LO_FLAGS_DIRECT_IO)
+		tst_res(flag ? TPASS : TFAIL, "lo_flags has LO_FLAGS_DIRECT_IO flag");
+	else
+		tst_res(flag ? TFAIL : TPASS, "lo_flags doesn't have LO_FLAGS_DIRECT_IO flag");
+
+	check_sys_value(sys_loop_diopath, flag);
+}
+
+static void verify_ioctl_loop(void)
+{
+	struct loop_info loopinfo;
+

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

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +10 -0
+	memset(&loopinfo, 0, sizeof(loopinfo));
+
+	SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
+	check_dio_value(0);
+	tst_res(TINFO, "Without setting lo_offset or sizelimit");
+	SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);
+	check_dio_value(1);
+
+	tst_res(TINFO, "With offset equal to sector size");
+	loopinfo.lo_offset = 512;

We should use BLKSSZGET ioctl() to get the block size for direct I/O otherwise I would expect that it would break on one of the less common architectures. See also discussion at the end of man 2 open.

Quoted 41 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +41 -0
+	safe_set_status(dev_fd, loopinfo);
+	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+	if (TST_RET == 0) {
+		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
+		check_dio_value(1);
+	} else {
+		tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed");
+	}
+
+	tst_res(TINFO, "With offset less than or unalign sector size");
+	loopinfo.lo_offset = 256;
+	safe_set_status(dev_fd, loopinfo);
+
+	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+	if (TST_RET == 0) {
+		tst_res(TFAIL, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
+		return;
+	}
+	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");
+
+	loopinfo.lo_offset = 0;
+	safe_set_status(dev_fd, loopinfo);
+}
+
+static void setup(void)
+{
+	if (tst_fs_type(".") == TST_TMPFS_MAGIC)
+		tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag, skip it");
+
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num);
+	tst_fill_file("test.img", 0, 1024, 1024);
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);

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

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +10 -0
+	check_support_cmd(dev_fd, LOOP_SET_DIRECT_IO, 0, "LOOP_SET_DIRECT_IO");
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+	unlink("test.img");

We don't have to remove the image here once the needs_tmpdir has been uncommented below, right?

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

Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +8 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+//	.needs_tmpdir = 1,

Looks like a forgotten debug measure.

Quoted 13 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +5 -0
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	}
+};
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#53 lore raw

PATCH 7/10 syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test

Hi Cyril

Quoted 98 lines

Hi!

Quoted 97 lines

LOOP_SET_DIRECT_IO can updata a live loop device dio mode. It needs the backing file also supports dio mode and the lo_offset is aligned with the logical I/O size.

It was introduced into kernel since 4.10
commit ab1cb278bc70 ("block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO").

---
  runtest/syscalls                              |   1 +
  testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
  .../kernel/syscalls/ioctl/ioctl_loop05.c      | 120 ++++++++++++++++++
  3 files changed, 122 insertions(+)

create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c

runtest/syscalls +1 -0
index 6e8d71d44..9644588f3 100644
@@ -531,6 +531,7 @@ ioctl_loop01 ioctl_loop01
  ioctl_loop02 ioctl_loop02
  ioctl_loop03 ioctl_loop03
  ioctl_loop04 ioctl_loop04
+ioctl_loop05 ioctl_loop05
 
  ioctl_ns01 ioctl_ns01
  ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 039a5251c..f484d98d6 100644
@@ -10,6 +10,7 @@
  /ioctl_loop02
  /ioctl_loop03
  /ioctl_loop04
+/ioctl_loop05
  /ioctl_ns01
  /ioctl_ns02
  /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +52 -0
new file mode 100644
index 000000000..43bad6c18
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ *
+ * This is a basic ioctl test about loopdevice.
+ *
+ * It is designed to test LOOP_SET_DIRECT_IO can updata a live
+ * loop device dio mode. It need the backing file also supports
+ * dio mode and the lo_offset is aligned with the logical I/O size.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+#define DIO_MESSAGE "In dio mode"
+#define NON_DIO_MESSAGE "In non dio mode"
+
+static char dev_path[1024], sys_loop_diopath[1024];
+static int dev_num, dev_fd, attach_flag;
+
+static void check_dio_value(int flag)
+{
+	struct loop_info loopinfoget;
+
+	memset(&loopinfoget, 0, sizeof(loopinfoget));
+
+	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
+	tst_res(TINFO, "%s", flag ? DIO_MESSAGE : NON_DIO_MESSAGE);
+
+	if (loopinfoget.lo_flags & LO_FLAGS_DIRECT_IO)
+		tst_res(flag ? TPASS : TFAIL, "lo_flags has LO_FLAGS_DIRECT_IO flag");
+	else
+		tst_res(flag ? TFAIL : TPASS, "lo_flags doesn't have LO_FLAGS_DIRECT_IO flag");
+
+	check_sys_value(sys_loop_diopath, flag);
+}
+
+static void verify_ioctl_loop(void)
+{
+	struct loop_info loopinfo;
+
+	memset(&loopinfo, 0, sizeof(loopinfo));
+
+	SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
+	check_dio_value(0);
+	tst_res(TINFO, "Without setting lo_offset or sizelimit");
+	SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1);
Quoted 9 lines

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

Quoted 4 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +4 -0
+	check_dio_value(1);
+
+	tst_res(TINFO, "With offset equal to sector size");
+	loopinfo.lo_offset = 512;

We should use BLKSSZGET ioctl() to get the block size for direct I/O otherwise I would expect that it would break on one of the less common architectures. See also discussion at the end of man 2 open.

I see. Also, when testing LOOP_SET_BLOCK_SIZE ioctl, we can also call this to check whether this ioctl succeed.

Quoted 46 lines
Quoted 46 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +46 -0
+	safe_set_status(dev_fd, loopinfo);
+	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+	if (TST_RET == 0) {
+		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
+		check_dio_value(1);
+	} else {
+		tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed");
+	}
+
+	tst_res(TINFO, "With offset less than or unalign sector size");
+	loopinfo.lo_offset = 256;
+	safe_set_status(dev_fd, loopinfo);
+
+	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+	if (TST_RET == 0) {
+		tst_res(TFAIL, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
+		return;
+	}
+	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");
+
+	loopinfo.lo_offset = 0;
+	safe_set_status(dev_fd, loopinfo);
+}
+
+static void setup(void)
+{
+	if (tst_fs_type(".") == TST_TMPFS_MAGIC)
+		tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag, skip it");
+
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num);
+	tst_fill_file("test.img", 0, 1024, 1024);
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	check_support_cmd(dev_fd, LOOP_SET_DIRECT_IO, 0, "LOOP_SET_DIRECT_IO");
+}
+
+static void cleanup(void)
+{
Quoted 8 lines

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

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +5 -0
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+	unlink("test.img");

We don't have to remove the image here once the needs_tmpdir has been uncommented below, right?

Yes.

Quoted 12 lines

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

Quoted 9 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +8 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+//	.needs_tmpdir = 1,

Looks like a forgotten debug measure.

Yes, because some distribution use tmpfs in tmp directory, then this case will TCONF(tmpfs doesn't supprt DIO). I am indecisive, or I should
use all_filesystem =1, so it will not report TCONF? Or, keep it?

Quoted 14 lines
Quoted 13 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +5 -0
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	}
+};
Signature · 7 lines
2.23.0




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#54 lore raw

PATCH 7/10 syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl test

Hi!

Quoted 11 lines
Quoted 11 lines

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

Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file +8 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+//	.needs_tmpdir = 1,

Looks like a forgotten debug measure.

Quoted 3 lines

Yes, because some distribution use tmpfs in tmp directory, then this case will TCONF(tmpfs doesn't supprt DIO). I am indecisive, or I should
use all_filesystem =1, so it will not report TCONF? Or, keep it?

That will just create a loop device formatted with a filesystem and another loop device in that filesystem in most cases. I doubt that it will even work if we are doing all of that on the top of tmpfs anyways.

Signature · 1 line
[email protected]
author
#55 lore raw

PATCH 8/10 syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test

In reply to Yang Xu
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop06.c      | 90 +++++++++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop06.c
runtest/syscalls +1 -0
index 9644588f3..41774a494 100644
@@ -532,6 +532,7 @@ ioctl_loop02 ioctl_loop02
 ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
+ioctl_loop06 ioctl_loop06
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index f484d98d6..ec19b4901 100644
@@ -11,6 +11,7 @@
 /ioctl_loop03
 /ioctl_loop04
 /ioctl_loop05
+/ioctl_loop06
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop06.c new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#56 lore raw

PATCH 9/10 syscalls/ioctl_loop07: Add dio with logic block size error test

In reply to Yang Xu

This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE and LOOP_SET_DIRECT_IO. When blocksize is 1024(default align size is 512), set dio with 512 offset will fail.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop07.c      | 85 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c
runtest/syscalls +1 -0
index 41774a494..0e4dbaa77 100644
@@ -533,6 +533,7 @@ ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
 ioctl_loop06 ioctl_loop06
+ioctl_loop07 ioctl_loop07
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index ec19b4901..3a3d49adc 100644
@@ -12,6 +12,7 @@
 /ioctl_loop04
 /ioctl_loop05
 /ioctl_loop06
+/ioctl_loop07
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop07.c new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.23.0
author
#57 lore raw

PATCH 10/10 syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test

In reply to Yang Xu

Test its lo_sizelimit field. If lo_sizelimit is 0,it means max available. If sizelimit is less than loop_size, loopsize will be truncated.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop08.c      | 96 +++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop08.c
runtest/syscalls +1 -0
index 0e4dbaa77..d88848cb9 100644
@@ -534,6 +534,7 @@ ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
 ioctl_loop06 ioctl_loop06
 ioctl_loop07 ioctl_loop07
+ioctl_loop08 ioctl_loop08
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 3a3d49adc..97134aa0b 100644
@@ -13,6 +13,7 @@
 /ioctl_loop05
 /ioctl_loop06
 /ioctl_loop07
+/ioctl_loop08
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
testcases/kernel/syscalls/ioctl/ioctl_loop08.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.23.0