tools: remove xenstore entries on vchan server closure
PATCH 1/4 tools: remove xenstore entries on vchan server closure
From: Oleksandr Andrushchenko <[email protected]>
vchan server creates XenStore entries to advertise its event channel and ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try to connect to a non-existing server.
--- tools/include/libxenvchan.h | 5 +++++ tools/libs/vchan/init.c | 23 +++++++++++++++++++++++ tools/libs/vchan/io.c | 4 ++++ tools/libs/vchan/vchan.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tools/libs/vchan/vchan.h
tools/include/libxenvchan.h +5 -0
@@ -86,6 +86,11 @@ struct libxenvchan { int blocking:1;/* communication rings */ struct libxenvchan_ring read, write; +/** +* Base xenstore path for storing ring/event data used by the server +* during cleanup. +* */ +char *xs_path; };/**
tools/libs/vchan/init.c +23 -0
@@ -46,6 +46,8 @@#include <xen/sys/gntdev.h> #include <libxenvchan.h> +#include "vchan.h" +#ifndef PAGE_SHIFT #define PAGE_SHIFT 12#endif
@@ -251,6 +253,10 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_basechar ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ; + +// store the base path so we can clean up on server closure + ctrl->xs_path =strdup (xs_base); + xs =xs_open (0 );if (!xs) goto fail;
@@ -298,6 +304,23 @@ retry_transaction:return ret; } +void close_xs_srv (struct libxenvchan *ctrl) +{ +struct xs_handle *xs; + +if (!ctrl->xs_path) +return ; + + xs =xs_open (0 ); +if (!xs) + goto fail; + +xs_rm (xs,XBT_NULL , ctrl->xs_path); + +fail: +free (ctrl->xs_path); +} +static int min_order (size_t siz) {int rv =PAGE_SHIFT ;
tools/libs/vchan/io.c +4 -0
@@ -40,6 +40,8 @@#include <xenctrl.h> #include <libxenvchan.h> +#include "vchan.h" +#ifndef PAGE_SHIFT #define PAGE_SHIFT 12#endif
@@ -384,5 +386,7 @@ void libxenvchan_close(struct libxenvchan *ctrl)if (ctrl->gnttab)xengnttab_close (ctrl->gnttab); } +if (ctrl->is_server) +close_xs_srv (ctrl);free (ctrl); }
tools/libs/vchan/vchan.h new file +31 -0
@@ -0,0 +1,31 @@ +/** +* @file +* @section AUTHORS +* +* Copyright (C) 2021 EPAM Systems Inc. +* +* @section LICENSE +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; If not, see <http://www.gnu.org/licenses/>. +* +* @section DESCRIPTION +* +* This file contains common libxenvchan declarations. +*/ +#ifndef LIBVCHAN_H +#define LIBVCHAN_H + +void close_xs_srv (struct libxenvchan *ctrl); + +#endif /* LIBVCHAN_H */
Signature · 1 line
2.25.1
PATCH 2/4 tools: allow vchan XenStore paths more then 64 bytes long
From: Oleksandr Andrushchenko <[email protected]>
Current vchan implementation, while dealing with XenStore paths, allocates 64 bytes buffer on the stack which may not be enough for some use-cases. Make the buffer longer to respect maximum allowed XenStore path of XENSTORE_ABS_PATH_MAX.
--- tools/libs/vchan/init.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
tools/libs/vchan/init.c +22 -6
@@ -249,7 +249,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseint ret =-1 ;struct xs_handle *xs;struct xs_permissions perms[2 ]; -char buf[64 ]; +char *buf;char ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ;
@@ -257,6 +257,12 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base// store the base path so we can clean up on server closure ctrl->xs_path =strdup (xs_base); + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + xs =xs_open (0 );if (!xs) goto fail;
@@ -278,14 +284,14 @@ retry_transaction: goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 ))
@@ -301,6 +307,7 @@ retry_transaction:free (domid_str);xs_close (xs); fail: +free (buf);return ret; }
@@ -418,13 +425,20 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, {struct libxenvchan *ctrl =malloc (sizeof (struct libxenvchan ));struct xs_handle *xs =NULL ; -char buf[64 ]; +char *buf;char *ref;int ring_ref;unsigned int len;if (!ctrl)return 0 ; + + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + ctrl->ring =NULL ; ctrl->event =NULL ; ctrl->gnttab =NULL ;
@@ -435,8 +449,9 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (!xs) goto fail; +// find xenstore entry -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
@@ -444,7 +459,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,free (ref);if (!ring_ref) goto fail; -snprintf (buf,sizeof buf,"%s/event-channel" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
@@ -474,6 +489,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, out:if (xs)xs_close (xs); +free (buf);return ctrl; fail:libxenvchan_close (ctrl);
Signature · 1 line
2.25.1
Re: [PATCH 2/4] tools: allow vchan XenStore paths more then 64 bytes long
Quoted 86 lines · On 09.07.22 12:10, [email protected] wrote:
From: Oleksandr Andrushchenko <[email protected]>
Current vchan implementation, while dealing with XenStore paths, allocates 64 bytes buffer on the stack which may not be enough for some use-cases. Make the buffer longer to respect maximum allowed XenStore path of
XENSTORE_ABS_PATH_MAX.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/libs/vchan/init.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)tools/libs/vchan/init.c +18
-4@@ -249,7 +249,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseint ret =-1 ;struct xs_handle *xs;struct xs_permissions perms[2 ]; -char buf[64 ]; +char *buf;char ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ;@@ -257,6 +257,12 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base// store the base path so we can clean up on server closure ctrl->xs_path =strdup (xs_base); + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + xs =xs_open (0 );if (!xs) goto fail;@@ -278,14 +284,14 @@ retry_transaction: goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 ))@@ -301,6 +307,7 @@ retry_transaction:free (domid_str);xs_close (xs); fail: +free (buf);return ret; }@@ -418,13 +425,20 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, {struct libxenvchan *ctrl =malloc (sizeof (struct libxenvchan ));struct xs_handle *xs =NULL ; -char buf[64 ]; +char *buf;char *ref;int ring_ref;unsigned int len;if (!ctrl)return 0 ; + + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + ctrl->ring =NULL ; ctrl->event =NULL ; ctrl->gnttab =NULL ;
tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 450
Quoted 2 lines
tools/libs/vchan/init.c +0
-0@@ -435,8 +449,9 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (!xs) goto fail;
You are leaking buf in this case.
Quoted 18 lines
tools/libs/vchan/init.c +3
-2+// find xenstore entry -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;@@ -444,7 +459,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,free (ref);if (!ring_ref) goto fail; -snprintf (buf,sizeof buf,"%s/event-channel" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 495
Quoted 7 lines
tools/libs/vchan/init.c +1
-0@@ -474,6 +489,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, out:if (xs)xs_close (xs); +free (buf);return ctrl; fail:libxenvchan_close (ctrl);
Juergen
Re: [PATCH 2/4] tools: allow vchan XenStore paths more then 64 bytes long
Hello Juergen,
пн, 11 июл. 2022 г. в 10:24, Juergen Gross <[email protected]>:
Quoted 84 lines · On 09.07.22 12:10, [email protected] wrote:
Quoted 82 lines
From: Oleksandr Andrushchenko <[email protected]>
Current vchan implementation, while dealing with XenStore paths, allocates 64 bytes buffer on the stack which may not be enough for some use-cases. Make the buffer longer to respect maximum allowed XenStore path of
XENSTORE_ABS_PATH_MAX.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/libs/vchan/init.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)tools/libs/vchan/init.c +18
-4@@ -249,7 +249,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseint ret =-1 ;struct xs_handle *xs;struct xs_permissions perms[2 ]; -char buf[64 ]; +char *buf;char ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ;@@ -257,6 +257,12 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base// store the base path so we can clean up on server closure ctrl->xs_path =strdup (xs_base); + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + xs =xs_open (0 );if (!xs) goto fail;@@ -278,14 +284,14 @@ retry_transaction: goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 ))@@ -301,6 +307,7 @@ retry_transaction:free (domid_str);xs_close (xs); fail: +free (buf);return ret; }@@ -418,13 +425,20 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, {struct libxenvchan *ctrl =malloc (sizeof (struct libxenvchan ));struct xs_handle *xs =NULL ; -char buf[64 ]; +char *buf;char *ref;int ring_ref;unsigned int len;if (!ctrl)return 0 ; + + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } +
Quoted 8 lines
tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 450
Quoted 6 lines
tools/libs/vchan/init.c +0
-0ctrl->ring =NULL ; ctrl->event =NULL ; ctrl->gnttab =NULL ;@@ -435,8 +449,9 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (!xs) goto fail;You are leaking buf in this case.
No. buf released in line 474. ctrl leaks in fail case
Quoted 28 lines
Quoted 19 lines
tools/libs/vchan/init.c +3
-2+// find xenstore entry -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;@@ -444,7 +459,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,free (ref);if (!ring_ref) goto fail; -snprintf (buf,sizeof buf,"%s/event-channel" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 495
Quoted 7 lines
tools/libs/vchan/init.c +1
-0@@ -474,6 +489,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, out:if (xs)xs_close (xs); +free (buf);return ctrl; fail:libxenvchan_close (ctrl);Juergen
Re: [PATCH 2/4] tools: allow vchan XenStore paths more then 64 bytes long
Quoted 94 lines · Dmytro Semenets
Hello Juergen,
пн, 11 июл. 2022 г. в 10:24, Juergen Gross <[email protected]>:Quoted 84 lines · On 09.07.22 12:10, [email protected] wrote:
Quoted 82 lines
From: Oleksandr Andrushchenko <[email protected]>
Current vchan implementation, while dealing with XenStore paths, allocates 64 bytes buffer on the stack which may not be enough for some use-cases. Make the buffer longer to respect maximum allowed XenStore path of
XENSTORE_ABS_PATH_MAX.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/libs/vchan/init.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)tools/libs/vchan/init.c +18
-4@@ -249,7 +249,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseint ret =-1 ;struct xs_handle *xs;struct xs_permissions perms[2 ]; -char buf[64 ]; +char *buf;char ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ;@@ -257,6 +257,12 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base// store the base path so we can clean up on server closure ctrl->xs_path =strdup (xs_base); + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } + xs =xs_open (0 );if (!xs) goto fail;@@ -278,14 +284,14 @@ retry_transaction: goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 ))@@ -301,6 +307,7 @@ retry_transaction:free (domid_str);xs_close (xs); fail: +free (buf);return ret; }@@ -418,13 +425,20 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, {struct libxenvchan *ctrl =malloc (sizeof (struct libxenvchan ));struct xs_handle *xs =NULL ; -char buf[64 ]; +char *buf;char *ref;int ring_ref;unsigned int len;if (!ctrl)return 0 ; + + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return 0 ; + } +Quoted 8 lines
tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 450
Quoted 6 lines
tools/libs/vchan/init.c +0
-0ctrl->ring =NULL ; ctrl->event =NULL ; ctrl->gnttab =NULL ;@@ -435,8 +449,9 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (!xs) goto fail;You are leaking buf in this case.
Quoted 1 line
No. buf released in line 474. ctrl leaks in fail case
"goto fail" will go to line 476, and the call of libxenvchan_close() will free ctrl.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
tools/libs/vchan/init.c +3
-2+// find xenstore entry -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;@@ -444,7 +459,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,free (ref);if (!ring_ref) goto fail; -snprintf (buf,sizeof buf,"%s/event-channel" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
Quoted 8 lines
Quoted 8 lines
tools/libs/vchan/init.c struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, · line 495
Quoted 8 lines
tools/libs/vchan/init.c +1
-0@@ -474,6 +489,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, out:if (xs)xs_close (xs); +free (buf);return ctrl; fail:libxenvchan_close (ctrl);
Juergen
PATCH 3/4 tools/libs/light: Add vchan support to libxl
In reply to [email protected]From: Oleksandr Andrushchenko <[email protected]>
Add possibility to send commands from libxl and execute them on server side. Libxl vchan adds support for JSON messages processing.
The using of libxl vchan is preventing the client from libxl from reading and writing from / to the local sysfs directly.To do this, the libxl vchan was added - instead of working with the read and write functions from / to the sysfs, functionality allows to send requests to the server, then receive and process the response.
--- tools/helpers/Makefile | 4 +- tools/libs/light/Makefile | 7 +- tools/libs/light/libxl_vchan.c | 488 +++++++++++++++++++++++++++++++++ tools/libs/light/libxl_vchan.h | 92 +++++++ tools/xl/Makefile | 3 +- 5 files changed, 588 insertions(+), 6 deletions(-) create mode 100644 tools/libs/light/libxl_vchan.c create mode 100644 tools/libs/light/libxl_vchan.h
tools/helpers/Makefile +2 -2
@@ -30,10 +30,10 @@ $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h all: $(PROGS) xen-init-dom0: $(XEN_INIT_DOM0_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS) init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS) - $(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenlight) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS) .PHONY: install install: all
tools/libs/light/Makefile +4 -3
@@ -77,6 +77,7 @@ SRCS-y += libxl.c SRCS-y += libxl_create.c SRCS-y += libxl_dm.c SRCS-y += libxl_pci.c +SRCS-y += libxl_vchan.c SRCS-y += libxl_dom.c SRCS-y += libxl_exec.c SRCS-y += libxl_xshelp.c
@@ -175,7 +176,7 @@ LDUSELIBS-y += $(PTHREAD_LIBS) LDUSELIBS-y += -lyajl LDUSELIBS += $(LDUSELIBS-y) -$(LIB_OBJS) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h +$(LIB_OBJS) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) $(CFLAGS_libxenevtchn) -include $(XEN_ROOT)/tools/config.h $(ACPI_OBJS) $(ACPI_PIC_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\" $(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore) libxl_dom.o libxl_dom.opic: CFLAGS += -I$(XEN_ROOT)/tools # include libacpi/x86.h
@@ -231,13 +232,13 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDUSELIBS) $(APPEND_LDFLAGS) test_%: test_%.o test_common.o libxenlight_test.so - $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS) libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) testidl: testidl.o libxenlight.so - $(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS) install: installlocal $(LIBHEADERS)
tools/libs/light/libxl_vchan.c new file +488 -0
488 lines not on this page · raw message
tools/libs/light/libxl_vchan.h new file +92 -0
92 lines not on this page · raw message
tools/xl/Makefile +2 -1
@@ -15,6 +15,7 @@ LDFLAGS += $(PTHREAD_LDFLAGS) CFLAGS_XL += $(CFLAGS_libxenlight) CFLAGS_XL += $(CFLAGS_libxenutil) CFLAGS_XL += -Wshadow +CFLAGS_XL += $(CFLAGS_libxenvchan) XL_OBJS-$(CONFIG_X86) = xl_psr.o XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y)
@@ -33,7 +34,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i all: xl xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS) .PHONY: install install: all
Signature · 1 line
2.25.1
PATCH 4/4 tools/xl: Add pcid daemon to xl
In reply to [email protected]From: Oleksandr Andrushchenko <[email protected]>
Add pcid daemon (based on vchan-node2) implements pcid protocol. Protocol is OS independed and should work on ane supported OS.
Add essential functionality to handle pcid protocol:
- define required constants
- prepare for handling remote requests
- prepare and send an error packet
pcid server used if domain has passthrough PCI controller and we wants assign some device to other domain.
pcid server should be launched in domain owns the PCI controller and process request from other domains.
Message exchange imnplementation based on JSON via libvchan. Supported messages:
- make_assignable
- revert_assignable
- is_device_assigned
- resource_list
- reset_device
- write_bdf
--- docs/man/xl-pci-configuration.5.pod | 14 + tools/configure | 8 +- tools/configure.ac | 1 + tools/hotplug/FreeBSD/rc.d/xlpcid.in | 75 ++ tools/hotplug/Linux/init.d/xlpcid.in | 76 ++ tools/hotplug/Linux/systemd/Makefile | 1 + .../hotplug/Linux/systemd/xenpcid.service.in | 10 + tools/hotplug/NetBSD/rc.d/xlpcid.in | 75 ++ tools/include/libxl.h | 2 +- tools/include/pcid.h | 228 ++++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_pci.c | 701 +++++------ tools/libs/light/libxl_pcid.c | 1095 +++++++++++++++++ tools/libs/light/libxl_types.idl | 2 + tools/libs/light/libxl_vchan.c | 64 +- tools/libs/light/libxl_vchan.h | 7 +- tools/libs/util/libxlu_pci.c | 6 +- tools/xl/Makefile | 4 +- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 7 + tools/xl/xl_parse.c | 1 + tools/xl/xl_pci.c | 4 +- tools/xl/xl_pcid.c | 81 ++ 23 files changed, 2070 insertions(+), 394 deletions(-) create mode 100644 tools/hotplug/FreeBSD/rc.d/xlpcid.in create mode 100644 tools/hotplug/Linux/init.d/xlpcid.in create mode 100644 tools/hotplug/Linux/systemd/xenpcid.service.in create mode 100644 tools/hotplug/NetBSD/rc.d/xlpcid.in create mode 100644 tools/include/pcid.h create mode 100644 tools/libs/light/libxl_pcid.c create mode 100644 tools/xl/xl_pcid.c
docs/man/xl-pci-configuration.5.pod +14 -0
@@ -215,4 +215,18 @@ required to look up the B<BDF> in the list of assignable devices. =back +=item B<domain>=I<STRING> + +=over 4 + +=item Description + +This is domain name with pcid daemon running + +=item Default Value + +None. Domain name with pcid daemon selects automatically + +=back + =back
tools/configure +6 -2
@@ -2452,7 +2452,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/FreeBSD/rc.d/xendriverdomain hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/sysconfig.xendomains hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/init.d/xendriverdomain hotplug/Linux/launch-xenstore hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons hotplug/NetBSD/rc.d/xendriverdomain ocaml/xenstored/oxenstored.conf" +ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/FreeBSD/rc.d/xendriverdomain hotplug/FreeBSD/rc.d/xlpcid hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/sysconfig.xendomains hotplug/Linux/init.d/xlpcid hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/init.d/xendriverdomain hotplug/Linux/launch-xenstore hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons hotplug/NetBSD/rc.d/xendriverdomain hotplug/NetBSD/rc.d/xlpcid ocaml/xenstored/oxenstored.conf" ac_config_headers="$ac_config_headers config.h"
@@ -10053,7 +10053,7 @@ fi if test "x$systemd" = "xy"; then : - ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service" + ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service hotplug/Linux/systemd/xenpcid.service" fi
@@ -10917,8 +10917,10 @@ do "../config/Tools.mk") CONFIG_FILES="$CONFIG_FILES ../config/Tools.mk" ;; "hotplug/FreeBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xencommons" ;; "hotplug/FreeBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xendriverdomain" ;; + "hotplug/FreeBSD/rc.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xlpcid" ;; "hotplug/Linux/init.d/sysconfig.xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xencommons" ;; "hotplug/Linux/init.d/sysconfig.xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xendomains" ;; + "hotplug/Linux/init.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xlpcid" ;; "hotplug/Linux/init.d/xen-watchdog") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xen-watchdog" ;; "hotplug/Linux/init.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xencommons" ;; "hotplug/Linux/init.d/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xendomains" ;;
@@ -10929,6 +10931,7 @@ do "hotplug/Linux/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/xendomains" ;; "hotplug/NetBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xencommons" ;; "hotplug/NetBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xendriverdomain" ;; + "hotplug/NetBSD/rc.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xlpcid" ;; "ocaml/xenstored/oxenstored.conf") CONFIG_FILES="$CONFIG_FILES ocaml/xenstored/oxenstored.conf" ;; "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "hotplug/Linux/systemd/proc-xen.mount") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/proc-xen.mount" ;;
@@ -10940,6 +10943,7 @@ do "hotplug/Linux/systemd/xendomains.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendomains.service" ;; "hotplug/Linux/systemd/xendriverdomain.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendriverdomain.service" ;; "hotplug/Linux/systemd/xenstored.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenstored.service" ;; + "hotplug/Linux/systemd/xenpcid.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenpcid.service" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac
tools/configure.ac +1 -0
@@ -477,6 +477,7 @@ AS_IF([test "x$systemd" = "xy"], [ hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service + hotplug/Linux/systemd/xenpcid.service ]) ])
tools/hotplug/FreeBSD/rc.d/xlpcid.in new file +75 -0
75 lines not on this page · raw message
tools/hotplug/Linux/init.d/xlpcid.in new file +76 -0
76 lines not on this page · raw message
tools/hotplug/Linux/systemd/Makefile +1 -0
@@ -13,6 +13,7 @@ XEN_SYSTEMD_SERVICE += xendomains.service XEN_SYSTEMD_SERVICE += xen-watchdog.service XEN_SYSTEMD_SERVICE += xen-init-dom0.service XEN_SYSTEMD_SERVICE += xendriverdomain.service +XEN_SYSTEMD_SERVICE += xenpcid.service ALL_XEN_SYSTEMD = $(XEN_SYSTEMD_MODULES) \ $(XEN_SYSTEMD_MOUNT) \
tools/hotplug/Linux/systemd/xenpcid.service.in new file +10 -0
@@ -0,0 +1,10 @@ +[Unit] +Description=Xen PCI host daemon +ConditionVirtualization=xen + +[Service] +Type=forking +ExecStart=@sbindir@/xl pcid + +[Install] +WantedBy=multi-user.target
tools/hotplug/NetBSD/rc.d/xlpcid.in new file +75 -0
75 lines not on this page · raw message
tools/include/libxl.h +1 -1
@@ -2465,7 +2465,7 @@ int libxl_device_events_handler(libxl_ctx *ctx,*/ int libxl_device_pci_assignable_add (libxl_ctx *ctx,libxl_device_pci *pci,int rebind);int libxl_device_pci_assignable_remove (libxl_ctx *ctx,libxl_device_pci *pci,int rebind); -libxl_device_pci *libxl_device_pci_assignable_list (libxl_ctx *ctx,int *num); +libxl_device_pci *libxl_device_pci_assignable_list (libxl_ctx *ctx,int *num,libxl_domid backend_domid);void libxl_device_pci_assignable_list_free (libxl_device_pci *list,int num);/* CPUID handling */
tools/include/pcid.h new file +228 -0
228 lines not on this page · raw message
tools/libs/light/Makefile +1 -0
@@ -77,6 +77,7 @@ SRCS-y += libxl.c SRCS-y += libxl_create.c SRCS-y += libxl_dm.c SRCS-y += libxl_pci.c +SRCS-y += libxl_pcid.c SRCS-y += libxl_vchan.c SRCS-y += libxl_dom.c SRCS-y += libxl_exec.c
tools/libs/light/libxl_pci.c +341 -360
910 lines not on this page · raw message
tools/libs/light/libxl_pcid.c new file +1095 -0
1,095 lines not on this page · raw message
tools/libs/light/libxl_types.idl +2 -0
@@ -802,6 +802,8 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ("rdm_policy", libxl_rdm_reserve_policy), ("name", string), + ("backend", string), + ("backend_domid", libxl_domid), ]) libxl_device_rdm = Struct("device_rdm", [
tools/libs/light/libxl_vchan.c +39 -25
106 lines not on this page · raw message
tools/libs/light/libxl_vchan.h +5 -2
@@ -45,6 +45,7 @@ struct vchan_info {/* Buffer info. */ size_t receive_buf_size;size_t max_buf_size; +bool initialized; }; int libxl__vchan_field_add_string(libxl__gc *gc, yajl_gen hand,
@@ -58,7 +59,9 @@ static inline libxl__json_object *libxl__vchan_start_args(libxl__gc *gc)void libxl__vchan_arg_add_string (libxl__gc *gc,libxl__json_object *args,char *key,char *val);void libxl__vchan_arg_add_bool (libxl__gc *gc,libxl__json_object *args, -char *key,bool val); +char *key,bool val); +void libxl__vchan_arg_add_integer (libxl__gc *gc,libxl__json_object *args, +char *key,int val);libxl__json_object *vchan_send_command (libxl__gc *gc,struct vchan_info *vchan,char *cmd,libxl__json_object *args);
@@ -72,7 +75,7 @@ char *vchan_get_server_xs_path(libxl__gc *gc, libxl_domid domid, char *srv_name)struct vchan_state *vchan_init_new_state (libxl__gc *gc,libxl_domid domid,char *vchan_xs_path,bool is_server); -struct vchan_state *vchan_new_client (libxl__gc *gc,char *srv_name); +struct vchan_state *vchan_new_client (libxl__gc *gc,char *srv_name,libxl_domid domid);void vchan_fini_one (libxl__gc *gc,struct vchan_state *state);
tools/libs/util/libxlu_pci.c +5 -1
@@ -1,6 +1,8 @@#define _GNU_SOURCE#include <ctype.h> +#include <stdint.h> +#include <xen/xen.h> #include "libxlu_internal.h" #include "libxlu_disk_l.h"
@@ -195,8 +197,10 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci, name_present = true; pci->name =strdup (val);if (!pci->name) ret =ERROR_NOMEM ; + }else if (!strcmp (key,"backend" )) { + pci->backend =strdup (val); }else { -XLU__PCI_ERR (cfg,"Unknown PCI_SPEC_STRING option: %s" , key); +XLU__PCI_ERR (cfg,"Unknown PCI_SPEC_STRING option: '%s'\n" , key); ret =ERROR_INVAL ; }
tools/xl/Makefile +2 -2
@@ -22,7 +22,7 @@ XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y) XL_OBJS += xl_parse.o xl_cpupool.o xl_flask.o XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o -XL_OBJS += xl_info.o xl_console.o xl_misc.o +XL_OBJS += xl_info.o xl_console.o xl_misc.o xl_pcid.o XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o
@@ -34,7 +34,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i all: xl xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS) .PHONY: install install: all
tools/xl/xl.h +1 -0
@@ -202,6 +202,7 @@ int main_loadpolicy(int argc, char **argv);int main_remus (int argc,char **argv);#endif int main_devd (int argc,char **argv); +int main_pcid (int argc,char **argv);#if defined(__i386__) || defined(__x86_64__)int main_psr_hwinfo (int argc,char **argv);int main_psr_cmt_attach (int argc,char **argv);
tools/xl/xl_cmdtable.c +7 -0
@@ -545,6 +545,13 @@ const struct cmd_spec cmd_table[] = { "-F Run in the foreground.\n" "-p, --pidfile [FILE] Write PID to pidfile when daemonizing.", }, + { "pcid", + &main_pcid, 0, 1, + "Daemon that acts as a server for the client in the libxl PCI", + "[options]", + "-f Run in the foreground.\n" + "-p, --pidfile [FILE] Write PID to pidfile when daemonizing.", + }, #if defined(__i386__) || defined(__x86_64__) {"psr-hwinfo" , &main_psr_hwinfo, 0, 1,
tools/xl/xl_parse.c +1 -0
@@ -1491,6 +1491,7 @@ void parse_config_data(const char *config_source, pci->power_mgmt = pci_power_mgmt; pci->permissive = pci_permissive; pci->seize = pci_seize; + pci->backend =NULL ;/* * Like other pci option, the per-device policy always follows * the global policy by default.
tools/xl/xl_pci.c +3 -1
@@ -13,7 +13,9 @@*/ #include <stdlib.h> +#include <stdint.h> +#include <xen/xen.h> #include <libxl.h> #include <libxl_utils.h> #include <libxlutil.h>
@@ -156,7 +158,7 @@ static void pciassignable_list(bool show_names)libxl_device_pci *pcis;int num, i; - pcis =libxl_device_pci_assignable_list (ctx, &num); + pcis =libxl_device_pci_assignable_list (ctx, &num,DOMID_INVALID );if ( pcis ==NULL )return ;
tools/xl/xl_pcid.c new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 46 lines · On 09.07.22 12:10, [email protected] wrote:
From: Oleksandr Andrushchenko <[email protected]>
vchan server creates XenStore entries to advertise its event channel and ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try to connect to a non-existing server.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/include/libxenvchan.h | 5 +++++ tools/libs/vchan/init.c | 23 +++++++++++++++++++++++ tools/libs/vchan/io.c | 4 ++++ tools/libs/vchan/vchan.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+)create mode 100644
tools/libs/vchan/vchan.htools/include/libxenvchan.h +5
-0@@ -86,6 +86,11 @@ struct libxenvchan { int blocking:1;/* communication rings */ struct libxenvchan_ring read, write; +/** +* Base xenstore path for storing ring/event data used by the server +* during cleanup. +* */ +char *xs_path; };/** tools/libs/vchan/init.c +2
-0@@ -46,6 +46,8 @@#include <xen/sys/gntdev.h> #include <libxenvchan.h> +#include "vchan.h" +#ifndef PAGE_SHIFT #define PAGE_SHIFT 12#endif
tools/libs/vchan/init.c static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base · line 257
Quoted 5 lines
tools/libs/vchan/init.c +2
-0@@ -251,6 +253,10 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_basechar ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ; + +// store the base path so we can clean up on server closure
Please don't introduce new usages of the C++ comment style.
tools/libs/vchan/init.c static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base · line 258
Quoted 1 line
tools/libs/vchan/init.c +1
-0+ ctrl->xs_path =strdup (xs_base);
Return an error in case of strdup() failure?
Quoted 10 lines
tools/libs/vchan/init.c +3
-0+ xs =xs_open (0 );if (!xs) goto fail;@@ -298,6 +304,23 @@ retry_transaction:return ret; } +void close_xs_srv (struct libxenvchan *ctrl) +{
tools/libs/vchan/init.c retry_transaction: · line 318
Quoted 10 lines
tools/libs/vchan/init.c +10
-0+struct xs_handle *xs; + +if (!ctrl->xs_path) +return ; + + xs =xs_open (0 ); +if (!xs) + goto fail; + +xs_rm (xs,XBT_NULL , ctrl->xs_path);
In this simple case I'd prefer
if (xs)
xs_rm(xs, XBT_NULL, ctrl->xs_path);
tools/libs/vchan/init.c retry_transaction: · line 321
Quoted 3 lines
tools/libs/vchan/init.c +3
-0+ +fail: +free (ctrl->xs_path);
No xs_close()?
Juergen
пн, 11 июл. 2022 г. в 10:09, Juergen Gross <[email protected]>:
Quoted 42 lines · On 09.07.22 12:10, [email protected] wrote:
Quoted 40 lines
From: Oleksandr Andrushchenko <[email protected]>
vchan server creates XenStore entries to advertise its event channel and ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try to connect to a non-existing server.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/include/libxenvchan.h | 5 +++++ tools/libs/vchan/init.c | 23 +++++++++++++++++++++++ tools/libs/vchan/io.c | 4 ++++ tools/libs/vchan/vchan.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+)create mode 100644
tools/libs/vchan/vchan.htools/include/libxenvchan.h +5
-0@@ -86,6 +86,11 @@ struct libxenvchan { int blocking:1;/* communication rings */ struct libxenvchan_ring read, write; +/** +* Base xenstore path for storing ring/event data used by the server +* during cleanup. +* */ +char *xs_path; };/** tools/libs/vchan/init.c +0
-0@@ -46,6 +46,8 @@#include <xen/sys/gntdev.h> #include <libxenvchan.h>
Quoted 13 lines
tools/libs/vchan/init.c static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base · line 257
Quoted 11 lines
tools/libs/vchan/init.c +4
-0+#include "vchan.h" +#ifndef PAGE_SHIFT #define PAGE_SHIFT 12#endif @@ -251,6 +253,10 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_basechar ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ; + +// store the base path so we can clean up on server closure Please don't introduce new usages of the C++ comment style.
Most comments in this file are C++ style since libvchan introduced
Quoted 39 lines
tools/libs/vchan/init.c static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base · line 258
Quoted 2 lines
tools/libs/vchan/init.c +1
-0+ ctrl->xs_path =strdup (xs_base);Return an error in case of
strdup()failure?Quoted 10 lines
tools/libs/vchan/init.c +3
-0+ xs =xs_open (0 );if (!xs) goto fail;@@ -298,6 +304,23 @@ retry_transaction:return ret; } +void close_xs_srv (struct libxenvchan *ctrl) +{tools/libs/vchan/init.c retry_transaction: · line 318
Quoted 10 lines
tools/libs/vchan/init.c +10
-0+struct xs_handle *xs; + +if (!ctrl->xs_path) +return ; + + xs =xs_open (0 ); +if (!xs) + goto fail; + +xs_rm (xs,XBT_NULL , ctrl->xs_path);In this simple case I'd prefer
if (xs)
xs_rm(xs, XBT_NULL, ctrl->xs_path);tools/libs/vchan/init.c retry_transaction: · line 321
Quoted 3 lines
tools/libs/vchan/init.c +3
-0+ +fail: +free (ctrl->xs_path);No
xs_close()?Juergen
Quoted 56 lines · Dmytro Semenets
пн, 11 июл. 2022 г. в 10:09, Juergen Gross <[email protected]>:
Quoted 42 lines · On 09.07.22 12:10, [email protected] wrote:
Quoted 40 lines
From: Oleksandr Andrushchenko <[email protected]>
vchan server creates XenStore entries to advertise its event channel and ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try to connect to a non-existing server.Signed-off-by Oleksandr Andrushchenko <[email protected]>--- tools/include/libxenvchan.h | 5 +++++ tools/libs/vchan/init.c | 23 +++++++++++++++++++++++ tools/libs/vchan/io.c | 4 ++++ tools/libs/vchan/vchan.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+)create mode 100644
tools/libs/vchan/vchan.htools/include/libxenvchan.h +5
-0@@ -86,6 +86,11 @@ struct libxenvchan { int blocking:1;/* communication rings */ struct libxenvchan_ring read, write; +/** +* Base xenstore path for storing ring/event data used by the server +* during cleanup. +* */ +char *xs_path; };/** tools/libs/vchan/init.c +0
-0@@ -46,6 +46,8 @@#include <xen/sys/gntdev.h> #include <libxenvchan.h> Quoted 13 lines
tools/libs/vchan/init.c static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base · line 257
Quoted 11 lines
tools/libs/vchan/init.c +4
-0+#include "vchan.h" +#ifndef PAGE_SHIFT #define PAGE_SHIFT 12#endif @@ -251,6 +253,10 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_basechar ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ; + +// store the base path so we can clean up on server closure Please don't introduce new usages of the C++ comment style.
Quoted 1 line
Most comments in this file are C++ style since libvchan introduced
I know. Nevertheless introducing new coding style violations should be avoided, especially as io.c is using /* ... */ already.
Juergen