]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
11 years agoconf: drop redundant parameter to chain lookup
Eric Blake [Sat, 12 Apr 2014 04:08:07 +0000 (22:08 -0600)]
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>
11 years agoconf: report error on chain lookup failure
Eric Blake [Fri, 11 Apr 2014 01:03:01 +0000 (19:03 -0600)]
conf: report error on chain lookup failure

The chain lookup function was inconsistent on whether it left
a message in the log when looking up a name that is not found
on the chain (leaving a message for OOM or if name was
relative but not part of the chain), and could litter the log
even when successful (when name was relative but deep in the
chain, use of virFindBackingFile early in the chain would complain
about a file not found).  It's easier to make the function
consistently emit a message exactly once on failure, and to let
all callers rely on the clean semantics.

* src/util/virstoragefile.c (virStorageFileChainLookup): Always
report error on failure.  Simplify relative lookups.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Avoid
overwriting error.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoutil: new virFileRelLinkPointsTo function
Eric Blake [Thu, 10 Apr 2014 23:36:06 +0000 (17:36 -0600)]
util: new virFileRelLinkPointsTo function

When checking if two filenames point to the same inode (whether
by hardlink or symlink), sometimes one of the names might be
relative.  This convenience function makes it easier to check.

* src/util/virfile.h (virFileRelLinkPointsTo): New prototype.
* src/util/virfile.c (virFileRelLinkPointsTo): New function.
* src/libvirt_private.syms (virfile.h): Export it.
* src/xen/xm_internal.c (xenXMDomainGetAutostart): Use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: test backing chain lookup
Eric Blake [Thu, 10 Apr 2014 19:56:57 +0000 (13:56 -0600)]
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>
11 years agoIntroduce --without-pm-utils to get rid of pm-is-supported dependency
Cédric Bosdonnat [Fri, 11 Apr 2014 07:20:48 +0000 (09:20 +0200)]
Introduce --without-pm-utils to get rid of pm-is-supported dependency

This uses the dbus api of systemd to check the power management
capabilities of the node.

11 years agotests: drop dead code from argv2xml and xml2xml
Eric Blake [Fri, 11 Apr 2014 18:51:00 +0000 (12:51 -0600)]
tests: drop dead code from argv2xml and xml2xml

Noticed while tweaking the RelaxNG grammar for <disk> elements.

* tests/qemuxml2xmloutdata/qemuxml2xmlout-numad-static-vcpu-no-numatune.xml:
* tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-cdrom-empty.xml:
Drop unused files.
* tests/qemuargv2xmltest.c (testInfo, DO_TEST_FULL): Drop unused
field.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agobhyve: fix domain management
Wojciech Macek [Wed, 9 Apr 2014 05:52:11 +0000 (07:52 +0200)]
bhyve: fix domain management

When domain is not persistent, it should be forgotten upon destroying.

11 years agoconf: delete useless backingStoreFormat field
Eric Blake [Thu, 10 Apr 2014 02:37:16 +0000 (20:37 -0600)]
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>
11 years agoconf: return backing information separately from metadata
Eric Blake [Thu, 10 Apr 2014 01:49:07 +0000 (19:49 -0600)]
conf: return backing information separately from metadata

A couple pieces of virStorageFileMetadata are used only while
collecting information about the chain, and don't need to
live permanently in the struct.  This patch refactors external
callers to collect the information separately, so that the
next patch can remove the fields.

* src/util/virstoragefile.h (virStorageFileGetMetadataFromBuf):
Alter signature.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Likewise.
(virStorageFileGetMetadataFromFDInternal): Adjust callers.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: delete useless backingStoreIsFile field
Eric Blake [Wed, 9 Apr 2014 22:21:19 +0000 (16:21 -0600)]
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>
11 years agoconf: expose probe for non-local storage
Eric Blake [Wed, 9 Apr 2014 22:08:42 +0000 (16:08 -0600)]
conf: expose probe for non-local storage

Deciding if a user string represents a local file instead of a
network path is an operation worth exposing directly, particularly
since the next patch will be removing a redundant variable that
was caching the information.

* src/util/virstoragefile.h (virStorageIsFile): New declaration.
* src/util/virstoragefile.c (virBackingStoreIsFile): Rename...
(virStorageIsFile): ...export, and allow NULL input.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Use it.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/libvirt_private.syms (virstoragefile.h): Export function.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: provide details on network backing store
Eric Blake [Wed, 9 Apr 2014 21:36:30 +0000 (15:36 -0600)]
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>
11 years agoconf: make virstoragetest debug easier
Eric Blake [Thu, 10 Apr 2014 19:34:15 +0000 (13:34 -0600)]
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>
11 years agocpu: Properly check input parameters
Jiri Denemark [Wed, 26 Mar 2014 14:59:26 +0000 (15:59 +0100)]
cpu: Properly check input parameters

Most of the APIs in CPU driver do not expect to get NULL for input
parameters. Let's mark them with ATTRIBUTE_NONNULL and also check for
some members of virCPUDef when the APIs expect them have some specific
values.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agocpu: Add documentation for CPU driver APIs
Jiri Denemark [Wed, 26 Mar 2014 14:45:50 +0000 (15:45 +0100)]
cpu: Add documentation for CPU driver APIs

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agotests: Fix systemd test with --without-driver-modules
Jiri Denemark [Thu, 10 Apr 2014 15:18:35 +0000 (17:18 +0200)]
tests: Fix systemd test with --without-driver-modules

Every test that makes use of virmock.h (only virsystemdtest as of now)
needs to be linked with -export-dynamic to make sure the LD_PRELOADed
mock library can access its wrap_* symbols. Normally,
DRIVER_MODULE_LDFLAGS variable contains -export-dynamic but when
--without-driver-modules configure option is used, DRIVER_MODULE_LDFLAGS
is empty.

