5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-01-06 13:18:00 +03:00
Commit Graph

222 Commits

Author SHA1 Message Date
Maximiliano Sandoval
a637e7f490 datastore: remove lazy_static dependency
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-08-14 12:08:01 +02:00
Thomas Lamprecht
8caf3f9f57 cargo fmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-08-07 20:50:28 +02:00
Dominik Csapak
98c4056eaa datastore: data blob encode: simplify code
by combining the compression call from both encrypted and unencrypted
paths and deciding on the header magic at one site.

No functional changes intended, besides reusing the same buffer for
compression.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-08-07 18:58:11 +02:00
Dominik Csapak
aae596ee18 datastore: data blob: increase compression throughput
Increase the zstd compression throughput by not using the
`zstd::stream::copy_encode` method, because it seems it uses an
internal buffer size of 32 KiB [0], copies at least once extra in the
target buffer and might have some additional (allocation and/or
syscall) overhead. Due to the amount of wrappers and indirections it's
a bit hard to tell for sure.  In anyway, there can be a reduced
throughput observed if all, the target and source storage and the
network are so fast that the operations from creating chunks, like
compressions, can become the bottleneck.

Instead use the lower-level `zstd_safe::compress` which avoids (big)
allocations, since we provide the target buffer.

In case of a compression error just return the uncompressed data,
there's nothing we can do and saving uncompressed data is better than
having none. Additionally, log any such error besides the one for the
target buffer being too small.

Some benchmarks on my machine (Intel i7-12700K with DDR5-4800 memory
using a ASUS Prime Z690-A motherboard) from a tmpfs to a datastore on
tmpfs:

Type                without patches (MiB/s)  with patches (MiB/s)
.img file           ~614                     ~767
pxar one big file   ~657                     ~807
pxar small files    ~576                     ~627

The new approach is faster by a factor of 1.19.

Note that the new approach should not have a measurable negative
impact, e.g. (peak) memory usage wise. That is because we always
reserved a vector with max-data-size (data length + header length) and
thus did not have to add a new buffer, rather we actually removed the
buffer that the high-level zstd wrapper crate used internally.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-08-07 18:57:39 +02:00
Dominik Csapak
e1d92bce57 datastore: data blob: allow checking for zstd internal buffer-to-small error
We want to check the error code of zstd not to be 'Destination buffer
to small' (dstSize_tooSmall),  but currently there is no practical API
that is also public. So we introduce a helper that uses the internal
logic of zstd to determine the error.

Since this is not guaranteed to be a stable api, add a test for that
so we catch that error early on build. This should be fine, as long as
the zstd behavior only changes with e.g. major debian upgrades, which
is normally the only time where the zstd version is updated.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ TL: re-order fn, rename test and reword comments ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-08-07 18:54:04 +02:00
Dominik Csapak
69b8b4b02f datastore: test DataBlob encode/decode roundtrip
so that we can be sure we can decode an encoded blob again

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-08-07 18:52:06 +02:00
Dominik Csapak
b43845aa07 datastore: remove unused data blob writer
This is leftover code that is not currently used outside of its own
tests.

Should we need it again, we can just revert this commit.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-08-07 18:51:09 +02:00
Wolfgang Bumiller
3f325047dc remove use of proxmox_lang::error::io_err_other
by now its functionality is provided by std::io::Error::other

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-26 13:05:20 +02:00
Christian Ebner
077c1a9979 datastore: data blob: fix typos in comments
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-07-17 14:41:58 +02:00
Christian Ebner
6e3f844f9a datastore: replace deprecated archive_type function
Commit ea584a75 "move more api types for the client" deprecated
the `archive_type` function in favor of the associated function
`ArchiveType::from_path`.

Replace all remaining callers of the deprecated function with its
replacement.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
[WB: and remove the deprecated function]
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-12 13:57:59 +02:00
Gabriel Goller
c052040028 datastore: fix typo in comment
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2024-07-12 13:50:30 +02:00
Gabriel Goller
c1689192d9 datastore: use cached snapshot time string in path
When getting the `full_path` of a snapshot we did not use the cached
time string. By using it we avoid a call to the super-slow libc strftime.

