From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v3 2/4] tape: lock media_catalog file to to get a consistent view with load_catalog
Date: Wed, 28 Jul 2021 11:11:16 +0200 [thread overview]
Message-ID: <20210728091118.581161-3-dietmar@proxmox.com> (raw)
In-Reply-To: <20210728091118.581161-1-dietmar@proxmox.com>
---
src/tape/media_catalog.rs | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index 62c6acb3..1bd136f9 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -231,7 +231,12 @@ impl MediaCatalog {
pending: Vec::new(),
};
- let (found_magic_number, _) = me.load_catalog(&mut file, media_id.media_set_label.as_ref())?;
+ // Note: lock file, to get a consistent view with load_catalog
+ nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::LockExclusive)?;
+ let result = me.load_catalog(&mut file, media_id.media_set_label.as_ref());
+ nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::Unlock)?;
+
+ let (found_magic_number, _) = result?;
if !found_magic_number {
me.pending.extend(&Self::PROXMOX_BACKUP_MEDIA_CATALOG_MAGIC_1_1);
@@ -372,9 +377,18 @@ impl MediaCatalog {
match self.file {
Some(ref mut file) => {
- file.write_all(&self.pending)?;
- file.flush()?;
- file.sync_data()?;
+ let pending = &self.pending;
+ // Note: lock file, to get a consistent view with load_catalog
+ nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::LockExclusive)?;
+ let result: Result<(), Error> = proxmox::try_block!({
+ file.write_all(pending)?;
+ file.flush()?;
+ file.sync_data()?;
+ Ok(())
+ });
+ nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::Unlock)?;
+
+ result?;
}
None => bail!("media catalog not writable (opened read only)"),
}
--
2.30.2
next prev parent reply other threads:[~2021-07-28 9:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 9:11 [pbs-devel] [PATCH proxmox-backup v3 0/4] improve catalog handling Dietmar Maurer
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 1/4] cleanup: factor out tape catalog path helpers Dietmar Maurer
2021-07-28 9:11 ` Dietmar Maurer [this message]
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 3/4] tape: media_catalog: add snapshot list cache for catalog Dietmar Maurer
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 4/4] api2: tape: media: use MediaCatalog::snapshot_list for content listing Dietmar Maurer
2021-07-29 12:30 ` [pbs-devel] applied: [PATCH proxmox-backup v3 0/4] improve catalog handling Dietmar Maurer
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=20210728091118.581161-3-dietmar@proxmox.com \
--to=dietmar@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.