util: extract virStorageFile code into storage_source

Up until now we had a runtime code and XML related code in the same
source file inside util directory.

This patch takes the runtime part and extracts it into the new
storage_file directory.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Pavel Hrdina 2021-01-22 10:36:21 +01:00
parent 296032bfb2
commit 01f7ade912
25 changed files with 2833 additions and 2679 deletions

View File

@ -225,6 +225,7 @@
@SRCDIR@src/storage/storage_util.c
@SRCDIR@src/storage_file/storage_file_backend_fs.c
@SRCDIR@src/storage_file/storage_file_backend_gluster.c
@SRCDIR@src/storage_file/storage_source.c
@SRCDIR@src/test/test_driver.c
@SRCDIR@src/util/iohelper.c
@SRCDIR@src/util/viralloc.c

View File

@ -1618,6 +1618,36 @@ virSecurityManagerVerify;
virSecurityXATTRNamespaceDefined;
# storage_file/storage_source.h
virStorageFileAccess;
virStorageFileChainLookup;
virStorageFileChown;
virStorageFileCreate;
virStorageFileDeinit;
virStorageFileGetBackingStoreStr;
virStorageFileGetMetadata;
virStorageFileGetMetadataFromBuf;
virStorageFileGetMetadataFromFD;
virStorageFileGetRelativeBackingPath;
virStorageFileGetUniqueIdentifier;
virStorageFileInit;
virStorageFileInitAs;
virStorageFileRead;
virStorageFileReportBrokenChain;
virStorageFileStat;
virStorageFileSupportsAccess;
virStorageFileSupportsBackingChainTraversal;
virStorageFileSupportsCreate;
virStorageFileSupportsSecurityDriver;
virStorageFileUnlink;
virStorageSourceNewFromBacking;
virStorageSourceNewFromBackingAbsolute;
virStorageSourceParseRBDColonString;
virStorageSourceUpdateBackingSizes;
virStorageSourceUpdateCapacity;
virStorageSourceUpdatePhysicalSize;
# util/glibcompat.h
vir_g_canonicalize_filename;
vir_g_fsync;
@ -3126,36 +3156,15 @@ virStorageAuthDefCopy;
virStorageAuthDefFormat;
virStorageAuthDefFree;
virStorageAuthDefParse;
virStorageFileAccess;
virStorageFileCanonicalizePath;
virStorageFileChainLookup;
virStorageFileChown;
virStorageFileCreate;
virStorageFileDeinit;
virStorageFileFeatureTypeFromString;
virStorageFileFeatureTypeToString;
virStorageFileFormatTypeFromString;
virStorageFileFormatTypeToString;
virStorageFileGetBackingStoreStr;
virStorageFileGetMetadata;
virStorageFileGetMetadataFromBuf;
virStorageFileGetMetadataFromFD;
virStorageFileGetNPIVKey;
virStorageFileGetRelativeBackingPath;
virStorageFileGetSCSIKey;
virStorageFileGetUniqueIdentifier;
virStorageFileInit;
virStorageFileInitAs;
virStorageFileParseBackingStoreStr;
virStorageFileParseChainIndex;
virStorageFileRead;
virStorageFileReportBrokenChain;
virStorageFileStat;
virStorageFileSupportsAccess;
virStorageFileSupportsBackingChainTraversal;
virStorageFileSupportsCreate;
virStorageFileSupportsSecurityDriver;
virStorageFileUnlink;
virStorageIsFile;
virStorageIsRelative;
virStorageNetHostDefClear;
@ -3191,18 +3200,12 @@ virStorageSourceIsSameLocation;
virStorageSourceNetCookiesValidate;
virStorageSourceNetworkAssignDefaultPorts;
virStorageSourceNew;
virStorageSourceNewFromBacking;
virStorageSourceNewFromBackingAbsolute;
virStorageSourceNVMeDefFree;
virStorageSourceParseRBDColonString;
virStorageSourcePoolDefFree;
virStorageSourcePoolModeTypeFromString;
virStorageSourcePoolModeTypeToString;
virStorageSourcePrivateDataFormatRelPath;
virStorageSourcePrivateDataParseRelPath;
virStorageSourceUpdateBackingSizes;
virStorageSourceUpdateCapacity;
virStorageSourceUpdatePhysicalSize;
virStorageTypeFromString;
virStorageTypeToString;

