pr-manager/qemu-pr-helper patches for QEMU 3.0
v2 cover pr-manager/qemu-pr-helper patches for QEMU 3.0
The first three patches are more or less trivial bugfixes. The last three allow libvirt to know the status of the qemu-pr-helper process that is attached to a running QEMU instance.
Thanks,
Paolo
v1->v2: new patch for non-Linux portability
issue event as soon as the socket is disconnected do not include full object path in event renamed "is_connected" field to "connected"
Paolo Bonzini (6):
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: put stubs in .c file
pr-manager: add query-pr-managers QMP command
pr-manager-helper: report event on connection/disconnection
include/scsi/pr-manager.h | 11 ++-------- qapi/block.json | 52 +++++++++++++++++++++++++++++++++++++++++++++++ scsi/Makefile.objs | 1 + scsi/pr-manager-helper.c | 28 +++++++++++++++++++++++++ scsi/pr-manager-stub.c | 30 +++++++++++++++++++++++++++ scsi/pr-manager.c | 45 ++++++++++++++++++++++++++++++++++++++++ scsi/qemu-pr-helper.c | 21 +++++++++++-------- 7 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 scsi/pr-manager-stub.c
Signature · 1 line
1.8.3.1
PATCH v2 1/6 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
@@ -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
1.8.3.1
PATCH v2 2/6 pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN
In reply to Paolo BonziniThe 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
@@ -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
1.8.3.1
PATCH v2 3/6 pr-manager-helper: avoid SIGSEGV when writing to the socket fail
In reply to Paolo BonziniWhen 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
@@ -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
1.8.3.1
PATCH v2 4/6 pr-manager: put stubs in .c file
In reply to Paolo Bonzini--- include/scsi/pr-manager.h | 9 --------- scsi/Makefile.objs | 1 + scsi/pr-manager-stub.c | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 scsi/pr-manager-stub.c
include/scsi/pr-manager.h +0 -9
@@ -41,15 +41,6 @@ BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, BlockCompletionFunc *complete, void *opaque); -#ifdef CONFIG_LINUX PRManager *pr_manager_lookup (const char *id,Error **errp); -#else -static inline PRManager *pr_manager_lookup (const char *id,Error **errp) -{ -/* The classes do not exist at all! */ -error_setg (errp,"No persistent reservation manager with id '%s'" , id); -return NULL ; -} -#endif #endif
scsi/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ block-obj-y += utils.o block-obj-$(CONFIG_LINUX) += pr-manager.o pr-manager-helper.o +block-obj-$(call lnot,$(CONFIG_LINUX)) += pr-manager-stub.o
scsi/pr-manager-stub.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Persistent reservation manager - stub for non-Linux platforms +* +* Copyright (c) 2018 Red Hat, Inc. +* +* Author: Paolo Bonzini <[email protected]> +* +* This code is licensed under the LGPL. +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "scsi/pr-manager.h" +#include "trace.h" +#include "qapi/qapi-types-block.h" +#include "qapi/qapi-commands-block.h" + +PRManager *pr_manager_lookup (const char *id,Error **errp) +{ +/* The classes do not exist at all! */ +error_setg (errp,"No persistent reservation manager with id '%s'" , id); +return NULL ; +}
Signature · 1 line
1.8.3.1
PATCH v2 5/6 pr-manager: add query-pr-managers QMP command
In reply to Paolo BonziniThis command lets you query the connection status of each pr-manager-helper object.
--- include/scsi/pr-manager.h | 2 ++ qapi/block.json | 28 ++++++++++++++++++++++++++++ scsi/pr-manager-helper.c | 13 +++++++++++++ scsi/pr-manager-stub.c | 6 ++++++ scsi/pr-manager.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+)
include/scsi/pr-manager.h +2 -0
@@ -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 +28 -0
@@ -78,6 +78,34 @@ 'data': { 'device': 'str', 'name': 'str' } } ## +# @PRManagerInfo: +# +# Information about a persistent reservation manager +# +# @id: the identifier of the persistent reservation manager +# +# @connected: true if the persistent reservation manager is connected to +# the underlying storage or helper +# +# Since: 3.0 +## +{ 'struct': 'PRManagerInfo', + 'data': {'id': 'str', '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'], + 'allow-preconfig': true } + + +## # @blockdev-snapshot-internal-sync: # # Synchronously take an internal snapshot of a block device, when the
scsi/pr-manager-helper.c +13 -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 ); +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-stub.c +6 -0
@@ -22,3 +22,9 @@ PRManager *pr_manager_lookup(const char *id, Error **errp)error_setg (errp,"No persistent reservation manager with id '%s'" , id);return NULL ; } + + +PRManagerInfoList *qmp_query_pr_managers (Error **errp) +{ +return NULL ; +}
scsi/pr-manager.c +45 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 6/6 pr-manager-helper: report event on connection/disconnection
In reply to Paolo BonziniLet 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 | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
qapi/block.json +24 -0
@@ -359,6 +359,30 @@ '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 id of the PR manager object +# +# @connected: true if the PR manager is connected to a backend +# +# Since: 3.0 +# +# Example: +# +# <- { "event": "PR_MANAGER_STATUS_CHANGED", +# "data": { "id": "pr-helper0", +# "connected": true +# }, +# "timestamp": { "seconds": 1519840375, "microseconds": 450486 } } +# +## +{ 'event': 'PR_MANAGER_STATUS_CHANGED', + 'data': { 'id': 'str', 'connected': 'bool' } } + +## # @QuorumOpType: # # An enumeration of the quorum operation types
scsi/pr-manager-helper.c +14 -0
@@ -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>
@@ -38,6 +39,16 @@ typedef struct PRManagerHelper {QIOChannel *ioc; } PRManagerHelper; +static void pr_manager_send_status_changed_event (PRManagerHelper *pr_mgr) +{ +char *id =object_get_canonical_path_component (OBJECT (pr_mgr)); + +if (id) { +qapi_event_send_pr_manager_status_changed (id, !!pr_mgr->ioc, + &error_abort); + } +} +/* Called with lock held. */ static int pr_manager_helper_read (PRManagerHelper *pr_mgr,void *buf,int sz,Error **errp)
@@ -47,6 +58,7 @@ static int pr_manager_helper_read(PRManagerHelper *pr_mgr,if (r <0 ) {object_unref (OBJECT (pr_mgr->ioc)); pr_mgr->ioc =NULL ; +pr_manager_send_status_changed_event (pr_mgr);return -EINVAL ; }
@@ -72,6 +84,7 @@ 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 ; +pr_manager_send_status_changed_event (pr_mgr);return n_written <0 ? -EINVAL :0 ; }
@@ -127,6 +140,7 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr, goto out_close; } +pr_manager_send_status_changed_event (pr_mgr);return 0 ; out_close:
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 6/6] pr-manager-helper: report event on connection/disconnection
Quoted 3 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.
Is this something that guest actions can intentionally trigger, and thus cause a DoS attack by flooding the management app with events faster than they can process? If so, this event should use rate-limiting.
Quoted 6 lines
Signed-off-by Paolo Bonzini <[email protected]>--- qapi/block.json | 24 ++++++++++++++++++++++++ scsi/pr-manager-helper.c | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 6/6] pr-manager-helper: report event on connection/disconnection
Quoted 8 lines · Eric Blake
Quoted 3 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.
Is this something that guest actions can intentionally trigger, and thus cause a DoS attack by flooding the management app with events faster than they can process?
No, unless they find a way to crash qemu-pr-helper and libvirt immediately restarts it. If anything libvirt could throttle the restart of the process, or ultimately not restart it at all, but I don't think it's necessary.
Paolo
Quoted 9 lines
If so, this event should use rate-limiting.
Quoted 6 lines
Signed-off-by Paolo Bonzini <[email protected]>---
qapi/block.json | 24 ++++++++++++++++++++++++scsi/pr-manager-helper.c| 14 ++++++++++++++2 files changed, 38 insertions(+)