c401cc
From dfb0b07976de883017a8a176b18c6c1101108f5d Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <dfb0b07976de883017a8a176b18c6c1101108f5d@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:55:26 +0100
c401cc
Subject: [PATCH] storage: add file functions for local and block files
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Implement the "stat" and "unlink" function for "file" volumes and "stat"
c401cc
for "block" volumes using the regular system calls.
c401cc
c401cc
(cherry picked from commit e62d09b155f005e2001277c13cbbb34e754c1b62)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/storage/storage_backend.c    |  4 ++++
c401cc
 src/storage/storage_backend_fs.c | 48 ++++++++++++++++++++++++++++++++++++++++
c401cc
 src/storage/storage_backend_fs.h |  2 ++
c401cc
 3 files changed, 54 insertions(+)
c401cc
c401cc
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
c401cc
index aa620f7..999f48f 100644
c401cc
--- a/src/storage/storage_backend.c
c401cc
+++ b/src/storage/storage_backend.c
c401cc
@@ -123,6 +123,10 @@ static virStorageBackendPtr backends[] = {
c401cc
 
c401cc
 
c401cc
 static virStorageFileBackendPtr fileBackends[] = {
c401cc
+#if WITH_STORAGE_FS
c401cc
+    &virStorageFileBackendFile,
c401cc
+    &virStorageFileBackendBlock,
c401cc
+#endif
c401cc
     NULL
c401cc
 };
c401cc
 
c401cc
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
c401cc
index 11bb39b..5b436ee 100644
c401cc
--- a/src/storage/storage_backend_fs.c
c401cc
+++ b/src/storage/storage_backend_fs.c
c401cc
@@ -1331,4 +1331,52 @@ virStorageBackend virStorageBackendNetFileSystem = {
c401cc
     .deleteVol = virStorageBackendFileSystemVolDelete,
c401cc
     .resizeVol = virStorageBackendFileSystemVolResize,
c401cc
 };
c401cc
+
c401cc
+
c401cc
+static int
c401cc
+virStorageFileBackendFileUnlink(virStorageFilePtr file)
c401cc
+{
c401cc
+    int ret;
c401cc
+
c401cc
+    ret = unlink(file->path);
c401cc
+    /* preserve errno */
c401cc
+
c401cc
+    VIR_DEBUG("removing storage file %p(%s): ret=%d, errno=%d",
c401cc
+              file, file->path, ret, errno);
c401cc
+
c401cc
+    return ret;
c401cc
+}
c401cc
+
c401cc
+
c401cc
+static int
c401cc
+virStorageFileBackendFileStat(virStorageFilePtr file,
c401cc
+                              struct stat *st)
c401cc
+{
c401cc
+    int ret;
c401cc
+
c401cc
+    ret = stat(file->path, st);
c401cc
+    /* preserve errno */
c401cc
+
c401cc
+    VIR_DEBUG("stat of storage file %p(%s): ret=%d, errno=%d",
c401cc
+              file, file->path, ret, errno);
c401cc
+
c401cc
+    return ret;
c401cc
+}
c401cc
+
c401cc
+
c401cc
+virStorageFileBackend virStorageFileBackendFile = {
c401cc
+    .type = VIR_DOMAIN_DISK_TYPE_FILE,
c401cc
+
c401cc
+    .storageFileUnlink = virStorageFileBackendFileUnlink,
c401cc
+    .storageFileStat = virStorageFileBackendFileStat,
c401cc
+};
c401cc
+
c401cc
+
c401cc
+virStorageFileBackend virStorageFileBackendBlock = {
c401cc
+    .type = VIR_DOMAIN_DISK_TYPE_BLOCK,
c401cc
+
c401cc
+    .storageFileStat = virStorageFileBackendFileStat,
c401cc
+};
c401cc
+
c401cc
+
c401cc
 #endif /* WITH_STORAGE_FS */
c401cc
diff --git a/src/storage/storage_backend_fs.h b/src/storage/storage_backend_fs.h
c401cc
index a519b38..347ea9b 100644
c401cc
--- a/src/storage/storage_backend_fs.h
c401cc
+++ b/src/storage/storage_backend_fs.h
c401cc
@@ -38,4 +38,6 @@ typedef enum {
c401cc
 } virStoragePoolProbeResult;
c401cc
 extern virStorageBackend virStorageBackendDirectory;
c401cc
 
c401cc
+extern virStorageFileBackend virStorageFileBackendFile;
c401cc
+extern virStorageFileBackend virStorageFileBackendBlock;
c401cc
 #endif /* __VIR_STORAGE_BACKEND_FS_H__ */
c401cc
-- 
c401cc
1.9.0
c401cc