View File

@ -27,6 +27,7 @@ if conf.has('WITH_LIBXL')
include_directories: [
conf_inc_dir,
hypervisor_inc_dir,
storage_file_inc_dir,
],
)

View File

@ -29,7 +29,7 @@
#include "domain_conf.h"
#include "viralloc.h"
#include "virstring.h"
#include "virstoragefile.h"
#include "storage_source.h"
#include "xen_xl.h"
#include "libxl_capabilities.h"
#include "libxl_conf.h"

View File

@ -104,6 +104,7 @@ if conf.has('WITH_QEMU')
include_directories: [
conf_inc_dir,
hypervisor_inc_dir,
storage_file_inc_dir,
],
)

View File

@ -29,6 +29,7 @@
#include "qemu_checkpoint.h"
#include "qemu_command.h"
#include "storage_source.h"
#include "virerror.h"
#include "virlog.h"
#include "virbuffer.h"

View File

@ -24,6 +24,7 @@
#include "qemu_alias.h"
#include "qemu_security.h"
#include "storage_source.h"
#include "viralloc.h"
#include "virstoragefile.h"
#include "virstring.h"

View File

@ -52,6 +52,7 @@
#include "virtime.h"
#include "virnetdevopenvswitch.h"
#include "virstoragefile.h"
#include "storage_source.h"
#include "virstring.h"
#include "virthreadjob.h"
#include "virprocess.h"

View File

@ -84,6 +84,7 @@
#include "virhook.h"
#include "virstoragefile.h"
#include "virstoragefileprobe.h"
#include "storage_source.h"
#include "virfile.h"
#include "virfdstream.h"
#include "configmake.h"

View File

@ -53,6 +53,7 @@
#include "virnetdevmidonet.h"
#include "device_conf.h"
#include "virstoragefile.h"
#include "storage_source.h"
#include "virstring.h"
#include "virtime.h"
#include "virqemu.h"

View File

@ -95,6 +95,7 @@
#include "viridentity.h"
#include "virthreadjob.h"
#include "virutil.h"
#include "storage_source.h"
#define VIR_FROM_THIS VIR_FROM_QEMU

View File

@ -42,6 +42,7 @@
#include "virstring.h"
#include "virdomainsnapshotobjlist.h"
#include "virqemu.h"
#include "storage_source.h"
#define VIR_FROM_THIS VIR_FROM_QEMU

View File

@ -48,6 +48,7 @@ if conf.has('WITH_LIBVIRTD') and conf.has('WITH_APPARMOR')
conf_inc_dir,
hypervisor_inc_dir,
include_directories('.'),
include_directories('../storage_file'),
],
}
endif

View File

@ -37,6 +37,7 @@
#include "security_driver.h"
#include "security_apparmor.h"
#include "storage_source.h"
#include "domain_conf.h"
#include "virxml.h"
#include "viruuid.h"
@ -46,7 +47,6 @@
#include "virfile.h"
#include "configmake.h"
#include "virrandom.h"
#include "virstoragefile.h"
#include "virstring.h"
#include "virgettext.h"
#include "virhostdev.h"

View File

@ -79,6 +79,7 @@ if conf.has('WITH_STORAGE')
],
include_directories: [
conf_inc_dir,
include_directories('../storage_file'),
],
)
@ -162,6 +163,9 @@ if conf.has('WITH_STORAGE_GLUSTER')
'deps': [
glusterfs_dep,
],
'include': [
include_directories('../storage_file'),
],
'install_dir': storage_backend_install_dir,
}
endif

View File

@ -32,6 +32,7 @@
#include "virstring.h"
#include "viruri.h"
#include "storage_util.h"
#include "storage_source.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE

View File

@ -64,6 +64,7 @@
#include "virstoragefile.h"
#include "virstoragefileprobe.h"
#include "storage_util.h"
#include "storage_source.h"
#include "virlog.h"
#include "virfile.h"
#include "virjson.h"

View File

