mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-13 08:58:33 +03:00
storage: Use virStoragePoolObjGetDef accessor for FS backend
In preparation for privatizing the object, use the accessor.
This commit is contained in:
parent
2bbb66c4b7
commit
759fbdd00b
@ -222,25 +222,27 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
||||
static int
|
||||
virStorageBackendFileSystemIsValid(virStoragePoolObjPtr pool)
|
||||
{
|
||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||
if (pool->def->source.nhost != 1) {
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
|
||||
if (def->type == VIR_STORAGE_POOL_NETFS) {
|
||||
if (def->source.nhost != 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("expected exactly 1 host for the storage pool"));
|
||||
return -1;
|
||||
}
|
||||
if (pool->def->source.hosts[0].name == NULL) {
|
||||
if (def->source.hosts[0].name == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("missing source host"));
|
||||
return -1;
|
||||
}
|
||||
if (pool->def->source.dir == NULL) {
|
||||
if (def->source.dir == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("missing source path"));
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (pool->def->source.ndevice != 1) {
|
||||
if (pool->def->source.ndevice == 0)
|
||||
if (def->source.ndevice != 1) {
|
||||
if (def->source.ndevice == 0)
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("missing source device"));
|
||||
else
|
||||
@ -264,22 +266,23 @@ virStorageBackendFileSystemIsValid(virStoragePoolObjPtr pool)
|
||||
static char *
|
||||
virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool)
|
||||
{
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
char *src = NULL;
|
||||
|
||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||
if (pool->def->source.format == VIR_STORAGE_POOL_NETFS_CIFS) {
|
||||
if (def->type == VIR_STORAGE_POOL_NETFS) {
|
||||
if (def->source.format == VIR_STORAGE_POOL_NETFS_CIFS) {
|
||||
if (virAsprintf(&src, "//%s/%s",
|
||||
pool->def->source.hosts[0].name,
|
||||
pool->def->source.dir) < 0)
|
||||
def->source.hosts[0].name,
|
||||
def->source.dir) < 0)
|
||||
return NULL;
|
||||
} else {
|
||||
if (virAsprintf(&src, "%s:%s",
|
||||
pool->def->source.hosts[0].name,
|
||||
pool->def->source.dir) < 0)
|
||||
def->source.hosts[0].name,
|
||||
def->source.dir) < 0)
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0)
|
||||
if (VIR_STRDUP(src, def->source.devices[0].path) < 0)
|
||||
return NULL;
|
||||
}
|
||||
return src;
|
||||
@ -297,6 +300,7 @@ static int
|
||||
virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
|
||||
{
|
||||
int ret = -1;
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
char *src = NULL;
|
||||
FILE *mtab;
|
||||
struct mntent ent;
|
||||
@ -317,8 +321,7 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
|
||||
/* compare both mount destinations and sources to be sure the mounted
|
||||
* FS pool is really the one we're looking for
|
||||
*/
|
||||
if ((rc1 = virFileComparePaths(ent.mnt_dir,
|
||||
pool->def->target.path)) < 0 ||
|
||||
if ((rc1 = virFileComparePaths(ent.mnt_dir, def->target.path)) < 0 ||
|
||||
(rc2 = virFileComparePaths(ent.mnt_fsname, src)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -349,16 +352,17 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
|
||||
static int
|
||||
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
|
||||
{
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
char *src = NULL;
|
||||
/* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
|
||||
* while plain 'mount' does. We have to craft separate argvs to
|
||||
* accommodate this */
|
||||
bool netauto = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
pool->def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
|
||||
bool glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
|
||||
bool cifsfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
pool->def->source.format == VIR_STORAGE_POOL_NETFS_CIFS);
|
||||
bool netauto = (def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
def->source.format == VIR_STORAGE_POOL_NETFS_AUTO);
|
||||
bool glusterfs = (def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);
|
||||
bool cifsfs = (def->type == VIR_STORAGE_POOL_NETFS &&
|
||||
def->source.format == VIR_STORAGE_POOL_NETFS_CIFS);
|
||||
virCommandPtr cmd = NULL;
|
||||
int ret = -1;
|
||||
int rc;
|
||||
@ -371,7 +375,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
|
||||
|
||||
/* Short-circuit if already mounted */
|
||||
if (rc == 1) {
|
||||
VIR_INFO("Target '%s' is already mounted", pool->def->target.path);
|
||||
VIR_INFO("Target '%s' is already mounted", def->target.path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -381,34 +385,34 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
|
||||
if (netauto)
|
||||
cmd = virCommandNewArgList(MOUNT,
|
||||
src,
|
||||
pool->def->target.path,
|
||||
def->target.path,
|
||||
NULL);
|
||||
else if (glusterfs)
|
||||
cmd = virCommandNewArgList(MOUNT,
|
||||
"-t",
|
||||
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
|
||||
virStoragePoolFormatFileSystemNetTypeToString(def->source.format),
|
||||
src,
|
||||
"-o",
|
||||
"direct-io-mode=1",
|
||||
pool->def->target.path,
|
||||
def->target.path,
|
||||
NULL);
|
||||
else if (cifsfs)
|
||||
cmd = virCommandNewArgList(MOUNT,
|
||||
"-t",
|
||||
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),
|
||||
virStoragePoolFormatFileSystemNetTypeToString(def->source.format),
|
||||
src,
|
||||
pool->def->target.path,
|
||||
def->target.path,
|
||||
"-o",
|
||||
"guest",
|
||||
NULL);
|
||||
else
|
||||
cmd = virCommandNewArgList(MOUNT,
|
||||
"-t",
|
||||
(pool->def->type == VIR_STORAGE_POOL_FS ?
|
||||
virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :
|
||||
virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format)),
|
||||
(def->type == VIR_STORAGE_POOL_FS ?
|
||||
virStoragePoolFormatFileSystemTypeToString(def->source.format) :
|
||||
virStoragePoolFormatFileSystemNetTypeToString(def->source.format)),
|
||||
src,
|
||||
pool->def->target.path,
|
||||
def->target.path,
|
||||
NULL);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
@ -435,7 +439,9 @@ static int
|
||||
virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virStoragePoolObjPtr pool)
|
||||
{
|
||||
if (pool->def->type != VIR_STORAGE_POOL_DIR &&
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
|
||||
if (def->type != VIR_STORAGE_POOL_DIR &&
|
||||
virStorageBackendFileSystemMount(pool) < 0)
|
||||
return -1;
|
||||
|
||||
@ -459,6 +465,7 @@ static int
|
||||
virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virStoragePoolObjPtr pool)
|
||||
{
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
virCommandPtr cmd = NULL;
|
||||
int ret = -1;
|
||||
int rc;
|
||||
@ -470,7 +477,7 @@ virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
if ((rc = virStorageBackendFileSystemIsMounted(pool)) != 1)
|
||||
return rc;
|
||||
|
||||
cmd = virCommandNewArgList(UMOUNT, pool->def->target.path, NULL);
|
||||
cmd = virCommandNewArgList(UMOUNT, def->target.path, NULL);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -486,8 +493,10 @@ static int
|
||||
virStorageBackendFileSystemCheck(virStoragePoolObjPtr pool,
|
||||
bool *isActive)
|
||||
{
|
||||
if (pool->def->type == VIR_STORAGE_POOL_DIR) {
|
||||
*isActive = virFileExists(pool->def->target.path);
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
|
||||
if (def->type == VIR_STORAGE_POOL_DIR) {
|
||||
*isActive = virFileExists(def->target.path);
|
||||
#if WITH_STORAGE_FS
|
||||
} else {
|
||||
int ret;
|
||||
@ -561,25 +570,26 @@ static int
|
||||
virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool,
|
||||
unsigned int flags)
|
||||
{
|
||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||
const char *device = NULL, *format = NULL;
|
||||
bool ok_to_mkfs = false;
|
||||
int ret = -1;
|
||||
|
||||
if (pool->def->source.devices == NULL) {
|
||||
if (def->source.devices == NULL) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("No source device specified when formatting pool '%s'"),
|
||||
pool->def->name);
|
||||
def->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
device = pool->def->source.devices[0].path;
|
||||
format = virStoragePoolFormatFileSystemTypeToString(pool->def->source.format);
|
||||
device = def->source.devices[0].path;
|
||||
format = virStoragePoolFormatFileSystemTypeToString(def->source.format);
|
||||
VIR_DEBUG("source device: '%s' format: '%s'", device, format);
|
||||
|
||||
if (!virFileExists(device)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("Source device does not exist when formatting pool '%s'"),
|
||||
pool->def->name);
|
||||
def->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user