Skip to contentSkip to conversation

pr-manager/qemu-pr-helper patches for QEMU 3.0

PATCH Superseded Paolo Bonzini 4 participants 21 messages Jun 26, 2018 – Jun 28, 2018 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover pr-manager/qemu-pr-helper patches for QEMU 3.0

The first three patches are more or less trivial bugfixes. The last two allow libvirt to know the status of the qemu-pr-helper process that is attached to a running QEMU instance.

Michal, can you check that the interface in the last two patches is good for you?

Thanks,

Paolo

Paolo Bonzini (5):
pr-helper: fix --socket-path default in help
pr-helper: fix assertion failure on failed multipath PERSISTENT
RESERVE IN
pr-manager-helper: avoid SIGSEGV when writing to the socket fail
pr-manager: add query-pr-managers QMP command
pr-manager-helper: report event on connection/disconnection

 include/scsi/pr-manager.h |  2 ++
 qapi/block.json           | 51 +++++++++++++++++++++++++++++++++++++++
 scsi/pr-manager-helper.c  | 39 +++++++++++++++++++++++++-----
 scsi/pr-manager.c         | 45 ++++++++++++++++++++++++++++++++++
 scsi/qemu-pr-helper.c     | 21 ++++++++++------
 5 files changed, 144 insertions(+), 14 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 pr-helper: fix --socket-path default in help

Currently --help shows "(default '(null)')" for the -k/--socket-path option. Fix it by getting the default path in /var/run.

---
 scsi/qemu-pr-helper.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
scsi/qemu-pr-helper.c +8 -7
index d0f83176e1..4057cf355c 100644
@@ -74,8 +74,16 @@ static int uid = -1;
 static int gid = -1;
 #endif
 