@ -1,3 +1,7 @@
storage_file_sources = [
'storage_source.c',
]
stoarge_file_fs_sources = [
'storage_file_backend_fs.c',
]
@ -8,6 +12,18 @@ storage_file_gluster_sources = [
storage_file_install_dir = libdir / 'libvirt' / 'storage-file'
virt_storage_file_lib = static_library(
'virt_storage_file',
[
storage_file_sources,
],
dependencies: [
src_dep,
],
)
libvirt_libs += virt_storage_file_lib
if conf.has('WITH_STORAGE')
virt_modules += {
'name': 'virt_storage_file_fs',
@ -36,3 +52,5 @@ if conf.has('WITH_STORAGE_GLUSTER')
'install_dir': storage_file_install_dir,
}
endif
storage_file_inc_dir = include_directories('.')

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,148 @@
/*
* storage_source.h: file utility functions for FS storage backend
*
* Copyright (C) 2007-2009, 2012-2016 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "virstoragefile.h"
#ifndef DEV_BSIZE
# define DEV_BSIZE 512
#endif
virStorageSourcePtr
virStorageFileGetMetadataFromFD(const char *path,
int fd,
int format);
virStorageSourcePtr
virStorageFileGetMetadataFromBuf(const char *path,
char *buf,
size_t len,
int format)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
virStorageSourcePtr
virStorageFileChainLookup(virStorageSourcePtr chain,
virStorageSourcePtr startFrom,
const char *name,
unsigned int idx,
virStorageSourcePtr *parent)
ATTRIBUTE_NONNULL(1);
int
virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
int fd,
struct stat const *sb);
int
virStorageSourceUpdateBackingSizes(virStorageSourcePtr src,
int fd,
struct stat const *sb);
int
virStorageSourceUpdateCapacity(virStorageSourcePtr src,
char *buf,
ssize_t len);
int
virStorageSourceNewFromBacking(virStorageSourcePtr parent,
virStorageSourcePtr *backing);
int
virStorageSourceParseRBDColonString(const char *rbdstr,
virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int
virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
virStorageSourcePtr base,
char **relpath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int
virStorageSourceNewFromBackingAbsolute(const char *path,
virStorageSourcePtr *src);
int
virStorageFileInit(virStorageSourcePtr src);
int
virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid);
void
virStorageFileDeinit(virStorageSourcePtr src);
int
virStorageFileCreate(virStorageSourcePtr src);
int
virStorageFileUnlink(virStorageSourcePtr src);
int
virStorageFileStat(virStorageSourcePtr src,
struct stat *st);
ssize_t
virStorageFileRead(virStorageSourcePtr src,
size_t offset,
size_t len,
char **buf);
const char *
virStorageFileGetUniqueIdentifier(virStorageSourcePtr src);
int
virStorageFileAccess(virStorageSourcePtr src,
int mode);
int
virStorageFileChown(const virStorageSource *src,
uid_t uid,
gid_t gid);
int
virStorageFileSupportsSecurityDriver(const virStorageSource *src);
int
virStorageFileSupportsAccess(const virStorageSource *src);
int
virStorageFileSupportsCreate(const virStorageSource *src);
int
virStorageFileSupportsBackingChainTraversal(const virStorageSource *src);
int
virStorageFileGetMetadata(virStorageSourcePtr src,
uid_t uid, gid_t gid,
bool report_broken)
ATTRIBUTE_NONNULL(1);
int
virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
char **backing)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void
virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr src,
virStorageSourcePtr parent);

File diff suppressed because it is too large Load Diff

View File

@ -388,18 +388,6 @@ struct _virStorageSource {
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
#ifndef DEV_BSIZE
# define DEV_BSIZE 512
#endif
virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path,
int fd,
int format);
virStorageSourcePtr virStorageFileGetMetadataFromBuf(const char *path,
char *buf,
size_t len,
int format)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virStorageFileParseChainIndex(const char *diskTarget,
const char *name,
unsigned int *chainIndex)
@ -410,13 +398,6 @@ int virStorageFileParseBackingStoreStr(const char *str,
unsigned int *chainIndex)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain,
virStorageSourcePtr startFrom,
const char *name,
unsigned int idx,
virStorageSourcePtr *parent)
ATTRIBUTE_NONNULL(1);
bool virStorageIsFile(const char *path);
bool virStorageIsRelative(const char *backing);
@ -469,15 +450,6 @@ bool virStorageSourceIsEmpty(virStorageSourcePtr src);
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
virStorageSourcePtr virStorageSourceNew(void);
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
int fd, struct stat const *sb);
int virStorageSourceUpdateBackingSizes(virStorageSourcePtr src,
int fd, struct stat const *sb);
int virStorageSourceUpdateCapacity(virStorageSourcePtr src,
char *buf, ssize_t len);
int virStorageSourceNewFromBacking(virStorageSourcePtr parent,
virStorageSourcePtr *backing);
int virStorageSourceNetCookiesValidate(virStorageSourcePtr src);
@ -488,10 +460,6 @@ bool virStorageSourceIsSameLocation(virStorageSourcePtr a,
virStorageSourcePtr b)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virStorageSourceParseRBDColonString(const char *rbdstr,
virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
typedef int
(*virStorageFileSimplifyPathReadlinkCallback)(const char *path,
char **link,
@ -500,14 +468,6 @@ char *virStorageFileCanonicalizePath(const char *path,
virStorageFileSimplifyPathReadlinkCallback cb,
void *cbdata);
int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from,
virStorageSourcePtr to,
char **relpath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int virStorageSourceNewFromBackingAbsolute(const char *path,
virStorageSourcePtr *src);
bool virStorageSourceIsRelative(virStorageSourcePtr src);
void
@ -542,39 +502,4 @@ virStorageSourceInitiatorCopy(virStorageSourceInitiatorDefPtr dest,
void
virStorageSourceInitiatorClear(virStorageSourceInitiatorDefPtr initiator);
int virStorageFileInit(virStorageSourcePtr src);
int virStorageFileInitAs(virStorageSourcePtr src,
uid_t uid, gid_t gid);
void virStorageFileDeinit(virStorageSourcePtr src);
int virStorageFileCreate(virStorageSourcePtr src);
int virStorageFileUnlink(virStorageSourcePtr src);
int virStorageFileStat(virStorageSourcePtr src,
struct stat *stat);
ssize_t virStorageFileRead(virStorageSourcePtr src,
size_t offset,
size_t len,
char **buf);
const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src);
int virStorageFileAccess(virStorageSourcePtr src, int mode);
int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid);
int virStorageFileSupportsSecurityDriver(const virStorageSource *src);
int virStorageFileSupportsAccess(const virStorageSource *src);
int virStorageFileSupportsCreate(const virStorageSource *src);
int virStorageFileSupportsBackingChainTraversal(const virStorageSource *src);
int virStorageFileGetMetadata(virStorageSourcePtr src,
uid_t uid, gid_t gid,
bool report_broken)
ATTRIBUTE_NONNULL(1);
int virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
char **backing)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr src,
virStorageSourcePtr parent);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageAuthDef, virStorageAuthDefFree);

View File

@ -442,7 +442,7 @@ endif
if conf.has('WITH_QEMU')
tests += [
{ 'name': 'qemuagenttest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
{ 'name': 'qemublocktest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
{ 'name': 'qemublocktest', 'include': [ storage_file_inc_dir ], 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
{ 'name': 'qemucapabilitiestest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
{ 'name': 'qemucaps2xmltest', 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib ] },
{ 'name': 'qemucommandutiltest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
@ -509,7 +509,7 @@ endif
if conf.has('WITH_STORAGE_FS')
tests += [
{ 'name': 'virstoragetest', 'link_with': [ storage_driver_impl_lib ] },
{ 'name': 'virstoragetest', 'include': [ storage_file_inc_dir ],'link_with': [ storage_driver_impl_lib ] },
]
endif

View File

@ -17,6 +17,7 @@
#include <config.h>
#include "storage_source.h"
#include "testutils.h"
#include "testutilsqemu.h"
#include "testutilsqemuschema.h"

View File

@ -20,6 +20,7 @@
#include <unistd.h>
#include "storage_source.h"
#include "testutils.h"
#include "vircommand.h"
#include "virerror.h"