Re: [libvirt] [PATCH v3 3/4] conf: Add XML resolution support for video models

2019-10-10 Thread Cole Robinson

On 10/7/19 11:35 PM, jcfara...@gmail.com wrote:

From: Julio Faracco 

XML need to support both properties together. This commit adds XML
support for video model if they are set. Domain configuration is able
to parse this properties as 'x' and 'y'. Code is not using same label as
QEMU: 'xres' and 'yres'.



Compared to v2, the commit message here dropped the XML example, which I 
find useful; can make it easier to grep git logs in some instances



Signed-off-by: Julio Faracco 
---
  src/conf/domain_conf.c  | 74 -
  src/conf/domain_conf.h  |  5 +++
  src/conf/virconftypes.h |  3 ++
  3 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a53cd6a725..950c4522f9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15403,6 +15403,52 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node)
  return def;
  }
  
+static virDomainVideoResolutionDefPtr

+virDomainVideoResolutionDefParseXML(xmlNodePtr node)
+{
+xmlNodePtr cur;
+virDomainVideoResolutionDefPtr def;
+VIR_AUTOFREE(char *) x = NULL;
+VIR_AUTOFREE(char *) y = NULL;
+
+cur = node->children;
+while (cur != NULL) {
+if (cur->type == XML_ELEMENT_NODE) {
+if (!x && !y &&
+virXMLNodeNameEqual(cur, "resolution")) {
+x = virXMLPropString(cur, "x");
+y = virXMLPropString(cur, "y");
+}
+}
+cur = cur->next;
+}
+
+if (!x || !y)
+return NULL;
+
+if (VIR_ALLOC(def) < 0)
+goto cleanup;
+
+if (x) {
+if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("cannot parse video x-resolution '%s'"), x);
+goto cleanup;
+}
+}
+
+if (y) {
+if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("cannot parse video y-resolution '%s'"), y);
+goto cleanup;
+}
+}
+
+ cleanup:
+return def;
+}
+
  static virDomainVideoDriverDefPtr
  virDomainVideoDriverDefParseXML(xmlNodePtr node)
  {
@@ -15482,6 +15528,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
  }
  
  def->accel = virDomainVideoAccelDefParseXML(cur);

+def->res = virDomainVideoResolutionDefParseXML(cur);
  }
  if (virXMLNodeNameEqual(cur, "driver")) {
  if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
@@ -15569,6 +15616,17 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
  }
  }
  
+if (def->res) {

+if (def->type != VIR_DOMAIN_VIDEO_TYPE_VGA &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_BOCHS) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("model resolution is not supported"));
+goto error;
+}
+}
+


I mentioned this in v2: IMO this check should be removed, it's just a 
whitelist duplicating qemu logic which could easily go out of date. But 
if you want to keep it, it should go in a Validate callback, 
specifically virDomainVideoDefValidate. We are trying to avoid adding 
more of these checks inline in the XML parser


You can CC me on v4 and I'll review it

Thanks,
Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 3/4] conf: Add XML resolution support for video models

2019-10-07 Thread jcfaracco
From: Julio Faracco 

XML need to support both properties together. This commit adds XML
support for video model if they are set. Domain configuration is able
to parse this properties as 'x' and 'y'. Code is not using same label as
QEMU: 'xres' and 'yres'.

Signed-off-by: Julio Faracco 
---
 src/conf/domain_conf.c  | 74 -
 src/conf/domain_conf.h  |  5 +++
 src/conf/virconftypes.h |  3 ++
 3 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a53cd6a725..950c4522f9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15403,6 +15403,52 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node)
 return def;
 }
 
+static virDomainVideoResolutionDefPtr
+virDomainVideoResolutionDefParseXML(xmlNodePtr node)
+{
+xmlNodePtr cur;
+virDomainVideoResolutionDefPtr def;
+VIR_AUTOFREE(char *) x = NULL;
+VIR_AUTOFREE(char *) y = NULL;
+
+cur = node->children;
+while (cur != NULL) {
+if (cur->type == XML_ELEMENT_NODE) {
+if (!x && !y &&
+virXMLNodeNameEqual(cur, "resolution")) {
+x = virXMLPropString(cur, "x");
+y = virXMLPropString(cur, "y");
+}
+}
+cur = cur->next;
+}
+
+if (!x || !y)
+return NULL;
+
+if (VIR_ALLOC(def) < 0)
+goto cleanup;
+
+if (x) {
+if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("cannot parse video x-resolution '%s'"), x);
+goto cleanup;
+}
+}
+
+if (y) {
+if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("cannot parse video y-resolution '%s'"), y);
+goto cleanup;
+}
+}
+
+ cleanup:
+return def;
+}
+
 static virDomainVideoDriverDefPtr
 virDomainVideoDriverDefParseXML(xmlNodePtr node)
 {
@@ -15482,6 +15528,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 
 def->accel = virDomainVideoAccelDefParseXML(cur);
+def->res = virDomainVideoResolutionDefParseXML(cur);
 }
 if (virXMLNodeNameEqual(cur, "driver")) {
 if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
@@ -15569,6 +15616,17 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 }
 
+if (def->res) {
+if (def->type != VIR_DOMAIN_VIDEO_TYPE_VGA &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+def->type != VIR_DOMAIN_VIDEO_TYPE_BOCHS) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("model resolution is not supported"));
+goto error;
+}
+}
+
 if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0)
 goto error;
 
@@ -26574,6 +26632,18 @@ virDomainVideoAccelDefFormat(virBufferPtr buf,
 virBufferAddLit(buf, "/>\n");
 }
 
+static void
+virDomainVideoResolutionDefFormat(virBufferPtr buf,
+  virDomainVideoResolutionDefPtr def)
+{
+virBufferAddLit(buf, "x && def->y) {
+virBufferAsprintf(buf, " x='%u' y='%u'",
+  def->x, def->y);
+}
+virBufferAddLit(buf, "/>\n");
+}
+
 static int
 virDomainVideoDefFormat(virBufferPtr buf,
 virDomainVideoDefPtr def,
@@ -26621,11 +26691,13 @@ virDomainVideoDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf, " heads='%u'", def->heads);
 if (def->primary)
 virBufferAddLit(buf, " primary='yes'");
-if (def->accel) {
+if (def->accel || def->res) {
 virBufferAddLit(buf, ">\n");
 virBufferAdjustIndent(buf, 2);
 if (def->accel)
 virDomainVideoAccelDefFormat(buf, def->accel);
+if (def->res)
+virDomainVideoResolutionDefFormat(buf, def->res);
 virBufferAdjustIndent(buf, -2);
 virBufferAddLit(buf, "\n");
 } else {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2884af49d8..ce5da4ddf4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1420,6 +1420,10 @@ struct _virDomainVideoAccelDef {
 char *rendernode;
 };
 
+struct _virDomainVideoResolutionDef {
+unsigned int x;
+unsigned int y;
+};
 
 struct _virDomainVideoDriverDef {
virDomainVideoVGAConf vgaconf;
@@ -1437,6 +1441,7 @@ struct _virDomainVideoDef {
 unsigned int heads;
 bool primary;
 virDomainVideoAccelDefPtr accel;
+virDomainVideoResolutionDefPtr res;
 virDomainVideoDriverDefPtr driver;
 virDomainDeviceInfo info;
 virDomainVirtioOptionsPtr virtio;
diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h
index a15cfb5f9e..462842f324 100644
--- a/src/conf/virconftypes.h
+++ b/src/conf/virconft