[pbs-devel] [PATCH proxmox-backup v4 1/2] fix #5439: allow to reuse existing datastore

Gabriel Goller g.goller at proxmox.com
Thu Aug 29 10:12:42 CEST 2024


On 28.08.2024 15:48, Wolfgang Bumiller wrote:
>On Wed, Aug 14, 2024 at 10:57:11AM GMT, Gabriel Goller wrote:
>> [skip]
>>      /// Opens the chunk store with a new process locker.
>>      ///
>>      /// Note that this must be used with care, as it's dangerous to create two instances on the
>>      /// same base path, as closing the underlying ProcessLocker drops all locks from this process
>>      /// on the lockfile (even if separate FDs)
>> -    pub(crate) fn open<P: Into<PathBuf>>(
>> +    pub fn open<P: Into<PathBuf>>(
>
>^ This is not used and should be dropped.

Correct, no idea why I did this.

>> [skip]
>> +    /// Checks permissions and owner of passed path.
>> +    fn check_permissions<T: AsRef<Path>>(path: T, file_mode: u32) -> Result<(), Error> {
>> +        match nix::sys::stat::stat(path.as_ref()) {
>> +            Ok(stat) => {
>> +                if stat.st_uid != u32::from(pbs_config::backup_user()?.uid)
>> +                    || stat.st_gid != u32::from(pbs_config::backup_group()?.gid)
>> +                    || stat.st_mode & 0o700 != file_mode
>
>Either be exact:
>    st_mode != file_mode
>
>or only check the required bits:
>    (st_mode & file_mode) != file_mode
>
>(This is one of those rare cases where I'd rather go with the first
>option. If users modified the permissions via the shell, they can just
>fix them up, too.)
>
>as your current code would for instance fail if the lock file had *more*
>permissions for the *user* (u+x) but would ignore more permissions for
>*others* (o+rwx or g+w).

Hmm locally I actually have:

     || stat.st_mode & 0o770 < file_mode

with file_mode being 0o640.
I forgot to add this hunk to the commit :)

Let me know if this is better or if I should revert to your exact
match (st_mode != file_mode).

>> [skip]
>> +
>> +    if reuse_datastore {
>> +        ChunkStore::verify_chunkstore(&path)?;
>
>^ If this is successful
>
>> +        ChunkStore::chunk_dir_accessible(&path)?;
>
>^ then this will be, too, no?
>I think this can just be dropped? Or am I missing something.
>The root check is already up there in this hunk, and other than that
>this just tries to call `fs::metadata()` which is also just a `stat()`
>which `verify_chunkstore()` already does.

Correct, removed the chunk_dir_accessible invokation.

>> [skip]
>> @@ -110,6 +139,7 @@ pub(crate) fn do_create_datastore(
>>  /// Create new datastore config.
>>  pub fn create_datastore(
>>      config: DataStoreConfig,
>> +    reuse_datastore: bool,
>>      rpcenv: &mut dyn RpcEnvironment,
>>  ) -> Result<String, Error> {
>>      let lock = pbs_config::datastore::lock_config()?;
>> @@ -153,8 +183,8 @@ pub fn create_datastore(
>>          Some(config.name.to_string()),
>>          auth_id.to_string(),
>>          to_stdout,
>> -        move |_worker| {
>> -            do_create_datastore(lock, section_config, config)?;
>> +        move |worker| {
>
>`worker` is not used

No idea why I changed this either :/
Reverted it.





More information about the pbs-devel mailing list