[libvirt] [PATCHv6 4/8] storage: add file functions for local and block files

Peter Krempa pkrempa at redhat.com
Thu Feb 13 16:49:46 UTC 2014


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

Notes:
    Version 6:
    - tweaked error message style
    - made sure that libvirt compiles cleanly with --without-storage-fs (added ifdefs)
    
    Version 5:
    - added debug messages
    - adapted to error reporting changes
    
    Version 4:
    - adapt to change in error reporting
    
    Version 6:
    - tweaked error message style
    
    Version 5:
    - added debug messages
    - adapted to error reporting changes
    
    Version 4:
    - adapt to change in error reporting

 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 b59b5b7..aa12c5a 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 fa11e2f..4d69f74 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1327,4 +1327,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.8.5.3




More information about the libvir-list mailing list