This has some minor performance improvements of circa 7%. That is ~100ms
on my datastore with ~5000 snapshots.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2024-07-12 13:41:04 +02:00
Wolfgang Bumiller
c4f2bb70da bump sys and rest-server dependencies to 0.6
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-11 16:02:38 +02:00
Gabriel Goller
7e2486e800 switch from task_log! macro to tracing
Import `proxmox-log` and substitute all `task_log!`
(and task_warn!, task_error!) invocations with tracing calls (info!,
warn!, etc..). Remove worker references where it isn't necessary
anymore.

Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2024-07-11 15:56:04 +02:00
Hannes Laimer
0020601d52 datastore: fix problem with operations counting
... if `.chunks/` is not available(deleted/moved) ChunkStore::open
fails, but that would happen after updating the active operations on the
datastore, so no reference that could be dropped is returned. Leading to
the operations counter to always increase. This only updates the counter
when a reference is returned, not before.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
2024-07-02 17:02:38 +02:00
Maximiliano Sandoval
cef764ff85 chunk_store: do not explicitly write implied trait
Fixes the clippy warning:

warning: this bound is already specified as the supertrait of `std::iter::FusedIterator`
   --> pbs-datastore/src/chunk_store.rs:254:14
    |
254 |         impl Iterator<Item = (Result<proxmox_sys::fs::ReadDirEntry, Error>, usize, bool)>
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls
    = note: `#[warn(clippy::implied_bounds_in_impls)]` on by default
help: try removing this bound
    |
254 -         impl Iterator<Item = (Result<proxmox_sys::fs::ReadDirEntry, Error>, usize, bool)>
255 -             + std::iter::FusedIterator,
254 +         impl std::iter::FusedIterator<Item = (Result<proxmox_sys::fs::ReadDirEntry, Error>, usize, bool)>,

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-06-28 09:21:06 +02:00
Maximiliano Sandoval
f3f3c67267 replace get(key).is_some() with contains_key()
Fixes the clippy warning:

warning: unnecessary use of `get(realm).is_some()`
  --> pbs-config/src/domains.rs:68:58
   |
68 |     realm == "pbs" || realm == "pam" || domains.sections.get(realm).is_some()
   |                                                          ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(realm)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-06-28 09:20:56 +02:00
Wolfgang Bumiller
6359e6d4d4 replace c_str! macro with c"literals"
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-06-20 11:07:11 +02:00
Christian Ebner
e11ee319ce chunker: tests: add regression tests for payload chunker
Test chunking of a payload stream with suggested chunk boundaries.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-06-05 16:39:42 +02:00
Christian Ebner
88ef759cc4 datastore: chunker: implement chunker for payload stream
Implement the Chunker trait for a dedicated payload stream chunker,
which extends the regular chunker by the option to suggest boundaries
to be used over the hast based boundaries whenever possible.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-06-05 16:39:42 +02:00
Christian Ebner
e321815635 datastore: chunker: add Chunker trait
Add the Chunker trait and move the current Chunker to ChunkerImpl to
implement the trait instead. This allows to use different chunker
implementations by dynamic dispatch and is in preparation for
implementing a dedicated payload chunker.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-06-05 16:39:42 +02:00
Christian Ebner
77fdae28cf chunker: add method to reset chunker state
When forcing a boundary, the internal chunker state is not in sync
with the chunk stream anymore. The reset method therefore allows
to reset the internal state.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-06-05 16:39:41 +02:00
Christian Ebner
9978f6934b datastore: dynamic index: add method to get digest
In preparation for injecting reused payload chunks in payload streams
for regular files with unchanged metaddata. Allows to get the digest
of a dynamic index entry to construct a reusable dynamic entry from
it.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-06-05 10:47:36 +02:00
Dietmar Maurer
50c0246a89 api: assert that maintenance mode transitions are valid
Maintenance mode Delete locks the datastore. It must not be possible to go
back to normal modes, because the datastore may be in undefined state.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2024-04-22 12:19:22 +02:00
Christian Ebner
524ed4048b datastore: group: return basic stats on backup group destroy
No functional change intended: In preparation for including the
removed vanished groups and snapshots statistics in a sync jobs task
log output.

