Commit Graph

530 Commits

Author SHA1 Message Date
Ján Tomko
490bf29d50 Log an error when we fail to set the COW attribute
Coverity complains about the return value of ioctl not being checked.

Even though we carry on when this fails (just like qemu-img does),
we can log an error.
2014-07-17 14:32:29 +02:00
Peter Krempa
11d28050c5 storage: Split out volume wiping as separate backend function
For non-local storage drivers we can't expect to use the "scrub" tool to
wipe the volume. Split the code into a separate backend function so that
we can add protocol specific code later.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1118710
2014-07-17 10:12:34 +02:00
Peter Krempa
4d799b65cd storage: wipe: Move helper code into storage backend
The next patch will move the storage volume wiping code into the
individual backends. This patch splits out the common code to wipe a
local volume into a separate backend helper so that the next patch is
simpler.
2014-07-17 10:12:34 +02:00
Chunyan Liu
a9fd30e633 storagevol: add nocow to vol xml
Add 'nocow' to storage volume xml so that user can have an option
to set NOCOW flag to the newly created volume. It's useful on btrfs
file system to enhance performance.

Btrfs has low performance when hosting VM images, even more when the guest
in those VM are also using btrfs as file system. One way to mitigate this
bad performance is to turn off COW attributes on VM files. Generally, there
are two ways to turn off COW on btrfs: a) by mounting fs with nodatacow,
then all newly created files will be NOCOW. b) per file. Add the NOCOW file
attribute. It could only be done to empty or new files.

This patch tries the second way, according to 'nocow' option, it could set
NOCOW flag per file:
for raw file images, handle 'nocow' in libvirt code; for non-raw file images,
pass 'nocow=on' option to qemu-img, and let qemu-img to handle that (requires
qemu-img version >= 2.1).

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-07-16 13:35:20 +02:00
Peter Krempa
70120e2f5d storage: fs: Don't fail volume update if backing store isn't accessible
When the backing store of a volume wasn't accessible while updating the
volume definition the call would fail altogether. In cases where we
currently (incorrectly) treat remote backing stores as local one this
might lead to strange errors.

Ignore the opening errors until we figure out how to track proper volume
metadata.
2014-07-16 11:42:52 +02:00
Peter Krempa
dc2943579f storage: fs: Properly parse backing store info
Use the backing store parser to properly create the information about a
volume's backing store. Unfortunately as the storage driver isn't
prepared to allow volumes backed by networked filesystems add a
workaround that will avoid changing the XML output.
2014-07-16 11:42:51 +02:00
Peter Krempa
cd4d547576 storage: fs: Process backing store data in virStorageBackendProbeTarget
Move the processing of the backend metadata directly to the helper
instead of passing it through arguments to the function.
2014-07-16 11:42:51 +02:00
Peter Krempa
9f20d6a56d storage: backend: fs: Touch up coding style
virStorageBackendFileSystemRefresh() used "cleanup" label just for error
exits and didn't meet libvirt's standard for braces in one case.
2014-07-16 11:42:51 +02:00
Peter Krempa
15213d1e5d storage: Track backing store of a volume in the target struct
As we have a nested pointer for storing the backing store of a volume
there's no need to store it in a separate struct.
2014-07-16 11:42:51 +02:00
Peter Krempa
c861750ee9 storage: backend: Fix formatting of function arguments 2014-07-16 11:42:51 +02:00
Ján Tomko
d7dedc3650 Fix error on fs pool build failure
https://bugzilla.redhat.com/show_bug.cgi?id=1119592

