Commit Graph

34 Commits

Author SHA1 Message Date
John Ferlan
be1bb6c95b storage: Complete implementation volume by hash object
Alter the volume logic to use the hash tables instead of forward
linked lists. There are three hash tables to allow for fast lookup
by name, target.path, and key.

Modify the virStoragePoolObjAddVol to place the object in all 3
tables if possible using self locking RWLock on the volumes object.
Conversely when removing the volume, it's a removal of the object
from the various hash tables.

Implement functions to handle remote ForEach and Search Volume
type helpers. These are used by the disk backend in order to
facilitate adding a primary, extended, or logical partition.

Implement the various VolDefFindBy* helpers as simple (and fast)
hash lookups. The NumOfVolumes, GetNames, and ListExport helpers
are all implemented using standard for each hash table calls.
2018-01-10 08:10:24 -05:00
John Ferlan
f77c898d1e storage: Introduce _virStorageVolObj[List]
Prepare for hash table volume lists by creating the object infrastructure
for a Volume Object and Volume Object List

The _virStorageVolObj will contain just a pointer to the "current"
(and live) volume definition.

The _virStorageVolObjList will contain three hash tables, one for
each of the lookup options allowed for a volume.
2018-01-10 08:10:23 -05:00
John Ferlan
607524af4f conf: Use bool for @check_active parameter
Use a bool as that's how the variable is used in the function.
2018-01-04 10:54:08 -05:00
John Ferlan
c00643f86f conf: Need to unlock pools on object allocation failure
The RW pool could be left locked if allocation fails.
2018-01-04 10:54:08 -05:00
John Ferlan
4b2e0ed6e3 storage: Convert virStoragePoolObjList to use virObjectRWLockable
Now that we have a private storage pool list, we can take the next
step and convert to using objects. In this case, we're going to use
RWLockable objects (just like every other driver) with two hash
tables for lookup by UUID or Name.

Along the way the ForEach and Search API's will be adjusted to use
the related Hash API's and the various FindBy functions altered and
augmented to allow for HashLookup w/ and w/o the pool lock already
taken.

After virStoragePoolObjRemove we will need to virObjectUnref(obj)
after to indicate the caller is "done" with it's reference. The
Unlock occurs during the Remove.

The NumOf, GetNames, and Export functions all have their own callback
functions to return the required data and the FindDuplicate code
can use the HashSearch function callbacks.
2017-12-13 15:05:10 -05:00
John Ferlan
90e65353a2 storage: Privatize virStoragePoolObjListPtr
Move the structure into virstorageobj.c.

Use the virStoragePoolObjListNew allocator to fill in the @pools for
the storage driver and test driver.
2017-12-13 14:51:30 -05:00
John Ferlan
dcb5d8bb13 storage: Convert virStoragePoolObj into virObjectLockable
Now that we're moved the object into virstorageobj, let's make the
code use the lockable object.
2017-11-24 08:08:36 -05:00
John Ferlan
5d5c732d74 storage: Introduce virStoragePoolObjListSearch
Create an API to search through the storage pool objects looking for
a specific truism from a callback API in order to return the specific
storage pool object that is desired.
2017-11-24 08:08:32 -05:00
John Ferlan
d0258dd9d6 storage: Introduce virStoragePoolObjListForEach
Create an API to walk the pools->objs[] list in order to perform a
callback function for each element of the objs array that doesn't care
about whether the action succeeds or fails as the desire is to run the
code over every element in the array rather than fail as soon as or if
one fails.
2017-11-24 07:26:06 -05:00
John Ferlan
770aa08e48 storage: Introduce virStoragePoolObjEndAPI
For now it'll just call the virStoragePoolObjUnlock, but a future
adjustment will do something different. Since the new API will check
for a NULL object before the Unlock call, callers no longer need to
check for NULL before calling.

