Skip to contentSkip to conversation

fsconfig04: Check FSCONFIG_SET_PATH

PATCH In review Wei Gao via ltp 2 participants 5 messages Nov 16 Library code

lore
Share & tools
lore
#0 lore raw

v19 cover fsconfig04: Check FSCONFIG_SET_PATH

v18->v19:
- Update tst_attach_loopdev take the file name as ONLY parameter and return newly allocated string with the path to the device it was attached to.

Wei Gao (3):
lib: Add tst_attach_loopdev()
newlib_tests: Add tst_attach_loopdev test
fsconfig04: Check FSCONFIG_SET_PATH

 include/tst_device.h                          |  26 +++
 lib/newlib_tests/.gitignore                   |   1 +
 lib/newlib_tests/runtest.sh                   |   1 +
 lib/newlib_tests/tst_attach_loopdev.c         | 145 +++++++++++++++
 lib/tst_device.c                              |  82 ++++++++-
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/fsconfig/.gitignore |   1 +
 .../kernel/syscalls/fsconfig/fsconfig04.c     | 167 ++++++++++++++++++
 8 files changed, 417 insertions(+), 7 deletions(-)
 create mode 100644 lib/newlib_tests/tst_attach_loopdev.c
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig04.c
Signature · 5 lines
2.55.0


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

PATCH v19 1/3 lib: Add tst_attach_loopdev()

Calling tst_find_free_loopdev() followed by tst_attach_device() has a race window where another process can claim the loop device before LOOP_SET_FD is issued, causing attachment to fail with EBUSY.

Introduce tst_attach_loopdev() which finds an unused loop device and attaches a backing file to it, retrying the lookup with exponential backoff if the candidate device is claimed concurrently (EBUSY). The function returns a newly allocated string containing the device path on success, or NULL on failure. Also introduce the SAFE_ATTACH_LOOPDEV() helper macro.

Update tst_acquire_loop_device() to use tst_attach_loopdev().

---
 include/tst_device.h | 26 ++++++++++++++
 lib/tst_device.c     | 82 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 101 insertions(+), 7 deletions(-)
include/tst_device.h +26 -0
index 0989e4501..4e2e14b89 100644
@@ -110,6 +110,32 @@ int tst_find_free_loopdev(char *path, size_t path_len);
  */
 int tst_attach_device(const char *dev_path, const char *file_path);
 
+/**
+ * tst_attach_loopdev() - Find a free loop device and attach a file to it.
+ * @file_path: Path to a file (e.g. disk.img).
+ *
+ * Finds an unused loop device and attaches @file_path to it, automatically
+ * retrying the lookup if the chosen device is claimed concurrently (EBUSY).
+ *
+ * Return: Newly allocated string containing the device path on success,
+ *         or NULL on failure. Caller is responsible for free()-ing the string.
+ */
+char *tst_attach_loopdev(const char *file_path);
+
+/**
+ * safe_attach_loopdev() - Safe wrapper for tst_attach_loopdev().
+ * @file: Source file where called.
+ * @lineno: Line number where called.
+ * @file_path: Path to a file (e.g. disk.img).
+ *
+ * Return: Newly allocated string containing the device path. Calls tst_brk()
+ *         on failure. Caller is responsible for free()-ing the string.
+ */
+char *safe_attach_loopdev(const char *file, const int lineno, const char *file_path);
+
+#define SAFE_ATTACH_LOOPDEV(file_path) \
+	safe_attach_loopdev(__FILE__, __LINE__, (file_path))
+
 /**
  * tst_get_device_size() - Get device size in megabytes.
  * @dev_path: Device path.
lib/tst_device.c +75 -7

122 lines not on this page · raw message

Signature · 5 lines
2.55.0


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

Re: [LTP] lib: Add tst_attach_loopdev()

Hi Wei,

Quoted 1 line · Wei Gao

lib: Add tst_attach_loopdev()

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v19 2/3 newlib_tests: Add tst_attach_loopdev test

In reply to Wei Gao via ltp

Add a unit test in lib/newlib_tests/ to verify the newly added tst_attach_loopdev() function.

The test covers:
- Concurrent allocation of multiple loop devices without collisions.
- Parallel worker stress testing to exercise the exponential backoff retry loop upon transient EBUSY conditions.

---
 lib/newlib_tests/.gitignore           |   1 +
 lib/newlib_tests/runtest.sh           |   1 +
 lib/newlib_tests/tst_attach_loopdev.c | 145 ++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 lib/newlib_tests/tst_attach_loopdev.c
lib/newlib_tests/.gitignore +1 -0
index 3a6e1643c..2d4b3d43f 100644
@@ -11,6 +11,7 @@ test11
 test13
 test14
 test15
+tst_attach_loopdev
 tst_capability01
 tst_capability02
 tst_cgroup01
lib/newlib_tests/runtest.sh +1 -0
index 71808ef8b..18b64c07a 100755
@@ -16,6 +16,7 @@ test_zero_hugepage.sh
 test0[579]
 test1[59]
 test2[04]
+tst_attach_loopdev
 tst_bool_expr
 tst_capability02
 tst_checkpoint
lib/newlib_tests/tst_attach_loopdev.c new file +145 -0

145 lines not on this page · raw message

Signature · 5 lines
2.55.0


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

PATCH v19 3/3 fsconfig04: Check FSCONFIG_SET_PATH

In reply to Wei Gao via ltp

The fsconfig01.c does not test if FSCONFIG_SET_PATH has any effect; most of the calls there just set a dummy "sync" parameter. This test case aims to verify if the FSCONFIG_SET_PATH operation can be used to dynamically change the external journal device of an ext3 or ext4 filesystem.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/fsconfig/.gitignore |   1 +
 .../kernel/syscalls/fsconfig/fsconfig04.c     | 167 ++++++++++++++++++
 3 files changed, 169 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig04.c
runtest/syscalls +1 -0
index 7b6a7d376..58d26571d 100644
@@ -452,6 +452,7 @@ fremovexattr02 fremovexattr02
 fsconfig01 fsconfig01
 fsconfig02 fsconfig02
 fsconfig03 fsconfig03
+fsconfig04 fsconfig04
 
 fsmount01 fsmount01
 fsmount02 fsmount02
testcases/kernel/syscalls/fsconfig/.gitignore +1 -0
index cfedae5f7..bd3754c34 100644
@@ -1,3 +1,4 @@
 /fsconfig01
 /fsconfig02
 /fsconfig03
+/fsconfig04
testcases/kernel/syscalls/fsconfig/fsconfig04.c new file +167 -0

167 lines not on this page · raw message

Signature · 5 lines
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp