Commit Graph

62 Commits

Author SHA1 Message Date
Peter Krempa
750177104d util: storage: Return complete parent info from virStorageFileChainLookup
Instead of just returning the parent path, return the complete parent
source structure.
2014-07-09 11:41:34 +02:00
Peter Krempa
9a39f50420 storage: Don't store parent directory of an image explicitly
The parent directory doesn't necessarily need to be stored after we
don't mangle the path stored in the image. Remove it and tweak the code
to avoid using it.
2014-06-25 10:05:56 +02:00
Peter Krempa
e71437fff2 storage: Don't canonicalize paths unnecessarily
Store backing chain paths as non-canonical. The canonicalization step
will be already taken. This will allow to avoid storing unnecessary
amounts of data.
2014-06-25 10:02:59 +02:00
Peter Krempa
4074ad2d74 tests: virstoragetest: Remove unneeded relative test plumbing
After we don't test relative paths, remove even more unnecessary cruft
from the test code.
2014-06-25 10:02:02 +02:00
Peter Krempa
0e46f267b7 tests: virstoragetest: Don't test relative start of backing chains
libvirt always uses an absolute path to address the top image of an
image chain. Our storage test tests also the relative path which won't
ever be used. Additionally it makes the test more complicated.
2014-06-25 10:00:54 +02:00
Peter Krempa
84b1f5d875 util: storage: Remove now redundant backingRelative from virStorageSource
Now that we store only relative names in virStorageSource's member
relPath the backingRelative member is obsolete. Remove it and adapt the
code to the removal.
2014-06-25 09:58:42 +02:00
Peter Krempa
feb26b85f3 tests: virstoragetest: Remove now unused pathAbs
Separately remove the now unused variable.
2014-06-25 09:57:44 +02:00
Peter Krempa
7ba6a6f973 storage: Store relative path only for relatively backed storage
Due to various refactors and compatibility with the virstoragetest the
relPath field of the virStorageSource structure was always filled either
with the relative name or the full path in case of absolutely backed
storage. Return its original purpose to store only the relative name of
the disk if it is backed relatively and tweak the tests.
2014-06-25 09:54:42 +02:00
Peter Krempa
89bb95059a tests: virstoragetest: Remove "expBackingStore" field
Now that we changed ordering of the stored metadata so that the backing
store is described by the child element the test should reflect this
change too.

Remove the expected backing store field as it's actually described by
the next element in the backing chain, so there's no need for
duplication.
2014-06-25 09:39:15 +02:00
Peter Krempa
157a33a707 util: storage: Add helper to resolve relative path difference
This patch introduces a function that will allow us to resolve a
relative difference between two elements of a disk backing chain. This
function will be used to allow relative block commit and block pull
where we need to specify the new relative name of the image to qemu.

This patch also adds unit tests for the function to verify that it works
correctly.
2014-06-25 09:27:16 +02:00
Ján Tomko
ebd05fd562 Fix shadowed variable with older gcc
Commit 2cff94c fixed the shadowed 'link' added by commit 975f0e2,
but forgot the 'link' added by commit 08aa22e.
2014-06-24 12:53:44 +02:00
Peter Krempa
08aa22ec1d util: storagefile: Introduce universal function to canonicalize paths
Introduce a common function that will take a callback to resolve links
that will be used to canonicalize paths on various storage systems and
add extensive tests.
2014-06-24 10:45:43 +02:00
Eric Blake
3e3c6ff10f blockcommit: require base below top
The block commit code looks for an explicit base file relative
to the discovered top file; so for a chain of:
  base <- snap1 <- snap2 <- snap3
and a command of:
  virsh blockcommit $dom vda --base snap2 --top snap1
we got a sane message (here from libvirt 1.0.5):
error: invalid argument: could not find base 'snap2' below 'snap1' in chain for 'vda'

Meanwhile, recent refactoring has slightly reduced the quality of the
libvirt error messages, by losing the phrase 'below xyz':
error: invalid argument: could not find image 'snap2' in chain for 'snap3'

But we had a one-off, where we were not excluding the top file
itself in searching for the base; thankfully qemu still reports
the error, but the quality is worse:
  virsh blockcommit $dom vda --base snap2 --top snap2
error: internal error unable to execute QEMU command 'block-commit': Base '/snap2' not found

Fix the one-off in blockcommit by changing the semantics of name
lookup - if a starting point is specified, then the result must
be below that point, rather than including that point.  The only
other call to chain lookup was blockpull code, which was already
forcing the lookup to omit the active layer and only needs a
tweak to use the new semantics.

This also fixes the bug exposed in the testsuite, where when doing
a lookup pinned to an intermediate point in the chain, we were
unable to return the name of the parent also in the chain.

