virstoragefile: change virStorageSource->drv to void pointer

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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Pavel Hrdina 2020-12-08 15:22:57 +01:00
parent 7b4e3bab5b
commit 3e210d204c
5 changed files with 122 additions and 55 deletions

View File

@ -51,7 +51,8 @@ struct _virStorageFileBackendFsPriv {
static void static void
virStorageFileBackendFileDeinit(virStorageSourcePtr src) 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, VIR_DEBUG("deinitializing FS storage file %p (%s:%s)", src,
virStorageTypeToString(virStorageSourceGetActualType(src)), virStorageTypeToString(virStorageSourceGetActualType(src)),
@ -66,16 +67,17 @@ virStorageFileBackendFileDeinit(virStorageSourcePtr src)
static int static int
virStorageFileBackendFileInit(virStorageSourcePtr src) virStorageFileBackendFileInit(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendFsPrivPtr priv = NULL; virStorageFileBackendFsPrivPtr priv = NULL;
VIR_DEBUG("initializing FS storage file %p (%s:%s)[%u:%u]", src, VIR_DEBUG("initializing FS storage file %p (%s:%s)[%u:%u]", src,
virStorageTypeToString(virStorageSourceGetActualType(src)), virStorageTypeToString(virStorageSourceGetActualType(src)),
src->path, 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); priv = g_new0(virStorageFileBackendFsPriv, 1);
src->drv->priv = priv; drv->priv = priv;
return 0; return 0;
} }
@ -84,10 +86,11 @@ virStorageFileBackendFileInit(virStorageSourcePtr src)
static int static int
virStorageFileBackendFileCreate(virStorageSourcePtr src) virStorageFileBackendFileCreate(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = src->drv;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR, 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; errno = -fd;
return -1; return -1;
} }
@ -117,11 +120,12 @@ virStorageFileBackendFileRead(virStorageSourcePtr src,
size_t len, size_t len,
char **buf) char **buf)
{ {
virStorageDriverDataPtr drv = src->drv;
ssize_t ret = -1; ssize_t ret = -1;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
if ((fd = virFileOpenAs(src->path, O_RDONLY, 0, 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'"), virReportSystemError(-fd, _("Failed to open file '%s'"),
src->path); src->path);
return -1; return -1;
@ -146,7 +150,8 @@ virStorageFileBackendFileRead(virStorageSourcePtr src,
static const char * static const char *
virStorageFileBackendFileGetUniqueIdentifier(virStorageSourcePtr src) virStorageFileBackendFileGetUniqueIdentifier(virStorageSourcePtr src)
{ {
virStorageFileBackendFsPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendFsPrivPtr priv = drv->priv;
if (!priv->canonpath) { if (!priv->canonpath) {
if (!(priv->canonpath = virFileCanonicalizePath(src->path))) { if (!(priv->canonpath = virFileCanonicalizePath(src->path))) {
@ -164,8 +169,10 @@ static int
virStorageFileBackendFileAccess(virStorageSourcePtr src, virStorageFileBackendFileAccess(virStorageSourcePtr src,
int mode) int mode)
{ {
virStorageDriverDataPtr drv = src->drv;
return virFileAccessibleAs(src->path, mode, return virFileAccessibleAs(src->path, mode,
src->drv->uid, src->drv->gid); drv->uid, drv->gid);
} }

View File

@ -47,7 +47,8 @@ struct _virStorageFileBackendGlusterPriv {
static void static void
virStorageFileBackendGlusterDeinit(virStorageSourcePtr src) 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)", VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%u/%s%s)",
src, src->hosts->name, src->hosts->port, src->volume, src->path); src, src->hosts->name, src->hosts->port, src->volume, src->path);
@ -57,7 +58,7 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
VIR_FREE(priv->canonpath); VIR_FREE(priv->canonpath);
VIR_FREE(priv); VIR_FREE(priv);
src->drv->priv = NULL; drv->priv = NULL;
} }
static int static int
@ -100,6 +101,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
static int static int
virStorageFileBackendGlusterInit(virStorageSourcePtr src) virStorageFileBackendGlusterInit(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = NULL; virStorageFileBackendGlusterPrivPtr priv = NULL;
size_t i; size_t i;
@ -115,7 +117,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
VIR_DEBUG("initializing gluster storage file %p " VIR_DEBUG("initializing gluster storage file %p "
"(priv='%p' volume='%s' path='%s') as [%u:%u]", "(priv='%p' volume='%s' path='%s') as [%u:%u]",
src, priv, src->volume, src->path, 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))) { if (!(priv->vol = glfs_new(src->volume))) {
virReportOOMError(); virReportOOMError();
@ -134,7 +136,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
goto error; goto error;
} }
src->drv->priv = priv; drv->priv = priv;
return 0; return 0;
@ -150,7 +152,8 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
static int static int
virStorageFileBackendGlusterCreate(virStorageSourcePtr src) virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
glfs_fd_t *fd = NULL; glfs_fd_t *fd = NULL;
if (!(fd = glfs_creat(priv->vol, src->path, if (!(fd = glfs_creat(priv->vol, src->path,
@ -165,7 +168,8 @@ virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
static int static int
virStorageFileBackendGlusterUnlink(virStorageSourcePtr src) virStorageFileBackendGlusterUnlink(virStorageSourcePtr src)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_unlink(priv->vol, src->path); return glfs_unlink(priv->vol, src->path);
} }
@ -175,7 +179,8 @@ static int
virStorageFileBackendGlusterStat(virStorageSourcePtr src, virStorageFileBackendGlusterStat(virStorageSourcePtr src,
struct stat *st) struct stat *st)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_stat(priv->vol, src->path, st); return glfs_stat(priv->vol, src->path, st);
} }
@ -187,7 +192,8 @@ virStorageFileBackendGlusterRead(virStorageSourcePtr src,
size_t len, size_t len,
char **buf) char **buf)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
glfs_fd_t *fd = NULL; glfs_fd_t *fd = NULL;
ssize_t ret = -1; ssize_t ret = -1;
char *s; char *s;
@ -242,7 +248,8 @@ static int
virStorageFileBackendGlusterAccess(virStorageSourcePtr src, virStorageFileBackendGlusterAccess(virStorageSourcePtr src,
int mode) int mode)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
return glfs_access(priv->vol, src->path, mode); return glfs_access(priv->vol, src->path, mode);
} }
@ -295,7 +302,8 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
static const char * static const char *
virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageDriverDataPtr drv = src->drv;
virStorageFileBackendGlusterPrivPtr priv = drv->priv;
g_autofree char *filePath = NULL; g_autofree char *filePath = NULL;
if (priv->canonpath) if (priv->canonpath)
@ -321,7 +329,8 @@ virStorageFileBackendGlusterChown(const virStorageSource *src,
uid_t uid, uid_t uid,
gid_t gid) 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); return glfs_chown(priv->vol, src->path, uid, gid);
} }

View File

@ -4619,7 +4619,8 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
} }
if (src->drv) { if (src->drv) {
*backend = src->drv->backend; virStorageDriverDataPtr drv = src->drv;
*backend = drv->backend;
return 1; return 1;
} }
@ -4715,12 +4716,16 @@ virStorageFileSupportsCreate(const virStorageSource *src)
void void
virStorageFileDeinit(virStorageSourcePtr src) virStorageFileDeinit(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = NULL;
if (!virStorageFileIsInitialized(src)) if (!virStorageFileIsInitialized(src))
return; return;
if (src->drv->backend && drv = src->drv;
src->drv->backend->backendDeinit)
src->drv->backend->backendDeinit(src); if (drv->backend &&
drv->backend->backendDeinit)
drv->backend->backendDeinit(src);
VIR_FREE(src->drv); VIR_FREE(src->drv);
} }
@ -4744,26 +4749,28 @@ virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid) uid_t uid, gid_t gid)
{ {
int actualType = virStorageSourceGetActualType(src); int actualType = virStorageSourceGetActualType(src);
src->drv = g_new0(virStorageDriverData, 1); virStorageDriverDataPtr drv = g_new0(virStorageDriverData, 1);
src->drv = drv;
if (uid == (uid_t) -1) if (uid == (uid_t) -1)
src->drv->uid = geteuid(); drv->uid = geteuid();
else else
src->drv->uid = uid; drv->uid = uid;
if (gid == (gid_t) -1) if (gid == (gid_t) -1)
src->drv->gid = getegid(); drv->gid = getegid();
else else
src->drv->gid = gid; drv->gid = gid;
if (virStorageFileBackendForType(actualType, if (virStorageFileBackendForType(actualType,
src->protocol, src->protocol,
true, true,
&src->drv->backend) < 0) &drv->backend) < 0)
goto error; goto error;
if (src->drv->backend->backendInit && if (drv->backend->backendInit &&
src->drv->backend->backendInit(src) < 0) drv->backend->backendInit(src) < 0)
goto error; goto error;
return 0; return 0;
@ -4798,15 +4805,22 @@ virStorageFileInit(virStorageSourcePtr src)
int int
virStorageFileCreate(virStorageSourcePtr src) virStorageFileCreate(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = NULL;
int ret; int ret;
if (!virStorageFileIsInitialized(src) || if (!virStorageFileIsInitialized(src)) {
!src->drv->backend->storageFileCreate) {
errno = ENOSYS; errno = ENOSYS;
return -2; 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", VIR_DEBUG("created storage file %p: ret=%d, errno=%d",
src, ret, errno); src, ret, errno);
@ -4828,15 +4842,22 @@ virStorageFileCreate(virStorageSourcePtr src)
int int
virStorageFileUnlink(virStorageSourcePtr src) virStorageFileUnlink(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = NULL;
int ret; int ret;
if (!virStorageFileIsInitialized(src) || if (!virStorageFileIsInitialized(src)) {
!src->drv->backend->storageFileUnlink) {
errno = ENOSYS; errno = ENOSYS;
return -2; 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", VIR_DEBUG("unlinked storage file %p: ret=%d, errno=%d",
src, ret, errno); src, ret, errno);
@ -4858,15 +4879,22 @@ int
virStorageFileStat(virStorageSourcePtr src, virStorageFileStat(virStorageSourcePtr src,
struct stat *st) struct stat *st)
{ {
virStorageDriverDataPtr drv = NULL;
int ret; int ret;
if (!virStorageFileIsInitialized(src) || if (!virStorageFileIsInitialized(src)) {
!src->drv->backend->storageFileStat) {
errno = ENOSYS; errno = ENOSYS;
return -2; 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", VIR_DEBUG("stat of storage file %p: ret=%d, errno=%d",
src, ret, errno); src, ret, errno);
@ -4893,6 +4921,7 @@ virStorageFileRead(virStorageSourcePtr src,
size_t len, size_t len,
char **buf) char **buf)
{ {
virStorageDriverDataPtr drv = NULL;
ssize_t ret; ssize_t ret;
if (!virStorageFileIsInitialized(src)) { if (!virStorageFileIsInitialized(src)) {
@ -4901,10 +4930,12 @@ virStorageFileRead(virStorageSourcePtr src,
return -1; return -1;
} }
if (!src->drv->backend->storageFileRead) drv = src->drv;
if (!drv->backend->storageFileRead)
return -2; 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'", VIR_DEBUG("read '%zd' bytes from storage '%p' starting at offset '%zu'",
ret, src, offset); ret, src, offset);
@ -4924,13 +4955,17 @@ virStorageFileRead(virStorageSourcePtr src,
const char * const char *
virStorageFileGetUniqueIdentifier(virStorageSourcePtr src) virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
{ {
virStorageDriverDataPtr drv = NULL;
if (!virStorageFileIsInitialized(src)) { if (!virStorageFileIsInitialized(src)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("storage file backend not initialized")); _("storage file backend not initialized"));
return NULL; return NULL;
} }
if (!src->drv->backend->storageFileGetUniqueIdentifier) { drv = src->drv;
if (!drv->backend->storageFileGetUniqueIdentifier) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unique storage file identifier not implemented for " _("unique storage file identifier not implemented for "
"storage type %s (protocol: %s)'"), "storage type %s (protocol: %s)'"),
@ -4939,7 +4974,7 @@ virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
return NULL; return NULL;
} }
return src->drv->backend->storageFileGetUniqueIdentifier(src); return drv->backend->storageFileGetUniqueIdentifier(src);
} }
@ -4957,13 +4992,21 @@ int
virStorageFileAccess(virStorageSourcePtr src, virStorageFileAccess(virStorageSourcePtr src,
int mode) int mode)
{ {
if (!virStorageFileIsInitialized(src) || virStorageDriverDataPtr drv = NULL;
!src->drv->backend->storageFileAccess) {
if (!virStorageFileIsInitialized(src)) {
errno = ENOSYS; errno = ENOSYS;
return -2; return -2;
} }
return src->drv->backend->storageFileAccess(src, mode); drv = src->drv;
if (!drv->backend->storageFileAccess) {
errno = ENOSYS;
return -2;
}
return drv->backend->storageFileAccess(src, mode);
} }
@ -4983,8 +5026,16 @@ virStorageFileChown(const virStorageSource *src,
uid_t uid, uid_t uid,
gid_t gid) gid_t gid)
{ {
if (!virStorageFileIsInitialized(src) || virStorageDriverDataPtr drv = NULL;
!src->drv->backend->storageFileChown) {
if (!virStorageFileIsInitialized(src)) {
errno = ENOSYS;
return -2;
}
drv = src->drv;
if (!drv->backend->storageFileChown) {
errno = ENOSYS; errno = ENOSYS;
return -2; return -2;
} }
@ -4992,7 +5043,7 @@ virStorageFileChown(const virStorageSource *src,
VIR_DEBUG("chown of storage file %p to %u:%u", VIR_DEBUG("chown of storage file %p to %u:%u",
src, (unsigned int)uid, (unsigned int)gid); src, (unsigned int)uid, (unsigned int)gid);
return src->drv->backend->storageFileChown(src, uid, gid); return drv->backend->storageFileChown(src, uid, gid);
} }
@ -5012,8 +5063,9 @@ virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr parent) virStorageSourcePtr parent)
{ {
if (src->drv) { if (src->drv) {
unsigned int access_user = src->drv->uid; virStorageDriverDataPtr drv = src->drv;
unsigned int access_group = src->drv->gid; unsigned int access_user = drv->uid;
unsigned int access_group = drv->gid;
if (src == parent) { if (src == parent) {
virReportSystemError(errcode, virReportSystemError(errcode,

View File

@ -263,9 +263,6 @@ struct _virStorageSourceSlice {
}; };
typedef struct _virStorageDriverData virStorageDriverData;
typedef virStorageDriverData *virStorageDriverDataPtr;
typedef struct _virStorageSource virStorageSource; typedef struct _virStorageSource virStorageSource;
typedef virStorageSource *virStorageSourcePtr; typedef virStorageSource *virStorageSourcePtr;
@ -337,7 +334,7 @@ struct _virStorageSource {
virStorageSourcePtr backingStore; virStorageSourcePtr backingStore;
/* metadata for storage driver access to remote and local volumes */ /* metadata for storage driver access to remote and local volumes */
virStorageDriverDataPtr drv; void *drv;
/* metadata about storage image which need separate fields */ /* metadata about storage image which need separate fields */
/* Relative name by which this image was opened from its parent, or NULL /* Relative name by which this image was opened from its parent, or NULL

View File

@ -28,6 +28,8 @@
typedef struct _virStorageFileBackend virStorageFileBackend; typedef struct _virStorageFileBackend virStorageFileBackend;
typedef virStorageFileBackend *virStorageFileBackendPtr; typedef virStorageFileBackend *virStorageFileBackendPtr;
typedef struct _virStorageDriverData virStorageDriverData;
typedef virStorageDriverData *virStorageDriverDataPtr;
struct _virStorageDriverData { struct _virStorageDriverData {
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
void *priv; void *priv;