[pbs-devel] [PATCH proxmox-backup v9 24/26] api: node: include removable datastores in directory list

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Apr 24 15:06:33 CEST 2024


On Tue, Apr 23, 2024 at 10:29:58AM +0200, Hannes Laimer wrote:
> Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
> ---
>  src/api2/node/disks/directory.rs | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs
> index 34304216..f7e4a1a3 100644
> --- a/src/api2/node/disks/directory.rs
> +++ b/src/api2/node/disks/directory.rs
> @@ -43,6 +43,8 @@ pub struct DatastoreMountInfo {
>      pub path: String,
>      /// The mounted device.
>      pub device: String,
> +    /// This is removable
> +    pub removable: bool,
>      /// File system type
>      pub filesystem: Option<String>,
>      /// Mount options
> @@ -59,7 +61,7 @@ pub struct DatastoreMountInfo {
>          }
>      },
>      returns: {
> -        description: "List of systemd datastore mount units.",
> +        description: "List of removable-datastore devices and systemd datastore mount units.",
>          type: Array,
>          items: {
>              type: DatastoreMountInfo,
> @@ -99,6 +101,28 @@ pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
>              path: data.Where,
>              filesystem: data.Type,
>              options: data.Options,
> +            removable: false,
> +        });
> +    }
> +
> +    let (config, _digest) = pbs_config::datastore::config()?;
> +    let store_list: Vec<DataStoreConfig> = config.convert_to_typed_array("datastore")?;
> +
> +    for item in store_list
> +        .into_iter()
> +        .filter(|store| store.backing_device.is_some())
> +    {

This checks that backing_device is Some, but then below you use unwraps
on that Option.
Just do

    for item in store_list {
        let Some(backing_device) = item.backing_device.as_deref() else {
            continue;
        };

> +        list.push(DatastoreMountInfo {
> +            unitfile: "datastore config".to_string(),
> +            name: item.name.clone(),
> +            device: format!(
> +                "/dev/disk/by-uuid/{}",
> +                item.backing_device.as_ref().unwrap_or(&"none".to_string())
> +            ),

            device: format!("/dev/disk/by-uuid/{backing_device}"),

^ since we then already have it available

> +            path: item.get_mount_point().unwrap_or("none".to_string()),
> +            filesystem: None,
> +            options: None,
> +            removable: item.backing_device.is_some(),

            removable: true,

^ since we only iterate over items with backing devices

>          });
>      }
>  
> -- 
> 2.39.2




More information about the pbs-devel mailing list