The virStoragePoolObjUnlock is now private/static to virstorageobj.c
with a short term forward reference.
2017-11-24 07:26:06 -05:00
John Ferlan
8fe48f20f8 storage: Privatize virStoragePoolObj and virStorageVolDefList
Move the structures into virstorageobj so that both are known
within virstorageobj.c.
2017-11-07 14:12:52 -05:00
John Ferlan
ee5498304f conf: Fix prototype/definition for virStoragePoolObj get functions
Modify virStoragePoolObjGetAutostartLink and
virStoragePoolObjGetConfigFile to return "const char *"
since that's how both are used and to ensure no one
tries to VIR_FREE the result.
2017-10-06 06:53:05 -04:00
John Ferlan
ccc8c311b2 storage: Internally represent @autostart as bool
Since it's been used that way anyway, let's just convert it to a bool
and only make the external representation be an int.
2017-09-19 08:30:37 -04:00
John Ferlan
5bf9b65501 storage: Introduce APIs to search/scan storage pool volumes list
Introduce virStoragePoolObjForEachVolume to scan each volume
calling the passed callback function until all volumes have been
processed in the storage pool volume list, unless the callback
function returns an error.

Introduce virStoragePoolObjSearchVolume to search each volume
calling the passed callback function until it returns true
indicating that the desired volume was found.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:50 -04:00
John Ferlan
40630a8e45 storage: Introduce storage volume add, delete, count APIs
Create/use virStoragePoolObjAddVol in order to add volumes onto list.

Create/use virStoragePoolObjRemoveVol in order to remove volumes from list.

Create/use virStoragePoolObjGetVolumesCount to get count of volumes on list.

For the storage driver, the logic alters when the volumes.obj list grows
to after we've fetched the volobj. This is an optimization of sorts, but
also doesn't "needlessly" grow the volumes.objs list and then just decr
the count if the virGetStorageVol fails.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:50 -04:00
John Ferlan
acd9a38069 storage: Fill in storage pool @active properly
It's a bool not an int, so use true/false and not 1/0
2017-09-19 08:28:50 -04:00
John Ferlan
407e6a3678 storage: Introduce virStoragePoolObjNew
Create/use a helper to perform object allocation.

Adjust storagevolxml2argvtest.c in order to use the allocator and
setting of the obj->def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:38 -04:00
John Ferlan
b31982868a storage: Create accessor API's for virStoragePoolObj
In preparation for making a private object, create accessor API's for
consumer storage functions to use:

    virStoragePoolObjGetDef
    virStoragePoolObjSetDef
    virStoragePoolObjGetNewDef
    virStoragePoolObjDefUseNewDef
    virStoragePoolObjGetConfigFile
    virStoragePoolObjSetConfigFile
    virStoragePoolObjGetAutostartLink
    virStoragePoolObjIsActive
    virStoragePoolObjSetActive
    virStoragePoolObjIsAutostart
    virStoragePoolObjSetAutostart
    virStoragePoolObjGetAsyncjobs
    virStoragePoolObjIncrAsyncjobs
    virStoragePoolObjDecrAsyncjobs

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 07:58:15 -04:00
John Ferlan
1910abbf47 storage: Alter @aclfilter to just @filter
Rename the variable, recent review requested just use of @filter,
so be consistent throughout.
2017-08-16 14:24:38 -04:00
John Ferlan
7cc30e0ed7 storage: Alter volume num, name, and export API's to just take obj
Alter the virStoragePoolObjNumOfVolumes, virStoragePoolObjVolumeGetNames,
and virStoragePoolObjVolumeListExport APIs to take a virStoragePoolObjPtr
instead of the &obj->volumes and obj->def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-21 14:51:47 -04:00
John Ferlan
b157f7e734 storage: Use consistent variable names in virstorageobj
A virStoragePoolObjPtr will be an 'obj'.

Also modify the @matchpool to @matchobj.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-21 14:51:47 -04:00
John Ferlan
4143b194ce conf: Check for storage conflicts across pool types
https://bugzilla.redhat.com/show_bug.cgi?id=1233129

The virStoragePoolObjSourceFindDuplicate logic used by PoolCreateXML
and PoolDefineXML avoids comparing the new definition against "other"
pool types. This can cause unexpected corruption if two different pool
source types used the same source device path. For example, a 'disk'
pool using source type device=/dev/sdc could be unwittingly overwritten
by using /dev/sdc for a 'logical' pool which also uses the source
device path.

