Skip to content

Commit

Permalink
Check disks that udev does not know about
Browse files Browse the repository at this point in the history
I frequently find that dead disks are still considered mounted
by mtab but udev doesn't know about them when you list all
devices.
  • Loading branch information
cholcombe973 committed Sep 20, 2017
1 parent 188a74c commit 8c1275e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 44 deletions.
79 changes: 40 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ fn main() {
error!("Check for failed disks failed with error: {}", e);
}
_ => {
info!("check_for_failed_disks completed");
info!("Check for failed disks completed");
}
};
match add_repaired_disks(config_dir, simulate) {
Err(e) => {
error!("add_repaired_disks failed with error: {}", e);
error!("Add repaired disks failed with error: {}", e);
}
_ => {
info!("add_repaired_disks completed");
info!("Add repaired disks completed");
}
};
}
22 changes: 20 additions & 2 deletions src/test_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
//! +----->disk_is_ok +---->unmoun
//extern crate blkid;
extern crate block_utils;
extern crate fstab;
extern crate libatasmart;
extern crate log;
extern crate mktemp;

use self::block_utils::{Device, get_block_devices, get_mount_device, get_mountpoint,
FilesystemType, is_mounted, MediaType, RaidType};
use self::fstab::{FsEntry, FsTab};
use self::mktemp::Temp;

use std::fs::{File, OpenOptions};
Expand All @@ -41,6 +43,9 @@ pub struct Status {

pub fn check_all_disks() -> Result<Vec<Result<Status>>> {
let mut results: Vec<Result<Status>> = Vec::new();
// Udev will only show the disks that are currently attached to the tree
// It will fail to show disks that have died and disconnected but are still
// shown as mounted in /etc/mtab
let devices = block_utils::get_block_devices().map_err(|e| {
Error::new(ErrorKind::Other, e)
})?;
Expand All @@ -57,9 +62,22 @@ pub fn check_all_disks() -> Result<Vec<Result<Status>>> {
.filter(|d| !(d.media_type == MediaType::Ram))
.collect();

for device in device_info {
results.push(run_checks(&device));
// Gather info on all the currently mounted devices
let mut mtab_devices: Vec<Device> = block_utils::get_mounted_devices()?;

// Remove any mtab_devices that udev already knows about leaving only ones
// that udev doesn't know about, ie broken mounted devices
mtab_devices.retain(|mtab_device| {
!device_info.iter().any(|udev_device| {
mtab_device.name.contains(&udev_device.name)
})
});

// Check any devices that udev doesn't know about that are still mounted
for mtab_device in mtab_devices {
results.push(run_checks(&mtab_device));
}

Ok(results)
}

Expand Down

0 comments on commit 8c1275e

Please sign in to comment.