[libvirt] [PATCH v2 1/5] Implement public API for virDomainGetFSInfo

Tomoki Sekiyama tomoki.sekiyama at hds.com
Mon Nov 17 23:26:53 UTC 2014


virDomainGetFSInfo returns a list of filesystems information mounted in the
guest, which contains mountpoints, device names, filesystem types, and
device aliases named by libvirt. This will be useful, for example, to
specify mountpoints to fsfreeze when taking snapshot of a part of disks.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama at hds.com>
---
 include/libvirt/libvirt-domain.h |   21 ++++++++++++
 src/driver-hypervisor.h          |    6 +++
 src/libvirt.c                    |   66 ++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |    6 +++
 4 files changed, 99 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 1fac2a3..c889cd0 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3456,6 +3456,27 @@ int virDomainFSThaw(virDomainPtr dom,
                     unsigned int nmountpoints,
                     unsigned int flags);
 
+/**
+ * virDomainFSInfo:
+ *
+ * The data structure containing mounted file systems within a guset
+ *
+ */
+typedef struct _virDomainFSInfo virDomainFSInfo;
+typedef virDomainFSInfo *virDomainFSInfoPtr;
+struct _virDomainFSInfo {
+    char *mountpoint; /* path to mount point */
+    char *name;       /* device name in the guest (e.g. "sda1") */
+    char *type;       /* filesystem type */
+    char **devAlias;  /* NULL-terminated array of disk device aliases */
+};
+
+void virDomainFSInfoFree(virDomainFSInfoPtr info);
+
+int virDomainGetFSInfo(virDomainPtr dom,
+                       virDomainFSInfoPtr **info,
+                       unsigned int flags);
+
 int virDomainGetTime(virDomainPtr dom,
                      long long *seconds,
                      unsigned int *nseconds,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index ad66629..9f26b13 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1139,6 +1139,11 @@ typedef int
                       unsigned int flags);
 
 typedef int
+(*virDrvDomainGetFSInfo)(virDomainPtr dom,
+                         virDomainFSInfoPtr **info,
+                         unsigned int flags);
+
+typedef int
 (*virDrvNodeGetFreePages)(virConnectPtr conn,
                           unsigned int npages,
                           unsigned int *pages,
@@ -1390,6 +1395,7 @@ struct _virHypervisorDriver {
     virDrvConnectGetDomainCapabilities connectGetDomainCapabilities;
     virDrvConnectGetAllDomainStats connectGetAllDomainStats;
     virDrvNodeAllocPages nodeAllocPages;
+    virDrvDomainGetFSInfo domainGetFSInfo;
 };
 
 
diff --git a/src/libvirt.c b/src/libvirt.c
index 3abedb4..34eaed1 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1401,6 +1401,72 @@ virConnectOpenAuth(const char *name,
 
 
 /**
+ * virDomainGetFSInfo:
+ * @dom: a domain object
+ * @info: a pointer to a variable to store an array of mount points information
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Get a list of mapping informaiton for each mounted file systems within the
+ * specified guest and the disks.
+ *
+ * Returns the number of returned mount points, or -1 in case of error.
+ * On success, the array of the information is stored into @info. The caller is
+ * responsible for calling virDomainFSInfoFree() on each array element, then
+ * calling free() on @info. On error, @info is set to NULL.
+ */
+int
+virDomainGetFSInfo(virDomainPtr dom,
+                   virDomainFSInfoPtr **info,
+                   unsigned int flags)
+{
+    VIR_DOMAIN_DEBUG(dom, "info=%p, flags=%x", info, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(dom, -1);
+    virCheckReadOnlyGoto(dom->conn->flags, error);
+
+    if (dom->conn->driver->domainGetFSInfo) {
+        int ret = dom->conn->driver->domainGetFSInfo(dom, info, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(dom->conn);
+    return -1;
+}
+
+
+/**
+ * virDomainFSInfoFree:
+ * @info: pointer to a FSInfo object
+ *
+ * Frees all the memory occupied by @info.
+ */
+void
+virDomainFSInfoFree(virDomainFSInfoPtr info)
+{
+    char **alias;
+
+    if (!info)
+        return;
+
+    VIR_FREE(info->mountpoint);
+    VIR_FREE(info->name);
+    VIR_FREE(info->type);
+
+    for (alias = info->devAlias; alias && *alias; alias++)
+        VIR_FREE(*alias);
+    VIR_FREE(info->devAlias);
+}
+
+
+
+/**
  * virConnectClose:
  * @conn: pointer to the hypervisor connection
  *
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 5f95802..e4c2df1 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -684,4 +684,10 @@ LIBVIRT_1.2.9 {
         virNodeAllocPages;
 } LIBVIRT_1.2.8;
 
+LIBVIRT_1.2.11 {
+    global:
+        virDomainFSInfoFree;
+        virDomainGetFSInfo;
+} LIBVIRT_1.2.9;
+
 # .... define new API here using predicted next version number ....




More information about the libvir-list mailing list