2013-02-13 22:04:05 +04:00
/*
2014-04-02 05:13:51 +04:00
* Copyright ( C ) 2013 - 2014 Red Hat , Inc .
2013-02-13 22:04:05 +04:00
*
* 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/>.
*
* Author : Eric Blake < eblake @ redhat . com >
*/
# include <config.h>
# include <stdlib.h>
# include "testutils.h"
# include "vircommand.h"
# include "virerror.h"
2013-05-09 22:59:04 +04:00
# include "virfile.h"
2013-02-13 22:04:05 +04:00
# include "virlog.h"
# include "virstoragefile.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2013-02-13 22:04:05 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2014-02-28 16:16:17 +04:00
VIR_LOG_INIT ( " tests.storagetest " ) ;
2013-02-13 22:04:05 +04:00
# define datadir abs_builddir " / virstoragedata"
/* This test creates the following files, all in datadir:
* raw : 1024 - byte raw file
* qcow2 : qcow2 file with ' raw ' as backing
* wrap : qcow2 file with ' qcow2 ' as backing
* qed : qed file with ' raw ' as backing
* sub / link1 : symlink to qcow2
* sub / link2 : symlink to wrap
*
* Relative names to these files are known at compile time , but absolute
* and canonical names depend on where the test is run ; for convenience ,
* we pre - populate the computation of these names for use during the test .
*/
static char * qemuimg ;
static char * absraw ;
static char * canonraw ;
static char * absqcow2 ;
static char * canonqcow2 ;
static char * abswrap ;
2014-04-09 08:28:35 +04:00
static char * canonwrap ;
2013-02-13 22:04:05 +04:00
static char * absqed ;
2014-04-09 08:28:35 +04:00
static char * canonqed ;
2014-04-04 23:35:22 +04:00
static char * absdir ;
2014-04-09 08:28:35 +04:00
static char * canondir ;
2013-02-13 22:04:05 +04:00
static char * abslink2 ;
static void
testCleanupImages ( void )
{
VIR_FREE ( qemuimg ) ;
VIR_FREE ( absraw ) ;
VIR_FREE ( canonraw ) ;
VIR_FREE ( absqcow2 ) ;
VIR_FREE ( canonqcow2 ) ;
VIR_FREE ( abswrap ) ;
2014-04-09 08:28:35 +04:00
VIR_FREE ( canonwrap ) ;
2013-02-13 22:04:05 +04:00
VIR_FREE ( absqed ) ;
2014-04-09 08:28:35 +04:00
VIR_FREE ( canonqed ) ;
2014-04-04 23:35:22 +04:00
VIR_FREE ( absdir ) ;
2014-04-09 08:28:35 +04:00
VIR_FREE ( canondir ) ;
2013-02-13 22:04:05 +04:00
VIR_FREE ( abslink2 ) ;
if ( chdir ( abs_builddir ) < 0 ) {
fprintf ( stderr , " unable to return to correct directory, refusing to "
" clean up %s \n " , datadir ) ;
return ;
}
2014-04-03 01:52:18 +04:00
virFileDeleteTree ( datadir ) ;
2013-02-13 22:04:05 +04:00
}
static int
testPrepImages ( void )
{
int ret = EXIT_FAILURE ;
virCommandPtr cmd = NULL ;
2013-12-18 03:28:20 +04:00
char * buf = NULL ;
bool compat = false ;
2013-02-13 22:04:05 +04:00
qemuimg = virFindFileInPath ( " kvm-img " ) ;
if ( ! qemuimg )
qemuimg = virFindFileInPath ( " qemu-img " ) ;
2013-02-26 23:45:38 +04:00
if ( ! qemuimg )
goto skip ;
2013-02-13 22:04:05 +04:00
2013-12-18 03:28:20 +04:00
/* See if qemu-img supports '-o compat=xxx'. If so, we force the
* use of both v2 and v3 files ; if not , it is v2 only but the test
* still works . */
cmd = virCommandNewArgList ( qemuimg , " create " , " -f " , " qcow2 " ,
" -o? " , " /dev/null " , NULL ) ;
virCommandSetOutputBuffer ( cmd , & buf ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
goto skip ;
if ( strstr ( buf , " compat " ) )
compat = true ;
VIR_FREE ( buf ) ;
2013-02-13 22:04:05 +04:00
if ( virAsprintf ( & absraw , " %s/raw " , datadir ) < 0 | |
virAsprintf ( & absqcow2 , " %s/qcow2 " , datadir ) < 0 | |
virAsprintf ( & abswrap , " %s/wrap " , datadir ) < 0 | |
virAsprintf ( & absqed , " %s/qed " , datadir ) < 0 | |
2014-04-04 23:35:22 +04:00
virAsprintf ( & absdir , " %s/dir " , datadir ) < 0 | |
2013-07-04 14:20:21 +04:00
virAsprintf ( & abslink2 , " %s/sub/link2 " , datadir ) < 0 )
2013-02-13 22:04:05 +04:00
goto cleanup ;
if ( virFileMakePath ( datadir " /sub " ) < 0 ) {
fprintf ( stderr , " unable to create directory %s \n " , datadir " /sub " ) ;
goto cleanup ;
}
2014-04-04 23:35:22 +04:00
if ( virFileMakePath ( datadir " /dir " ) < 0 ) {
fprintf ( stderr , " unable to create directory %s \n " , datadir " /dir " ) ;
goto cleanup ;
}
2014-04-09 08:28:35 +04:00
if ( ! ( canondir = canonicalize_file_name ( absdir ) ) ) {
virReportOOMError ( ) ;
goto cleanup ;
}
2013-02-13 22:04:05 +04:00
if ( chdir ( datadir ) < 0 ) {
fprintf ( stderr , " unable to test relative backing chains \n " ) ;
goto cleanup ;
}
2013-12-18 03:28:20 +04:00
if ( virAsprintf ( & buf , " %1024d " , 0 ) < 0 | |
virFileWriteStr ( " raw " , buf , 0600 ) < 0 ) {
2013-02-26 23:45:38 +04:00
fprintf ( stderr , " unable to create raw file \n " ) ;
2013-02-13 22:04:05 +04:00
goto cleanup ;
2013-02-26 23:45:38 +04:00
}
2013-02-13 22:04:05 +04:00
if ( ! ( canonraw = canonicalize_file_name ( absraw ) ) ) {
virReportOOMError ( ) ;
goto cleanup ;
}
/* Create a qcow2 wrapping relative raw; later on, we modify its
* metadata to test other configurations */
virCommandFree ( cmd ) ;
2013-12-18 03:28:20 +04:00
cmd = virCommandNewArgList ( qemuimg , " create " , " -f " , " qcow2 " , NULL ) ;
virCommandAddArgFormat ( cmd , " -obacking_file=raw,backing_fmt=raw%s " ,
compat ? " ,compat=0.10 " : " " ) ;
virCommandAddArg ( cmd , " qcow2 " ) ;
2013-02-13 22:04:05 +04:00
if ( virCommandRun ( cmd , NULL ) < 0 )
2013-02-26 23:45:38 +04:00
goto skip ;
2013-02-13 22:04:05 +04:00
/* Make sure our later uses of 'qemu-img rebase' will work */
virCommandFree ( cmd ) ;
2013-02-26 23:45:38 +04:00
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
2013-02-13 22:04:05 +04:00
" -F " , " raw " , " -b " , " raw " , " qcow2 " , NULL ) ;
2013-02-26 23:45:38 +04:00
if ( virCommandRun ( cmd , NULL ) < 0 )
goto skip ;
2013-02-13 22:04:05 +04:00
if ( ! ( canonqcow2 = canonicalize_file_name ( absqcow2 ) ) ) {
virReportOOMError ( ) ;
goto cleanup ;
}
/* Create a second qcow2 wrapping the first, to be sure that we
* can correctly avoid insecure probing . */
virCommandFree ( cmd ) ;
2013-02-26 23:45:38 +04:00
cmd = virCommandNewArgList ( qemuimg , " create " , " -f " , " qcow2 " , NULL ) ;
2013-12-18 03:28:20 +04:00
virCommandAddArgFormat ( cmd , " -obacking_file=%s,backing_fmt=qcow2%s " ,
absqcow2 , compat ? " ,compat=1.1 " : " " ) ;
2013-02-13 22:04:05 +04:00
virCommandAddArg ( cmd , " wrap " ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
2013-02-26 23:45:38 +04:00
goto skip ;
2014-04-09 08:28:35 +04:00
if ( ! ( canonwrap = canonicalize_file_name ( abswrap ) ) ) {
virReportOOMError ( ) ;
goto cleanup ;
}
2013-02-13 22:04:05 +04:00
/* Create a qed file. */
virCommandFree ( cmd ) ;
2013-02-26 23:45:38 +04:00
cmd = virCommandNewArgList ( qemuimg , " create " , " -f " , " qed " , NULL ) ;
2013-02-13 22:04:05 +04:00
virCommandAddArgFormat ( cmd , " -obacking_file=%s,backing_fmt=raw " ,
absraw ) ;
virCommandAddArg ( cmd , " qed " ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
2013-02-26 23:45:38 +04:00
goto skip ;
2014-04-09 08:28:35 +04:00
if ( ! ( canonqed = canonicalize_file_name ( absqed ) ) ) {
virReportOOMError ( ) ;
goto cleanup ;
}
2013-02-13 22:04:05 +04:00
2013-04-15 20:00:17 +04:00
# ifdef HAVE_SYMLINK
2013-02-13 22:04:05 +04:00
/* Create some symlinks in a sub-directory. */
if ( symlink ( " ../qcow2 " , datadir " /sub/link1 " ) < 0 | |
symlink ( " ../wrap " , datadir " /sub/link2 " ) < 0 ) {
fprintf ( stderr , " unable to create symlink " ) ;
goto cleanup ;
}
2013-04-15 20:00:17 +04:00
# endif
2013-02-13 22:04:05 +04:00
ret = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2013-12-18 03:28:20 +04:00
VIR_FREE ( buf ) ;
2013-02-13 22:04:05 +04:00
virCommandFree ( cmd ) ;
if ( ret )
testCleanupImages ( ) ;
return ret ;
2013-02-26 23:45:38 +04:00
2014-03-25 10:53:44 +04:00
skip :
2013-02-26 23:45:38 +04:00
fputs ( " qemu-img is too old; skipping this test \n " , stderr ) ;
ret = EXIT_AM_SKIP ;
goto cleanup ;
2013-02-13 22:04:05 +04:00
}
2014-04-05 22:00:48 +04:00
/* Many fields of virStorageFileMetadata have the same content whether
* we access the file relatively or absolutely ; but file names differ
* depending on how the chain was opened . For ease of testing , we
* test both relative and absolute starts , and use a flag to say which
* of the two variations to compare against . */
2013-02-13 22:04:05 +04:00
typedef struct _testFileData testFileData ;
struct _testFileData
{
const char * expBackingStore ;
const char * expBackingStoreRaw ;
2014-04-09 03:15:04 +04:00
const char * expBackingDirRel ;
const char * expBackingDirAbs ;
enum virStorageFileFormat expBackingFormat ;
2013-02-13 22:04:05 +04:00
bool expIsFile ;
unsigned long long expCapacity ;
bool expEncrypted ;
2014-04-04 08:03:04 +04:00
const char * pathRel ;
const char * pathAbs ;
2014-04-09 08:28:35 +04:00
const char * canonPath ;
const char * relDirRel ;
const char * relDirAbs ;
int type ;
int format ;
2013-02-13 22:04:05 +04:00
} ;
enum {
EXP_PASS = 0 ,
EXP_FAIL = 1 ,
EXP_WARN = 2 ,
ALLOW_PROBE = 4 ,
2014-04-05 22:00:48 +04:00
ABS_START = 8 ,
2013-02-13 22:04:05 +04:00
} ;
struct testChainData
{
const char * start ;
enum virStorageFileFormat format ;
2014-04-05 22:00:48 +04:00
const testFileData * files [ 4 ] ;
2013-02-13 22:04:05 +04:00
int nfiles ;
unsigned int flags ;
} ;
static int
testStorageChain ( const void * args )
{
const struct testChainData * data = args ;
int ret = - 1 ;
virStorageFileMetadataPtr meta ;
virStorageFileMetadataPtr elt ;
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i = 0 ;
2014-04-04 23:35:22 +04:00
char * broken = NULL ;
2014-04-09 10:50:24 +04:00
bool isAbs = ! ! ( data - > flags & ABS_START ) ;
2013-02-13 22:04:05 +04:00
meta = virStorageFileGetMetadata ( data - > start , data - > format , - 1 , - 1 ,
( data - > flags & ALLOW_PROBE ) ! = 0 ) ;
if ( ! meta ) {
if ( data - > flags & EXP_FAIL ) {
virResetLastError ( ) ;
ret = 0 ;
}
goto cleanup ;
} else if ( data - > flags & EXP_FAIL ) {
fprintf ( stderr , " call should have failed \n " ) ;
goto cleanup ;
}
if ( data - > flags & EXP_WARN ) {
if ( ! virGetLastError ( ) ) {
fprintf ( stderr , " call should have warned \n " ) ;
goto cleanup ;
}
virResetLastError ( ) ;
2014-04-04 23:35:22 +04:00
if ( virStorageFileChainGetBroken ( meta , & broken ) | | ! broken ) {
fprintf ( stderr , " call should identify broken part of chain \n " ) ;
goto cleanup ;
}
} else {
if ( virGetLastError ( ) ) {
fprintf ( stderr , " call should not have warned \n " ) ;
goto cleanup ;
}
if ( virStorageFileChainGetBroken ( meta , & broken ) | | broken ) {
fprintf ( stderr , " chain should not be identified as broken \n " ) ;
goto cleanup ;
}
2013-02-13 22:04:05 +04:00
}
elt = meta ;
while ( elt ) {
char * expect = NULL ;
char * actual = NULL ;
2014-04-09 03:15:04 +04:00
const char * expBackingDirectory ;
2014-04-04 08:03:04 +04:00
const char * expPath ;
2014-04-09 08:28:35 +04:00
const char * expRelDir ;
2013-02-13 22:04:05 +04:00
if ( i = = data - > nfiles ) {
fprintf ( stderr , " probed chain was too long \n " ) ;
goto cleanup ;
}
2014-04-09 03:15:04 +04:00
expBackingDirectory = isAbs ? data - > files [ i ] - > expBackingDirAbs
: data - > files [ i ] - > expBackingDirRel ;
2014-04-04 08:03:04 +04:00
expPath = isAbs ? data - > files [ i ] - > pathAbs
: data - > files [ i ] - > pathRel ;
2014-04-09 08:28:35 +04:00
expRelDir = isAbs ? data - > files [ i ] - > relDirAbs
: data - > files [ i ] - > relDirRel ;
2013-02-13 22:04:05 +04:00
if ( virAsprintf ( & expect ,
2014-04-04 08:03:04 +04:00
" store:%s \n raw:%s \n directory:%s \n other:%d %d %lld %d \n "
2014-04-09 08:28:35 +04:00
" path:%s \n canon:%s \n relDir:%s \n type:%d %d \n " ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
NULLSTR ( data - > files [ i ] - > expBackingStore ) ,
NULLSTR ( data - > files [ i ] - > expBackingStoreRaw ) ,
2014-04-09 03:15:04 +04:00
NULLSTR ( expBackingDirectory ) ,
data - > files [ i ] - > expBackingFormat ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
data - > files [ i ] - > expIsFile ,
data - > files [ i ] - > expCapacity ,
2014-04-04 08:03:04 +04:00
data - > files [ i ] - > expEncrypted ,
2014-04-09 08:28:35 +04:00
NULLSTR ( expPath ) ,
NULLSTR ( data - > files [ i ] - > canonPath ) ,
NULLSTR ( expRelDir ) ,
data - > files [ i ] - > type ,
data - > files [ i ] - > format ) < 0 | |
2013-02-13 22:04:05 +04:00
virAsprintf ( & actual ,
2014-04-04 08:03:04 +04:00
" store:%s \n raw:%s \n directory:%s \n other:%d %d %lld %d \n "
2014-04-09 08:28:35 +04:00
" path:%s \n canon:%s \n relDir:%s \n type:%d %d \n " ,
2013-02-13 22:04:05 +04:00
NULLSTR ( elt - > backingStore ) ,
NULLSTR ( elt - > backingStoreRaw ) ,
NULLSTR ( elt - > directory ) ,
elt - > backingStoreFormat , elt - > backingStoreIsFile ,
2014-04-04 08:03:04 +04:00
elt - > capacity , ! ! elt - > encryption ,
2014-04-09 08:28:35 +04:00
NULLSTR ( elt - > path ) ,
NULLSTR ( elt - > canonPath ) ,
NULLSTR ( elt - > relDir ) ,
elt - > type , elt - > format ) < 0 ) {
2013-02-13 22:04:05 +04:00
VIR_FREE ( expect ) ;
VIR_FREE ( actual ) ;
goto cleanup ;
}
if ( STRNEQ ( expect , actual ) ) {
2014-04-05 21:34:32 +04:00
fprintf ( stderr , " chain member %zu " , i ) ;
2013-02-13 22:04:05 +04:00
virtTestDifference ( stderr , expect , actual ) ;
VIR_FREE ( expect ) ;
VIR_FREE ( actual ) ;
goto cleanup ;
}
VIR_FREE ( expect ) ;
VIR_FREE ( actual ) ;
elt = elt - > backingMeta ;
i + + ;
}
if ( i ! = data - > nfiles ) {
fprintf ( stderr , " probed chain was too short \n " ) ;
goto cleanup ;
}
ret = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2014-04-04 23:35:22 +04:00
VIR_FREE ( broken ) ;
2013-02-13 22:04:05 +04:00
virStorageFileFreeMetadata ( meta ) ;
return ret ;
}
static int
mymain ( void )
{
int ret ;
virCommandPtr cmd = NULL ;
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
struct testChainData data ;
2013-02-13 22:04:05 +04:00
/* Prep some files with qemu-img; if that is not found on PATH, or
* if it lacks support for qcow2 and qed , skip this test . */
if ( ( ret = testPrepImages ( ) ) ! = 0 )
return ret ;
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
# define TEST_ONE_CHAIN(id, start, format, flags, ...) \
2013-02-13 22:04:05 +04:00
do { \
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
size_t i ; \
memset ( & data , 0 , sizeof ( data ) ) ; \
data = ( struct testChainData ) { \
start , format , { __VA_ARGS__ } , 0 , flags , \
2013-02-13 22:04:05 +04:00
} ; \
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
for ( i = 0 ; i < ARRAY_CARDINALITY ( data . files ) ; i + + ) \
if ( data . files [ i ] ) \
data . nfiles + + ; \
2013-09-20 22:13:35 +04:00
if ( virtTestRun ( " Storage backing chain " id , \
2013-02-13 22:04:05 +04:00
testStorageChain , & data ) < 0 ) \
ret = - 1 ; \
} while ( 0 )
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
# define VIR_FLATTEN_2(...) __VA_ARGS__
# define VIR_FLATTEN_1(_1) VIR_FLATTEN_2 _1
2013-02-13 22:04:05 +04:00
# define TEST_CHAIN(id, relstart, absstart, format, chain1, flags1, \
chain2 , flags2 , chain3 , flags3 , chain4 , flags4 ) \
do { \
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
TEST_ONE_CHAIN ( # id " a " , relstart , format , flags1 , \
VIR_FLATTEN_1 ( chain1 ) ) ; \
TEST_ONE_CHAIN ( # id " b " , relstart , format , flags2 , \
VIR_FLATTEN_1 ( chain2 ) ) ; \
2014-04-05 22:00:48 +04:00
TEST_ONE_CHAIN ( # id " c " , absstart , format , flags3 | ABS_START , \
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
VIR_FLATTEN_1 ( chain3 ) ) ; \
2014-04-05 22:00:48 +04:00
TEST_ONE_CHAIN ( # id " d " , absstart , format , flags4 | ABS_START , \
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
VIR_FLATTEN_1 ( chain4 ) ) ; \
2013-02-13 22:04:05 +04:00
} while ( 0 )
/* The actual tests, in several groups. */
/* Missing file */
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
TEST_ONE_CHAIN ( " 0 " , " bogus " , VIR_STORAGE_FILE_RAW , EXP_FAIL ) ;
2013-02-13 22:04:05 +04:00
/* Raw image, whether with right format or no specified format */
2014-04-05 21:34:32 +04:00
testFileData raw = {
2014-04-09 03:15:04 +04:00
. expBackingFormat = VIR_STORAGE_FILE_NONE ,
2014-04-04 08:03:04 +04:00
. pathRel = " raw " ,
. pathAbs = canonraw ,
2014-04-09 08:28:35 +04:00
. canonPath = canonraw ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
} ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 1 , " raw " , absraw , VIR_STORAGE_FILE_RAW ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
( & raw ) , EXP_PASS ,
( & raw ) , ALLOW_PROBE | EXP_PASS ,
( & raw ) , EXP_PASS ,
( & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 2 , " raw " , absraw , VIR_STORAGE_FILE_AUTO ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
( & raw ) , EXP_PASS ,
( & raw ) , ALLOW_PROBE | EXP_PASS ,
( & raw ) , EXP_PASS ,
( & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* Qcow2 file with relative raw backing, format provided */
2014-04-04 08:03:04 +04:00
raw . pathAbs = " raw " ;
2014-04-05 22:00:48 +04:00
testFileData qcow2 = {
2014-04-05 21:34:32 +04:00
. expBackingStore = canonraw ,
. expBackingStoreRaw = " raw " ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = " . " ,
. expBackingDirAbs = datadir ,
. expBackingFormat = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " qcow2 " ,
. pathAbs = canonqcow2 ,
2014-04-09 08:28:35 +04:00
. canonPath = canonqcow2 ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QCOW2 ,
2014-04-04 08:03:04 +04:00
} ;
testFileData qcow2_as_raw = {
. expBackingFormat = VIR_STORAGE_FILE_NONE ,
. pathRel = " qcow2 " ,
. pathAbs = canonqcow2 ,
2014-04-09 08:28:35 +04:00
. canonPath = canonqcow2 ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
} ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 3 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , EXP_PASS ,
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
( & qcow2 , & raw ) , EXP_PASS ,
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 4 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_AUTO ,
2014-04-04 08:03:04 +04:00
( & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
2014-04-04 08:03:04 +04:00
( & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 file to use absolute backing name */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " raw " , " -b " , absraw , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-05 22:00:48 +04:00
qcow2 . expBackingStoreRaw = absraw ;
2014-04-09 03:15:04 +04:00
qcow2 . expBackingDirRel = datadir ;
2014-04-04 08:03:04 +04:00
raw . pathRel = absraw ;
raw . pathAbs = absraw ;
2014-04-09 08:28:35 +04:00
raw . relDirRel = datadir ;
2013-02-13 22:04:05 +04:00
/* Qcow2 file with raw as absolute backing, backing format provided */
TEST_CHAIN ( 5 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , EXP_PASS ,
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
( & qcow2 , & raw ) , EXP_PASS ,
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 6 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_AUTO ,
2014-04-04 08:03:04 +04:00
( & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
2014-04-04 08:03:04 +04:00
( & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* Wrapped file access */
2014-04-05 21:34:32 +04:00
testFileData wrap = {
. expBackingStore = canonqcow2 ,
. expBackingStoreRaw = absqcow2 ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = datadir ,
. expBackingDirAbs = datadir ,
. expBackingFormat = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " wrap " ,
. pathAbs = abswrap ,
2014-04-09 08:28:35 +04:00
. canonPath = canonwrap ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
} ;
2014-04-04 08:03:04 +04:00
qcow2 . pathRel = absqcow2 ;
2014-04-09 08:28:35 +04:00
qcow2 . relDirRel = datadir ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 7 , " wrap " , abswrap , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & wrap , & qcow2 , & raw ) , EXP_PASS ,
( & wrap , & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
( & wrap , & qcow2 , & raw ) , EXP_PASS ,
( & wrap , & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 and wrap file to omit backing file type */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -b " , absraw , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -b " , absqcow2 , " wrap " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-09 03:15:04 +04:00
wrap . expBackingFormat = VIR_STORAGE_FILE_AUTO ;
qcow2 . expBackingFormat = VIR_STORAGE_FILE_AUTO ;
2014-04-04 08:03:04 +04:00
qcow2_as_raw . pathRel = absqcow2 ;
2014-04-09 08:28:35 +04:00
qcow2_as_raw . relDirRel = datadir ;
2013-02-13 22:04:05 +04:00
/* Qcow2 file with raw as absolute backing, backing format omitted */
2014-04-05 21:34:32 +04:00
testFileData wrap_as_raw = {
. expBackingStore = canonqcow2 ,
. expBackingStoreRaw = absqcow2 ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = datadir ,
. expBackingDirAbs = datadir ,
. expBackingFormat = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " wrap " ,
. pathAbs = abswrap ,
2014-04-09 08:28:35 +04:00
. canonPath = canonwrap ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
} ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 8 , " wrap " , abswrap , VIR_STORAGE_FILE_QCOW2 ,
2014-04-04 08:03:04 +04:00
( & wrap_as_raw , & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & wrap , & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ,
2014-04-04 08:03:04 +04:00
( & wrap_as_raw , & qcow2_as_raw ) , EXP_PASS ,
2014-04-05 22:00:48 +04:00
( & wrap , & qcow2 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 to a missing backing file, with backing type */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " qcow2 " , " -b " , datadir " /bogus " ,
" qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-05 22:00:48 +04:00
qcow2 . expBackingStore = NULL ;
qcow2 . expBackingStoreRaw = datadir " /bogus " ;
2014-04-09 03:15:04 +04:00
qcow2 . expBackingFormat = VIR_STORAGE_FILE_NONE ;
2014-04-05 22:00:48 +04:00
qcow2 . expIsFile = false ;
2014-04-04 08:03:04 +04:00
qcow2 . pathRel = " qcow2 " ;
2014-04-09 08:28:35 +04:00
qcow2 . relDirRel = " . " ;
2013-02-13 22:04:05 +04:00
/* Qcow2 file with missing backing file but specified type */
TEST_CHAIN ( 9 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ,
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ) ;
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 to a missing backing file, without backing type */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -b " , datadir " /bogus " , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
/* Qcow2 file with missing backing file and no specified type */
TEST_CHAIN ( 10 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ,
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ) ;
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 to use an nbd: protocol as backend */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " raw " , " -b " , " nbd:example.org:6000 " ,
" qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-05 22:00:48 +04:00
qcow2 . expBackingStore = " nbd:example.org:6000 " ;
qcow2 . expBackingStoreRaw = NULL ;
2014-04-09 03:15:04 +04:00
qcow2 . expBackingDirRel = NULL ;
qcow2 . expBackingDirAbs = NULL ;
qcow2 . expBackingFormat = VIR_STORAGE_FILE_RAW ;
2013-02-13 22:04:05 +04:00
/* Qcow2 file with backing protocol instead of file */
TEST_CHAIN ( 11 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 ) , EXP_PASS ,
( & qcow2 ) , ALLOW_PROBE | EXP_PASS ,
( & qcow2 ) , EXP_PASS ,
( & qcow2 ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
/* qed file */
2014-04-05 21:34:32 +04:00
testFileData qed = {
. expBackingStore = canonraw ,
. expBackingStoreRaw = absraw ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = datadir ,
. expBackingDirAbs = datadir ,
. expBackingFormat = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " qed " ,
. pathAbs = absqed ,
2014-04-09 08:28:35 +04:00
. canonPath = canonqed ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QED ,
2014-04-04 08:03:04 +04:00
} ;
testFileData qed_as_raw = {
. expBackingFormat = VIR_STORAGE_FILE_NONE ,
. pathRel = " qed " ,
. pathAbs = absqed ,
2014-04-09 08:28:35 +04:00
. canonPath = canonqed ,
. relDirRel = " . " ,
. relDirAbs = datadir ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
} ;
2013-02-13 22:04:05 +04:00
TEST_CHAIN ( 12 , " qed " , absqed , VIR_STORAGE_FILE_AUTO ,
2014-04-04 08:03:04 +04:00
( & qed_as_raw ) , EXP_PASS ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
( & qed , & raw ) , ALLOW_PROBE | EXP_PASS ,
2014-04-04 08:03:04 +04:00
( & qed_as_raw ) , EXP_PASS ,
tests: refactor virstoragetest for less stack space
I'm about to add fields to virStorageFileMetadata, which means
also adding fields to the testFileData struct in virstoragetest.
Alas, adding even one pointer on an x86_64 machine gave me a
dreaded compiler error:
virstoragetest.c:712:1: error: the frame size of 4208 bytes is larger than 4096 bytes [-Werror=frame-larger-than=]
After some experimentation, I realized that each test was creating
yet another testChainData (which contains testFileData) on the stack;
forcing the reuse of one of these structures instead of creating a
fresh one each time drastically reduces the size requirements. While
at it, I also got rid of a lot of intermediate structs, with some
macro magic that lets me directly build up the destination chains
inline.
For a bit more insight into what this patch does:
The old code uses an intermediate variable as a fixed-size array
of structs:
testFileData chain[] = { a, b };
data.files = chain;
In the new code, the use of VIR_FLATTEN_* allows the TEST_CHAIN()
macro to still take a single argument for each chain, but now of
the form '(a, b)', where it is turned into the var-args 'a, b'
multiple arguments understood by TEST_ONE_CHAIN(). Thus, the
new code avoids an intermediate variable, and directly provides
the list of pointers to be assigned into array elements:
data.files = { &a, &b };
* tests/virstoragetest.c (mymain): Rewrite TEST_ONE_CHAIN to
reuse the same struct for each test, and to take the data
inline rather than via intermediate variables.
(testChainData): Use bounded array of pointers instead of
unlimited array of struct.
(testStorageChain): Reflect struct change.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 06:26:59 +04:00
( & qed , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-02-13 22:04:05 +04:00
2014-04-04 23:35:22 +04:00
/* directory */
2014-04-05 21:34:32 +04:00
testFileData dir = {
2014-04-04 08:03:04 +04:00
. pathRel = " dir " ,
. pathAbs = absdir ,
2014-04-09 08:28:35 +04:00
. type = VIR_STORAGE_TYPE_DIR ,
. format = VIR_STORAGE_FILE_DIR ,
2014-04-05 21:34:32 +04:00
} ;
2014-04-04 23:35:22 +04:00
TEST_CHAIN ( 13 , " dir " , absdir , VIR_STORAGE_FILE_AUTO ,
( & dir ) , EXP_PASS ,
( & dir ) , ALLOW_PROBE | EXP_PASS ,
( & dir ) , EXP_PASS ,
( & dir ) , ALLOW_PROBE | EXP_PASS ) ;
TEST_CHAIN ( 14 , " dir " , absdir , VIR_STORAGE_FILE_DIR ,
( & dir ) , EXP_PASS ,
( & dir ) , ALLOW_PROBE | EXP_PASS ,
( & dir ) , EXP_PASS ,
( & dir ) , ALLOW_PROBE | EXP_PASS ) ;
2013-04-15 20:00:17 +04:00
# ifdef HAVE_SYMLINK
2013-02-13 22:04:05 +04:00
/* Rewrite qcow2 and wrap file to use backing names relative to a
* symlink from a different directory */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " raw " , " -b " , " ../raw " , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " qcow2 " , " -b " , " ../sub/link1 " , " wrap " ,
NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
/* Behavior of symlinks to qcow2 with relative backing files */
2014-04-05 22:00:48 +04:00
testFileData link1 = {
2014-04-05 21:34:32 +04:00
. expBackingStore = canonraw ,
. expBackingStoreRaw = " ../raw " ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = " sub/../sub/.. " ,
. expBackingDirAbs = datadir " /sub/../sub/.. " ,
. expBackingFormat = VIR_STORAGE_FILE_RAW ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " ../sub/link1 " ,
. pathAbs = " ../sub/link1 " ,
2014-04-09 08:28:35 +04:00
. canonPath = canonqcow2 ,
. relDirRel = " sub/../sub " ,
. relDirAbs = datadir " /sub/../sub " ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
} ;
2014-04-05 22:00:48 +04:00
testFileData link2 = {
2014-04-05 21:34:32 +04:00
. expBackingStore = canonqcow2 ,
. expBackingStoreRaw = " ../sub/link1 " ,
2014-04-09 03:15:04 +04:00
. expBackingDirRel = " sub/../sub " ,
. expBackingDirAbs = datadir " /sub/../sub " ,
. expBackingFormat = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
. expIsFile = true ,
. expCapacity = 1024 ,
2014-04-04 08:03:04 +04:00
. pathRel = " sub/link2 " ,
. pathAbs = abslink2 ,
2014-04-09 08:28:35 +04:00
. canonPath = canonwrap ,
. relDirRel = " sub " ,
. relDirAbs = datadir " /sub " ,
. type = VIR_STORAGE_TYPE_FILE ,
. format = VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 21:34:32 +04:00
} ;
2014-04-04 08:03:04 +04:00
raw . pathRel = " ../raw " ;
raw . pathAbs = " ../raw " ;
2014-04-09 08:28:35 +04:00
raw . relDirRel = " sub/../sub/.. " ;
raw . relDirAbs = datadir " /sub/../sub/.. " ;
2014-04-04 23:35:22 +04:00
TEST_CHAIN ( 15 , " sub/link2 " , abslink2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & link2 , & link1 , & raw ) , EXP_PASS ,
( & link2 , & link1 , & raw ) , ALLOW_PROBE | EXP_PASS ,
( & link2 , & link1 , & raw ) , EXP_PASS ,
( & link2 , & link1 , & raw ) , ALLOW_PROBE | EXP_PASS ) ;
2013-04-15 20:00:17 +04:00
# endif
2014-04-04 23:35:22 +04:00
/* Rewrite qcow2 to be a self-referential loop */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " qcow2 " , " -b " , " qcow2 " , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-05 22:00:48 +04:00
qcow2 . expBackingStore = NULL ;
qcow2 . expBackingStoreRaw = " qcow2 " ;
2014-04-09 03:15:04 +04:00
qcow2 . expBackingDirRel = " . " ;
qcow2 . expBackingDirAbs = datadir ;
qcow2 . expBackingFormat = VIR_STORAGE_FILE_NONE ;
2014-04-05 22:00:48 +04:00
qcow2 . expIsFile = true ;
2014-04-04 23:35:22 +04:00
/* Behavior of an infinite loop chain */
TEST_CHAIN ( 16 , " qcow2 " , absqcow2 , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ,
( & qcow2 ) , EXP_WARN ,
( & qcow2 ) , ALLOW_PROBE | EXP_WARN ) ;
2014-04-04 23:35:22 +04:00
/* Rewrite wrap and qcow2 to be mutually-referential loop */
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " qcow2 " , " -b " , " wrap " , " qcow2 " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
virCommandFree ( cmd ) ;
cmd = virCommandNewArgList ( qemuimg , " rebase " , " -u " , " -f " , " qcow2 " ,
" -F " , " qcow2 " , " -b " , absqcow2 , " wrap " , NULL ) ;
if ( virCommandRun ( cmd , NULL ) < 0 )
ret = - 1 ;
2014-04-05 22:00:48 +04:00
qcow2 . expBackingStoreRaw = " wrap " ;
2014-04-09 03:15:04 +04:00
qcow2 . expBackingDirRel = datadir ;
2014-04-04 08:03:04 +04:00
qcow2 . pathRel = absqcow2 ;
2014-04-09 08:28:35 +04:00
qcow2 . relDirRel = datadir ;
2014-04-09 03:15:04 +04:00
wrap . expBackingFormat = VIR_STORAGE_FILE_QCOW2 ;
2014-04-04 23:35:22 +04:00
/* Behavior of an infinite loop chain */
TEST_CHAIN ( 17 , " wrap " , abswrap , VIR_STORAGE_FILE_QCOW2 ,
2014-04-05 22:00:48 +04:00
( & wrap , & qcow2 ) , EXP_WARN ,
( & wrap , & qcow2 ) , ALLOW_PROBE | EXP_WARN ,
( & wrap , & qcow2 ) , EXP_WARN ,
( & wrap , & qcow2 ) , ALLOW_PROBE | EXP_WARN ) ;
2014-04-04 23:35:22 +04:00
2013-02-13 22:04:05 +04:00
/* Final cleanup */
testCleanupImages ( ) ;
virCommandFree ( cmd ) ;
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
}
VIRT_TEST_MAIN ( mymain )