[libvirt PATCH v2 03/13] virstoragefile: change virStorageSource->drv to void pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 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 0fc6835f11..2560e10d37 100644
--- a/src/storage/storage_file_gluster.c
+++ b/src/storage/storage_file_gluster.c
@@ -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);
 }
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 17579126b0..24b47fc788 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -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;
+    }
+
+    drv = src->drv;
+
+    if (!drv->backend->storageFileAccess) {
         errno = ENOSYS;
         return -2;
     }
 
-    return src->drv->backend->storageFileAccess(src, mode);
+    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,
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 5689c39092..1a722e1fa4 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -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
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.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux