all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Hannes Laimer <h.laimer@proxmox.com>
Cc: pbs-devel@lists.proxmox.com, Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/5] pbs-datastore: add check_maintenence function
Date: Fri, 1 Oct 2021 14:06:35 +0200	[thread overview]
Message-ID: <20211001120635.eqr5plsa3fsyigpw@wobu-vie.proxmox.com> (raw)
In-Reply-To: <20210928100548.4873-3-h.laimer@proxmox.com>

On Tue, Sep 28, 2021 at 12:05:45PM +0200, Hannes Laimer wrote:
> This function checks if something is allowed in a specific maintenance
> type, it has to be called whenever something depends on maintenance to
> be off or less rescrictive than a specific type.
> ---
>  pbs-datastore/src/datastore.rs | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
> index b068a9c9..1014b357 100644
> --- a/pbs-datastore/src/datastore.rs
> +++ b/pbs-datastore/src/datastore.rs
> @@ -11,7 +11,7 @@ use lazy_static::lazy_static;
>  
>  use proxmox::tools::fs::{replace_file, file_read_optional_string, CreateOptions};
>  
> -use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus};
> +use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus, MaintenanceType};
>  use pbs_tools::format::HumanByte;
>  use pbs_tools::fs::{lock_dir_noblock, DirLockGuard};
>  use pbs_tools::process_locker::ProcessLockSharedGuard;
> @@ -98,6 +98,22 @@ impl DataStore {
>          Ok(())
>      }
>  
> +    /// checks if the current maintenace mode of the datastore allows something
> +    pub fn check_maintenance(&self, need_less_than: MaintenanceType) -> Result<(), Error> {

I'd very much like the method name itself to suggest the direction of
such a check, rather than have only the parameter name tell you this,
not even the doc comment ;-)
When you read `datastore.check_maintenance(foo)` the parameter name
isn't actually visible in code, but the code should speak for itself.

And like Dominik said, it's a confusing interface. Plus, I can't think
if a really good name for the method that fixes my remark above.

So maybe the public facing interface should just be:

    pub fn can_read(&self) -> bool;
    pub fn can_write(&self) -> bool;

and/or

    pub fn check_read(&self) -> Result<(), Error>;
    pub fn check_write(&self) -> Result<(), Error>;

with the error including the maintenance message

> +        let (config, _digest) = pbs_config::datastore::config()?;
> +        let config: DataStoreConfig = config.lookup("datastore", &self.name())?;
> +        if let Some(maintenance_type) = config.maintenance_type {
> +            if maintenance_type >= need_less_than {
> +                bail!("Datastore '{}' is in maintenance {} mode: {}", 
> +                    &self.name(),
> +                    maintenance_type,
> +                    config.maintenance_msg.unwrap_or(String::from("no description"))
> +                ); 
> +            }
> +        }
> +        Ok(())
> +    }
> +
>      fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result<Self, Error> {
>          let chunk_store = ChunkStore::open(store_name, path)?;
>  
> -- 
> 2.30.2




  reply	other threads:[~2021-10-01 12:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 10:05 [pbs-devel] [PATCH proxmox-backup 0/5] maintenance mode for datastore Hannes Laimer
2021-09-28 10:05 ` [pbs-devel] [PATCH proxmox-backup 1/5] pbs-api-types: add maintenance type and msg to ds config Hannes Laimer
2021-10-01  8:23   ` Dominik Csapak
2021-10-01 12:00     ` Wolfgang Bumiller
2021-09-28 10:05 ` [pbs-devel] [PATCH proxmox-backup 2/5] pbs-datastore: add check_maintenence function Hannes Laimer
2021-10-01 12:06   ` Wolfgang Bumiller [this message]
2021-09-28 10:05 ` [pbs-devel] [PATCH proxmox-backup 3/5] api2: make maintenance type and msg updatable/deletable Hannes Laimer
2021-09-28 10:05 ` [pbs-devel] [PATCH proxmox-backup 4/5] jobs/api2: add checks for maintenance Hannes Laimer
2021-10-01  8:28   ` Dominik Csapak
2021-09-28 10:05 ` [pbs-devel] [PATCH proxmox-backup 5/5] ui: add maintenance to datastore options Hannes Laimer
2021-10-01  8:36   ` Dominik Csapak
2021-10-01  8:18 ` [pbs-devel] [PATCH proxmox-backup 0/5] maintenance mode for datastore Dominik Csapak
2021-10-01  9:36 ` Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211001120635.eqr5plsa3fsyigpw@wobu-vie.proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=h.laimer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal