Blame SOURCES/kvm-pr-manager-helper-report-event-on-connection-disconn.patch

26ba25
From 83a0b1b1828bf5e22da506c39848a3b226892c3d Mon Sep 17 00:00:00 2001
26ba25
From: Paolo Bonzini <pbonzini@redhat.com>
26ba25
Date: Fri, 6 Jul 2018 17:56:56 +0200
26ba25
Subject: [PATCH 196/268] pr-manager-helper: report event on
26ba25
 connection/disconnection
26ba25
26ba25
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
26ba25
Message-id: <20180706175659.30615-7-pbonzini@redhat.com>
26ba25
Patchwork-id: 81247
26ba25
O-Subject: [RHEL7.6 qemu-kvm-rhev PATCH 6/9] pr-manager-helper: report event on connection/disconnection
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
Let management know if there were any problems communicating with
26ba25
qemu-pr-helper.  The event is edge-triggered, and is sent every time
26ba25
the connection status of the pr-manager-helper object changes.
26ba25
26ba25
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
26ba25
(cherry picked from commit e2c81a45101fdddfd47477a1805806f2c76639bf)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 qapi/block.json          | 24 ++++++++++++++++++++++++
26ba25
 scsi/pr-manager-helper.c | 14 ++++++++++++++
26ba25
 2 files changed, 38 insertions(+)
26ba25
26ba25
diff --git a/qapi/block.json b/qapi/block.json
26ba25
index cf63ea2..528c1e6 100644
26ba25
--- a/qapi/block.json
26ba25
+++ b/qapi/block.json
26ba25
@@ -335,6 +335,30 @@
26ba25
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
26ba25
 
26ba25
 ##
26ba25
+# @PR_MANAGER_STATUS_CHANGED:
26ba25
+#
26ba25
+# Emitted whenever the connected status of a persistent reservation
26ba25
+# manager changes.
26ba25
+#
26ba25
+# @id: The id of the PR manager object
26ba25
+#
26ba25
+# @connected: true if the PR manager is connected to a backend
26ba25
+#
26ba25
+# Since: 3.0
26ba25
+#
26ba25
+# Example:
26ba25
+#
26ba25
+# <- { "event": "PR_MANAGER_STATUS_CHANGED",
26ba25
+#      "data": { "id": "pr-helper0",
26ba25
+#                "connected": true
26ba25
+#      },
26ba25
+#      "timestamp": { "seconds": 1519840375, "microseconds": 450486 } }
26ba25
+#
26ba25
+##
26ba25
+{ 'event': 'PR_MANAGER_STATUS_CHANGED',
26ba25
+  'data': { 'id': 'str', 'connected': 'bool' } }
26ba25
+
26ba25
+##
26ba25
 # @QuorumOpType:
26ba25
 #
26ba25
 # An enumeration of the quorum operation types
26ba25
diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c
26ba25
index b11481b..519a296 100644
26ba25
--- a/scsi/pr-manager-helper.c
26ba25
+++ b/scsi/pr-manager-helper.c
26ba25
@@ -17,6 +17,7 @@
26ba25
 #include "io/channel.h"
26ba25
 #include "io/channel-socket.h"
26ba25
 #include "pr-helper.h"
26ba25
+#include "qapi/qapi-events-block.h"
26ba25
 
26ba25
 #include <scsi/sg.h>
26ba25
 
26ba25
@@ -38,6 +39,16 @@ typedef struct PRManagerHelper {
26ba25
     QIOChannel *ioc;
26ba25
 } PRManagerHelper;
26ba25
 
26ba25
+static void pr_manager_send_status_changed_event(PRManagerHelper *pr_mgr)
26ba25
+{
26ba25
+    char *id = object_get_canonical_path_component(OBJECT(pr_mgr));
26ba25
+
26ba25
+    if (id) {
26ba25
+        qapi_event_send_pr_manager_status_changed(id, !!pr_mgr->ioc,
26ba25
+                                                  &error_abort);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
 /* Called with lock held.  */
26ba25
 static int pr_manager_helper_read(PRManagerHelper *pr_mgr,
26ba25
                                   void *buf, int sz, Error **errp)
26ba25
@@ -47,6 +58,7 @@ static int pr_manager_helper_read(PRManagerHelper *pr_mgr,
26ba25
     if (r < 0) {
26ba25
         object_unref(OBJECT(pr_mgr->ioc));
26ba25
         pr_mgr->ioc = NULL;
26ba25
+        pr_manager_send_status_changed_event(pr_mgr);
26ba25
         return -EINVAL;
26ba25
     }
26ba25
 
26ba25
@@ -72,6 +84,7 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mgr,
26ba25
             assert(n_written != QIO_CHANNEL_ERR_BLOCK);
26ba25
             object_unref(OBJECT(pr_mgr->ioc));
26ba25
             pr_mgr->ioc = NULL;
26ba25
+            pr_manager_send_status_changed_event(pr_mgr);
26ba25
             return n_written < 0 ? -EINVAL : 0;
26ba25
         }
26ba25
 
26ba25
@@ -127,6 +140,7 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
26ba25
         goto out_close;
26ba25
     }
26ba25
 
26ba25
+    pr_manager_send_status_changed_event(pr_mgr);
26ba25
     return 0;
26ba25
 
26ba25
 out_close:
26ba25
-- 
26ba25
1.8.3.1
26ba25