提交 cd3eecd8 编写于 作者: J John Ferlan

storage: Use virStoragePoolObjGetDef accessor for Disk backend

In preparation for privatizing the object, use the accessor.
上级 c0682800
...@@ -59,6 +59,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -59,6 +59,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
char **const groups, char **const groups,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *tmp, *devpath, *partname; char *tmp, *devpath, *partname;
/* Prepended path will be same for all partitions, so we can /* Prepended path will be same for all partitions, so we can
...@@ -114,8 +115,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -114,8 +115,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
* our deletion will fail because the name we generated is wrong. * our deletion will fail because the name we generated is wrong.
* Check for our conditions and see if the generated name is the * Check for our conditions and see if the generated name is the
* same as StablePath returns and has the 'p' in it */ * same as StablePath returns and has the 'p' in it */
if (pool->def->source.devices[0].part_separator == if (def->source.devices[0].part_separator == VIR_TRISTATE_BOOL_YES &&
VIR_TRISTATE_BOOL_YES &&
!virIsDevMapperDevice(vol->target.path) && !virIsDevMapperDevice(vol->target.path) &&
STREQ(groups[0], vol->target.path) && STREQ(groups[0], vol->target.path) &&
(tmp = strrchr(groups[0], 'p'))) { (tmp = strrchr(groups[0], 'p'))) {
...@@ -158,7 +158,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -158,7 +158,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
} }
if (VIR_STRDUP(vol->source.extents[0].path, if (VIR_STRDUP(vol->source.extents[0].path,
pool->def->source.devices[0].path) < 0) def->source.devices[0].path) < 0)
return -1; return -1;
} }
...@@ -212,9 +212,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -212,9 +212,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
} }
if (STRNEQ(groups[2], "metadata")) if (STRNEQ(groups[2], "metadata"))
pool->def->allocation += vol->target.allocation; def->allocation += vol->target.allocation;
if (vol->source.extents[0].end > pool->def->capacity) if (vol->source.extents[0].end > def->capacity)
pool->def->capacity = vol->source.extents[0].end; def->capacity = vol->source.extents[0].end;
return 0; return 0;
} }
...@@ -223,7 +223,8 @@ static int ...@@ -223,7 +223,8 @@ static int
virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool, virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool,
char **const groups) char **const groups)
{ {
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0]; virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStoragePoolSourceDevicePtr dev = &def->source.devices[0];
if (VIR_REALLOC_N(dev->freeExtents, if (VIR_REALLOC_N(dev->freeExtents,
dev->nfreeExtent + 1) < 0) dev->nfreeExtent + 1) < 0)
...@@ -253,11 +254,10 @@ virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool, ...@@ -253,11 +254,10 @@ virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool,
if (dev->freeExtents[dev->nfreeExtent].start == 0) if (dev->freeExtents[dev->nfreeExtent].start == 0)
dev->freeExtents[dev->nfreeExtent].start = SECTOR_SIZE; dev->freeExtents[dev->nfreeExtent].start = SECTOR_SIZE;
pool->def->available += def->available += (dev->freeExtents[dev->nfreeExtent].end -
(dev->freeExtents[dev->nfreeExtent].end - dev->freeExtents[dev->nfreeExtent].start);
dev->freeExtents[dev->nfreeExtent].start); if (dev->freeExtents[dev->nfreeExtent].end > def->capacity)
if (dev->freeExtents[dev->nfreeExtent].end > pool->def->capacity) def->capacity = dev->freeExtents[dev->nfreeExtent].end;
pool->def->capacity = dev->freeExtents[dev->nfreeExtent].end;
dev->nfreeExtent++; dev->nfreeExtent++;
...@@ -339,6 +339,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, ...@@ -339,6 +339,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
* *
*/ */
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *parthelper_path; char *parthelper_path;
virCommandPtr cmd; virCommandPtr cmd;
struct virStorageBackendDiskPoolVolData cbdata = { struct virStorageBackendDiskPoolVolData cbdata = {
...@@ -353,7 +354,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, ...@@ -353,7 +354,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
return -1; return -1;
cmd = virCommandNewArgList(parthelper_path, cmd = virCommandNewArgList(parthelper_path,
pool->def->source.devices[0].path, def->source.devices[0].path,
NULL); NULL);
/* Check for the presence of the part_separator='yes'. Pass this /* Check for the presence of the part_separator='yes'. Pass this
...@@ -362,16 +363,15 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, ...@@ -362,16 +363,15 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
* the generated device name for a source device which ends with * the generated device name for a source device which ends with
* a non-numeric value (e.g. mpatha would generate mpathap#). * a non-numeric value (e.g. mpatha would generate mpathap#).
*/ */
if (pool->def->source.devices[0].part_separator == if (def->source.devices[0].part_separator == VIR_TRISTATE_BOOL_YES)
VIR_TRISTATE_BOOL_YES)
virCommandAddArg(cmd, "-p"); virCommandAddArg(cmd, "-p");
/* If a volume is passed, virStorageBackendDiskMakeVol only updates the /* If a volume is passed, virStorageBackendDiskMakeVol only updates the
* pool allocation for that single volume. * pool allocation for that single volume.
*/ */
if (!vol) if (!vol)
pool->def->allocation = 0; def->allocation = 0;
pool->def->capacity = pool->def->available = 0; def->capacity = def->available = 0;
ret = virCommandRunNul(cmd, ret = virCommandRunNul(cmd,
6, 6,
...@@ -388,7 +388,8 @@ virStorageBackendDiskMakePoolGeometry(size_t ntok ATTRIBUTE_UNUSED, ...@@ -388,7 +388,8 @@ virStorageBackendDiskMakePoolGeometry(size_t ntok ATTRIBUTE_UNUSED,
void *data) void *data)
{ {
virStoragePoolObjPtr pool = data; virStoragePoolObjPtr pool = data;
virStoragePoolSourceDevicePtr device = &(pool->def->source.devices[0]); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStoragePoolSourceDevicePtr device = &(def->source.devices[0]);
if (virStrToLong_i(groups[0], NULL, 0, &device->geometry.cylinders) < 0 || if (virStrToLong_i(groups[0], NULL, 0, &device->geometry.cylinders) < 0 ||
virStrToLong_i(groups[1], NULL, 0, &device->geometry.heads) < 0 || virStrToLong_i(groups[1], NULL, 0, &device->geometry.heads) < 0 ||
virStrToLong_i(groups[2], NULL, 0, &device->geometry.sectors) < 0) { virStrToLong_i(groups[2], NULL, 0, &device->geometry.sectors) < 0) {
...@@ -403,6 +404,7 @@ virStorageBackendDiskMakePoolGeometry(size_t ntok ATTRIBUTE_UNUSED, ...@@ -403,6 +404,7 @@ virStorageBackendDiskMakePoolGeometry(size_t ntok ATTRIBUTE_UNUSED,
static int static int
virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *parthelper_path; char *parthelper_path;
virCommandPtr cmd; virCommandPtr cmd;
int ret; int ret;
...@@ -413,9 +415,9 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) ...@@ -413,9 +415,9 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
return -1; return -1;
cmd = virCommandNewArgList(parthelper_path, cmd = virCommandNewArgList(parthelper_path,
pool->def->source.devices[0].path, def->source.devices[0].path,
"-g", "-g",
NULL); NULL);
ret = virCommandRunNul(cmd, ret = virCommandRunNul(cmd,
3, 3,
...@@ -430,15 +432,17 @@ static int ...@@ -430,15 +432,17 @@ static int
virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool) virStoragePoolObjPtr pool)
{ {
VIR_FREE(pool->def->source.devices[0].freeExtents); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
pool->def->source.devices[0].nfreeExtent = 0;
VIR_FREE(def->source.devices[0].freeExtents);
def->source.devices[0].nfreeExtent = 0;
virWaitForDevices(); virWaitForDevices();
if (!virFileExists(pool->def->source.devices[0].path)) { if (!virFileExists(def->source.devices[0].path)) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("device path '%s' doesn't exist"), _("device path '%s' doesn't exist"),
pool->def->source.devices[0].path); def->source.devices[0].path);
return -1; return -1;
} }
...@@ -453,8 +457,9 @@ static int ...@@ -453,8 +457,9 @@ static int
virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool) virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
const char *format; const char *format;
const char *path = pool->def->source.devices[0].path; const char *path = def->source.devices[0].path;
virWaitForDevices(); virWaitForDevices();
...@@ -464,9 +469,9 @@ virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -464,9 +469,9 @@ virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
return -1; return -1;
} }
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_UNKNOWN) if (def->source.format == VIR_STORAGE_POOL_DISK_UNKNOWN)
pool->def->source.format = VIR_STORAGE_POOL_DISK_DOS; def->source.format = VIR_STORAGE_POOL_DISK_DOS;
format = virStoragePoolFormatDiskTypeToString(pool->def->source.format); format = virStoragePoolFormatDiskTypeToString(def->source.format);
if (!virStorageBackendDeviceIsEmpty(path, format, false)) if (!virStorageBackendDeviceIsEmpty(path, format, false))
return -1; return -1;
...@@ -482,7 +487,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -482,7 +487,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
unsigned int flags) unsigned int flags)
{ {
int format = pool->def->source.format; virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int format = def->source.format;
const char *fmt; const char *fmt;
bool ok_to_mklabel = false; bool ok_to_mklabel = false;
int ret = -1; int ret = -1;
...@@ -499,26 +505,26 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -499,26 +505,26 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
ok_to_mklabel = true; ok_to_mklabel = true;
} else { } else {
if (virStorageBackendDeviceIsEmpty(pool->def->source.devices[0].path, if (virStorageBackendDeviceIsEmpty(def->source.devices[0].path,
fmt, true)) fmt, true))
ok_to_mklabel = true; ok_to_mklabel = true;
} }
if (ok_to_mklabel) { if (ok_to_mklabel) {
if (virStorageBackendZeroPartitionTable(pool->def->source.devices[0].path, if (virStorageBackendZeroPartitionTable(def->source.devices[0].path,
1024 * 1024) < 0) 1024 * 1024) < 0)
goto error; goto error;
/* eg parted /dev/sda mklabel --script msdos */ /* eg parted /dev/sda mklabel --script msdos */
if (format == VIR_STORAGE_POOL_DISK_UNKNOWN) if (format == VIR_STORAGE_POOL_DISK_UNKNOWN)
format = pool->def->source.format = VIR_STORAGE_POOL_DISK_DOS; format = def->source.format = VIR_STORAGE_POOL_DISK_DOS;
if (format == VIR_STORAGE_POOL_DISK_DOS) if (format == VIR_STORAGE_POOL_DISK_DOS)
fmt = "msdos"; fmt = "msdos";
else else
fmt = virStoragePoolFormatDiskTypeToString(format); fmt = virStoragePoolFormatDiskTypeToString(format);
cmd = virCommandNewArgList(PARTED, cmd = virCommandNewArgList(PARTED,
pool->def->source.devices[0].path, def->source.devices[0].path,
"mklabel", "mklabel",
"--script", "--script",
fmt, fmt,
...@@ -557,9 +563,10 @@ virStorageVolNumOfPartTypes(virStorageVolDefPtr def, ...@@ -557,9 +563,10 @@ virStorageVolNumOfPartTypes(virStorageVolDefPtr def,
static int static int
virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
struct virStorageVolNumData data = { .count = 0 }; struct virStorageVolNumData data = { .count = 0 };
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { if (def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
/* count primary and extended partitions, /* count primary and extended partitions,
can't be more than 3 to create a new primary partition */ can't be more than 3 to create a new primary partition */
if (virStoragePoolObjForEachVolume(pool, virStorageVolNumOfPartTypes, if (virStoragePoolObjForEachVolume(pool, virStorageVolNumOfPartTypes,
...@@ -578,7 +585,9 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, ...@@ -578,7 +585,9 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
char** partFormat) char** partFormat)
{ {
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
if (def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
const char *partedFormat; const char *partedFormat;
partedFormat = virStoragePartedFsTypeToString(vol->target.format); partedFormat = virStoragePartedFsTypeToString(vol->target.format);
if (partedFormat == NULL) { if (partedFormat == NULL) {
...@@ -652,7 +661,8 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool, ...@@ -652,7 +661,8 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool,
unsigned long long smallestSize = 0; unsigned long long smallestSize = 0;
unsigned long long extraBytes = 0; unsigned long long extraBytes = 0;
unsigned long long alignedAllocation = allocation; unsigned long long alignedAllocation = allocation;
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0]; virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStoragePoolSourceDevicePtr dev = &def->source.devices[0];
unsigned long long cylinderSize = (unsigned long long)dev->geometry.heads * unsigned long long cylinderSize = (unsigned long long)dev->geometry.heads *
dev->geometry.sectors * SECTOR_SIZE; dev->geometry.sectors * SECTOR_SIZE;
...@@ -670,7 +680,7 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool, ...@@ -670,7 +680,7 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool,
dev->freeExtents[i].start; dev->freeExtents[i].start;
unsigned long long neededSize = allocation; unsigned long long neededSize = allocation;
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { if (def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
/* align to cylinder boundary */ /* align to cylinder boundary */
neededSize += extraBytes; neededSize += extraBytes;
if ((*start % cylinderSize) > extraBytes) { if ((*start % cylinderSize) > extraBytes) {
...@@ -718,7 +728,7 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool, ...@@ -718,7 +728,7 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool,
} }
*end = *start + alignedAllocation; *end = *start + alignedAllocation;
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { if (def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
/* adjust our allocation if start is not at a cylinder boundary */ /* adjust our allocation if start is not at a cylinder boundary */
*end -= (*start % cylinderSize); *end -= (*start % cylinderSize);
} }
...@@ -764,7 +774,8 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn, ...@@ -764,7 +774,8 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn,
char *part_num = NULL; char *part_num = NULL;
char *devpath = NULL; char *devpath = NULL;
char *dev_name; char *dev_name;
char *src_path = pool->def->source.devices[0].path; virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *src_path = def->source.devices[0].path;
char *srcname = last_component(src_path); char *srcname = last_component(src_path);
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
bool isDevMapperDevice; bool isDevMapperDevice;
...@@ -854,8 +865,9 @@ virStorageBackendDiskCreateVol(virConnectPtr conn, ...@@ -854,8 +865,9 @@ virStorageBackendDiskCreateVol(virConnectPtr conn,
int res = -1; int res = -1;
char *partFormat = NULL; char *partFormat = NULL;
unsigned long long startOffset = 0, endOffset = 0; unsigned long long startOffset = 0, endOffset = 0;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virCommandPtr cmd = virCommandNewArgList(PARTED, virCommandPtr cmd = virCommandNewArgList(PARTED,
pool->def->source.devices[0].path, def->source.devices[0].path,
"mkpart", "mkpart",
"--script", "--script",
NULL); NULL);
...@@ -887,8 +899,8 @@ virStorageBackendDiskCreateVol(virConnectPtr conn, ...@@ -887,8 +899,8 @@ virStorageBackendDiskCreateVol(virConnectPtr conn,
virWaitForDevices(); virWaitForDevices();
/* Blow away free extent info, as we're about to re-populate it */ /* Blow away free extent info, as we're about to re-populate it */
VIR_FREE(pool->def->source.devices[0].freeExtents); VIR_FREE(def->source.devices[0].freeExtents);
pool->def->source.devices[0].nfreeExtent = 0; def->source.devices[0].nfreeExtent = 0;
/* Specifying a target path is meaningless */ /* Specifying a target path is meaningless */
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册