[libvirt] [PATCH v2 2/3] conf: add 'sharePolicy' attribute to graphics element for vnc

Guannan Ren gren at redhat.com
Wed May 8 05:22:47 UTC 2013


 -vnc :5900,share=allow-exclusive
allows clients to ask for exclusive access which is
implemented by dropping other connections Connecting
multiple clients in parallel requires all clients asking
for a shared session (vncviewer: -shared switch)

 -vnc :5900,share=force-shared
disables exclusive client access.  Useful for shared
desktop sessions, where you don't want someone forgetting
specify -shared disconnect everybody else.

 -vnc :5900,share=ignore
completely ignores the shared flag and allows everybody
connect unconditionally
---
 docs/formatdomain.html.in     | 13 +++++++++++--
 docs/schemas/domaincommon.rng |  9 +++++++++
 src/conf/domain_conf.c        | 28 ++++++++++++++++++++++++++++
 src/conf/domain_conf.h        | 11 +++++++++++
 src/libvirt_private.syms      |  2 ++
 5 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 572d7ee..fee2a1c 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3493,7 +3493,7 @@ qemu-kvm -net nic,model=? /dev/null
   ...
   <devices>
     <graphics type='sdl' display=':0.0'/>
-    <graphics type='vnc' port='5904'>
+    <graphics type='vnc' port='5904' sharePolicy='allow-exclusive'>
       <listen type='address' address='1.2.3.4'/>
     </graphics>
     <graphics type='rdp' autoport='yes' multiUser='yes' />
@@ -3536,7 +3536,16 @@ qemu-kvm -net nic,model=? /dev/null
             allows control of connected client during password changes.
             VNC accepts <code>keep</code> value only.
             <span class="since">since 0.9.3</span>
-            NB, this may not be supported by all hypervisors.<br/>  <br/>
+            NB, this may not be supported by all hypervisors.<br/>
+            The optional <code>sharePolicy</code> attribute specifies vnc server
+            display sharing policy. "allow-exclusive" allows clients to ask
+            for exclusive access by dropping other connections. Connecting
+            multiple clients in parallel requires all clients asking for a
+            shared session (vncviewer: -Shared switch). This is the default
+            value. "force-shared" disables exclusive client access, every
+            connection has to specify -Shared switch for vncviewer. "ignore"
+            welcomes every connection unconditionally
+            <span class="since">since 1.0.6</span>. <br/> <br/>
             Rather than using listen/port, QEMU supports a
             <code>socket</code> attribute for listening on a unix
             domain socket path.<span class="since">Since 0.8.8</span>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 10596dc..26779e7 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2075,6 +2075,15 @@
                   <ref name="addrIPorName"/>
                 </attribute>
               </optional>
+              <optional>
+                <attribute name='sharePolicy'>
+                  <choice>
+                    <value>allow-exclusive</value>
+                    <value>force-shared</value>
+                    <value>ignore</value>
+                  </choice>
+                </attribute>
+              </optional>
             </group>
             <group>
               <optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 59badf8..1b4a7ae 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -513,6 +513,13 @@ VIR_ENUM_IMPL(virDomainGraphicsAuthConnected,
               "disconnect",
               "keep")
 
+VIR_ENUM_IMPL(virDomainGraphicsVNCSharePolicy,
+              VIR_DOMAIN_GRAPHICS_VNC_SHARE_LAST,
+              "default",
+              "allow-exclusive",
+              "force-shared",
+              "ignore")
+
 VIR_ENUM_IMPL(virDomainGraphicsSpiceChannelName,
               VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST,
               "main",
@@ -7545,6 +7552,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
     if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
         char *port = virXMLPropString(node, "port");
         char *autoport;
+        char *policy;
 
         if (port) {
             if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) {
@@ -7574,6 +7582,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
             VIR_FREE(autoport);
         }
 
+        if ((policy = virXMLPropString(node, "sharePolicy")) != NULL) {
+            int sharePolicy =
+               virDomainGraphicsVNCSharePolicyTypeFromString(policy);
+
+            if (sharePolicy < 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown vnc display sharing policy '%s'"), policy);
+                VIR_FREE(policy);
+                goto error;
+            } else {
+                def->data.vnc.sharePolicy = sharePolicy;
+            }
+            VIR_FREE(policy);
+        }
+
         def->data.vnc.socket = virXMLPropString(node, "socket");
         def->data.vnc.keymap = virXMLPropString(node, "keymap");
 
@@ -14986,6 +15009,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             virBufferEscapeString(buf, " keymap='%s'",
                                   def->data.vnc.keymap);
 
+        if (def->data.vnc.sharePolicy)
+            virBufferAsprintf(buf, " sharePolicy='%s'",
+                              virDomainGraphicsVNCSharePolicyTypeToString(
+                              def->data.vnc.sharePolicy));
+
         virDomainGraphicsAuthDefFormatAttr(buf, &def->data.vnc.auth, flags);
         break;
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 21f7ce2..20eb0cb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1284,6 +1284,15 @@ struct _virDomainGraphicsAuthDef {
     int connected; /* action if connected */
 };
 
+enum virDomainGraphicsVNCSharePolicy {
+    VIR_DOMAIN_GRAPHICS_VNC_SHARE_DEFAULT = 0,
+    VIR_DOMAIN_GRAPHICS_VNC_SHARE_ALLOW_EXCLUSIVE,
+    VIR_DOMAIN_GRAPHICS_VNC_SHARE_FORCE_SHARED,
+    VIR_DOMAIN_GRAPHICS_VNC_SHARE_IGNORE,
+
+    VIR_DOMAIN_GRAPHICS_VNC_SHARE_LAST
+};
+
 enum virDomainGraphicsSpiceChannelName {
     VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MAIN,
     VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_DISPLAY,
@@ -1404,6 +1413,7 @@ struct _virDomainGraphicsDef {
             char *keymap;
             char *socket;
             virDomainGraphicsAuthDef auth;
+            int sharePolicy;
         } vnc;
         struct {
             char *display;
@@ -2493,6 +2503,7 @@ VIR_ENUM_DECL(virDomainInputBus)
 VIR_ENUM_DECL(virDomainGraphics)
 VIR_ENUM_DECL(virDomainGraphicsListen)
 VIR_ENUM_DECL(virDomainGraphicsAuthConnected)
+VIR_ENUM_DECL(virDomainGraphicsVNCSharePolicy)
 VIR_ENUM_DECL(virDomainGraphicsSpiceChannelName)
 VIR_ENUM_DECL(virDomainGraphicsSpiceChannelMode)
 VIR_ENUM_DECL(virDomainGraphicsSpiceImageCompression)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d4cb4a3..1540f27 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -201,6 +201,8 @@ virDomainGraphicsSpiceZlibCompressionTypeFromString;
 virDomainGraphicsSpiceZlibCompressionTypeToString;
 virDomainGraphicsTypeFromString;
 virDomainGraphicsTypeToString;
+virDomainGraphicsVNCSharePolicyTypeFromString;
+virDomainGraphicsVNCSharePolicyTypeToString;
 virDomainHasDiskMirror;
 virDomainHostdevCapsTypeToString;
 virDomainHostdevDefAlloc;
-- 
1.8.1.4




More information about the libvir-list mailing list