Blob Blame History Raw
From dfb0b07976de883017a8a176b18c6c1101108f5d Mon Sep 17 00:00:00 2001
Message-Id: <dfb0b07976de883017a8a176b18c6c1101108f5d@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:55:26 +0100
Subject: [PATCH] storage: add file functions for local and block files

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

Implement the "stat" and "unlink" function for "file" volumes and "stat"
for "block" volumes using the regular system calls.

(cherry picked from commit e62d09b155f005e2001277c13cbbb34e754c1b62)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage/storage_backend.c    |  4 ++++
 src/storage/storage_backend_fs.c | 48 ++++++++++++++++++++++++++++++++++++++++
 src/storage/storage_backend_fs.h |  2 ++
 3 files changed, 54 insertions(+)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index aa620f7..999f48f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -123,6 +123,10 @@ static virStorageBackendPtr backends[] = {
 
 
 static virStorageFileBackendPtr fileBackends[] = {
+#if WITH_STORAGE_FS
+    &virStorageFileBackendFile,
+    &virStorageFileBackendBlock,
+#endif
     NULL
 };
 
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 11bb39b..5b436ee 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1331,4 +1331,52 @@ virStorageBackend virStorageBackendNetFileSystem = {
     .deleteVol = virStorageBackendFileSystemVolDelete,
     .resizeVol = virStorageBackendFileSystemVolResize,
 };
+
+
+static int
+virStorageFileBackendFileUnlink(virStorageFilePtr file)
+{
+    int ret;
+
+    ret = unlink(file->path);
+    /* preserve errno */
+
+    VIR_DEBUG("removing storage file %p(%s): ret=%d, errno=%d",
+              file, file->path, ret, errno);
+
+    return ret;
+}
+
+
+static int
+virStorageFileBackendFileStat(virStorageFilePtr file,
+                              struct stat *st)
+{
+    int ret;
+
+    ret = stat(file->path, st);
+    /* preserve errno */
+
+    VIR_DEBUG("stat of storage file %p(%s): ret=%d, errno=%d",
+              file, file->path, ret, errno);
+
+    return ret;
+}
+
+
+virStorageFileBackend virStorageFileBackendFile = {
+    .type = VIR_DOMAIN_DISK_TYPE_FILE,
+
+    .storageFileUnlink = virStorageFileBackendFileUnlink,
+    .storageFileStat = virStorageFileBackendFileStat,
+};
+
+
+virStorageFileBackend virStorageFileBackendBlock = {
+    .type = VIR_DOMAIN_DISK_TYPE_BLOCK,
+
+    .storageFileStat = virStorageFileBackendFileStat,
+};
+
+
 #endif /* WITH_STORAGE_FS */
diff --git a/src/storage/storage_backend_fs.h b/src/storage/storage_backend_fs.h
index a519b38..347ea9b 100644
--- a/src/storage/storage_backend_fs.h
+++ b/src/storage/storage_backend_fs.h
@@ -38,4 +38,6 @@ typedef enum {
 } virStoragePoolProbeResult;
 extern virStorageBackend virStorageBackendDirectory;
 
+extern virStorageFileBackend virStorageFileBackendFile;
+extern virStorageFileBackend virStorageFileBackendBlock;
 #endif /* __VIR_STORAGE_BACKEND_FS_H__ */
-- 
1.9.0