Introduced by commit 62927dd v0.7.6.
2014-07-16 09:39:57 +02:00
Peter Krempa
589c2ad93f storage: Split out volume upload/download as separate backend function
For non-local storage drivers we can't expect to use the FDStream
backend for up/downloading volumes. Split the code into a separate
backend function so that we can add protocol specific code later.
2014-07-11 09:54:08 +02:00
Peter Krempa
96e00c4fc1 storage: file: Tolerate NULL src when uninitializing the backend
Allow de-init of null storage sources.
2014-07-08 14:27:19 +02:00
Peter Krempa
912911a497 storage: gluster: Optimize header reader functions
The gluster code had two functions for reading volume headers, remove
one and reuse the second one.
2014-07-08 11:36:18 +02:00
Peter Krempa
25924dec0f util: storage: Allow specifying format for virStorageFileGetMetadataFromBuf
To allow reusing this function in the qemu driver we need to allow
specifying the storage format. Also separate return of the backing store
path now isn't necessary.
2014-07-08 11:35:50 +02:00
John Ferlan
97e3397cde Utilize virDomainDiskAuth for storage pools
Replace the authType, chap, and cephx unions in virStoragePoolSource
with a single pointer to a virStorageAuthDefPtr.  Adjust all users of
the previous chap/cephx and secret unions with the source->auth data.
2014-07-03 17:39:15 -04:00
Ján Tomko
92a8e72f9d Use virBufferCheckError everywhere we report OOM error
Replace:
if (virBufferError(&buf)) {
    virBufferFreeAndReset(&buf);
    virReportOOMError();
    ...
}

with:
if (virBufferCheckError(&buf) < 0)
    ...

This should not be a functional change (unless some callers
misused the virBuffer APIs - a different error would be reported
then)
2014-07-03 10:48:14 +02:00
Ján Tomko
275f022454 More indentation fixes
Reindent nwfilter gentech driver and one block in rbd storage backend.
2014-07-03 10:41:15 +02:00
Peter Krempa
f412fc9ffa storage: gluster: Fix header reader function
Advance the right pointer to actually append to the buffer. We were
lucky that all reads were completed in one try.
2014-07-01 17:39:50 +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
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
Ján Tomko
7086d7fab9 Free file header in virStorageFileGetMetadataRecurse
Introduced by commit 2bdb8b9
2014-06-24 14:41:19 +02:00
Peter Krempa
2cff94cc85 storage: gluster: Avoid name shadow on older compilers
s/link/linkpath/g in virStorageFileBackendGlusterReadlinkCallback as
older gcc complains.
2014-06-24 11:22:17 +02:00
Peter Krempa
975f0e2eb4 storage: gluster: Add backend to return unique storage file path
Use virStorageFileSimplifyPathInternal to canonicalize gluster paths
via a callback and use it for the unique volume path retrieval API.
2014-06-24 10:45:43 +02:00
Giuseppe Scrivano
d6e92bfa38 storage: report VIR_ERR_NO_STORAGE_VOL when the file doesn't exist
Report VIR_ERR_NO_STORAGE_VOL instead of a system error when lstat
fails because the file doesn't exist.

