[libvirt] [PATCH 09/19] virdomainobjlist: Add vnc into filter group to check the vnc existence of guest

Lin Ma posted 19 patches 5 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCH 09/19] virdomainobjlist: Add vnc into filter group to check the vnc existence of guest
Posted by Lin Ma 5 years, 3 months ago
Signed-off-by: Lin Ma <lma@suse.com>
---
 include/libvirt/libvirt-domain.h |  3 +++
 src/conf/virdomainobjlist.c      | 15 +++++++++++++++
 src/conf/virdomainobjlist.h      |  7 ++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index b3310729bf..c138e8299c 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1877,6 +1877,9 @@ typedef enum {
 
     VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT = 1 << 14,
     VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT  = 1 << 15,
+
+    VIR_CONNECT_LIST_DOMAINS_HAS_VNC        = 1 << 16,
+    VIR_CONNECT_LIST_DOMAINS_NO_VNC         = 1 << 17,
 } virConnectListAllDomainsFlags;
 
 int                     virConnectListAllDomains (virConnectPtr conn,
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index e9a4b271df..5931669b5d 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -912,6 +912,21 @@ virDomainObjMatchFilter(virDomainObjPtr vm,
             return false;
     }
 
+    /* filter by vnc existence */
+    if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_VNC)) {
+        int i;
+        bool hasVnc = false;
+        for (i = 0; i < vm->def->ngraphics; ++i) {
+            if (vm->def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+                hasVnc = true;
+                break;
+            }
+        }
+        if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_VNC) && hasVnc) ||
+              (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_VNC) && !hasVnc)))
+            return false;
+    }
+
     return true;
 }
 #undef MATCH
diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h
index 6150e13aa4..3a86e24100 100644
--- a/src/conf/virdomainobjlist.h
+++ b/src/conf/virdomainobjlist.h
@@ -124,6 +124,10 @@ int virDomainObjListForEach(virDomainObjListPtr doms,
                 (VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT | \
                  VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT)
 
+#define VIR_CONNECT_LIST_DOMAINS_FILTERS_VNC \
+                (VIR_CONNECT_LIST_DOMAINS_HAS_VNC | \
+                 VIR_CONNECT_LIST_DOMAINS_NO_VNC)
+
 #define VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL \
                 (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE      | \
                  VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT  | \
@@ -131,7 +135,8 @@ int virDomainObjListForEach(virDomainObjListPtr doms,
                  VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE | \
                  VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART   | \
                  VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT    | \
-                 VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)
+                 VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT  | \
+                 VIR_CONNECT_LIST_DOMAINS_FILTERS_VNC)
 
 int virDomainObjListCollect(virDomainObjListPtr doms,
                             virConnectPtr conn,
-- 
2.26.0


Re: [libvirt] [PATCH 09/19] virdomainobjlist: Add vnc into filter group to check the vnc existence of guest
Posted by Peter Krempa 5 years, 3 months ago
On Mon, Nov 02, 2020 at 16:26:11 +0800, Lin Ma wrote:
> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>  include/libvirt/libvirt-domain.h |  3 +++
>  src/conf/virdomainobjlist.c      | 15 +++++++++++++++
>  src/conf/virdomainobjlist.h      |  7 ++++++-
>  3 files changed, 24 insertions(+), 1 deletion(-)

I'm not persuaded (and the non-existing commit message doesn't help)
that we should add arbitrary filters here. Specifically there's a rather
limited amount of flags we can use for filtering and thus we should not
add them without proper consideration.

Specifically anything that is related to VM config is for me off limits
to be used as filtering as there are many options and they may change
over time.

This filtering can be done client side. It will be expensive, but
command line completers are not really intensively used code paths.

NACK