2009-10-09 01:26:30 +04:00
# include <config.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <string.h>
# include <sys/types.h>
# include <fcntl.h>
# include "internal.h"
# include "testutils.h"
# include "storage_conf.h"
# include "testutilsqemu.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2009-10-09 01:26:30 +04:00
2013-06-07 19:10:28 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2011-04-25 02:25:10 +04:00
static int
testCompareXMLToXMLFiles ( const char * inxml , const char * outxml )
{
2009-10-09 01:26:30 +04:00
char * actual = NULL ;
int ret = - 1 ;
virStoragePoolDefPtr dev = NULL ;
2015-04-23 18:10:15 +03:00
if ( ! ( dev = virStoragePoolDefParseFile ( inxml ) ) )
2009-10-09 01:26:30 +04:00
goto fail ;
2010-02-10 14:42:56 +03:00
if ( ! ( actual = virStoragePoolDefFormat ( dev ) ) )
2009-10-09 01:26:30 +04:00
goto fail ;
2016-05-26 18:01:53 +03:00
if ( virTestCompareToFile ( actual , outxml ) < 0 )
2009-10-09 01:26:30 +04:00
goto fail ;
ret = 0 ;
fail :
2012-02-03 03:16:43 +04:00
VIR_FREE ( actual ) ;
2009-10-09 01:26:30 +04:00
virStoragePoolDefFree ( dev ) ;
return ret ;
}
2011-04-25 02:25:10 +04:00
static int
testCompareXMLToXMLHelper ( const void * data )
{
int result = - 1 ;
char * inxml = NULL ;
char * outxml = NULL ;
if ( virAsprintf ( & inxml , " %s/storagepoolxml2xmlin/%s.xml " ,
abs_srcdir , ( const char * ) data ) < 0 | |
virAsprintf ( & outxml , " %s/storagepoolxml2xmlout/%s.xml " ,
abs_srcdir , ( const char * ) data ) < 0 ) {
goto cleanup ;
}
result = testCompareXMLToXMLFiles ( inxml , outxml ) ;
2009-10-09 01:26:30 +04:00
2014-03-25 10:53:44 +04:00
cleanup :
2012-02-03 03:16:43 +04:00
VIR_FREE ( inxml ) ;
VIR_FREE ( outxml ) ;
2011-04-25 02:25:10 +04:00
return result ;
}
2009-10-09 01:26:30 +04:00
static int
2011-04-29 20:21:20 +04:00
mymain ( void )
2009-10-09 01:26:30 +04:00
{
int ret = 0 ;
2017-11-03 15:09:47 +03:00
# define DO_TEST(name) \
if ( virTestRun ( " Storage Pool XML-2-XML " name , \
testCompareXMLToXMLHelper , ( name ) ) < 0 ) \
2009-10-09 01:26:30 +04:00
ret = - 1
DO_TEST ( " pool-dir " ) ;
storage: use valid XML for awkward volume names
$ touch /var/lib/libvirt/images/'a<b>c'
$ virsh pool-refresh default
$ virsh vol-dumpxml 'a<b>c' default | head -n2
<volume>
<name>a<b>c</name>
Oops. That's not valid XML. And when we fix the XML
generation, it fails RelaxNG validation.
I'm also tired of seeing <key>(null)</key> in the example
output for volume xml; while we used NULLSTR() to avoid
a NULL deref rather than relying on glibc's printf
extension behavior, it's even better if we avoid the issue
in the first place. But this requires being careful that
we don't invalidate any storage backends that were relying
on key being unassigned during virStoragVolCreateXML[From].
I would have split this into two patches (one for escaping,
one for avoiding <key>(null)</key>), but since they both
end up touching a lot of the same test files, I ended up
merging it into one.
Note that this patch allows pretty much any volume name
that can appear in a directory (excluding . and .. because
those are special), but does nothing to change the current
(unenforced) RelaxNG claim that pool names will consist
only of letters, numbers, _, -, and +. Tightening the C
code to match RelaxNG patterns and/or relaxing the grammar
to match the C code for pool names is a task for another
day (but remember, we DID recently tighten C code for
domain names to exclude a leading '.').
* src/conf/storage_conf.c (virStoragePoolSourceFormat)
(virStoragePoolDefFormat, virStorageVolTargetDefFormat)
(virStorageVolDefFormat): Escape user-controlled strings.
(virStorageVolDefParseXML): Parse key, for use in unit tests.
* src/storage/storage_driver.c (storageVolCreateXML)
(storageVolCreateXMLFrom): Ensure parsed key doesn't confuse
volume creation.
* docs/schemas/basictypes.rng (volName): Relax definition.
* tests/storagepoolxml2xmltest.c (mymain): Test it.
* tests/storagevolxml2xmltest.c (mymain): Likewise.
* tests/storagepoolxml2xmlin/pool-dir-naming.xml: New file.
* tests/storagepoolxml2xmlout/pool-dir-naming.xml: Likewise.
* tests/storagevolxml2xmlin/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-*.xml: Fix fallout.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-21 04:04:05 +04:00
DO_TEST ( " pool-dir-naming " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-fs " ) ;
DO_TEST ( " pool-logical " ) ;
2013-04-30 15:48:46 +04:00
DO_TEST ( " pool-logical-nopath " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-logical-create " ) ;
2017-03-28 16:11:52 +03:00
DO_TEST ( " pool-logical-noname " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-disk " ) ;
2016-01-07 14:57:28 +03:00
DO_TEST ( " pool-disk-device-nopartsep " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-iscsi " ) ;
DO_TEST ( " pool-iscsi-auth " ) ;
DO_TEST ( " pool-netfs " ) ;
2013-11-13 03:35:36 +04:00
DO_TEST ( " pool-netfs-gluster " ) ;
2015-06-03 18:43:00 +03:00
DO_TEST ( " pool-netfs-cifs " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-scsi " ) ;
2013-03-25 20:43:36 +04:00
DO_TEST ( " pool-scsi-type-scsi-host " ) ;
DO_TEST ( " pool-scsi-type-fc-host " ) ;
storage: Introduce 'managed' for the fchost parent
https://bugzilla.redhat.com/show_bug.cgi?id=1160926
Introduce a 'managed' attribute to allow libvirt to decide whether to
delete a vHBA vport created via external means such as nodedev-create.
The code currently decides whether to delete the vHBA based solely on
whether the parent was provided at creation time. However, that may not
be the desired action, so rather than delete and force someone to create
another vHBA via an additional nodedev-create allow the configuration of
the storage pool to decide the desired action.
During createVport when libvirt does the VPORT_CREATE, set the managed
value to YES if not already set to indicate to the deleteVport code that
it should delete the vHBA when the pool is destroyed.
If libvirtd is restarted all the memory only state was lost, so for a
persistent storage pool, use the virStoragePoolSaveConfig in order to
write out the managed value.
Because we're now saving the current configuration, we need to be sure
to not save the parent in the output XML if it was undefined at start.
Saving the name would cause future starts to always use the same parent
which is not the expected result when not providing a parent. By not
providing a parent, libvirt is expected to find the best available
vHBA port for each subsequent (re)start.
At deleteVport, use the new managed value to decide whether to execute
the VPORT_DELETE. Since we no longer save the parent in memory or in
XML when provided, if it was not provided, then we have to look it up.
2014-11-10 19:19:51 +03:00
DO_TEST ( " pool-scsi-type-fc-host-managed " ) ;
2009-10-09 01:26:30 +04:00
DO_TEST ( " pool-mpath " ) ;
2010-06-08 00:47:37 +04:00
DO_TEST ( " pool-iscsi-multiiqn " ) ;
2010-08-17 21:44:27 +04:00
DO_TEST ( " pool-iscsi-vendor-product " ) ;
2012-07-18 23:06:58 +04:00
DO_TEST ( " pool-sheepdog " ) ;
2013-10-16 03:06:18 +04:00
DO_TEST ( " pool-gluster " ) ;
DO_TEST ( " pool-gluster-sub " ) ;
2014-03-04 07:15:13 +04:00
DO_TEST ( " pool-scsi-type-scsi-host-stable " ) ;
2014-09-07 18:01:34 +04:00
DO_TEST ( " pool-zfs " ) ;
DO_TEST ( " pool-zfs-sourcedev " ) ;
2016-03-11 19:50:54 +03:00
DO_TEST ( " pool-rbd " ) ;
2017-01-17 17:10:59 +03:00
DO_TEST ( " pool-vstorage " ) ;
2009-10-09 01:26:30 +04:00
2014-03-17 13:38:38 +04:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2009-10-09 01:26:30 +04:00
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )