2017-03-07 20:18:01 +00:00
|
|
|
/*
|
|
|
|
* virstorageobj.c: internal storage pool and volume objects handling
|
|
|
|
* (derived from storage_conf.c)
|
|
|
|
*
|
|
|
|
* 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, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "node_device_conf.h"
|
2018-09-19 11:34:35 +00:00
|
|
|
#include "node_device_util.h"
|
2017-03-07 20:18:01 +00:00
|
|
|
#include "virstorageobj.h"
|
|
|
|
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virerror.h"
|
|
|
|
#include "virfile.h"
|
2017-10-09 17:34:45 +00:00
|
|
|
#include "virhash.h"
|
2017-03-07 20:18:01 +00:00
|
|
|
#include "virlog.h"
|
|
|
|
#include "virscsihost.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "virvhba.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
|
|
|
VIR_LOG_INIT("conf.virstorageobj");
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
static virClassPtr virStoragePoolObjClass;
|
2017-10-09 17:34:45 +00:00
|
|
|
static virClassPtr virStoragePoolObjListClass;
|
2017-10-10 20:49:04 +00:00
|
|
|
static virClassPtr virStorageVolObjClass;
|
|
|
|
static virClassPtr virStorageVolObjListClass;
|
2017-10-09 10:19:37 +00:00
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
static void
|
2017-10-09 10:19:37 +00:00
|
|
|
virStoragePoolObjDispose(void *opaque);
|
2017-10-09 17:34:45 +00:00
|
|
|
static void
|
|
|
|
virStoragePoolObjListDispose(void *opaque);
|
2017-10-10 20:49:04 +00:00
|
|
|
static void
|
|
|
|
virStorageVolObjDispose(void *opaque);
|
|
|
|
static void
|
|
|
|
virStorageVolObjListDispose(void *opaque);
|
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 20:49:04 +00:00
|
|
|
typedef struct _virStorageVolObj virStorageVolObj;
|
|
|
|
typedef virStorageVolObj *virStorageVolObjPtr;
|
|
|
|
struct _virStorageVolObj {
|
|
|
|
virObjectLockable parent;
|
|
|
|
|
|
|
|
virStorageVolDefPtr voldef;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _virStorageVolObjList virStorageVolObjList;
|
|
|
|
typedef virStorageVolObjList *virStorageVolObjListPtr;
|
|
|
|
struct _virStorageVolObjList {
|
|
|
|
virObjectRWLockable parent;
|
|
|
|
|
|
|
|
/* key string -> virStorageVolObj mapping
|
|
|
|
* for (1), lockless lookup-by-key */
|
|
|
|
virHashTable *objsKey;
|
|
|
|
|
|
|
|
/* name string -> virStorageVolObj mapping
|
|
|
|
* for (1), lockless lookup-by-name */
|
|
|
|
virHashTable *objsName;
|
|
|
|
|
|
|
|
/* path string -> virStorageVolObj mapping
|
|
|
|
* for (1), lockless lookup-by-path */
|
|
|
|
virHashTable *objsPath;
|
|
|
|
};
|
|
|
|
|
2017-07-26 19:13:28 +00:00
|
|
|
struct _virStoragePoolObj {
|
2017-10-09 10:19:37 +00:00
|
|
|
virObjectLockable parent;
|
2017-07-26 19:13:28 +00:00
|
|
|
|
|
|
|
char *configFile;
|
|
|
|
char *autostartLink;
|
|
|
|
bool active;
|
2019-05-24 14:35:46 +00:00
|
|
|
bool starting;
|
2017-07-26 19:13:28 +00:00
|
|
|
bool autostart;
|
|
|
|
unsigned int asyncjobs;
|
|
|
|
|
|
|
|
virStoragePoolDefPtr def;
|
|
|
|
virStoragePoolDefPtr newDef;
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjListPtr volumes;
|
2017-07-26 19:13:28 +00:00
|
|
|
};
|
|
|
|
|
2017-10-07 11:24:24 +00:00
|
|
|
struct _virStoragePoolObjList {
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockable parent;
|
|
|
|
|
|
|
|
/* uuid string -> virStoragePoolObj mapping
|
|
|
|
* for (1), lockless lookup-by-uuid */
|
|
|
|
virHashTable *objs;
|
|
|
|
|
|
|
|
/* name string -> virStoragePoolObj mapping
|
|
|
|
* for (1), lockless lookup-by-name */
|
|
|
|
virHashTable *objsName;
|
2017-10-07 11:24:24 +00:00
|
|
|
};
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
|
2017-10-10 20:49:04 +00:00
|
|
|
static int
|
|
|
|
virStorageVolObjOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virStorageVolObj, virClassForObjectLockable()))
|
2017-10-10 20:49:04 +00:00
|
|
|
return -1;
|
|
|
|
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virStorageVolObjList, virClassForObjectRWLockable()))
|
2017-10-10 20:49:04 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virStorageVolObj);
|
2017-10-10 20:49:04 +00:00
|
|
|
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
static virStorageVolObjPtr
|
2017-10-10 20:49:04 +00:00
|
|
|
virStorageVolObjNew(void)
|
|
|
|
{
|
|
|
|
virStorageVolObjPtr obj;
|
|
|
|
|
|
|
|
if (virStorageVolObjInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(obj = virObjectLockableNew(virStorageVolObjClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
static void
|
2017-10-10 20:49:04 +00:00
|
|
|
virStorageVolObjEndAPI(virStorageVolObjPtr *obj)
|
|
|
|
{
|
|
|
|
if (!*obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virObjectUnlock(*obj);
|
|
|
|
virObjectUnref(*obj);
|
|
|
|
*obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virStorageVolObjDispose(void *opaque)
|
|
|
|
{
|
|
|
|
virStorageVolObjPtr obj = opaque;
|
|
|
|
|
|
|
|
virStorageVolDefFree(obj->voldef);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
static virStorageVolObjListPtr
|
2017-10-10 20:49:04 +00:00
|
|
|
virStorageVolObjListNew(void)
|
|
|
|
{
|
|
|
|
virStorageVolObjListPtr vols;
|
|
|
|
|
|
|
|
if (virStorageVolObjInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(vols = virObjectRWLockableNew(virStorageVolObjListClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(vols->objsKey = virHashCreate(10, virObjectFreeHashData)) ||
|
|
|
|
!(vols->objsName = virHashCreate(10, virObjectFreeHashData)) ||
|
|
|
|
!(vols->objsPath = virHashCreate(10, virObjectFreeHashData))) {
|
|
|
|
virObjectUnref(vols);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vols;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virStorageVolObjListDispose(void *opaque)
|
|
|
|
{
|
|
|
|
virStorageVolObjListPtr vols = opaque;
|
|
|
|
|
|
|
|
virHashFree(vols->objsKey);
|
|
|
|
virHashFree(vols->objsName);
|
|
|
|
virHashFree(vols->objsPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
static int
|
|
|
|
virStoragePoolObjOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virStoragePoolObj, virClassForObjectLockable()))
|
2017-10-09 10:19:37 +00:00
|
|
|
return -1;
|
|
|
|
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virStoragePoolObjList, virClassForObjectRWLockable()))
|
2017-10-09 17:34:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virStoragePoolObj);
|
2017-10-09 10:19:37 +00:00
|
|
|
|
|
|
|
|
2017-05-08 20:02:36 +00:00
|
|
|
virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjNew(void)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
if (virStoragePoolObjInitialize() < 0)
|
2017-05-08 20:02:36 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
if (!(obj = virObjectLockableNew(virStoragePoolObjClass)))
|
2017-05-08 20:02:36 +00:00
|
|
|
return NULL;
|
2017-10-09 10:19:37 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (!(obj->volumes = virStorageVolObjListNew())) {
|
|
|
|
virObjectUnref(obj);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
virObjectLock(obj);
|
2017-08-19 12:25:21 +00:00
|
|
|
obj->active = false;
|
2017-05-08 20:02:36 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 13:09:09 +00:00
|
|
|
void
|
|
|
|
virStoragePoolObjEndAPI(virStoragePoolObjPtr *obj)
|
|
|
|
{
|
|
|
|
if (!*obj)
|
|
|
|
return;
|
|
|
|
|
2017-10-09 10:19:37 +00:00
|
|
|
virObjectUnlock(*obj);
|
|
|
|
virObjectUnref(*obj);
|
|
|
|
*obj = NULL;
|
2017-10-08 13:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-07 11:56:03 +00:00
|
|
|
virStoragePoolDefPtr
|
|
|
|
virStoragePoolObjGetDef(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->def;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjSetDef(virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def)
|
|
|
|
{
|
|
|
|
virStoragePoolDefFree(obj->def);
|
|
|
|
obj->def = def;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStoragePoolDefPtr
|
|
|
|
virStoragePoolObjGetNewDef(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->newDef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjDefUseNewDef(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
virStoragePoolDefFree(obj->def);
|
|
|
|
obj->def = obj->newDef;
|
|
|
|
obj->newDef = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-19 12:55:43 +00:00
|
|
|
const char *
|
2017-05-07 11:56:03 +00:00
|
|
|
virStoragePoolObjGetConfigFile(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->configFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjSetConfigFile(virStoragePoolObjPtr obj,
|
|
|
|
char *configFile)
|
|
|
|
{
|
|
|
|
VIR_FREE(obj->configFile);
|
|
|
|
obj->configFile = configFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-19 12:55:43 +00:00
|
|
|
const char *
|
2017-05-07 11:56:03 +00:00
|
|
|
virStoragePoolObjGetAutostartLink(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->autostartLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virStoragePoolObjIsActive(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjSetActive(virStoragePoolObjPtr obj,
|
|
|
|
bool active)
|
|
|
|
{
|
|
|
|
obj->active = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 14:35:46 +00:00
|
|
|
void
|
|
|
|
virStoragePoolObjSetStarting(virStoragePoolObjPtr obj,
|
|
|
|
bool starting)
|
|
|
|
{
|
|
|
|
obj->starting = starting;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virStoragePoolObjIsStarting(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->starting;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-07 11:56:03 +00:00
|
|
|
bool
|
|
|
|
virStoragePoolObjIsAutostart(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
if (!obj->configFile)
|
|
|
|
return 0;
|
|
|
|
|
2017-08-19 12:16:18 +00:00
|
|
|
return obj->autostart;
|
2017-05-07 11:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj,
|
2017-08-19 12:16:18 +00:00
|
|
|
bool autostart)
|
2017-05-07 11:56:03 +00:00
|
|
|
{
|
|
|
|
obj->autostart = autostart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
return obj->asyncjobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjIncrAsyncjobs(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
obj->asyncjobs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjDecrAsyncjobs(virStoragePoolObjPtr obj)
|
|
|
|
{
|
|
|
|
obj->asyncjobs--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
void
|
2017-10-09 10:19:37 +00:00
|
|
|
virStoragePoolObjDispose(void *opaque)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2017-10-09 10:19:37 +00:00
|
|
|
virStoragePoolObjPtr obj = opaque;
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
virStoragePoolObjClearVols(obj);
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectUnref(obj->volumes);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
virStoragePoolDefFree(obj->def);
|
|
|
|
virStoragePoolDefFree(obj->newDef);
|
|
|
|
|
|
|
|
VIR_FREE(obj->configFile);
|
|
|
|
VIR_FREE(obj->autostartLink);
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
void
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolObjListDispose(void *opaque)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolObjListPtr pools = opaque;
|
|
|
|
|
|
|
|
virHashFree(pools->objs);
|
|
|
|
virHashFree(pools->objsName);
|
2017-10-07 11:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStoragePoolObjListPtr
|
|
|
|
virStoragePoolObjListNew(void)
|
|
|
|
{
|
|
|
|
virStoragePoolObjListPtr pools;
|
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
if (virStoragePoolObjInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(pools = virObjectRWLockableNew(virStoragePoolObjListClass)))
|
2017-10-07 11:24:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
if (!(pools->objs = virHashCreate(20, virObjectFreeHashData)) ||
|
|
|
|
!(pools->objsName = virHashCreate(20, virObjectFreeHashData))) {
|
|
|
|
virObjectUnref(pools);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-07 11:24:24 +00:00
|
|
|
return pools;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
struct _virStoragePoolObjListForEachData {
|
|
|
|
virStoragePoolObjListIterator iter;
|
|
|
|
const void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjListForEachCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-09 17:34:45 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj = payload;
|
|
|
|
struct _virStoragePoolObjListForEachData *data = opaque;
|
|
|
|
|
2019-05-24 14:35:38 +00:00
|
|
|
/* Grab a reference so that we don't rely only on references grabbed by
|
|
|
|
* hash table earlier. Remember, an iterator can remove object from the
|
|
|
|
* hash table. */
|
|
|
|
virObjectRef(obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectLock(obj);
|
|
|
|
data->iter(obj, data->opaque);
|
2019-05-24 14:35:38 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 12:14:56 +00:00
|
|
|
/**
|
|
|
|
* virStoragePoolObjListForEach
|
|
|
|
* @pools: Pointer to pools object
|
|
|
|
* @iter: Callback iteration helper
|
|
|
|
* @opaque: Opaque data to use as argument to helper
|
|
|
|
*
|
|
|
|
* For each object in @pools, call the @iter helper using @opaque as
|
|
|
|
* an argument. This function doesn't care whether the @iter fails or
|
|
|
|
* not as it's being used for Autostart and UpdateAllState callers
|
|
|
|
* that want to iterate over all the @pools objects not stopping if
|
|
|
|
* one happens to fail.
|
2018-05-24 19:38:18 +00:00
|
|
|
*
|
|
|
|
* NB: We cannot take the Storage Pool lock here because it's possible
|
|
|
|
* that some action as part of Autostart or UpdateAllState will need
|
|
|
|
* to modify/destroy a transient pool. Since these paths only occur
|
|
|
|
* during periods in which the storageDriverLock is held (Initialization,
|
|
|
|
* AutoStart, or Reload) this is OK.
|
2017-10-08 12:14:56 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
virStoragePoolObjListForEach(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolObjListIterator iter,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
struct _virStoragePoolObjListForEachData data = { .iter = iter,
|
|
|
|
.opaque = opaque };
|
2017-10-08 12:14:56 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virHashForEach(pools->objs, virStoragePoolObjListForEachCb, &data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct _virStoragePoolObjListSearchData {
|
|
|
|
virStoragePoolObjListSearcher searcher;
|
|
|
|
const void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjListSearchCb(const void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-09 17:34:45 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj = (virStoragePoolObjPtr) payload;
|
|
|
|
struct _virStoragePoolObjListSearchData *data =
|
|
|
|
(struct _virStoragePoolObjListSearchData *)opaque;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
if (data->searcher(obj, data->opaque))
|
|
|
|
return 1;
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
2017-10-08 12:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-08 12:44:31 +00:00
|
|
|
/**
|
|
|
|
* virStoragePoolObjListSearch
|
|
|
|
* @pools: Pointer to pools object
|
|
|
|
* @search: Callback searcher helper
|
|
|
|
* @opaque: Opaque data to use as argument to helper
|
|
|
|
*
|
|
|
|
* Search through the @pools objects calling the @search helper using
|
|
|
|
* the @opaque data in order to find an object that matches some criteria
|
|
|
|
* and return that object locked.
|
|
|
|
*
|
2017-10-09 10:19:37 +00:00
|
|
|
* Returns a locked and reffed object when found and NULL when not found
|
2017-10-08 12:44:31 +00:00
|
|
|
*/
|
|
|
|
virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjListSearch(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolObjListSearcher searcher,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolObjPtr obj = NULL;
|
|
|
|
struct _virStoragePoolObjListSearchData data = { .searcher = searcher,
|
|
|
|
.opaque = opaque };
|
2017-10-08 12:44:31 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockRead(pools);
|
|
|
|
obj = virHashSearch(pools->objs, virStoragePoolObjListSearchCb, &data, NULL);
|
|
|
|
virObjectRWUnlock(pools);
|
2017-10-08 12:44:31 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
return virObjectRef(obj);
|
2017-10-08 12:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
void
|
|
|
|
virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
|
2017-05-05 19:12:59 +00:00
|
|
|
virStoragePoolObjPtr obj)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virUUIDFormat(obj->def->uuid, uuidstr);
|
|
|
|
virObjectRef(obj);
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
virObjectRWLockWrite(pools);
|
|
|
|
virObjectLock(obj);
|
|
|
|
virHashRemoveEntry(pools->objs, uuidstr);
|
|
|
|
virHashRemoveEntry(pools->objsName, obj->def->name);
|
|
|
|
virObjectUnref(obj);
|
|
|
|
virObjectRWUnlock(pools);
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjFindByUUIDLocked(virStoragePoolObjListPtr pools,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
|
|
|
return virObjectRef(virHashLookup(pools->objs, uuidstr));
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
/**
|
|
|
|
* virStoragePoolObjFindByUUID
|
|
|
|
* @pools: Storage pool object list pointer
|
|
|
|
* @uuid: Storage object uuid to find
|
|
|
|
*
|
|
|
|
* Lock the @pools and lookup the object by @uuid
|
|
|
|
*
|
|
|
|
* Returns: Locked and reffed storage pool object or NULL if not found
|
|
|
|
*/
|
2017-03-07 20:18:01 +00:00
|
|
|
virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-10-09 10:19:37 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockRead(pools);
|
|
|
|
obj = virStoragePoolObjFindByUUIDLocked(pools, uuid);
|
|
|
|
virObjectRWUnlock(pools);
|
|
|
|
if (obj)
|
2017-10-09 10:19:37 +00:00
|
|
|
virObjectLock(obj);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjFindByNameLocked(virStoragePoolObjListPtr pools,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
return virObjectRef(virHashLookup(pools->objsName, name));
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
/**
|
|
|
|
* virStoragePoolObjFindByName
|
|
|
|
* @pools: Storage pool object list pointer
|
|
|
|
* @name: Storage object name to find
|
|
|
|
*
|
|
|
|
* Lock the @pools and lookup the object by @name
|
|
|
|
*
|
|
|
|
* Returns: Locked and reffed storage pool object or NULL if not found
|
|
|
|
*/
|
2017-03-07 20:18:01 +00:00
|
|
|
virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
|
|
|
|
const char *name)
|
|
|
|
{
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2017-10-09 10:19:37 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockRead(pools);
|
|
|
|
obj = virStoragePoolObjFindByNameLocked(pools, name);
|
|
|
|
virObjectRWUnlock(pools);
|
|
|
|
if (obj)
|
2017-10-09 10:19:37 +00:00
|
|
|
virObjectLock(obj);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
return obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 21:10:38 +00:00
|
|
|
static virStoragePoolObjPtr
|
2017-05-05 19:12:59 +00:00
|
|
|
virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr obj,
|
2017-03-07 20:18:01 +00:00
|
|
|
virStoragePoolDefPtr def)
|
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
|
2017-05-05 19:12:59 +00:00
|
|
|
for (i = 0; i < obj->def->source.ndevice; i++) {
|
2017-03-07 20:18:01 +00:00
|
|
|
for (j = 0; j < def->source.ndevice; j++) {
|
2017-05-05 19:12:59 +00:00
|
|
|
if (STREQ(obj->def->source.devices[i].path, def->source.devices[j].path))
|
|
|
|
return obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
void
|
2017-05-05 19:12:59 +00:00
|
|
|
virStoragePoolObjClearVols(virStoragePoolObjPtr obj)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2019-05-14 08:31:52 +00:00
|
|
|
if (!obj->volumes)
|
|
|
|
return;
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virHashRemoveAll(obj->volumes->objsKey);
|
|
|
|
virHashRemoveAll(obj->volumes->objsName);
|
|
|
|
virHashRemoveAll(obj->volumes->objsPath);
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-05-09 12:05:16 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjAddVol(virStoragePoolObjPtr obj,
|
|
|
|
virStorageVolDefPtr voldef)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjPtr volobj = NULL;
|
|
|
|
virStorageVolObjListPtr volumes = obj->volumes;
|
|
|
|
|
|
|
|
virObjectRWLockWrite(volumes);
|
|
|
|
|
|
|
|
if (!(volobj = virStorageVolObjNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virHashAddEntry(volumes->objsKey, voldef->key, volobj) < 0)
|
|
|
|
goto error;
|
|
|
|
virObjectRef(volobj);
|
|
|
|
|
|
|
|
if (virHashAddEntry(volumes->objsName, voldef->name, volobj) < 0) {
|
|
|
|
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virObjectRef(volobj);
|
|
|
|
|
|
|
|
if (virHashAddEntry(volumes->objsPath, voldef->target.path, volobj) < 0) {
|
|
|
|
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
|
|
|
virHashRemoveEntry(volumes->objsName, voldef->name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virObjectRef(volobj);
|
|
|
|
|
|
|
|
volobj->voldef = voldef;
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
virStorageVolObjEndAPI(&volobj);
|
2017-05-09 12:05:16 +00:00
|
|
|
return 0;
|
2017-10-10 22:32:40 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
virStorageVolObjEndAPI(&volobj);
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
return -1;
|
2017-05-09 12:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj,
|
|
|
|
virStorageVolDefPtr voldef)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjListPtr volumes = obj->volumes;
|
|
|
|
virStorageVolObjPtr volobj;
|
|
|
|
|
|
|
|
virObjectRWLockWrite(volumes);
|
|
|
|
volobj = virHashLookup(volumes->objsName, voldef->name);
|
|
|
|
if (!volobj) {
|
|
|
|
VIR_INFO("Cannot find volume '%s' from storage pool '%s'",
|
|
|
|
voldef->name, obj->def->name);
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
|
|
|
voldef->name, obj->def->name);
|
2017-05-09 12:05:16 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRef(volobj);
|
|
|
|
virObjectLock(volobj);
|
|
|
|
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
|
|
|
virHashRemoveEntry(volumes->objsName, voldef->name);
|
|
|
|
virHashRemoveEntry(volumes->objsPath, voldef->target.path);
|
|
|
|
virStorageVolObjEndAPI(&volobj);
|
2017-05-09 12:05:16 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWUnlock(volumes);
|
2017-05-09 12:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
size_t nbElems;
|
|
|
|
|
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
nbElems = virHashSize(obj->volumes->objsKey);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
|
|
|
|
|
|
|
return nbElems;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct _virStoragePoolObjForEachVolData {
|
|
|
|
virStorageVolObjListIterator iter;
|
|
|
|
const void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjForEachVolumeCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-10 22:32:40 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
virStorageVolObjPtr volobj = payload;
|
|
|
|
struct _virStoragePoolObjForEachVolData *data = opaque;
|
|
|
|
|
|
|
|
virObjectLock(volobj);
|
|
|
|
if (data->iter(volobj->voldef, data->opaque) < 0)
|
|
|
|
ret = -1;
|
|
|
|
virObjectUnlock(volobj);
|
|
|
|
|
|
|
|
return ret;
|
2017-05-09 12:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-09 12:18:33 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj,
|
|
|
|
virStorageVolObjListIterator iter,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
struct _virStoragePoolObjForEachVolData data = {
|
|
|
|
.iter = iter, .opaque = opaque };
|
2017-05-09 12:18:33 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
virHashForEach(obj->volumes->objsKey, virStoragePoolObjForEachVolumeCb,
|
|
|
|
&data);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
2017-05-09 12:18:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
struct _virStoragePoolObjSearchVolData {
|
|
|
|
virStorageVolObjListSearcher iter;
|
|
|
|
const void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjSearchVolumeCb(const void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-10 22:32:40 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
|
|
|
virStorageVolObjPtr volobj = (virStorageVolObjPtr) payload;
|
|
|
|
struct _virStoragePoolObjSearchVolData *data =
|
|
|
|
(struct _virStoragePoolObjSearchVolData *) opaque;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
virObjectLock(volobj);
|
|
|
|
if (data->iter(volobj->voldef, data->opaque))
|
|
|
|
found = 1;
|
|
|
|
virObjectUnlock(volobj);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-09 12:18:33 +00:00
|
|
|
virStorageVolDefPtr
|
|
|
|
virStoragePoolObjSearchVolume(virStoragePoolObjPtr obj,
|
|
|
|
virStorageVolObjListSearcher iter,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjPtr volobj;
|
|
|
|
struct _virStoragePoolObjSearchVolData data = {
|
|
|
|
.iter = iter, .opaque = opaque };
|
2017-05-09 12:18:33 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
volobj = virHashSearch(obj->volumes->objsKey,
|
|
|
|
virStoragePoolObjSearchVolumeCb,
|
|
|
|
&data, NULL);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
|
|
|
|
|
|
|
if (volobj)
|
|
|
|
return volobj->voldef;
|
2017-05-09 12:18:33 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
virStorageVolDefPtr
|
2017-05-05 19:12:59 +00:00
|
|
|
virStorageVolDefFindByKey(virStoragePoolObjPtr obj,
|
2017-03-07 20:18:01 +00:00
|
|
|
const char *key)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjPtr volobj;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
volobj = virHashLookup(obj->volumes->objsKey, key);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (volobj)
|
|
|
|
return volobj->voldef;
|
2017-03-07 20:18:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
virStorageVolDefPtr
|
2017-05-05 19:12:59 +00:00
|
|
|
virStorageVolDefFindByPath(virStoragePoolObjPtr obj,
|
2017-03-07 20:18:01 +00:00
|
|
|
const char *path)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjPtr volobj;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
volobj = virHashLookup(obj->volumes->objsPath, path);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (volobj)
|
|
|
|
return volobj->voldef;
|
2017-03-07 20:18:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
virStorageVolDefPtr
|
2017-05-05 19:12:59 +00:00
|
|
|
virStorageVolDefFindByName(virStoragePoolObjPtr obj,
|
2017-03-07 20:18:01 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjPtr volobj;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(obj->volumes);
|
|
|
|
volobj = virHashLookup(obj->volumes->objsName, name);
|
|
|
|
virObjectRWUnlock(obj->volumes);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (volobj)
|
|
|
|
return volobj->voldef;
|
2017-03-07 20:18:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
struct _virStorageVolObjCountData {
|
|
|
|
virConnectPtr conn;
|
|
|
|
virStoragePoolVolumeACLFilter filter;
|
|
|
|
virStoragePoolDefPtr pooldef;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjNumOfVolumesCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-10 22:32:40 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virStorageVolObjPtr volobj = payload;
|
|
|
|
struct _virStorageVolObjCountData *data = opaque;
|
|
|
|
|
|
|
|
virObjectLock(volobj);
|
|
|
|
|
|
|
|
if (data->filter &&
|
|
|
|
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(volobj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-20 14:13:27 +00:00
|
|
|
int
|
2017-05-09 11:00:41 +00:00
|
|
|
virStoragePoolObjNumOfVolumes(virStoragePoolObjPtr obj,
|
2017-03-20 14:13:27 +00:00
|
|
|
virConnectPtr conn,
|
2017-08-16 13:26:59 +00:00
|
|
|
virStoragePoolVolumeACLFilter filter)
|
2017-03-20 14:13:27 +00:00
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjListPtr volumes = obj->volumes;
|
|
|
|
struct _virStorageVolObjCountData data = {
|
|
|
|
.conn = conn, .filter = filter, .pooldef = obj->def, .count = 0 };
|
|
|
|
|
|
|
|
virObjectRWLockRead(volumes);
|
|
|
|
virHashForEach(volumes->objsName, virStoragePoolObjNumOfVolumesCb, &data);
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
|
|
|
|
return data.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct _virStorageVolObjNameData {
|
|
|
|
virConnectPtr conn;
|
|
|
|
virStoragePoolVolumeACLFilter filter;
|
|
|
|
virStoragePoolDefPtr pooldef;
|
|
|
|
bool error;
|
|
|
|
int nnames;
|
|
|
|
int maxnames;
|
|
|
|
char **const names;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStoragePoolObjVolumeGetNamesCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2017-10-10 22:32:40 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virStorageVolObjPtr volobj = payload;
|
|
|
|
struct _virStorageVolObjNameData *data = opaque;
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
virObjectLock(volobj);
|
|
|
|
|
|
|
|
if (data->filter &&
|
|
|
|
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
|
|
goto cleanup;
|
2017-03-20 14:13:27 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (data->names) {
|
|
|
|
if (VIR_STRDUP(data->names[data->nnames], volobj->voldef->name) < 0) {
|
|
|
|
data->error = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-03-20 14:13:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
data->nnames++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(volobj);
|
|
|
|
return 0;
|
2017-03-20 14:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-20 16:16:26 +00:00
|
|
|
int
|
2017-05-09 11:00:41 +00:00
|
|
|
virStoragePoolObjVolumeGetNames(virStoragePoolObjPtr obj,
|
2017-03-20 16:16:26 +00:00
|
|
|
virConnectPtr conn,
|
2017-08-16 13:26:59 +00:00
|
|
|
virStoragePoolVolumeACLFilter filter,
|
2017-03-20 16:16:26 +00:00
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjListPtr volumes = obj->volumes;
|
|
|
|
struct _virStorageVolObjNameData data = {
|
|
|
|
.conn = conn, .filter = filter, .pooldef = obj->def, .error = false,
|
|
|
|
.nnames = 0, .maxnames = maxnames, .names = names };
|
2017-03-20 16:16:26 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWLockRead(volumes);
|
|
|
|
virHashForEach(volumes->objsName, virStoragePoolObjVolumeGetNamesCb, &data);
|
|
|
|
virObjectRWUnlock(volumes);
|
2017-03-20 16:16:26 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (data.error)
|
|
|
|
goto error;
|
2017-03-20 16:16:26 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
return data.nnames;
|
|
|
|
|
|
|
|
error:
|
|
|
|
while (--data.nnames)
|
|
|
|
VIR_FREE(data.names[data.nnames]);
|
2017-03-20 16:16:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-13 15:55:14 +00:00
|
|
|
typedef struct _virStoragePoolObjVolumeListExportData virStoragePoolObjVolumeListExportData;
|
|
|
|
typedef virStoragePoolObjVolumeListExportData *virStoragePoolObjVolumeListExportDataPtr;
|
|
|
|
struct _virStoragePoolObjVolumeListExportData {
|
2017-10-10 22:32:40 +00:00
|
|
|
virConnectPtr conn;
|
|
|
|
virStoragePoolVolumeACLFilter filter;
|
|
|
|
virStoragePoolDefPtr pooldef;
|
|
|
|
bool error;
|
|
|
|
int nvols;
|
|
|
|
virStorageVolPtr *vols;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2018-08-13 15:55:15 +00:00
|
|
|
virStoragePoolObjVolumeListExportCallback(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2018-08-13 15:55:15 +00:00
|
|
|
void *opaque)
|
2017-10-10 22:32:40 +00:00
|
|
|
{
|
|
|
|
virStorageVolObjPtr volobj = payload;
|
2018-08-13 15:55:14 +00:00
|
|
|
virStoragePoolObjVolumeListExportDataPtr data = opaque;
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolPtr vol = NULL;
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
virObjectLock(volobj);
|
|
|
|
|
|
|
|
if (data->filter &&
|
|
|
|
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (data->vols) {
|
|
|
|
if (!(vol = virGetStorageVol(data->conn, data->pooldef->name,
|
|
|
|
volobj->voldef->name, volobj->voldef->key,
|
|
|
|
NULL, NULL))) {
|
|
|
|
data->error = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
data->vols[data->nvols] = vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->nvols++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(volobj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-20 17:48:47 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjVolumeListExport(virConnectPtr conn,
|
2017-05-09 11:00:41 +00:00
|
|
|
virStoragePoolObjPtr obj,
|
2017-03-20 17:48:47 +00:00
|
|
|
virStorageVolPtr **vols,
|
2017-08-16 13:26:59 +00:00
|
|
|
virStoragePoolVolumeACLFilter filter)
|
2017-03-20 17:48:47 +00:00
|
|
|
{
|
2017-10-10 22:32:40 +00:00
|
|
|
virStorageVolObjListPtr volumes = obj->volumes;
|
2018-08-13 15:55:14 +00:00
|
|
|
virStoragePoolObjVolumeListExportData data = {
|
2017-10-10 22:32:40 +00:00
|
|
|
.conn = conn, .filter = filter, .pooldef = obj->def, .error = false,
|
|
|
|
.nvols = 0, .vols = NULL };
|
|
|
|
|
|
|
|
virObjectRWLockRead(volumes);
|
2017-03-20 17:48:47 +00:00
|
|
|
|
|
|
|
if (!vols) {
|
2017-10-10 22:32:40 +00:00
|
|
|
int ret = virHashSize(volumes->objsName);
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
return ret;
|
2017-03-20 17:48:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (VIR_ALLOC_N(data.vols, virHashSize(volumes->objsName) + 1) < 0) {
|
|
|
|
virObjectRWUnlock(volumes);
|
|
|
|
return -1;
|
2017-03-20 17:48:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 15:55:15 +00:00
|
|
|
virHashForEach(volumes->objsName, virStoragePoolObjVolumeListExportCallback, &data);
|
2017-10-10 22:32:40 +00:00
|
|
|
virObjectRWUnlock(volumes);
|
2017-03-20 17:48:47 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
if (data.error)
|
|
|
|
goto error;
|
2017-03-20 17:48:47 +00:00
|
|
|
|
2017-10-10 22:32:40 +00:00
|
|
|
*vols = data.vols;
|
|
|
|
|
|
|
|
return data.nvols;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectListFree(data.vols);
|
|
|
|
return -1;
|
2017-03-20 17:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 10:14:41 +00:00
|
|
|
/*
|
|
|
|
* virStoragePoolObjIsDuplicate:
|
|
|
|
* @doms : virStoragePoolObjListPtr to search
|
|
|
|
* @def : virStoragePoolDefPtr definition of pool to lookup
|
|
|
|
* @check_active: If true, ensure that pool is not active
|
2018-08-17 10:30:08 +00:00
|
|
|
* @objRet: returned pool object
|
2018-08-17 10:14:41 +00:00
|
|
|
*
|
2018-08-17 10:30:08 +00:00
|
|
|
* Assumes @pools is locked by caller already.
|
|
|
|
*
|
|
|
|
* Returns: -1 on error (name/uuid mismatch or check_active failure)
|
2018-08-17 10:14:41 +00:00
|
|
|
* 0 if pool is new
|
2018-08-17 10:30:08 +00:00
|
|
|
* 1 if pool is a duplicate (name and UUID match)
|
2018-08-17 10:14:41 +00:00
|
|
|
*/
|
2018-08-17 10:30:08 +00:00
|
|
|
static int
|
2018-08-17 10:14:41 +00:00
|
|
|
virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolDefPtr def,
|
2018-08-17 10:30:08 +00:00
|
|
|
bool check_active,
|
|
|
|
virStoragePoolObjPtr *objRet)
|
2018-08-17 10:14:41 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virStoragePoolObjPtr obj = NULL;
|
|
|
|
|
|
|
|
/* See if a Pool with matching UUID already exists */
|
2018-08-17 10:30:08 +00:00
|
|
|
obj = virStoragePoolObjFindByUUIDLocked(pools, def->uuid);
|
2018-08-17 10:14:41 +00:00
|
|
|
if (obj) {
|
2018-08-17 10:30:08 +00:00
|
|
|
virObjectLock(obj);
|
|
|
|
|
2018-08-17 10:14:41 +00:00
|
|
|
/* UUID matches, but if names don't match, refuse it */
|
|
|
|
if (STRNEQ(obj->def->name, def->name)) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(obj->def->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("pool '%s' is already defined with uuid %s"),
|
|
|
|
obj->def->name, uuidstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_active) {
|
|
|
|
/* UUID & name match, but if Pool is already active, refuse it */
|
|
|
|
if (virStoragePoolObjIsActive(obj)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("pool is already active as '%s'"),
|
|
|
|
obj->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-05-24 14:35:46 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsStarting(obj)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("pool '%s' is starting up"),
|
|
|
|
obj->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-08-17 10:14:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 10:30:08 +00:00
|
|
|
VIR_STEAL_PTR(*objRet, obj);
|
2018-08-17 10:14:41 +00:00
|
|
|
ret = 1;
|
|
|
|
} else {
|
|
|
|
/* UUID does not match, but if a name matches, refuse it */
|
2018-08-17 10:30:08 +00:00
|
|
|
obj = virStoragePoolObjFindByNameLocked(pools, def->name);
|
2018-08-17 10:14:41 +00:00
|
|
|
if (obj) {
|
2018-08-17 10:30:08 +00:00
|
|
|
virObjectLock(obj);
|
|
|
|
|
2018-08-17 10:14:41 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(obj->def->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("pool '%s' already exists with uuid %s"),
|
|
|
|
def->name, uuidstr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virStoragePoolObjEndAPI(&obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static int
|
|
|
|
getSCSIHostNumber(virStorageAdapterSCSIHostPtr scsi_host,
|
|
|
|
unsigned int *hostnum)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
int ret = -1;
|
|
|
|
unsigned int num;
|
|
|
|
char *name = NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (scsi_host->has_parent) {
|
|
|
|
virPCIDeviceAddressPtr addr = &scsi_host->parentaddr;
|
|
|
|
unsigned int unique_id = scsi_host->unique_id;
|
2018-08-17 10:30:08 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(name = virSCSIHostGetNameByParentaddr(addr->domain,
|
|
|
|
addr->bus,
|
|
|
|
addr->slot,
|
|
|
|
addr->function,
|
|
|
|
unique_id)))
|
|
|
|
goto cleanup;
|
|
|
|
if (virSCSIHostGetNumber(name, &num) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virSCSIHostGetNumber(scsi_host->name, &num) < 0)
|
|
|
|
goto cleanup;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
*hostnum = num;
|
|
|
|
ret = 0;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(name);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static bool
|
|
|
|
virStorageIsSameHostnum(const char *name,
|
|
|
|
unsigned int scsi_hostnum)
|
|
|
|
{
|
|
|
|
unsigned int fc_hostnum;
|
|
|
|
|
|
|
|
if (virSCSIHostGetNumber(name, &fc_hostnum) == 0 &&
|
|
|
|
scsi_hostnum == fc_hostnum)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/*
|
|
|
|
* matchFCHostToSCSIHost:
|
|
|
|
*
|
|
|
|
* @fchost: fc_host adapter ptr (either def or pool->def)
|
|
|
|
* @scsi_hostnum: Already determined "scsi_pool" hostnum
|
|
|
|
*
|
|
|
|
* Returns true/false whether there is a match between the incoming
|
|
|
|
* fc_adapter host# and the scsi_host host#
|
|
|
|
*/
|
|
|
|
static bool
|
2018-08-17 13:14:31 +00:00
|
|
|
matchFCHostToSCSIHost(virStorageAdapterFCHostPtr fchost,
|
2018-08-17 12:50:59 +00:00
|
|
|
unsigned int scsi_hostnum)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 13:14:31 +00:00
|
|
|
virConnectPtr conn = NULL;
|
2018-08-17 12:50:59 +00:00
|
|
|
bool ret = false;
|
|
|
|
char *name = NULL;
|
|
|
|
char *scsi_host_name = NULL;
|
|
|
|
char *parent_name = NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* If we have a parent defined, get its hostnum, and compare to the
|
|
|
|
* scsi_hostnum. If they are the same, then we have a match
|
|
|
|
*/
|
|
|
|
if (fchost->parent &&
|
|
|
|
virStorageIsSameHostnum(fchost->parent, scsi_hostnum))
|
|
|
|
return true;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* If we find an fc adapter name, then either libvirt created a vHBA
|
|
|
|
* for this fc_host or a 'virsh nodedev-create' generated a vHBA.
|
|
|
|
*/
|
|
|
|
if ((name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* Get the scsi_hostN for the vHBA in order to see if it
|
|
|
|
* matches our scsi_hostnum
|
|
|
|
*/
|
|
|
|
if (virStorageIsSameHostnum(name, scsi_hostnum)) {
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* We weren't provided a parent, so we have to query the node
|
|
|
|
* device driver in order to ascertain the parent of the vHBA.
|
|
|
|
* If the parent fc_hostnum is the same as the scsi_hostnum, we
|
|
|
|
* have a match.
|
|
|
|
*/
|
2018-08-17 13:14:31 +00:00
|
|
|
if (!fchost->parent &&
|
|
|
|
(conn = virGetConnectNodeDev())) {
|
2018-08-17 12:50:59 +00:00
|
|
|
if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if ((parent_name = virNodeDeviceGetParentName(conn,
|
|
|
|
scsi_host_name))) {
|
|
|
|
if (virStorageIsSameHostnum(parent_name, scsi_hostnum)) {
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Throw away the error and fall through */
|
|
|
|
virResetLastError();
|
|
|
|
VIR_DEBUG("Could not determine parent vHBA");
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* NB: Lack of a name means that this vHBA hasn't yet been created,
|
|
|
|
* which means our scsi_host cannot be using the vHBA. Furthermore,
|
|
|
|
* lack of a provided parent means libvirt is going to choose the
|
2018-12-04 17:08:14 +00:00
|
|
|
* "best" fc_host capable adapter based on availability. That could
|
2018-08-17 12:50:59 +00:00
|
|
|
* conflict with an existing scsi_host definition, but there's no
|
|
|
|
* way to know that now.
|
|
|
|
*/
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(name);
|
|
|
|
VIR_FREE(parent_name);
|
|
|
|
VIR_FREE(scsi_host_name);
|
2018-08-17 13:14:31 +00:00
|
|
|
virConnectClose(conn);
|
2018-08-17 12:50:59 +00:00
|
|
|
return ret;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static bool
|
|
|
|
matchSCSIAdapterParent(virStorageAdapterSCSIHostPtr pool_scsi_host,
|
|
|
|
virStorageAdapterSCSIHostPtr def_scsi_host)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
virPCIDeviceAddressPtr pooladdr = &pool_scsi_host->parentaddr;
|
|
|
|
virPCIDeviceAddressPtr defaddr = &def_scsi_host->parentaddr;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (pooladdr->domain == defaddr->domain &&
|
|
|
|
pooladdr->bus == defaddr->bus &&
|
|
|
|
pooladdr->slot == defaddr->slot &&
|
|
|
|
pooladdr->function == defaddr->function &&
|
|
|
|
pool_scsi_host->unique_id == def_scsi_host->unique_id)
|
|
|
|
return true;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static bool
|
|
|
|
virStoragePoolSourceMatchSingleHost(virStoragePoolSourcePtr poolsrc,
|
|
|
|
virStoragePoolSourcePtr defsrc)
|
|
|
|
{
|
|
|
|
if (poolsrc->nhost != 1 && defsrc->nhost != 1)
|
|
|
|
return false;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (defsrc->hosts[0].port &&
|
|
|
|
poolsrc->hosts[0].port != defsrc->hosts[0].port)
|
|
|
|
return false;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return STREQ(poolsrc->hosts[0].name, defsrc->hosts[0].name);
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static bool
|
|
|
|
virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def)
|
|
|
|
{
|
|
|
|
virStoragePoolSourcePtr poolsrc = &obj->def->source;
|
|
|
|
virStoragePoolSourcePtr defsrc = &def->source;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* NB: Do not check the source host name */
|
|
|
|
if (STRNEQ_NULLABLE(poolsrc->initiator.iqn, defsrc->initiator.iqn))
|
|
|
|
return false;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return true;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjSourceMatchTypeDIR(virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
if (obj->def->type == VIR_STORAGE_POOL_DIR) {
|
|
|
|
if (STREQ(obj->def->target.path, def->target.path))
|
|
|
|
return obj;
|
|
|
|
} else if (obj->def->type == VIR_STORAGE_POOL_GLUSTER) {
|
|
|
|
if (STREQ(obj->def->source.name, def->source.name) &&
|
|
|
|
STREQ_NULLABLE(obj->def->source.dir, def->source.dir) &&
|
|
|
|
virStoragePoolSourceMatchSingleHost(&obj->def->source,
|
|
|
|
&def->source))
|
|
|
|
return obj;
|
|
|
|
} else if (obj->def->type == VIR_STORAGE_POOL_NETFS) {
|
|
|
|
if (STREQ(obj->def->source.dir, def->source.dir) &&
|
|
|
|
virStoragePoolSourceMatchSingleHost(&obj->def->source,
|
|
|
|
&def->source))
|
|
|
|
return obj;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr obj,
|
2018-08-17 13:14:31 +00:00
|
|
|
virStoragePoolDefPtr def)
|
2018-08-17 12:50:59 +00:00
|
|
|
{
|
|
|
|
virStorageAdapterPtr pool_adapter = &obj->def->source.adapter;
|
|
|
|
virStorageAdapterPtr def_adapter = &def->source.adapter;
|
|
|
|
virStorageAdapterSCSIHostPtr pool_scsi_host;
|
|
|
|
virStorageAdapterSCSIHostPtr def_scsi_host;
|
|
|
|
virStorageAdapterFCHostPtr pool_fchost;
|
|
|
|
virStorageAdapterFCHostPtr def_fchost;
|
|
|
|
unsigned int pool_hostnum;
|
|
|
|
unsigned int def_hostnum;
|
|
|
|
unsigned int scsi_hostnum;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST &&
|
|
|
|
def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
|
|
|
pool_fchost = &pool_adapter->data.fchost;
|
|
|
|
def_fchost = &def_adapter->data.fchost;
|
|
|
|
|
|
|
|
if (STREQ(pool_fchost->wwnn, def_fchost->wwnn) &&
|
|
|
|
STREQ(pool_fchost->wwpn, def_fchost->wwpn))
|
|
|
|
return obj;
|
|
|
|
} else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST &&
|
|
|
|
def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) {
|
|
|
|
pool_scsi_host = &pool_adapter->data.scsi_host;
|
|
|
|
def_scsi_host = &def_adapter->data.scsi_host;
|
|
|
|
|
|
|
|
if (pool_scsi_host->has_parent &&
|
|
|
|
def_scsi_host->has_parent &&
|
|
|
|
matchSCSIAdapterParent(pool_scsi_host, def_scsi_host))
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
if (getSCSIHostNumber(pool_scsi_host, &pool_hostnum) < 0 ||
|
|
|
|
getSCSIHostNumber(def_scsi_host, &def_hostnum) < 0)
|
|
|
|
return NULL;
|
|
|
|
if (pool_hostnum == def_hostnum)
|
|
|
|
return obj;
|
|
|
|
} else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST &&
|
|
|
|
def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) {
|
|
|
|
pool_fchost = &pool_adapter->data.fchost;
|
|
|
|
def_scsi_host = &def_adapter->data.scsi_host;
|
|
|
|
|
|
|
|
/* Get the scsi_hostN for the scsi_host source adapter def */
|
|
|
|
if (getSCSIHostNumber(def_scsi_host, &scsi_hostnum) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2018-08-17 13:14:31 +00:00
|
|
|
if (matchFCHostToSCSIHost(pool_fchost, scsi_hostnum))
|
2018-08-17 12:50:59 +00:00
|
|
|
return obj;
|
|
|
|
|
|
|
|
} else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST &&
|
|
|
|
def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
|
|
|
pool_scsi_host = &pool_adapter->data.scsi_host;
|
|
|
|
def_fchost = &def_adapter->data.fchost;
|
|
|
|
|
|
|
|
if (getSCSIHostNumber(pool_scsi_host, &scsi_hostnum) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2018-08-17 13:14:31 +00:00
|
|
|
if (matchFCHostToSCSIHost(def_fchost, scsi_hostnum))
|
2018-08-17 12:50:59 +00:00
|
|
|
return obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjSourceMatchTypeDEVICE(virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjPtr matchobj = NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (obj->def->type == VIR_STORAGE_POOL_ISCSI) {
|
|
|
|
if (def->type != VIR_STORAGE_POOL_ISCSI)
|
|
|
|
return NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if ((matchobj = virStoragePoolSourceFindDuplicateDevices(obj, def))) {
|
|
|
|
if (!virStoragePoolSourceISCSIMatch(matchobj, def))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return matchobj;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (def->type == VIR_STORAGE_POOL_ISCSI)
|
|
|
|
return NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* VIR_STORAGE_POOL_FS
|
|
|
|
* VIR_STORAGE_POOL_LOGICAL
|
|
|
|
* VIR_STORAGE_POOL_DISK
|
|
|
|
* VIR_STORAGE_POOL_ZFS */
|
|
|
|
return virStoragePoolSourceFindDuplicateDevices(obj, def);
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
struct _virStoragePoolObjFindDuplicateData {
|
|
|
|
virStoragePoolDefPtr def;
|
|
|
|
};
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static int
|
|
|
|
virStoragePoolObjSourceFindDuplicateCb(const void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2018-08-17 12:50:59 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj = (virStoragePoolObjPtr) payload;
|
|
|
|
struct _virStoragePoolObjFindDuplicateData *data =
|
|
|
|
(struct _virStoragePoolObjFindDuplicateData *) opaque;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* Don't match against ourself if re-defining existing pool ! */
|
|
|
|
if (STREQ(obj->def->name, data->def->name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch ((virStoragePoolType)obj->def->type) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_GLUSTER:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
if (data->def->type == obj->def->type &&
|
|
|
|
virStoragePoolObjSourceMatchTypeDIR(obj, data->def))
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
if (data->def->type == obj->def->type &&
|
2018-08-17 13:14:31 +00:00
|
|
|
virStoragePoolObjSourceMatchTypeISCSI(obj, data->def))
|
2018-08-17 12:50:59 +00:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
case VIR_STORAGE_POOL_ISCSI_DIRECT:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
case VIR_STORAGE_POOL_ZFS:
|
|
|
|
if ((data->def->type == VIR_STORAGE_POOL_ISCSI ||
|
|
|
|
data->def->type == VIR_STORAGE_POOL_ISCSI_DIRECT ||
|
|
|
|
data->def->type == VIR_STORAGE_POOL_FS ||
|
|
|
|
data->def->type == VIR_STORAGE_POOL_LOGICAL ||
|
|
|
|
data->def->type == VIR_STORAGE_POOL_DISK ||
|
|
|
|
data->def->type == VIR_STORAGE_POOL_ZFS) &&
|
|
|
|
virStoragePoolObjSourceMatchTypeDEVICE(obj, data->def))
|
|
|
|
return 1;
|
|
|
|
break;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
case VIR_STORAGE_POOL_SHEEPDOG:
|
|
|
|
if (data->def->type == obj->def->type &&
|
|
|
|
virStoragePoolSourceMatchSingleHost(&obj->def->source,
|
|
|
|
&data->def->source))
|
|
|
|
return 1;
|
|
|
|
break;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
case VIR_STORAGE_POOL_MPATH:
|
|
|
|
/* Only one mpath pool is valid per host */
|
|
|
|
if (data->def->type == obj->def->type)
|
|
|
|
return 1;
|
|
|
|
break;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
case VIR_STORAGE_POOL_VSTORAGE:
|
|
|
|
if (data->def->type == obj->def->type &&
|
|
|
|
STREQ(obj->def->source.name, data->def->source.name))
|
|
|
|
return 1;
|
|
|
|
break;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
case VIR_STORAGE_POOL_RBD:
|
|
|
|
case VIR_STORAGE_POOL_LAST:
|
|
|
|
break;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return 0;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2018-08-17 13:07:01 +00:00
|
|
|
static int
|
2018-08-17 13:14:31 +00:00
|
|
|
virStoragePoolObjSourceFindDuplicate(virStoragePoolObjListPtr pools,
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolDefPtr def)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 13:14:31 +00:00
|
|
|
struct _virStoragePoolObjFindDuplicateData data = {.def = def};
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjPtr obj = NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
obj = virHashSearch(pools->objs, virStoragePoolObjSourceFindDuplicateCb,
|
|
|
|
&data, NULL);
|
|
|
|
|
|
|
|
if (obj) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Storage source conflict with pool: '%s'"),
|
2017-05-05 19:12:59 +00:00
|
|
|
obj->def->name);
|
2017-03-07 20:18:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 14:35:43 +00:00
|
|
|
static void
|
|
|
|
virStoragePoolObjAssignDef(virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def,
|
2019-05-24 14:35:44 +00:00
|
|
|
unsigned int flags)
|
2019-05-24 14:35:43 +00:00
|
|
|
{
|
2019-05-24 14:35:46 +00:00
|
|
|
if (virStoragePoolObjIsActive(obj) ||
|
|
|
|
virStoragePoolObjIsStarting(obj)) {
|
2019-05-24 14:35:43 +00:00
|
|
|
virStoragePoolDefFree(obj->newDef);
|
|
|
|
obj->newDef = def;
|
2019-05-24 14:35:44 +00:00
|
|
|
} else {
|
|
|
|
if (!obj->newDef &&
|
|
|
|
flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE)
|
|
|
|
VIR_STEAL_PTR(obj->newDef, obj->def);
|
|
|
|
|
|
|
|
virStoragePoolDefFree(obj->def);
|
|
|
|
obj->def = def;
|
2019-05-24 14:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/**
|
2019-05-24 14:35:41 +00:00
|
|
|
* virStoragePoolObjListAdd:
|
2018-08-17 12:50:59 +00:00
|
|
|
* @pools: Storage Pool object list pointer
|
|
|
|
* @def: Storage pool definition to add or update
|
2019-05-24 14:35:42 +00:00
|
|
|
* @flags: bitwise-OR of VIR_STORAGE_POOL_OBJ_LIST_* flags
|
2018-08-17 12:50:59 +00:00
|
|
|
*
|
|
|
|
* Lookup the @def to see if it already exists in the @pools in order
|
|
|
|
* to either update or add if it does not exist.
|
|
|
|
*
|
2019-05-24 14:35:44 +00:00
|
|
|
* Use VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE to denote that @def
|
|
|
|
* refers to an active definition and thus any possible inactive
|
|
|
|
* definition found should be saved to ->newDef (in case of
|
|
|
|
* future restore).
|
|
|
|
*
|
2019-05-24 14:35:42 +00:00
|
|
|
* If VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE is set in @flags
|
|
|
|
* then this will fail if the pool exists and is active.
|
|
|
|
*
|
2018-08-17 12:50:59 +00:00
|
|
|
* Returns locked and reffed object pointer or NULL on error
|
|
|
|
*/
|
|
|
|
virStoragePoolObjPtr
|
2019-05-24 14:35:41 +00:00
|
|
|
virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
|
|
|
|
virStoragePoolDefPtr def,
|
2019-05-24 14:35:42 +00:00
|
|
|
unsigned int flags)
|
2017-10-09 17:34:45 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjPtr obj = NULL;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
int rc;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
virObjectRWLockWrite(pools);
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 13:07:01 +00:00
|
|
|
if (virStoragePoolObjSourceFindDuplicate(pools, def) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2019-05-24 14:35:42 +00:00
|
|
|
rc = virStoragePoolObjIsDuplicate(pools, def,
|
|
|
|
!!(flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE),
|
|
|
|
&obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (rc < 0)
|
|
|
|
goto error;
|
|
|
|
if (rc > 0) {
|
2019-05-24 14:35:43 +00:00
|
|
|
virStoragePoolObjAssignDef(obj, def, flags);
|
2018-08-17 12:50:59 +00:00
|
|
|
virObjectRWUnlock(pools);
|
|
|
|
return obj;
|
|
|
|
}
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(obj = virStoragePoolObjNew()))
|
|
|
|
goto error;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
virUUIDFormat(def->uuid, uuidstr);
|
|
|
|
if (virHashAddEntry(pools->objs, uuidstr, obj) < 0)
|
|
|
|
goto error;
|
|
|
|
virObjectRef(obj);
|
2017-03-21 10:30:46 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (virHashAddEntry(pools->objsName, def->name, obj) < 0) {
|
|
|
|
virHashRemoveEntry(pools->objs, uuidstr);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virObjectRef(obj);
|
|
|
|
obj->def = def;
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWUnlock(pools);
|
2018-08-17 12:50:59 +00:00
|
|
|
return obj;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
error:
|
|
|
|
virStoragePoolObjEndAPI(&obj);
|
|
|
|
virObjectRWUnlock(pools);
|
|
|
|
return NULL;
|
2017-10-09 17:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
|
|
|
|
const char *file,
|
|
|
|
const char *path,
|
|
|
|
const char *autostartLink)
|
2017-10-09 17:34:45 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virStoragePoolDef) def = NULL;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(def = virStoragePoolDefParseFile(path)))
|
|
|
|
return NULL;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2019-03-06 14:45:15 +00:00
|
|
|
if (!virStringMatchesNameSuffix(file, def->name, ".xml")) {
|
2018-08-17 12:50:59 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Storage pool config filename '%s' does "
|
|
|
|
"not match pool name '%s'"),
|
|
|
|
path, def->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2019-05-24 14:35:42 +00:00
|
|
|
if (!(obj = virStoragePoolObjListAdd(pools, def, 0)))
|
2018-08-17 12:50:59 +00:00
|
|
|
return NULL;
|
2019-01-31 15:21:47 +00:00
|
|
|
def = NULL;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
VIR_FREE(obj->configFile); /* for driver reload */
|
|
|
|
if (VIR_STRDUP(obj->configFile, path) < 0) {
|
|
|
|
virStoragePoolObjRemove(pools, obj);
|
2019-05-24 14:35:37 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2018-08-17 12:50:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
VIR_FREE(obj->autostartLink); /* for driver reload */
|
|
|
|
if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0) {
|
|
|
|
virStoragePoolObjRemove(pools, obj);
|
2019-05-24 14:35:37 +00:00
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2018-08-17 12:50:59 +00:00
|
|
|
return NULL;
|
2017-03-21 10:30:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
obj->autostart = virFileLinkPointsTo(obj->autostartLink,
|
|
|
|
obj->configFile);
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return obj;
|
2017-03-21 10:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static virStoragePoolObjPtr
|
|
|
|
virStoragePoolObjLoadState(virStoragePoolObjListPtr pools,
|
|
|
|
const char *stateDir,
|
|
|
|
const char *name)
|
2017-03-21 13:15:18 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
char *stateFile = NULL;
|
|
|
|
virStoragePoolObjPtr obj = NULL;
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlNodePtr node = NULL;
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virStoragePoolDef) def = NULL;
|
2017-03-21 13:15:18 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(stateFile = virFileBuildPath(stateDir, name, ".xml")))
|
2019-01-31 15:21:47 +00:00
|
|
|
return NULL;
|
2017-03-21 13:15:18 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(xml = virXMLParseCtxt(stateFile, NULL, _("(pool state)"), &ctxt)))
|
2019-01-31 15:21:47 +00:00
|
|
|
goto cleanup;
|
2017-03-21 13:15:18 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(node = virXPathNode("//pool", ctxt))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not find any 'pool' element in state file"));
|
2019-01-31 15:21:47 +00:00
|
|
|
goto cleanup;
|
2018-08-17 12:50:59 +00:00
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
ctxt->node = node;
|
|
|
|
if (!(def = virStoragePoolDefParseXML(ctxt)))
|
2019-01-31 15:21:47 +00:00
|
|
|
goto cleanup;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (STRNEQ(name, def->name)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Storage pool state file '%s' does not match "
|
|
|
|
"pool name '%s'"),
|
|
|
|
stateFile, def->name);
|
2019-01-31 15:21:47 +00:00
|
|
|
goto cleanup;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* create the object */
|
2019-05-24 14:35:42 +00:00
|
|
|
if (!(obj = virStoragePoolObjListAdd(pools, def,
|
|
|
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
2019-01-31 15:21:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
/* XXX: future handling of some additional useful status data,
|
|
|
|
* for now, if a status file for a pool exists, the pool will be marked
|
|
|
|
* as active
|
|
|
|
*/
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
obj->active = true;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(stateFile);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
|
|
|
|
const char *stateDir)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
int ret = -1;
|
|
|
|
int rc;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if ((rc = virDirOpenIfExists(&dir, stateDir)) <= 0)
|
|
|
|
return rc;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
|
|
|
|
virStoragePoolObjPtr obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2019-03-06 14:30:04 +00:00
|
|
|
if (!virStringStripSuffix(entry->d_name, ".xml"))
|
2018-08-17 12:50:59 +00:00
|
|
|
continue;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(obj = virStoragePoolObjLoadState(pools, stateDir, entry->d_name)))
|
|
|
|
continue;
|
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
VIR_DIR_CLOSE(dir);
|
2017-03-07 20:18:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
|
|
|
|
const char *configDir,
|
|
|
|
const char *autostartDir)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
int ret;
|
|
|
|
int rc;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if ((rc = virDirOpenIfExists(&dir, configDir)) <= 0)
|
|
|
|
return rc;
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
|
|
|
|
char *path;
|
|
|
|
char *autostartLink;
|
|
|
|
virStoragePoolObjPtr obj;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2019-03-07 08:40:54 +00:00
|
|
|
if (!virStringHasSuffix(entry->d_name, ".xml"))
|
2018-08-17 12:50:59 +00:00
|
|
|
continue;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
|
|
|
|
continue;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!(autostartLink = virFileBuildPath(autostartDir, entry->d_name,
|
|
|
|
NULL))) {
|
|
|
|
VIR_FREE(path);
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
obj = virStoragePoolObjLoad(pools, entry->d_name, path, autostartLink);
|
|
|
|
virStoragePoolObjEndAPI(&obj);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
VIR_FREE(path);
|
|
|
|
VIR_FREE(autostartLink);
|
|
|
|
}
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
VIR_DIR_CLOSE(dir);
|
|
|
|
return ret;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|
|
|
virStoragePoolObjPtr obj,
|
|
|
|
virStoragePoolDefPtr def)
|
2017-04-05 12:14:49 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!obj->configFile) {
|
|
|
|
if (virFileMakePath(driver->configDir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("cannot create config directory %s"),
|
|
|
|
driver->configDir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(obj->configFile = virFileBuildPath(driver->configDir,
|
|
|
|
def->name, ".xml"))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(obj->autostartLink = virFileBuildPath(driver->autostartDir,
|
|
|
|
def->name, ".xml"))) {
|
|
|
|
VIR_FREE(obj->configFile);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-04-05 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return virStoragePoolSaveConfig(obj->configFile, def);
|
2017-04-05 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj)
|
2017-04-05 12:40:10 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
if (!obj->configFile) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no config file for %s"), obj->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (unlink(obj->configFile) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot remove config for %s"),
|
|
|
|
obj->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-04-05 12:40:10 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
struct _virStoragePoolCountData {
|
|
|
|
virConnectPtr conn;
|
|
|
|
virStoragePoolObjListACLFilter filter;
|
|
|
|
bool wantActive;
|
|
|
|
int count;
|
|
|
|
};
|
2017-04-05 12:40:10 +00:00
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
static int
|
|
|
|
virStoragePoolObjNumOfStoragePoolsCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2018-08-17 12:50:59 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj = payload;
|
|
|
|
struct _virStoragePoolCountData *data = opaque;
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
virObjectLock(obj);
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->filter && !data->filter(data->conn, obj->def))
|
|
|
|
goto cleanup;
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
|
|
|
goto cleanup;
|
2017-04-05 12:40:10 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
data->count++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
2017-04-05 12:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
|
|
|
|
virConnectPtr conn,
|
|
|
|
bool wantActive,
|
|
|
|
virStoragePoolObjListACLFilter filter)
|
2017-04-05 12:54:29 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
struct _virStoragePoolCountData data = {
|
|
|
|
.conn = conn, .filter = filter, .wantActive = wantActive, .count = 0 };
|
2017-04-05 12:54:29 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
virObjectRWLockRead(pools);
|
|
|
|
virHashForEach(pools->objs, virStoragePoolObjNumOfStoragePoolsCb, &data);
|
|
|
|
virObjectRWUnlock(pools);
|
2017-04-05 13:04:54 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return data.count;
|
2017-04-05 12:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
struct _virStoragePoolNameData {
|
2017-10-09 17:34:45 +00:00
|
|
|
virConnectPtr conn;
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjListACLFilter filter;
|
|
|
|
bool wantActive;
|
|
|
|
bool error;
|
|
|
|
int nnames;
|
|
|
|
int maxnames;
|
|
|
|
char **const names;
|
2017-10-09 17:34:45 +00:00
|
|
|
};
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
static int
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjGetNamesCb(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2018-08-17 12:50:59 +00:00
|
|
|
void *opaque)
|
2017-10-09 17:34:45 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjPtr obj = payload;
|
|
|
|
struct _virStoragePoolNameData *data = opaque;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->error)
|
2017-10-09 17:34:45 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
|
|
|
return 0;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
virObjectLock(obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->filter && !data->filter(data->conn, obj->def))
|
|
|
|
goto cleanup;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
|
|
|
goto cleanup;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data->names) {
|
|
|
|
if (VIR_STRDUP(data->names[data->nnames], obj->def->name) < 0) {
|
|
|
|
data->error = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-10-09 17:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
data->nnames++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(obj);
|
2017-10-09 17:34:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
int
|
2018-08-17 12:50:59 +00:00
|
|
|
virStoragePoolObjGetNames(virStoragePoolObjListPtr pools,
|
|
|
|
virConnectPtr conn,
|
|
|
|
bool wantActive,
|
|
|
|
virStoragePoolObjListACLFilter filter,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
2018-08-17 12:50:59 +00:00
|
|
|
struct _virStoragePoolNameData data = {
|
|
|
|
.conn = conn, .filter = filter, .wantActive = wantActive,
|
|
|
|
.error = false, .nnames = 0, .maxnames = maxnames, .names = names };
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockRead(pools);
|
2018-08-17 12:50:59 +00:00
|
|
|
virHashForEach(pools->objs, virStoragePoolObjGetNamesCb, &data);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWUnlock(pools);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
if (data.error)
|
|
|
|
goto error;
|
2017-10-09 17:34:45 +00:00
|
|
|
|
2018-08-17 12:50:59 +00:00
|
|
|
return data.nnames;
|
|
|
|
|
|
|
|
error:
|
|
|
|
while (data.nnames)
|
|
|
|
VIR_FREE(data.names[--data.nnames]);
|
|
|
|
return -1;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
#define MATCH(FLAG) (flags & (FLAG))
|
|
|
|
static bool
|
2018-08-13 15:55:16 +00:00
|
|
|
virStoragePoolObjMatch(virStoragePoolObjPtr obj,
|
|
|
|
unsigned int flags)
|
2017-03-07 20:18:01 +00:00
|
|
|
{
|
|
|
|
/* filter by active state */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) &&
|
|
|
|
!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
virStoragePoolObjIsActive(obj)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
!virStoragePoolObjIsActive(obj))))
|
2017-03-07 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* filter by persistence */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT) &&
|
|
|
|
!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
obj->configFile) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
!obj->configFile)))
|
2017-03-07 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* filter by autostart option */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART) &&
|
|
|
|
!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
obj->autostart) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
!obj->autostart)))
|
2017-03-07 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* filter by pool type */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)) {
|
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DIR) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_DIR)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FS) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_FS)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NETFS) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_NETFS)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_LOGICAL)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DISK) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_DISK)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_ISCSI)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SCSI) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_SCSI)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_MPATH) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_MPATH)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_RBD) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_RBD)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_SHEEPDOG)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_GLUSTER)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ZFS) &&
|
2017-05-05 19:12:59 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_ZFS)) ||
|
2017-03-07 20:18:01 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE) &&
|
2019-07-11 07:23:05 +00:00
|
|
|
(obj->def->type == VIR_STORAGE_POOL_VSTORAGE)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI_DIRECT) &&
|
|
|
|
(obj->def->type == VIR_STORAGE_POOL_ISCSI_DIRECT))))
|
2017-03-07 20:18:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#undef MATCH
|
|
|
|
|
2017-03-07 20:28:27 +00:00
|
|
|
|
2018-08-13 15:55:14 +00:00
|
|
|
typedef struct _virStoragePoolObjListExportData virStoragePoolObjListExportData;
|
|
|
|
typedef virStoragePoolObjListExportData *virStoragePoolObjListExportDataPtr;
|
|
|
|
struct _virStoragePoolObjListExportData {
|
2017-10-09 17:34:45 +00:00
|
|
|
virConnectPtr conn;
|
|
|
|
virStoragePoolObjListACLFilter filter;
|
|
|
|
bool checkActive;
|
|
|
|
bool wantActive;
|
|
|
|
bool checkMatch;
|
|
|
|
unsigned int flags;
|
|
|
|
bool error;
|
|
|
|
int nPools;
|
|
|
|
virStoragePoolPtr *pools;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-08-13 15:55:15 +00:00
|
|
|
virStoragePoolObjListExportCallback(void *payload,
|
2019-10-14 12:45:33 +00:00
|
|
|
const void *name G_GNUC_UNUSED,
|
2018-08-13 15:55:15 +00:00
|
|
|
void *opaque)
|
2017-10-09 17:34:45 +00:00
|
|
|
{
|
|
|
|
virStoragePoolObjPtr obj = payload;
|
2018-08-13 15:55:14 +00:00
|
|
|
virStoragePoolObjListExportDataPtr data = opaque;
|
2017-10-09 17:34:45 +00:00
|
|
|
virStoragePoolPtr pool = NULL;
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
|
|
|
|
if (data->filter && !data->filter(data->conn, obj->def))
|
|
|
|
goto cleanup;
|
|
|
|
|
2018-08-13 15:55:16 +00:00
|
|
|
if (!virStoragePoolObjMatch(obj, data->flags))
|
2017-10-09 17:34:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (data->pools) {
|
|
|
|
if (!(pool = virGetStoragePool(data->conn, obj->def->name,
|
|
|
|
obj->def->uuid, NULL, NULL))) {
|
|
|
|
data->error = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
data->pools[data->nPools] = pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->nPools++;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 20:18:01 +00:00
|
|
|
int
|
|
|
|
virStoragePoolObjListExport(virConnectPtr conn,
|
2017-03-21 14:07:46 +00:00
|
|
|
virStoragePoolObjListPtr poolobjs,
|
2017-03-07 20:18:01 +00:00
|
|
|
virStoragePoolPtr **pools,
|
|
|
|
virStoragePoolObjListFilter filter,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2018-08-13 15:55:14 +00:00
|
|
|
virStoragePoolObjListExportData data = {
|
2017-10-09 17:34:45 +00:00
|
|
|
.conn = conn, .filter = filter, .flags = flags, .error = false,
|
|
|
|
.nPools = 0, .pools = NULL };
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWLockRead(poolobjs);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
if (pools && VIR_ALLOC_N(data.pools, virHashSize(poolobjs->objs) + 1) < 0)
|
|
|
|
goto error;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2018-08-13 15:55:15 +00:00
|
|
|
virHashForEach(poolobjs->objs, virStoragePoolObjListExportCallback, &data);
|
2017-10-09 17:34:45 +00:00
|
|
|
virObjectRWUnlock(poolobjs);
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
if (data.error)
|
|
|
|
goto error;
|
2017-03-07 20:18:01 +00:00
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
if (data.pools) {
|
|
|
|
/* trim the array to the final size */
|
|
|
|
ignore_value(VIR_REALLOC_N(data.pools, data.nPools + 1));
|
|
|
|
*pools = data.pools;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:34:45 +00:00
|
|
|
return data.nPools;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectListFree(data.pools);
|
|
|
|
return -1;
|
2017-03-07 20:18:01 +00:00
|
|
|
}
|