LCOV - code coverage report
Current view: top level - compute_tools/src - disk_quota.rs (source / functions) Coverage Total Hit
Test: 1b0a6a0c05cee5a7de360813c8034804e105ce1c.info Lines: 0.0 % 6 0
Test Date: 2025-03-12 00:01:28 Functions: 0.0 % 3 0

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

Generated by: LCOV version 2.1-beta