Instead of returning a boolean value showing whether all of the
snapshots of the group have been removed, return an instance of
`BackupGroupDeleteStats`, containing the count of deleted and
protected snapshots, the latter not having been removed from the
group.

The `removed_all` method is introduced as replacement for the previous
boolean return value and can be used to check if all snapshots have
been removed. If there are no protected snapshots, the group is
considered to be deleted.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-03-25 17:17:12 +01:00
Hannes Laimer
9cba51ac78 datastore: remove datastore from internal cache based on maintenance mode
We keep a DataStore cache, so ChunkStore's and lock files are kept by
the proxy process and don't have to be reopened every time. However,
for specific maintenance modes, e.g. 'offline', our process should not
keep file in that datastore open. This clears the cache entry of a
datastore if it is in a specific maintanance mode and the last task
finished, which also drops any files still open by the process.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Gabriel Goller <g.goller@proxmox.com>
2024-03-25 16:12:41 +01:00
Maximiliano Sandoval
1c3f1e7cdf datastore: use is_{err, some} rather than match {Ok, Some}(_)
Fixes the clippy lint:

```
warning: redundant pattern matching, consider using `is_ok()`
    --> pbs-datastore/src/datastore.rs:1025:10
     |
1025 |         !matches!(self.inner.gc_mutex.try_lock(), Ok(_))
     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.inner.gc_mutex.try_lock().is_ok()`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
     = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
```

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-02-13 10:10:56 +01:00
Maximiliano Sandoval
5251bf89ba remove redundant guards
Fixes the clippy lint:

```
warning: redundant guard
   --> pbs-datastore/src/chunk_store.rs:325:37
    |
