]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: add file functions for local and block files
authorPeter Krempa <pkrempa@redhat.com>
Mon, 3 Feb 2014 15:41:49 +0000 (16:41 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Feb 2014 09:47:57 +0000 (10:47 +0100)
Implement the "stat" and "unlink" function for "file" volumes and "stat"
for "block" volumes using the regular system calls.

src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_fs.h

index b59b5b7b80549bfa446e6d3132cc9fb843fa26f3..aa12c5aecea1d1e45f36cf5820d7c774edb60398 100644 (file)
@@ -123,6 +123,10 @@ static virStorageBackendPtr backends[] = {
 
 
 static virStorageFileBackendPtr fileBackends[] = {
+#if WITH_STORAGE_FS
+    &virStorageFileBackendFile,
+    &virStorageFileBackendBlock,
+#endif
     NULL
 };
 
index fa11e2f41c22a9281bbacb69e6fbf69cca5eaff5..4d69f74a998a27b7c1352c70fbce2d3a24438688 100644 (file)
@@ -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 */
index a519b3810bb40418a9c54e97c2aa255ece94a2d2..347ea9be5c7f33a1cfe116e126cd6b1a3daaab71 100644 (file)
@@ -38,4 +38,6 @@ typedef enum {
 } virStoragePoolProbeResult;
 extern virStorageBackend virStorageBackendDirectory;
 
+extern virStorageFileBackend virStorageFileBackendFile;
+extern virStorageFileBackend virStorageFileBackendBlock;
 #endif /* __VIR_STORAGE_BACKEND_FS_H__ */