]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Rework debugging of storage file access through storage driver
authorPeter Krempa <pkrempa@redhat.com>
Fri, 2 May 2014 14:51:48 +0000 (16:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 23 May 2014 07:25:52 +0000 (09:25 +0200)
Print the debug statements of individual file access functions from the
main API functions instead of the individual backend functions.

Also enhance initialization debug messages on a per-backend basis.

src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/storage/storage_driver.c

index de27890712db09ddf52cf5603e55ce529c501d9e..3d088baa659b0e4a7a07a990d2cbbad440792c12 100644 (file)
@@ -1339,18 +1339,31 @@ virStorageBackend virStorageBackendNetFileSystem = {
 };
 
 
+static void
+virStorageFileBackendFileDeinit(virStorageSourcePtr src)
+{
+    VIR_DEBUG("deinitializing FS storage file %p (%s:%s)", src,
+              virStorageTypeToString(virStorageSourceGetActualType(src)),
+              src->path);
+
+}
+
+
 static int
-virStorageFileBackendFileUnlink(virStorageSourcePtr src)
+virStorageFileBackendFileInit(virStorageSourcePtr src)
 {
-    int ret;
+    VIR_DEBUG("initializing FS storage file %p (%s:%s)", src,
+              virStorageTypeToString(virStorageSourceGetActualType(src)),
+              src->path);
 
-    ret = unlink(src->path);
-    /* preserve errno */
+    return 0;
+}
 
-    VIR_DEBUG("removing storage file %p(%s): ret=%d, errno=%d",
-              src, src->path, ret, errno);
 
-    return ret;
+static int
+virStorageFileBackendFileUnlink(virStorageSourcePtr src)
+{
+    return unlink(src->path);
 }
 
 
@@ -1358,21 +1371,16 @@ static int
 virStorageFileBackendFileStat(virStorageSourcePtr src,
                               struct stat *st)
 {
-    int ret;
-
-    ret = stat(src->path, st);
-    /* preserve errno */
-
-    VIR_DEBUG("stat of storage file %p(%s): ret=%d, errno=%d",
-              src, src->path, ret, errno);
-
-    return ret;
+    return stat(src->path, st);
 }
 
 
 virStorageFileBackend virStorageFileBackendFile = {
     .type = VIR_STORAGE_TYPE_FILE,
 
+    .backendInit = virStorageFileBackendFileInit,
+    .backendDeinit = virStorageFileBackendFileDeinit,
+
     .storageFileUnlink = virStorageFileBackendFileUnlink,
     .storageFileStat = virStorageFileBackendFileStat,
 };
@@ -1381,6 +1389,9 @@ virStorageFileBackend virStorageFileBackendFile = {
 virStorageFileBackend virStorageFileBackendBlock = {
     .type = VIR_STORAGE_TYPE_BLOCK,
 
+    .backendInit = virStorageFileBackendFileInit,
+    .backendDeinit = virStorageFileBackendFileDeinit,
+
     .storageFileStat = virStorageFileBackendFileStat,
 };
 
index 8679d968f8e18869a2212d7686a102d64c50ba24..e578e73cc10d3c9c9953a1ff545d77f4524dbc4e 100644 (file)
@@ -539,10 +539,12 @@ struct _virStorageFileBackendGlusterPriv {
 static void
 virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
 {
-    VIR_DEBUG("deinitializing gluster storage file %p(%s/%s)",
-              src, src->hosts[0].name, src->path);
     virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
 
+    VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%s/%s%s)",
+              src, src->hosts->name, src->hosts->port ? src->hosts->port : "0",
+              src->volume, src->path);
+
     if (priv->vol)
         glfs_fini(priv->vol);
 
@@ -558,12 +560,14 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
     const char *hostname = host->name;
     int port = 0;
 
-    VIR_DEBUG("initializing gluster storage file %p(%s/%s)",
-              src, hostname, src->path);
+    VIR_DEBUG("initializing gluster storage file %p (gluster://%s:%s/%s%s)",
+              src, hostname, host->port ? host->port : "0",
+              NULLSTR(src->volume), src->path);
 
     if (!src->volume) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("missing gluster volume name for path '%s'"), src->path);
+                       _("missing gluster volume name for path '%s'"),
+                       src->path);
         return -1;
     }
 
@@ -619,14 +623,8 @@ static int
 virStorageFileBackendGlusterUnlink(virStorageSourcePtr src)
 {
     virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
-    int ret;
-
-    ret = glfs_unlink(priv->vol, src->path);
-    /* preserve errno */
 
-    VIR_DEBUG("removing storage file %p(%s/%s): ret=%d, errno=%d",
-              src, src->hosts[0].name, src->path, ret, errno);
-    return ret;
+    return glfs_unlink(priv->vol, src->path);
 }
 
 
@@ -635,14 +633,8 @@ virStorageFileBackendGlusterStat(virStorageSourcePtr src,
                                  struct stat *st)
 {
     virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
-    int ret;
 
-    ret = glfs_stat(priv->vol, src->path, st);
-    /* preserve errno */
-
-    VIR_DEBUG("stat of storage file %p(%s/%s): ret=%d, errno=%d",
-              src, src->hosts[0].name, src->path, ret, errno);
-    return ret;
+    return glfs_stat(priv->vol, src->path, st);
 }
 
 
index f58e0a4ec6a8162f990dbce92e2f7e682c2fb80f..455a2efcc0e752d397820fb4895324e5364dcdc4 100644 (file)
@@ -2835,13 +2835,20 @@ virStorageFileInit(virStorageSourcePtr src)
 int
 virStorageFileCreate(virStorageSourcePtr src)
 {
+    int ret;
+
     if (!virStorageFileIsInitialized(src) ||
         !src->drv->backend->storageFileCreate) {
         errno = ENOSYS;
         return -2;
     }
 
-    return src->drv->backend->storageFileCreate(src);
+    ret = src->drv->backend->storageFileCreate(src);
+
+    VIR_DEBUG("created storage file %p: ret=%d, errno=%d",
+              src, ret, errno);
+
+    return ret;
 }
 
 
@@ -2858,13 +2865,20 @@ virStorageFileCreate(virStorageSourcePtr src)
 int
 virStorageFileUnlink(virStorageSourcePtr src)
 {
+    int ret;
+
     if (!virStorageFileIsInitialized(src) ||
         !src->drv->backend->storageFileUnlink) {
         errno = ENOSYS;
         return -2;
     }
 
-    return src->drv->backend->storageFileUnlink(src);
+    ret = src->drv->backend->storageFileUnlink(src);
+
+    VIR_DEBUG("unlinked storage file %p: ret=%d, errno=%d",
+              src, ret, errno);
+
+    return ret;
 }
 
 
@@ -2881,11 +2895,18 @@ int
 virStorageFileStat(virStorageSourcePtr src,
                    struct stat *st)
 {
+    int ret;
+
     if (!virStorageFileIsInitialized(src) ||
         !src->drv->backend->storageFileStat) {
         errno = ENOSYS;
         return -2;
     }
 
-    return src->drv->backend->storageFileStat(src, st);
+    ret = src->drv->backend->storageFileStat(src, st);
+
+    VIR_DEBUG("stat of storage file %p: ret=%d, errno=%d",
+              src, ret, errno);
+
+    return ret;
 }