Skip to content

Commit

Permalink
fix(csi-node): cherry-pick remount staging path as ro before final um…
Browse files Browse the repository at this point in the history
…ount

Sometimes after/during disconnect we get some page write errors, triggered by a journal update by
the JBD2 worker task.
We don't really know how we can "flush" these tasks so at the moment the best solution we have is
to remount the staging path as RO before we umount it for good, which seems to help.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Nov 28, 2022
1 parent f429f45 commit 9a8a636
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
23 changes: 20 additions & 3 deletions csi/src/filesystem_vol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ pub async fn stage_fs_volume(
}
};

if mount::find_mount(Some(&device_path), Some(fs_staging_path)).is_some() {
if let Some(existing) =
mount::find_mount(Some(&device_path), Some(fs_staging_path))
{
debug!(
"Device {} is already mounted onto {}",
device_path, fs_staging_path
);

info!(
"Volume {} is already staged to {}",
volume_id, fs_staging_path
%existing,
"Volume {} is already staged to {}", volume_id, fs_staging_path
);

// todo: validate other flags?
if mnt.mount_flags.readonly() != existing.options.readonly() {
mount::remount(fs_staging_path, mnt.mount_flags.readonly())?;
}

return Ok(());
}

Expand Down Expand Up @@ -152,6 +161,14 @@ pub async fn unstage_fs_volume(
unkown_mount.source
));
}

// Sometimes after/during disconnect we get some page write errors,
// triggered by a journal update by the JBD2 worker task. We
// don't really know how we can "flush" these tasks so at the
// moment the best solution we have is to remount the staging path
// as RO before we umount it for good, which seems to help.
mount::remount(fs_staging_path, true)?;

if let Err(error) = mount::filesystem_unmount(fs_staging_path) {
return Err(failure!(
Code::Internal,
Expand Down
17 changes: 17 additions & 0 deletions csi/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@ pub fn bind_unmount(target: &str) -> Result<(), Error> {
Ok(())
}

/// Remount existing mount as read only or read write.
pub(crate) fn remount(target: &str, ro: bool) -> Result<Mount, Error> {
let mut flags = MountFlags::empty();
flags.insert(MountFlags::REMOUNT);

if ro {
flags.insert(MountFlags::RDONLY);
}

let mount =
Mount::new("", target, FilesystemType::Manual("none"), flags, None)?;

debug!("Target {} remounted with {:?}", target, flags);

Ok(mount)
}

/// Mount a block device
pub fn blockdevice_mount(
source: &str,
Expand Down

0 comments on commit 9a8a636

Please sign in to comment.