runtime-rs: correct the path from cid to device_id.

When a direct volume is used by multiple containers in Kata,
Generating many shared paths with cids will cause IO error
as the result of one direct volume mounts more than once.
To correct it, use the device_id instead of cid which
ensures that the guest only mounts the FS once.

Fixes: #8328

Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn 2023-11-15 10:18:08 +08:00
parent 906f6b7380
commit d7594d830c

View File

@ -57,13 +57,13 @@ pub fn get_file_name<P: AsRef<Path>>(src: P) -> Result<String> {
pub(crate) async fn generate_shared_path( pub(crate) async fn generate_shared_path(
dest: String, dest: String,
read_only: bool, read_only: bool,
cid: &str, device_id: &str,
sid: &str, sid: &str,
) -> Result<String> { ) -> Result<String> {
let file_name = get_file_name(&dest).context("failed to get file name.")?; let file_name = get_file_name(&dest).context("failed to get file name.")?;
let mount_name = generate_mount_path(cid, file_name.as_str()); let mount_name = generate_mount_path(device_id, file_name.as_str());
let guest_path = do_get_guest_path(&mount_name, cid, true, false); let guest_path = do_get_guest_path(&mount_name, device_id, true, false);
let host_path = do_get_host_path(&mount_name, sid, cid, true, read_only); let host_path = do_get_host_path(&mount_name, sid, device_id, true, read_only);
if dest.starts_with("/dev") { if dest.starts_with("/dev") {
fs::File::create(&host_path).context(format!("failed to create file {:?}", &host_path))?; fs::File::create(&host_path).context(format!("failed to create file {:?}", &host_path))?;