* src/util/virstoragefile.c (virStorageFileChainLookup): Change
semantics for non-NULL startFrom.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Adjust caller,
to keep existing semantics.
* tests/virstoragetest.c (mymain): Adjust to expose new semantics.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-16 09:33:57 -06:00
Eric Blake
b10a0e9198 storage: better tests of lookup
Add some more tests of what happens when we restrict a lookup
to begin at a point in the middle of a chain.  In particular,
we want to ensure that a parent is not found when starting at
the child.  This commit also demonstrates that we have a slight
difference in behavior on what parent we report when filtering
is in effect; as the determination of the parent affects the
code in block commit, exposing this in the testsuite will help
justify changes in future patches that tweak the semantics of
what lookups are allowed.

* tests/virstoragetest.c (testStorageLookup): Test user input.
(TEST_LOOKUP_TARGET): Add parameter.
(mymain): Add lookup tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-16 09:33:57 -06:00
Eric Blake
54597c5698 storage: renumber lookup tests
The next patch will be adding tests, including adding a parameter
for testing more conditions.  For ease of review of that patch, I
want to create common context lines that don't change when the new
tests are added (it's easier to visually review additions than it
is to review an entire chunk of tests rewritten into another
larger chunk of tests).

* tests/virstoragetest.c (mymain): Add a parameter and renumber
the lookup tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-16 09:33:57 -06:00
Eric Blake
47aaceb7cc storage: add alias for less typing
Typing chain->backingStore->backingStore gets old after a while;
introduce some alias variables to make the test more compact.

* tests/virstoragetest.c (mymain): Introduce some shorthand.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-16 09:33:57 -06:00
Peter Krempa
51c439056b tests: virstoragetest: Fix output when hitting errors
When the test is failing but the debug output isn't enabled the
resulting line would look ugly like and would not contain the actual
difference.

TEST: virstoragetest
      .................chain member 1!chain member 1!chain member 1!

Store the member index in the actual checked string to hide this problem
2014-06-13 10:57:43 +02:00
Peter Krempa
8ed19d8cc5 tests: storagetest: Unify and reformat storage chain format string
All the fields crammed into two lines weren't easy to parse by human
eyes. Split up the format string into lines and put it into a central
variable so that changes in two places aren't necessary.
2014-06-03 09:51:49 +02:00
Peter Krempa
b225444e25 storage: Change to new backing store parser
Use the new backing store parser in the backing chain crawler. This
change needs one test change where information about the NBD image are
now parsed differently.
2014-06-03 09:27:24 +02:00
Peter Krempa
29aabe73fe test: storage: Initialize storage source to correct type
Stat the path of the storage file being tested to set the correct type
into the virStorageSource. This will avoid breaking the test suite when
inquiring metadata of directory paths in the next patches.
2014-06-03 09:27:23 +02:00
Peter Krempa
713cc3b0a7 storage: Move virStorageFileGetMetadata to the storage driver
My future work will modify the metadata crawler function to use the
storage driver file APIs to access the files instead of accessing them
directly so that we will be able to request the metadata for remote
files too. To avoid linking the storage driver to every helper file
using the utils code, the backing chain traversal function needs to be
moved to the storage driver source.

Additionally the virt-aa-helper and virstoragetest programs need to be
linked with the storage driver as a result of this change.
2014-06-03 09:27:23 +02:00
Julio Faracco
1b14c449b8 util: use typedefs for enums in "src/util/" directory
In "src/util/" there are many enumeration (enum) declarations.
Sometimes, it's better using a typedef for variable types,
function types and other usages. Other enumeration will be
changed to typedef's in the future.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-05 14:30:01 -06:00
Jiri Denemark
f22b7899a8 Add support for addressing backing stores by index
Each backing store of a given disk is associated with a unique index
(which is also formatted in domain XML) for easier addressing of any
particular backing store. With this patch, any backing store can be
addressed by its disk target and the index. For example, "vdc[4]"
addresses the backing store with index equal to 4 of the disk identified
by "vdc" target. Such shorthand can be used in any API in place for a
backing file path:

    virsh blockcommit domain vda --base vda[3] --top vda[2]

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 11:11:03 +02:00
Jiri Denemark
f5869657c8 virStorageFileChainLookup: Return virStorageSourcePtr
Returning both virStorageSourcePtr and its path member does not make a
lot of sense.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 09:48:00 +02:00
Peter Krempa
8823272d41 util: storage: Invert the way recursive metadata retrieval works
To avoid having the root of a backing chain present twice in the list we
need to invert the working of virStorageFileGetMetadataRecurse.

