mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
storage: Split utility functions from storage_backend.(ch)
The file became a garbage dump for all kinds of utility functions over time. Move them to a separate file so that the files can become a clean interface for the storage backends.
This commit is contained in:
parent
4417481d8a
commit
46e8049c15
@ -177,6 +177,7 @@ src/storage/storage_backend_scsi.c
|
||||
src/storage/storage_backend_sheepdog.c
|
||||
src/storage/storage_backend_zfs.c
|
||||
src/storage/storage_driver.c
|
||||
src/storage/storage_util.c
|
||||
src/test/test_driver.c
|
||||
src/uml/uml_conf.c
|
||||
src/uml/uml_driver.c
|
||||
|
@ -972,7 +972,8 @@ SECRET_DRIVER_SOURCES = \
|
||||
# Storage backend specific impls
|
||||
STORAGE_DRIVER_SOURCES = \
|
||||
storage/storage_driver.h storage/storage_driver.c \
|
||||
storage/storage_backend.h storage/storage_backend.c
|
||||
storage/storage_backend.h storage/storage_backend.c \
|
||||
storage/storage_util.h storage/storage_util.c
|
||||
|
||||
STORAGE_DRIVER_FS_SOURCES = \
|
||||
storage/storage_backend_fs.h storage/storage_backend_fs.c
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,6 @@
|
||||
/*
|
||||
* storage_backend.h: internal storage driver backend contract
|
||||
*
|
||||
* Copyright (C) 2007-2010, 2012-2014 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
|
||||
@ -17,8 +14,6 @@
|
||||
* 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/>.
|
||||
*
|
||||
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __VIR_STORAGE_BACKEND_H__
|
||||
@ -28,7 +23,6 @@
|
||||
|
||||
# include "internal.h"
|
||||
# include "storage_conf.h"
|
||||
# include "vircommand.h"
|
||||
# include "storage_driver.h"
|
||||
|
||||
typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn,
|
||||
@ -102,67 +96,6 @@ typedef int (*virStorageBackendVolumeWipe)(virConnectPtr conn,
|
||||
unsigned int algorithm,
|
||||
unsigned int flags);
|
||||
|
||||
/* File creation/cloning functions used for cloning between backends */
|
||||
int virStorageBackendCreateRaw(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendCreateQemuImg(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendCreatePloop(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStoragePloopResize(virStorageVolDefPtr vol,
|
||||
unsigned long long capacity);
|
||||
|
||||
int virStorageBackendRedoPloopUpdate(virStorageSourcePtr target,
|
||||
struct stat *sb, int *fd,
|
||||
unsigned int flags);
|
||||
bool virStorageBackendIsPloopDir(char *path);
|
||||
|
||||
virStorageBackendBuildVolFrom
|
||||
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol);
|
||||
|
||||
int virStorageBackendFindGlusterPoolSources(const char *host,
|
||||
int pooltype,
|
||||
virStoragePoolSourceListPtr list,
|
||||
bool report);
|
||||
|
||||
int virStorageBackendVolUploadLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStreamPtr stream,
|
||||
unsigned long long offset,
|
||||
unsigned long long len,
|
||||
unsigned int flags);
|
||||
int virStorageBackendVolDownloadLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStreamPtr stream,
|
||||
unsigned long long offset,
|
||||
unsigned long long len,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendVolWipeLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
unsigned int algorithm,
|
||||
unsigned int flags);
|
||||
|
||||
bool virStorageBackendDeviceIsEmpty(const char *devpath,
|
||||
const char *format,
|
||||
bool writelabel);
|
||||
|
||||
typedef struct _virStorageBackend virStorageBackend;
|
||||
typedef virStorageBackend *virStorageBackendPtr;
|
||||
|
||||
@ -192,64 +125,6 @@ struct _virStorageBackend {
|
||||
|
||||
virStorageBackendPtr virStorageBackendForType(int type);
|
||||
|
||||
/* VolOpenCheckMode flags */
|
||||
enum {
|
||||
VIR_STORAGE_VOL_OPEN_NOERROR = 1 << 0, /* don't error if unexpected type
|
||||
* encountered, just warn */
|
||||
VIR_STORAGE_VOL_OPEN_REG = 1 << 1, /* regular files okay */
|
||||
VIR_STORAGE_VOL_OPEN_BLOCK = 1 << 2, /* block files okay */
|
||||
VIR_STORAGE_VOL_OPEN_CHAR = 1 << 3, /* char files okay */
|
||||
VIR_STORAGE_VOL_OPEN_DIR = 1 << 4, /* directories okay */
|
||||
};
|
||||
|
||||
/* VolReadErrorMode flags
|
||||
* If flag is present, then operation won't cause fatal error for
|
||||
* specified operation, rather a VIR_WARN will be issued and a -2 returned
|
||||
* for function call
|
||||
*/
|
||||
enum {
|
||||
VIR_STORAGE_VOL_READ_NOERROR = 1 << 0, /* ignore *read errors */
|
||||
};
|
||||
|
||||
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG |\
|
||||
VIR_STORAGE_VOL_OPEN_BLOCK)
|
||||
|
||||
int virStorageBackendVolOpen(const char *path, struct stat *sb,
|
||||
unsigned int flags)
|
||||
ATTRIBUTE_RETURN_CHECK
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
# define VIR_STORAGE_DEFAULT_POOL_PERM_MODE 0755
|
||||
# define VIR_STORAGE_DEFAULT_VOL_PERM_MODE 0600
|
||||
|
||||
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
|
||||
bool withBlockVolFormat,
|
||||
unsigned int openflags,
|
||||
unsigned int readflags);
|
||||
int virStorageBackendUpdateVolTargetInfo(virStorageVolType voltype,
|
||||
virStorageSourcePtr target,
|
||||
bool withBlockVolFormat,
|
||||
unsigned int openflags,
|
||||
unsigned int readflags);
|
||||
int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
|
||||
int fd,
|
||||
struct stat *sb);
|
||||
|
||||
bool virStorageBackendPoolPathIsStable(const char *path);
|
||||
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
||||
const char *devpath,
|
||||
bool loop);
|
||||
|
||||
virCommandPtr
|
||||
virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags,
|
||||
const char *create_tool,
|
||||
int imgformat,
|
||||
const char *secretPath);
|
||||
|
||||
/* ------- virStorageFile backends ------------ */
|
||||
typedef struct _virStorageFileBackend virStorageFileBackend;
|
||||
typedef virStorageFileBackend *virStorageFileBackendPtr;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "virerror.h"
|
||||
#include "virlog.h"
|
||||
#include "storage_backend_disk.h"
|
||||
#include "storage_util.h"
|
||||
#include "viralloc.h"
|
||||
#include "vircommand.h"
|
||||
#include "virfile.h"
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "virerror.h"
|
||||
#include "storage_backend_fs.h"
|
||||
#include "storage_util.h"
|
||||
#include "storage_conf.h"
|
||||
#include "virstoragefile.h"
|
||||
#include "vircommand.h"
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "virstoragefile.h"
|
||||
#include "virstring.h"
|
||||
#include "viruri.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "virstring.h"
|
||||
#include "viruuid.h"
|
||||
#include "secret_util.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "virlog.h"
|
||||
#include "virfile.h"
|
||||
#include "virstring.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "virlog.h"
|
||||
#include "virfile.h"
|
||||
#include "virstring.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "rados/librados.h"
|
||||
#include "rbd/librbd.h"
|
||||
#include "secret_util.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "virfile.h"
|
||||
#include "vircommand.h"
|
||||
#include "virstring.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "vircommand.h"
|
||||
#include "viralloc.h"
|
||||
#include "virstring.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "storage_backend_zfs.h"
|
||||
#include "virlog.h"
|
||||
#include "virstring.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "virstring.h"
|
||||
#include "viraccessapicheck.h"
|
||||
#include "dirname.h"
|
||||
#include "storage_util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
|
2919
src/storage/storage_util.c
Normal file
2919
src/storage/storage_util.c
Normal file
File diff suppressed because it is too large
Load Diff
149
src/storage/storage_util.h
Normal file
149
src/storage/storage_util.h
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* storage_util.h: utility functions for storage driver
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef __VIR_STORAGE_UTIL_H__
|
||||
# define __VIR_STORAGE_UTIL_H__
|
||||
|
||||
# include <sys/stat.h>
|
||||
|
||||
# include "internal.h"
|
||||
# include "storage_conf.h"
|
||||
# include "vircommand.h"
|
||||
# include "storage_driver.h"
|
||||
# include "storage_backend.h"
|
||||
|
||||
/* File creation/cloning functions used for cloning between backends */
|
||||
int virStorageBackendCreateRaw(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendCreateQemuImg(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendCreatePloop(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags);
|
||||
|
||||
int virStoragePloopResize(virStorageVolDefPtr vol,
|
||||
unsigned long long capacity);
|
||||
|
||||
int virStorageBackendRedoPloopUpdate(virStorageSourcePtr target,
|
||||
struct stat *sb, int *fd,
|
||||
unsigned int flags);
|
||||
bool virStorageBackendIsPloopDir(char *path);
|
||||
|
||||
virStorageBackendBuildVolFrom
|
||||
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol);
|
||||
|
||||
int virStorageBackendFindGlusterPoolSources(const char *host,
|
||||
int pooltype,
|
||||
virStoragePoolSourceListPtr list,
|
||||
bool report);
|
||||
|
||||
int virStorageBackendVolUploadLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStreamPtr stream,
|
||||
unsigned long long offset,
|
||||
unsigned long long len,
|
||||
unsigned int flags);
|
||||
int virStorageBackendVolDownloadLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStreamPtr stream,
|
||||
unsigned long long offset,
|
||||
unsigned long long len,
|
||||
unsigned int flags);
|
||||
|
||||
int virStorageBackendVolWipeLocal(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
unsigned int algorithm,
|
||||
unsigned int flags);
|
||||
|
||||
bool virStorageBackendDeviceIsEmpty(const char *devpath,
|
||||
const char *format,
|
||||
bool writelabel);
|
||||
|
||||
/* VolOpenCheckMode flags */
|
||||
enum {
|
||||
VIR_STORAGE_VOL_OPEN_NOERROR = 1 << 0, /* don't error if unexpected type
|
||||
* encountered, just warn */
|
||||
VIR_STORAGE_VOL_OPEN_REG = 1 << 1, /* regular files okay */
|
||||
VIR_STORAGE_VOL_OPEN_BLOCK = 1 << 2, /* block files okay */
|
||||
VIR_STORAGE_VOL_OPEN_CHAR = 1 << 3, /* char files okay */
|
||||
VIR_STORAGE_VOL_OPEN_DIR = 1 << 4, /* directories okay */
|
||||
};
|
||||
|
||||
/* VolReadErrorMode flags
|
||||
* If flag is present, then operation won't cause fatal error for
|
||||
* specified operation, rather a VIR_WARN will be issued and a -2 returned
|
||||
* for function call
|
||||
*/
|
||||
enum {
|
||||
VIR_STORAGE_VOL_READ_NOERROR = 1 << 0, /* ignore *read errors */
|
||||
};
|
||||
|
||||
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG |\
|
||||
VIR_STORAGE_VOL_OPEN_BLOCK)
|
||||
|
||||
int virStorageBackendVolOpen(const char *path, struct stat *sb,
|
||||
unsigned int flags)
|
||||
ATTRIBUTE_RETURN_CHECK
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
# define VIR_STORAGE_DEFAULT_POOL_PERM_MODE 0755
|
||||
# define VIR_STORAGE_DEFAULT_VOL_PERM_MODE 0600
|
||||
|
||||
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
|
||||
bool withBlockVolFormat,
|
||||
unsigned int openflags,
|
||||
unsigned int readflags);
|
||||
int virStorageBackendUpdateVolTargetInfo(virStorageVolType voltype,
|
||||
virStorageSourcePtr target,
|
||||
bool withBlockVolFormat,
|
||||
unsigned int openflags,
|
||||
unsigned int readflags);
|
||||
int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
|
||||
int fd,
|
||||
struct stat *sb);
|
||||
|
||||
bool virStorageBackendPoolPathIsStable(const char *path);
|
||||
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
||||
const char *devpath,
|
||||
bool loop);
|
||||
|
||||
virCommandPtr
|
||||
virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool,
|
||||
virStorageVolDefPtr vol,
|
||||
virStorageVolDefPtr inputvol,
|
||||
unsigned int flags,
|
||||
const char *create_tool,
|
||||
int imgformat,
|
||||
const char *secretPath);
|
||||
|
||||
#endif /* __VIR_STORAGE_UTIL_H__ */
|
@ -3,7 +3,7 @@
|
||||
#include "internal.h"
|
||||
#include "testutils.h"
|
||||
#include "datatypes.h"
|
||||
#include "storage/storage_backend.h"
|
||||
#include "storage/storage_util.h"
|
||||
#include "testutilsqemu.h"
|
||||
#include "virstring.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user