LCOV - code coverage report
Current view: top level - compute_tools/src - disk_quota.rs (source / functions) Coverage Total Hit
Test: e5024a5c05016c30dec7897aca22d1040a340f63.info Lines: 0.0 % 19 0
Test Date: 2024-11-20 11:45:54 Functions: 0.0 % 4 0

            Line data    Source code
       1              : use anyhow::Context;
       2              : 
       3              : pub const DISK_QUOTA_BIN: &str = "/neonvm/bin/set-disk-quota";
       4              : 
       5              : /// If size_bytes is 0, it disables the quota. Otherwise, it sets filesystem quota to size_bytes.
       6              : /// `fs_mountpoint` should point to the mountpoint of the filesystem where the quota should be set.
       7            0 : pub fn set_disk_quota(size_bytes: u64, fs_mountpoint: &str) -> anyhow::Result<()> {
       8            0 :     let size_kb = size_bytes / 1024;
       9            0 :     // run `/neonvm/bin/set-disk-quota {size_kb} {mountpoint}`
      10            0 :     let child_result = std::process::Command::new("/usr/bin/sudo")
      11            0 :         .arg(DISK_QUOTA_BIN)
      12            0 :         .arg(size_kb.to_string())
      13            0 :         .arg(fs_mountpoint)
      14            0 :         .spawn();
      15            0 : 
      16            0 :     child_result
      17            0 :         .context("spawn() failed")
      18            0 :         .and_then(|mut child| child.wait().context("wait() failed"))
      19            0 :         .and_then(|status| match status.success() {
      20            0 :             true => Ok(()),
      21            0 :             false => Err(anyhow::anyhow!("process exited with {status}")),
      22            0 :         })
      23            0 :         // wrap any prior error with the overall context that we couldn't run the command
      24            0 :         .with_context(|| format!("could not run `/usr/bin/sudo {DISK_QUOTA_BIN}`"))
      25            0 : }
        

Generated by: LCOV version 2.1-beta