325 |                     Err(ref err) if err == &nix::errno::Errno::ENOENT => {
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
    = note: `#[warn(clippy::redundant_guards)]` on by default
help: try
    |
325 -                     Err(ref err) if err == &nix::errno::Errno::ENOENT => {
325 +                     Err(nix::errno::Errno::ENOENT) => {
    |
```

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-02-13 10:05:39 +01:00
Thomas Lamprecht
fa86b05d45 run cargo fmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-01-18 16:36:02 +01:00
Christian Ebner
de6b0ea35a datastore: add additional context for get_owner parsing error
By this it becomes clear that the error stems from a parsing error when
getting the backup group owner.

See also: https://forum.proxmox.com/threads/139482/

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2024-01-10 10:41:36 +01:00
Hannes Laimer
05a52d0106 pull: refactor pulling from a datastore
... making the pull logic independent from the actual source
using two traits.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Tested-by: Gabriel Goller <g.goller@proxmox.com>
2023-11-25 17:07:42 +01:00
Gabriel Goller
5116d051a8 docs: rustdoc warnings
Fixed a few rustdoc warnings. Converted some 'html'-links to
intra-doc-links and surrounded paths with '`'.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2023-11-11 10:10:21 +01:00
Gabriel Goller
e9c18590f5 datastore: catalog: added lifetime to find function
Added lifetime to `find` function. We need this lifetime
because of the `impl MatchList` and 'anonymous lifetimes in
`impl Trait` are unstable'.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2023-10-19 11:13:27 +02:00
Gabriel Goller
9d1ba51de7 fix #4823: datastore: ignore vanished files when walking directory
When walking through a datastore on a GC run, it can
happen that the snapshot is deleted, and then walked over.
For example:
- read dir entry for group
- walk entries (snapshots)
- snapshot X is removed/pruned
- walking reaches snapshot X, but ENOENT
Previously we bailed here, now we just ignore it.
Backups that are just created (and a atomic rename from
tmpdir happens, which might triggers a ENOENT error) are
not a problem here, the GC handles them separately.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2023-09-18 16:42:39 +02:00
Fabian Grünbichler
8fcd709cf2 gc: improve lost+found comment
this sounded like we need to skip lost+found to avoid pruning too many chunks,
while the opposite is true - it's safe to skip lost+found on EPERM without
pruning too many chunks, but this is not the case for all EPERM situations..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-09-12 11:29:11 +02:00
Hannes Laimer
0d69dcb497 gc: fix ignoring if lost+found can't be accessed
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>

Fixes: e2516f61a860eae59395a3a990d9abe4c445ce8c
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-09-12 11:26:36 +02:00
Thomas Lamprecht
5b16dffcf2 datastore: list images: reduce indentation depth on error checking
Simply pull out the inner IO error and the affected path first.

Clean up style-wise a bit while touching this anyway, but no semantic
change intended.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-09-08 11:05:10 +02:00
Gabriel Goller
b65908fac2 fix #4380: check if file is excluded before running stat()
Passed a closure with the `stat()` function call to `matches()`. This
will traverse through all patterns and try to match using the path only, if a
`file_mode` is needed, it will run the closure. This means that if we exclude
a file with the `MatchType::ANY_FILE_TYPE`, we will skip it without running
`stat()` on it. As we updated the `matches()` function, we also updated all the
invocations of it.
Added `pathpatterns` crate to local overrides in cargo.toml.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2023-08-24 10:17:41 +02:00
Fabian Grünbichler
61167351a1 blobs: fix outdated comment about file format
the wrong info here was rather misleading, especially when encountering errors
just talking about "blobs" when the actual problem is with a chunk.

chunks did originally have their own magic values, but that got removed in

4ee8f53d07 "remove DataChunk file format - use DataBlob instead"

back in 2019, before the 0.1.1 release(!)

Reported-by: Dominik Csapak <d.csapak@proxmox.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-08-08 13:57:06 +02:00
Lukas Wagner
08f8a3e5aa api-types: client: datastore: tools: use proxmox-human-bytes crate
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-06-26 13:56:45 +02:00
Fabian Grünbichler
4341a3f0cc update zstd to 0.12
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-05-21 15:32:45 +02:00
Thomas Lamprecht
a57413a54c pbs-datastore: clippy fixes
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-05-17 17:43:17 +02:00
Thomas Lamprecht
48efb5268d datastore: return error instead of unreachable
very unexpected and unreachable is probably fine here, but it's not
really winning us anything, so avoid the panic-potential and just
bail out.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-05-17 16:06:28 +02:00
Thomas Lamprecht
071d345781 datastore: fix compiler warning for unused FromStr import
Fixes: 161a8864 ("fix #4357: datastore: take into account namespaces ...")
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-05-17 14:33:23 +02:00
Stefan Sterz
161a88644f fix #4357: datastore: take into account namespaces when marking chunks
previously when marking used chunks the namespace wasn't taken into
account and valid snapshots were marked as "strange paths". this lead
to a line in the log of a gc job such as this:

found (and marked) 2 index files outside of expected directory scheme

which some users perceived as an error. parse the namespace too and
only mark the path as strange if parsing the namespace and/or backup
dir fails.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2023-05-17 11:35:08 +02:00
Fabian Grünbichler
42018aeae5 chunk store: handle insertion edge cases
these were previously called out in a comment, but should now be handled (as
much as they can be).

the performance impact shouldn't be too bad, since we only look at the magic 8
bytes at the start of the existing chunk (we already did a stat on it, so that
might even be prefetched already by storage), and only if there is a size
mismatch and encryption is enabled.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
 [ T: fold in "just to be sure" touch_chunk calls ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-04-06 09:36:51 +02:00
Fabian Grünbichler
c78437e320 verify/protect: improve error on disappearing snapshots
or clients passing in a non-existent snapshot.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-02-08 15:19:32 +01:00
Fabian Grünbichler
07b6db8099 backup/snapshot reader: improve error message for ENOENT
instead of

 Error: unable to open snapshot directory "/full/path/to/snapshot" for locking - ENOENT: No such file or directory

this will now print

 Error: Snapshot vm/800/2023-01-16T12:28:11Z does not exist.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-02-08 15:19:29 +01:00
Thomas Lamprecht
9f43a9febf datastore: rustfmt
Fixes: d2aff935 ("update to nix 0.26")
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-01-19 11:37:24 +01:00
Fabian Grünbichler
d2aff935c9 update to nix 0.26
and corresponding proxmox-* dependencies to their versions depending on nix
0.26.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-01-05 13:16:21 +01:00