<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 01/05/2017 09:46 AM, Roman
      Bogorodskiy wrote:<br>
    </div>
    <blockquote cite="mid:20170105144634.28675-2-bogorodskiy@gmail.com"
      type="cite">
      <pre wrap="">From: Fabian Freyer <a class="moz-txt-link-rfc2396E" href="mailto:fabian.freyer@physik.tu-berlin.de"><fabian.freyer@physik.tu-berlin.de></a>

Introduce a BHYVE_CAP_AHCI32SLOT capability that shows
if 32 devices per SATA controller are supported, and
a bhyveProbeCapsAHCI32Slot function that probes it.
---
 src/bhyve/bhyve_capabilities.c | 59 +++++++++++++++++++++++++++++++++++-------
 src/bhyve/bhyve_capabilities.h |  3 ++-
 2 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 10c33b9d7..83e3ae1b4 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -168,19 +168,13 @@ virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps)
     return ret;
 }
 
-int
-virBhyveProbeCaps(unsigned int *caps)
+static int
+bhyveProbeCapsRTC_UTC(unsigned int *caps, char *binary)
 {
-    char *binary, *help;
+    char *help;
     virCommandPtr cmd = NULL;
     int ret = 0, exit;
 
-    binary = virFindFileInPath("bhyve");
-    if (binary == NULL)
-        goto out;
-    if (!virFileIsExecutable(binary))
-        goto out;
-
     cmd = virCommandNew(binary);
     virCommandAddArg(cmd, "-h");
     virCommandSetErrorBuffer(cmd, &help);
@@ -195,6 +189,53 @@ virBhyveProbeCaps(unsigned int *caps)
  out:
     VIR_FREE(help);
     virCommandFree(cmd);
+    return ret;
+}
+
+static int
+bhyveProbeCapsAHCI32Slot(unsigned int *caps, char *binary)
+{
+    char *error;
+    virCommandPtr cmd = NULL;
+    int ret = 0, exit;
+
+    cmd = virCommandNew(binary);
+    virCommandAddArgList(cmd, "-s", "0,ahci", NULL);
+    virCommandSetErrorBuffer(cmd, &error);</pre>
    </blockquote>
    <br>
    Too bad there isn't some way you could learn both of these with a
    single run of the binary.<br>
    <br>
    <blockquote cite="mid:20170105144634.28675-2-bogorodskiy@gmail.com"
      type="cite">
      <pre wrap="">+    if (virCommandRun(cmd, &exit) < 0) {
+        ret = -1;
+        goto out;
+    }
+
+    if (strstr(error, "pci slot 0:0: unknown device \"ahci\"") == NULL)
+        *caps |= BHYVE_CAP_AHCI32SLOT;</pre>
    </blockquote>
    <br>
    That seems like a fairly fragile check. Are you certain there aren't
    older versions where the error string is different?<br>
    <br>
    Anyway, lacking any better check, ACK.<br>
    <blockquote cite="mid:20170105144634.28675-2-bogorodskiy@gmail.com"
      type="cite">
      <pre wrap="">+
+ out:
+    VIR_FREE(error);
+    virCommandFree(cmd);
+    return ret;
+}
+
+
+int
+virBhyveProbeCaps(unsigned int *caps)
+{
+    char *binary;
+    int ret = 0;
+
+    binary = virFindFileInPath("bhyve");
+    if (binary == NULL)
+        goto out;
+    if (!virFileIsExecutable(binary))
+        goto out;
+
+    if ((ret = bhyveProbeCapsRTC_UTC(caps, binary)))
+        goto out;
+
+    if ((ret = bhyveProbeCapsAHCI32Slot(caps, binary)))
+        goto out;
+
+ out:
     VIR_FREE(binary);
     return ret;
 }
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 8e7646dfa..55581bd68 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -37,7 +37,8 @@ typedef enum {
 } virBhyveGrubCapsFlags;
 
 typedef enum {
-    BHYVE_CAP_RTC_UTC = 1,
+    BHYVE_CAP_RTC_UTC = 1 << 0,
+    BHYVE_CAP_AHCI32SLOT = 1 << 1,
 } virBhyveCapsFlags;
 
 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>