summaryrefslogtreecommitdiff
path: root/src/test/test-loop-block.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-12-01 17:17:46 +0100
committerLennart Poettering <lennart@poettering.net>2022-12-01 22:07:36 +0100
commit59a4c0d7e362269c708ab8359f7e47e952ab245e (patch)
tree37656efa2d9951362cbfeec40aeec83a2339c460 /src/test/test-loop-block.c
parent9f2d9a4aaba63d3b93d72e776413c8ed5c86e3fb (diff)
downloadsystemd-59a4c0d7e362269c708ab8359f7e47e952ab245e.tar.gz
test-loop-block: let's explicitly flush buffer cache on whole block device
Let's explicitly flush the kernel's buffer cache on the whole block device once we ran "mkfs". This is necessary, because partition and whole block devices maintain separate buffer caches, and thus writing to one will not be visible on the other if cached there already, until the latter's cache is explicitly flushed. This is preparation for later adding support for probing file sytems also if we have no open partition block devices, and hence want to use the whole block device instead.
Diffstat (limited to 'src/test/test-loop-block.c')
-rw-r--r--src/test/test-loop-block.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c
index 01db8b092e..b06ab0d172 100644
--- a/src/test/test-loop-block.c
+++ b/src/test/test-loop-block.c
@@ -4,6 +4,8 @@
#include <linux/loop.h>
#include <pthread.h>
#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
#include "alloc-util.h"
#include "capability-util.h"
@@ -256,6 +258,13 @@ static int run(int argc, char *argv[]) {
dissected = dissected_image_unref(dissected);
+ /* We created the file systems now via the per-partition block devices. But the dissection code might
+ * probe them via the whole block device. These block devices have separate buffer caches though,
+ * hence what was written via the partition device might not appear on the whole block device
+ * yet. Let's hence explicitly flush the whole block device, so that the read-back definitely
+ * works. */
+ assert_se(ioctl(loop->fd, BLKFLSBUF, 0) >= 0);
+
/* Try to read once, without pinning or adding partitions, i.e. by only accessing the whole block
* device. */
assert_se(dissect_loop_device(loop, NULL, NULL, 0, &dissected) >= 0);