2008-02-20 15:34:52 +00:00
|
|
|
/*
|
|
|
|
* storage_backend.h: internal storage driver backend contract
|
|
|
|
*
|
2010-01-15 09:38:36 +00:00
|
|
|
* Copyright (C) 2007-2010 Red Hat, Inc.
|
2008-02-20 15:34:52 +00:00
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_STORAGE_BACKEND_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_STORAGE_BACKEND_H__
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <stdint.h>
|
|
|
|
# include "internal.h"
|
|
|
|
# include "storage_conf.h"
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn, const char *srcSpec, unsigned int flags);
|
2008-02-20 15:34:52 +00:00
|
|
|
typedef int (*virStorageBackendStartPool)(virConnectPtr conn, virStoragePoolObjPtr pool);
|
|
|
|
typedef int (*virStorageBackendBuildPool)(virConnectPtr conn, virStoragePoolObjPtr pool, unsigned int flags);
|
|
|
|
typedef int (*virStorageBackendRefreshPool)(virConnectPtr conn, virStoragePoolObjPtr pool);
|
|
|
|
typedef int (*virStorageBackendStopPool)(virConnectPtr conn, virStoragePoolObjPtr pool);
|
|
|
|
typedef int (*virStorageBackendDeletePool)(virConnectPtr conn, virStoragePoolObjPtr pool, unsigned int flags);
|
|
|
|
|
2010-01-20 23:41:52 +00:00
|
|
|
typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool, virStorageVolDefPtr vol);
|
2008-02-20 15:34:52 +00:00
|
|
|
typedef int (*virStorageBackendCreateVol)(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol);
|
|
|
|
typedef int (*virStorageBackendRefreshVol)(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol);
|
|
|
|
typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned int flags);
|
2010-01-20 23:41:52 +00:00
|
|
|
typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn, virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr origvol, virStorageVolDefPtr newvol,
|
|
|
|
unsigned int flags);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-07-16 16:09:26 +00:00
|
|
|
/* File creation/cloning functions used for cloning between backends */
|
|
|
|
int virStorageBackendCreateRaw(virConnectPtr conn,
|
2010-01-20 23:41:52 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2009-07-16 16:09:26 +00:00
|
|
|
virStorageVolDefPtr vol,
|
2009-07-16 16:27:07 +00:00
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags);
|
|
|
|
virStorageBackendBuildVolFrom
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
|
2009-07-16 16:09:26 +00:00
|
|
|
virStorageVolDefPtr inputvol);
|
|
|
|
int virStorageBackendFindFSImageTool(char **tool);
|
2009-07-16 16:27:07 +00:00
|
|
|
virStorageBackendBuildVolFrom
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendFSImageToolTypeToFunc(int tool_type);
|
2009-07-16 16:09:26 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
typedef struct _virStorageBackend virStorageBackend;
|
|
|
|
typedef virStorageBackend *virStorageBackendPtr;
|
|
|
|
|
|
|
|
struct _virStorageBackend {
|
|
|
|
int type;
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
virStorageBackendFindPoolSources findPoolSources;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendStartPool startPool;
|
|
|
|
virStorageBackendBuildPool buildPool;
|
|
|
|
virStorageBackendRefreshPool refreshPool;
|
|
|
|
virStorageBackendStopPool stopPool;
|
|
|
|
virStorageBackendDeletePool deletePool;
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
virStorageBackendBuildVol buildVol;
|
2009-05-19 13:37:51 +00:00
|
|
|
virStorageBackendBuildVolFrom buildVolFrom;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendCreateVol createVol;
|
|
|
|
virStorageBackendRefreshVol refreshVol;
|
|
|
|
virStorageBackendDeleteVol deleteVol;
|
|
|
|
};
|
|
|
|
|
|
|
|
virStorageBackendPtr virStorageBackendForType(int type);
|
2008-11-17 11:19:33 +00:00
|
|
|
|
storage: Check for invalid storage mode before opening
If a directory pool contains pipes or sockets, a pool start can fail or hang:
https://bugzilla.redhat.com/show_bug.cgi?id=589577
We already try to avoid these special files, but only attempt after
opening the path, which is where the problems lie. Unify volume opening
into helper functions, which use the proper open() flags to avoid error,
followed by fstat to validate storage mode.
Previously, virStorageBackendUpdateVolTargetInfoFD attempted to enforce the
storage mode check, but allowed callers to detect this case and silently
continue. In practice, only the FS backend was using this feature, the rest
were treating unknown mode as an error condition. Unfortunately the InfoFD
function wasn't raising an error message here, so error reporting was
busted.
This patch adds 2 functions: virStorageBackendVolOpen, and
virStorageBackendVolOpenModeSkip. The latter retains the original opt out
semantics, the former now throws an explicit error.
This patch maintains the previous volume mode checks: allowing specific
modes for specific pool types requires a bit of surgery, since VolOpen
is called through several different helper functions.
v2: Use ATTRIBUTE_NONNULL. Drop stat check, just open with
O_NONBLOCK|O_NOCTTY.
v3: Move mode check logic back to VolOpen. Use 2 VolOpen functions with
different error semantics.
v4: Make second VolOpen function more extensible. Didn't opt to change
FS backend defaults, this can just be to fix the original bug.
v5: Prefix default flags with VIR_, use ATTRIBUTE_RETURN_CHECK
2010-05-20 18:25:01 +00:00
|
|
|
int virStorageBackendVolOpen(const char *path)
|
|
|
|
ATTRIBUTE_RETURN_CHECK
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
|
|
|
|
/* VolOpenCheckMode flags */
|
|
|
|
enum {
|
|
|
|
VIR_STORAGE_VOL_OPEN_ERROR = 1 << 0, /* warn if unexpected type
|
|
|
|
* encountered */
|
|
|
|
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 */
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:45:21 +00:00
|
|
|
# define VIR_STORAGE_VOL_OPEN_DEFAULT (VIR_STORAGE_VOL_OPEN_ERROR |\
|
|
|
|
VIR_STORAGE_VOL_OPEN_REG |\
|
|
|
|
VIR_STORAGE_VOL_OPEN_CHAR |\
|
|
|
|
VIR_STORAGE_VOL_OPEN_BLOCK)
|
storage: Check for invalid storage mode before opening
If a directory pool contains pipes or sockets, a pool start can fail or hang:
https://bugzilla.redhat.com/show_bug.cgi?id=589577
We already try to avoid these special files, but only attempt after
opening the path, which is where the problems lie. Unify volume opening
into helper functions, which use the proper open() flags to avoid error,
followed by fstat to validate storage mode.
Previously, virStorageBackendUpdateVolTargetInfoFD attempted to enforce the
storage mode check, but allowed callers to detect this case and silently
continue. In practice, only the FS backend was using this feature, the rest
were treating unknown mode as an error condition. Unfortunately the InfoFD
function wasn't raising an error message here, so error reporting was
busted.
This patch adds 2 functions: virStorageBackendVolOpen, and
virStorageBackendVolOpenModeSkip. The latter retains the original opt out
semantics, the former now throws an explicit error.
This patch maintains the previous volume mode checks: allowing specific
modes for specific pool types requires a bit of surgery, since VolOpen
is called through several different helper functions.
v2: Use ATTRIBUTE_NONNULL. Drop stat check, just open with
O_NONBLOCK|O_NOCTTY.
v3: Move mode check logic back to VolOpen. Use 2 VolOpen functions with
different error semantics.
v4: Make second VolOpen function more extensible. Didn't opt to change
FS backend defaults, this can just be to fix the original bug.
v5: Prefix default flags with VIR_, use ATTRIBUTE_RETURN_CHECK
2010-05-20 18:25:01 +00:00
|
|
|
|
|
|
|
int virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
|
|
|
|
ATTRIBUTE_RETURN_CHECK
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 20:02:58 +00:00
|
|
|
int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
|
2008-02-20 15:38:29 +00:00
|
|
|
int withCapacity);
|
|
|
|
|
2010-02-04 20:02:58 +00:00
|
|
|
int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
|
2009-01-27 18:30:03 +00:00
|
|
|
unsigned long long *allocation,
|
|
|
|
unsigned long long *capacity);
|
2010-02-04 20:02:58 +00:00
|
|
|
int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
|
2009-01-27 18:30:03 +00:00
|
|
|
int fd,
|
|
|
|
unsigned long long *allocation,
|
|
|
|
unsigned long long *capacity);
|
2009-09-08 13:47:45 +00:00
|
|
|
int
|
2010-05-20 17:29:24 +00:00
|
|
|
virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
|
|
|
|
int fd);
|
2008-11-28 07:50:20 +00:00
|
|
|
|
2010-02-04 20:02:58 +00:00
|
|
|
char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
2008-11-03 11:37:11 +00:00
|
|
|
const char *devpath);
|
2008-02-20 15:38:29 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
typedef int (*virStorageBackendListVolRegexFunc)(virStoragePoolObjPtr pool,
|
2008-02-20 15:38:29 +00:00
|
|
|
char **const groups,
|
|
|
|
void *data);
|
2010-02-10 11:42:56 +00:00
|
|
|
typedef int (*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool,
|
2008-02-20 15:38:29 +00:00
|
|
|
size_t n_tokens,
|
|
|
|
char **const groups,
|
|
|
|
void *data);
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
|
2008-06-24 14:30:25 +00:00
|
|
|
const char *const*prog,
|
2008-02-20 15:38:29 +00:00
|
|
|
int nregex,
|
|
|
|
const char **regex,
|
|
|
|
int *nvars,
|
|
|
|
virStorageBackendListVolRegexFunc func,
|
2008-06-17 12:45:24 +00:00
|
|
|
void *data,
|
|
|
|
int *exitstatus);
|
2008-02-20 15:38:29 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
|
2008-02-20 15:38:29 +00:00
|
|
|
const char **prog,
|
|
|
|
size_t n_columns,
|
|
|
|
virStorageBackendListVolNulFunc func,
|
|
|
|
void *data);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-06-17 08:38:17 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
#endif /* __VIR_STORAGE_BACKEND_H__ */
|