Fixes this problem in virt-install:

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2014-06-13 10:05:33 -06:00
Peter Krempa
f332ffc0dc storage: volume: Rework lookup of volume objects
Add a helper to do all the lookup steps and remove a ton of duplicated
code.
2014-06-12 10:26:56 +02:00
Peter Krempa
30d99eb534 storage: Clean up unlocking of storage pool objects
Most of the APIs now don't reach the cleanup section when the pool
object wasn't found and thus don't need to check before unlocking it.
2014-06-12 09:55:17 +02:00
Peter Krempa
efd892761e storage: pool: Fix handling of errors on pool lookup failure
Rework internal pool lookup code to avoid printing the raw UUID buffer
in the case a storage pool can't be found:

 $ virsh pool-name e012ace0-0460-5810-39ef-1bce5fa5a4dd
 error: failed to get pool 'e012ace0-0460-5810-39ef-1bce5fa5a4dd'
 error: Storage pool not found: no storage pool with matching uuid à¬à`X9ï_¥¤Ý

The rework is mostly done by switching the lookup code to the newly
introduced helper virStoragePoolObjFromStoragePool

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1104993
2014-06-12 09:55:08 +02:00
Ján Tomko
c110cdb2bc Fix storage format probing
Commit fff74b2 moved the probing into virStorageFileGetMetadataFromBuf
but didn't update the format in volume definition.

https://bugzilla.redhat.com/show_bug.cgi?id=1104908
2014-06-05 18:58:58 +02:00
Ján Tomko
effbb11e29 Simplify conditions in virStorageBackendProbeTarget
Jump out early if no metadata was detected (for directories).
Join the error and cleanup labels.
2014-06-05 18:46:20 +02:00
Ján Tomko
febcb89c5b Don't reuse 'ret' variable in virStorageBackendProbeTarget
To match the convention:
ret - current function's return value
rc - other function's return values
2014-06-05 18:19:16 +02:00
Peter Krempa
1423ae296f storage: Traverse backing chains of network disks
Now we don't need to skip backing chain detection for remote disks.
2014-06-03 09:27:24 +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
6cdff20c2a storage: Switch metadata crawler to use storage driver file access check
Use virStorageFileAccess() to to check whether the file is accessible in
the main part of the metadata crawler.
2014-06-03 09:27:23 +02:00
Peter Krempa
2bdb8b965b storage: Switch metadata crawler to use storage driver to read headers
Use virStorageFileReadHeader() to read headers of storage files possibly
on remote storage to retrieve the image metadata.

The backend information is now parsed by
virStorageFileGetMetadataInternal which is now exported from the util
source and virStorageFileGetMetadataFromFDInternal now doesn't need to
be exported.
2014-06-03 09:27:23 +02:00
Peter Krempa
395171f87f storage: Switch metadata crawler to use storage driver to get unique path
Use the virStorageFileGetUniqueIdentifier() function to get a unique
identifier regardless of the target storage type instead of relying on
canonicalize_path().

A new function that checks whether we support a given image is
introduced to avoid errors for unimplemented backends.
2014-06-03 09:27:23 +02:00
Peter Krempa
edfd6127c1 storage: backend: Add possibility to suppress errors from backend lookup
Add a new function wrapper and tweak the storage file backend lookup
function so that it can be used without reporting error. This will be
useful in the metadata crawler code where we need silently break if
metadata retrieval is not supported for the current storage type.
2014-06-03 09:27:23 +02:00
Peter Krempa
d4c0ceae1b storage: Determine the local storage type right away
When walking the backing chain we previously set the storage type to
_FILE and let the virStorageFileGetMetadataFromFDInternal update it to
the correct type later on.

This patch moves the actual storage type determination to the place
where we parse the backing store name so that the code can later be
switched to use virStorageFileReadHeader() directly.
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
Peter Krempa
4cb2505557 storage: Add API to check accessibility of storage volumes
Add a storage driver API equivalent of the access() function.
Implementations for the filesystem and gluster backends are provided.
2014-06-03 09:27:23 +02:00
Peter Krempa
684ec651e9 storage: backend: Add unique id retrieval API
Different protocols have different means to uniquely identify a storage
file. This patch implements a storage driver API to retrieve a unique
string describing a volume. The current implementation works for local
storage only and returns the canonical path of the volume.

To add caching support the local filesystem driver now has a private
structure holding the cached string, which is created only when it's
initially accessed.

This patch provides the implementation for local files only for start.
2014-06-03 09:27:22 +02:00
Peter Krempa
34d86185ec storage: fs: Drop-in replace use of virStorageFileGetMetadataFromBuf
Use virStorageFileGetMetadataFromFD instead in
virStorageBackendProbeTarget as it now returns all required data and the
storage file is already open in a filedescriptor.

Also fix improper error code being returned when virFileReadHeaderFD
would fail as virStorageBackendUpdateVolTargetInfoFD would set the
return code to 0.
2014-05-28 19:23:35 +02:00
Daniel Veillard
f07d24a6b8 Fix an extra ' in a translated string
Raised by ukrainian translator Yuri Chornoivan
https://fedora.transifex.com/projects/p/libvirt/translate/#uk/strings/25483059
2014-05-26 21:51:26 +08:00
Peter Krempa
81271a9261 storage: Add storage file API to read file headers
Add storage driver based functions to access headers of storage files
for metadata extraction. Along with this patch a local filesystem and
gluster via libgfapi implementation is provided. The gluster
implementation is based on code of the saferead_lim function.
2014-05-23 10:57:33 +02:00
Peter Krempa
ae26731e1f storage: Add support for access to files using provided uid/gid
To allow using the storage driver APIs to access files on various
storage sources in a universal fashion possibly on storage such as nfs
with root squash we'll need to store the desired uid/gid in the
metadata.

Add new initialisation API that will store the desired uid/gid and a
wrapper for the current use. Additionally add docs for the two APIs.
2014-05-23 10:48:48 +02:00
Peter Krempa
0620bd42ad storage: Rework debugging of storage file access through storage driver
Print the debug statements of individual file access functions from the
main API functions instead of the individual backend functions.

Also enhance initialization debug messages on a per-backend basis.
2014-05-23 09:25:52 +02:00
Peter Krempa
1115f975b4 storage: Store gluster volume name separately
The gluster volume name was previously stored as part of the source path
string. This is unfortunate when we want to do operations on the path as
the volume is used separately.

Parse and store the volume name separately for gluster storage volumes
and use the newly stored variable appropriately.
2014-05-23 09:25:51 +02:00
Eric Blake
ab5178188f maint: shorten 'TypeType' function names
The VIR_ENUM_DECL/VIR_ENUM_IMPL helper macros already append 'Type'
to the enum name being converted; it looks silly to have functions
with 'TypeType' in their name.  Even though some of our enums have
to have a 'Type' suffix, the corresponding string conversion
functions do not.

* src/conf/secret_conf.h (VIR_ENUM_DECL): Rename virSecretUsageType.
* src/conf/storage_conf.h (VIR_ENUM_DECL): Rename
virStoragePoolAuthType, virStoragePoolSourceAdapterType,
virStoragePartedFsType.
* src/conf/domain_conf.c (virDomainDiskDefParseXML)
(virDomainFSDefParseXML, virDomainFSDefFormat): Update callers.
* src/conf/secret_conf.c (virSecretDefParseUsage)
(virSecretDefFormatUsage): Likewise.
* src/conf/storage_conf.c (virStoragePoolDefParseAuth)
(virStoragePoolDefParseSource, virStoragePoolSourceFormat):
Likewise.
* src/lxc/lxc_controller.c (virLXCControllerSetupLoopDevices):
Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskPartFormat): Likewise.
* src/util/virstorageencryption.c (virStorageEncryptionSecretParse)
(virStorageEncryptionSecretFormat): Likewise.
* tools/virsh-secret.c (cmdSecretList): Likewise.
* src/libvirt_private.syms (secret_conf.h, storage_conf.h): Export
corrected names.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-16 00:22:18 -06:00
Julio Faracco
1ce86e62e1 conf: use typedefs for enums in "src/conf/storage_conf.h"
In "src/conf/" there are many enumeration (enum) declarations.
Similar to the recent cleanup to "src/util" directory, it's
better to use a typedef for variable types, function types and
other usages. Other enumeration and folders will be changed to
typedef's in the future. Most of the files changed in this
commit are related to storage (storage_conf) enums.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-14 10:18:35 -06:00
John Ferlan
e1e4483c90 storage: Resolve issues in failure path
https://bugzilla.redhat.com/show_bug.cgi?id=1092882

Refactoring in commit id '0c2305b3' resulted in the wrong storage
volume object being passed to the new storageVolDeleteInternal().
It should have passed 'voldef' which is the address found in the
pool->volumes.objs[i] array.  By passing 'voldef', the DeleteInternal
code will find and remove the voldef from the volumes.objs[] list.
2014-05-07 10:21:18 -04:00