Description
The file backing Firecracker's block device, like any other rust File
is closed when going out of scope or when calling drop
on the File
, without any error handling: https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/fd.rs#L284.
This may be a design flaw of rust's File
struct, since the linux man page states that:
Not checking the return value of close() is a common but nevertheless serious programming error. It is quite possible that errors on a previous write(2) operation are first reported at the final close(). Not checking the return value when closing the file may lead to silent loss of data.
One thing we can do to ensure that the subsequent close()
will run successfully is calling fsync()
on the file descriptor in advance.
This can be done as a Drop
implementation for the DiskProperties
member struct of the block device.
As far as I can tell, there is not much we can do to handle the potential error and data loss, apart from logging it, which may still be useful.