1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

storage: extract storage file backend from main storage driver backend

The storage driver backends are serving the public storage pools API,
while the storage file backends are serving the internal QEMU driver and
/ or libvirt utility code.

To prep for moving this storage file backend framework into the utility
code, split out the backend definitions.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-01-25 09:35:44 +00:00
parent d0a60771ab
commit 3be2d1684a
9 changed files with 221 additions and 146 deletions

View File

@ -187,6 +187,7 @@ src/storage/storage_backend_vstorage.c
src/storage/storage_backend_zfs.c
src/storage/storage_driver.c
src/storage/storage_source.c
src/storage/storage_source_backend.c
src/storage/storage_util.c
src/test/test_driver.c
src/uml/uml_conf.c

View File

@ -1065,6 +1065,7 @@ STORAGE_DRIVER_BACKEND_SOURCES = \
STORAGE_DRIVER_SOURCES = \
storage/storage_driver.h storage/storage_driver.c \
storage/storage_source.h storage/storage_source.c \
storage/storage_source_backend.h storage/storage_source_backend.c \
$(STORAGE_DRIVER_BACKEND_SOURCES) \
storage/storage_util.h storage/storage_util.c

View File

@ -78,8 +78,6 @@ VIR_LOG_INIT("storage.storage_backend");
static virStorageBackendPtr virStorageBackends[VIR_STORAGE_BACKENDS_MAX];
static size_t virStorageBackendsCount;
static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKENDS_MAX];
static size_t virStorageFileBackendsCount;
#define STORAGE_BACKEND_MODULE_DIR LIBDIR "/libvirt/storage-backend"
@ -179,27 +177,6 @@ virStorageBackendRegister(virStorageBackendPtr backend)
}
int
virStorageBackendFileRegister(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;
}
virStorageBackendPtr
virStorageBackendForType(int type)
{
@ -213,46 +190,3 @@ virStorageBackendForType(int type)
type, NULLSTR(virStoragePoolTypeToString(type)));
return NULL;
}
virStorageFileBackendPtr
virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report)
{
size_t i;
for (i = 0; i < virStorageFileBackendsCount; i++) {
if (virStorageFileBackends[i]->type == type) {
if (type == VIR_STORAGE_TYPE_NETWORK &&
virStorageFileBackends[i]->protocol != protocol)
continue;
return virStorageFileBackends[i];
}
}
if (!report)
return NULL;
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 NULL;
}
virStorageFileBackendPtr
virStorageFileBackendForType(int type,
int protocol)
{
return virStorageFileBackendForTypeInternal(type, protocol, true);
}

View File

@ -110,83 +110,8 @@ struct _virStorageBackend {
virStorageBackendPtr virStorageBackendForType(int type);
/* ------- virStorageFile backends ------------ */
typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr;
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);
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report);
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 virStorageBackendDriversRegister(bool allmodules);
int virStorageBackendRegister(virStorageBackendPtr backend);
int virStorageBackendFileRegister(virStorageFileBackendPtr backend);
#endif /* __VIR_STORAGE_BACKEND_H__ */

View File

@ -37,6 +37,7 @@
#include "virerror.h"
#include "storage_backend_fs.h"
#include "storage_source_backend.h"
#include "storage_util.h"
#include "storage_conf.h"
#include "virstoragefile.h"
@ -911,13 +912,13 @@ virStorageBackendFsRegister(void)
return -1;
#endif /* WITH_STORAGE_FS */
if (virStorageBackendFileRegister(&virStorageFileBackendFile) < 0)
if (virStorageFileBackendRegister(&virStorageFileBackendFile) < 0)
return -1;
if (virStorageBackendFileRegister(&virStorageFileBackendBlock) < 0)
if (virStorageFileBackendRegister(&virStorageFileBackendBlock) < 0)
return -1;
if (virStorageBackendFileRegister(&virStorageFileBackendDir) < 0)
if (virStorageFileBackendRegister(&virStorageFileBackendDir) < 0)
return -1;
return 0;

View File

@ -24,6 +24,7 @@
#include <glusterfs/api/glfs.h>
#include "storage_backend_gluster.h"
#include "storage_source_backend.h"
#include "storage_conf.h"
#include "viralloc.h"
#include "virerror.h"
@ -866,7 +867,7 @@ virStorageBackendGlusterRegister(void)
if (virStorageBackendRegister(&virStorageBackendGluster) < 0)
return -1;
if (virStorageBackendFileRegister(&virStorageFileBackendGluster) < 0)
if (virStorageFileBackendRegister(&virStorageFileBackendGluster) < 0)
return -1;
return 0;

View File

@ -26,7 +26,7 @@
#include "virerror.h"
#include "storage_source.h"
#include "storage_backend.h"
#include "storage_source_backend.h"
#include "viralloc.h"
#include "virlog.h"
#include "virstring.h"

View File

@ -0,0 +1,108 @@
/*
* storage_source_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/>.
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include <string.h>
#include <sys/stat.h>
#include "datatypes.h"
#include "virerror.h"
#include "viralloc.h"
#include "internal.h"
#include "storage_source_backend.h"
#include "virlog.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;
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;
}
virStorageFileBackendPtr
virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report)
{
size_t i;
for (i = 0; i < virStorageFileBackendsCount; i++) {
if (virStorageFileBackends[i]->type == type) {
if (type == VIR_STORAGE_TYPE_NETWORK &&
virStorageFileBackends[i]->protocol != protocol)
continue;
return virStorageFileBackends[i];
}
}
if (!report)
return NULL;
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 NULL;
}
virStorageFileBackendPtr
virStorageFileBackendForType(int type,
int protocol)
{
return virStorageFileBackendForTypeInternal(type, protocol, true);
}

View File

@ -0,0 +1,104 @@
/*
* storage_source_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/>.
*/
#ifndef __VIR_STORAGE_SOURCE_BACKEND_H__
# define __VIR_STORAGE_SOURCE_BACKEND_H__
# include <sys/stat.h>
# include "virstoragefile.h"
/* ------- virStorageFile backends ------------ */
typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr;
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);
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report);
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);
#endif /* __VIR_STORAGE_SOURCE_BACKEND_H__ */