Skip to content

Commit e7f22ef

Browse files
committed
chore: include file name in the BackingFile
If the file cannot be found, it's not clear what file Firecracker is referring to. Be explicit about what file it failed to find. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent e34ff13 commit e7f22ef

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/devices/src/virtio/block/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl DiskProperties {
9393
.read(true)
9494
.write(!is_disk_read_only)
9595
.open(PathBuf::from(&disk_image_path))
96-
.map_err(Error::BackingFile)?;
96+
.map_err(|x| Error::BackingFile(x, disk_image_path.clone()))?;
9797
let disk_size = disk_image
9898
.seek(SeekFrom::End(0))
99-
.map_err(Error::BackingFile)?;
99+
.map_err(|x| Error::BackingFile(x, disk_image_path.clone()))?;
100100

101101
// We only support disk size, which uses the first two words of the configuration space.
102102
// If the image is not a multiple of the sector size, the tail bits are not exposed.

src/devices/src/virtio/block/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum Error {
4545
// Error coming from the IO engine.
4646
FileEngine(io::Error),
4747
// Error manipulating the backing file.
48-
BackingFile(std::io::Error),
48+
BackingFile(std::io::Error, String),
4949
// Error opening eventfd.
5050
EventFd(std::io::Error),
5151
// Error creating an irqfd.

tests/integration_tests/functional/test_api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,33 +871,36 @@ def _drive_patch(test_microvm):
871871
assert test_microvm.api_session.is_status_bad_request(response.status_code)
872872
assert "at least one property to patch: path_on_host, rate_limiter" in response.text
873873

874+
drive_path = "foo.bar"
875+
874876
# Cannot patch drive permissions post boot.
875877
response = test_microvm.drive.patch(
876-
drive_id="scratch", path_on_host="foo.bar", is_read_only=True
878+
drive_id="scratch", path_on_host=drive_path, is_read_only=True
877879
)
878880
assert test_microvm.api_session.is_status_bad_request(response.status_code)
879881
assert "unknown field `is_read_only`" in response.text
880882

881883
# Cannot patch io_engine post boot.
882884
response = test_microvm.drive.patch(
883-
drive_id="scratch", path_on_host="foo.bar", io_engine="Sync"
885+
drive_id="scratch", path_on_host=drive_path, io_engine="Sync"
884886
)
885887
assert test_microvm.api_session.is_status_bad_request(response.status_code)
886888
assert "unknown field `io_engine`" in response.text
887889

888890
# Updates to `is_root_device` with a valid value are not allowed.
889891
response = test_microvm.drive.patch(
890-
drive_id="scratch", path_on_host="foo.bar", is_root_device=False
892+
drive_id="scratch", path_on_host=drive_path, is_root_device=False
891893
)
892894
assert test_microvm.api_session.is_status_bad_request(response.status_code)
893895
assert "unknown field `is_root_device`" in response.text
894896

895897
# Updates to `path_on_host` with an invalid path are not allowed.
896-
response = test_microvm.drive.patch(drive_id="scratch", path_on_host="foo.bar")
898+
response = test_microvm.drive.patch(drive_id="scratch", path_on_host=drive_path)
897899
assert test_microvm.api_session.is_status_bad_request(response.status_code)
898900
assert (
899901
"Unable to patch the block device: BackingFile(Os { code: 2, "
900-
'kind: NotFound, message: \\"No such file or directory\\" })' in response.text
902+
f'kind: NotFound, message: \\"No such file or directory\\" }}, \\"{drive_path}\\")'
903+
in response.text
901904
)
902905

903906
fs = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, "scratch_new"))

0 commit comments

Comments
 (0)