So rather than blindly ignoring those checks when def->type !=
pool->def->type - have the pool->def->type switch logic handle the
check for which def->type's should be checked.
2017-04-13 10:10:39 -04:00
John Ferlan
f84b89fb19 conf: Introduce virStoragePoolObjSourceMatchTypeDEVICE
Refactor virStoragePoolObjSourceFindDuplicate into smaller units
separated by the "supported" pool source type. The ISCSI, FS,
LOGICAL, DISK, and ZFS pools can use "<source>... <device='%s'/>...
</source>".

Alter the logic slightly to return the matching pool or NULL rather
than setting matchpool = pool and break.  Easier to read that way.
2017-04-13 10:10:39 -04:00
John Ferlan
2811e29e10 conf: Introduce virStoragePoolObjSourceMatchTypeISCSI
In the effort to reduce the virStoragePoolObjSourceFindDuplicate logic,
create a new helper which will handle all the ISCSI type differences.

Alter things just a little bit to return NULL or pool rather than
using breaks and matchpool = pool, then break. Also rather than creating
variables withing the if...else if... conditions, have them all at the
top of the function to make things a bit easier to read.
2017-04-13 10:10:39 -04:00
John Ferlan
6ddd6ae811 conf: Introduce virStoragePoolObjSourceMatchTypeDIR
Refactor virStoragePoolObjSourceFindDuplicate into smaller units
separated by the "supported" pool source type. The DIR, GLUSTER,
and NETFS pools all can use "<source>... <dir='%s'/>... </source>".

Alter the logic slightly to return the matching pool or NULL rather
than setting matchpool = pool and break.  Easier to read that way.
2017-04-13 10:10:39 -04:00
John Ferlan
babf148a94 storage: Pass driver arg by ref
Alter virStoragePoolObjListExport in order to pass the drivers->pools
by reference

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
50e6d4e8e1 storage: Introduce virStoragePoolObjGetNames
Mostly code motion to move storageConnectList[Defined]StoragePools
and similar test driver code into virstorageobj.c and rename to
virStoragePoolObjGetNames.

Also includes a couple of variable name adjustments to keep code consistent
with other drivers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
2fae7c7fb2 storage: Introduce virStoragePoolObjNumOfStoragePools
Unify the NumOf[Defined]StoragePools API into virstorageobj.c from
storage_driver and test_driver.  The only real difference between the
two is the test driver doesn't call using the aclfilter API.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
96155c6994 storage: Introduce virStoragePoolObjVolumeListExport
Essentially code motion to move the storage/test driver ListAllVolumes
logic into virstorageobj.c

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
7e94830f07 storage: Introduce virStoragePoolObjVolumeGetNames
Mostly code motion to move storagePoolListVolumes code into virstorageobj.c
and rename to virStoragePoolObjVolumeGetNames.

Also includes a couple of variable name adjustments to keep code consistent
with other drivers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
4a440e4366 storage: Introduce virStoragePoolObjNumOfVolumes
Unify the NumOfVolumes API into virstorageobj.c from storage_driver and
test_driver.  The only real difference between the two is the test driver
doesn't call using the aclfilter API.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-04-11 08:49:51 -04:00
John Ferlan
a6d681485f conf: Use consistent function name prefixes for virstorageobj
Use "virStoragePoolObj" as a prefix for any external API in virstorageobj.

Also a couple of functions were local to virstorageobj.c, so remove their
external defs iin virstorageobj.h.

NB: The virStorageVolDef* API's won't change.
Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-17 14:40:09 -04:00
John Ferlan
749c1bb33a conf: Adjust coding style for storage conf sources
Alter the format of the code to follow more recent style guidelines of
two empty lines between functions, function decls with "[static] type"
on one line followed by function name with arguments to functions each
on one line.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-17 14:40:09 -04:00
John Ferlan
7c151e3398 conf: Introduce virstorageobj
Move all the StoragePoolObj related API's into their own module
virstorageobj from the storage_conf

Purely code motion at this point, plus adjustments to cleanly build

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-17 14:40:09 -04:00