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

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