This patch turns on -export-dynamic for all tests unconditionally
regardless on --without-driver-modules. This fixes virsystemdtest and
all future users of virmock.h.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoFix build on mingw32
Ján Tomko [Wed, 9 Apr 2014 14:47:26 +0000 (16:47 +0200)]
Fix build on mingw32

My commit 897808e added a parameter to virCgroupGetPercpuStats,
but didn't change the stub for systems where cgroups are not supported.

11 years agovirsh: Fix comment of vshCmdInfo
Li Yang [Fri, 4 Apr 2014 07:18:54 +0000 (15:18 +0800)]
virsh: Fix comment of vshCmdInfo

The original comment of vshCmdInfo:
"name" - command name

Actually it's 'help' and the short description
of command, not the command name.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
11 years agoClean up virCgroupGetPercpuStats
Ján Tomko [Thu, 3 Apr 2014 17:23:25 +0000 (19:23 +0200)]
Clean up virCgroupGetPercpuStats

The iterator is checked for being less than or equal to need_cpus.
The 'n' variable is incremented need_cpus + 1 times.

Simplify the computation of need_cpus and make its value one larger,
to let it be used instead of 'n' and compared without the equal sign
in loop conditions.

Just index the sum_cpu_time array instead of using a helper variable.

Start the loop at start_cpu instead of continuing for all lower values.

11 years agoCheck maximum startcpu value correctly
Ján Tomko [Thu, 3 Apr 2014 17:38:54 +0000 (19:38 +0200)]
Check maximum startcpu value correctly

The cpus are indexed from 0, so a startcpu value equal
to the number of CPUs is invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=1070680

11 years agoRename id, max_id to need_cpus, total_cpus
Ján Tomko [Thu, 3 Apr 2014 17:53:13 +0000 (19:53 +0200)]
Rename id, max_id to need_cpus, total_cpus

total_cpus is the total number of CPUs on the host
need_cpus is the number of CPUs we need to look at

(need_cpus can be larger than ncpus, because we need to look
 at CPUs before the startcpu too, even if we aren't reporting
 their stats)

11 years agoExtend virCgroupGetPercpuStats to fill in vcputime too
Ján Tomko [Thu, 3 Apr 2014 15:53:43 +0000 (17:53 +0200)]
Extend virCgroupGetPercpuStats to fill in vcputime too

Currently, virCgroupGetPercpuStats is only used by the LXC driver,
filling out the CPUTIME stats. qemuDomainGetPercpuStats does this
and also filles out VCPUTIME stats.

Extend virCgroupGetPercpuStats to also report VCPUTIME stats if
nvcpupids is non-zero. In the LXC driver, we don't have cpupids.
In the QEMU driver, there is at least one cpupid for a running domain,
so the behavior shouldn't change for QEMU either.

Also rename getSumVcpuPercpuStats to virCgroupGetPercpuVcpuSum.

11 years agoFix return value of virCgroupGetPercpuStats
Ján Tomko [Fri, 4 Apr 2014 07:26:23 +0000 (09:26 +0200)]
Fix return value of virCgroupGetPercpuStats

We need to return the number of successfully populated stats,
not the nparams supplied by the user.

11 years agoDon't require domain obj in qemuDomainGetPercpuStats
Ján Tomko [Thu, 3 Apr 2014 15:19:23 +0000 (17:19 +0200)]
Don't require domain obj in qemuDomainGetPercpuStats

All we need is the virCgroupPtr and number of vcpupids.
This will allow the function to be moved to util/vircgroup.c.

11 years agoconf: test for more fields
Eric Blake [Wed, 9 Apr 2014 04:28:35 +0000 (22:28 -0600)]
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>
11 years agoconf: start testing contents of the new backing chain fields
Eric Blake [Fri, 4 Apr 2014 04:03:04 +0000 (22:03 -0600)]
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>
11 years agoconf: track more fields in backing chain metadata
Eric Blake [Tue, 8 Apr 2014 22:09:05 +0000 (16:09 -0600)]
conf: track more fields in backing chain metadata

The current use of virStorageFileMetadata is awkward; to learn
some of the information about a child node, you have to read
fields in the parent node.  This does not lend itself well to
modifying backing chains (whether inserting a new node in the
chain, or consolidating existing nodes); better would be to
learn about a child node directly in that node.  This patch
sets up some new fields which contain redundant information,
although not necessarily in the final desired state for the
new fields (see the next patch for actual tests of what is there
now).  Then later patches will do any refactoring necessary to
get the fields to their desired states, and update clients to
get the information from the new fields, so we can finally
delete the fields that are tracking information about the wrong
node.

More concretely, compare these three example backing chains:

good <- one
missing <- two
gluster://server/vol/img <- three

Pre-patch, querying the chains gives:
{ .backingStore = "/path/to/good",
  .backingStoreRaw = "good",
  .backingStoreIsFile = true,
  .backingStoreFormat = VIR_STORAGE_FILE_RAW,
  .backingMeta = {
    .backingStore = NULL,
    .backingStoreRaw = NULL,
    .backingStoreIsFile = false,
    .backingMeta = NULL,
  }
}
{ .backingStore = NULL,
  .backingStoreRaw = "missing",
  .backingStoreIsFile = false,
  .backingStoreFormat = VIR_STORAGE_FILE_NONE,
  .backingMeta = NULL,
}
{ .backingStore = "gluster://server/vol/img",
  .backingStoreRaw = NULL,
  .backingStoreIsFile = false,
  .backingStoreFormat = VIR_STORAGE_FILE_RAW,
  .backingMeta = NULL,
}

Deciding whether to ignore a missing backing file (as in virsh
vol-dumpxml) or report an error (as in security manager sVirt
labeling) requires reading multiple fields.  Plus, the format
is hard-coded to treat all network protocols as end-of-the-chain,
as if they were raw.  By the end of this patch series, the goal
is to instead represent these three situations as:

