render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 080e123711e8c31634567836c9ca1adf79bcf904 Mon Sep 17 00:00:00 2001
Message-Id: <080e123711e8c31634567836c9ca1adf79bcf904@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 16 Aug 2019 14:36:52 +0200
Subject: [PATCH] util: storage: Allow checking whether virStorageFileCreate is
 supported
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add virStorageFileSupportsCreate which allows silent check whether
virStorageFileCreate is implemented.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit e776194ad2501c9dcba8b4d9f1272342cd7f7c41)
https: //bugzilla.redhat.com/show_bug.cgi?id=1724808
Message-Id: <e4d77e48d0f20da3d0254c95de9904d77cf971df.1565958905.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 20 ++++++++++++++++++++
 src/util/virstoragefile.h |  1 +
 3 files changed, 22 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bf99930802..e696fa512c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2845,6 +2845,7 @@ virStorageFileReportBrokenChain;
 virStorageFileResize;
 virStorageFileStat;
 virStorageFileSupportsAccess;
+virStorageFileSupportsCreate;
 virStorageFileSupportsSecurityDriver;
 virStorageFileUnlink;
 virStorageIsFile;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index f320bc1928..faf21db567 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -4446,6 +4446,26 @@ virStorageFileSupportsAccess(const virStorageSource *src)
 }
 
 
+/**
+ * virStorageFileSupportsCreate:
+ * @src: a storage file structure
+ *
+ * Check if the storage driver supports creating storage described by @src
+ * via virStorageFileCreate.
+ */
+int
+virStorageFileSupportsCreate(const virStorageSource *src)
+{
+    virStorageFileBackendPtr backend;
+    int rv;
+
+    if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
+        return rv;
+
+    return backend->storageFileCreate ? 1 : 0;
+}
+
+
 void
 virStorageFileDeinit(virStorageSourcePtr src)
 {
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 7d28dcfe65..b99afee437 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -505,6 +505,7 @@ int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid);
 
 int virStorageFileSupportsSecurityDriver(const virStorageSource *src);
 int virStorageFileSupportsAccess(const virStorageSource *src);
+int virStorageFileSupportsCreate(const virStorageSource *src);
 
 int virStorageFileGetMetadata(virStorageSourcePtr src,
                               uid_t uid, gid_t gid,
-- 
2.22.1