mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
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:
parent
7b4e3bab5b
commit
3e210d204c
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,7 +47,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);
|
||||
@ -57,7 +58,7 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
|
||||
VIR_FREE(priv->canonpath);
|
||||
|
||||
VIR_FREE(priv);
|
||||
src->drv->priv = NULL;
|
||||
drv->priv = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -100,6 +101,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
|
||||
static int
|
||||
virStorageFileBackendGlusterInit(virStorageSourcePtr src)
|
||||
{
|
||||
virStorageDriverDataPtr drv = src->drv;
|
||||
virStorageFileBackendGlusterPrivPtr priv = NULL;
|
||||
size_t i;
|
||||
|
||||
@ -115,7 +117,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();
|
||||
@ -134,7 +136,7 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
|
||||
goto error;
|
||||
}
|
||||
|
||||
src->drv->priv = priv;
|
||||
drv->priv = priv;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -150,7 +152,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,
|
||||
@ -165,7 +168,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);
|
||||
}
|
||||
@ -175,7 +179,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);
|
||||
}
|
||||
@ -187,7 +192,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;
|
||||
@ -242,7 +248,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);
|
||||
}
|
||||
@ -295,7 +302,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)
|
||||
@ -321,7 +329,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);
|
||||
}
|
||||
|
@ -4619,7 +4619,8 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
|
||||
}
|
||||
|
||||
if (src->drv) {
|
||||
*backend = src->drv->backend;
|
||||
virStorageDriverDataPtr drv = src->drv;
|
||||
*backend = drv->backend;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -4715,12 +4716,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);
|
||||
}
|
||||
@ -4744,26 +4749,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;
|
||||
@ -4798,15 +4805,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);
|
||||
@ -4828,15 +4842,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);
|
||||
@ -4858,15 +4879,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);
|
||||
@ -4893,6 +4921,7 @@ virStorageFileRead(virStorageSourcePtr src,
|
||||
size_t len,
|
||||
char **buf)
|
||||
{
|
||||
virStorageDriverDataPtr drv = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (!virStorageFileIsInitialized(src)) {
|
||||
@ -4901,10 +4930,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);
|
||||
@ -4924,13 +4955,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)'"),
|
||||
@ -4939,7 +4974,7 @@ virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return src->drv->backend->storageFileGetUniqueIdentifier(src);
|
||||
return drv->backend->storageFileGetUniqueIdentifier(src);
|
||||
}
|
||||
|
||||
|
||||
@ -4957,13 +4992,21 @@ int
|
||||
virStorageFileAccess(virStorageSourcePtr src,
|
||||
int mode)
|
||||
{
|
||||
if (!virStorageFileIsInitialized(src) ||
|
||||
!src->drv->backend->storageFileAccess) {
|
||||
virStorageDriverDataPtr drv = NULL;
|
||||
|
||||
if (!virStorageFileIsInitialized(src)) {
|
||||
errno = ENOSYS;
|
||||
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,
|
||||
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;
|
||||
}
|
||||
@ -4992,7 +5043,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);
|
||||
}
|
||||
|
||||
|
||||
@ -5012,8 +5063,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,
|
||||
|
@ -263,9 +263,6 @@ struct _virStorageSourceSlice {
|
||||
};
|
||||
|
||||
|
||||
typedef struct _virStorageDriverData virStorageDriverData;
|
||||
typedef virStorageDriverData *virStorageDriverDataPtr;
|
||||
|
||||
typedef struct _virStorageSource virStorageSource;
|
||||
typedef virStorageSource *virStorageSourcePtr;
|
||||
|
||||
@ -337,7 +334,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
|
||||
|
@ -28,6 +28,8 @@
|
||||
typedef struct _virStorageFileBackend virStorageFileBackend;
|
||||
typedef virStorageFileBackend *virStorageFileBackendPtr;
|
||||
|
||||
typedef struct _virStorageDriverData virStorageDriverData;
|
||||
typedef virStorageDriverData *virStorageDriverDataPtr;
|
||||
struct _virStorageDriverData {
|
||||
virStorageFileBackendPtr backend;
|
||||
void *priv;
|
||||
|
Loading…
Reference in New Issue
Block a user