2017-01-11 17:04:15 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#pragma once
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#include <sys/stat.h>
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "vircommand.h"
|
|
|
|
#include "storage_driver.h"
|
|
|
|
#include "storage_backend.h"
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2019-01-07 22:14:57 +00:00
|
|
|
/* Storage Pool Namespace options to share w/ storage_backend_fs.c and
|
|
|
|
* the virStorageBackendFileSystemMountCmd method */
|
|
|
|
typedef struct _virStoragePoolFSMountOptionsDef virStoragePoolFSMountOptionsDef;
|
|
|
|
typedef virStoragePoolFSMountOptionsDef *virStoragePoolFSMountOptionsDefPtr;
|
|
|
|
struct _virStoragePoolFSMountOptionsDef {
|
|
|
|
size_t noptions;
|
|
|
|
char **options;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendNamespaceInit(int poolType,
|
|
|
|
virStoragePoolXMLNamespacePtr xmlns);
|
|
|
|
|
|
|
|
|
2017-01-11 17:04:15 +00:00
|
|
|
/* File creation/cloning functions used for cloning between backends */
|
2017-10-06 20:29:21 +00:00
|
|
|
|
|
|
|
int
|
2018-01-26 13:15:33 +00:00
|
|
|
virStorageBackendCreateVolUsingQemuImg(virStoragePoolObjPtr pool,
|
2017-10-06 20:29:21 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageBackendBuildVolFrom
|
|
|
|
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolCreateLocal(virStoragePoolObjPtr pool,
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageVolDefPtr vol);
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolBuildLocal(virStoragePoolObjPtr pool,
|
2017-01-11 17:04:15 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolBuildFromLocal(virStoragePoolObjPtr pool,
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolDeleteLocal(virStoragePoolObjPtr pool,
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags);
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolRefreshLocal(virStoragePoolObjPtr pool,
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageVolDefPtr vol);
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolResizeLocal(virStoragePoolObjPtr pool,
|
2017-01-21 14:05:41 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned long long capacity,
|
|
|
|
unsigned int flags);
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolUploadLocal(virStoragePoolObjPtr pool,
|
2017-01-11 17:04:15 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStreamPtr stream,
|
|
|
|
unsigned long long offset,
|
|
|
|
unsigned long long len,
|
|
|
|
unsigned int flags);
|
2017-01-21 14:05:41 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolDownloadLocal(virStoragePoolObjPtr pool,
|
2017-01-11 17:04:15 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStreamPtr stream,
|
|
|
|
unsigned long long offset,
|
|
|
|
unsigned long long len,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendVolWipeLocal(virStoragePoolObjPtr pool,
|
2017-01-11 17:04:15 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int algorithm,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2017-01-18 19:17:21 +00:00
|
|
|
/* Local/Common Storage Pool Backend APIs */
|
|
|
|
int virStorageBackendBuildLocal(virStoragePoolObjPtr pool);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendDeleteLocal(virStoragePoolObjPtr pool,
|
2017-01-18 19:17:21 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
2017-08-24 21:56:47 +00:00
|
|
|
int
|
|
|
|
virStorageBackendRefreshVolTargetUpdate(virStorageVolDefPtr vol);
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
int virStorageBackendRefreshLocal(virStoragePoolObjPtr pool);
|
2017-01-18 19:17:21 +00:00
|
|
|
|
2017-04-04 11:39:37 +00:00
|
|
|
int virStorageUtilGlusterExtractPoolSources(const char *host,
|
|
|
|
const char *xml,
|
|
|
|
virStoragePoolSourceListPtr list,
|
|
|
|
virStoragePoolType pooltype);
|
2017-01-18 19:17:21 +00:00
|
|
|
int virStorageBackendFindGlusterPoolSources(const char *host,
|
2017-03-30 13:08:06 +00:00
|
|
|
virStoragePoolType pooltype,
|
2017-01-18 19:17:21 +00:00
|
|
|
virStoragePoolSourceListPtr list,
|
|
|
|
bool report);
|
|
|
|
|
2017-01-11 17:04:15 +00:00
|
|
|
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 */
|
|
|
|
};
|
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_REG |\
|
|
|
|
VIR_STORAGE_VOL_OPEN_BLOCK)
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#define VIR_STORAGE_VOL_FS_OPEN_FLAGS (VIR_STORAGE_VOL_OPEN_DEFAULT | \
|
|
|
|
VIR_STORAGE_VOL_OPEN_DIR)
|
|
|
|
#define VIR_STORAGE_VOL_FS_PROBE_FLAGS (VIR_STORAGE_VOL_FS_OPEN_FLAGS | \
|
|
|
|
VIR_STORAGE_VOL_OPEN_NOERROR)
|
2017-01-18 19:17:21 +00:00
|
|
|
|
2017-01-11 17:04:15 +00:00
|
|
|
int virStorageBackendVolOpen(const char *path, struct stat *sb,
|
|
|
|
unsigned int flags)
|
|
|
|
ATTRIBUTE_RETURN_CHECK
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2019-06-18 16:12:42 +00:00
|
|
|
#define VIR_STORAGE_DEFAULT_POOL_PERM_MODE 0711
|
|
|
|
#define VIR_STORAGE_DEFAULT_VOL_PERM_MODE 0600
|
2017-01-11 17:04:15 +00:00
|
|
|
|
|
|
|
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
|
|
|
|
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);
|
|
|
|
|
storage: Add support for using inputvol for encryption
Starting with QEMU 2.9, encryption convert processing requires
a multi-step process in order to generate an encrypted image from
some non encrypted raw image.
Processing requires to first create an encrypted image using the
sizing parameters from the input source and second to use the
--image-opts, -n, and --target-image-opts options along with inline
driver options to describe the input and output files, generating
two commands such as:
$ qemu-img create -f luks \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
-o key-secret=demo.img_encrypt0 \
demo.img 500K
Formatting 'demo.img', fmt=luks size=512000 key-secret=demo.img_encrypt0
$ qemu-img convert --image-opts -n --target-image-opts \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
driver=raw,file.filename=sparse.img \
driver=luks,file.filename=demo.img,key-secret=demo.img_encrypt0
$
This patch handles the convert processing by running the processing
in a do..while loop essentially reusing the existing create logic and
arguments to create the target vol from the inputvol and then converting
the inputvol using new arguments.
This then allows the following virsh command to work properly:
virsh vol-create-from default encrypt1-luks.xml data.img --inputpool default
where encrypt1-luks.xml would provided the path and secret for
the new image, while data.img would be the source image.
Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-20 19:51:47 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_STORAGE_VOL_ENCRYPT_NONE = 0,
|
|
|
|
VIR_STORAGE_VOL_ENCRYPT_CREATE,
|
|
|
|
VIR_STORAGE_VOL_ENCRYPT_CONVERT,
|
|
|
|
VIR_STORAGE_VOL_ENCRYPT_DONE,
|
|
|
|
} virStorageVolEncryptConvertStep;
|
|
|
|
|
2017-01-11 17:04:15 +00:00
|
|
|
virCommandPtr
|
2018-01-26 13:15:33 +00:00
|
|
|
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
2017-01-11 17:04:15 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *create_tool,
|
storage: Add support for using inputvol for encryption
Starting with QEMU 2.9, encryption convert processing requires
a multi-step process in order to generate an encrypted image from
some non encrypted raw image.
Processing requires to first create an encrypted image using the
sizing parameters from the input source and second to use the
--image-opts, -n, and --target-image-opts options along with inline
driver options to describe the input and output files, generating
two commands such as:
$ qemu-img create -f luks \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
-o key-secret=demo.img_encrypt0 \
demo.img 500K
Formatting 'demo.img', fmt=luks size=512000 key-secret=demo.img_encrypt0
$ qemu-img convert --image-opts -n --target-image-opts \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
driver=raw,file.filename=sparse.img \
driver=luks,file.filename=demo.img,key-secret=demo.img_encrypt0
$
This patch handles the convert processing by running the processing
in a do..while loop essentially reusing the existing create logic and
arguments to create the target vol from the inputvol and then converting
the inputvol using new arguments.
This then allows the following virsh command to work properly:
virsh vol-create-from default encrypt1-luks.xml data.img --inputpool default
where encrypt1-luks.xml would provided the path and secret for
the new image, while data.img would be the source image.
Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-20 19:51:47 +00:00
|
|
|
const char *secretPath,
|
2018-08-20 16:25:44 +00:00
|
|
|
const char *inputSecretPath,
|
storage: Add support for using inputvol for encryption
Starting with QEMU 2.9, encryption convert processing requires
a multi-step process in order to generate an encrypted image from
some non encrypted raw image.
Processing requires to first create an encrypted image using the
sizing parameters from the input source and second to use the
--image-opts, -n, and --target-image-opts options along with inline
driver options to describe the input and output files, generating
two commands such as:
$ qemu-img create -f luks \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
-o key-secret=demo.img_encrypt0 \
demo.img 500K
Formatting 'demo.img', fmt=luks size=512000 key-secret=demo.img_encrypt0
$ qemu-img convert --image-opts -n --target-image-opts \
--object secret,id=demo.img_encrypt0,file=/path/to/secretFile \
driver=raw,file.filename=sparse.img \
driver=luks,file.filename=demo.img,key-secret=demo.img_encrypt0
$
This patch handles the convert processing by running the processing
in a do..while loop essentially reusing the existing create logic and
arguments to create the target vol from the inputvol and then converting
the inputvol using new arguments.
This then allows the following virsh command to work properly:
virsh vol-create-from default encrypt1-luks.xml data.img --inputpool default
where encrypt1-luks.xml would provided the path and secret for
the new image, while data.img would be the source image.
Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-20 19:51:47 +00:00
|
|
|
virStorageVolEncryptConvertStep convertStep);
|
2017-01-11 17:04:15 +00:00
|
|
|
|
2017-01-13 16:48:00 +00:00
|
|
|
int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
|
|
|
uint32_t scanhost);
|
|
|
|
|
2017-04-06 17:18:16 +00:00
|
|
|
int
|
|
|
|
virStorageBackendZeroPartitionTable(const char *path,
|
|
|
|
unsigned long long size);
|
|
|
|
|
2018-12-04 11:50:06 +00:00
|
|
|
char *
|
|
|
|
virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool);
|
|
|
|
|
2018-12-04 11:34:58 +00:00
|
|
|
virCommandPtr
|
2018-12-13 16:11:18 +00:00
|
|
|
virStorageBackendFileSystemMountCmd(const char *cmdstr,
|
|
|
|
virStoragePoolDefPtr def,
|
2018-12-04 11:34:58 +00:00
|
|
|
const char *src);
|
|
|
|
|
2018-12-04 16:12:37 +00:00
|
|
|
virCommandPtr
|
2018-12-13 16:11:18 +00:00
|
|
|
virStorageBackendLogicalChangeCmd(const char *cmdstr,
|
|
|
|
virStoragePoolDefPtr def,
|
2018-12-04 16:12:37 +00:00
|
|
|
bool on);
|