This will allow following patches to move virStorageSource into conf
directory and virStorageDriverData into a new storage_file directory.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/storage/storage_file_fs.c | 21 +++--
src/storage/storage_file_gluster.c | 31 +++++---
src/util/virstoragefile.c | 118 +++++++++++++++++++++--------
src/util/virstoragefile.h | 5 +-
src/util/virstoragefilebackend.h | 2 +
5 files changed, 122 insertions(+), 55 deletions(-)
diff --git a/src/storage/storage_file_fs.c b/src/storage/storage_file_fs.c
index b379a8ca8e..5a44ef8c2d 100644
--- a/src/storage/storage_file_fs.c
+++ b/src/storage/storage_file_fs.c
@@ -51,7 +51,8 @@ struct _virStorageFileBackendFsPriv {
static void
virStorageFileBackendFileDeinit(virStorageSourcePtr src)
{
- virStorageFileBackendFsPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendFsPrivPtr priv = drv->priv;
VIR_DEBUG("deinitializing FS storage file %p (%s:%s)", src,
virStorageTypeToString(virStorageSourceGetActualType(src)),
@@ -66,16 +67,17 @@ virStorageFileBackendFileDeinit(virStorageSourcePtr src)
static int
virStorageFileBackendFileInit(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendFsPrivPtr priv = NULL;
VIR_DEBUG("initializing FS storage file %p (%s:%s)[%u:%u]", src,
virStorageTypeToString(virStorageSourceGetActualType(src)),
src->path,
- (unsigned int)src->drv->uid, (unsigned int)src->drv->gid);
+ (unsigned int)drv->uid, (unsigned int)drv->gid);
priv = g_new0(virStorageFileBackendFsPriv, 1);
- src->drv->priv = priv;
+ drv->priv = priv;
return 0;
}
@@ -84,10 +86,11 @@ virStorageFileBackendFileInit(virStorageSourcePtr src)
static int
virStorageFileBackendFileCreate(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = src->drv;
VIR_AUTOCLOSE fd = -1;
if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR |
S_IWUSR,
- src->drv->uid, src->drv->gid, 0)) < 0) {
+ drv->uid, drv->gid, 0)) < 0) {
errno = -fd;
return -1;
}
@@ -117,11 +120,12 @@ virStorageFileBackendFileRead(virStorageSourcePtr src,
size_t len,
char **buf)
{
+ virStorageDriverDataPtr drv = src->drv;
ssize_t ret = -1;
VIR_AUTOCLOSE fd = -1;
if ((fd = virFileOpenAs(src->path, O_RDONLY, 0,
- src->drv->uid, src->drv->gid, 0)) < 0) {
+ drv->uid, drv->gid, 0)) < 0) {
virReportSystemError(-fd, _("Failed to open file '%s'"),
src->path);
return -1;
@@ -146,7 +150,8 @@ virStorageFileBackendFileRead(virStorageSourcePtr src,
static const char *
virStorageFileBackendFileGetUniqueIdentifier(virStorageSourcePtr src)
{
- virStorageFileBackendFsPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendFsPrivPtr priv = drv->priv;
if (!priv->canonpath) {
if (!(priv->canonpath = virFileCanonicalizePath(src->path))) {
@@ -164,8 +169,10 @@ static int
virStorageFileBackendFileAccess(virStorageSourcePtr src,
int mode)
{
+ virStorageDriverDataPtr drv = src->drv;
+
return virFileAccessibleAs(src->path, mode,
- src->drv->uid, src->drv->gid);
+ drv->uid, drv->gid);
}
diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_gluster.c
index c84af8a4e8..e26dfdfd99 100644
--- a/src/storage/storage_file_gluster.c
+++ b/src/storage/storage_file_gluster.c
@@ -46,7 +46,8 @@ struct _virStorageFileBackendGlusterPriv {
static void
virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%u/%s%s)",
src, src->hosts->name, src->hosts->port, src->volume,
src->path);
@@ -56,7 +57,7 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
VIR_FREE(priv->canonpath);
VIR_FREE(priv);
- src->drv->priv = NULL;
+ drv->priv = NULL;
}
static int
@@ -99,6 +100,7 @@
virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
static int
virStorageFileBackendGlusterInit(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = NULL;
size_t i;
@@ -114,7 +116,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
VIR_DEBUG("initializing gluster storage file %p "
"(priv='%p' volume='%s' path='%s') as
[%u:%u]",
src, priv, src->volume, src->path,
- (unsigned int)src->drv->uid, (unsigned int)src->drv->gid);
+ (unsigned int)drv->uid, (unsigned int)drv->gid);
if (!(priv->vol = glfs_new(src->volume))) {
virReportOOMError();
@@ -133,7 +135,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
goto error;
}
- src->drv->priv = priv;
+ drv->priv = priv;
return 0;
@@ -149,7 +151,8 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
static int
virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
glfs_fd_t *fd = NULL;
if (!(fd = glfs_creat(priv->vol, src->path,
@@ -164,7 +167,8 @@ virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
static int
virStorageFileBackendGlusterUnlink(virStorageSourcePtr src)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_unlink(priv->vol, src->path);
}
@@ -174,7 +178,8 @@ static int
virStorageFileBackendGlusterStat(virStorageSourcePtr src,
struct stat *st)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_stat(priv->vol, src->path, st);
}
@@ -186,7 +191,8 @@ virStorageFileBackendGlusterRead(virStorageSourcePtr src,
size_t len,
char **buf)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
glfs_fd_t *fd = NULL;
ssize_t ret = -1;
char *s;
@@ -241,7 +247,8 @@ static int
virStorageFileBackendGlusterAccess(virStorageSourcePtr src,
int mode)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_access(priv->vol, src->path, mode);
}
@@ -294,7 +301,8 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
static const char *
virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
g_autofree char *filePath = NULL;
if (priv->canonpath)
@@ -320,7 +328,8 @@ virStorageFileBackendGlusterChown(const virStorageSource *src,
uid_t uid,
gid_t gid)
{
- virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ virStorageDriverDataPtr drv = src->drv;
+ virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_chown(priv->vol, src->path, uid, gid);
}
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 6ced28762a..524204a56c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -4521,7 +4521,8 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource
*src,
}
if (src->drv) {
- *backend = src->drv->backend;
+ virStorageDriverDataPtr drv = src->drv;
+ *backend = drv->backend;
return 1;
}
@@ -4617,12 +4618,16 @@ virStorageFileSupportsCreate(const virStorageSource *src)
void
virStorageFileDeinit(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = NULL;
+
if (!virStorageFileIsInitialized(src))
return;
- if (src->drv->backend &&
- src->drv->backend->backendDeinit)
- src->drv->backend->backendDeinit(src);
+ drv = src->drv;
+
+ if (drv->backend &&
+ drv->backend->backendDeinit)
+ drv->backend->backendDeinit(src);
VIR_FREE(src->drv);
}
@@ -4646,26 +4651,28 @@ virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid)
{
int actualType = virStorageSourceGetActualType(src);
- src->drv = g_new0(virStorageDriverData, 1);
+ virStorageDriverDataPtr drv = g_new0(virStorageDriverData, 1);
+
+ src->drv = drv;
if (uid == (uid_t) -1)
- src->drv->uid = geteuid();
+ drv->uid = geteuid();
else
- src->drv->uid = uid;
+ drv->uid = uid;
if (gid == (gid_t) -1)
- src->drv->gid = getegid();
+ drv->gid = getegid();
else
- src->drv->gid = gid;
+ drv->gid = gid;
if (virStorageFileBackendForType(actualType,
src->protocol,
true,
- &src->drv->backend) < 0)
+ &drv->backend) < 0)
goto error;
- if (src->drv->backend->backendInit &&
- src->drv->backend->backendInit(src) < 0)
+ if (drv->backend->backendInit &&
+ drv->backend->backendInit(src) < 0)
goto error;
return 0;
@@ -4700,15 +4707,22 @@ virStorageFileInit(virStorageSourcePtr src)
int
virStorageFileCreate(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = NULL;
int ret;
- if (!virStorageFileIsInitialized(src) ||
- !src->drv->backend->storageFileCreate) {
+ if (!virStorageFileIsInitialized(src)) {
errno = ENOSYS;
return -2;
}
- ret = src->drv->backend->storageFileCreate(src);
+ drv = src->drv;
+
+ if (!drv->backend->storageFileCreate) {
+ errno = ENOSYS;
+ return -2;
+ }
+
+ ret = drv->backend->storageFileCreate(src);
VIR_DEBUG("created storage file %p: ret=%d, errno=%d",
src, ret, errno);
@@ -4730,15 +4744,22 @@ virStorageFileCreate(virStorageSourcePtr src)
int
virStorageFileUnlink(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = NULL;
int ret;
- if (!virStorageFileIsInitialized(src) ||
- !src->drv->backend->storageFileUnlink) {
+ if (!virStorageFileIsInitialized(src)) {
errno = ENOSYS;
return -2;
}
- ret = src->drv->backend->storageFileUnlink(src);
+ drv = src->drv;
+
+ if (!drv->backend->storageFileUnlink) {
+ errno = ENOSYS;
+ return -2;
+ }
+
+ ret = drv->backend->storageFileUnlink(src);
VIR_DEBUG("unlinked storage file %p: ret=%d, errno=%d",
src, ret, errno);
@@ -4760,15 +4781,22 @@ int
virStorageFileStat(virStorageSourcePtr src,
struct stat *st)
{
+ virStorageDriverDataPtr drv = NULL;
int ret;
- if (!virStorageFileIsInitialized(src) ||
- !src->drv->backend->storageFileStat) {
+ if (!virStorageFileIsInitialized(src)) {
errno = ENOSYS;
return -2;
}
- ret = src->drv->backend->storageFileStat(src, st);
+ drv = src->drv;
+
+ if (!drv->backend->storageFileStat) {
+ errno = ENOSYS;
+ return -2;
+ }
+
+ ret = drv->backend->storageFileStat(src, st);
VIR_DEBUG("stat of storage file %p: ret=%d, errno=%d",
src, ret, errno);
@@ -4795,6 +4823,7 @@ virStorageFileRead(virStorageSourcePtr src,
size_t len,
char **buf)
{
+ virStorageDriverDataPtr drv = NULL;
ssize_t ret;
if (!virStorageFileIsInitialized(src)) {
@@ -4803,10 +4832,12 @@ virStorageFileRead(virStorageSourcePtr src,
return -1;
}
- if (!src->drv->backend->storageFileRead)
+ drv = src->drv;
+
+ if (!drv->backend->storageFileRead)
return -2;
- ret = src->drv->backend->storageFileRead(src, offset, len, buf);
+ ret = drv->backend->storageFileRead(src, offset, len, buf);
VIR_DEBUG("read '%zd' bytes from storage '%p' starting at offset
'%zu'",
ret, src, offset);
@@ -4826,13 +4857,17 @@ virStorageFileRead(virStorageSourcePtr src,
const char *
virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
{
+ virStorageDriverDataPtr drv = NULL;
+
if (!virStorageFileIsInitialized(src)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("storage file backend not initialized"));
return NULL;
}
- if (!src->drv->backend->storageFileGetUniqueIdentifier) {
+ drv = src->drv;
+
+ if (!drv->backend->storageFileGetUniqueIdentifier) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unique storage file identifier not implemented for "
"storage type %s (protocol: %s)'"),
@@ -4841,7 +4876,7 @@ virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
return NULL;
}
- return src->drv->backend->storageFileGetUniqueIdentifier(src);
+ return drv->backend->storageFileGetUniqueIdentifier(src);
}
@@ -4859,13 +4894,21 @@ int
virStorageFileAccess(virStorageSourcePtr src,
int mode)
{
- if (!virStorageFileIsInitialized(src) ||
- !src->drv->backend->storageFileAccess) {
+ virStorageDriverDataPtr drv = NULL;
+
+ if (!virStorageFileIsInitialized(src)) {
+ errno = ENOSYS;
+ return -2;
+ }
+
+ drv = src->drv;
+
+ if (!drv->backend->storageFileAccess) {
errno = ENOSYS;
return -2;
}
- return src->drv->backend->storageFileAccess(src, mode);
+ return drv->backend->storageFileAccess(src, mode);
}
@@ -4885,8 +4928,16 @@ virStorageFileChown(const virStorageSource *src,
uid_t uid,
gid_t gid)
{
- if (!virStorageFileIsInitialized(src) ||
- !src->drv->backend->storageFileChown) {
+ virStorageDriverDataPtr drv = NULL;
+
+ if (!virStorageFileIsInitialized(src)) {
+ errno = ENOSYS;
+ return -2;
+ }
+
+ drv = src->drv;
+
+ if (!drv->backend->storageFileChown) {
errno = ENOSYS;
return -2;
}
@@ -4894,7 +4945,7 @@ virStorageFileChown(const virStorageSource *src,
VIR_DEBUG("chown of storage file %p to %u:%u",
src, (unsigned int)uid, (unsigned int)gid);
- return src->drv->backend->storageFileChown(src, uid, gid);
+ return drv->backend->storageFileChown(src, uid, gid);
}
@@ -4914,8 +4965,9 @@ virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr parent)
{
if (src->drv) {
- unsigned int access_user = src->drv->uid;
- unsigned int access_group = src->drv->gid;
+ virStorageDriverDataPtr drv = src->drv;
+ unsigned int access_user = drv->uid;
+ unsigned int access_group = drv->gid;
if (src == parent) {
virReportSystemError(errcode,
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index d39486ad59..a1e0afb28f 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -262,9 +262,6 @@ struct _virStorageSourceSlice {
};
-typedef struct _virStorageDriverData virStorageDriverData;
-typedef virStorageDriverData *virStorageDriverDataPtr;
-
typedef struct _virStorageSource virStorageSource;
typedef virStorageSource *virStorageSourcePtr;
@@ -334,7 +331,7 @@ struct _virStorageSource {
virStorageSourcePtr backingStore;
/* metadata for storage driver access to remote and local volumes */
- virStorageDriverDataPtr drv;
+ void *drv;
/* metadata about storage image which need separate fields */
/* Relative name by which this image was opened from its parent, or NULL
diff --git a/src/util/virstoragefilebackend.h b/src/util/virstoragefilebackend.h
index c7af77bf8f..43b36e95bc 100644
--- a/src/util/virstoragefilebackend.h
+++ b/src/util/virstoragefilebackend.h
@@ -28,6 +28,8 @@
typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr;
+typedef struct _virStorageDriverData virStorageDriverData;
+typedef virStorageDriverData *virStorageDriverDataPtr;
struct _virStorageDriverData {
virStorageFileBackendPtr backend;
void *priv;
--
2.28.0