]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add virStorageFileGetMetadata() helper
authorMark McLoughlin <markmc@redhat.com>
Tue, 29 Sep 2009 08:41:23 +0000 (09:41 +0100)
committerMark McLoughlin <markmc@redhat.com>
Wed, 30 Sep 2009 09:37:00 +0000 (10:37 +0100)
* src/util/storage_file.c: add virStorageFileGetMetadata() so that
  the caller does not need to open the file

src/libvirt_private.syms
src/util/storage_file.c
src/util/storage_file.h

index 9eb4b77974c6f06bd8da9ae08ace4c52154de5f5..b699fb2187aa1a962afa16ed876583f80a0c9938 100644 (file)
@@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase;
 # storage_file.h
 virStorageFileFormatTypeToString;
 virStorageFileFormatTypeFromString;
+virStorageFileGetMetadata;
 virStorageFileGetMetadataFromFD;
 
 # threads.h
index e674713d12d8dfaba085d11454e6cb6fce117a97..44057d2fceb481ee22a664ea8a048e5d00bb967c 100644 (file)
@@ -25,6 +25,7 @@
 #include "storage_file.h"
 
 #include <unistd.h>
+#include <fcntl.h>
 #include "memory.h"
 #include "virterror_internal.h"
 
@@ -402,3 +403,22 @@ virStorageFileGetMetadataFromFD(virConnectPtr conn,
 
     return 0;
 }
+
+int
+virStorageFileGetMetadata(virConnectPtr conn,
+                          const char *path,
+                          virStorageFileMetadata *meta)
+{
+    int fd, ret;
+
+    if ((fd = open(path, O_RDONLY)) < 0) {
+        virReportSystemError(conn, errno, _("cannot open file '%s'"), path);
+        return -1;
+    }
+
+    ret = virStorageFileGetMetadataFromFD(conn, path, fd, meta);
+
+    close(fd);
+
+    return ret;
+}
index e34d7495a6ac83a4564c4b3f2b8c4e28ec923b18..b0abcafe89f4412d35f83eeb9ec2951cc3aee058 100644 (file)
@@ -51,6 +51,9 @@ typedef struct _virStorageFileMetadata {
     bool encrypted;
 } virStorageFileMetadata;
 
+int virStorageFileGetMetadata(virConnectPtr conn,
+                              const char *path,
+                              virStorageFileMetadata *meta);
 int virStorageFileGetMetadataFromFD(virConnectPtr conn,
                                     const char *path,
                                     int fd,