mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-12 12:29:11 +00:00
Merge pull request #8332 from Apokleos/bugfix-directvol-multicontainers
runitme-rs/bugfix: kata pod with multi-containers sharing one direct volume
This commit is contained in:
@@ -35,7 +35,6 @@ impl BlockVolume {
|
||||
d: &RwLock<DeviceManager>,
|
||||
m: &oci::Mount,
|
||||
read_only: bool,
|
||||
cid: &str,
|
||||
sid: &str,
|
||||
) -> Result<Self> {
|
||||
let mnt_src: &str = &m.source;
|
||||
@@ -97,23 +96,16 @@ impl BlockVolume {
|
||||
.await
|
||||
.context("do handle device failed.")?;
|
||||
|
||||
// generate host guest shared path
|
||||
let guest_path = generate_shared_path(m.destination.clone(), read_only, cid, sid)
|
||||
.await
|
||||
.context("generate host-guest shared path failed")?;
|
||||
|
||||
// storage
|
||||
let mut storage = agent::Storage {
|
||||
mount_point: guest_path.clone(),
|
||||
options: if read_only {
|
||||
vec!["ro".to_string()]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
storage.options = if read_only {
|
||||
vec!["ro".to_string()]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
// As the true Block Device wrapped in DeviceType, we need to
|
||||
// get it out from the wrapper, and the device_id will be for
|
||||
// BlockVolume.
|
||||
@@ -127,6 +119,12 @@ impl BlockVolume {
|
||||
device_id = device.device_id;
|
||||
}
|
||||
|
||||
// generate host guest shared path
|
||||
let guest_path = generate_shared_path(m.destination.clone(), read_only, &device_id, sid)
|
||||
.await
|
||||
.context("generate host-guest shared path failed")?;
|
||||
storage.mount_point = guest_path.clone();
|
||||
|
||||
// In some case, dest is device /dev/xxx
|
||||
if m.destination.clone().starts_with("/dev") {
|
||||
storage.fs_type = "bind".to_string();
|
||||
|
@@ -77,7 +77,7 @@ impl VolumeResource {
|
||||
} else if is_block_volume(m).context("block volume type")? {
|
||||
// handle block volume
|
||||
Arc::new(
|
||||
block_volume::BlockVolume::new(d, m, read_only, cid, sid)
|
||||
block_volume::BlockVolume::new(d, m, read_only, sid)
|
||||
.await
|
||||
.with_context(|| format!("new share fs volume {:?}", m))?,
|
||||
)
|
||||
|
@@ -57,13 +57,13 @@ pub fn get_file_name<P: AsRef<Path>>(src: P) -> Result<String> {
|
||||
pub(crate) async fn generate_shared_path(
|
||||
dest: String,
|
||||
read_only: bool,
|
||||
cid: &str,
|
||||
device_id: &str,
|
||||
sid: &str,
|
||||
) -> Result<String> {
|
||||
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 guest_path = do_get_guest_path(&mount_name, cid, true, false);
|
||||
let host_path = do_get_host_path(&mount_name, sid, cid, true, read_only);
|
||||
let mount_name = generate_mount_path(device_id, file_name.as_str());
|
||||
let guest_path = do_get_guest_path(&mount_name, device_id, true, false);
|
||||
let host_path = do_get_host_path(&mount_name, sid, device_id, true, read_only);
|
||||
|
||||
if dest.starts_with("/dev") {
|
||||
fs::File::create(&host_path).context(format!("failed to create file {:?}", &host_path))?;
|
||||
|
Reference in New Issue
Block a user