提交 da665fbd 编写于 作者: O Olga Krishtal 提交者: Maxim Nestratov

filesystem: adds possibility to use storage pool as fs source

Signed-off-by: NOlga Krishtal <okrishtal@virtuozzo.com>
上级 799b5aa5
......@@ -296,8 +296,8 @@ virDomainAuditFS(virDomainObjPtr vm,
const char *reason, bool success)
{
virDomainAuditGenericDev(vm, "fs",
oldDef ? oldDef->src : NULL,
newDef ? newDef->src : NULL,
oldDef ? oldDef->src->path : NULL,
newDef ? newDef->src->path : NULL,
reason, success);
}
......
......@@ -1730,12 +1730,31 @@ void virDomainControllerDefFree(virDomainControllerDefPtr def)
VIR_FREE(def);
}
virDomainFSDefPtr
virDomainFSDefNew(void)
{
virDomainFSDefPtr ret;
if (VIR_ALLOC(ret) < 0)
return NULL;
if (VIR_ALLOC(ret->src) < 0)
goto cleanup;
return ret;
cleanup:
virDomainFSDefFree(ret);
return NULL;
}
void virDomainFSDefFree(virDomainFSDefPtr def)
{
if (!def)
return;
VIR_FREE(def->src);
virStorageSourceFree(def->src);
VIR_FREE(def->dst);
virDomainDeviceInfoClear(&def->info);
......@@ -8540,7 +8559,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
ctxt->node = node;
if (VIR_ALLOC(def) < 0)
if (!(def = virDomainFSDefNew()))
return NULL;
type = virXMLPropString(node, "type");
......@@ -8667,7 +8686,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
goto error;
}
def->src = source;
def->src->path = source;
source = NULL;
def->dst = target;
target = NULL;
......@@ -20227,6 +20246,7 @@ virDomainFSDefFormat(virBufferPtr buf,
const char *accessmode = virDomainFSAccessModeTypeToString(def->accessmode);
const char *fsdriver = virDomainFSDriverTypeToString(def->fsdriver);
const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
const char *src = def->src->path;
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -20263,22 +20283,22 @@ virDomainFSDefFormat(virBufferPtr buf,
case VIR_DOMAIN_FS_TYPE_MOUNT:
case VIR_DOMAIN_FS_TYPE_BIND:
virBufferEscapeString(buf, "<source dir='%s'/>\n",
def->src);
src);
break;
case VIR_DOMAIN_FS_TYPE_BLOCK:
virBufferEscapeString(buf, "<source dev='%s'/>\n",
def->src);
src);
break;
case VIR_DOMAIN_FS_TYPE_FILE:
virBufferEscapeString(buf, "<source file='%s'/>\n",
def->src);
src);
break;
case VIR_DOMAIN_FS_TYPE_TEMPLATE:
virBufferEscapeString(buf, "<source name='%s'/>\n",
def->src);
src);
break;
case VIR_DOMAIN_FS_TYPE_RAM:
......
......@@ -807,7 +807,7 @@ struct _virDomainFSDef {
int wrpolicy; /* enum virDomainFSWrpolicy */
int format; /* virStorageFileFormat */
unsigned long long usage; /* in bytes */
char *src;
virStorageSourcePtr src;
char *dst;
bool readonly;
virDomainDeviceInfo info;
......@@ -2497,6 +2497,7 @@ virDomainDiskDefPtr virDomainDiskFindByBusAndDst(virDomainDefPtr def,
int bus,
char *dst);
void virDomainControllerDefFree(virDomainControllerDefPtr def);
virDomainFSDefPtr virDomainFSDefNew(void);
virDomainControllerDefPtr
virDomainControllerDefNew(virDomainControllerType type);
void virDomainFSDefFree(virDomainFSDefPtr def);
......
......@@ -296,6 +296,7 @@ virDomainDiskSetFormat;
virDomainDiskSetSource;
virDomainDiskSetType;
virDomainFSDefFree;
virDomainFSDefNew;
virDomainFSIndexByName;
virDomainFSInsert;
virDomainFSRemove;
......
......@@ -412,7 +412,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
continue;
if (virCgroupAllowDevicePath(cgroup,
def->fss[i]->src,
def->fss[i]->src->path,
def->fss[i]->readonly ?
VIR_CGROUP_DEVICE_READ :
VIR_CGROUP_DEVICE_RW, false) < 0)
......
......@@ -619,27 +619,27 @@ static int lxcContainerResolveSymlinks(virDomainFSDefPtr fs, bool gentle)
if (!fs->src || fs->symlinksResolved)
return 0;
if (access(fs->src, F_OK)) {
if (access(fs->src->path, F_OK)) {
if (gentle) {
/* Just ignore the error for the while, we'll try again later */
VIR_DEBUG("Skipped unaccessible '%s'", fs->src);
VIR_DEBUG("Skipped unaccessible '%s'", fs->src->path);
return 0;
} else {
virReportSystemError(errno,
_("Failed to access '%s'"), fs->src);
_("Failed to access '%s'"), fs->src->path);
return -1;
}
}
VIR_DEBUG("Resolving '%s'", fs->src);
if (virFileResolveAllLinks(fs->src, &newroot) < 0) {
VIR_DEBUG("Resolving '%s'", fs->src->path);
if (virFileResolveAllLinks(fs->src->path, &newroot) < 0) {
if (gentle) {
VIR_DEBUG("Skipped non-resolvable '%s'", fs->src);
VIR_DEBUG("Skipped non-resolvable '%s'", fs->src->path);
return 0;
} else {
virReportSystemError(errno,
_("Failed to resolve symlink at %s"),
fs->src);
fs->src->path);
}
return -1;
}
......@@ -647,10 +647,10 @@ static int lxcContainerResolveSymlinks(virDomainFSDefPtr fs, bool gentle)
/* Mark it resolved to skip it the next time */
fs->symlinksResolved = true;
VIR_DEBUG("Resolved '%s' to %s", fs->src, newroot);
VIR_DEBUG("Resolved '%s' to %s", fs->src->path, newroot);
VIR_FREE(fs->src);
fs->src = newroot;
VIR_FREE(fs->src->path);
fs->src->path = newroot;
return 0;
}
......@@ -698,8 +698,8 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def,
root->dst = tmp;
root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
VIR_FREE(root->src);
root->src = dst;
VIR_FREE(root->src->path);
root->src->path = dst;
return 0;
}
......@@ -711,7 +711,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
ret = -1;
VIR_DEBUG("Pivot via %s", root->src);
VIR_DEBUG("Pivot via %s", root->src->path);
/* root->parent must be private, so make / private. */
if (mount("", "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
......@@ -720,7 +720,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
goto err;
}
if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0)
if (virAsprintf(&oldroot, "%s/.oldroot", root->src->path) < 0)
goto err;
if (virFileMakePath(oldroot) < 0) {
......@@ -751,18 +751,18 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
}
/* ... and mount our root onto it */
if (mount(root->src, newroot, NULL, MS_BIND|MS_REC, NULL) < 0) {
if (mount(root->src->path, newroot, NULL, MS_BIND|MS_REC, NULL) < 0) {
virReportSystemError(errno,
_("Failed to bind %s to new root %s"),
root->src, newroot);
root->src->path, newroot);
goto err;
}
if (root->readonly) {
if (mount(root->src, newroot, NULL, MS_BIND|MS_REC|MS_RDONLY|MS_REMOUNT, NULL) < 0) {
if (mount(root->src->path, newroot, NULL, MS_BIND|MS_REC|MS_RDONLY|MS_REMOUNT, NULL) < 0) {
virReportSystemError(errno,
_("Failed to make new root %s readonly"),
root->src);
root->src->path);
goto err;
}
}
......@@ -1179,9 +1179,9 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
int ret = -1;
struct stat st;
VIR_DEBUG("src=%s dst=%s", fs->src, fs->dst);
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0)
if (virAsprintf(&src, "%s%s", srcprefix, fs->src->path) < 0)
goto cleanup;
if (stat(fs->dst, &st) < 0) {
......@@ -1514,9 +1514,9 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
char *src = NULL;
int ret = -1;
VIR_DEBUG("src=%s dst=%s", fs->src, fs->dst);
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0)
if (virAsprintf(&src, "%s%s", srcprefix, fs->src->path) < 0)
goto cleanup;
ret = lxcContainerMountFSBlockHelper(fs, src, srcprefix, sec_mount_options);
......@@ -1622,14 +1622,14 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
if (STREQ(vmDef->fss[i]->dst, "/"))
continue;
VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src, vmDef->fss[i]->dst);
VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src->path, vmDef->fss[i]->dst);
if (lxcContainerResolveSymlinks(vmDef->fss[i], false) < 0)
return -1;
if (!(vmDef->fss[i]->src &&
STRPREFIX(vmDef->fss[i]->src, vmDef->fss[i]->dst)) &&
STRPREFIX(vmDef->fss[i]->src->path, vmDef->fss[i]->dst)) &&
lxcContainerUnmountSubtree(vmDef->fss[i]->dst, false) < 0)
return -1;
......@@ -1777,7 +1777,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
/* FIXME: we should find a way to unmount these mounts for container
* even user namespace is enabled. */
if (STREQ(root->src, "/") && (!vmDef->idmap.nuidmap) &&
if (STREQ(root->src->path, "/") && (!vmDef->idmap.nuidmap) &&
lxcContainerUnmountForSharedRoot(stateDir, vmDef->name) < 0)
goto cleanup;
......
......@@ -424,18 +424,18 @@ static int virLXCControllerSetupLoopDeviceFS(virDomainFSDefPtr fs)
int lofd;
char *loname = NULL;
if ((lofd = virFileLoopDeviceAssociate(fs->src, &loname)) < 0)
if ((lofd = virFileLoopDeviceAssociate(fs->src->path, &loname)) < 0)
return -1;
VIR_DEBUG("Changing fs %s to use type=block for dev %s",
fs->src, loname);
fs->src->path, loname);
/*
* We now change it into a block device type, so that
* the rest of container setup 'just works'
*/
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
VIR_FREE(fs->src);
fs->src = loname;
VIR_FREE(fs->src->path);
fs->src->path = loname;
loname = NULL;
return lofd;
......@@ -485,21 +485,21 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFSDefPtr fs)
return -1;
}
if (virFileNBDDeviceAssociate(fs->src,
if (virFileNBDDeviceAssociate(fs->src->path,
fs->format,
fs->readonly,
&dev) < 0)
return -1;
VIR_DEBUG("Changing fs %s to use type=block for dev %s",
fs->src, dev);
fs->src->path, dev);
/*
* We now change it into a block device type, so that
* the rest of container setup 'just works'
*/
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
VIR_FREE(fs->src);
fs->src = dev;
VIR_FREE(fs->src->path);
fs->src->path = dev;
return 0;
}
......@@ -635,7 +635,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
/* The NBD device will be cleaned up while the cgroup will end.
* For this we need to remember the qemu-nbd pid and add it to
* the cgroup*/
if (virLXCControllerAppendNBDPids(ctrl, fs->src) < 0)
if (virLXCControllerAppendNBDPids(ctrl, fs->src->path) < 0)
goto cleanup;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
......
......@@ -32,6 +32,7 @@
#include "util/virlog.h"
#include "util/virstring.h"
#include "util/virconf.h"
#include "conf/domain_conf.h"
#define VIR_FROM_THIS VIR_FROM_LXC
......@@ -46,12 +47,12 @@ lxcCreateFSDef(int type,
{
virDomainFSDefPtr def;
if (VIR_ALLOC(def) < 0)
if (!(def = virDomainFSDefNew()))
return NULL;
def->type = type;
def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
if (src && VIR_STRDUP(def->src, src) < 0)
if (src && VIR_STRDUP(def->src->path, src) < 0)
goto error;
if (VIR_STRDUP(def->dst, dst) < 0)
goto error;
......
......@@ -1153,12 +1153,12 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
if (root)
return 0;
if (VIR_ALLOC(root) < 0)
if (!(root = virDomainFSDefNew()) < 0)
goto error;
root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
if (VIR_STRDUP(root->src, "/") < 0 ||
if (VIR_STRDUP(root->src->path, "/") < 0 ||
VIR_STRDUP(root->dst, "/") < 0)
goto error;
......
......@@ -351,11 +351,11 @@ openvzReadFSConf(virDomainDefPtr def,
veid);
goto error;
} else if (ret > 0) {
if (VIR_ALLOC(fs) < 0)
if (!(fs = virDomainFSDefNew()) < 0)
goto error;
fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE;
if (VIR_STRDUP(fs->src, temp) < 0)
if (VIR_STRDUP(fs->src->path, temp) < 0)
goto error;
} else {
/* OSTEMPLATE was not found, VE was booted from a private dir directly */
......@@ -374,7 +374,7 @@ openvzReadFSConf(virDomainDefPtr def,
goto error;
fs->type = VIR_DOMAIN_FS_TYPE_MOUNT;
if (!(fs->src = virStringReplace(temp, "$VEID", veid_str)))
if (!(fs->src->path = virStringReplace(temp, "$VEID", veid_str)))
goto error;
VIR_FREE(veid_str);
......
......@@ -207,7 +207,7 @@ static int openvzSetInitialConfig(virDomainDefPtr vmdef)
goto cleanup;
}
if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src) < 0) {
if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src->path) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not set the source dir for the filesystem"));
goto cleanup;
......@@ -2054,7 +2054,7 @@ openvzUpdateDevice(virDomainDefPtr vmdef,
cur = vmdef->fss[pos];
/* We only allow updating the quota */
if (STRNEQ(cur->src, fs->src)
if (STRNEQ(cur->src->path, fs->src->path)
|| cur->type != fs->type
|| cur->accessmode != fs->accessmode
|| cur->wrpolicy != fs->wrpolicy
......
......@@ -2091,7 +2091,7 @@ qemuBuildFSStr(virDomainFSDefPtr fs,
}
virBufferAsprintf(&opt, ",id=%s%s", QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
virBufferAsprintf(&opt, ",path=%s", fs->src);
virBufferAsprintf(&opt, ",path=%s", fs->src->path);
if (fs->readonly) {
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_FSDEV_READONLY)) {
......
......@@ -1839,7 +1839,7 @@ vboxAttachSharedFolder(virDomainDefPtr def, vboxGlobalData *data, IMachine *mach
continue;
VBOX_UTF8_TO_UTF16(def->fss[i]->dst, &nameUtf16);
VBOX_UTF8_TO_UTF16(def->fss[i]->src, &hostPathUtf16);
VBOX_UTF8_TO_UTF16(def->fss[i]->src->path, &hostPathUtf16);
writable = !def->fss[i]->readonly;
gVBoxAPI.UIMachine.CreateSharedFolder(machine, nameUtf16, hostPathUtf16,
......@@ -3448,7 +3448,7 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxGlobalData *data, IMachine *machi
gVBoxAPI.UISharedFolder.GetHostPath(sharedFolder, &hostPathUtf16);
VBOX_UTF16_TO_UTF8(hostPathUtf16, &hostPath);
if (VIR_STRDUP(def->fss[i]->src, hostPath) < 0) {
if (VIR_STRDUP(def->fss[i]->src->path, hostPath) < 0) {
VBOX_UTF8_FREE(hostPath);
VBOX_UTF16_FREE(hostPathUtf16);
goto sharedFoldersCleanup;
......@@ -4159,7 +4159,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
PRBool writable;
VBOX_UTF8_TO_UTF16(dev->data.fs->dst, &nameUtf16);
VBOX_UTF8_TO_UTF16(dev->data.fs->src, &hostPathUtf16);
VBOX_UTF8_TO_UTF16(dev->data.fs->src->path, &hostPathUtf16);
writable = !dev->data.fs->readonly;
rc = gVBoxAPI.UIMachine.CreateSharedFolder(machine, nameUtf16, hostPathUtf16,
......
......@@ -2422,7 +2422,7 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
return -1;
}
if (VIR_ALLOC(*def) < 0)
if (!(*def = virDomainFSDefNew()))
return -1;
(*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT;
......@@ -2450,7 +2450,7 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0)
goto cleanup;
(*def)->src = hostPath;
(*def)->src->path = hostPath;
hostPath = NULL;
/* vmx:guestName */
......@@ -3690,7 +3690,7 @@ virVMXFormatFileSystem(virDomainFSDefPtr def, int number, virBufferPtr buffer)
virBufferAsprintf(buffer, "sharedFolder%d.writeAccess = \"%s\"\n", number,
def->readonly ? "false" : "true");
virBufferAsprintf(buffer, "sharedFolder%d.hostPath = \"%s\"\n", number,
def->src);
def->src->path);
virBufferAsprintf(buffer, "sharedFolder%d.guestName = \"%s\"\n", number,
def->dst);
......
......@@ -673,7 +673,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
if (!(buf = prlsdkGetStringParamVar(PrlVmDev_GetImagePath, prldisk)))
goto cleanup;
fs->src = buf;
fs->src->path = buf;
buf = NULL;
if (!(buf = prlsdkGetStringParamVar(PrlVmDevHd_GetMountPoint, prldisk)))
......@@ -714,7 +714,7 @@ prlsdkAddDomainHardDisksInfo(vzDriverPtr driver, PRL_HANDLE sdkdom, virDomainDef
if (PDT_USE_REAL_DEVICE != emulatedType && IS_CT(def)) {
if (VIR_ALLOC(fs) < 0)
if (!(fs = virDomainFSDefNew()))
goto error;
if (prlsdkGetFSInfo(hdd, fs) < 0)
......@@ -3544,13 +3544,13 @@ prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs)
pret = PrlVmDev_SetEmulatedType(sdkdisk, PDT_USE_IMAGE_FILE);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmDev_SetSysName(sdkdisk, fs->src);
pret = PrlVmDev_SetSysName(sdkdisk, fs->src->path);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmDev_SetImagePath(sdkdisk, fs->src);
pret = PrlVmDev_SetImagePath(sdkdisk, fs->src->path);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmDev_SetFriendlyName(sdkdisk, fs->src);
pret = PrlVmDev_SetFriendlyName(sdkdisk, fs->src->path);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmDevHd_SetMountPoint(sdkdisk, fs->dst);
......@@ -3903,7 +3903,7 @@ prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def)
prlsdkCheckRetGoto(pret, cleanup);
if (useTemplate) {
pret = PrlVmCfg_SetOsTemplate(sdkdom, def->fss[0]->src);
pret = PrlVmCfg_SetOsTemplate(sdkdom, def->fss[0]->src->path);
prlsdkCheckRetGoto(pret, cleanup);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册