diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 41ce0a978d..635fdcc5a4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1357,6 +1357,45 @@ virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
     return ret;
 }
 
+
+/**
+ * virQEMUDriverGetDomainCapabilities:
+ *
+ * Build a virDomainCapsPtr instance for the passed data.
+ *
+ * Returns: a reference to a virDomainCapsPtr instance or NULL
+ */
+virDomainCapsPtr
+virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
+                                   virQEMUCapsPtr qemuCaps,
+                                   const char *machine,
+                                   virArch arch,
+                                   virDomainVirtType virttype)
+{
+    virDomainCapsPtr ret = NULL, domCaps = NULL;
+    virCapsPtr caps = NULL;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,
+                                     arch, virttype)))
+        goto cleanup;
+
+    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
+                                  cfg->firmwares, cfg->nfirmwares) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, domCaps);
+ cleanup:
+    virObjectUnref(domCaps);
+    virObjectUnref(cfg);
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 struct _qemuSharedDeviceEntry {
     size_t ref;
     char **domains; /* array of domain names */
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 14c9d15a72..ddf5ea4b8f 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -331,6 +331,13 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
                                         bool refresh);
 
+virDomainCapsPtr
+virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
+                                   virQEMUCapsPtr qemuCaps,
+                                   const char *machine,
+                                   virArch arch,
+                                   virDomainVirtType virttype);
+
 typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
 typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7e5bbc3cc9..3e8ae8a4dc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19829,19 +19829,12 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
     virArch arch;
     virDomainVirtType virttype;
     virDomainCapsPtr domCaps = NULL;
-    virQEMUDriverConfigPtr cfg = NULL;
-    virCapsPtr caps = NULL;
 
     virCheckFlags(0, ret);
 
     if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
         return ret;
 
-    cfg = virQEMUDriverGetConfig(driver);
-
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-        goto cleanup;
-
     qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache,
                                              emulatorbin,
                                              arch_str,
@@ -19851,18 +19844,13 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
     if (!qemuCaps)
         goto cleanup;
 
-    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,
-                                     arch, virttype)))
-        goto cleanup;
-
-    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
-                                  cfg->firmwares, cfg->nfirmwares) < 0)
+    if (!(domCaps = virQEMUDriverGetDomainCapabilities(driver,
+                                                       qemuCaps, machine,
+                                                       arch, virttype)))
         goto cleanup;
 
     ret = virDomainCapsFormat(domCaps);
  cleanup:
-    virObjectUnref(cfg);
-    virObjectUnref(caps);
     virObjectUnref(domCaps);
     virObjectUnref(qemuCaps);
     return ret;
