1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

storage: add file functions for local and block files

Implement the "stat" and "unlink" function for "file" volumes and "stat"
for "block" volumes using the regular system calls.
This commit is contained in:
Peter Krempa 2014-02-03 16:41:49 +01:00
parent e32268184b
commit e62d09b155
3 changed files with 54 additions and 0 deletions

View File

@ -123,6 +123,10 @@ static virStorageBackendPtr backends[] = {
static virStorageFileBackendPtr fileBackends[] = {
#if WITH_STORAGE_FS
&virStorageFileBackendFile,
&virStorageFileBackendBlock,
#endif
NULL
};

View 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 */

View File

@ -38,4 +38,6 @@ typedef enum {
} virStoragePoolProbeResult;
extern virStorageBackend virStorageBackendDirectory;
extern virStorageFileBackend virStorageFileBackendFile;
extern virStorageFileBackend virStorageFileBackendBlock;
#endif /* __VIR_STORAGE_BACKEND_FS_H__ */