Until now the recursive worker created a new backing chain element from
the name and other information passed as arguments. This required us to
pass the data of the parent in a deconstructed way and the worker
created a new entry for the parent.

This patch converts this function so that it just fills in metadata
about the parent and creates a backing chain element from those. This
removes the duplication of the first element.

To avoid breaking the test suite, virstoragetest now calls a wrapper
that creates the parent structure explicitly and pre-fills it with the
test data with same function signature as previously used.
2014-04-24 14:27:57 +02:00
Peter Krempa
cc92ee32cd util: virstoragefile: Don't mangle data stored about directories
Don't remove detected metadata about directory based storage volumes.
2014-04-23 23:11:08 +02:00
Peter Krempa
b627b8fd05 util: virstoragefile: Rename backingMeta to backingStore
To conform with the naming of the planned XML output rename the metadata
variable name.

s/backingMeta/backingStore/g
2014-04-23 23:11:07 +02:00
Peter Krempa
d64d9ff948 maint: Switch over from struct virStorageFileMetadata to virStorageSource
Replace the old structure with the new one. This change is a trivial
name change operation (along with change of the freeing function).
2014-04-23 23:11:07 +02:00
Peter Krempa
39c5aa4e4c virstoragefile: Kill "backingStore" field from virStorageFileMetadata
Remove the obsolete field replaced by data in "path".

The testsuite requires tweaking as the name of the backing file is now
stored one layer deeper in the backing chain linked list.
2014-04-23 23:11:06 +02:00
Peter Krempa
05bc536c83 util: storagefile: Rename "canonPath" to "path" in virStorageFileMetadata
As for the previous patch, this change is needed to achieve
compatibility with all the existing code, where we expect a fully
qualified path of local files to be present.
2014-04-23 23:11:06 +02:00
Peter Krempa
f34b829692 util: storage: Rename "path" to "relPath" in virStorageFileMetadata
To allow future change of virStorageFileMetadata to virStorageSource we
need to store a full path in the "path" variable as rest of the code
expects it to be a full path. Rename the "path" field to "relPath" to
keep tracking the info but allowing a real "path" field.
2014-04-23 23:11:06 +02:00
Eric Blake
e0292e0c2a conf: delete internal directory field
Another field no longer needed, getting us one step closer to
merging virStorageFileMetadata and virStorageSource.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Alter signature.
(virStorageFileFreeMetadata, virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataFromFD): Adjust clients.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-12 07:16:54 -06:00
Eric Blake
d193b34deb conf: tweak chain lookup internals
Thanks to the testsuite, I feel quite confident that this rewrite
is correct; it gives the same results for all cases except for one.
I can make the argument that _that_ case was a pre-existing bug:
when looking up relative names, the lookup is supposed to be
pegged to the directory that contains the parent qcow2 file.  Thus,
this resolves the fixme first mentioned in commit 367cd69 (even
though I accidentally removed the fixme comment early in 74430fe).

* src/util/virstoragefile.c (virStorageFileChainLookup): Depend on
new rather than old fields.
* tests/virstoragetest.c (mymain): Adjust test to match fix.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-12 07:16:03 -06:00
Eric Blake
74430fe364 conf: drop redundant parameter to chain lookup
The original chain lookup code had to pass in the starting name,
because it was not available in the chain.  But now that we have
added fields to the struct, this parameter is redundant.

* src/util/virstoragefile.h (virStorageFileChainLookup): Alter
signature.
* src/util/virstoragefile.c (virStorageFileChainLookup): Adjust
handling of top of chain.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Adjust caller.
* tests/virstoragetest.c (testStorageLookup, mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-11 22:09:37 -06:00
Eric Blake
367cd69d0d conf: test backing chain lookup
I realized that we had no good test coverage of looking up a
name from within a backing chain, even though code like
block-commit is relying on it.

* tests/virstoragetest.c (testStorageLookup): New function.
(mymain): New tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-11 19:49:52 -06:00
Eric Blake
86cfa1f603 conf: delete useless backingStoreFormat field
Drop another redundant field from virStorageFileMetadata.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c
(virStorageFileGetMetadataFromFDInternal)
(virStorageFileGetMetadataFromFD)
(virStorageFileGetMetadataRecurse): Adjust callers.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:59:26 -06:00
Eric Blake
c919ed7ea5 conf: delete useless backingStoreIsFile field
Finally starting to prune away some of the old fields that have
been made redundant by the new fields, on my way towards directly
reusing virStorageSource.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileChainLookup): Adjust callers.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:39:43 -06:00
Eric Blake
7010768c5e conf: provide details on network backing store
So far, my work has been merely preserving the status quo of
backing file analysis.  But this patch starts to tread in the
territory of making the backing chain code more powerful - we
will eventually support network storage containing non-raw
formats.  Here, we expose metadata information about a network
backing store, even if that information is still hardcoded to
a raw format for now.