+static void compute_default_paths(void)
+{
+    if (!socket_path) {
+        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
+    }
+}
+
 static void usage(const char *name)
 {
+    compute_default_paths();
     (printf) (
 "Usage: %s [OPTIONS] FILE\n"
 "Persistent Reservation helper program for QEMU\n"
@@ -845,13 +853,6 @@ static const char *socket_activation_validate_opts(void)
     return NULL;
 }
 
-static void compute_default_paths(void)
-{
-    if (!socket_path) {
-        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
-    }
-}
-
 static void termsig_handler(int signum)
 {
     atomic_cmpxchg(&state, RUNNING, TERMINATE);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] pr-helper: fix --socket-path default in help

Quoted 4 lines · Paolo Bonzini

Currently --help shows "(default '(null)')" for the -k/--socket-path option. Fix it by getting the default path in /var/run.

Quoted 40 lines
---
 scsi/qemu-pr-helper.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
scsi/qemu-pr-helper.c +8 -7
index d0f83176e1..4057cf355c 100644
@@ -74,8 +74,16 @@ static int uid = -1;
 static int gid = -1;
 #endif
 
+static void compute_default_paths(void)
+{
+    if (!socket_path) {
+        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
+    }
+}
+
 static void usage(const char *name)
 {
+    compute_default_paths();
     (printf) (
 "Usage: %s [OPTIONS] FILE\n"
 "Persistent Reservation helper program for QEMU\n"
@@ -845,13 +853,6 @@ static const char *socket_activation_validate_opts(void)
     return NULL;
 }
 
-static void compute_default_paths(void)
-{
-    if (!socket_path) {
-        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
-    }
-}
-
 static void termsig_handler(int signum)
 {
     atomic_cmpxchg(&state, RUNNING, TERMINATE);
Reviewed-by on v1 1/5
#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] pr-helper: fix --socket-path default in help

In reply to Paolo Bonzini
Quoted 13 lines · Paolo Bonzini

Currently --help shows "(default '(null)')" for the -k/--socket-path option. Fix it by getting the default path in /var/run.

---
 scsi/qemu-pr-helper.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
scsi/qemu-pr-helper.c +0 -0
index d0f83176e1..4057cf355c 100644

scsi/qemu-pr-helper.c static int uid = -1; · line 83

Quoted 10 lines
scsi/qemu-pr-helper.c +7 -0
@@ -74,8 +74,16 @@ static int uid = -1;
 static int gid = -1;
 #endif
 
+static void compute_default_paths(void)
+{
+    if (!socket_path) {
+        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
+    }
+}
+

Pre-existing, but pidfile path is computed elsewhere. I'll post a patch that cleans things up. Not a show stopper for this one though.

Michal

#4 lore raw

PATCH 2/5 pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN

In reply to Paolo Bonzini

The response size is expected to be zero if the SCSI status is not "GOOD", but nothing was resetting it.

This can be reproduced simply by "sg_persist -s /dev/sdb" where /dev/sdb in the guest is a scsi-block device corresponding to a multipath device on the host.

Before:

PR in (Read full status): Aborted command

and on the host:

prh_write_response: Assertion `resp->sz == 0' failed.

After:

PR in (Read full status): bad field in cdb or parameter list (perhaps unsupported service action)

---
 scsi/qemu-pr-helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scsi/qemu-pr-helper.c +5 -1
index 4057cf355c..0218d65bbf 100644
@@ -558,7 +558,11 @@ static int do_pr_in(int fd, const uint8_t *cdb, uint8_t *sense,
 #ifdef CONFIG_MPATH
     if (is_mpath(fd)) {
         /* multipath_pr_in fills the whole input buffer.  */
-        return multipath_pr_in(fd, cdb, sense, data, *resp_sz);
+        int r = multipath_pr_in(fd, cdb, sense, data, *resp_sz);
+        if (r != GOOD) {
+            *resp_sz = 0;
+        }
+        return r;
     }
 #endif
 
Signature · 1 line
2.17.1
Reviewed-by on v1 2/5
#5 lore raw

Re: [Qemu-devel] [PATCH 2/5] pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN

Quoted 15 lines · Paolo Bonzini

The response size is expected to be zero if the SCSI status is not "GOOD", but nothing was resetting it.

This can be reproduced simply by "sg_persist -s /dev/sdb" where /dev/sdb in the guest is a scsi-block device corresponding to a multipath device on the host.

Before:

PR in (Read full status): Aborted command

and on the host:

prh_write_response: Assertion `resp->sz == 0' failed.

Quoted 7 lines

After:

PR in (Read full status): bad field in cdb or parameter list (perhaps unsupported service action)

Quoted 22 lines
---
 scsi/qemu-pr-helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scsi/qemu-pr-helper.c +5 -1
index 4057cf355c..0218d65bbf 100644
@@ -558,7 +558,11 @@ static int do_pr_in(int fd, const uint8_t *cdb, uint8_t *sense,
 #ifdef CONFIG_MPATH
     if (is_mpath(fd)) {
         /* multipath_pr_in fills the whole input buffer.  */
-        return multipath_pr_in(fd, cdb, sense, data, *resp_sz);
+        int r = multipath_pr_in(fd, cdb, sense, data, *resp_sz);
+        if (r != GOOD) {
+            *resp_sz = 0;
+        }
+        return r;
     }
 #endif
 
Reviewed-by on v1 2/5
#6 lore raw

Re: [Qemu-devel] [PATCH 2/5] pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN

In reply to Paolo Bonzini
Quoted 17 lines · Paolo Bonzini

The response size is expected to be zero if the SCSI status is not "GOOD", but nothing was resetting it.

This can be reproduced simply by "sg_persist -s /dev/sdb" where /dev/sdb in the guest is a scsi-block device corresponding to a multipath device on the host.

Before:

PR in (Read full status): Aborted command

and on the host:

prh_write_response: Assertion `resp->sz == 0' failed.

After:

Quoted 9 lines

PR in (Read full status): bad field in cdb or parameter list (perhaps unsupported service action)

---
 scsi/qemu-pr-helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Michal

#7 lore raw

PATCH 3/5 pr-manager-helper: avoid SIGSEGV when writing to the socket fail

In reply to Paolo Bonzini

When writing to the qemu-pr-helper socket failed, the persistent reservation manager was correctly disconnecting the socket, but it did not clear pr_mgr->ioc. So the rest of the code did not know that the socket had been disconnected, accessed pr_mgr->ioc and happily caused a crash.

To reproduce, it is enough to stop qemu-pr-helper between QEMU startup and executing e.g. sg_persist -k /dev/sdb.

---
 scsi/pr-manager-helper.c | 1 +
 1 file changed, 1 insertion(+)
scsi/pr-manager-helper.c +1 -0
index 82ff6b6123..0c0fe389b7 100644
@@ -71,6 +71,7 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mgr,
         if (n_written <= 0) {
             assert(n_written != QIO_CHANNEL_ERR_BLOCK);
             object_unref(OBJECT(pr_mgr->ioc));
+            pr_mgr->ioc = NULL;
             return n_written < 0 ? -EINVAL : 0;
         }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 3/5
#8 lore raw

Re: [Qemu-devel] [PATCH 3/5] pr-manager-helper: avoid SIGSEGV when writing to the socket fail

Quoted 6 lines · Paolo Bonzini

When writing to the qemu-pr-helper socket failed, the persistent reservation manager was correctly disconnecting the socket, but it did not clear pr_mgr->ioc. So the rest of the code did not know that the socket had been disconnected, accessed pr_mgr->ioc and happily caused a crash.

Quoted 7 lines

To reproduce, it is enough to stop qemu-pr-helper between QEMU startup and executing e.g. sg_persist -k /dev/sdb.

---
 scsi/pr-manager-helper.c | 1 +
 1 file changed, 1 insertion(+)

Michal

#9 lore raw

PATCH 4/5 pr-manager: add query-pr-managers QMP command

In reply to Paolo Bonzini

This command lets you query the connection status of each pr-manager-helper object.

---
 include/scsi/pr-manager.h |  2 ++
 qapi/block.json           | 27 +++++++++++++++++++++++
 scsi/pr-manager-helper.c  | 13 +++++++++++
 scsi/pr-manager.c         | 45 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)
include/scsi/pr-manager.h +2 -0
index 5d2f13a5e4..adadca7954 100644
@@ -33,8 +33,10 @@ typedef struct PRManagerClass {
 
     /* <public> */
     int (*run)(PRManager *pr_mgr, int fd, struct sg_io_hdr *hdr);
+    bool (*is_connected)(PRManager *pr_mgr);
 } PRManagerClass;
 
+bool pr_manager_is_connected(PRManager *pr_mgr);
 BlockAIOCB *pr_manager_execute(PRManager *pr_mgr,
                                AioContext *ctx, int fd,
                                struct sg_io_hdr *hdr,
qapi/block.json +27 -0
index c694524002..dc3323c954 100644
@@ -77,6 +77,33 @@
 { 'struct': 'BlockdevSnapshotInternal',
   'data': { 'device': 'str', 'name': 'str' } }
 
+##
+# @PRManagerInfo:
+#
+# Information about a persistent reservation manager
+#
+# @id: the identifier of the persistent reservation manager
+#
+# @is-connected: whether the persistent reservation manager is connected to
+#                the underlying storage or helper
+#
+# Since: 3.0
+##
+{ 'struct': 'PRManagerInfo',
+  'data': {'id': 'str', 'is-connected': 'bool'} }
+
+##
+# @query-pr-managers:
+#
+# Returns a list of information about each persistent reservation manager.
+#
+# Returns: a list of @PRManagerInfo for each persistent reservation manager
+#
+# Since: 3.0
+##
+{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'] }
+
+
 ##
 # @blockdev-snapshot-internal-sync:
 #
scsi/pr-manager-helper.c +13 -0
index 0c0fe389b7..b11481be9e 100644
@@ -235,6 +235,18 @@ out:
     return ret;
 }
 
+static bool pr_manager_helper_is_connected(PRManager *p)
+{
+    PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(p);
+    bool result;
+
+    qemu_mutex_lock(&pr_mgr->lock);
+    result = (pr_mgr->ioc != NULL);
+    qemu_mutex_unlock(&pr_mgr->lock);
+
+    return result;
+}
+
 static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
 {
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
@@ -284,6 +296,7 @@ static void pr_manager_helper_class_init(ObjectClass *klass,
                                   &error_abort);
     uc_klass->complete = pr_manager_helper_complete;
     prmgr_klass->run = pr_manager_helper_run;
+    prmgr_klass->is_connected = pr_manager_helper_is_connected;
 }
 
 static const TypeInfo pr_manager_helper_info = {
scsi/pr-manager.c +45 -0

62 lines not on this page · raw message

Signature · 1 line
2.17.1
#10 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

Quoted 69 lines · Paolo Bonzini

This command lets you query the connection status of each pr-manager-helper object.

---
 include/scsi/pr-manager.h |  2 ++
 qapi/block.json           | 27 +++++++++++++++++++++++
 scsi/pr-manager-helper.c  | 13 +++++++++++
 scsi/pr-manager.c         | 45 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)
include/scsi/pr-manager.h +2 -0
index 5d2f13a5e4..adadca7954 100644
@@ -33,8 +33,10 @@ typedef struct PRManagerClass {
 
     /* <public> */
     int (*run)(PRManager *pr_mgr, int fd, struct sg_io_hdr *hdr);
+    bool (*is_connected)(PRManager *pr_mgr);
 } PRManagerClass;
 
+bool pr_manager_is_connected(PRManager *pr_mgr);
 BlockAIOCB *pr_manager_execute(PRManager *pr_mgr,
                                AioContext *ctx, int fd,
                                struct sg_io_hdr *hdr,
qapi/block.json +27 -0
index c694524002..dc3323c954 100644
@@ -77,6 +77,33 @@
 { 'struct': 'BlockdevSnapshotInternal',
   'data': { 'device': 'str', 'name': 'str' } }
 
+##
+# @PRManagerInfo:
+#
+# Information about a persistent reservation manager
+#
+# @id: the identifier of the persistent reservation manager
+#
+# @is-connected: whether the persistent reservation manager is connected to
+#                the underlying storage or helper
+#
+# Since: 3.0
+##
+{ 'struct': 'PRManagerInfo',
+  'data': {'id': 'str', 'is-connected': 'bool'} }
+
+##
+# @query-pr-managers:
+#
+# Returns a list of information about each persistent reservation manager.
+#
+# Returns: a list of @PRManagerInfo for each persistent reservation manager
+#
+# Since: 3.0
+##
+{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'] }
+
+
 ##
 # @blockdev-snapshot-internal-sync:
 #
scsi/pr-manager-helper.c +0 -0
index 0c0fe389b7..b11481be9e 100644

scsi/pr-manager-helper.c out: · line 244

Quoted 10 lines
scsi/pr-manager-helper.c +7 -0
@@ -235,6 +235,18 @@ out:
     return ret;
 }
 
+static bool pr_manager_helper_is_connected(PRManager *p)
+{
+    PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(p);
+    bool result;
+
+    qemu_mutex_lock(&pr_mgr->lock);
+    result = (pr_mgr->ioc != NULL);

I worry it is not that easy. pr_mgr->ioc is unset only when there's PR_IN/PR_OUT command coming from the guest (in pr_manager_helper_run -> pr_manager_helper_write). In fact, after 5/5 that is also the time when the event is delivered. But that might be too late for mgmt app to restart the helper process (although pr_manager_helper_run() tries to reconnect for 5 seconds before giving up).

The patch is good code-wise though.

Michal

#11 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

Quoted 14 lines · Michal Privoznik

scsi/pr-manager-helper.c out: · line 244

Quoted 8 lines
scsi/pr-manager-helper.c +7 -0
+static bool pr_manager_helper_is_connected(PRManager *p)
+{
+    PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(p);
+    bool result;
+
+    qemu_mutex_lock(&pr_mgr->lock);
+    result = (pr_mgr->ioc != NULL);

I worry it is not that easy. pr_mgr->ioc is unset only when there's PR_IN/PR_OUT command coming from the guest (in pr_manager_helper_run -> pr_manager_helper_write). In fact, after 5/5 that is also the time when the event is delivered. But that might be too late for mgmt app to restart the helper process (although pr_manager_helper_run() tries to reconnect for 5 seconds before giving up).

That's true, however the important thing IMO is to have a QMP interface that libvirt can use; everything else is just quality of implementation.

qemu-pr-helper anyway does something only when a guests sends it a PR command - and with libvirt's per-guest model, that would (hopefully) mean that the only case that remains is when someone manually kills the qemu-pr-helper process. In that case there's a certain amount of PEBKAC involved... :)

Paolo

Quoted 1 line

The patch is good code-wise though.

#12 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

Quoted 16 lines · Paolo Bonzini
Quoted 14 lines · Michal Privoznik

scsi/pr-manager-helper.c out: · line 244

Quoted 8 lines
scsi/pr-manager-helper.c +7 -0
+static bool pr_manager_helper_is_connected(PRManager *p)
+{
+    PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(p);
+    bool result;
+
+    qemu_mutex_lock(&pr_mgr->lock);
+    result = (pr_mgr->ioc != NULL);

I worry it is not that easy. pr_mgr->ioc is unset only when there's PR_IN/PR_OUT command coming from the guest (in pr_manager_helper_run -> pr_manager_helper_write). In fact, after 5/5 that is also the time when the event is delivered. But that might be too late for mgmt app to restart the helper process (although pr_manager_helper_run() tries to reconnect for 5 seconds before giving up).

Quoted 8 lines

That's true, however the important thing IMO is to have a QMP interface that libvirt can use; everything else is just quality of implementation.

qemu-pr-helper anyway does something only when a guests sends it a PR command - and with libvirt's per-guest model, that would (hopefully) mean that the only case that remains is when someone manually kills the qemu-pr-helper process. In that case there's a certain amount of PEBKAC involved... :)

Unless an assert() is triggered ;-)

But since you merged my suggested changes in 5/5 libvirt can catch the event pretty soon, so in my testing qemu was still left with 3-4 connection retries which is plenty.

Michal

#13 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

Quoted 7 lines · Michal Prívozník
Quoted 5 lines

qemu-pr-helper anyway does something only when a guests sends it a PR command - and with libvirt's per-guest model, that would (hopefully) mean that the only case that remains is when someone manually kills the qemu-pr-helper process. In that case there's a certain amount of PEBKAC involved... :)

Unless an assert() is triggered ;-)

Indeed, but that should still happen "when a guest sends it a PR command". The problematic case would only arise if qemu-pr-helper crashes between the last time QEMU sent a command, and the time libvirt sends query-pr-managers.

Quoted 3 lines

But since you merged my suggested changes in 5/5 libvirt can catch the event pretty soon, so in my testing qemu was still left with 3-4 connection retries which is plenty.

Good, thanks.

Paolo

#14 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

In reply to Paolo Bonzini
Quoted 15 lines · Paolo Bonzini

This command lets you query the connection status of each pr-manager-helper object.

---

+++ b/qapi/block.json

qapi/block.json +4 -0
@@ -77,6 +77,33 @@
  { 'struct': 'BlockdevSnapshotInternal',
    'data': { 'device': 'str', 'name': 'str' } }
 
+##
+# @PRManagerInfo:
+#
+# Information about a persistent reservation manager

qapi/block.json line 93

Quoted 10 lines
qapi/block.json +10 -0
+#
+# @id: the identifier of the persistent reservation manager
+#
+# @is-connected: whether the persistent reservation manager is connected to
+#                the underlying storage or helper
+#
+# Since: 3.0
+##
+{ 'struct': 'PRManagerInfo',
+  'data': {'id': 'str', 'is-connected': 'bool'} }

Bike-shedding: I think 'connected' is a reasonable (and shorter) name for this member

qapi/block.json line 105

Quoted 12 lines
qapi/block.json +12 -0
+
+##
+# @query-pr-managers:
+#
+# Returns a list of information about each persistent reservation manager.
+#
+# Returns: a list of @PRManagerInfo for each persistent reservation manager
+#
+# Since: 3.0
+##
+{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'] }
+

As a query command, does it make sense to consider whether this command could be provided during preconfig?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#15 lore raw

Re: [Qemu-devel] [PATCH 4/5] pr-manager: add query-pr-managers QMP command

Quoted 22 lines · Eric Blake
Quoted 21 lines · Paolo Bonzini

This command lets you query the connection status of each pr-manager-helper
object.

---

+++ b/qapi/block.json

qapi/block.json +0 -0
@@ -77,6 +77,33 @@
   { 'struct': 'BlockdevSnapshotInternal',
     'data': { 'device': 'str', 'name': 'str' } }

  +##

qapi/block.json +7 -0
+# @PRManagerInfo:
+#
+# Information about a persistent reservation manager
+#
+# @id: the identifier of the persistent reservation manager
+#
+# @is-connected: whether the persistent reservation manager is

connected to
+#                the underlying storage or helper

Quoted 8 lines

qapi/block.json line 93

Quoted 5 lines
qapi/block.json +5 -0
+#
+# Since: 3.0
+##
+{ 'struct': 'PRManagerInfo',
+  'data': {'id': 'str', 'is-connected': 'bool'} }

Bike-shedding: I think 'connected' is a reasonable (and shorter) name for this member

Sounds good.

Quoted 9 lines
Quoted 9 lines
qapi/block.json +5 -0
+
+##
+# @query-pr-managers:
+#
+# Returns a list of information about each persistent reservation

manager.

(quoted diff) +2 -0
+#
+# Returns: a list of @PRManagerInfo for each persistent reservation

manager

Quoted 8 lines

qapi/block.json line 105

Quoted 5 lines
qapi/block.json +5 -0
+#
+# Since: 3.0
+##
+{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'] }
+

As a query command, does it make sense to consider whether this command could be provided during preconfig?

Yes, definitely.

Paolo

#16 lore raw

PATCH 5/5 pr-manager-helper: report event on connection/disconnection

In reply to Paolo Bonzini

Let management know if there were any problems communicating with qemu-pr-helper. The event is edge-triggered, and is sent every time the connection status of the pr-manager-helper object changes.

---
 qapi/block.json          | 24 ++++++++++++++++++++++++
 scsi/pr-manager-helper.c | 25 +++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)
qapi/block.json +24 -0
index dc3323c954..1882a8d107 100644
@@ -334,6 +334,30 @@
 { 'event': 'DEVICE_TRAY_MOVED',
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
 
+##
+# @PR_MANAGER_STATUS_CHANGED:
+#
+# Emitted whenever the connected status of a persistent reservation
+# manager changes.
+#
+# @id: The QOM path of the PR manager object
+#
+# @connected: true if the PR manager is connected to a backend
+#
+# Since: 2.12
+#
+# Example:
+#
+# <- { "event": "PR_MANAGER_STATUS_CHANGED",
+#      "data": { "id": "/object/pr-helper0",
+#                "connected": true
+#      },
+#      "timestamp": { "seconds": 1519840375, "microseconds": 450486 } }
+#
+##
+{ 'event': 'PR_MANAGER_STATUS_CHANGED',
+  'data': { 'id': 'str', 'connected': 'bool' } }
+
 ##
 # @QuorumOpType:
 #
scsi/pr-manager-helper.c +19 -6
index b11481be9e..6643caf4cf 100644
@@ -17,6 +17,7 @@
 #include "io/channel.h"
 #include "io/channel-socket.h"
 #include "pr-helper.h"
+#include "qapi/qapi-events-block.h"
 
 #include <scsi/sg.h>
 
@@ -33,6 +34,7 @@ typedef struct PRManagerHelper {
     PRManager parent;
 
     char *path;
+    char *qom_path;
 
     QemuMutex lock;
     QIOChannel *ioc;
@@ -127,6 +129,8 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
         goto out_close;
     }
 
+    qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, true,
+                                              &error_abort);
     return 0;
 
 out_close:
@@ -142,9 +146,11 @@ static int pr_manager_helper_run(PRManager *p,
 
     uint32_t len;
     PRHelperResponse resp;
+    int sense_len;
     int ret;
     int expected_dir;
     int attempts;
+    bool was_connected = pr_mgr->ioc != NULL;
     uint8_t cdb[PR_HELPER_CDB_SIZE] = { 0 };
 
     if (!io_hdr->cmd_len || io_hdr->cmd_len > PR_HELPER_CDB_SIZE) {
@@ -222,15 +228,19 @@ static int pr_manager_helper_run(PRManager *p,
         io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, PR_HELPER_SENSE_SIZE);
         memcpy(io_hdr->sbp, resp.sense, io_hdr->sb_len_wr);
     }
+    qemu_mutex_unlock(&pr_mgr->lock);
+    return ret;
 
 out:
-    if (ret < 0) {
-        int sense_len = scsi_build_sense(io_hdr->sbp,
-                                         SENSE_CODE(LUN_COMM_FAILURE));
-        io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
-        io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
-        io_hdr->status = CHECK_CONDITION;
+    if (was_connected) {
+        qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
+                                                  &error_abort);
     }
+
+    sense_len = scsi_build_sense(io_hdr->sbp, SENSE_CODE(LUN_COMM_FAILURE));
+    io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
+    io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
+    io_hdr->status = CHECK_CONDITION;
     qemu_mutex_unlock(&pr_mgr->lock);
     return ret;
 }
@@ -251,6 +261,8 @@ static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
 {
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
 
+    pr_mgr->qom_path = object_get_canonical_path(OBJECT(pr_mgr));
+
     qemu_mutex_lock(&pr_mgr->lock);
     pr_manager_helper_initialize(pr_mgr, errp);
     qemu_mutex_unlock(&pr_mgr->lock);
@@ -276,6 +288,7 @@ static void pr_manager_helper_instance_finalize(Object *obj)
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(obj);
 
     object_unref(OBJECT(pr_mgr->ioc));
+    g_free(pr_mgr->qom_path);
     qemu_mutex_destroy(&pr_mgr->lock);
 }
 
Signature · 1 line
2.17.1
#17 lore raw

Re: [Qemu-devel] [PATCH 5/5] pr-manager-helper: report event on connection/disconnection

Hi Paolo,

Quoted 19 lines · Paolo Bonzini

Let management know if there were any problems communicating with qemu-pr-helper. The event is edge-triggered, and is sent every time the connection status of the pr-manager-helper object changes.

---
 qapi/block.json          | 24 ++++++++++++++++++++++++
 scsi/pr-manager-helper.c | 25 +++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)
qapi/block.json +1 -0
index dc3323c954..1882a8d107 100644
@@ -334,6 +334,30 @@
 { 'event': 'DEVICE_TRAY_MOVED',
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
 
+##

qapi/block.json line 347

Quoted 10 lines
qapi/block.json +10 -0
+# @PR_MANAGER_STATUS_CHANGED:
+#
+# Emitted whenever the connected status of a persistent reservation
+# manager changes.
+#
+# @id: The QOM path of the PR manager object
+#
+# @connected: true if the PR manager is connected to a backend
+#
+# Since: 2.12

3.0?

Quoted 58 lines
qapi/block.json +13 -0
+#
+# Example:
+#
+# <- { "event": "PR_MANAGER_STATUS_CHANGED",
+#      "data": { "id": "/object/pr-helper0",
+#                "connected": true
+#      },
+#      "timestamp": { "seconds": 1519840375, "microseconds": 450486 } }
+#
+##
+{ 'event': 'PR_MANAGER_STATUS_CHANGED',
+  'data': { 'id': 'str', 'connected': 'bool' } }
+
 ##
 # @QuorumOpType:
 #
scsi/pr-manager-helper.c +6 -0
index b11481be9e..6643caf4cf 100644
@@ -17,6 +17,7 @@
 #include "io/channel.h"
 #include "io/channel-socket.h"
 #include "pr-helper.h"
+#include "qapi/qapi-events-block.h"
 
 #include <scsi/sg.h>
 
@@ -33,6 +34,7 @@ typedef struct PRManagerHelper {
     PRManager parent;
 
     char *path;
+    char *qom_path;
 
     QemuMutex lock;
     QIOChannel *ioc;
@@ -127,6 +129,8 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
         goto out_close;
     }
 
+    qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, true,
+                                              &error_abort);
     return 0;
 
 out_close:
@@ -142,9 +146,11 @@ static int pr_manager_helper_run(PRManager *p,
 
     uint32_t len;
     PRHelperResponse resp;
+    int sense_len;
     int ret;
     int expected_dir;
     int attempts;
+    bool was_connected = pr_mgr->ioc != NULL;
     uint8_t cdb[PR_HELPER_CDB_SIZE] = { 0 };
 
     if (!io_hdr->cmd_len || io_hdr->cmd_len > PR_HELPER_CDB_SIZE) {

scsi/pr-manager-helper.c static int pr_manager_helper_run(PRManager *p, · line 232

Quoted 5 lines
scsi/pr-manager-helper.c +2 -0
@@ -222,15 +228,19 @@ static int pr_manager_helper_run(PRManager *p,
         io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, PR_HELPER_SENSE_SIZE);
         memcpy(io_hdr->sbp, resp.sense, io_hdr->sb_len_wr);
     }
+    qemu_mutex_unlock(&pr_mgr->lock);
+    return ret;

Maybe this big function can be refactored in 2, the second being the bottom code with the mutex locked.

Quoted 38 lines
scsi/pr-manager-helper.c +11 -6
 out:
-    if (ret < 0) {
-        int sense_len = scsi_build_sense(io_hdr->sbp,
-                                         SENSE_CODE(LUN_COMM_FAILURE));
-        io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
-        io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
-        io_hdr->status = CHECK_CONDITION;
+    if (was_connected) {
+        qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
+                                                  &error_abort);
     }
+
+    sense_len = scsi_build_sense(io_hdr->sbp, SENSE_CODE(LUN_COMM_FAILURE));
+    io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
+    io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
+    io_hdr->status = CHECK_CONDITION;
     qemu_mutex_unlock(&pr_mgr->lock);
     return ret;
 }
@@ -251,6 +261,8 @@ static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
 {
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
 
+    pr_mgr->qom_path = object_get_canonical_path(OBJECT(pr_mgr));
+
     qemu_mutex_lock(&pr_mgr->lock);
     pr_manager_helper_initialize(pr_mgr, errp);
     qemu_mutex_unlock(&pr_mgr->lock);
@@ -276,6 +288,7 @@ static void pr_manager_helper_instance_finalize(Object *obj)
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(obj);
 
     object_unref(OBJECT(pr_mgr->ioc));
+    g_free(pr_mgr->qom_path);
     qemu_mutex_destroy(&pr_mgr->lock);
 }
 
#18 lore raw

Re: [Qemu-devel] [PATCH 5/5] pr-manager-helper: report event on connection/disconnection

In reply to Paolo Bonzini
Quoted 113 lines · Paolo Bonzini

Let management know if there were any problems communicating with qemu-pr-helper. The event is edge-triggered, and is sent every time the connection status of the pr-manager-helper object changes.

---
 qapi/block.json          | 24 ++++++++++++++++++++++++
 scsi/pr-manager-helper.c | 25 +++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)
qapi/block.json +24 -0
index dc3323c954..1882a8d107 100644
@@ -334,6 +334,30 @@
 { 'event': 'DEVICE_TRAY_MOVED',
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
 
+##
+# @PR_MANAGER_STATUS_CHANGED:
+#
+# Emitted whenever the connected status of a persistent reservation
+# manager changes.
+#
+# @id: The QOM path of the PR manager object
+#
+# @connected: true if the PR manager is connected to a backend
+#
+# Since: 2.12
+#
+# Example:
+#
+# <- { "event": "PR_MANAGER_STATUS_CHANGED",
+#      "data": { "id": "/object/pr-helper0",
+#                "connected": true
+#      },
+#      "timestamp": { "seconds": 1519840375, "microseconds": 450486 } }
+#
+##
+{ 'event': 'PR_MANAGER_STATUS_CHANGED',
+  'data': { 'id': 'str', 'connected': 'bool' } }
+
 ##
 # @QuorumOpType:
 #
scsi/pr-manager-helper.c +16 -6
index b11481be9e..6643caf4cf 100644
@@ -17,6 +17,7 @@
 #include "io/channel.h"
 #include "io/channel-socket.h"
 #include "pr-helper.h"
+#include "qapi/qapi-events-block.h"
 
 #include <scsi/sg.h>
 
@@ -33,6 +34,7 @@ typedef struct PRManagerHelper {
     PRManager parent;
 
     char *path;
+    char *qom_path;
 
     QemuMutex lock;
     QIOChannel *ioc;
@@ -127,6 +129,8 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
         goto out_close;
     }
 
+    qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, true,
+                                              &error_abort);
     return 0;
 
 out_close:
@@ -142,9 +146,11 @@ static int pr_manager_helper_run(PRManager *p,
 
     uint32_t len;
     PRHelperResponse resp;
+    int sense_len;
     int ret;
     int expected_dir;
     int attempts;
+    bool was_connected = pr_mgr->ioc != NULL;
     uint8_t cdb[PR_HELPER_CDB_SIZE] = { 0 };
 
     if (!io_hdr->cmd_len || io_hdr->cmd_len > PR_HELPER_CDB_SIZE) {
@@ -222,15 +228,19 @@ static int pr_manager_helper_run(PRManager *p,
         io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, PR_HELPER_SENSE_SIZE);
         memcpy(io_hdr->sbp, resp.sense, io_hdr->sb_len_wr);
     }
+    qemu_mutex_unlock(&pr_mgr->lock);
+    return ret;
 
 out:
-    if (ret < 0) {
-        int sense_len = scsi_build_sense(io_hdr->sbp,
-                                         SENSE_CODE(LUN_COMM_FAILURE));
-        io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
-        io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
-        io_hdr->status = CHECK_CONDITION;
+    if (was_connected) {
+        qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
+                                                  &error_abort);
     }
+
+    sense_len = scsi_build_sense(io_hdr->sbp, SENSE_CODE(LUN_COMM_FAILURE));
+    io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
+    io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
+    io_hdr->status = CHECK_CONDITION;
     qemu_mutex_unlock(&pr_mgr->lock);
     return ret;
 }

scsi/pr-manager-helper.c static void pr_manager_helper_complete(UserCreatable *uc, Error **errp) · line 264

Quoted 4 lines
scsi/pr-manager-helper.c +1 -0
@@ -251,6 +261,8 @@ static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
 {
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
 
+    pr_mgr->qom_path = object_get_canonical_path(OBJECT(pr_mgr));

Might be worth returning just object_get_canonical_path_component() so that the event looks like this:

{"event": "PR_MANAGER_STATUS_CHANGED", "data": {"connected": false, "id": "pr-helper0"}}

(instead of full /object/pr-helper0 path). This corresponds to what 'query-pr-managers' returns too.

Michal

#19 lore raw

Re: [Qemu-devel] [PATCH 5/5] pr-manager-helper: report event on connection/disconnection

In reply to Paolo Bonzini
Quoted 66 lines · Paolo Bonzini

Let management know if there were any problems communicating with qemu-pr-helper. The event is edge-triggered, and is sent every time the connection status of the pr-manager-helper object changes.

---
 qapi/block.json          | 24 ++++++++++++++++++++++++
 scsi/pr-manager-helper.c | 25 +++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)
qapi/block.json +24 -0
index dc3323c954..1882a8d107 100644
@@ -334,6 +334,30 @@
 { 'event': 'DEVICE_TRAY_MOVED',
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
 
+##
+# @PR_MANAGER_STATUS_CHANGED:
+#
+# Emitted whenever the connected status of a persistent reservation
+# manager changes.
+#
+# @id: The QOM path of the PR manager object
+#
+# @connected: true if the PR manager is connected to a backend
+#
+# Since: 2.12
+#
+# Example:
+#
+# <- { "event": "PR_MANAGER_STATUS_CHANGED",
+#      "data": { "id": "/object/pr-helper0",
+#                "connected": true
+#      },
+#      "timestamp": { "seconds": 1519840375, "microseconds": 450486 } }
+#
+##
+{ 'event': 'PR_MANAGER_STATUS_CHANGED',
+  'data': { 'id': 'str', 'connected': 'bool' } }
+
 ##
 # @QuorumOpType:
 #
scsi/pr-manager-helper.c +2 -0
index b11481be9e..6643caf4cf 100644
@@ -17,6 +17,7 @@
 #include "io/channel.h"
 #include "io/channel-socket.h"
 #include "pr-helper.h"
+#include "qapi/qapi-events-block.h"
 
 #include <scsi/sg.h>
 
@@ -33,6 +34,7 @@ typedef struct PRManagerHelper {
     PRManager parent;
 
     char *path;
+    char *qom_path;
 
     QemuMutex lock;
     QIOChannel *ioc;

scsi/pr-manager-helper.c static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr, · line 134

Quoted 6 lines
scsi/pr-manager-helper.c +2 -0
@@ -127,6 +129,8 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
         goto out_close;
     }
 
+    qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, true,
+                                              &error_abort);
     return 0;

Also, can we emit this earlier? For instance at the two places where we unset pr_mgr->ioc:

scsi/pr-manager-helper.c +5 -7
index 6643caf4cf..4ca15dff3f 100644
@@ -48,6 +48,8 @@ static int pr_manager_helper_read(PRManagerHelper *pr_mgr,
 
     if (r < 0) {
         object_unref(OBJECT(pr_mgr->ioc));
+        qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
+                                                  &error_abort);
         pr_mgr->ioc = NULL;
         return -EINVAL;
     }
@@ -74,6 +76,8 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mgr,
             assert(n_written != QIO_CHANNEL_ERR_BLOCK);
             object_unref(OBJECT(pr_mgr->ioc));
             pr_mgr->ioc = NULL;
+            qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
+                                                      &error_abort);
             return n_written < 0 ? -EINVAL : 0;
         }
 
@@ -150,7 +154,6 @@ static int pr_manager_helper_run(PRManager *p,
     int ret;
     int expected_dir;
     int attempts;
-    bool was_connected = pr_mgr->ioc != NULL;
     uint8_t cdb[PR_HELPER_CDB_SIZE] = { 0 };
 
     if (!io_hdr->cmd_len || io_hdr->cmd_len > PR_HELPER_CDB_SIZE) {
@@ -232,11 +235,6 @@ static int pr_manager_helper_run(PRManager *p,
     return ret;
 
 out:
-    if (was_connected) {
-        qapi_event_send_pr_manager_status_changed(pr_mgr->qom_path, false,
-                                                  &error_abort);
-    }
-
     sense_len = scsi_build_sense(io_hdr->sbp, SENSE_CODE(LUN_COMM_FAILURE));
     io_hdr->driver_status = SG_ERR_DRIVER_SENSE;
     io_hdr->sb_len_wr = MIN(io_hdr->mx_sb_len, sense_len);
@@ -261,7 +259,7 @@ static void pr_manager_helper_complete(UserCreatable *uc, Error **errp)
 {
     PRManagerHelper *pr_mgr = PR_MANAGER_HELPER(uc);
 
-    pr_mgr->qom_path = object_get_canonical_path(OBJECT(pr_mgr));
+    pr_mgr->qom_path = object_get_canonical_path_component(OBJECT(pr_mgr));
 
     qemu_mutex_lock(&pr_mgr->lock);
     pr_manager_helper_initialize(pr_mgr, errp);

With your approach the event is emitted only after the 5 reconnect attempts (which makes little sense IMO). With my approach the event is emitted a bit sooner so that reconnect has at least chance of succeeding.

I've written some patches for libvirt and with these changes it works well.

Michal

#20 lore raw

Re: [Qemu-devel] [PATCH 5/5] pr-manager-helper: report event on connection/disconnection

Quoted 7 lines · Michal Privoznik

Also, can we emit this earlier? For instance at the two places where we unset pr_mgr->ioc:

With your approach the event is emitted only after the 5 reconnect attempts (which makes little sense IMO). With my approach the event is emitted a bit sooner so that reconnect has at least chance of succeeding.

Much better, yes. I included your change.

Paolo