2008-02-20 15:34:52 +00:00
|
|
|
/*
|
|
|
|
* storage_conf.c: config handling for storage driver
|
|
|
|
*
|
2012-02-23 00:48:38 +00:00
|
|
|
* Copyright (C) 2006-2012 Red Hat, Inc.
|
2008-02-20 15:34:52 +00:00
|
|
|
* Copyright (C) 2006-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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "storage_conf.h"
|
2009-09-25 13:20:13 +00:00
|
|
|
#include "storage_file.h"
|
2008-11-17 11:19:33 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "xml.h"
|
|
|
|
#include "uuid.h"
|
|
|
|
#include "buf.h"
|
|
|
|
#include "util.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
VIR_ENUM_IMPL(virStoragePool,
|
|
|
|
VIR_STORAGE_POOL_LAST,
|
|
|
|
"dir", "fs", "netfs",
|
|
|
|
"logical", "disk", "iscsi",
|
2009-09-08 13:47:45 +00:00
|
|
|
"scsi", "mpath")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStoragePoolFormatFileSystem,
|
|
|
|
VIR_STORAGE_POOL_FS_LAST,
|
|
|
|
"auto", "ext2", "ext3",
|
|
|
|
"ext4", "ufs", "iso9660", "udf",
|
2009-10-14 15:03:22 +00:00
|
|
|
"gfs", "gfs2", "vfat", "hfs+", "xfs", "ocfs2")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStoragePoolFormatFileSystemNet,
|
|
|
|
VIR_STORAGE_POOL_NETFS_LAST,
|
2010-05-17 23:24:32 +00:00
|
|
|
"auto", "nfs", "glusterfs", "cifs")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStoragePoolFormatDisk,
|
|
|
|
VIR_STORAGE_POOL_DISK_LAST,
|
|
|
|
"unknown", "dos", "dvh", "gpt",
|
2008-12-17 21:09:44 +00:00
|
|
|
"mac", "bsd", "pc98", "sun", "lvm2")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStoragePoolFormatLogical,
|
|
|
|
VIR_STORAGE_POOL_LOGICAL_LAST,
|
2008-12-17 21:09:44 +00:00
|
|
|
"unknown", "lvm2")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStorageVolFormatDisk,
|
|
|
|
VIR_STORAGE_VOL_DISK_LAST,
|
|
|
|
"none", "linux", "fat16",
|
|
|
|
"fat32", "linux-swap",
|
|
|
|
"linux-lvm", "linux-raid",
|
2008-12-17 21:09:44 +00:00
|
|
|
"extended")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
VIR_ENUM_IMPL(virStoragePartedFsType,
|
|
|
|
VIR_STORAGE_PARTED_FS_TYPE_LAST,
|
2009-07-10 13:02:30 +00:00
|
|
|
"ext2", "ext2", "fat16",
|
2009-06-26 16:18:59 +00:00
|
|
|
"fat32", "linux-swap",
|
|
|
|
"ext2", "ext2",
|
|
|
|
"extended")
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
typedef const char *(*virStorageVolFormatToString)(int format);
|
|
|
|
typedef int (*virStorageVolFormatFromString)(const char *format);
|
|
|
|
|
|
|
|
typedef const char *(*virStoragePoolFormatToString)(int format);
|
|
|
|
typedef int (*virStoragePoolFormatFromString)(const char *format);
|
|
|
|
|
|
|
|
typedef struct _virStorageVolOptions virStorageVolOptions;
|
|
|
|
typedef virStorageVolOptions *virStorageVolOptionsPtr;
|
|
|
|
struct _virStorageVolOptions {
|
2008-12-04 15:22:04 +00:00
|
|
|
int defaultFormat;
|
2008-11-17 11:19:33 +00:00
|
|
|
virStorageVolFormatToString formatToString;
|
|
|
|
virStorageVolFormatFromString formatFromString;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Flags to indicate mandatory components in the pool source */
|
|
|
|
enum {
|
2010-01-21 11:50:52 +00:00
|
|
|
VIR_STORAGE_POOL_SOURCE_HOST = (1<<0),
|
|
|
|
VIR_STORAGE_POOL_SOURCE_DEVICE = (1<<1),
|
|
|
|
VIR_STORAGE_POOL_SOURCE_DIR = (1<<2),
|
|
|
|
VIR_STORAGE_POOL_SOURCE_ADAPTER = (1<<3),
|
|
|
|
VIR_STORAGE_POOL_SOURCE_NAME = (1<<4),
|
|
|
|
VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN = (1<<5),
|
2008-11-17 11:19:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _virStoragePoolOptions virStoragePoolOptions;
|
|
|
|
typedef virStoragePoolOptions *virStoragePoolOptionsPtr;
|
|
|
|
struct _virStoragePoolOptions {
|
2011-07-07 23:29:42 +00:00
|
|
|
unsigned int flags;
|
2008-11-17 11:19:33 +00:00
|
|
|
int defaultFormat;
|
|
|
|
virStoragePoolFormatToString formatToString;
|
|
|
|
virStoragePoolFormatFromString formatFromString;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _virStoragePoolTypeInfo virStoragePoolTypeInfo;
|
|
|
|
typedef virStoragePoolTypeInfo *virStoragePoolTypeInfoPtr;
|
|
|
|
|
|
|
|
struct _virStoragePoolTypeInfo {
|
|
|
|
int poolType;
|
|
|
|
virStoragePoolOptions poolOptions;
|
|
|
|
virStorageVolOptions volOptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
static virStoragePoolTypeInfo poolTypeInfo[] = {
|
|
|
|
{ .poolType = VIR_STORAGE_POOL_LOGICAL,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_NAME |
|
|
|
|
VIR_STORAGE_POOL_SOURCE_DEVICE),
|
|
|
|
.defaultFormat = VIR_STORAGE_POOL_LOGICAL_LVM2,
|
|
|
|
.formatFromString = virStoragePoolFormatLogicalTypeFromString,
|
|
|
|
.formatToString = virStoragePoolFormatLogicalTypeToString,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ .poolType = VIR_STORAGE_POOL_DIR,
|
|
|
|
.volOptions = {
|
2009-09-25 13:20:13 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
|
|
|
.formatFromString = virStorageFileFormatTypeFromString,
|
|
|
|
.formatToString = virStorageFileFormatTypeToString,
|
2008-11-17 11:19:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{ .poolType = VIR_STORAGE_POOL_FS,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
|
2010-04-18 12:00:38 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_POOL_FS_AUTO,
|
2008-11-17 11:19:33 +00:00
|
|
|
.formatFromString = virStoragePoolFormatFileSystemTypeFromString,
|
|
|
|
.formatToString = virStoragePoolFormatFileSystemTypeToString,
|
|
|
|
},
|
|
|
|
.volOptions = {
|
2009-09-25 13:20:13 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
|
|
|
.formatFromString = virStorageFileFormatTypeFromString,
|
|
|
|
.formatToString = virStorageFileFormatTypeToString,
|
2008-11-17 11:19:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{ .poolType = VIR_STORAGE_POOL_NETFS,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_HOST |
|
|
|
|
VIR_STORAGE_POOL_SOURCE_DIR),
|
2010-04-18 12:00:38 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_POOL_NETFS_AUTO,
|
2008-11-17 11:19:33 +00:00
|
|
|
.formatFromString = virStoragePoolFormatFileSystemNetTypeFromString,
|
|
|
|
.formatToString = virStoragePoolFormatFileSystemNetTypeToString,
|
|
|
|
},
|
|
|
|
.volOptions = {
|
2009-09-25 13:20:13 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
|
|
|
.formatFromString = virStorageFileFormatTypeFromString,
|
|
|
|
.formatToString = virStorageFileFormatTypeToString,
|
2008-11-17 11:19:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{ .poolType = VIR_STORAGE_POOL_ISCSI,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_HOST |
|
2010-01-21 11:50:52 +00:00
|
|
|
VIR_STORAGE_POOL_SOURCE_DEVICE |
|
|
|
|
VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN),
|
2008-11-17 11:19:33 +00:00
|
|
|
},
|
|
|
|
.volOptions = {
|
|
|
|
.formatToString = virStoragePoolFormatDiskTypeToString,
|
|
|
|
}
|
|
|
|
},
|
2009-04-01 16:03:22 +00:00
|
|
|
{ .poolType = VIR_STORAGE_POOL_SCSI,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_ADAPTER),
|
|
|
|
},
|
|
|
|
.volOptions = {
|
|
|
|
.formatToString = virStoragePoolFormatDiskTypeToString,
|
|
|
|
}
|
|
|
|
},
|
2009-09-08 13:47:45 +00:00
|
|
|
{ .poolType = VIR_STORAGE_POOL_MPATH,
|
|
|
|
.volOptions = {
|
|
|
|
.formatToString = virStoragePoolFormatDiskTypeToString,
|
|
|
|
}
|
|
|
|
},
|
2008-11-17 11:19:33 +00:00
|
|
|
{ .poolType = VIR_STORAGE_POOL_DISK,
|
|
|
|
.poolOptions = {
|
|
|
|
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
|
|
|
|
.defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN,
|
|
|
|
.formatFromString = virStoragePoolFormatDiskTypeFromString,
|
|
|
|
.formatToString = virStoragePoolFormatDiskTypeToString,
|
|
|
|
},
|
|
|
|
.volOptions = {
|
2008-12-04 15:22:04 +00:00
|
|
|
.defaultFormat = VIR_STORAGE_VOL_DISK_NONE,
|
2008-11-17 11:19:33 +00:00
|
|
|
.formatFromString = virStorageVolFormatDiskTypeFromString,
|
|
|
|
.formatToString = virStorageVolFormatDiskTypeToString,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolTypeInfoPtr
|
|
|
|
virStoragePoolTypeInfoLookup(int type) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(poolTypeInfo) ; i++)
|
|
|
|
if (poolTypeInfo[i].poolType == type)
|
|
|
|
return &poolTypeInfo[i];
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-17 11:19:33 +00:00
|
|
|
_("missing backend for pool type %d"), type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolOptionsPtr
|
|
|
|
virStoragePoolOptionsForPoolType(int type) {
|
|
|
|
virStoragePoolTypeInfoPtr backend = virStoragePoolTypeInfoLookup(type);
|
|
|
|
if (backend == NULL)
|
|
|
|
return NULL;
|
|
|
|
return &backend->poolOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageVolOptionsPtr
|
|
|
|
virStorageVolOptionsForPoolType(int type) {
|
|
|
|
virStoragePoolTypeInfoPtr backend = virStoragePoolTypeInfoLookup(type);
|
|
|
|
if (backend == NULL)
|
|
|
|
return NULL;
|
|
|
|
return &backend->volOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
void
|
|
|
|
virStorageVolDefFree(virStorageVolDefPtr def) {
|
|
|
|
int i;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def->name);
|
|
|
|
VIR_FREE(def->key);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < def->source.nextent ; i++) {
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def->source.extents[i].path);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def->source.extents);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def->target.path);
|
|
|
|
VIR_FREE(def->target.perms.label);
|
2009-07-20 22:28:11 +00:00
|
|
|
virStorageEncryptionFree(def->target.encryption);
|
2009-01-27 18:30:03 +00:00
|
|
|
VIR_FREE(def->backingStore.path);
|
|
|
|
VIR_FREE(def->backingStore.perms.label);
|
2009-07-20 22:28:11 +00:00
|
|
|
virStorageEncryptionFree(def->backingStore.encryption);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-21 22:44:52 +00:00
|
|
|
virStoragePoolSourceClear(virStoragePoolSourcePtr source)
|
|
|
|
{
|
2008-02-20 15:34:52 +00:00
|
|
|
int i;
|
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
if (!source)
|
2008-10-10 15:13:28 +00:00
|
|
|
return;
|
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
VIR_FREE(source->host.name);
|
|
|
|
for (i = 0 ; i < source->ndevice ; i++) {
|
|
|
|
VIR_FREE(source->devices[i].freeExtents);
|
|
|
|
VIR_FREE(source->devices[i].path);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-10-23 11:39:53 +00:00
|
|
|
VIR_FREE(source->devices);
|
|
|
|
VIR_FREE(source->dir);
|
|
|
|
VIR_FREE(source->name);
|
2009-04-01 16:03:22 +00:00
|
|
|
VIR_FREE(source->adapter);
|
2010-01-21 11:50:52 +00:00
|
|
|
VIR_FREE(source->initiator.iqn);
|
2010-08-17 17:44:27 +00:00
|
|
|
VIR_FREE(source->vendor);
|
|
|
|
VIR_FREE(source->product);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
|
|
|
VIR_FREE(source->auth.chap.login);
|
|
|
|
VIR_FREE(source->auth.chap.passwd);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-10-23 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 22:44:52 +00:00
|
|
|
void
|
|
|
|
virStoragePoolSourceFree(virStoragePoolSourcePtr source)
|
|
|
|
{
|
|
|
|
virStoragePoolSourceClear(source);
|
|
|
|
VIR_FREE(source);
|
|
|
|
}
|
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
void
|
|
|
|
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(def->name);
|
|
|
|
|
2011-10-21 22:44:52 +00:00
|
|
|
virStoragePoolSourceClear(&def->source);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def->target.path);
|
|
|
|
VIR_FREE(def->target.perms.label);
|
|
|
|
VIR_FREE(def);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjFree(virStoragePoolObjPtr obj) {
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2009-01-30 16:48:52 +00:00
|
|
|
virStoragePoolObjClearVols(obj);
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolDefFree(obj->def);
|
|
|
|
virStoragePoolDefFree(obj->newDef);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(obj->configFile);
|
|
|
|
VIR_FREE(obj->autostartLink);
|
2009-01-15 19:56:05 +00:00
|
|
|
|
|
|
|
virMutexDestroy(&obj->lock);
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(obj);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
void virStoragePoolObjListFree(virStoragePoolObjListPtr pools)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0 ; i < pools->count ; i++)
|
|
|
|
virStoragePoolObjFree(pools->objs[i]);
|
|
|
|
VIR_FREE(pools->objs);
|
|
|
|
pools->count = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
void
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pools->count ; i++) {
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjLock(pools->objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (pools->objs[i] == pool) {
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjUnlock(pools->objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjFree(pools->objs[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (i < (pools->count - 1))
|
|
|
|
memmove(pools->objs + i, pools->objs + i + 1,
|
|
|
|
sizeof(*(pools->objs)) * (pools->count - (i + 1)));
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (VIR_REALLOC_N(pools->objs, pools->count - 1) < 0) {
|
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
|
|
|
pools->count--;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjUnlock(pools->objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt,
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolAuthChapPtr auth) {
|
2010-02-04 21:52:34 +00:00
|
|
|
auth->login = virXPathString("string(./auth/@login)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (auth->login == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("missing auth host attribute"));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
auth->passwd = virXPathString("string(./auth/@passwd)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (auth->passwd == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("missing auth passwd attribute"));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-15 14:55:19 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
|
2009-10-15 14:55:19 +00:00
|
|
|
virStoragePoolSourcePtr source,
|
|
|
|
int pool_type,
|
|
|
|
xmlNodePtr node) {
|
|
|
|
int ret = -1;
|
|
|
|
xmlNodePtr relnode, *nodeset = NULL;
|
|
|
|
char *authType = NULL;
|
|
|
|
int nsource, i;
|
|
|
|
virStoragePoolOptionsPtr options;
|
2011-03-16 08:28:07 +00:00
|
|
|
char *port = NULL;
|
2009-10-15 14:55:19 +00:00
|
|
|
|
|
|
|
relnode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
|
|
|
if ((options = virStoragePoolOptionsForPoolType(pool_type)) == NULL) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
source->name = virXPathString("string(./name)", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
|
|
|
|
if (options->formatFromString) {
|
2010-02-04 21:52:34 +00:00
|
|
|
char *format = virXPathString("string(./format/@type)", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
if (format == NULL)
|
|
|
|
source->format = options->defaultFormat;
|
|
|
|
else
|
|
|
|
source->format = options->formatFromString(format);
|
|
|
|
|
|
|
|
if (source->format < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
_("unknown pool format type %s"), format);
|
|
|
|
VIR_FREE(format);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(format);
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
source->host.name = virXPathString("string(./host/@name)", ctxt);
|
2010-11-12 13:23:55 +00:00
|
|
|
port = virXPathString("string(./host/@port)", ctxt);
|
|
|
|
if (port) {
|
|
|
|
if (virStrToLong_i(port, NULL, 10, &source->host.port) < 0) {
|
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid port number: %s"),
|
|
|
|
port);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
source->initiator.iqn = virXPathString("string(./initiator/iqn/@name)", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
nsource = virXPathNodeSet("./device", ctxt, &nodeset);
|
2011-05-12 19:45:22 +00:00
|
|
|
if (nsource < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-10-15 14:55:19 +00:00
|
|
|
if (nsource > 0) {
|
|
|
|
if (VIR_ALLOC_N(source->devices, nsource) < 0) {
|
|
|
|
VIR_FREE(nodeset);
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-10-15 14:55:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < nsource ; i++) {
|
2010-11-24 20:08:55 +00:00
|
|
|
char *path = virXMLPropString(nodeset[i], "path");
|
2009-10-15 14:55:19 +00:00
|
|
|
if (path == NULL) {
|
|
|
|
VIR_FREE(nodeset);
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
"%s", _("missing storage pool source device path"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-11-24 20:08:55 +00:00
|
|
|
source->devices[i].path = path;
|
2009-10-15 14:55:19 +00:00
|
|
|
}
|
|
|
|
source->ndevice = nsource;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
source->dir = virXPathString("string(./dir/@path)", ctxt);
|
|
|
|
source->adapter = virXPathString("string(./adapter/@name)", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
authType = virXPathString("string(./auth/@type)", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
if (authType == NULL) {
|
|
|
|
source->authType = VIR_STORAGE_POOL_AUTH_NONE;
|
|
|
|
} else {
|
|
|
|
if (STREQ(authType, "chap")) {
|
|
|
|
source->authType = VIR_STORAGE_POOL_AUTH_CHAP;
|
|
|
|
} else {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
_("unknown auth type '%s'"),
|
|
|
|
(const char *)authType);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolDefParseAuthChap(ctxt, &source->auth.chap) < 0)
|
2009-10-15 14:55:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-08-17 17:44:27 +00:00
|
|
|
source->vendor = virXPathString("string(./vendor/@name)", ctxt);
|
|
|
|
source->product = virXPathString("string(./product/@name)", ctxt);
|
|
|
|
|
2009-10-15 14:55:19 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
ctxt->node = relnode;
|
|
|
|
|
2010-11-12 13:23:55 +00:00
|
|
|
VIR_FREE(port);
|
2009-10-15 14:55:19 +00:00
|
|
|
VIR_FREE(authType);
|
|
|
|
VIR_FREE(nodeset);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-10-15 15:58:35 +00:00
|
|
|
virStoragePoolSourcePtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseSourceString(const char *srcSpec,
|
2009-10-15 15:58:35 +00:00
|
|
|
int pool_type)
|
|
|
|
{
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlNodePtr node = NULL;
|
|
|
|
xmlXPathContextPtr xpath_ctxt = NULL;
|
|
|
|
virStoragePoolSourcePtr def = NULL, ret = NULL;
|
|
|
|
|
2011-09-14 14:17:57 +00:00
|
|
|
if (!(doc = virXMLParseStringCtxt(srcSpec, _("(storage_source_specification)"), &xpath_ctxt))) {
|
2009-10-15 15:58:35 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(def) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-10-15 15:58:35 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
node = virXPathNode("/source", xpath_ctxt);
|
2009-10-15 15:58:35 +00:00
|
|
|
if (!node) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 15:58:35 +00:00
|
|
|
"%s", _("root element was not source"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type,
|
2009-10-15 15:58:35 +00:00
|
|
|
node) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = def;
|
|
|
|
def = NULL;
|
|
|
|
cleanup:
|
2010-02-05 16:09:43 +00:00
|
|
|
virStoragePoolSourceFree(def);
|
2009-10-15 15:58:35 +00:00
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlXPathFreeContext(xpath_ctxt);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageDefParsePerms(xmlXPathContextPtr ctxt,
|
2009-03-12 20:15:32 +00:00
|
|
|
virStoragePermsPtr perms,
|
|
|
|
const char *permxpath,
|
|
|
|
int defaultmode) {
|
2008-02-20 15:34:52 +00:00
|
|
|
char *mode;
|
|
|
|
long v;
|
2009-03-12 20:15:32 +00:00
|
|
|
int ret = -1;
|
|
|
|
xmlNodePtr relnode;
|
|
|
|
xmlNodePtr node;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
node = virXPathNode(permxpath, ctxt);
|
2009-03-12 20:15:32 +00:00
|
|
|
if (node == NULL) {
|
|
|
|
/* Set default values if there is not <permissions> element */
|
|
|
|
perms->mode = defaultmode;
|
2010-03-04 22:35:27 +00:00
|
|
|
perms->uid = -1;
|
|
|
|
perms->gid = -1;
|
2009-03-12 20:15:32 +00:00
|
|
|
perms->label = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
relnode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
mode = virXPathString("string(./mode)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!mode) {
|
2009-03-12 20:15:32 +00:00
|
|
|
perms->mode = defaultmode;
|
2008-02-20 15:34:52 +00:00
|
|
|
} else {
|
2009-03-02 10:07:55 +00:00
|
|
|
char *end = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
perms->mode = strtol(mode, &end, 8);
|
build: use correct type for pid and similar types
No thanks to 64-bit windows, with 64-bit pid_t, we have to avoid
constructs like 'int pid'. Our API in libvirt-qemu cannot be
changed without breaking ABI; but then again, libvirt-qemu can
only be used on systems that support UNIX sockets, which rules
out Windows (even if qemu could be compiled there) - so for all
points on the call chain that interact with this API decision,
we require a different variable name to make it clear that we
audited the use for safety.
Adding a syntax-check rule only solves half the battle; anywhere
that uses printf on a pid_t still needs to be converted, but that
will be a separate patch.
* cfg.mk (sc_correct_id_types): New syntax check.
* src/libvirt-qemu.c (virDomainQemuAttach): Document why we didn't
use pid_t for pid, and validate for overflow.
* include/libvirt/libvirt-qemu.h (virDomainQemuAttach): Tweak name
for syntax check.
* src/vmware/vmware_conf.c (vmwareExtractPid): Likewise.
* src/driver.h (virDrvDomainQemuAttach): Likewise.
* tools/virsh.c (cmdQemuAttach): Likewise.
* src/remote/qemu_protocol.x (qemu_domain_attach_args): Likewise.
* src/qemu_protocol-structs (qemu_domain_attach_args): Likewise.
* src/util/cgroup.c (virCgroupPidCode, virCgroupKillInternal):
Likewise.
* src/qemu/qemu_command.c(qemuParseProcFileStrings): Likewise.
(qemuParseCommandLinePid): Use pid_t for pid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* src/conf/domain_conf.h (_virDomainObj): Likewise.
* src/probes.d (rpc_socket_new): Likewise.
* src/qemu/qemu_command.h (qemuParseCommandLinePid): Likewise.
* src/qemu/qemu_driver.c (qemudGetProcessInfo, qemuDomainAttach):
Likewise.
* src/qemu/qemu_process.c (qemuProcessAttach): Likewise.
* src/qemu/qemu_process.h (qemuProcessAttach): Likewise.
* src/uml/uml_driver.c (umlGetProcessInfo): Likewise.
* src/util/virnetdev.h (virNetDevSetNamespace): Likewise.
* src/util/virnetdev.c (virNetDevSetNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* src/conf/storage_conf.h (_virStoragePerms): Use mode_t, uid_t,
and gid_t rather than int.
* src/security/security_dac.c (virSecurityDACSetOwnership): Likewise.
* src/conf/storage_conf.c (virStorageDefParsePerms): Avoid
compiler warning.
2012-02-10 23:08:11 +00:00
|
|
|
if (*end || (perms->mode & ~0777)) {
|
2009-04-01 10:21:34 +00:00
|
|
|
VIR_FREE(mode);
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed octal mode"));
|
2009-03-12 20:15:32 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2009-04-01 10:21:34 +00:00
|
|
|
VIR_FREE(mode);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathNode("./owner", ctxt) == NULL) {
|
2010-03-04 22:35:27 +00:00
|
|
|
perms->uid = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
} else {
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathLong("number(./owner)", ctxt, &v) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed owner element"));
|
2009-03-12 20:15:32 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
perms->uid = (int)v;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathNode("./group", ctxt) == NULL) {
|
2010-03-04 22:35:27 +00:00
|
|
|
perms->gid = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
} else {
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathLong("number(./group)", ctxt, &v) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed group element"));
|
2009-03-12 20:15:32 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
perms->gid = (int)v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB, we're ignoring missing labels here - they'll simply inherit */
|
2010-02-04 21:52:34 +00:00
|
|
|
perms->label = virXPathString("string(./label)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-03-12 20:15:32 +00:00
|
|
|
ret = 0;
|
|
|
|
error:
|
|
|
|
ctxt->node = relnode;
|
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) {
|
2008-11-17 11:19:33 +00:00
|
|
|
virStoragePoolOptionsPtr options;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefPtr ret;
|
2009-10-15 14:55:19 +00:00
|
|
|
xmlNodePtr source_node;
|
2009-06-22 16:41:34 +00:00
|
|
|
char *type = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
char *uuid = NULL;
|
2010-05-20 15:41:31 +00:00
|
|
|
char *tmppath;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
2008-06-06 11:09:57 +00:00
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
type = virXPathString("string(./@type)", ctxt);
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((ret->type = virStoragePoolTypeFromString((const char *)type)) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-17 11:19:33 +00:00
|
|
|
_("unknown storage pool type %s"), (const char*)type);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
2008-11-17 11:19:33 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
xmlFree(type);
|
|
|
|
type = NULL;
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options = virStoragePoolOptionsForPoolType(ret->type)) == NULL) {
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
source_node = virXPathNode("./source", ctxt);
|
2009-10-15 14:55:19 +00:00
|
|
|
if (source_node) {
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type,
|
2009-10-15 14:55:19 +00:00
|
|
|
source_node) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret->name = virXPathString("string(./name)", ctxt);
|
2008-09-02 14:15:42 +00:00
|
|
|
if (ret->name == NULL &&
|
2008-11-17 11:19:33 +00:00
|
|
|
options->flags & VIR_STORAGE_POOL_SOURCE_NAME)
|
2009-10-15 14:55:19 +00:00
|
|
|
ret->name = ret->source.name;
|
2008-09-02 14:15:42 +00:00
|
|
|
if (ret->name == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-09-02 14:15:42 +00:00
|
|
|
"%s", _("missing pool source name element"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
uuid = virXPathString("string(./uuid)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (uuid == NULL) {
|
|
|
|
if (virUUIDGenerate(ret->uuid) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("unable to generate uuid"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virUUIDParse(uuid, ret->uuid) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed uuid element"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(uuid);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) {
|
2009-10-15 14:55:19 +00:00
|
|
|
if (!ret->source.host.name) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
"%s",
|
|
|
|
_("missing storage pool source host name"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) {
|
2009-10-15 14:55:19 +00:00
|
|
|
if (!ret->source.dir) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
"%s", _("missing storage pool source path"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 11:19:33 +00:00
|
|
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
|
2008-09-02 14:15:42 +00:00
|
|
|
if (ret->source.name == NULL) {
|
|
|
|
/* source name defaults to pool name */
|
|
|
|
ret->source.name = strdup(ret->name);
|
2008-09-03 07:12:37 +00:00
|
|
|
if (ret->source.name == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-09-03 07:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-09-02 14:15:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-04-01 16:03:22 +00:00
|
|
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) {
|
2009-10-15 14:55:19 +00:00
|
|
|
if (!ret->source.adapter) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-10-15 14:55:19 +00:00
|
|
|
"%s", _("missing storage pool source adapter name"));
|
2009-04-01 16:03:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-03-03 18:47:12 +00:00
|
|
|
/* If DEVICE is the only source type, then its required */
|
|
|
|
if (options->flags == VIR_STORAGE_POOL_SOURCE_DEVICE) {
|
|
|
|
if (!ret->source.ndevice) {
|
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("missing storage pool source device name"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 15:41:31 +00:00
|
|
|
if ((tmppath = virXPathString("string(./target/path)", ctxt)) == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-09-02 14:15:42 +00:00
|
|
|
"%s", _("missing storage pool target path"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-05-20 15:41:31 +00:00
|
|
|
ret->target.path = virFileSanitizePath(tmppath);
|
|
|
|
VIR_FREE(tmppath);
|
|
|
|
if (!ret->target.path)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
2009-06-22 16:41:34 +00:00
|
|
|
"./target/permissions", 0700) < 0)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
cleanup:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(uuid);
|
2008-04-29 19:43:57 +00:00
|
|
|
xmlFree(type);
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefFree(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseNode(xmlDocPtr xml,
|
2009-06-22 16:41:34 +00:00
|
|
|
xmlNodePtr root) {
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virStoragePoolDefPtr def = NULL;
|
|
|
|
|
|
|
|
if (STRNEQ((const char *)root->name, "pool")) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("unknown root element for storage pool"));
|
2009-06-22 16:41:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt = xmlXPathNewContext(xml);
|
|
|
|
if (ctxt == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-22 16:41:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->node = root;
|
2010-02-10 11:42:56 +00:00
|
|
|
def = virStoragePoolDefParseXML(ctxt);
|
2009-06-22 16:41:34 +00:00
|
|
|
cleanup:
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParse(const char *xmlStr,
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *filename) {
|
|
|
|
virStoragePoolDefPtr ret = NULL;
|
2010-02-24 20:53:16 +00:00
|
|
|
xmlDocPtr xml;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2011-09-14 14:17:57 +00:00
|
|
|
if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)")))) {
|
2010-02-24 20:53:16 +00:00
|
|
|
ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
|
|
|
|
xmlFreeDoc(xml);
|
2009-06-22 16:41:34 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 16:41:34 +00:00
|
|
|
virStoragePoolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseString(const char *xmlStr)
|
2009-06-22 16:41:34 +00:00
|
|
|
{
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStoragePoolDefParse(xmlStr, NULL);
|
2009-06-22 16:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefParseFile(const char *filename)
|
2009-06-22 16:41:34 +00:00
|
|
|
{
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStoragePoolDefParse(NULL, filename);
|
2009-06-22 16:41:34 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 21:54:21 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolSourceFormat(virBufferPtr buf,
|
2008-11-17 11:19:33 +00:00
|
|
|
virStoragePoolOptionsPtr options,
|
2008-11-04 21:54:21 +00:00
|
|
|
virStoragePoolSourcePtr src)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
virBufferAddLit(buf," <source>\n");
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_HOST) &&
|
2010-11-12 13:23:55 +00:00
|
|
|
src->host.name) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " <host name='%s'", src->host.name);
|
2010-11-12 13:23:55 +00:00
|
|
|
if (src->host.port)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " port='%d'", src->host.port);
|
2010-11-12 13:23:55 +00:00
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
2008-11-04 21:54:21 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_DEVICE) &&
|
2008-11-04 21:54:21 +00:00
|
|
|
src->ndevice) {
|
|
|
|
for (i = 0 ; i < src->ndevice ; i++) {
|
|
|
|
if (src->devices[i].nfreeExtent) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <device path='%s'>\n",
|
2008-11-04 21:54:21 +00:00
|
|
|
src->devices[i].path);
|
|
|
|
for (j = 0 ; j < src->devices[i].nfreeExtent ; j++) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " <freeExtent start='%llu' end='%llu'/>\n",
|
2008-11-04 21:54:21 +00:00
|
|
|
src->devices[i].freeExtents[j].start,
|
|
|
|
src->devices[i].freeExtents[j].end);
|
|
|
|
}
|
|
|
|
virBufferAddLit(buf," </device>\n");
|
|
|
|
}
|
|
|
|
else
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " <device path='%s'/>\n",
|
2008-11-04 21:54:21 +00:00
|
|
|
src->devices[i].path);
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_DIR) &&
|
2008-11-04 21:54:21 +00:00
|
|
|
src->dir)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <dir path='%s'/>\n", src->dir);
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) &&
|
2008-11-04 21:54:21 +00:00
|
|
|
src->adapter)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <adapter name='%s'/>\n", src->adapter);
|
2008-11-17 11:19:33 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_NAME) &&
|
2008-11-04 21:54:21 +00:00
|
|
|
src->name)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <name>%s</name>\n", src->name);
|
2008-11-04 21:54:21 +00:00
|
|
|
|
2010-06-07 19:06:20 +00:00
|
|
|
if ((options->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN) &&
|
|
|
|
src->initiator.iqn) {
|
|
|
|
virBufferAddLit(buf," <initiator>\n");
|
|
|
|
virBufferEscapeString(buf," <iqn name='%s'/>\n", src->initiator.iqn);
|
|
|
|
virBufferAddLit(buf," </initiator>\n");
|
|
|
|
}
|
|
|
|
|
2008-11-04 21:54:21 +00:00
|
|
|
if (options->formatToString) {
|
|
|
|
const char *format = (options->formatToString)(src->format);
|
|
|
|
if (!format) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-04 21:54:21 +00:00
|
|
|
_("unknown pool format number %d"),
|
|
|
|
src->format);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <format type='%s'/>\n", format);
|
2008-11-04 21:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <auth type='chap' login='%s' passwd='%s'/>\n",
|
2008-11-04 21:54:21 +00:00
|
|
|
src->auth.chap.login,
|
|
|
|
src->auth.chap.passwd);
|
2010-08-17 17:44:27 +00:00
|
|
|
|
|
|
|
if (src->vendor != NULL) {
|
|
|
|
virBufferEscapeString(buf," <vendor name='%s'/>\n", src->vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->product != NULL) {
|
|
|
|
virBufferEscapeString(buf," <product name='%s'/>\n", src->product);
|
|
|
|
}
|
|
|
|
|
2008-11-04 21:54:21 +00:00
|
|
|
virBufferAddLit(buf," </source>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
char *
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolDefFormat(virStoragePoolDefPtr def) {
|
2008-11-17 11:19:33 +00:00
|
|
|
virStoragePoolOptionsPtr options;
|
2008-04-28 15:14:59 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *type;
|
|
|
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
options = virStoragePoolOptionsForPoolType(def->type);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (options == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
type = virStoragePoolTypeToString(def->type);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!type) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("unexpected pool type"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
|
|
|
|
virBufferAsprintf(&buf," <name>%s</name>\n", def->name);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
virUUIDFormat(def->uuid, uuid);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <uuid>%s</uuid>\n", uuid);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2012-02-23 00:48:38 +00:00
|
|
|
virBufferAsprintf(&buf," <capacity unit='bytes'>%llu</capacity>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->capacity);
|
2012-02-23 00:48:38 +00:00
|
|
|
virBufferAsprintf(&buf," <allocation unit='bytes'>%llu</allocation>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->allocation);
|
2012-02-23 00:48:38 +00:00
|
|
|
virBufferAsprintf(&buf," <available unit='bytes'>%llu</available>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->available);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0)
|
2008-11-04 21:54:21 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf," <target>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
if (def->target.path)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <path>%s</path>\n", def->target.path);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf," <permissions>\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <mode>0%o</mode>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->target.perms.mode);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <owner>%d</owner>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->target.perms.uid);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <group>%d</group>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->target.perms.gid);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
if (def->target.perms.label)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <label>%s</label>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->target.perms.label);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf," </permissions>\n");
|
|
|
|
virBufferAddLit(&buf," </target>\n");
|
|
|
|
virBufferAddLit(&buf,"</pool>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
if (virBufferError(&buf))
|
2008-02-20 15:34:52 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
return virBufferContentAndReset(&buf);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
no_memory:
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
cleanup:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageSize(const char *unit,
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *val,
|
|
|
|
unsigned long long *ret) {
|
|
|
|
unsigned long long mult;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
if (!unit) {
|
|
|
|
mult = 1;
|
|
|
|
} else {
|
|
|
|
switch (unit[0]) {
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
mult = 1024ull;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
mult = 1024ull * 1024ull;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
mult = 1024ull * 1024ull * 1024ull;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
|
|
|
mult = 1024ull * 1024ull * 1024ull * 1024ull;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
mult = 1024ull * 1024ull * 1024ull * 1024ull * 1024ull;
|
|
|
|
break;
|
|
|
|
|
2010-02-22 20:49:27 +00:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
2008-02-20 15:34:52 +00:00
|
|
|
mult = 1024ull * 1024ull * 1024ull * 1024ull * 1024ull *
|
|
|
|
1024ull;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-20 15:34:52 +00:00
|
|
|
_("unknown size units '%s'"), unit);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_ull (val, &end, 10, ret) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed capacity element"));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*ret > (ULLONG_MAX / mult)) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("capacity element value too large"));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret *= mult;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageVolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
2009-06-22 16:41:34 +00:00
|
|
|
xmlXPathContextPtr ctxt) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageVolDefPtr ret;
|
2008-11-17 11:19:33 +00:00
|
|
|
virStorageVolOptionsPtr options;
|
2008-02-20 15:34:52 +00:00
|
|
|
char *allocation = NULL;
|
|
|
|
char *capacity = NULL;
|
|
|
|
char *unit = NULL;
|
2009-07-20 22:28:11 +00:00
|
|
|
xmlNodePtr node;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
options = virStorageVolOptionsForPoolType(pool->type);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (options == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
2008-06-06 11:09:57 +00:00
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret->name = virXPathString("string(./name)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (ret->name == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-09-02 14:15:42 +00:00
|
|
|
"%s", _("missing volume name element"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:37:19 +00:00
|
|
|
/* Auto-generated so deliberately ignore */
|
2010-02-04 21:52:34 +00:00
|
|
|
/*ret->key = virXPathString("string(./key)", ctxt);*/
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
capacity = virXPathString("string(./capacity)", ctxt);
|
|
|
|
unit = virXPathString("string(./capacity/@unit)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (capacity == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("missing capacity element"));
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageSize(unit, capacity, &ret->capacity) < 0)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(capacity);
|
|
|
|
VIR_FREE(unit);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
allocation = virXPathString("string(./allocation)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (allocation) {
|
2010-02-04 21:52:34 +00:00
|
|
|
unit = virXPathString("string(./allocation/@unit)", ctxt);
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageSize(unit, allocation, &ret->allocation) < 0)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(allocation);
|
|
|
|
VIR_FREE(unit);
|
2008-02-20 15:34:52 +00:00
|
|
|
} else {
|
|
|
|
ret->allocation = ret->capacity;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret->target.path = virXPathString("string(./target/path)", ctxt);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (options->formatFromString) {
|
2010-02-04 21:52:34 +00:00
|
|
|
char *format = virXPathString("string(./target/format/@type)", ctxt);
|
2008-12-04 15:22:04 +00:00
|
|
|
if (format == NULL)
|
|
|
|
ret->target.format = options->defaultFormat;
|
|
|
|
else
|
|
|
|
ret->target.format = (options->formatFromString)(format);
|
|
|
|
|
|
|
|
if (ret->target.format < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2008-10-21 17:18:45 +00:00
|
|
|
_("unknown volume format type %s"), format);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(format);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(format);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
2009-06-22 16:41:34 +00:00
|
|
|
"./target/permissions", 0600) < 0)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
node = virXPathNode("./target/encryption", ctxt);
|
2009-07-20 22:28:11 +00:00
|
|
|
if (node != NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
ret->target.encryption = virStorageEncryptionParseNode(ctxt->doc,
|
2009-07-20 22:28:11 +00:00
|
|
|
node);
|
|
|
|
if (ret->target.encryption == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-01-27 18:30:03 +00:00
|
|
|
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
|
2009-01-27 18:30:03 +00:00
|
|
|
if (options->formatFromString) {
|
2010-02-04 21:52:34 +00:00
|
|
|
char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
|
2009-01-27 18:30:03 +00:00
|
|
|
if (format == NULL)
|
|
|
|
ret->backingStore.format = options->defaultFormat;
|
|
|
|
else
|
|
|
|
ret->backingStore.format = (options->formatFromString)(format);
|
|
|
|
|
|
|
|
if (ret->backingStore.format < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-01-27 18:30:03 +00:00
|
|
|
_("unknown volume format type %s"), format);
|
|
|
|
VIR_FREE(format);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(format);
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms,
|
2009-06-22 16:41:34 +00:00
|
|
|
"./backingStore/permissions", 0600) < 0)
|
2009-01-27 18:30:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
cleanup:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(allocation);
|
|
|
|
VIR_FREE(capacity);
|
|
|
|
VIR_FREE(unit);
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageVolDefFree(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStorageVolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefParseNode(virStoragePoolDefPtr pool,
|
2009-06-22 16:41:34 +00:00
|
|
|
xmlDocPtr xml,
|
|
|
|
xmlNodePtr root) {
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virStorageVolDefPtr def = NULL;
|
|
|
|
|
|
|
|
if (STRNEQ((const char *)root->name, "volume")) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2009-06-22 16:41:34 +00:00
|
|
|
"%s", _("unknown root element for storage vol"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt = xmlXPathNewContext(xml);
|
|
|
|
if (ctxt == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-06-22 16:41:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->node = root;
|
2010-02-10 11:42:56 +00:00
|
|
|
def = virStorageVolDefParseXML(pool, ctxt);
|
2009-06-22 16:41:34 +00:00
|
|
|
cleanup:
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageVolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefParse(virStoragePoolDefPtr pool,
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *xmlStr,
|
|
|
|
const char *filename) {
|
|
|
|
virStorageVolDefPtr ret = NULL;
|
2010-02-24 20:53:16 +00:00
|
|
|
xmlDocPtr xml;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2011-09-14 14:17:57 +00:00
|
|
|
if ((xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)")))) {
|
2010-02-24 20:53:16 +00:00
|
|
|
ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml));
|
|
|
|
xmlFreeDoc(xml);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 16:41:34 +00:00
|
|
|
virStorageVolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefParseString(virStoragePoolDefPtr pool,
|
2009-06-22 16:41:34 +00:00
|
|
|
const char *xmlStr)
|
|
|
|
{
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageVolDefParse(pool, xmlStr, NULL);
|
2009-06-22 16:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virStorageVolDefPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefParseFile(virStoragePoolDefPtr pool,
|
2009-06-22 16:41:34 +00:00
|
|
|
const char *filename)
|
|
|
|
{
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageVolDefParse(pool, NULL, filename);
|
2009-06-22 16:41:34 +00:00
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-01-27 18:30:03 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
|
2009-01-27 18:30:03 +00:00
|
|
|
virBufferPtr buf,
|
|
|
|
virStorageVolTargetPtr def,
|
|
|
|
const char *type) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " <%s>\n", type);
|
2009-01-27 18:30:03 +00:00
|
|
|
|
|
|
|
if (def->path)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <path>%s</path>\n", def->path);
|
2009-01-27 18:30:03 +00:00
|
|
|
|
|
|
|
if (options->formatToString) {
|
|
|
|
const char *format = (options->formatToString)(def->format);
|
|
|
|
if (!format) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2009-01-27 18:30:03 +00:00
|
|
|
_("unknown volume format number %d"),
|
|
|
|
def->format);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <format type='%s'/>\n", format);
|
2009-01-27 18:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(buf," <permissions>\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <mode>0%o</mode>\n",
|
2009-01-27 18:30:03 +00:00
|
|
|
def->perms.mode);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <owner>%d</owner>\n",
|
2009-01-27 18:30:03 +00:00
|
|
|
def->perms.uid);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <group>%d</group>\n",
|
2009-01-27 18:30:03 +00:00
|
|
|
def->perms.gid);
|
|
|
|
|
|
|
|
|
|
|
|
if (def->perms.label)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf," <label>%s</label>\n",
|
2009-01-27 18:30:03 +00:00
|
|
|
def->perms.label);
|
|
|
|
|
|
|
|
virBufferAddLit(buf," </permissions>\n");
|
|
|
|
|
2011-09-22 18:16:26 +00:00
|
|
|
if (def->encryption) {
|
|
|
|
virBufferAdjustIndent(buf, 4);
|
|
|
|
if (virStorageEncryptionFormat(buf, def->encryption) < 0)
|
|
|
|
return -1;
|
|
|
|
virBufferAdjustIndent(buf, -4);
|
|
|
|
}
|
2009-07-20 22:28:11 +00:00
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " </%s>\n", type);
|
2009-01-27 18:30:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
char *
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolDefFormat(virStoragePoolDefPtr pool,
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageVolDefPtr def) {
|
2008-11-17 11:19:33 +00:00
|
|
|
virStorageVolOptionsPtr options;
|
2008-04-28 15:14:59 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
options = virStorageVolOptionsForPoolType(pool->type);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (options == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf, "<volume>\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf," <name>%s</name>\n", def->name);
|
|
|
|
virBufferAsprintf(&buf," <key>%s</key>\n", def->key);
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf, " <source>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (def->source.nextent) {
|
|
|
|
int i;
|
|
|
|
const char *thispath = NULL;
|
|
|
|
for (i = 0 ; i < def->source.nextent ; i++) {
|
|
|
|
if (thispath == NULL ||
|
|
|
|
STRNEQ(thispath, def->source.extents[i].path)) {
|
|
|
|
if (thispath != NULL)
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf, " </device>\n");
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <device path='%s'>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->source.extents[i].path);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2008-04-28 15:14:59 +00:00
|
|
|
" <extent start='%llu' end='%llu'/>\n",
|
|
|
|
def->source.extents[i].start,
|
|
|
|
def->source.extents[i].end);
|
2008-02-20 15:34:52 +00:00
|
|
|
thispath = def->source.extents[i].path;
|
|
|
|
}
|
|
|
|
if (thispath != NULL)
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf, " </device>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&buf, " </source>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2012-02-23 00:48:38 +00:00
|
|
|
virBufferAsprintf(&buf," <capacity unit='bytes'>%llu</capacity>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->capacity);
|
2012-02-23 00:48:38 +00:00
|
|
|
virBufferAsprintf(&buf," <allocation unit='bytes'>%llu</allocation>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
def->allocation);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageVolTargetDefFormat(options, &buf,
|
2009-01-27 18:30:03 +00:00
|
|
|
&def->target, "target") < 0)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-01-27 18:30:03 +00:00
|
|
|
if (def->backingStore.path &&
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageVolTargetDefFormat(options, &buf,
|
2009-01-27 18:30:03 +00:00
|
|
|
&def->backingStore, "backingStore") < 0)
|
|
|
|
goto cleanup;
|
2008-04-28 15:14:59 +00:00
|
|
|
|
|
|
|
virBufferAddLit(&buf,"</volume>\n");
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
if (virBufferError(&buf))
|
2008-02-20 15:34:52 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
return virBufferContentAndReset(&buf);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
no_memory:
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
cleanup:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStoragePoolObjPtr
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
|
2008-02-20 15:34:52 +00:00
|
|
|
const unsigned char *uuid) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
for (i = 0 ; i < pools->count ; i++) {
|
|
|
|
virStoragePoolObjLock(pools->objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!memcmp(pools->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
|
|
|
|
return pools->objs[i];
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjUnlock(pools->objs[i]);
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolObjPtr
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *name) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
for (i = 0 ; i < pools->count ; i++) {
|
|
|
|
virStoragePoolObjLock(pools->objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (STREQ(pools->objs[i]->def->name, name))
|
|
|
|
return pools->objs[i];
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjUnlock(pools->objs[i]);
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:52:03 +00:00
|
|
|
virStoragePoolObjPtr
|
|
|
|
virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr pool,
|
|
|
|
virStoragePoolDefPtr def) {
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < pool->def->source.ndevice; i++) {
|
|
|
|
for (j = 0; j < def->source.ndevice; j++) {
|
|
|
|
if (STREQ(pool->def->source.devices[i].path, def->source.devices[j].path))
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
void
|
|
|
|
virStoragePoolObjClearVols(virStoragePoolObjPtr pool)
|
|
|
|
{
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i = 0 ; i < pool->volumes.count ; i++)
|
|
|
|
virStorageVolDefFree(pool->volumes.objs[i]);
|
|
|
|
|
|
|
|
VIR_FREE(pool->volumes.objs);
|
|
|
|
pool->volumes.count = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virStorageVolDefPtr
|
|
|
|
virStorageVolDefFindByKey(virStoragePoolObjPtr pool,
|
|
|
|
const char *key) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pool->volumes.count ; i++)
|
|
|
|
if (STREQ(pool->volumes.objs[i]->key, key))
|
|
|
|
return pool->volumes.objs[i];
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStorageVolDefPtr
|
|
|
|
virStorageVolDefFindByPath(virStoragePoolObjPtr pool,
|
|
|
|
const char *path) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pool->volumes.count ; i++)
|
|
|
|
if (STREQ(pool->volumes.objs[i]->target.path, path))
|
|
|
|
return pool->volumes.objs[i];
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStorageVolDefPtr
|
|
|
|
virStorageVolDefFindByName(virStoragePoolObjPtr pool,
|
|
|
|
const char *name) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pool->volumes.count ; i++)
|
|
|
|
if (STREQ(pool->volumes.objs[i]->name, name))
|
|
|
|
return pool->volumes.objs[i];
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolObjPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefPtr def) {
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if ((pool = virStoragePoolObjFindByName(pools, def->name))) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStoragePoolDefFree(pool->def);
|
|
|
|
pool->def = def;
|
|
|
|
} else {
|
2010-05-17 20:38:59 +00:00
|
|
|
virStoragePoolDefFree(pool->newDef);
|
2008-02-20 15:34:52 +00:00
|
|
|
pool->newDef = def;
|
|
|
|
}
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(pool) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&pool->lock) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2009-01-15 19:56:05 +00:00
|
|
|
"%s", _("cannot initialize mutex"));
|
|
|
|
VIR_FREE(pool);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
pool->active = 0;
|
|
|
|
pool->def = def;
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (VIR_REALLOC_N(pools->objs, pools->count+1) < 0) {
|
|
|
|
pool->def = NULL;
|
2009-01-15 19:56:05 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjFree(pool);
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-10-10 15:13:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pools->objs[pools->count++] = pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolObjPtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
|
2008-02-20 15:34:52 +00:00
|
|
|
const char *file,
|
|
|
|
const char *path,
|
|
|
|
const char *autostartLink) {
|
|
|
|
virStoragePoolDefPtr def;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(def = virStoragePoolDefParseFile(path))) {
|
2008-02-20 15:34:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
|
2011-01-15 15:31:29 +00:00
|
|
|
virStorageReportError(VIR_ERR_XML_ERROR,
|
2010-02-11 15:27:26 +00:00
|
|
|
_("Storage pool config filename '%s' does not match pool name '%s'"),
|
2010-02-10 11:42:56 +00:00
|
|
|
path, def->name);
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(pools, def))) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-28 21:38:06 +00:00
|
|
|
VIR_FREE(pool->configFile); /* for driver reload */
|
2008-02-20 15:34:52 +00:00
|
|
|
pool->configFile = strdup(path);
|
|
|
|
if (pool->configFile == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-28 21:38:06 +00:00
|
|
|
VIR_FREE(pool->autostartLink); /* for driver reload */
|
2008-02-20 15:34:52 +00:00
|
|
|
pool->autostartLink = strdup(autostartLink);
|
|
|
|
if (pool->autostartLink == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool->autostart = virFileLinkPointsTo(pool->autostartLink,
|
|
|
|
pool->configFile);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
|
2008-10-10 15:13:28 +00:00
|
|
|
const char *configDir,
|
|
|
|
const char *autostartDir) {
|
2008-02-20 15:34:52 +00:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!(dir = opendir(configDir))) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if (errno == ENOENT)
|
|
|
|
return 0;
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, _("Failed to open dir '%s'"),
|
2009-05-20 13:37:30 +00:00
|
|
|
configDir);
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((entry = readdir(dir))) {
|
2011-04-03 09:21:14 +00:00
|
|
|
char *path;
|
|
|
|
char *autostartLink;
|
2008-12-04 22:00:14 +00:00
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (entry->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!virFileHasSuffix(entry->d_name, ".xml"))
|
|
|
|
continue;
|
|
|
|
|
2011-04-24 09:48:00 +00:00
|
|
|
if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
|
2011-04-03 09:21:14 +00:00
|
|
|
if (!(autostartLink = virFileBuildPath(autostartDir, entry->d_name,
|
|
|
|
NULL))) {
|
|
|
|
VIR_FREE(path);
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
pool = virStoragePoolObjLoad(pools, entry->d_name, path,
|
2009-06-25 15:13:25 +00:00
|
|
|
autostartLink);
|
2008-12-04 22:00:14 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2011-04-03 09:21:14 +00:00
|
|
|
|
|
|
|
VIR_FREE(path);
|
|
|
|
VIR_FREE(autostartLink);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2011-10-27 16:55:47 +00:00
|
|
|
virStoragePoolDefPtr def)
|
|
|
|
{
|
2008-02-20 15:34:52 +00:00
|
|
|
char *xml;
|
2011-10-27 16:55:47 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (!pool->configFile) {
|
2011-07-05 21:02:53 +00:00
|
|
|
if (virFileMakePath(driver->configDir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
2009-10-27 16:20:22 +00:00
|
|
|
_("cannot create config directory %s"),
|
|
|
|
driver->configDir);
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-03 09:21:14 +00:00
|
|
|
if (!(pool->configFile = virFileBuildPath(driver->configDir,
|
|
|
|
def->name, ".xml"))) {
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-03 09:21:14 +00:00
|
|
|
if (!(pool->autostartLink = virFileBuildPath(driver->autostartDir,
|
|
|
|
def->name, ".xml"))) {
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(pool->configFile);
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(xml = virStoragePoolDefFormat(def))) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("failed to generate XML"));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-27 16:55:47 +00:00
|
|
|
ret = virXMLSaveFile(pool->configFile, def->name, "pool-edit", xml);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(xml);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool->configFile) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-20 15:34:52 +00:00
|
|
|
_("no config file for %s"), pool->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlink(pool->configFile) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-20 15:34:52 +00:00
|
|
|
_("cannot remove config for %s"),
|
|
|
|
pool->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-23 11:39:53 +00:00
|
|
|
|
2009-10-15 15:41:53 +00:00
|
|
|
virStoragePoolSourcePtr
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list)
|
2009-10-15 15:41:53 +00:00
|
|
|
{
|
|
|
|
virStoragePoolSourcePtr source;
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(list->sources, list->nsources+1) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-10-15 15:41:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
source = &list->sources[list->nsources++];
|
|
|
|
memset(source, 0, sizeof(*source));
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
char *virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def)
|
2008-10-23 11:39:53 +00:00
|
|
|
{
|
2008-11-17 11:19:33 +00:00
|
|
|
virStoragePoolOptionsPtr options;
|
2008-10-23 11:39:53 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2008-11-04 21:54:21 +00:00
|
|
|
const char *type;
|
|
|
|
int i;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
options = virStoragePoolOptionsForPoolType(def->type);
|
2008-11-04 21:54:21 +00:00
|
|
|
if (options == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
type = virStoragePoolTypeToString(def->type);
|
2008-11-04 21:54:21 +00:00
|
|
|
if (!type) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-04 21:54:21 +00:00
|
|
|
"%s", _("unexpected pool type"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "<sources>\n");
|
2008-10-23 11:39:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < def->nsources; i++) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolSourceFormat(&buf, options, &def->sources[i]);
|
2008-10-23 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 21:54:21 +00:00
|
|
|
virBufferAddLit(&buf, "</sources>\n");
|
|
|
|
|
|
|
|
if (virBufferError(&buf))
|
|
|
|
goto no_memory;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
2008-11-04 21:54:21 +00:00
|
|
|
|
|
|
|
no_memory:
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-04 21:54:21 +00:00
|
|
|
cleanup:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-11-04 21:54:21 +00:00
|
|
|
return NULL;
|
2008-10-23 11:39:53 +00:00
|
|
|
}
|
2008-12-04 20:53:20 +00:00
|
|
|
|
|
|
|
|
2010-05-27 11:41:30 +00:00
|
|
|
/*
|
|
|
|
* virStoragePoolObjIsDuplicate:
|
|
|
|
* @doms : virStoragePoolObjListPtr to search
|
|
|
|
* @def : virStoragePoolDefPtr definition of pool to lookup
|
|
|
|
* @check_active: If true, ensure that pool is not active
|
|
|
|
*
|
|
|
|
* Returns: -1 on error
|
|
|
|
* 0 if pool is new
|
|
|
|
* 1 if pool is a duplicate
|
|
|
|
*/
|
|
|
|
int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolDefPtr def,
|
|
|
|
unsigned int check_active)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int dupPool = 0;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
|
|
|
|
/* See if a Pool with matching UUID already exists */
|
|
|
|
pool = virStoragePoolObjFindByUUID(pools, def->uuid);
|
|
|
|
if (pool) {
|
|
|
|
/* UUID matches, but if names don't match, refuse it */
|
|
|
|
if (STRNEQ(pool->def->name, def->name)) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(pool->def->uuid, uuidstr);
|
|
|
|
virStorageReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("pool '%s' is already defined with uuid %s"),
|
|
|
|
pool->def->name, uuidstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_active) {
|
|
|
|
/* UUID & name match, but if Pool is already active, refuse it */
|
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("pool is already active as '%s'"),
|
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dupPool = 1;
|
|
|
|
} else {
|
|
|
|
/* UUID does not match, but if a name matches, refuse it */
|
|
|
|
pool = virStoragePoolObjFindByName(pools, def->name);
|
|
|
|
if (pool) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(pool->def->uuid, uuidstr);
|
|
|
|
virStorageReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("pool '%s' already exists with uuid %s"),
|
|
|
|
def->name, uuidstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dupPool;
|
|
|
|
cleanup:
|
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-05 07:52:03 +00:00
|
|
|
int virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolDefPtr def)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret = 1;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
virStoragePoolObjPtr matchpool = NULL;
|
|
|
|
|
|
|
|
/* Check the pool list for duplicate underlying storage */
|
|
|
|
for (i = 0; i < pools->count; i++) {
|
|
|
|
pool = pools->objs[i];
|
|
|
|
if (def->type != pool->def->type)
|
|
|
|
continue;
|
|
|
|
|
2011-10-07 16:38:09 +00:00
|
|
|
/* Don't mach against ourself if re-defining existing pool ! */
|
|
|
|
if (STREQ(pool->def->name, def->name))
|
|
|
|
continue;
|
|
|
|
|
2011-09-05 07:52:03 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
|
|
|
|
|
|
|
switch (pool->def->type) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
if (STREQ(pool->def->target.path, def->target.path))
|
|
|
|
matchpool = pool;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
if ((STREQ(pool->def->source.dir, def->source.dir)) \
|
|
|
|
&& (STREQ(pool->def->source.host.name, def->source.host.name)))
|
|
|
|
matchpool = pool;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
if (STREQ(pool->def->source.adapter, def->source.adapter))
|
|
|
|
matchpool = pool;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
{
|
|
|
|
matchpool = virStoragePoolSourceFindDuplicateDevices(pool, def);
|
|
|
|
if (matchpool) {
|
|
|
|
if (STREQ(matchpool->def->source.host.name, def->source.host.name)) {
|
|
|
|
if ((matchpool->def->source.initiator.iqn) && (def->source.initiator.iqn)) {
|
|
|
|
if (STREQ(matchpool->def->source.initiator.iqn, def->source.initiator.iqn))
|
|
|
|
break;
|
|
|
|
matchpool = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
matchpool = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
matchpool = virStoragePoolSourceFindDuplicateDevices(pool, def);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchpool) {
|
|
|
|
virStorageReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Storage source conflict with pool: '%s'"),
|
|
|
|
matchpool->def->name);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2010-05-27 11:41:30 +00:00
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
void virStoragePoolObjLock(virStoragePoolObjPtr obj)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&obj->lock);
|
2008-12-04 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void virStoragePoolObjUnlock(virStoragePoolObjPtr obj)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&obj->lock);
|
2008-12-04 22:00:14 +00:00
|
|
|
}
|