From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 38CFD20EC88
	for <inbox@lore.proxmox.com>; Wed, 24 Apr 2024 15:07:06 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 64458CCEF;
	Wed, 24 Apr 2024 15:07:11 +0200 (CEST)
Date: Wed, 24 Apr 2024 15:06:33 +0200
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Hannes Laimer <h.laimer@proxmox.com>
Message-ID: <fuincz4ymrlb7hz6eoqhh2zi3tkel2w3wh5tk4fmc45ixvtu6p@ordyvwfafp57>
References: <20240423083000.28002-1-h.laimer@proxmox.com>
 <20240423083000.28002-25-h.laimer@proxmox.com>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20240423083000.28002-25-h.laimer@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.085 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [directory.rs]
Subject: Re: [pbs-devel] [PATCH proxmox-backup v9 24/26] api: node: include
 removable datastores in directory list
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

On Tue, Apr 23, 2024 at 10:29:58AM +0200, Hannes Laimer wrote:
> Signed-off-by: Hannes Laimer <h.laimer@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


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel