From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id C903068B85
 for <pbs-devel@lists.proxmox.com>; Thu, 22 Jul 2021 15:41:12 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C6AC711EDE
 for <pbs-devel@lists.proxmox.com>; Thu, 22 Jul 2021 15:41:12 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 97D7711E3C
 for <pbs-devel@lists.proxmox.com>; Thu, 22 Jul 2021 15:41:11 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6CBE5423C4
 for <pbs-devel@lists.proxmox.com>; Thu, 22 Jul 2021 15:41:11 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu, 22 Jul 2021 15:41:02 +0200
Message-Id: <20210722134106.1280517-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210722134106.1280517-1-d.csapak@proxmox.com>
References: <20210722134106.1280517-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.523 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 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
Subject: [pbs-devel] [PATCH proxmox-backup v2 3/7] tape: pool_writer: finish
 the catalog when its done
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>
X-List-Received-Date: Thu, 22 Jul 2021 13:41:12 -0000

by adding a 'finish' method to the pool writer itself which must
be called before its dropped

and when the catalog gets moved into the read_only section of
the catalog set

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/tape/backup.rs             |  2 +-
 src/tape/pool_writer/catalog_set.rs |  3 ++-
 src/tape/pool_writer/mod.rs         | 15 +++++++++++++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index 8119482f..45ee4bad 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -520,7 +520,7 @@ fn backup_worker(
         }
     }
 
-    pool_writer.commit()?;
+    pool_writer.finish()?;
 
     if need_catalog {
         task_log!(worker, "append media catalog");
diff --git a/src/tape/pool_writer/catalog_set.rs b/src/tape/pool_writer/catalog_set.rs
index d5903413..da39b659 100644
--- a/src/tape/pool_writer/catalog_set.rs
+++ b/src/tape/pool_writer/catalog_set.rs
@@ -58,7 +58,8 @@ impl CatalogSet {
     pub fn append_catalog(&mut self, new_catalog: MediaCatalog) -> Result<(), Error> {
 
         // append current catalog to read-only set
-        if let Some(catalog) = self.catalog.take() {
+        if let Some(mut catalog) = self.catalog.take() {
+            catalog.finish()?;
             self.media_set_catalog.append_catalog(catalog)?;
         }
 
diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs
index 6f887c60..dc908ce5 100644
--- a/src/tape/pool_writer/mod.rs
+++ b/src/tape/pool_writer/mod.rs
@@ -186,8 +186,7 @@ impl PoolWriter {
 
     /// commit changes to tape and catalog
     ///
-    /// This is done automatically during a backupsession, but needs to
-    /// be called explicitly before dropping the PoolWriter
+    /// This is done automatically during a backupsession
     pub fn commit(&mut self) -> Result<(), Error> {
          if let Some(PoolWriterState {ref mut drive, .. }) = self.status {
             drive.sync()?; // sync all data to the tape
@@ -196,6 +195,18 @@ impl PoolWriter {
         Ok(())
     }
 
+    /// commit changes to tape and finished catalog
+    ///
+    /// this needs be called before the PoolWriter is dropped
+    pub fn finish(&mut self) -> Result<(), Error> {
+        self.commit()?;
+        let mut catalog_set = self.catalog_set.lock().unwrap();
+        if let Some(ref mut catalog) = catalog_set.catalog {
+            catalog.finish()?;
+        }
+        Ok(())
+    }
+
     /// Load a writable media into the drive
     pub fn load_writable_media(&mut self, worker: &WorkerTask) -> Result<Uuid, Error> {
         let last_media_uuid = match self.status {
-- 
2.30.2