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

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