* src/util/virstoragefile.c (virStorageFileGetMetadataRecurse):
Also populate struct for non-file backing.
(virStorageFileGetMetadata, virStorageFileGetMetadatainternal):
Recognize non-file top image.
(virFindBackingFile): Add comment.
(virStorageFileChainGetBroken): Adjust comment, ensure output
is set.
* tests/virstoragetest.c (mymain): Update test to reflect it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:34:21 -06:00
Eric Blake
aa506b462c conf: make virstoragetest debug easier
I'm tired of alternating between test failures due to bugs in
my refactoring work, vs. test failures due to leftovers in
the file system from the previous test.  This patch has no
impact when the testsuite is successful, but doeesn't hurt either.

* tests/virstoragetest.c (testPrepImages): Clean up from prior
failed test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 15:47:58 -06:00
Eric Blake
63fb786307 conf: test for more fields
Validate that all the new fields are getting set to desired values.

* tests/virstoragetest.c (_testFileData, testStorageChain): Check
for more fields.
(mymain): Populate additional fields.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:27 -06:00
Eric Blake
6d698220fd conf: start testing contents of the new backing chain fields
The testsuite is absolutely essential to feeling comfortable
about swapping the backing chain structure over to a new format.
This patch tests the path settings, and demonstrates that the
correct short name is being passed to the child.

* tests/virstoragetest.c (testStorageChain): Test path.
(mymain): Update expected data.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:27 -06:00
Eric Blake
4a349efccb conf: rename some test fields
A later patch will be adding some new fields to
virStorageFileMetadata; to minimize confusion, renaming the
test fields now will make it more obvious which fields are
being tested later.

* tests/virstoragetest.c (_testFileData): Alter names.
(testStorageChain, mymain): Adjust clients.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:26 -06:00
Jean-Baptiste Rouault
a18c713013 build: avoid compiler warning on shadowed name
Introduced in commit d1e55de3.
virstoragetest.c: In function ‘testStorageChain’:
virstoragetest.c:249:10: warning: declaration of ‘abs’ shadows a global
declaration [-Wshadow]
2014-04-09 09:05:42 +02:00
Eric Blake
d1e55de343 conf: another refactor of virstoragetest
Another reduction in the number of structs I have to modify
when I start tracking new fields in virStorageFileMetadata.

* tests/virstoragetest.c (_testFileData): Add fields.
(testStorageChain): Select between fields based on flag.
(mymain): Record both absolute and relative expectations in one
struct.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-08 13:32:55 -06:00
Eric Blake
3486133356 conf: interleave virstoragetest structs
As I add more tests, it's getting harder to follow the split between
a struct in one place and a test using the struct in another.
Interleaving the tests makes changes more localized, and also makes
debugging easier when a test goes wrong during my refactoring work.

* tests/virstoragetest.c (mymain): Modify structs as we go, rather
than up-front.
(testStorageChain): Make failure debugging easier.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-08 13:32:03 -06:00
Eric Blake
fcc7d0ed3a conf: test for more scenarios
Part of the upcoming refactoring will change how broken chains
are detected; it makes sense to test that this works.  In
particular, test the just-fixed infinite loop detection bug.
Also, make sure that detection of directories is sane.

* tests/virstoragetest.c (testStorageChain): Enhance test.
(mymain): Add more tests.
(testCleanupImages, testPrepImages): Populate a directory.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-08 13:29:21 -06:00
Eric Blake
d1a1d841db 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 10:48:58 -06:00
Eric Blake
7da61b30a0 tests: use C99 initialization for storage test
Writing this test with C99 initializers will make it easier to test
additions and deletions to struct members as I refactor the code.

* tests/virstoragetest.c (mymain): Rewrite initializers.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 10:48:53 -06:00
Eric Blake
8feec44a09 tests: simplify storage test cleanup
No need to spawn a child 'rm' process when we can do it ourselves.

* tests/virstoragetest.c (testCleanupImages): Use dedicated
helper.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 16:14:38 -06:00
Eric Blake
2279d5605c conf: modify tracking of encrypted images
A future patch will merge virStorageFileMetadata and virStorageSource,
but I found it easier to do if both structs use the same information
for tracking whether a source file needs encryption keys.

* src/util/virstoragefile.h (_virStorageFileMetadata): Prepare
full encryption struct instead of just a bool.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Use transfer semantics.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Populate struct.
(virStorageFileFreeMetadata): Adjust clients.
* tests/virstoragetest.c (testStorageChain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:01 -06:00