Skip to content

Commit 10af1df

Browse files
kalyazinroypat
authored andcommitted
test(drive): add support for drive creation on disk
So far, FilesystemFile was only creating drives in the default /srv location, which is mounted as tmpfs. Since Qemu vhost-user-blk backend always uses O_DIRECT when opening drive files, it cannot work with files on tmpfs. If the path argument is not provided to the FilesystemFile constructor, the drive file is created with a random name in /tmp. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent 8d1f58b commit 10af1df

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/host_tools/drive.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Utilities for creating filesystems on the host."""
44

55
import os
6+
import tempfile
67

78
from framework import utils
89

@@ -13,12 +14,20 @@ class FilesystemFile:
1314
KNOWN_FILEFS_FORMATS = {"ext4"}
1415
path = None
1516

16-
def __init__(self, path: str, size: int = 256, fs_format: str = "ext4"):
17+
def __init__(self, path: str = None, size: int = 256, fs_format: str = "ext4"):
1718
"""Create a new file system in a file.
1819
1920
Raises if the file system format is not supported, if the file already
2021
exists, or if it ends in '/'.
2122
"""
23+
24+
# If no path is supplied, use a temporary file.
25+
# This is useful to force placing the file on disk, not in memory,
26+
# because qemu vhost-user-blk backend always uses O_DIRECT,
27+
# but O_DIRECT is not supported by tmpfs.
28+
if path is None:
29+
_, path = tempfile.mkstemp(suffix=f".{fs_format}", dir="/tmp")
30+
2231
if fs_format not in self.KNOWN_FILEFS_FORMATS:
2332
raise ValueError("Format not in: + " + str(self.KNOWN_FILEFS_FORMATS))
2433
# Here we append the format as a

0 commit comments

Comments
 (0)