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

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