From nobody Wed May 14 20:50:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158392518133.25675649418963; Thu, 24 May 2018 03:39:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBC5F914F7; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 847381057FA4; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1DF3618033EE; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdOaA011660 for ; Thu, 24 May 2018 06:39:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9479E1049466; Thu, 24 May 2018 10:39:24 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A53F1049465 for ; Thu, 24 May 2018 10:39:24 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:14 +0200 Message-Id: <8766ea39c30484f26136d4e0ab66294fd48870b8.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 6/7] util: create virvsock.c X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 May 2018 10:39:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 A file for vsock-related helper functions. virVsockSetGuestCid to set an already-known CID, virVsockAcquireGuestCid that will use the first available CID https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- configure.ac | 8 +++++ src/libvirt_private.syms | 5 +++ src/util/Makefile.inc.am | 2 ++ src/util/virvsock.c | 89 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virvsock.h | 29 ++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 src/util/virvsock.c create mode 100644 src/util/virvsock.h diff --git a/configure.ac b/configure.ac index cc005ea9e8..b869a17afe 100644 --- a/configure.ac +++ b/configure.ac @@ -641,6 +641,14 @@ if test "$with_linux" =3D "yes"; then [[#include ]]) fi =20 +dnl +dnl check for VHOST_VSOCK_SET_GUEST_CID +dnl +if test "$with_linux" =3D "yes"; then + AC_CHECK_DECLS([VHOST_VSOCK_SET_GUEST_CID], [], [], + [[#include ]]) +fi + dnl Allow perl/python overrides AC_PATH_PROGS([PYTHON], [python3 python2 python]) if test -z "$PYTHON"; then diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8e33f3e9f6..0f8045454b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3121,6 +3121,11 @@ virVHBAManageVport; virVHBAPathExists; =20 =20 +# util/virvsock.h +virVsockAcquireGuestCid; +virVsockSetGuestCid; + + # util/virxml.h virXMLCheckIllegalChars; virXMLChildElementCount; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index ec8745da7e..a22265606c 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -204,6 +204,8 @@ UTIL_SOURCES =3D \ util/viruuid.h \ util/virvhba.c \ util/virvhba.h \ + util/virvsock.c \ + util/virvsock.h \ util/virxdrdefs.h \ util/virxml.c \ util/virxml.h \ diff --git a/src/util/virvsock.c b/src/util/virvsock.c new file mode 100644 index 0000000000..8a5c88700b --- /dev/null +++ b/src/util/virvsock.c @@ -0,0 +1,89 @@ +/* + * 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 + * . + * + */ + +#include + +#include +/* #include */ + +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +# include +#endif + +#include "virvsock.h" + +#include "virerror.h" +#include "virlog.h" + + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("util.vsock"); + +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +static int +virVsockSetGuestCidQuiet(int fd, + unsigned int guest_cid) +{ + uint64_t val =3D guest_cid; + + return ioctl(fd, VHOST_VSOCK_SET_GUEST_CID, &val); +} + +#else +static int +virVsockSetGuestCidQuiet(int fd ATTRIBUTE_UNUSED, + unsigned int guest_cid ATTRIBUTE_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} +#endif + + +int +virVsockSetGuestCid(int fd, + unsigned int guest_cid) +{ + if (virVsockSetGuestCidQuiet(fd, guest_cid) < 0) { + virReportSystemError(errno, "%s", + _("failed to set guest cid")); + return -1; + } + + return 0; +} + +#define VIR_VSOCK_GUEST_CID_MIN 3 + +int +virVsockAcquireGuestCid(int fd, + unsigned int *guest_cid) +{ + unsigned int cid =3D VIR_VSOCK_GUEST_CID_MIN; + + for (; virVsockSetGuestCidQuiet(fd, cid) < 0; cid++) { + if (errno !=3D EADDRINUSE) { + virReportSystemError(errno, "%s", + _("failed to acquire guest cid")); + return -1; + } + } + *guest_cid =3D cid; + + return 0; +} diff --git a/src/util/virvsock.h b/src/util/virvsock.h new file mode 100644 index 0000000000..080a322420 --- /dev/null +++ b/src/util/virvsock.h @@ -0,0 +1,29 @@ +/* + * virvsock.h - vsock related util functions + * + * 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 + * . + */ + +#ifndef __VIR_VSOCK_H__ +# define __VIR_VSOCK_H__ + +int +virVsockSetGuestCid(int fd, + unsigned int guest_cid); + +int +virVsockAcquireGuestCid(int fd, + unsigned int *guest_cid); +#endif /* __VIR_VSOCK_H__ */ --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list