Skip to content

Commit

Permalink
✨ Create @snapshots subvolume if it does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Jun 13, 2022
1 parent 6a79f48 commit f41467a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions service/src/snapshot/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use super::MountedBtrfs;
use crate::util::find_root_device;
use anyhow::{Context, Result};
use libbtrfsutil::CreateSubvolumeFlags;
use sys_mount::{FilesystemType, Mount, UnmountFlags};

impl MountedBtrfs {
Expand All @@ -15,6 +16,7 @@ impl MountedBtrfs {
.context("failed to find root device")?;
debug!("Found root device path at {}", root_device_path.display());
let tempdir_path = tempdir.path().to_path_buf();
let snapshots_path = tempdir_path.join("@snapshots");

debug!(
"Mounting {}[subvol=/] at {}",
Expand All @@ -30,6 +32,18 @@ impl MountedBtrfs {
.await?
.context("failed to mount root subvolume")?;

if !snapshots_path.exists() {
let pop_snapshots_dir = snapshots_path.join("pop-snapshots");
tokio::task::spawn_blocking(move || {
libbtrfsutil::create_subvolume(snapshots_path, CreateSubvolumeFlags::empty(), None)
})
.await?
.context("failed to create snapshot subvolume")?;
tokio::fs::create_dir(&pop_snapshots_dir)
.await
.with_context(|| format!("failed to create {}", pop_snapshots_dir.display()))?;
}

Ok(MountedBtrfs {
_mount: mount,
tempdir,
Expand Down

0 comments on commit f41467a

Please sign in to comment.