yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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