[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 5/6] Add virStorageFileGetMetadata() helper



* src/util/storage_file.c: add virStorageFileGetMetadata() so that
  the caller does not need to open the file
---
 src/libvirt_private.syms |    1 +
 src/util/storage_file.c  |   20 ++++++++++++++++++++
 src/util/storage_file.h  |    3 +++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4890032..635c6b6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -393,6 +393,7 @@ virStorageGenerateQcowPassphrase;
 # storage_file.h
 virStorageFileFormatTypeToString;
 virStorageFileFormatTypeFromString;
+virStorageFileGetMetadata;
 virStorageFileGetMetadataFromFD;
 
 # threads.h
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index e674713..44057d2 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -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;
+}
diff --git a/src/util/storage_file.h b/src/util/storage_file.h
index e34d749..b0abcaf 100644
--- a/src/util/storage_file.h
+++ b/src/util/storage_file.h
@@ -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,
-- 
1.6.2.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]