mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-31 18:33:11 +00:00
13284a6b83
In near future the storage pool object lock will be released during startPool and buildPool callback (in some backends). But this means that another thread may acquire the pool object lock and change its definition rendering the former thread access not only stale definition but also access freed memory (virStoragePoolObjAssignDef() will free old def when setting a new one). One way out of this would be to have the pool appear as active because our code deals with obj->def and obj->newdef just fine. But we can't declare a pool as active if it's not started or still building up. Therefore, have a boolean flag that is very similar and forces virStoragePoolObjAssignDef() to store new definition in obj->newdef even for an inactive pool. In turn, we have to move the definition to correct place when unsetting the flag. But that's as easy as calling virStoragePoolUpdateInactive(). Technically speaking, change made to storageDriverAutostartCallback() is not needed because until storage driver is initialized no storage API can run therefore there can't be anyone wanting to change the pool's definition. But I'm doing the change there for consistency anyways. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
272 lines
8.2 KiB
C
272 lines
8.2 KiB
C
/*
|
|
* virstorageobj.h: internal storage pool and volume objects handling
|
|
* (derived from storage_conf.h)
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "internal.h"
|
|
|
|
#include "storage_conf.h"
|
|
|
|
#include "capabilities.h"
|
|
|
|
typedef struct _virStoragePoolObj virStoragePoolObj;
|
|
typedef virStoragePoolObj *virStoragePoolObjPtr;
|
|
|
|
typedef struct _virStoragePoolObjList virStoragePoolObjList;
|
|
typedef virStoragePoolObjList *virStoragePoolObjListPtr;
|
|
|
|
typedef struct _virStorageDriverState virStorageDriverState;
|
|
typedef virStorageDriverState *virStorageDriverStatePtr;
|
|
|
|
struct _virStorageDriverState {
|
|
virMutex lock;
|
|
|
|
/* pid file FD, ensures two copies of the driver can't use the same root */
|
|
int lockFD;
|
|
|
|
virStoragePoolObjListPtr pools;
|
|
|
|
char *configDir;
|
|
char *autostartDir;
|
|
char *stateDir;
|
|
bool privileged;
|
|
|
|
/* Immutable pointer, self-locking APIs */
|
|
virObjectEventStatePtr storageEventState;
|
|
|
|
/* Immutable pointer, read only after initialized */
|
|
virCapsPtr caps;
|
|
};
|
|
|
|
typedef bool
|
|
(*virStoragePoolObjListFilter)(virConnectPtr conn,
|
|
virStoragePoolDefPtr def);
|
|
|
|
virStoragePoolObjPtr
|
|
virStoragePoolObjNew(void);
|
|
|
|
void
|
|
virStoragePoolObjEndAPI(virStoragePoolObjPtr *obj);
|
|
|
|
virStoragePoolDefPtr
|
|
virStoragePoolObjGetDef(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjSetDef(virStoragePoolObjPtr obj,
|
|
virStoragePoolDefPtr def);
|
|
|
|
virStoragePoolDefPtr
|
|
virStoragePoolObjGetNewDef(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjDefUseNewDef(virStoragePoolObjPtr obj);
|
|
|
|
const char *
|
|
virStoragePoolObjGetConfigFile(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjSetConfigFile(virStoragePoolObjPtr obj,
|
|
char *configFile);
|
|
|
|
const char *
|
|
virStoragePoolObjGetAutostartLink(virStoragePoolObjPtr obj);
|
|
|
|
bool
|
|
virStoragePoolObjIsActive(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjSetActive(virStoragePoolObjPtr obj,
|
|
bool active);
|
|
|
|
void
|
|
virStoragePoolObjSetStarting(virStoragePoolObjPtr obj,
|
|
bool starting);
|
|
bool
|
|
virStoragePoolObjIsStarting(virStoragePoolObjPtr obj);
|
|
|
|
bool
|
|
virStoragePoolObjIsAutostart(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj,
|
|
bool autostart);
|
|
|
|
unsigned int
|
|
virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjIncrAsyncjobs(virStoragePoolObjPtr obj);
|
|
|
|
void
|
|
virStoragePoolObjDecrAsyncjobs(virStoragePoolObjPtr obj);
|
|
|
|
int
|
|
virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
|
|
const char *configDir,
|
|
const char *autostartDir);
|
|
|
|
int
|
|
virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
|
|
const char *stateDir);
|
|
|
|
virStoragePoolObjPtr
|
|
virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
|
|
const unsigned char *uuid);
|
|
|
|
virStoragePoolObjPtr
|
|
virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
|
|
const char *name);
|
|
|
|
int
|
|
virStoragePoolObjAddVol(virStoragePoolObjPtr obj,
|
|
virStorageVolDefPtr voldef);
|
|
|
|
void
|
|
virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj,
|
|
virStorageVolDefPtr voldef);
|
|
|
|
size_t
|
|
virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj);
|
|
|
|
typedef int
|
|
(*virStorageVolObjListIterator)(virStorageVolDefPtr voldef,
|
|
const void *opaque);
|
|
|
|
int
|
|
virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj,
|
|
virStorageVolObjListIterator iter,
|
|
const void *opaque);
|
|
|
|
typedef bool
|
|
(*virStorageVolObjListSearcher)(virStorageVolDefPtr voldef,
|
|
const void *opaque);
|
|
|
|
virStorageVolDefPtr
|
|
virStoragePoolObjSearchVolume(virStoragePoolObjPtr obj,
|
|
virStorageVolObjListSearcher iter,
|
|
const void *opaque);
|
|
|
|
virStorageVolDefPtr
|
|
virStorageVolDefFindByKey(virStoragePoolObjPtr obj,
|
|
const char *key);
|
|
|
|
virStorageVolDefPtr
|
|
virStorageVolDefFindByPath(virStoragePoolObjPtr obj,
|
|
const char *path);
|
|
|
|
virStorageVolDefPtr
|
|
virStorageVolDefFindByName(virStoragePoolObjPtr obj,
|
|
const char *name);
|
|
|
|
void
|
|
virStoragePoolObjClearVols(virStoragePoolObjPtr obj);
|
|
|
|
typedef bool
|
|
(*virStoragePoolVolumeACLFilter)(virConnectPtr conn,
|
|
virStoragePoolDefPtr pool,
|
|
virStorageVolDefPtr def);
|
|
|
|
int
|
|
virStoragePoolObjNumOfVolumes(virStoragePoolObjPtr obj,
|
|
virConnectPtr conn,
|
|
virStoragePoolVolumeACLFilter filter);
|
|
|
|
int
|
|
virStoragePoolObjVolumeGetNames(virStoragePoolObjPtr obj,
|
|
virConnectPtr conn,
|
|
virStoragePoolVolumeACLFilter filter,
|
|
char **const names,
|
|
int maxnames);
|
|
|
|
int
|
|
virStoragePoolObjVolumeListExport(virConnectPtr conn,
|
|
virStoragePoolObjPtr obj,
|
|
virStorageVolPtr **vols,
|
|
virStoragePoolVolumeACLFilter filter);
|
|
|
|
typedef enum {
|
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE = (1 << 0),
|
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
|
|
} virStoragePoolObjListFlags;
|
|
|
|
virStoragePoolObjPtr
|
|
virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
|
|
virStoragePoolDefPtr def,
|
|
unsigned int flags);
|
|
|
|
int
|
|
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|
virStoragePoolObjPtr obj,
|
|
virStoragePoolDefPtr def);
|
|
|
|
int
|
|
virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj);
|
|
|
|
typedef bool (*virStoragePoolObjListACLFilter)(virConnectPtr conn,
|
|
virStoragePoolDefPtr def);
|
|
|
|
int
|
|
virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
|
|
virConnectPtr conn,
|
|
bool wantActive,
|
|
virStoragePoolObjListACLFilter filter);
|
|
|
|
int
|
|
virStoragePoolObjGetNames(virStoragePoolObjListPtr pools,
|
|
virConnectPtr conn,
|
|
bool wantActive,
|
|
virStoragePoolObjListACLFilter filter,
|
|
char **const names,
|
|
int maxnames);
|
|
|
|
void
|
|
virStoragePoolObjFree(virStoragePoolObjPtr obj);
|
|
|
|
typedef void
|
|
(*virStoragePoolObjListIterator)(virStoragePoolObjPtr obj,
|
|
const void *opaque);
|
|
|
|
void
|
|
virStoragePoolObjListForEach(virStoragePoolObjListPtr pools,
|
|
virStoragePoolObjListIterator iter,
|
|
const void *opaque);
|
|
|
|
typedef bool
|
|
(*virStoragePoolObjListSearcher)(virStoragePoolObjPtr obj,
|
|
const void *opaque);
|
|
|
|
virStoragePoolObjPtr
|
|
virStoragePoolObjListSearch(virStoragePoolObjListPtr pools,
|
|
virStoragePoolObjListSearcher searcher,
|
|
const void *opaque);
|
|
|
|
virStoragePoolObjListPtr
|
|
virStoragePoolObjListNew(void);
|
|
|
|
void
|
|
virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
|
|
virStoragePoolObjPtr obj);
|
|
|
|
int
|
|
virStoragePoolObjListExport(virConnectPtr conn,
|
|
virStoragePoolObjListPtr poolobjs,
|
|
virStoragePoolPtr **pools,
|
|
virStoragePoolObjListFilter filter,
|
|
unsigned int flags);
|