yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-pr-manager-add-query-pr-managers-QMP-command.patch

26ba25
From e34b60deac41fc0c642598ea9e84e6c919fe2d02 Mon Sep 17 00:00:00 2001
26ba25
From: Paolo Bonzini <pbonzini@redhat.com>
26ba25
Date: Fri, 6 Jul 2018 17:56:55 +0200
26ba25
Subject: [PATCH 195/268] pr-manager: add query-pr-managers QMP command
26ba25
26ba25
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
26ba25
Message-id: <20180706175659.30615-6-pbonzini@redhat.com>
26ba25
Patchwork-id: 81251
26ba25
O-Subject: [RHEL7.6 qemu-kvm-rhev PATCH 5/9] pr-manager: add query-pr-managers QMP command
26ba25
Bugzilla: 1533158
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Michal Privoznik <mprivozn@redhat.com>
26ba25
26ba25
This command lets you query the connection status of each pr-manager-helper
26ba25
object.
26ba25
26ba25
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
26ba25
(cherry picked from commit 5f64089416f0d77c87683401838f064c51a292ed)
26ba25
26ba25
[RHEL: no allow-preconfig yet, so don't specify it]
26ba25
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 include/scsi/pr-manager.h |  2 ++
26ba25
 qapi/block.json           | 27 +++++++++++++++++++++++++++
26ba25
 scsi/pr-manager-helper.c  | 13 +++++++++++++
26ba25
 scsi/pr-manager-stub.c    |  6 ++++++
26ba25
 scsi/pr-manager.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
26ba25
 5 files changed, 93 insertions(+)
26ba25
26ba25
diff --git a/include/scsi/pr-manager.h b/include/scsi/pr-manager.h
26ba25
index 71971ae..50a77b0 100644
26ba25
--- a/include/scsi/pr-manager.h
26ba25
+++ b/include/scsi/pr-manager.h
26ba25
@@ -33,8 +33,10 @@ typedef struct PRManagerClass {
26ba25
 
26ba25
     /* <public> */
26ba25
     int (*run)(PRManager *pr_mgr, int fd, struct sg_io_hdr *hdr);
26ba25
+    bool (*is_connected)(PRManager *pr_mgr);
26ba25
 } PRManagerClass;
26ba25
 
26ba25
+bool pr_manager_is_connected(PRManager *pr_mgr);
26ba25
 BlockAIOCB *pr_manager_execute(PRManager *pr_mgr,
26ba25
                                AioContext *ctx, int fd,
26ba25
                                struct sg_io_hdr *hdr,
26ba25
diff --git a/qapi/block.json b/qapi/block.json
26ba25
index c694524..cf63ea2 100644
26ba25
--- a/qapi/block.json
26ba25
+++ b/qapi/block.json
26ba25
@@ -78,6 +78,33 @@
26ba25
   'data': { 'device': 'str', 'name': 'str' } }
26ba25
 
26ba25
 ##
26ba25
+# @PRManagerInfo:
26ba25
+#
26ba25
+# Information about a persistent reservation manager
26ba25
+#
26ba25
+# @id: the identifier of the persistent reservation manager
26ba25
+#
26ba25
+# @connected: true if the persistent reservation manager is connected to
26ba25
+#             the underlying storage or helper
26ba25
+#
26ba25
+# Since: 3.0
26ba25
+##
26ba25
+{ 'struct': 'PRManagerInfo',
26ba25
+  'data': {'id': 'str', 'connected': 'bool'} }
26ba25
+
26ba25
+##
26ba25
+# @query-pr-managers:
26ba25
+#
26ba25
+# Returns a list of information about each persistent reservation manager.
26ba25
+#
26ba25
+# Returns: a list of @PRManagerInfo for each persistent reservation manager
26ba25
+#
26ba25
+# Since: 3.0
26ba25
+##
26ba25
+{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'] }
26ba25
+
26ba25
+
26ba25
+##
26ba25
 # @blockdev-snapshot-internal-sync:
26ba25
 #
26ba25
 # Synchronously take an internal snapshot of a block device, when the
26ba25
diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c
26ba25
index 0c0fe38..b11481b 100644
26ba25
--- a/scsi/pr-manager-helper.c
26ba25
+++ b/scsi/pr-manager-helper.c
26ba25
@@ -235,6 +235,18 @@ out:
26ba25
     return ret;
26ba25
 }
26ba25
 
26ba25
+static bool pr_manager_helper_is_connected(PRManager *p)
26ba25
+{
26ba25
+    PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(p);
26ba25
+    bool result;
26ba25
+
26ba25
+    qemu_mutex_lock(&pr_mgr->lock);
26ba25
+    result = (pr_mgr->ioc != NULL);
26ba25
+    qemu_mutex_unlock(&pr_mgr->lock);
26ba25
+
26ba25
+    return result;
26ba25
+}
26ba25
+
26ba25
 static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
26ba25
 {
26ba25
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
26ba25
@@ -284,6 +296,7 @@ static void pr_manager_helper_class_init(ObjectClass *klass,
26ba25
                                   &error_abort);
26ba25
     uc_klass->complete = pr_manager_helper_complete;
26ba25
     prmgr_klass->run = pr_manager_helper_run;
26ba25
+    prmgr_klass->is_connected = pr_manager_helper_is_connected;
26ba25
 }
26ba25
 
26ba25
 static const TypeInfo pr_manager_helper_info = {
26ba25
diff --git a/scsi/pr-manager-stub.c b/scsi/pr-manager-stub.c
26ba25
index 632f17c..738b6d7 100644
26ba25
--- a/scsi/pr-manager-stub.c
26ba25
+++ b/scsi/pr-manager-stub.c
26ba25
@@ -22,3 +22,9 @@ PRManager *pr_manager_lookup(const char *id, Error **errp)
26ba25
     error_setg(errp, "No persistent reservation manager with id '%s'", id);
26ba25
         return NULL;
26ba25
 }
26ba25
+
26ba25
+
26ba25
+PRManagerInfoList *qmp_query_pr_managers(Error **errp)
26ba25
+{
26ba25
+    return NULL;
26ba25
+}
26ba25
diff --git a/scsi/pr-manager.c b/scsi/pr-manager.c
26ba25
index 87c45db..2a8f300 100644
26ba25
--- a/scsi/pr-manager.c
26ba25
+++ b/scsi/pr-manager.c
26ba25
@@ -17,6 +17,10 @@
26ba25
 #include "block/thread-pool.h"
26ba25
 #include "scsi/pr-manager.h"
26ba25
 #include "trace.h"
26ba25
+#include "qapi/qapi-types-block.h"
26ba25
+#include "qapi/qapi-commands-block.h"
26ba25
+
26ba25
+#define PR_MANAGER_PATH     "/objects"
26ba25
 
26ba25
 typedef struct PRManagerData {
26ba25
     PRManager *pr_mgr;
26ba25
@@ -64,6 +68,14 @@ BlockAIOCB *pr_manager_execute(PRManager *pr_mgr,
26ba25
                                   data, complete, opaque);
26ba25
 }
26ba25
 
26ba25
+bool pr_manager_is_connected(PRManager *pr_mgr)
26ba25
+{
26ba25
+    PRManagerClass *pr_mgr_class =
26ba25
+        PR_MANAGER_GET_CLASS(pr_mgr);
26ba25
+
26ba25
+    return !pr_mgr_class->is_connected || pr_mgr_class->is_connected(pr_mgr);
26ba25
+}
26ba25
+
26ba25
 static const TypeInfo pr_manager_info = {
26ba25
     .parent = TYPE_OBJECT,
26ba25
     .name = TYPE_PR_MANAGER,
26ba25
@@ -105,5 +117,38 @@ pr_manager_register_types(void)
26ba25
     type_register_static(&pr_manager_info);
26ba25
 }
26ba25
 
26ba25
+static int query_one_pr_manager(Object *object, void *opaque)
26ba25
+{
26ba25
+    PRManagerInfoList ***prev = opaque;
26ba25
+    PRManagerInfoList *elem;
26ba25
+    PRManagerInfo *info;
26ba25
+    PRManager *pr_mgr;
26ba25
+
26ba25
+    pr_mgr = (PRManager *)object_dynamic_cast(object, TYPE_PR_MANAGER);
26ba25
+    if (!pr_mgr) {
26ba25
+        return 0;
26ba25
+    }
26ba25
+
26ba25
+    elem = g_new0(PRManagerInfoList, 1);
26ba25
+    info = g_new0(PRManagerInfo, 1);
26ba25
+    info->id = object_get_canonical_path_component(object);
26ba25
+    info->connected = pr_manager_is_connected(pr_mgr);
26ba25
+    elem->value = info;
26ba25
+    elem->next = NULL;
26ba25
+
26ba25
+    **prev = elem;
26ba25
+    *prev = &elem->next;
26ba25
+    return 0;
26ba25
+}
26ba25
+
26ba25
+PRManagerInfoList *qmp_query_pr_managers(Error **errp)
26ba25
+{
26ba25
+    PRManagerInfoList *head = NULL;
26ba25
+    PRManagerInfoList **prev = &head;
26ba25
+    Object *container = container_get(object_get_root(), PR_MANAGER_PATH);
26ba25
+
26ba25
+    object_child_foreach(container, query_one_pr_manager, &prev;;
26ba25
+    return head;
26ba25
+}
26ba25
 
26ba25
 type_init(pr_manager_register_types);
26ba25
-- 
26ba25
1.8.3.1
26ba25