]>
git.proxmox.com Git - proxmox-backup.git/blob - src/tools/disks/lvm.rs
1 use std
::collections
::HashSet
;
2 use std
::os
::unix
::fs
::MetadataExt
;
6 use lazy_static
::lazy_static
;
11 static ref LVM_UUIDS
: HashSet
<&'
static str> = {
12 let mut set
= HashSet
::new();
13 set
.insert("e6d6d379-f507-44c2-a23c-238f2a3df928");
18 /// Get set of devices used by LVM (pvs).
20 /// The set is indexed by using the unix raw device number (dev_t is u64)
21 pub fn get_lvm_devices(
22 lsblk_info
: &[LsblkInfo
],
23 ) -> Result
<HashSet
<u64>, Error
> {
25 const PVS_BIN_PATH
: &str = "pvs";
27 let mut command
= std
::process
::Command
::new(PVS_BIN_PATH
);
28 command
.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]);
30 let output
= proxmox_sys
::command
::run_command(command
, None
)?
;
32 let mut device_set
: HashSet
<u64> = HashSet
::new();
34 for info
in lsblk_info
.iter() {
35 if let Some(partition_type
) = &info
.partition_type
{
36 if LVM_UUIDS
.contains(partition_type
.as_str()) {
37 let meta
= std
::fs
::metadata(&info
.path
)?
;
38 device_set
.insert(meta
.rdev());
43 let output
: Value
= output
.parse()?
;
45 match output
["report"][0]["pv"].as_array() {
48 if let Some(pv_name
) = info
["pv_name"].as_str() {
49 let meta
= std
::fs
::metadata(pv_name
)?
;
50 device_set
.insert(meta
.rdev());
54 None
=> return Ok(device_set
),