]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: move virStorageFileBackend code into storage_file
authorPavel Hrdina <phrdina@redhat.com>
Fri, 22 Jan 2021 09:37:33 +0000 (10:37 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 22 Jan 2021 10:10:27 +0000 (11:10 +0100)
It's used only by storage file code so it doesn't make sense to have
it in util directory.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
po/POTFILES.in
src/libvirt_private.syms
src/storage_file/meson.build
src/storage_file/storage_file_backend.c [new file with mode: 0644]
src/storage_file/storage_file_backend.h [new file with mode: 0644]
src/storage_file/storage_file_backend_fs.c
src/storage_file/storage_file_backend_gluster.c
src/storage_file/storage_source.c
src/util/meson.build
src/util/virstoragefilebackend.c [deleted file]
src/util/virstoragefilebackend.h [deleted file]

index 59ae892b4c949d775e9155132107011133e7c60b..fd274e2c7a2d44dc0902ff72d89cddeb322dc4a7 100644 (file)
 @SRCDIR@src/storage/storage_backend_zfs.c
 @SRCDIR@src/storage/storage_driver.c
 @SRCDIR@src/storage/storage_util.c
+@SRCDIR@src/storage_file/storage_file_backend.c
 @SRCDIR@src/storage_file/storage_file_backend_fs.c
 @SRCDIR@src/storage_file/storage_file_backend_gluster.c
 @SRCDIR@src/storage_file/storage_source.c
 @SRCDIR@src/util/virsocketaddr.c
 @SRCDIR@src/util/virstorageencryption.c
 @SRCDIR@src/util/virstoragefile.c
-@SRCDIR@src/util/virstoragefilebackend.c
 @SRCDIR@src/util/virstoragefileprobe.c
 @SRCDIR@src/util/virstring.c
 @SRCDIR@src/util/virsysinfo.c
index 67a863467d4629bf1bfcc679f8c11296639f5b6d..e7af8f0599ba6d31b77e278e0c3bb6243507f94d 100644 (file)
@@ -1618,6 +1618,10 @@ virSecurityManagerVerify;
 virSecurityXATTRNamespaceDefined;
 
 
+# storage_file/storage_file_backend.h
+virStorageFileBackendRegister;
+
+
 # storage_file/storage_source.h
 virStorageFileAccess;
 virStorageFileChainLookup;
@@ -3210,10 +3214,6 @@ virStorageTypeFromString;
 virStorageTypeToString;
 
 
-# util/virstoragefilebackend.h
-virStorageFileBackendRegister;
-
-
 # util/virstoragefileprobe.h
 virStorageFileProbeFormat;
 virStorageFileProbeGetMetadata;
index b0f06c3f915172a515a3a6b436949f9127713bcc..f02ea8549e27fec80421559b077454b31f55f900 100644 (file)
@@ -1,5 +1,6 @@
 storage_file_sources = [
   'storage_source.c',
+  'storage_file_backend.c',
 ]
 
 stoarge_file_fs_sources = [
diff --git a/src/storage_file/storage_file_backend.c b/src/storage_file/storage_file_backend.c
new file mode 100644 (file)
index 0000000..6e4b2f4
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * storage_file_backend.c: internal storage source backend contract
+ *
+ * Copyright (C) 2007-2018 Red Hat, Inc.
+ * Copyright (C) 2007-2008 Daniel P. Berrange
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "datatypes.h"
+#include "virerror.h"
+#include "viralloc.h"
+#include "internal.h"
+#include "storage_file_backend.h"
+#include "virlog.h"
+#include "virmodule.h"
+#include "virfile.h"
+#include "configmake.h"
+
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
+VIR_LOG_INIT("storage.storage_source_backend");
+
+#define VIR_STORAGE_BACKENDS_MAX 20
+
+static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKENDS_MAX];
+static size_t virStorageFileBackendsCount;
+
+#if WITH_STORAGE_DIR || WITH_STORAGE_FS || WITH_STORAGE_GLUSTER
+
+# define STORAGE_FILE_MODULE_DIR LIBDIR "/libvirt/storage-file"
+
+static int
+virStorageFileLoadBackendModule(const char *name,
+                                const char *regfunc,
+                                bool forceload)
+{
+    g_autofree char *modfile = NULL;
+    int ret;
+
+    if (!(modfile = virFileFindResourceFull(name,
+                                            "libvirt_storage_file_",
+                                            VIR_FILE_MODULE_EXT,
+                                            abs_top_builddir "/src",
+                                            STORAGE_FILE_MODULE_DIR,
+                                            "LIBVIRT_STORAGE_FILE_DIR")))
+        return -1;
+
+    ret = virModuleLoad(modfile, regfunc, forceload);
+
+    return ret;
+}
+#endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS || WITH_STORAGE_GLUSTER */
+
+static int virStorageFileBackendOnceInit(void)
+{
+#if WITH_STORAGE_DIR || WITH_STORAGE_FS
+    if (virStorageFileLoadBackendModule("fs", "virStorageFileFsRegister", false) < 0)
+        return -1;
+#endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS */
+#if WITH_STORAGE_GLUSTER
+    if (virStorageFileLoadBackendModule("gluster", "virStorageFileGlusterRegister", false) < 0)
+        return -1;
+#endif /* WITH_STORAGE_GLUSTER */
+    return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virStorageFileBackend);
+
+int
+virStorageFileBackendRegister(virStorageFileBackendPtr backend)
+{
+    VIR_DEBUG("Registering storage file backend '%s' protocol '%s'",
+              virStorageTypeToString(backend->type),
+              virStorageNetProtocolTypeToString(backend->protocol));
+
+    if (virStorageFileBackendsCount >= VIR_STORAGE_BACKENDS_MAX) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Too many drivers, cannot register storage file "
+                         "backend '%s'"),
+                       virStorageTypeToString(backend->type));
+        return -1;
+    }
+
+    virStorageFileBackends[virStorageFileBackendsCount] = backend;
+    virStorageFileBackendsCount++;
+    return 0;
+}
+
+int
+virStorageFileBackendForType(int type,
+                             int protocol,
+                             bool required,
+                             virStorageFileBackendPtr *backend)
+{
+    size_t i;
+
+    *backend = NULL;
+
+    if (virStorageFileBackendInitialize() < 0)
+        return -1;
+
+    for (i = 0; i < virStorageFileBackendsCount; i++) {
+        if (virStorageFileBackends[i]->type == type) {
+            if (type == VIR_STORAGE_TYPE_NETWORK &&
+                virStorageFileBackends[i]->protocol != protocol)
+                continue;
+
+            *backend = virStorageFileBackends[i];
+            return 0;
+        }
+    }
+
+    if (!required)
+        return 0;
+
+    if (type == VIR_STORAGE_TYPE_NETWORK) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("missing storage backend for network files "
+                         "using %s protocol"),
+                       virStorageNetProtocolTypeToString(protocol));
+    } else {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("missing storage backend for '%s' storage"),
+                       virStorageTypeToString(type));
+    }
+
+    return -1;
+}
diff --git a/src/storage_file/storage_file_backend.h b/src/storage_file/storage_file_backend.h
new file mode 100644 (file)
index 0000000..ad0f662
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * storage_file_backend.h: internal storage source backend contract
+ *
+ * Copyright (C) 2007-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <sys/stat.h>
+
+#include "virstoragefile.h"
+
+/* ------- virStorageFile backends ------------ */
+typedef struct _virStorageFileBackend virStorageFileBackend;
+typedef virStorageFileBackend *virStorageFileBackendPtr;
+
+typedef struct _virStorageDriverData virStorageDriverData;
+typedef virStorageDriverData *virStorageDriverDataPtr;
+struct _virStorageDriverData {
+    virStorageFileBackendPtr backend;
+    void *priv;
+
+    uid_t uid;
+    gid_t gid;
+};
+
+typedef int
+(*virStorageFileBackendInit)(virStorageSourcePtr src);
+
+typedef void
+(*virStorageFileBackendDeinit)(virStorageSourcePtr src);
+
+typedef int
+(*virStorageFileBackendCreate)(virStorageSourcePtr src);
+
+typedef int
+(*virStorageFileBackendUnlink)(virStorageSourcePtr src);
+
+typedef int
+(*virStorageFileBackendStat)(virStorageSourcePtr src,
+                             struct stat *st);
+
+typedef ssize_t
+(*virStorageFileBackendRead)(virStorageSourcePtr src,
+                             size_t offset,
+                             size_t len,
+                             char **buf);
+
+typedef const char *
+(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src);
+
+typedef int
+(*virStorageFileBackendAccess)(virStorageSourcePtr src,
+                               int mode);
+
+typedef int
+(*virStorageFileBackendChown)(const virStorageSource *src,
+                              uid_t uid,
+                              gid_t gid);
+
+int virStorageFileBackendForType(int type,
+                                 int protocol,
+                                 bool required,
+                                 virStorageFileBackendPtr *backend);
+
+struct _virStorageFileBackend {
+    int type;
+    int protocol;
+
+    /* All storage file callbacks may be omitted if not implemented */
+
+    /* The following group of callbacks is expected to set a libvirt
+     * error on failure. */
+    virStorageFileBackendInit backendInit;
+    virStorageFileBackendDeinit backendDeinit;
+    virStorageFileBackendRead storageFileRead;
+    virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifier;
+
+    /* The following group of callbacks is expected to set errno
+     * and return -1 on error. No libvirt error shall be reported */
+    virStorageFileBackendCreate storageFileCreate;
+    virStorageFileBackendUnlink storageFileUnlink;
+    virStorageFileBackendStat   storageFileStat;
+    virStorageFileBackendAccess storageFileAccess;
+    virStorageFileBackendChown  storageFileChown;
+};
+
+int virStorageFileBackendRegister(virStorageFileBackendPtr backend);
index 42e514e4377bdaa363436249a65730390e9789a9..7b114fdeb0d0d1f5d44e6c93ff4c29cb48b56338 100644 (file)
@@ -25,9 +25,9 @@
 #include <fcntl.h>
 
 #include "virerror.h"