{ .path = "one",
  .canonPath = "/path/to/one",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "good",
  .backingMeta = {
    .path = "good",
    .canonPath = "/path/to/good",
    .type = VIR_STORAGE_TYPE_FILE,
    .format = VIR_STORAGE_FILE_RAW,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}
{ .path = "two",
  .canonPath = "/path/to/two",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "missing",
  .backingMeta = NULL,
}
{ .path = "three",
  .canonPath = "/path/to/three",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "gluster://server/vol/img",
  .backingMeta = {
    .path = "gluster://server/vol/img",
    .canonPath = "gluster://server/vol/img",
    .type = VIR_STORAGE_TYPE_NETWORK,
    .format = VIR_STORAGE_FILE_RAW,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}

or, for the second file, maybe also allowing:
{ .path = "two",
  .canonPath = "/path/to/two",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "missing",
  .backingMeta = {
    .path = "missing",
    .canonPath = NULL,
    .type = VIR_STORAGE_TYPE_NONE,
    .format = VIR_STORAGE_FILE_NONE,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}

* src/util/virstoragefile.h (_virStorageFileMetadata): Add
path, canonPath, relDir, type, and format fields.  Reorder
existing fields, and add lots of comments.
* src/util/virstoragefile.c (virStorageFileFreeMetadata): Clean
new fields.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Start populating new
fields.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: rename some test fields
Eric Blake [Tue, 8 Apr 2014 23:15:04 +0000 (17:15 -0600)]
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>
11 years agoconf: earlier allocation during backing chain crawl
Eric Blake [Tue, 8 Apr 2014 21:20:36 +0000 (15:20 -0600)]
conf: earlier allocation during backing chain crawl

Right now, we are allocating virStorageFileMetadata near the bottom
of the callchain, only after we have identified that we are visiting
a file (and not a network resource).  I'm hoping to eventually
support parsing the backing chain from XML, where the backing chain
crawl then validates what was parsed rather than allocating a fresh
structure.  Likewise, I'm working towards a setup where we have a
backing element even for networks.  Both of these use cases are
easier to code if the allocation is hoisted earlier.

* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Change signature.
(virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: track user vs. canonical name through full chain lookup
Eric Blake [Tue, 8 Apr 2014 20:26:02 +0000 (14:26 -0600)]
conf: track user vs. canonical name through full chain lookup

The previous patch started a separation of error messages
reported against the user-specified name, vs. tracking the
canonical path that was actually opened.  This patch extends
that notion, by hoisting directory detection up front, passing
the canonical path through the entire call chain, and
simplifying lower-level functions that can now assume that
a canonical path and directory have been supplied.

* src/util/virstoragefile.c
(virStorageFileGetMetadataFromFDInternal)
(virStorageFileGetMetadataInternal): Add parameter, require
directory.
(virFindBackingFile): Require directory.
(virStorageFileGetMetadataFromFD): Pass canonical path.
(virStorageFileGetMetadataFromBuf): Likewise.
(virStorageFileGetMetadata): Determine initial directory.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoqemu: Unexport qemuBuildNetworkDriveURI()
Peter Krempa [Tue, 8 Apr 2014 15:12:04 +0000 (17:12 +0200)]
qemu: Unexport qemuBuildNetworkDriveURI()

The function isn't used in any other file. Convert it to static.

11 years agoqemu: Refactor qemuGetDriveSourceString to take virStorageSourcePtr
Peter Krempa [Tue, 8 Apr 2014 15:50:50 +0000 (17:50 +0200)]
qemu: Refactor qemuGetDriveSourceString to take virStorageSourcePtr

Refactor the function to avoid multiple wrappers splitting identical
fields from the now common metadata struct.

The refactor is done by folding in the wrapper used for disk sources
which allows us to lookup secrets via the secret driver. This may allow
using stored secrets for snapshot disk images too in the future.

11 years agostorage: Refactor location of metadata for storage drive access to files
Peter Krempa [Tue, 8 Apr 2014 10:07:24 +0000 (12:07 +0200)]
storage: Refactor location of metadata for storage drive access to files

Now that we store all metadata about a storage image in a
virStorageSource struct let's use it also to store information needed by
the storage driver to access and do operations on the files.

11 years agostorage: Refactor storage file initialization to use virStorageSourcePtr
Peter Krempa [Tue, 8 Apr 2014 06:42:57 +0000 (08:42 +0200)]
storage: Refactor storage file initialization to use virStorageSourcePtr

Now that storage source metadata is stored in a single struct we don't
need two initialization functions for different structs.

11 years agoconf: Refactor helpers to retrieve actual storage type
Peter Krempa [Tue, 8 Apr 2014 06:51:06 +0000 (08:51 +0200)]
conf: Refactor helpers to retrieve actual storage type

Now that the storage source definition is uniform convert the helpers to
retrieve the actual storage type to a single one.

11 years agostorage: Don't update pool available/allocation if buildVol fails
John Ferlan [Tue, 8 Apr 2014 22:54:14 +0000 (18:54 -0400)]
storage: Don't update pool available/allocation if buildVol fails

https://bugzilla.redhat.com/show_bug.cgi?id=1024159

If adding a volume to a storage pool fails during the CreateXML or
CreateXMLFrom API's, we don't want to adjust the available and
allocation values for the storage pool during storageVolDelete
since we haven't adjusted the values for the create.

Refactor storageVolDelete() a bit to create a storageVolDeleteInternal()
which will handle the primary deletion activities.  Add a parameter
updateMeta which will signify whether to update the values or not.

Adjust the calls from CreateXML and CreateXMLFrom to directly call the
DeleteInternal with the pool lock held.  This does bypass the call
to virStorageVolDeleteEnsureACL().

11 years agobuild: avoid compiler warning on shadowed name
Jean-Baptiste Rouault [Wed, 9 Apr 2014 06:50:24 +0000 (08:50 +0200)]
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]

11 years agotests: use virBhyveCapsBuild in bhyvexml2argv test
Roman Bogorodskiy [Tue, 8 Apr 2014 17:18:00 +0000 (21:18 +0400)]
tests: use virBhyveCapsBuild in bhyvexml2argv test

As we can use virBhyveCapsBuild() now, replace
testBhyveBuildCapabilities() with it.

11 years agoconf: another refactor of virstoragetest
Eric Blake [Sat, 5 Apr 2014 18:00:48 +0000 (12:00 -0600)]
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>
11 years agoconf: interleave virstoragetest structs
Eric Blake [Sat, 5 Apr 2014 17:34:32 +0000 (11:34 -0600)]
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>
11 years agoconf: test for more scenarios
Eric Blake [Fri, 4 Apr 2014 19:35:22 +0000 (13:35 -0600)]
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>
11 years agoconf: fix detection of infinite backing loop
Eric Blake [Sat, 5 Apr 2014 00:05:22 +0000 (18:05 -0600)]
conf: fix detection of infinite backing loop

While trying to refactor the backing file chain, I noticed that
if you have a self-referential qcow2 file via a relative name:

qemu-img create -f qcow2 loop 10M
qemu-img rebase -u -f qcow2 -F qcow2 -b loop loop

then libvirt was creating a chain 2 deep before realizing it
had hit a loop; furthermore, virStorageFileChainCheckBroken
was not identifying the chain as broken.  With this patch,
the loop is detected when the chain is only 1 deep; still
enough for storage volume XML to display the file, but now
with a proper error report about where the loop was found.

This patch adds a parameter to virStorageFileGetMetadataRecurse,
so that errors at the top of the chain remain unchanged; messages
issued for backing files now use the name provided by the user
instead of the canonical name (for VDSM, which uses relative
symlinks to device mapper block devices, this is actually more
useful).

* src/util/virstoragefile.c (virStorageFileGetMetadataRecurse):
Add parameter, require canonical path up front.  Mark chain
broken on OOM or loop detection.
(virStorageFileGetMetadata): Pass in canonical name.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agovmware: set the driver version
Jean-Baptiste Rouault [Tue, 8 Apr 2014 16:01:32 +0000 (18:01 +0200)]
vmware: set the driver version

Since commit 7457cbe8 the vmware driver version isn't set anymore.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agotests: add bhyve xml2xml test
Roman Bogorodskiy [Sun, 6 Apr 2014 07:44:37 +0000 (11:44 +0400)]
tests: add bhyve xml2xml test

The only implemented test for now is domain metadata test.

11 years agobhyve: add domain metadata support
Roman Bogorodskiy [Sun, 6 Apr 2014 06:07:58 +0000 (10:07 +0400)]
bhyve: add domain metadata support

Implement domainSetMetadata and domainGetMetadata driver calls.

11 years agobhyve: fix ATTRIBUTE_NONNULL usage
Roman Bogorodskiy [Tue, 8 Apr 2014 16:30:23 +0000 (20:30 +0400)]
bhyve: fix ATTRIBUTE_NONNULL usage

Fix incorrect ATTRIBUTE_NONNULL usage introduced in 17b17565
which caused build failure:

bhyve/bhyve_driver.c:127:48: error: expected ')'
bhyveDriverGetCapabilities(bhyveConnPtr driver ATTRIBUTE_NONNULL)
                                               ^
bhyve/bhyve_driver.c:127:27: note: to match this '('
bhyveDriverGetCapabilities(bhyveConnPtr driver ATTRIBUTE_NONNULL)

Pushed under the build breaker rule.

11 years agoLXC: Fix return code evaulation in lxcCheckNetNsSupport()
Richard Weinberger [Tue, 8 Apr 2014 12:26:26 +0000 (14:26 +0200)]
LXC: Fix return code evaulation in lxcCheckNetNsSupport()

Commit b9dd878f (util: make it easier to grab only regular command exit)
changed the call semantics of virCommandRun() and therefore of virRun()
too. But lxcCheckNetNsSupport() was not updated.
As consequence of this lxcCheckNetNsSupport always failed and broke LXC.

Signed-off-by: Richard Weinberger <richard@nod.at>
11 years agoFix incorrect values in redirdev ABI check error
Ján Tomko [Tue, 8 Apr 2014 12:58:22 +0000 (14:58 +0200)]
Fix incorrect values in redirdev ABI check error

My commit c9123fb introduced this copy-and-paste error.

11 years agoUse a static initializer for static mutexes
Daniel P. Berrange [Tue, 25 Mar 2014 14:54:44 +0000 (14:54 +0000)]
Use a static initializer for static mutexes

Now that we ditched our custom pthread impl for Win32, we can
use PTHREAD_MUTEX_INITIALIZER for static mutexes. This avoids
the need to use a virOnce one-time global initializer in a
number of places.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd syntax check to validate capitalization of abbreviations
Daniel P. Berrange [Thu, 13 Mar 2014 12:00:16 +0000 (12:00 +0000)]
Add syntax check to validate capitalization of abbreviations

Use a syntax-check rule to force PCI, USB and SCSI instead
of Pci, Usb and Scsi.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoReplace Pci with PCI throughout
Daniel P. Berrange [Thu, 13 Mar 2014 11:59:32 +0000 (11:59 +0000)]
Replace Pci with PCI throughout

Since it is an abbreviation, PCI should always be fully
capitalized or full lower case, never Pci.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoReplace Usb with USB throughout
Daniel P. Berrange [Thu, 13 Mar 2014 11:58:17 +0000 (11:58 +0000)]
Replace Usb with USB throughout

Since it is an abbreviation, USB should always be fully
capitalized or full lower case, never Usb.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoReplace Scsi with SCSI throughout
Daniel P. Berrange [Thu, 13 Mar 2014 11:55:46 +0000 (11:55 +0000)]
Replace Scsi with SCSI throughout

Since it is an abbreviation, SCSI should always be fully
capitalized or full lower case, never Scsi.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoSwitch systemd test to use generic dbus mock
Daniel P. Berrange [Wed, 12 Mar 2014 12:20:07 +0000 (12:20 +0000)]
Switch systemd test to use generic dbus mock

Remove the virsystemdmock.la library and instead make use
of the shared virmockdbus.la library

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoCreate a re-usable DBus LD_PRELOAD mock library
Daniel P. Berrange [Wed, 12 Mar 2014 12:15:47 +0000 (12:15 +0000)]
Create a re-usable DBus LD_PRELOAD mock library

A number of test suites want to mock the DBus APIs. To avoid
re-inventing the wheel create a re-usable virmockdbus.la
library for LD_PRELOAD usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoIntroduce a new set of helper macros for mocking symbols
Daniel P. Berrange [Tue, 11 Mar 2014 17:48:10 +0000 (17:48 +0000)]
Introduce a new set of helper macros for mocking symbols

Introduce virmock.h which provides some macros to assist in
creation of LD_PRELOAD overrides. When these are used, the
LD_PRELOAD code simply has some stubs which forward to a
wrapper function inside the main test case. This means that
logic for the test no longer has to be split between the
virXXXtest.c and virXXXmock.c files. It will also make it
possible to provide some common reusable modules for mocking
code like DBus.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agovirNetDev{Replace,Restore}MacAddress: Fix memory leak
Wangrui (K) [Tue, 8 Apr 2014 04:25:31 +0000 (04:25 +0000)]
virNetDev{Replace,Restore}MacAddress: Fix memory leak

Functions virNetDevRestoreMacAddress() and virNetDevRestoreMacAddress()
allocate memory for variable @path using virAsprintf(), but they
haven't freed that memory before returning out.

Signed-off-by: Zhang bo <oscar.zhangbo@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agobhyveConnectGetCapabilities: Fix double caps unref
Michal Privoznik [Mon, 7 Apr 2014 15:29:18 +0000 (17:29 +0200)]
bhyveConnectGetCapabilities: Fix double caps unref

At the beginning of the function we gain a reference to the driver
capabilities. Then, we call format function (*) which if failed, unref
over caps is called. Then, at the end another unref occurs.

* - Moreover, the format was not called over gained caps, but over
privconn->caps directly which is not allowed anymore.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agoSimplify bhyveDriverGetCapabilities()
Michal Privoznik [Mon, 7 Apr 2014 15:25:49 +0000 (17:25 +0200)]
Simplify bhyveDriverGetCapabilities()

The driver passed as the only argument to the function should never be
NULL so there's no need to check it. After removing it, the whole
function collapses to a single line doing ref over driver
capabilities.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agobhyve_capabilities: Add Semihalf to Copyright
Michal Privoznik [Mon, 7 Apr 2014 15:21:59 +0000 (17:21 +0200)]
bhyve_capabilities: Add Semihalf to Copyright

Since b15a2bbd we have the new bhyve_capabilities.[ch] files.
However, the copyright is held by both Roman and Semihalf.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agotests: Don't crash when creating the config object fails
Guido Günther [Mon, 7 Apr 2014 06:53:26 +0000 (08:53 +0200)]
tests: Don't crash when creating the config object fails

As observed when building in a chroot and QEMU_USER doesn't exist

11 years agotests: link against libxml2
Guido Günther [Mon, 7 Apr 2014 07:57:11 +0000 (09:57 +0200)]
tests: link against libxml2

to avoid

CCLD     storagevolxml2argvtest
/usr/bin/ld: ../src/.libs/libvirt_driver_storage_impl.a(libvirt_driver_storage_impl_la-storage_backend.o): undefined reference to symbol 'xmlFreeDoc@@LIBXML2_2.4.30'
//usr/lib/x86_64-linux-gnu/libxml2.so.2: error adding symbols: DSO missing from command line

11 years agoconf: avoid memleak on NULL path
Eric Blake [Fri, 4 Apr 2014 22:56:29 +0000 (16:56 -0600)]
conf: avoid memleak on NULL path

I noticed that the apparmor code could request metadata even
for a cdrom with no media, which would cause a memory leak of
the hash table used to look for loops in the backing chain.
But even before that, we blindly dereferenced the path for
printing a debug statement, so it is just better to enforce
that this is only used on non-NULL names.

* src/util/virstoragefile.c (virStorageFileGetMetadata): Assume
non-NULL path.
* src/util/virstoragefile.h: Annotate this.
* src/security/virt-aa-helper.c (get_files): Fix caller.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agolxc conf2xml: don't let current vcpus at 0: define won't like it
Cédric Bosdonnat [Mon, 7 Apr 2014 07:22:39 +0000 (09:22 +0200)]
lxc conf2xml: don't let current vcpus at 0: define won't like it

11 years agobhyve: connectCompareCPU support
Wojciech Macek [Mon, 7 Apr 2014 05:06:41 +0000 (07:06 +0200)]
bhyve: connectCompareCPU support

Implement support for connectCompareCPU.

11 years agobhyve: create capabilities submodule
Wojciech Macek [Mon, 7 Apr 2014 05:06:40 +0000 (07:06 +0200)]
bhyve: create capabilities submodule

- Move all capabilities functions to separate file
- Add initCPU

11 years agobhyve: support for connectBaselineCPU
Wojciech Macek [Mon, 7 Apr 2014 05:06:39 +0000 (07:06 +0200)]
bhyve: support for connectBaselineCPU

Implement bhyveConnectBaselineCPU to support OpenStack/Nova

11 years agointerface: dump inactive xml when interface isn't active
Laine Stump [Mon, 7 Apr 2014 12:32:00 +0000 (15:32 +0300)]
interface: dump inactive xml when interface isn't active

Other drivers in libvirt (e.g. network, qemu) will automatically
return the "inactive" (persistent configuration) XML of an object when
that object is inactive. The netcf backend of the interface driver
would always try to return the live status XML of the interface, even
when it was down. Although netcf does return valid XML in that case,
for bond interfaces it is missing almost all of its content, including
the <bond> subelement itself, leading to this error message from
"virsh iface-dumpxml" of a bond interface that is inactive:

  error: XML error: bond interface misses the bond element

(this is because libvirt's validation of the XML returned by netcf
always requires a <bond> element be present).

This patch modifies the interface driver netcf backend to check if the
interface is inactive, and in that case always return the inactive XML
(which will always have a <bond> element, thus eliminating the error
message, as well as making operation more in line with other drivers.

This fixes the following bug:

  https://bugzilla.redhat.com/show_bug.cgi?id=878394

11 years agohash: add common utility functions
Eric Blake [Fri, 4 Apr 2014 23:36:25 +0000 (17:36 -0600)]
hash: add common utility functions

I almost wrote a hash value free function that just called
VIR_FREE, then realized I couldn't be the first person to
do that.  Sure enough, it was worth factoring into a common
helper routine.

* src/util/virhash.h (virHashValueFree): New function.
* src/util/virhash.c (virHashValueFree): Implement it.
* src/util/virobject.h (virObjectFreeHashData): New function.
* src/libvirt_private.syms (virhash.h, virobject.h): Export them.
* src/nwfilter/nwfilter_learnipaddr.c (virNWFilterLearnInit): Use
common function.
* src/qemu/qemu_capabilities.c (virQEMUCapsCacheNew): Likewise.
* src/qemu/qemu_command.c (qemuDomainCCWAddressSetCreate):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorGetBlockInfo): Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/util/virclosecallbacks.c (virCloseCallbacksNew): Likewise.
* src/util/virkeyfile.c (virKeyFileParseGroup): Likewise.
* tests/qemumonitorjsontest.c
(testQemuMonitorJSONqemuMonitorJSONGetBlockInfo): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agotests: build viridentitytest only WITH_ATTR.
Jincheng Miao [Fri, 4 Apr 2014 13:27:24 +0000 (21:27 +0800)]
tests: build viridentitytest only WITH_ATTR.

Commit d7c4e0036 assumed all SELinux tests depended upon
securityselinuxhelper need xattr support, but forgot to
move viridentitytest under WITH_ATTR.

Reported-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
Signed-off-by: Jincheng Miao <jmiao@redhat.com>
11 years agomaint: Correctly detect wether "gluster" cli tool is accessible
Peter Krempa [Mon, 7 Apr 2014 07:24:41 +0000 (09:24 +0200)]
maint: Correctly detect wether "gluster" cli tool is accessible

The configure definition previously always defined the GLUSTER_CLI macro
and thus the code needing it wasn't compiled out if the tool wasn't
accessible.

11 years agolibvirt-guests: avoid bashism
Guido Günther [Mon, 7 Apr 2014 09:11:07 +0000 (11:11 +0200)]
libvirt-guests: avoid bashism

At least Debian uses dash to run the init scripts

11 years agoQoS: make tc filters match all traffic
Antoni S. Puimedon [Fri, 4 Apr 2014 13:39:33 +0000 (15:39 +0200)]
QoS: make tc filters match all traffic

Up until now the traffic control filters for the vNIC QoS were
matching only ip traffic. For egress traffic that was unnoticed
because the unmatched traffic would just go to the default htb class
and be shaped anyway. For ingress, though, since the policing of the
rate is done by the filter itself.

The problem is solved by changing protocol to all and making anything
match the filter.

Bug-Url: https://bugzilla.redhat.com/1084444
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agobhyve: add xml2argv tests for console
Roman Bogorodskiy [Sun, 30 Mar 2014 11:54:52 +0000 (15:54 +0400)]
bhyve: add xml2argv tests for console

11 years agobhyve: add console support through nmdm device
Roman Bogorodskiy [Sat, 15 Mar 2014 12:30:01 +0000 (16:30 +0400)]
bhyve: add console support through nmdm device

nmdm is a FreeBSD driver which allows to create a pair of tty
devices one of which is passed to the guest and second is used
by the client.

This patch adds new 'nmdm' character device type. Its definition
looks this way:

<serial type='nmdm'>
  <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
</serial>

Master is passed to the hypervisior and slave is used for client
connection.

Also implement domainOpenConsole() for bhyve driver based on that.

11 years agobhyve: domain autostart support
David Shane Holden [Sun, 23 Mar 2014 09:16:09 +0000 (13:16 +0400)]
bhyve: domain autostart support

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
11 years agoconf: track when storage type is still undetermined
Eric Blake [Wed, 2 Apr 2014 19:01:46 +0000 (13:01 -0600)]
conf: track when storage type is still undetermined

Right now, virStorageFileMetadata tracks bool backingStoreIsFile
for whether the backing string specified in metadata can be
resolved as a file (covering both block and regular file
resources) or is treated as a network protocol.  But when
merging this struct with virStorageSource, it will be easier
to just actually track which type of resource it is, as well
as have a reserved value for the case where the resource type
is unknown (or had an error during probing).

* src/util/virstoragefile.h (virStorageType): Add a placeholder
value, swap order to match similar public enum.
* src/util/virstoragefile.c (virStorage): Update string mapping.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskDefParseXML, virDomainDiskDefFormat)
(virDomainDiskSourceFormat): Adjust clients.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML):
Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agotests: refactor virstoragetest for less stack space
Eric Blake [Fri, 4 Apr 2014 02:26:59 +0000 (20:26 -0600)]
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>
11 years agotests: use C99 initialization for storage test
Eric Blake [Wed, 2 Apr 2014 23:01:13 +0000 (17:01 -0600)]
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>
11 years agoNFS storage pool: Fix libvirtd crash due to refactor edit
John Ferlan [Fri, 4 Apr 2014 13:55:00 +0000 (09:55 -0400)]
NFS storage pool: Fix libvirtd crash due to refactor edit

Commit id '18642d10' refactored the call to virCommandRunRegex()
inside a new function virStorageBackendFileSystemNetFindNFSPoolSources(),
but the cut-n-paste didn't remove the "&state".  Now that state is passed
by reference, it results in a libvirtd core with a messages entry:

"...internal error: unknown storage pool type Unknow"

11 years agoDefine CPUINFO_FILE_LEN and fix maxlen of cpuinfo file for all uses
Olivia Yin [Fri, 4 Apr 2014 01:21:06 +0000 (09:21 +0800)]
Define CPUINFO_FILE_LEN and fix maxlen of cpuinfo file for all uses

For example, the file /proc/cpuinfo for 24 cores PowerPC platform is larger than
the previous maximum size 2KB.
It will fail to start libvirtd with the error message as below:
virFileReadAll: Failed to read file '/proc/cpuinfo': Value too large for defined
data type
virSysinfoRead: internal error Failed to open /proc/cpuinfo

This patch defines CPUINFO_FILE_LEN as 10KB which is enough for most architectures.

Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
11 years agoFix Memory Leak in daemon/libvirtd.c
Nehal J Wani [Thu, 3 Apr 2014 18:13:38 +0000 (23:43 +0530)]
Fix Memory Leak in daemon/libvirtd.c

Fixes leak introduced by e562e82f

==4937== 64 bytes in 1 blocks are definitely lost in loss record 270 of 405
==4937==    at 0x4A06BE0: realloc (vg_replace_malloc.c:662)
==4937==    by 0x6FA41C4: __vasprintf_chk (vasprintf_chk.c:90)
==4937==    by 0x50C8D29: virVasprintfInternal (stdio2.h:199)
==4937==    by 0x50C8E3A: virAsprintfInternal (virstring.c:362)
==4937==    by 0x11D01A: main (libvirtd.c:1170)

Signed-off-by: Ján Tomko <jtomko@redhat.com>
11 years agolibxl: Set disk format for empty cdrom device
Stefan Bader [Thu, 27 Mar 2014 16:55:03 +0000 (17:55 +0100)]
libxl: Set disk format for empty cdrom device

The XML config for a CDROM device can be without a source path,
indicating that there is no media present. Without this change
the libxl driver fails to start a guest in that case because
the libxl library checks for the LIBXL_DISK_FORMAT_EMPTY format
type and tries to stat the NULL pointer that gets passed on.

> libxl: error: libxl_device.c:265:libxl__device_disk_set_backend:
> Disk vdev=hdc failed to stat: (null): Bad address

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
11 years agolibxl: Use id from virDomainObj inside the driver
Stefan Bader [Thu, 27 Mar 2014 16:55:02 +0000 (17:55 +0100)]
libxl: Use id from virDomainObj inside the driver

There is a domain id in the virDomain structure as well as in the
virDomainObj structure. While the former can become stale the latter
is kept up to date. So it is safer to always (virDomainObjPtr)->def->id
internally.

This will fix issues seen when managing Xen guests through libvirt from
virt-manager (not being able to get domain info after define or reboot).
This was caused both though libxlDomainGetInfo() only but there were
a lot of places that might potentially cause issues, too.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
11 years agoAdd redirdevs to ABI stability check
Ján Tomko [Wed, 2 Apr 2014 12:00:28 +0000 (14:00 +0200)]
Add redirdevs to ABI stability check

Check the bus, type of the source device (tcp vs. spicevmc)
and the device address visible in the guest.

https://bugzilla.redhat.com/show_bug.cgi?id=1035128

11 years agoUse the force flag for mkfs -t xfs
Ján Tomko [Thu, 3 Apr 2014 09:09:14 +0000 (11:09 +0200)]
Use the force flag for mkfs -t xfs

Without this, building an XFS pool on a formatted partition
fails with --overwrite.

https://bugzilla.redhat.com/show_bug.cgi?id=927172

11 years agovirsh: Make 'exit' action same as 'quit'
Li Yang [Wed, 2 Apr 2014 08:43:03 +0000 (16:43 +0800)]
virsh: Make 'exit' action same as 'quit'

For now 'virsh quit' action like this:
--------------------------------
[root@localhost /]# virsh quit
[root@localhost /]#
--------------------------------
And 'virsh exit' action:
--------------------------------
[root@localhost /]# virsh exit

[root@localhost /]#
--------------------------------
There is a small difference('/n') between them.
According to manual said:
       quit, exit
           quit this interactive terminal

And in the code they all called cmdQuit func,
They should get same actions.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
11 years agoqemu: make sure agent returns error when required data are missing
Martin Kletzander [Thu, 3 Apr 2014 05:20:25 +0000 (07:20 +0200)]
qemu: make sure agent returns error when required data are missing

Commit 5b3492fa aimed to fix this and caught one error but exposed
another one.  When agent command is being executed and the thread
waiting for the reply is woken up by an event (e.g. EOF in case of
shutdown), the command finishes with no data (rxObject == NULL), but
no error is reported, since this might be desired by the caller
(e.g. suspend through agent).  However, in other situations, when the
data are required (e.g. getting vCPUs), we proceed to getting desired
data out of the reply, but none of the virJSON*() functions works well
with NULLs.  I chose the way of a new parameter for qemuAgentCommand()
function that specifies whether reply is required and behaves
according to that.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1058149

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agoInclude PCI address in the error in virDomainNetFindIdx
Ján Tomko [Tue, 1 Apr 2014 14:26:24 +0000 (16:26 +0200)]
Include PCI address in the error in virDomainNetFindIdx

When looking up a net device by a MAC and PCI address, it is possible
that we've got a match on the MAC address but failed to match the
PCI address.

In that case, outputting just the MAC address can be confusing.

Partially resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=872028

11 years agoMove error reporting into virDomainNetFindIdx
Ján Tomko [Tue, 1 Apr 2014 13:56:55 +0000 (15:56 +0200)]
Move error reporting into virDomainNetFindIdx

Every caller checked the return value and logged an error
- one if no device with the specified MAC was found,
other if there were multiple devices matching the MAC address
(except for qemuDomainUpdateDeviceConfig which logged the same
 message in both cases).

Move the error reporting into virDomainNetFindIdx, since in both cases,
we couldn't find one single match - it's just the error messages that
differ.

11 years agotests: simplify storage test cleanup
Eric Blake [Wed, 2 Apr 2014 21:52:18 +0000 (15:52 -0600)]
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>
11 years agostorage: Report error from VolOpen by default
Cole Robinson [Wed, 2 Apr 2014 15:51:45 +0000 (11:51 -0400)]
storage: Report error from VolOpen by default

Currently VolOpen notifies the user of a potentially non-fatal failure by
returning -2 and logging a VIR_WARN or VIR_INFO. Unfortunately most
callers treat -2 as fatal but don't actually report any message with
the error APIs.

Rename the VOL_OPEN_ERROR flag to VOL_OPEN_NOERROR. If NOERROR is specified,
we preserve the current behavior of returning -2 (there's only one caller
that wants this).

However in the default case, only return -1, and actually use the error
APIs. Fix up a couple callers as a result.

11 years agoFix coverity-reported leak in virSecurityManagerGenLabel
Ján Tomko [Wed, 2 Apr 2014 12:37:35 +0000 (14:37 +0200)]
Fix coverity-reported leak in virSecurityManagerGenLabel

Coverity complains about a possible leak of seclabel if
!sec_managers[i]->drv->domainGenSecurityLabel is true
and the seclabel might be overwritten by the next iteration
of the loop.

This leak should never happen, because every security driver
has domainGenSecurityLabel defined.

11 years agoconf: modify tracking of encrypted images
Eric Blake [Wed, 2 Apr 2014 01:13:51 +0000 (19:13 -0600)]
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>
11 years agoconf: drop redundant parameters during probe
Eric Blake [Tue, 1 Apr 2014 23:52:41 +0000 (17:52 -0600)]
conf: drop redundant parameters during probe

Now that each virStorageSource can track allocation information,
and given that we already have the information without extra
syscalls, it's easier to just always populate the information
directly into the struct than it is to sometimes pass the address
of the struct members down the call chain.

* src/storage/storage_backend.h (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Update signature.
* src/storage/storage_backend.c (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Always populate struct
members instead.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol): Update client.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: track sizes directly in source struct
Eric Blake [Tue, 1 Apr 2014 23:43:36 +0000 (17:43 -0600)]
conf: track sizes directly in source struct

One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile.  As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file.  This sets up the fields for
the tracking, although it does not modify XML to display any
new information.

* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.

11 years agoconf: use common struct in storage volumes
Eric Blake [Tue, 1 Apr 2014 21:11:30 +0000 (15:11 -0600)]
conf: use common struct in storage volumes

A fairly smooth transition.  And now that domain disks and
storage volumes share a common struct, it opens the doors for
a future patch to expose more details in the XML for both
objects.

* src/conf/storage_conf.h (_virStorageVolTarget): Delete.
(_virStorageVolDef): Use common type.
* src/conf/storage_conf.c (virStorageVolDefFree)
(virStorageVolTargetDefFormat): Update clients.
* src/storage/storage_backend.h: Likewise.
* src/storage/storage_backend.c
(virStorageBackendDetectBlockVolFormatFD)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: move volume structs to util/
Eric Blake [Sun, 30 Mar 2014 03:21:06 +0000 (21:21 -0600)]
conf: move volume structs to util/

Another step towards unification of structures.  While we might
not expose everything in XML via domain disk as we do for
storage volume pointer, both places want to deal with (at least
part of) the backing chain; therefore, moving towards a single
struct usable from both contexts will make the backing chain
code more reusable.

* src/conf/storage_conf.h (_virStoragePerms)
(virStorageTimestamps): Move...
* src/util/virstoragefile.h: ...here.
(_virStorageSource): Add more fields.
* src/util/virstoragefile.c (virStorageSourceClear): Clean
additional fields.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: tweak volume target struct details
Eric Blake [Sun, 30 Mar 2014 02:27:44 +0000 (20:27 -0600)]
conf: tweak volume target struct details

Some preparatory work before consolidating storage volume
structs with the rest of virstoragefile.  Making these
changes allows a volume target to be much closer to (a
subset of) the virStorageSource struct.

Making perms be a pointer allows it to be optional if we
have a storage pool that doesn't expose permissions in a
way we can access.  It also allows future patches to
optionally expose permissions details learned about a disk
image via domain <disk> listings, rather than just
limiting it to storage volume listings.

Disk partition types was only used by internal code to
control what type of partition to create when carving up
an MS-DOS partition table storage pool (and is not used
for GPT partition tables or other storage pools).  It was
not exposed in volume XML, and as it is more closely
related to extent information of the overall block device
than it is to the <target> information describing the host
file.  Besides, if we ever decide to expose it in XML down
the road, we can move it back as needed.

* src/conf/storage_conf.h (_virStorageVolTarget): Change perms to
pointer, enhance comments.  Move partition type...
(_virStorageVolSource): ...here.
* src/conf/storage_conf.c (virStorageVolDefFree)
(virStorageVolDefParseXML, virStorageVolTargetDefFormat): Update
clients.
* src/storage/storage_backend_fs.c (createFileDir): Likewise.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(virStorageBackendCreateRaw, virStorageBackendCreateExecCommand)
(virStorageBackendUpdateVolTargetInfoFD): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskPartTypeToCreate): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: manage disk source by struct instead of pieces
Eric Blake [Mon, 31 Mar 2014 18:07:04 +0000 (12:07 -0600)]
conf: manage disk source by struct instead of pieces

Now that we have a dedicated type for representing a disk source,
we might as well parse and format directly into that type instead
of piecemeal into pointers to members of the type.

* src/conf/domain_conf.h (virDomainDiskSourceDefFormatInternal)
(virDomainDiskSourceDefParse): Rename...
(virDomainDiskSourceFormat, virDomainDiskSourceParse): ...and
compress signatures.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskSourceFormat): Rewrite to use common struct.
(virDomainDiskSourceDefFormat): Delete.
(virDomainDiskDefParseXML, virDomainDiskDefFormat): Update
callers.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotDiskDefFormat): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>