From b1e6324ca272acd69573571fcb5184b1ac417d1d Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Sun, 7 Feb 2021 07:57:07 +0400 Subject: [PATCH] bhyve: auto allocate nmdm console paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, nmdm console device requires user to specify master and slave path attributes (such as /dev/nmdm0A and /dev/nmdm0B respectively). However, making user find a non-occupied device name might be not convenient, especially for the remote connections. Update the logic to make these attributes optional. In case if not specified, use /dev/nmdm$UUID[AB], where $UUID is a domain's UUID. With this schema it's unlikely nmdm device will clash with other domains or even other non-bhyve nmdm devices. Signed-off-by: Roman Bogorodskiy Reviewed-by: Ján Tomko --- src/bhyve/bhyve_domain.c | 14 ++++++ src/conf/domain_validate.c | 15 +++---- ...gv-console-master-slave-not-specified.args | 11 +++++ ...-console-master-slave-not-specified.ldargs | 3 ++ ...rgv-console-master-slave-not-specified.xml | 24 ++++++++++ tests/bhyvexml2argvtest.c | 1 + ...out-console-master-slave-not-specified.xml | 44 +++++++++++++++++++ tests/bhyvexml2xmltest.c | 1 + 8 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.xml create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-console-master-slave-not-specified.xml diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 1d99ba6c96..8fbc554a0a 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -170,6 +170,20 @@ bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, dev->data.video->type = VIR_DOMAIN_VIDEO_TYPE_GOP; } + if (dev->type == VIR_DOMAIN_DEVICE_CHR && + dev->data.chr->source->type == VIR_DOMAIN_CHR_TYPE_NMDM) { + virDomainChrDefPtr chr = dev->data.chr; + + if (!chr->source->data.nmdm.master) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(def->uuid, uuidstr); + + chr->source->data.nmdm.master = g_strdup_printf("/dev/nmdm%sA", uuidstr); + chr->source->data.nmdm.slave = g_strdup_printf("/dev/nmdm%sB", uuidstr); + } + } + return 0; } diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 6b3e892332..b6f53886cd 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -559,17 +559,14 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *src_def, break; case VIR_DOMAIN_CHR_TYPE_NMDM: - if (!src_def->data.nmdm.master) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing master path attribute for nmdm device")); - return -1; + if ((src_def->data.nmdm.master && !src_def->data.nmdm.slave) || + (!src_def->data.nmdm.master && src_def->data.nmdm.slave)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Should define both master and slave " + "path attributes for nmdm device")); + return -1; } - if (!src_def->data.nmdm.slave) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing slave path attribute for nmdm device")); - return -1; - } break; case VIR_DOMAIN_CHR_TYPE_TCP: diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.args b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.args new file mode 100644 index 0000000000..b24918e7eb --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.args @@ -0,0 +1,11 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:0,lpc \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,virtio-net,faketapdev,mac=52:54:00:b1:42:eb \ +-l com1,/dev/nmdmdf3be7e7-a104-11e3-aeb0-50e5492bd3dcA bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.ldargs new file mode 100644 index 0000000000..32538b558e --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.ldargs @@ -0,0 +1,3 @@ +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/freebsd.img bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.xml new file mode 100644 index 0000000000..6e198a49d1 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-console-master-slave-not-specified.xml @@ -0,0 +1,24 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index be816e554f..197334f9c4 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -177,6 +177,7 @@ mymain(void) DO_TEST("macaddr"); DO_TEST("serial"); DO_TEST("console"); + DO_TEST("console-master-slave-not-specified"); DO_TEST("grub-defaults"); DO_TEST("grub-bootorder"); DO_TEST("grub-bootorder2"); diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-console-master-slave-not-specified.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-console-master-slave-not-specified.xml new file mode 100644 index 0000000000..6a2f58a947 --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-console-master-slave-not-specified.xml @@ -0,0 +1,44 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + +
+ + + +
+ + +
+ + + + + +
+ + + + + + + + + + + diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index eb9b108704..428f1b47bb 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -88,6 +88,7 @@ mymain(void) DO_TEST_DIFFERENT("bhyveload-bootorder4"); DO_TEST_DIFFERENT("bhyveload-explicitargs"); DO_TEST_DIFFERENT("console"); + DO_TEST_DIFFERENT("console-master-slave-not-specified"); DO_TEST_DIFFERENT("custom-loader"); DO_TEST_DIFFERENT("disk-cdrom"); DO_TEST_DIFFERENT("disk-cdrom-grub");