On 05/22/2014 07:47 AM, Peter Krempa wrote:
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.
---
src/storage/storage_backend.h | 7 ++++
src/storage/storage_backend_fs.c | 30 ++++++++++++++++
src/storage/storage_backend_gluster.c | 66 +++++++++++++++++++++++++++++++++++
src/storage/storage_driver.c | 40 +++++++++++++++++++++
src/storage/storage_driver.h | 3 ++
5 files changed, 146 insertions(+)
+++ b/src/storage/storage_backend_gluster.c
@@ -638,6 +638,71 @@ virStorageFileBackendGlusterStat(virStorageSourcePtr src,
}
+static ssize_t
+virStorageFileBackendGlusterReadHeader(virStorageSourcePtr src,
+ ssize_t max_len,
+ char **buf)
+{
+ virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
+ glfs_fd_t *fd = NULL;
+ size_t alloc = 0;
+ size_t size = 0;
+ int save_errno;
+ ssize_t ret = -1;
+
+ *buf = NULL;
+
+ if (!(fd = glfs_open(priv->vol, src->path, O_RDONLY))) {
+ virReportSystemError(errno, _("Failed to open file '%s'"),
+ src->path);
+ goto cleanup;
+ }
+
+ /* code below is shamelesly stolen from saferead_lim */
s/shamelesly/shamelessly/
+ if (!src->drv->backend->storageFileReadHeader) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("storage file header reading is not supported for "
+ "storage type %s (protocol: %s)'"),
+ virStorageTypeToString(src->type),
+ virStorageNetProtocolTypeToString(src->protocol));
Oh slick - the earlier patch that adds protocol==0 as "none" rather than
"nbd" makes this message tolerable even for non-network storage types.
Less special-casing is always good :)
+ return -1;
Isn't this supposed to be 'return -2' according to the function
documentation?
ACK if you agree about the return value fix, and if it is the only
change you make besides the typo fix.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org