+#include "storage_file_backend.h"
 #include "storage_file_backend_fs.h"
 #include "storage_util.h"
-#include "virstoragefilebackend.h"
 #include "vircommand.h"
 #include "viralloc.h"
 #include "virfile.h"
index e6ce8d4c928c6a32084802b4842588c7bf5903b1..9b3b783274e954932fd5dc4cec6747d817aa8031 100644 (file)
 
 #include <glusterfs/api/glfs.h>
 
+#include "storage_file_backend.h"
 #include "storage_file_backend_gluster.h"
 #include "viralloc.h"
 #include "virerror.h"
 #include "virlog.h"
 #include "virstoragefile.h"
-#include "virstoragefilebackend.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_STORAGE
index b5e0bc5040762c606ee45dbd3140e3c002375c27..744d3e94fdd49706a1be29653854867e6e311189 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 
 #include "internal.h"
+#include "storage_file_backend.h"
 #include "storage_source.h"
 #include "viralloc.h"
 #include "virerror.h"
@@ -34,7 +35,6 @@
 #include "virlog.h"
 #include "virobject.h"
 #include "virstoragefile.h"
-#include "virstoragefilebackend.h"
 #include "virstoragefileprobe.h"
 #include "virstring.h"
 #include "viruri.h"
index 9fb270fadd88f892782324c9c286b0bce13775ee..64c0f9df6d36f8c3b212f539197433b0a2197100 100644 (file)
@@ -90,7 +90,6 @@ util_sources = [
   'virsocketaddr.c',
   'virstorageencryption.c',
   'virstoragefile.c',
-  'virstoragefilebackend.c',
   'virstoragefileprobe.c',
   'virstring.c',
   'virsysinfo.c',
diff --git a/src/util/virstoragefilebackend.c b/src/util/virstoragefilebackend.c
deleted file mode 100644 (file)
index 55c62b0..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * virstoragefilebackend.c: internal storage source backend contract
- *
- * Copyright (C) 2007-2018 Red Hat, Inc.
- * Copyright (C) 2007-2008 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include <sys/stat.h>
-
-#include "datatypes.h"
-#include "virerror.h"
-#include "viralloc.h"
-#include "internal.h"
-#include "virstoragefilebackend.h"
-#include "virlog.h"
-#include "virmodule.h"
-#include "virfile.h"
-#include "configmake.h"
-
-#define VIR_FROM_THIS VIR_FROM_STORAGE
-
-VIR_LOG_INIT("storage.storage_source_backend");
-
-#define VIR_STORAGE_BACKENDS_MAX 20
-
-static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKENDS_MAX];
-static size_t virStorageFileBackendsCount;
-
-#if WITH_STORAGE_DIR || WITH_STORAGE_FS || WITH_STORAGE_GLUSTER
-
-# define STORAGE_FILE_MODULE_DIR LIBDIR "/libvirt/storage-file"
-
-static int
-virStorageFileLoadBackendModule(const char *name,
-                                const char *regfunc,
-                                bool forceload)
-{
-    g_autofree char *modfile = NULL;
-    int ret;
-
-    if (!(modfile = virFileFindResourceFull(name,
-                                            "libvirt_storage_file_",
-                                            VIR_FILE_MODULE_EXT,
-                                            abs_top_builddir "/src",
-                                            STORAGE_FILE_MODULE_DIR,
-                                            "LIBVIRT_STORAGE_FILE_DIR")))
-        return -1;
-
-    ret = virModuleLoad(modfile, regfunc, forceload);
-
-    return ret;
-}
-#endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS || WITH_STORAGE_GLUSTER */
-
-static int virStorageFileBackendOnceInit(void)
-{
-#if WITH_STORAGE_DIR || WITH_STORAGE_FS
-    if (virStorageFileLoadBackendModule("fs", "virStorageFileFsRegister", false) < 0)
-        return -1;
-#endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS */
-#if WITH_STORAGE_GLUSTER
-    if (virStorageFileLoadBackendModule("gluster", "virStorageFileGlusterRegister", false) < 0)
-        return -1;
-#endif /* WITH_STORAGE_GLUSTER */
-    return 0;
-}
-
-VIR_ONCE_GLOBAL_INIT(virStorageFileBackend);
-
-int
-virStorageFileBackendRegister(virStorageFileBackendPtr backend)
-{
-    VIR_DEBUG("Registering storage file backend '%s' protocol '%s'",
-              virStorageTypeToString(backend->type),
-              virStorageNetProtocolTypeToString(backend->protocol));
-
-    if (virStorageFileBackendsCount >= VIR_STORAGE_BACKENDS_MAX) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Too many drivers, cannot register storage file "
-                         "backend '%s'"),
-                       virStorageTypeToString(backend->type));
-        return -1;
-    }
-
-    virStorageFileBackends[virStorageFileBackendsCount] = backend;
-    virStorageFileBackendsCount++;
-    return 0;
-}
-
-int
-virStorageFileBackendForType(int type,
-                             int protocol,
-                             bool required,
-                             virStorageFileBackendPtr *backend)
-{
-    size_t i;
-
-    *backend = NULL;
-
-    if (virStorageFileBackendInitialize() < 0)
-        return -1;
-
-    for (i = 0; i < virStorageFileBackendsCount; i++) {
-        if (virStorageFileBackends[i]->type == type) {
-            if (type == VIR_STORAGE_TYPE_NETWORK &&
-                virStorageFileBackends[i]->protocol != protocol)
-                continue;
-
-            *backend = virStorageFileBackends[i];
-            return 0;
-        }
-    }
-
-    if (!required)
-        return 0;
-
-    if (type == VIR_STORAGE_TYPE_NETWORK) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("missing storage backend for network files "
-                         "using %s protocol"),
-                       virStorageNetProtocolTypeToString(protocol));
-    } else {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("missing storage backend for '%s' storage"),
-                       virStorageTypeToString(type));
-    }
-
-    return -1;
-}
diff --git a/src/util/virstoragefilebackend.h b/src/util/virstoragefilebackend.h
deleted file mode 100644 (file)
index 43b36e9..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * virstoragefilebackend.h: internal storage source backend contract
- *
- * Copyright (C) 2007-2018 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include <sys/stat.h>
-
-#include "virstoragefile.h"
-
-/* ------- virStorageFile backends ------------ */
-typedef struct _virStorageFileBackend virStorageFileBackend;
-typedef virStorageFileBackend *virStorageFileBackendPtr;
-
-typedef struct _virStorageDriverData virStorageDriverData;
-typedef virStorageDriverData *virStorageDriverDataPtr;
-struct _virStorageDriverData {
-    virStorageFileBackendPtr backend;
-    void *priv;
-
-    uid_t uid;
-    gid_t gid;
-};
-
-typedef int
-(*virStorageFileBackendInit)(virStorageSourcePtr src);
-
-typedef void
-(*virStorageFileBackendDeinit)(virStorageSourcePtr src);
-
-typedef int
-(*virStorageFileBackendCreate)(virStorageSourcePtr src);
-
-typedef int
-(*virStorageFileBackendUnlink)(virStorageSourcePtr src);
-
-typedef int
-(*virStorageFileBackendStat)(virStorageSourcePtr src,
-                             struct stat *st);
-
-typedef ssize_t
-(*virStorageFileBackendRead)(virStorageSourcePtr src,
-                             size_t offset,
-                             size_t len,
-                             char **buf);
-
-typedef const char *
-(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src);
-
-typedef int
-(*virStorageFileBackendAccess)(virStorageSourcePtr src,
-                               int mode);
-
-typedef int
-(*virStorageFileBackendChown)(const virStorageSource *src,
-                              uid_t uid,
-                              gid_t gid);
-
-int virStorageFileBackendForType(int type,
-                                 int protocol,
-                                 bool required,
-                                 virStorageFileBackendPtr *backend);
-
-struct _virStorageFileBackend {
-    int type;
-    int protocol;
-
-    /* All storage file callbacks may be omitted if not implemented */
-
-    /* The following group of callbacks is expected to set a libvirt
-     * error on failure. */
-    virStorageFileBackendInit backendInit;
-    virStorageFileBackendDeinit backendDeinit;
-    virStorageFileBackendRead storageFileRead;
-    virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifier;
-
-    /* The following group of callbacks is expected to set errno
-     * and return -1 on error. No libvirt error shall be reported */
-    virStorageFileBackendCreate storageFileCreate;
-    virStorageFileBackendUnlink storageFileUnlink;
-    virStorageFileBackendStat   storageFileStat;
-    virStorageFileBackendAccess storageFileAccess;
-    virStorageFileBackendChown  storageFileChown;
-};
-
-int virStorageFileBackendRegister(virStorageFileBackendPtr backend);