From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 163848583629693.14048258546325; Thu, 2 Dec 2021 14:57:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-VOC9ox2NNQKzgJgOfatXOQ-1; Thu, 02 Dec 2021 17:57:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7F18192CC47; Thu, 2 Dec 2021 22:57:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C962F17D61; Thu, 2 Dec 2021 22:57:06 +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 99A784A70D; Thu, 2 Dec 2021 22:57:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuRjb015575 for ; Thu, 2 Dec 2021 17:56:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1AD84C0808C; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16180C08089 for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E94C5185A7B2 for ; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-38-KlghzshBONicH1nJo-9V-Q-1; Thu, 02 Dec 2021 17:56:24 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 1EC6D20E67AA; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: VOC9ox2NNQKzgJgOfatXOQ-1 X-MC-Unique: KlghzshBONicH1nJo-9V-Q-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1EC6D20E67AA From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/17] util: fix indentation in virprocess.c Date: Thu, 2 Dec 2021 22:55:58 +0000 Message-Id: <20211202225614.1118066-2-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuRjb015575 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485836920100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/util/virprocess.c | 501 +++++++++++++++++++++--------------------- 1 file changed, 249 insertions(+), 252 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 7b0ad9c97b..8288e71f67 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -25,36 +25,36 @@ #include #include #ifndef WIN32 -# include +#include #endif #include #if WITH_SYS_MOUNT_H -# include +#include #endif #if WITH_SETRLIMIT -# include -# include +#include +#include #endif #if WITH_SCHED_H -# include +#include #endif =20 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || WITH_BSD_CPU_AF= FINITY -# include +#include #endif =20 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -# include -# include +#include +#include #endif =20 #if WITH_BSD_CPU_AFFINITY -# include +#include #endif =20 #ifdef WIN32 -# define WIN32_LEAN_AND_MEAN -# include +#define WIN32_LEAN_AND_MEAN +#include #endif =20 #include "virprocess.h" @@ -71,41 +71,44 @@ VIR_LOG_INIT("util.process"); =20 #ifdef __linux__ + /* * Workaround older glibc. While kernel may support the setns * syscall, the glibc wrapper might not exist. If that's the * case, use our own. */ -# ifndef __NR_setns -# if defined(__x86_64__) -# define __NR_setns 308 -# elif defined(__i386__) -# define __NR_setns 346 -# elif defined(__arm__) -# define __NR_setns 375 -# elif defined(__aarch64__) -# define __NR_setns 375 -# elif defined(__powerpc__) -# define __NR_setns 350 -# elif defined(__s390__) -# define __NR_setns 339 -# endif -# endif - -# ifndef WITH_SETNS -# if defined(__NR_setns) -# include - -static inline int setns(int fd, int nstype) +#ifndef __NR_setns +#if defined(__x86_64__) +#define __NR_setns 308 +#elif defined(__i386__) +#define __NR_setns 346 +#elif defined(__arm__) +#define __NR_setns 375 +#elif defined(__aarch64__) +#define __NR_setns 375 +#elif defined(__powerpc__) +#define __NR_setns 350 +#elif defined(__s390__) +#define __NR_setns 339 +#endif +#endif + +#ifndef WITH_SETNS +#if defined(__NR_setns) +#include + +static inline int +setns(int fd, int nstype) { return syscall(__NR_setns, fd, nstype); } -# else /* !__NR_setns */ -# error Please determine the syscall number for setns on your architectu= re -# endif -# endif +#else /* !__NR_setns */ +#error Please determine the syscall number for setns on your architecture +#endif +#endif #else /* !__linux__ */ -static inline int setns(int fd G_GNUC_UNUSED, int nstype G_GNUC_UNUSED) +static inline int +setns(int fd G_GNUC_UNUSED, int nstype G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Namespaces are not supported on this platform.= ")); @@ -115,15 +118,11 @@ static inline int setns(int fd G_GNUC_UNUSED, int nst= ype G_GNUC_UNUSED) =20 VIR_ENUM_IMPL(virProcessSchedPolicy, VIR_PROC_POLICY_LAST, - "none", - "batch", - "idle", - "fifo", - "rr", -); + "none", "batch", "idle", "fifo", "rr",); =20 =20 #ifndef WIN32 + /** * virProcessTranslateStatus: * @status: child exit status to translate @@ -136,12 +135,11 @@ char * virProcessTranslateStatus(int status) { char *buf; + if (WIFEXITED(status)) { - buf =3D g_strdup_printf(_("exit status %d"), - WEXITSTATUS(status)); + buf =3D g_strdup_printf(_("exit status %d"), WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - buf =3D g_strdup_printf(_("fatal signal %d"), - WTERMSIG(status)); + buf =3D g_strdup_printf(_("fatal signal %d"), WTERMSIG(status)); } else { buf =3D g_strdup_printf(_("invalid value %d"), status); } @@ -175,8 +173,7 @@ virProcessAbort(pid_t pid) */ saved_errno =3D errno; VIR_DEBUG("aborting child process %d", pid); - while ((ret =3D waitpid(pid, &status, WNOHANG)) =3D=3D -1 && - errno =3D=3D EINTR); + while ((ret =3D waitpid(pid, &status, WNOHANG)) =3D=3D -1 && errno =3D= =3D EINTR); if (ret =3D=3D pid) { tmp =3D virProcessTranslateStatus(status); VIR_DEBUG("process has ended: %s", tmp); @@ -185,8 +182,7 @@ virProcessAbort(pid_t pid) VIR_DEBUG("trying SIGTERM to child process %d", pid); kill(pid, SIGTERM); g_usleep(10 * 1000); - while ((ret =3D waitpid(pid, &status, WNOHANG)) =3D=3D -1 && - errno =3D=3D EINTR); + while ((ret =3D waitpid(pid, &status, WNOHANG)) =3D=3D -1 && errno= =3D=3D EINTR); if (ret =3D=3D pid) { tmp =3D virProcessTranslateStatus(status); VIR_DEBUG("process has ended: %s", tmp); @@ -194,8 +190,7 @@ virProcessAbort(pid_t pid) } else if (ret =3D=3D 0) { VIR_DEBUG("trying SIGKILL to child process %d", pid); kill(pid, SIGKILL); - while ((ret =3D waitpid(pid, &status, 0)) =3D=3D -1 && - errno =3D=3D EINTR); + while ((ret =3D waitpid(pid, &status, 0)) =3D=3D -1 && errno = =3D=3D EINTR); if (ret =3D=3D pid) { tmp =3D virProcessTranslateStatus(status); VIR_DEBUG("process has ended: %s", tmp); @@ -246,8 +241,7 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) } =20 /* Wait for intermediate process to exit */ - while ((ret =3D waitpid(pid, &status, 0)) =3D=3D -1 && - errno =3D=3D EINTR); + while ((ret =3D waitpid(pid, &status, 0)) =3D=3D -1 && errno =3D=3D EI= NTR); =20 if (ret =3D=3D -1) { virReportSystemError(errno, _("unable to wait for process %lld"), @@ -289,7 +283,7 @@ void virProcessAbort(pid_t pid) { /* Not yet ported to mingw. Any volunteers? */ - VIR_DEBUG("failed to reap child %lld, abandoning it", (long long)pid); + VIR_DEBUG("failed to reap child %lld, abandoning it", (long long) pid); } =20 =20 @@ -305,7 +299,8 @@ virProcessWait(pid_t pid, int *exitstatus G_GNUC_UNUSED= , bool raw G_GNUC_UNUSED) =20 =20 /* send signal to a single process */ -int virProcessKill(pid_t pid, int sig) +int +virProcessKill(pid_t pid, int sig) { if (pid <=3D 1) { errno =3D ESRCH; @@ -315,44 +310,45 @@ int virProcessKill(pid_t pid, int sig) #ifdef WIN32 /* Mingw / Windows don't have many signals (AFAIK) */ switch (sig) { - case SIGINT: - /* This does a Ctrl+C equiv */ - if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) { - errno =3D ESRCH; - return -1; - } - break; + case SIGINT: + /* This does a Ctrl+C equiv */ + if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) { + errno =3D ESRCH; + return -1; + } + break; + + case SIGTERM: + /* Since TerminateProcess is closer to SIG_KILL, we do + * a Ctrl+Break equiv which is more pleasant like the + * good old unix SIGTERM/HUP + */ + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) { + errno =3D ESRCH; + return -1; + } + break; =20 - case SIGTERM: - /* Since TerminateProcess is closer to SIG_KILL, we do - * a Ctrl+Break equiv which is more pleasant like the - * good old unix SIGTERM/HUP - */ - if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) { - errno =3D ESRCH; - return -1; - } - break; - - default: - { - HANDLE proc; - proc =3D OpenProcess(PROCESS_TERMINATE, FALSE, pid); - if (!proc) { - errno =3D ESRCH; /* Not entirely accurate, but close enough */ - return -1; - } + default: + { + HANDLE proc; =20 - /* - * TerminateProcess is more or less equiv to SIG_KILL, in that - * a process can't trap / block it - */ - if (sig !=3D 0 && !TerminateProcess(proc, sig)) { - errno =3D ESRCH; - return -1; - } - CloseHandle(proc); - } + proc =3D OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (!proc) { + errno =3D ESRCH; /* Not entirely accurate, but cl= ose enough */ + return -1; + } + + /* + * TerminateProcess is more or less equiv to SIG_KILL, in = that + * a process can't trap / block it + */ + if (sig !=3D 0 && !TerminateProcess(proc, sig)) { + errno =3D ESRCH; + return -1; + } + CloseHandle(proc); + } } return 0; #else @@ -362,7 +358,8 @@ int virProcessKill(pid_t pid, int sig) =20 =20 /* send signal to a process group */ -int virProcessGroupKill(pid_t pid, int sig G_GNUC_UNUSED) +int +virProcessGroupKill(pid_t pid, int sig G_GNUC_UNUSED) { if (pid <=3D 1) { errno =3D ESRCH; @@ -379,7 +376,8 @@ int virProcessGroupKill(pid_t pid, int sig G_GNUC_UNUSE= D) =20 =20 /* get process group from a pid */ -pid_t virProcessGroupGet(pid_t pid) +pid_t +virProcessGroupGet(pid_t pid) { if (pid <=3D 1) { errno =3D ESRCH; @@ -406,15 +404,17 @@ pid_t virProcessGroupGet(pid_t pid) * wait longer than the default. */ int -virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradela= y, bool group) +virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradela= y, + bool group) { size_t i; + /* This is in 1/5th seconds since polling is on a 0.2s interval */ - unsigned int polldelay =3D (force ? 200 : 75) + (extradelay*5); + unsigned int polldelay =3D (force ? 200 : 75) + (extradelay * 5); const char *signame =3D "TERM"; =20 VIR_DEBUG("vpid=3D%lld force=3D%d extradelay=3D%u group=3D%d", - (long long)pid, force, extradelay, group); + (long long) pid, force, extradelay, group); =20 /* This loop sends SIGTERM, then waits a few iterations (10 seconds) * to see if it dies. If the process still hasn't exited, and @@ -432,21 +432,21 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, u= nsigned int extradelay, boo int rc; =20 if (i =3D=3D 0) { - signum =3D SIGTERM; /* kindly suggest it should exit */ + signum =3D SIGTERM; /* kindly suggest it should exit */ } else if (i =3D=3D 50 && force) { VIR_DEBUG("Timed out waiting after SIGTERM to process %lld, " - "sending SIGKILL", (long long)pid); + "sending SIGKILL", (long long) pid); /* No SIGKILL kill on Win32 ! Use SIGABRT instead which our * virProcessKill proc will handle more or less like SIGKILL */ #ifdef WIN32 - signum =3D SIGABRT; /* kill it after a grace period */ + signum =3D SIGABRT; /* kill it after a grace period */ signame =3D "ABRT"; #else - signum =3D SIGKILL; /* kill it after a grace period */ + signum =3D SIGKILL; /* kill it after a grace period */ signame =3D "KILL"; #endif } else { - signum =3D 0; /* Just check for existence */ + signum =3D 0; /* Just check for existence */ } =20 if (group) @@ -457,8 +457,9 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, uns= igned int extradelay, boo if (rc < 0) { if (errno !=3D ESRCH) { virReportSystemError(errno, - _("Failed to terminate process %lld w= ith SIG%s"), - (long long)pid, signame); + _ + ("Failed to terminate process %lld wi= th SIG%s"), + (long long) pid, signame); return -1; } return signum =3D=3D SIGTERM ? 0 : 1; @@ -469,20 +470,22 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, u= nsigned int extradelay, boo =20 virReportSystemError(EBUSY, _("Failed to terminate process %lld with SIG%s"), - (long long)pid, signame); + (long long) pid, signame); =20 return 0; } =20 =20 -int virProcessKillPainfully(pid_t pid, bool force) +int +virProcessKillPainfully(pid_t pid, bool force) { return virProcessKillPainfullyDelay(pid, force, 0, false); } =20 #if WITH_DECL_CPU_SET_T =20 -int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet) +int +virProcessSetAffinity(pid_t pid, virBitmap * map, bool quiet) { size_t i; int numcpus =3D 1024; @@ -490,7 +493,7 @@ int virProcessSetAffinity(pid_t pid, virBitmap *map, bo= ol quiet) cpu_set_t *mask; int rv =3D -1; =20 - VIR_DEBUG("Set process affinity on %lld", (long long)pid); + VIR_DEBUG("Set process affinity on %lld", (long long) pid); =20 /* Not only may the statically allocated cpu_set_t be too small, * but there is no way to ask the kernel what size is large enough. @@ -516,8 +519,7 @@ int virProcessSetAffinity(pid_t pid, virBitmap *map, bo= ol quiet) CPU_FREE(mask); =20 if (rv < 0) { - if (errno =3D=3D EINVAL && - numcpus < (1024 << 8)) { /* 262144 cpus ought to be enough for= anyone */ + if (errno =3D=3D EINVAL && numcpus < (1024 << 8)) { /* 262144 cpus= ought to be enough for anyone */ numcpus =3D numcpus << 2; goto realloc; } @@ -526,7 +528,8 @@ int virProcessSetAffinity(pid_t pid, virBitmap *map, bo= ol quiet) pid, g_strerror(errno)); } else { virReportSystemError(errno, - _("cannot set CPU affinity on process %d"= ), pid); + _("cannot set CPU affinity on process %d"= ), + pid); return -1; } } @@ -574,9 +577,8 @@ virProcessGetAffinity(pid_t pid) =20 #elif defined(WITH_BSD_CPU_AFFINITY) =20 -int virProcessSetAffinity(pid_t pid, - virBitmap *map, - bool quiet) +int +virProcessSetAffinity(pid_t pid, virBitmap * map, bool quiet) { size_t i; cpuset_t mask; @@ -594,7 +596,8 @@ int virProcessSetAffinity(pid_t pid, pid, g_strerror(errno)); } else { virReportSystemError(errno, - _("cannot set CPU affinity on process %d"= ), pid); + _("cannot set CPU affinity on process %d"= ), + pid); return -1; } } @@ -628,14 +631,15 @@ virProcessGetAffinity(pid_t pid) =20 #else /* WITH_DECL_CPU_SET_T */ =20 -int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED, - virBitmap *map G_GNUC_UNUSED, - bool quiet G_GNUC_UNUSED) +int +virProcessSetAffinity(pid_t pid G_GNUC_UNUSED, + virBitmap * map G_GNUC_UNUSED, bool quiet G_GNUC_UNU= SED) { /* The @quiet parameter is ignored here, it is used only for silencing * actual failures. */ virReportSystemError(ENOSYS, "%s", - _("Process CPU affinity is not supported on this = platform")); + _ + ("Process CPU affinity is not supported on this p= latform")); return -1; } =20 @@ -643,15 +647,18 @@ virBitmap * virProcessGetAffinity(pid_t pid G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", - _("Process CPU affinity is not supported on this = platform")); + _ + ("Process CPU affinity is not supported on this p= latform")); return NULL; } #endif /* WITH_DECL_CPU_SET_T */ =20 =20 -int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) +int +virProcessGetPids(pid_t pid, size_t *npids, pid_t ** pids) { int ret =3D -1; + g_autoptr(DIR) dir =3D NULL; int value; struct dirent *ent; @@ -660,7 +667,7 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) *npids =3D 0; *pids =3D NULL; =20 - taskPath =3D g_strdup_printf("/proc/%llu/task", (long long)pid); + taskPath =3D g_strdup_printf("/proc/%llu/task", (long long) pid); =20 if (virDirOpen(&dir, taskPath) < 0) goto cleanup; @@ -688,9 +695,8 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) } =20 =20 -int virProcessGetNamespaces(pid_t pid, - size_t *nfdlist, - int **fdlist) +int +virProcessGetNamespaces(pid_t pid, size_t *nfdlist, int **fdlist) { size_t i =3D 0; const char *ns[] =3D { "user", "ipc", "uts", "net", "pid", "mnt" }; @@ -702,11 +708,11 @@ int virProcessGetNamespaces(pid_t pid, int fd; g_autofree char *nsfile =3D NULL; =20 - nsfile =3D g_strdup_printf("/proc/%llu/ns/%s", (long long)pid, ns[= i]); + nsfile =3D g_strdup_printf("/proc/%llu/ns/%s", (long long) pid, ns= [i]); =20 if ((fd =3D open(nsfile, O_RDONLY)) >=3D 0) { VIR_EXPAND_N(*fdlist, *nfdlist, 1); - (*fdlist)[(*nfdlist)-1] =3D fd; + (*fdlist)[(*nfdlist) - 1] =3D fd; } } =20 @@ -714,8 +720,8 @@ int virProcessGetNamespaces(pid_t pid, } =20 =20 -int virProcessSetNamespaces(size_t nfdlist, - int *fdlist) +int +virProcessSetNamespaces(size_t nfdlist, int *fdlist) { size_t i; =20 @@ -733,8 +739,7 @@ int virProcessSetNamespaces(size_t nfdlist, * type passed to setns()'s second param. Since we * pass 0, we know the EINVAL is harmless */ - if (setns(fdlist[i], 0) < 0 && - errno !=3D EINVAL) { + if (setns(fdlist[i], 0) < 0 && errno !=3D EINVAL) { virReportSystemError(errno, "%s", _("Unable to join domain namespace")); return -1; @@ -747,8 +752,7 @@ int virProcessSetNamespaces(size_t nfdlist, static int virProcessPrLimit(pid_t pid, int resource, - const struct rlimit *new_limit, - struct rlimit *old_limit) + const struct rlimit *new_limit, struct rlimit *old_limit) { return prlimit(pid, resource, new_limit, old_limit); } @@ -766,8 +770,7 @@ virProcessPrLimit(pid_t pid G_GNUC_UNUSED, =20 #if WITH_GETRLIMIT static int -virProcessGetRLimit(int resource, - struct rlimit *old_limit) +virProcessGetRLimit(int resource, struct rlimit *old_limit) { return getrlimit(resource, old_limit); } @@ -775,51 +778,49 @@ virProcessGetRLimit(int resource, =20 #if WITH_SETRLIMIT static int -virProcessSetRLimit(int resource, - const struct rlimit *new_limit) +virProcessSetRLimit(int resource, const struct rlimit *new_limit) { return setrlimit(resource, new_limit); } #endif /* WITH_SETRLIMIT */ =20 #if WITH_GETRLIMIT -static const char* +static const char * virProcessLimitResourceToLabel(int resource) { switch (resource) { -# if defined(RLIMIT_MEMLOCK) +#if defined(RLIMIT_MEMLOCK) case RLIMIT_MEMLOCK: return "Max locked memory"; -# endif /* defined(RLIMIT_MEMLOCK) */ +#endif /* defined(RLIMIT_MEMLOCK) */ =20 -# if defined(RLIMIT_NPROC) +#if defined(RLIMIT_NPROC) case RLIMIT_NPROC: return "Max processes"; -# endif /* defined(RLIMIT_NPROC) */ +#endif /* defined(RLIMIT_NPROC) */ =20 -# if defined(RLIMIT_NOFILE) +#if defined(RLIMIT_NOFILE) case RLIMIT_NOFILE: return "Max open files"; -# endif /* defined(RLIMIT_NOFILE) */ +#endif /* defined(RLIMIT_NOFILE) */ =20 -# if defined(RLIMIT_CORE) +#if defined(RLIMIT_CORE) case RLIMIT_CORE: return "Max core file size"; -# endif /* defined(RLIMIT_CORE) */ +#endif /* defined(RLIMIT_CORE) */ =20 default: return NULL; } } =20 -# if defined(__linux__) +#if defined(__linux__) static int -virProcessGetLimitFromProc(pid_t pid, - int resource, - struct rlimit *limit) +virProcessGetLimitFromProc(pid_t pid, int resource, struct rlimit *limit) { g_autofree char *procfile =3D NULL; g_autofree char *buf =3D NULL; + g_auto(GStrv) lines =3D NULL; const char *label; size_t i; @@ -829,7 +830,7 @@ virProcessGetLimitFromProc(pid_t pid, return -1; } =20 - procfile =3D g_strdup_printf("/proc/%lld/limits", (long long)pid); + procfile =3D g_strdup_printf("/proc/%lld/limits", (long long) pid); =20 if (virFileReadAllQuiet(procfile, 2048, &buf) < 0) { /* virFileReadAllQuiet() already sets errno, so don't overwrite @@ -873,7 +874,7 @@ virProcessGetLimitFromProc(pid_t pid, errno =3D EIO; return -1; } -# else /* !defined(__linux__) */ +#else /* !defined(__linux__) */ static int virProcessGetLimitFromProc(pid_t pid G_GNUC_UNUSED, int resource G_GNUC_UNUSED, @@ -882,12 +883,10 @@ virProcessGetLimitFromProc(pid_t pid G_GNUC_UNUSED, errno =3D ENOSYS; return -1; } -# endif /* !defined(__linux__) */ +#endif /* !defined(__linux__) */ =20 static int -virProcessGetLimit(pid_t pid, - int resource, - struct rlimit *old_limit) +virProcessGetLimit(pid_t pid, int resource, struct rlimit *old_limit) { pid_t current_pid =3D getpid(); bool same_process =3D (pid =3D=3D current_pid); @@ -913,9 +912,7 @@ virProcessGetLimit(pid_t pid, =20 #if WITH_SETRLIMIT static int -virProcessSetLimit(pid_t pid, - int resource, - const struct rlimit *new_limit) +virProcessSetLimit(pid_t pid, int resource, const struct rlimit *new_limit) { pid_t current_pid =3D getpid(); bool same_process =3D (pid =3D=3D current_pid); @@ -931,6 +928,7 @@ virProcessSetLimit(pid_t pid, #endif /* WITH_SETRLIMIT */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_MEMLOCK) + /** * virProcessSetMaxMemLock: * @pid: process to be changed @@ -958,7 +956,7 @@ virProcessSetMaxMemLock(pid_t pid, unsigned long long b= ytes) virReportSystemError(errno, _("cannot limit locked memory " "of process %lld to %llu"), - (long long int)pid, bytes); + (long long int) pid, bytes); } =20 VIR_DEBUG("Locked memory for process %lld limited to %llu bytes", @@ -977,6 +975,7 @@ virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_MEMLOCK)) */ =20 #if WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK) + /** * virProcessGetMaxMemLock: * @pid: process to be queried @@ -987,8 +986,7 @@ virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, * Returns: 0 on success, <0 on failure. */ int -virProcessGetMaxMemLock(pid_t pid, - unsigned long long *bytes) +virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) { struct rlimit rlim; =20 @@ -998,8 +996,7 @@ virProcessGetMaxMemLock(pid_t pid, if (virProcessGetLimit(pid, RLIMIT_MEMLOCK, &rlim) < 0) { virReportSystemError(errno, _("cannot get locked memory limit " - "of process %lld"), - (long long int) pid); + "of process %lld"), (long long int) pid); return -1; } =20 @@ -1026,6 +1023,7 @@ virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, #endif /* ! (WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_NPROC) + /** * virProcessSetMaxProcesses: * @pid: process to be changed @@ -1045,9 +1043,9 @@ virProcessSetMaxProcesses(pid_t pid, unsigned int pro= cs) =20 if (virProcessSetLimit(pid, RLIMIT_NPROC, &rlim) < 0) { virReportSystemError(errno, - _("cannot limit number of subprocesses " - "of process %lld to %u"), - (long long int)pid, procs); + _("cannot limit number of subprocesses " + "of process %lld to %u"), + (long long int) pid, procs); return -1; } return 0; @@ -1063,6 +1061,7 @@ virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_NPROC)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_NOFILE) + /** * virProcessSetMaxFiles: * @pid: process to be changed @@ -1077,21 +1076,21 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) { struct rlimit rlim; =20 - /* Max number of opened files is one greater than actual limit. See - * man setrlimit. - * - * NB: That indicates to me that we would want the following code - * to say "files - 1", but the original of this code in - * qemu_process.c also had files + 1, so this preserves current - * behavior. - */ + /* Max number of opened files is one greater than actual limit. See + * man setrlimit. + * + * NB: That indicates to me that we would want the following code + * to say "files - 1", but the original of this code in + * qemu_process.c also had files + 1, so this preserves current + * behavior. + */ rlim.rlim_cur =3D rlim.rlim_max =3D files + 1; =20 if (virProcessSetLimit(pid, RLIMIT_NOFILE, &rlim) < 0) { virReportSystemError(errno, _("cannot limit number of open files " "of process %lld to %u"), - (long long int)pid, files); + (long long int) pid, files); return -1; } =20 @@ -1099,8 +1098,7 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) } #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ int -virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, - unsigned int files G_GNUC_UNUSED) +virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, unsigned int files G_GNUC_U= NUSED) { virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; @@ -1108,6 +1106,7 @@ virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_CORE) + /** * virProcessSetMaxCoreSize: * @pid: process to be changed @@ -1126,9 +1125,9 @@ virProcessSetMaxCoreSize(pid_t pid, unsigned long lon= g bytes) =20 if (virProcessSetLimit(pid, RLIMIT_CORE, &rlim) < 0) { virReportSystemError(errno, - _("cannot limit core file size " - "of process %lld to %llu"), - (long long int)pid, bytes); + _("cannot limit core file size " + "of process %lld to %llu"), + (long long int) pid, bytes); return -1; } =20 @@ -1146,19 +1145,20 @@ virProcessSetMaxCoreSize(pid_t pid G_GNUC_UNUSED, =20 =20 #ifdef __linux__ + /* * Port of code from polkitunixprocess.c under terms * of the LGPLv2+ */ -int virProcessGetStartTime(pid_t pid, - unsigned long long *timestamp) +int +virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { g_auto(GStrv) proc_stat =3D virProcessGetStat(pid, 0); const char *starttime_str =3D NULL; =20 if (!proc_stat || g_strv_length(proc_stat) < 22) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find start time for pid %d"), (int)pid); + _("Cannot find start time for pid %d"), (int) pid); return -1; } =20 @@ -1166,14 +1166,14 @@ int virProcessGetStartTime(pid_t pid, if (virStrToLong_ull(starttime_str, NULL, 10, timestamp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse start time %s for pid %d"), - starttime_str, (int)pid); + starttime_str, (int) pid); return -1; } return 0; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -int virProcessGetStartTime(pid_t pid, - unsigned long long *timestamp) +int +virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { struct kinfo_proc p; int mib[4]; @@ -1190,19 +1190,21 @@ int virProcessGetStartTime(pid_t pid, return -1; } =20 - *timestamp =3D (unsigned long long)p.ki_start.tv_sec; + *timestamp =3D (unsigned long long) p.ki_start.tv_sec; =20 return 0; =20 } #else -int virProcessGetStartTime(pid_t pid, - unsigned long long *timestamp) +int +virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { static int warned; + if (g_atomic_int_add(&warned, 1) =3D=3D 0) { - VIR_WARN("Process start time of pid %lld not available on this pla= tform", - (long long) pid); + VIR_WARN + ("Process start time of pid %lld not available on this platfor= m", + (long long) pid); } *timestamp =3D 0; return 0; @@ -1218,15 +1220,15 @@ struct _virProcessNamespaceHelperData { void *opaque; }; =20 -static int virProcessNamespaceHelper(pid_t pid G_GNUC_UNUSED, - void *opaque) +static int +virProcessNamespaceHelper(pid_t pid G_GNUC_UNUSED, void *opaque) { virProcessNamespaceHelperData *data =3D opaque; int fd =3D -1; int ret =3D -1; g_autofree char *path =3D NULL; =20 - path =3D g_strdup_printf("/proc/%lld/ns/mnt", (long long)data->pid); + path =3D g_strdup_printf("/proc/%lld/ns/mnt", (long long) data->pid); =20 if ((fd =3D open(path, O_RDONLY)) < 0) { virReportSystemError(errno, "%s", @@ -1235,8 +1237,7 @@ static int virProcessNamespaceHelper(pid_t pid G_GNUC= _UNUSED, } =20 if (setns(fd, 0) < 0) { - virReportSystemError(errno, "%s", - _("Unable to enter mount namespace")); + virReportSystemError(errno, "%s", _("Unable to enter mount namespa= ce")); goto cleanup; } =20 @@ -1255,10 +1256,10 @@ static int virProcessNamespaceHelper(pid_t pid G_GN= UC_UNUSED, */ int virProcessRunInMountNamespace(pid_t pid, - virProcessNamespaceCallback cb, - void *opaque) + virProcessNamespaceCallback cb, void *opaque) { - virProcessNamespaceHelperData data =3D {.pid =3D pid, .cb =3D cb, .opa= que =3D opaque}; + virProcessNamespaceHelperData data =3D {.pid =3D pid, .cb =3D cb, + .opaque =3D opaque}; =20 return virProcessRunInFork(virProcessNamespaceHelper, &data); } @@ -1279,8 +1280,9 @@ virProcessRunInMountNamespace(pid_t pid G_GNUC_UNUSED, =20 =20 #ifndef WIN32 + /* We assume that error messages will fit into 1024 chars */ -# define VIR_PROCESS_ERROR_MAX_LENGTH 1024 +#define VIR_PROCESS_ERROR_MAX_LENGTH 1024 typedef struct { int code; int domain; @@ -1296,13 +1298,12 @@ typedef struct { typedef union { errorData data; char bindata[sizeof(errorData)]; -} errorDataBin; +} +errorDataBin; =20 static int virProcessRunInForkHelper(int errfd, - pid_t ppid, - virProcessForkCallback cb, - void *opaque) + pid_t ppid, virProcessForkCallback cb, void *opa= que) { int ret =3D 0; =20 @@ -1355,8 +1356,7 @@ virProcessRunInForkHelper(int errfd, * Otherwise the returned value is the retval of the callback. */ int -virProcessRunInFork(virProcessForkCallback cb, - void *opaque) +virProcessRunInFork(virProcessForkCallback cb, void *opaque) { int ret =3D -1; pid_t child =3D -1; @@ -1402,8 +1402,7 @@ virProcessRunInFork(virProcessForkCallback cb, bin->data.str2, bin->data.str3, bin->data.int1, - bin->data.int2, - "%s", bin->data.message); + bin->data.int2, "%s", bin->data.mess= age); } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("child didn't write error (status=3D%= d)"), @@ -1426,7 +1425,8 @@ virProcessRunInFork(virProcessForkCallback cb G_GNUC_= UNUSED, void *opaque G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", - _("Process spawning is not supported on this plat= form")); + _ + ("Process spawning is not supported on this platf= orm")); return -1; } =20 @@ -1438,14 +1438,14 @@ int virProcessSetupPrivateMountNS(void) { if (unshare(CLONE_NEWNS) < 0) { - virReportSystemError(errno, "%s", - _("Cannot unshare mount namespace")); + virReportSystemError(errno, "%s", _("Cannot unshare mount namespac= e")); return -1; } =20 - if (mount("", "/", "none", MS_SLAVE|MS_REC, NULL) < 0) { + if (mount("", "/", "none", MS_SLAVE | MS_REC, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed disable mount propagation out of th= e root filesystem")); + _ + ("Failed disable mount propagation out of the= root filesystem")); return -1; } =20 @@ -1558,8 +1558,7 @@ virProcessExitWithStatus(int status) struct sigaction act; sigset_t sigs; =20 - if (sigemptyset(&sigs) =3D=3D 0 && - sigaddset(&sigs, WTERMSIG(status)) =3D=3D 0) + if (sigemptyset(&sigs) =3D=3D 0 && sigaddset(&sigs, WTERMSIG(statu= s)) =3D=3D 0) sigprocmask(SIG_UNBLOCK, &sigs, NULL); memset(&act, 0, sizeof(act)); act.sa_handler =3D SIG_DFL; @@ -1569,7 +1568,7 @@ virProcessExitWithStatus(int status) value =3D 128 + WTERMSIG(status); } #else /* WIN32 */ - (void)status; + (void) status; #endif /* WIN32 */ exit(value); } @@ -1580,43 +1579,41 @@ static int virProcessSchedTranslatePolicy(virProcessSchedPolicy policy) { switch (policy) { - case VIR_PROC_POLICY_NONE: - return SCHED_OTHER; + case VIR_PROC_POLICY_NONE: + return SCHED_OTHER; =20 - case VIR_PROC_POLICY_BATCH: -# ifdef SCHED_BATCH - return SCHED_BATCH; -# else - return -1; -# endif + case VIR_PROC_POLICY_BATCH: +#ifdef SCHED_BATCH + return SCHED_BATCH; +#else + return -1; +#endif =20 - case VIR_PROC_POLICY_IDLE: -# ifdef SCHED_IDLE - return SCHED_IDLE; -# else - return -1; -# endif + case VIR_PROC_POLICY_IDLE: +#ifdef SCHED_IDLE + return SCHED_IDLE; +#else + return -1; +#endif =20 - case VIR_PROC_POLICY_FIFO: - return SCHED_FIFO; + case VIR_PROC_POLICY_FIFO: + return SCHED_FIFO; =20 - case VIR_PROC_POLICY_RR: - return SCHED_RR; + case VIR_PROC_POLICY_RR: + return SCHED_RR; =20 - case VIR_PROC_POLICY_LAST: - /* nada */ - break; + case VIR_PROC_POLICY_LAST: + /* nada */ + break; } =20 return -1; } =20 int -virProcessSetScheduler(pid_t pid, - virProcessSchedPolicy policy, - int priority) +virProcessSetScheduler(pid_t pid, virProcessSchedPolicy policy, int priori= ty) { - struct sched_param param =3D {0}; + struct sched_param param =3D { 0 }; int pol =3D virProcessSchedTranslatePolicy(policy); =20 VIR_DEBUG("pid=3D%lld, policy=3D%d, priority=3D%u", @@ -1674,8 +1671,7 @@ virProcessSetScheduler(pid_t pid, =20 int virProcessSetScheduler(pid_t pid G_GNUC_UNUSED, - virProcessSchedPolicy policy, - int priority G_GNUC_UNUSED) + virProcessSchedPolicy policy, int priority G_GNUC_U= NUSED) { if (!policy) return 0; @@ -1697,10 +1693,9 @@ virProcessSetScheduler(pid_t pid G_GNUC_UNUSED, * and return them as array of strings. */ GStrv -virProcessGetStat(pid_t pid, - pid_t tid) +virProcessGetStat(pid_t pid, pid_t tid) { - int len =3D 10 * 1024; /* 10kB ought to be enough for everyone */ + int len =3D 10 * 1024; /* 10kB ought to be enough for everyone = */ g_autofree char *buf =3D NULL; g_autofree char *path =3D NULL; GStrv rest =3D NULL; @@ -1711,12 +1706,13 @@ virProcessGetStat(pid_t pid, =20 if (pid) { if (tid) - path =3D g_strdup_printf("/proc/%d/task/%d/stat", (int)pid, (i= nt)tid); + path =3D + g_strdup_printf("/proc/%d/task/%d/stat", (int) pid, (int) = tid); else - path =3D g_strdup_printf("/proc/%d/stat", (int)pid); + path =3D g_strdup_printf("/proc/%d/stat", (int) pid); } else { if (tid) - path =3D g_strdup_printf("/proc/self/task/%d/stat", (int)tid); + path =3D g_strdup_printf("/proc/self/task/%d/stat", (int) tid); else path =3D g_strdup("/proc/self/stat"); } @@ -1727,7 +1723,7 @@ virProcessGetStat(pid_t pid, =20 /* eliminate trailing spaces */ while (len > 0 && g_ascii_isspace(buf[--len])) - buf[len] =3D '\0'; + buf[len] =3D '\0'; =20 /* Find end of the first field */ if (!(comm =3D strchr(buf, ' '))) @@ -1755,6 +1751,7 @@ virProcessGetStat(pid_t pid, rest =3D g_strsplit(rparen + 2, " ", 0); nrest =3D g_strv_length(rest); ret =3D g_new0(char *, nrest + 3); + ret[0] =3D g_strdup(buf); ret[1] =3D g_strdup(comm); memcpy(ret + 2, rest, nrest * sizeof(char *)); --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485817266253.8676875009603; Thu, 2 Dec 2021 14:56:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-358-djzL7AISNJurCD6EVU6gyQ-1; Thu, 02 Dec 2021 17:56:54 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1FB951023F4D; Thu, 2 Dec 2021 22:56:50 +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 01E70ADDC; Thu, 2 Dec 2021 22:56:50 +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 C6B3B1809CB8; Thu, 2 Dec 2021 22:56:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuRnk015588 for ; Thu, 2 Dec 2021 17:56:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 917E740CFD10; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CCB540CFD0C for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6FBD3185A7BA for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-305-bdf8mSHHPhSl9WRNQVKB6A-1; Thu, 02 Dec 2021 17:56:25 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 3D31320E67AD; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: djzL7AISNJurCD6EVU6gyQ-1 X-MC-Unique: bdf8mSHHPhSl9WRNQVKB6A-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3D31320E67AD From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/17] util: Helper functions to get process info Date: Thu, 2 Dec 2021 22:55:59 +0000 Message-Id: <20211202225614.1118066-3-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuRnk015588 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485818026100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/libvirt_private.syms | 2 + src/qemu/qemu_driver.c | 116 ++------------------------------------- src/util/virprocess.c | 108 ++++++++++++++++++++++++++++++++++++ src/util/virprocess.h | 5 ++ 4 files changed, 120 insertions(+), 111 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b98cb0f66d..e0c4fba522 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3099,8 +3099,10 @@ virProcessGetAffinity; virProcessGetMaxMemLock; virProcessGetNamespaces; virProcessGetPids; +virProcessGetSchedInfo; virProcessGetStartTime; virProcessGetStat; +virProcessGetStatInfo; virProcessGroupGet; virProcessGroupKill; virProcessKill; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4e680bc0a7..a7088d3a66 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1323,113 +1323,6 @@ qemuGetSchedstatDelay(unsigned long long *cpudelay, return 0; } =20 - -static int -qemuGetSchedInfo(unsigned long long *cpuWait, - pid_t pid, pid_t tid) -{ - g_autofree char *proc =3D NULL; - g_autofree char *data =3D NULL; - g_auto(GStrv) lines =3D NULL; - size_t i; - double val; - - *cpuWait =3D 0; - - /* In general, we cannot assume pid_t fits in int; but /proc parsing - * is specific to Linux where int works fine. */ - if (tid) - proc =3D g_strdup_printf("/proc/%d/task/%d/sched", (int)pid, (int)= tid); - else - proc =3D g_strdup_printf("/proc/%d/sched", (int)pid); - if (!proc) - return -1; - - /* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */ - if (access(proc, R_OK) < 0) { - return 0; - } - - if (virFileReadAll(proc, (1<<16), &data) < 0) - return -1; - - lines =3D g_strsplit(data, "\n", 0); - if (!lines) - return -1; - - for (i =3D 0; lines[i] !=3D NULL; i++) { - const char *line =3D lines[i]; - - /* Needs CONFIG_SCHEDSTATS. The second check - * is the old name the kernel used in past */ - if (STRPREFIX(line, "se.statistics.wait_sum") || - STRPREFIX(line, "se.wait_sum")) { - line =3D strchr(line, ':'); - if (!line) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing separator in sched info '%s'"), - lines[i]); - return -1; - } - line++; - while (*line =3D=3D ' ') - line++; - - if (virStrToDouble(line, NULL, &val) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse sched info value '%s'"), - line); - return -1; - } - - *cpuWait =3D (unsigned long long)(val * 1000000); - break; - } - } - - return 0; -} - - -static int -qemuGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss, - pid_t pid, pid_t tid) -{ - g_auto(GStrv) proc_stat =3D virProcessGetStat(pid, tid); - unsigned long long usertime =3D 0, systime =3D 0; - long rss =3D 0; - int cpu =3D 0; - - if (!proc_stat || - virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &us= ertime) < 0 || - virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &sy= stime) < 0 || - virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < = 0 || - virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &c= pu) < 0) { - VIR_WARN("cannot parse process status data"); - } - - /* We got jiffies - * We want nanoseconds - * _SC_CLK_TCK is jiffies per second - * So calculate thus.... - */ - if (cpuTime) - *cpuTime =3D 1000ull * 1000ull * 1000ull * (usertime + systime) - / (unsigned long long)sysconf(_SC_CLK_TCK); - if (lastCpu) - *lastCpu =3D cpu; - - if (vm_rss) - *vm_rss =3D rss * virGetSystemPageSizeKB(); - - - VIR_DEBUG("Got status for %d/%d user=3D%llu sys=3D%llu cpu=3D%d rss=3D= %ld", - (int)pid, tid, usertime, systime, cpu, rss); - - return 0; -} - - static int qemuDomainHelperGetVcpus(virDomainObj *vm, virVcpuInfoPtr info, @@ -1469,7 +1362,7 @@ qemuDomainHelperGetVcpus(virDomainObj *vm, vcpuinfo->number =3D i; vcpuinfo->state =3D VIR_VCPU_RUNNING; =20 - if (qemuGetProcessInfo(&vcpuinfo->cpuTime, + if (virProcessGetStatInfo(&vcpuinfo->cpuTime, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { virReportSystemError(errno, "%s", @@ -1490,7 +1383,7 @@ qemuDomainHelperGetVcpus(virDomainObj *vm, } =20 if (cpuwait) { - if (qemuGetSchedInfo(&(cpuwait[ncpuinfo]), vm->pid, vcpupid) <= 0) + if (virProcessGetSchedInfo(&(cpuwait[ncpuinfo]), vm->pid, vcpu= pid) < 0) return -1; } =20 @@ -2638,7 +2531,8 @@ qemuDomainGetInfo(virDomainPtr dom, } =20 if (virDomainObjIsActive(vm)) { - if (qemuGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) <= 0) { + if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL, + vm->pid, 0) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("cannot read cputime for domain")); goto cleanup; @@ -10650,7 +10544,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriver *driver, ret =3D 0; } =20 - if (qemuGetProcessInfo(NULL, NULL, &rss, vm->pid, 0) < 0) { + if (virProcessGetStatInfo(NULL, NULL, &rss, vm->pid, 0) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("cannot get RSS for domain")); } else { diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 8288e71f67..efa96299fc 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1761,3 +1761,111 @@ virProcessGetStat(pid_t pid, pid_t tid) =20 return ret; } + + +int +virProcessGetStatInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_= rss, + pid_t pid, pid_t tid) +{ + g_auto(GStrv) proc_stat =3D virProcessGetStat(pid, tid); + unsigned long long usertime =3D 0, systime =3D 0; + long rss =3D 0; + int cpu =3D 0; + + if (!proc_stat || + virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, + &usertime) < 0 + || virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, + &systime) < 0 + || virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss)= < 0 + || virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, + &cpu) < 0) { + VIR_WARN("cannot parse process status data"); + } + + /* We got jiffies + * We want nanoseconds + * _SC_CLK_TCK is jiffies per second + * So calculate thus.... + */ + if (cpuTime) + *cpuTime =3D 1000ull * 1000ull * 1000ull * (usertime + systime) + / (unsigned long long) sysconf(_SC_CLK_TCK); + if (lastCpu) + *lastCpu =3D cpu; + + if (vm_rss) + *vm_rss =3D rss * virGetSystemPageSizeKB(); + + + VIR_DEBUG("Got status for %d/%d user=3D%llu sys=3D%llu cpu=3D%d rss=3D= %ld", + (int) pid, tid, usertime, systime, cpu, rss); + + return 0; +} + +int +virProcessGetSchedInfo(unsigned long long *cpuWait, pid_t pid, pid_t tid) +{ + g_autofree char *proc =3D NULL; + g_autofree char *data =3D NULL; + + g_auto(GStrv) lines =3D NULL; + size_t i; + double val; + + *cpuWait =3D 0; + + /* In general, we cannot assume pid_t fits in int; but /proc parsing + * is specific to Linux where int works fine. */ + if (tid) + proc =3D g_strdup_printf("/proc/%d/task/%d/sched", (int) pid, (int= ) tid); + else + proc =3D g_strdup_printf("/proc/%d/sched", (int) pid); + if (!proc) + return -1; + + /* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */ + if (access(proc, R_OK) < 0) { + return 0; + } + + if (virFileReadAll(proc, (1 << 16), &data) < 0) + return -1; + + lines =3D g_strsplit(data, "\n", 0); + if (!lines) + return -1; + + for (i =3D 0; lines[i] !=3D NULL; i++) { + const char *line =3D lines[i]; + + /* Needs CONFIG_SCHEDSTATS. The second check + * is the old name the kernel used in past */ + if (STRPREFIX(line, "se.statistics.wait_sum") || + STRPREFIX(line, "se.wait_sum")) { + line =3D strchr(line, ':'); + if (!line) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing separator in sched info '%s'"), + lines[i]); + return -1; + } + line++; + while (*line =3D=3D ' ') + line++; + + if (virStrToDouble(line, NULL, &val) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse sched info value '%s'"), + line); + return -1; + } + + *cpuWait =3D (unsigned long long) (val * 1000000); + break; + } + } + + return 0; +} diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 82b7403964..d9d27c29b8 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -193,3 +193,8 @@ typedef enum { } virProcessNamespaceFlags; =20 int virProcessNamespaceAvailable(unsigned int ns); + +int virProcessGetStatInfo(unsigned long long *cpuTime, int *lastCpu, + long *vm_rss, pid_t pid, pid_t tid); +int virProcessGetSchedInfo(unsigned long long *cpuWait, pid_t pid, + pid_t tid); --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163848580299266.6322286783145; Thu, 2 Dec 2021 14:56:42 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-21-j17x3aKIOw2DSosgkYlA3A-1; Thu, 02 Dec 2021 17:56:38 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88BE4192CC40; Thu, 2 Dec 2021 22:56:32 +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 0F477ADC5; Thu, 2 Dec 2021 22:56:32 +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 8023A1809C89; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuQH0015574 for ; Thu, 2 Dec 2021 17:56:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id D4A181402408; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D08C01402406 for ; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7194811E7A for ; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-333-QY0h2HlPPlO5ympk3ITF-g-1; Thu, 02 Dec 2021 17:56:24 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 56F8E20E67B1; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: j17x3aKIOw2DSosgkYlA3A-1 X-MC-Unique: QY0h2HlPPlO5ympk3ITF-g-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 56F8E20E67B1 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/17] ch_domain: fix indentation in ch_domain Date: Thu, 2 Dec 2021 22:56:00 +0000 Message-Id: <20211202225614.1118066-4-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuQH0015574 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485803882100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.c | 130 ++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index dd4de9e1ea..44f7d26ca4 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -30,16 +30,12 @@ =20 VIR_ENUM_IMPL(virCHDomainJob, CH_JOB_LAST, - "none", - "query", - "destroy", - "modify", -); + "none", "query", "destroy", "modify",); =20 VIR_LOG_INIT("ch.ch_domain"); =20 static int -virCHDomainObjInitJob(virCHDomainObjPrivate *priv) +virCHDomainObjInitJob(virCHDomainObjPrivate * priv) { memset(&priv->job, 0, sizeof(priv->job)); =20 @@ -50,7 +46,7 @@ virCHDomainObjInitJob(virCHDomainObjPrivate *priv) } =20 static void -virCHDomainObjResetJob(virCHDomainObjPrivate *priv) +virCHDomainObjResetJob(virCHDomainObjPrivate * priv) { struct virCHDomainJobObj *job =3D &priv->job; =20 @@ -59,7 +55,7 @@ virCHDomainObjResetJob(virCHDomainObjPrivate *priv) } =20 static void -virCHDomainObjFreeJob(virCHDomainObjPrivate *priv) +virCHDomainObjFreeJob(virCHDomainObjPrivate * priv) { ignore_value(virCondDestroy(&priv->job.cond)); } @@ -74,7 +70,7 @@ virCHDomainObjFreeJob(virCHDomainObjPrivate *priv) * Successful calls must be followed by EndJob eventually. */ int -virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDomainJob job) +virCHDomainObjBeginJob(virDomainObj * obj, enum virCHDomainJob job) { virCHDomainObjPrivate *priv =3D obj->privateData; unsigned long long now; @@ -121,13 +117,12 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHD= omainJob job) * earlier virCHDomainBeginJob() call */ void -virCHDomainObjEndJob(virDomainObj *obj) +virCHDomainObjEndJob(virDomainObj * obj) { virCHDomainObjPrivate *priv =3D obj->privateData; enum virCHDomainJob job =3D priv->job.active; =20 - VIR_DEBUG("Stopping job: %s", - virCHDomainJobTypeToString(job)); + VIR_DEBUG("Stopping job: %s", virCHDomainJobTypeToString(job)); =20 virCHDomainObjResetJob(priv); virCondSignal(&priv->job.cond); @@ -170,8 +165,7 @@ virDomainXMLPrivateDataCallbacks virCHDriverPrivateData= Callbacks =3D { }; =20 static int -virCHDomainDefPostParseBasic(virDomainDef *def, - void *opaque G_GNUC_UNUSED) +virCHDomainDefPostParseBasic(virDomainDef * def, void *opaque G_GNUC_UNUSE= D) { /* check for emulator and create a default one if needed */ if (!def->emulator) { @@ -186,71 +180,70 @@ virCHDomainDefPostParseBasic(virDomainDef *def, } =20 static int -virCHDomainDefPostParse(virDomainDef *def, +virCHDomainDefPostParse(virDomainDef * def, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque, - void *parseOpaque G_GNUC_UNUSED) + void *opaque, void *parseOpaque G_GNUC_UNUSED) { virCHDriver *driver =3D opaque; + g_autoptr(virCaps) caps =3D virCHDriverGetCapabilities(driver, false); if (!caps) return -1; if (!virCapabilitiesDomainSupported(caps, def->os.type, - def->os.arch, - def->virtType)) + def->os.arch, def->virtType)) return -1; =20 return 0; } =20 static int -chValidateDomainDeviceDef(const virDomainDeviceDef *dev, - const virDomainDef *def G_GNUC_UNUSED, +chValidateDomainDeviceDef(const virDomainDeviceDef * dev, + const virDomainDef * def G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { - switch ((virDomainDeviceType)dev->type) { - case VIR_DOMAIN_DEVICE_DISK: - case VIR_DOMAIN_DEVICE_NET: - case VIR_DOMAIN_DEVICE_MEMORY: - case VIR_DOMAIN_DEVICE_VSOCK: - case VIR_DOMAIN_DEVICE_CONTROLLER: - case VIR_DOMAIN_DEVICE_CHR: - break; - - case VIR_DOMAIN_DEVICE_LEASE: - case VIR_DOMAIN_DEVICE_FS: - case VIR_DOMAIN_DEVICE_INPUT: - case VIR_DOMAIN_DEVICE_SOUND: - case VIR_DOMAIN_DEVICE_VIDEO: - case VIR_DOMAIN_DEVICE_HOSTDEV: - case VIR_DOMAIN_DEVICE_WATCHDOG: - case VIR_DOMAIN_DEVICE_GRAPHICS: - case VIR_DOMAIN_DEVICE_HUB: - case VIR_DOMAIN_DEVICE_REDIRDEV: - case VIR_DOMAIN_DEVICE_SMARTCARD: - case VIR_DOMAIN_DEVICE_MEMBALLOON: - case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_RNG: - case VIR_DOMAIN_DEVICE_SHMEM: - case VIR_DOMAIN_DEVICE_TPM: - case VIR_DOMAIN_DEVICE_PANIC: - case VIR_DOMAIN_DEVICE_IOMMU: - case VIR_DOMAIN_DEVICE_AUDIO: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Cloud-Hypervisor doesn't support '%s' device"), - virDomainDeviceTypeToString(dev->type)); - return -1; + switch ((virDomainDeviceType) dev->type) { + case VIR_DOMAIN_DEVICE_DISK: + case VIR_DOMAIN_DEVICE_NET: + case VIR_DOMAIN_DEVICE_MEMORY: + case VIR_DOMAIN_DEVICE_VSOCK: + case VIR_DOMAIN_DEVICE_CONTROLLER: + case VIR_DOMAIN_DEVICE_CHR: + break; + + case VIR_DOMAIN_DEVICE_LEASE: + case VIR_DOMAIN_DEVICE_FS: + case VIR_DOMAIN_DEVICE_INPUT: + case VIR_DOMAIN_DEVICE_SOUND: + case VIR_DOMAIN_DEVICE_VIDEO: + case VIR_DOMAIN_DEVICE_HOSTDEV: + case VIR_DOMAIN_DEVICE_WATCHDOG: + case VIR_DOMAIN_DEVICE_GRAPHICS: + case VIR_DOMAIN_DEVICE_HUB: + case VIR_DOMAIN_DEVICE_REDIRDEV: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_RNG: + case VIR_DOMAIN_DEVICE_SHMEM: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_AUDIO: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cloud-Hypervisor doesn't support '%s' device= "), + virDomainDeviceTypeToString(dev->type)); + return -1; =20 - case VIR_DOMAIN_DEVICE_NONE: - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected VIR_DOMAIN_DEVICE_NONE")); - return -1; + case VIR_DOMAIN_DEVICE_NONE: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected VIR_DOMAIN_DEVICE_NONE")); + return -1; =20 - case VIR_DOMAIN_DEVICE_LAST: - default: - virReportEnumRangeError(virDomainDeviceType, dev->type); - return -1; + case VIR_DOMAIN_DEVICE_LAST: + default: + virReportEnumRangeError(virDomainDeviceType, dev->type); + return -1; } =20 if ((def->nconsoles && @@ -258,25 +251,30 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *d= ev, && (def->nserials && def->serials[0]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY))= { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only a single console or serial can be configure= d for this domain")); + _ + ("Only a single console or serial can be configured= for this domain")); return -1; } else if (def->nconsoles > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only a single console can be configured for this= domain")); + _ + ("Only a single console can be configured for this = domain")); return -1; } else if (def->nserials > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only a single serial can be configured for this = domain")); + _ + ("Only a single serial can be configured for this d= omain")); return -1; } =20 - if (def->nconsoles && def->consoles[0]->source->type !=3D VIR_DOMAIN_C= HR_TYPE_PTY) { + if (def->nconsoles + && def->consoles[0]->source->type !=3D VIR_DOMAIN_CHR_TYPE_PTY) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Console can only be enabled for a PTY")); return -1; } =20 - if (def->nserials && def->serials[0]->source->type !=3D VIR_DOMAIN_CHR= _TYPE_PTY) { + if (def->nserials + && def->serials[0]->source->type !=3D VIR_DOMAIN_CHR_TYPE_PTY) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Serial can only be enabled for a PTY")); return -1; --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638485848349884.9378739514033; Thu, 2 Dec 2021 14:57:28 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-549-tA50fi0iOXeBiWcfMUzr9Q-1; Thu, 02 Dec 2021 17:57:22 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48133344B3; Thu, 2 Dec 2021 22:57:17 +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 2A63B45D68; Thu, 2 Dec 2021 22:57:17 +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 F1C581802E2E; Thu, 2 Dec 2021 22:57:16 +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 1B2MuTMO015653 for ; Thu, 2 Dec 2021 17:56:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id BA47E1121314; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84F591121318 for ; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A14358011A5 for ; Thu, 2 Dec 2021 22:56:26 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-367-6hOiQFRKOKKNICyO73tpdQ-1; Thu, 02 Dec 2021 17:56:25 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 6CA7A20E67B5; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: tA50fi0iOXeBiWcfMUzr9Q-1 X-MC-Unique: 6hOiQFRKOKKNICyO73tpdQ-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6CA7A20E67B5 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/17] ch_domain: add virCHDomainGetMonitor helper method Date: Thu, 2 Dec 2021 22:56:01 +0000 Message-Id: <20211202225614.1118066-5-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuTMO015653 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485850079100005 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.c | 6 ++++++ src/ch/ch_domain.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 44f7d26ca4..7bfe950822 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -288,3 +288,9 @@ virDomainDefParserConfig virCHDriverDomainDefParserConf= ig =3D { .domainPostParseCallback =3D virCHDomainDefPostParse, .deviceValidateCallback =3D chValidateDomainDeviceDef, }; + +virCHMonitor * +virCHDomainGetMonitor(virDomainObj * vm) +{ + return CH_DOMAIN_PRIVATE(vm)->monitor; +} diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 61b34b0467..04d19398b4 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -57,6 +57,11 @@ struct _virCHDomainObjPrivate { virChrdevs *chrdevs; }; =20 +#define CH_DOMAIN_PRIVATE(vm) \ + ((virCHDomainObjPrivate *) (vm)->privateData) + +virCHMonitor *virCHDomainGetMonitor(virDomainObj *vm); + extern virDomainXMLPrivateDataCallbacks virCHDriverPrivateDataCallbacks; extern virDomainDefParserConfig virCHDriverDomainDefParserConfig; =20 --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638485818010275.12789795666674; Thu, 2 Dec 2021 14:56:58 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-_q28om-gPoG6JR38idWV9Q-1; Thu, 02 Dec 2021 17:56:55 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16600344AF; Thu, 2 Dec 2021 22:56:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9A0C100E125; Thu, 2 Dec 2021 22:56: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 AE3574A7C8; Thu, 2 Dec 2021 22:56:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSD3015596 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 36FD1492CA3; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32D6F492C38 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18121100E65A for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-139-pHDGBlTdM1GhjZy9ni91Lg-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 8230D20E67B8; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: _q28om-gPoG6JR38idWV9Q-1 X-MC-Unique: pHDGBlTdM1GhjZy9ni91Lg-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8230D20E67B8 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/17] ch_domain: add methods to manage private vcpu data Date: Thu, 2 Dec 2021 22:56:02 +0000 Message-Id: <20211202225614.1118066-6-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSD3015596 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485820018100003 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.c | 50 +++++++++++++++++++++++++++++++++++++++++----- src/ch/ch_domain.h | 11 ++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 7bfe950822..2769d758fe 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -159,11 +159,6 @@ virCHDomainObjPrivateFree(void *data) g_free(priv); } =20 -virDomainXMLPrivateDataCallbacks virCHDriverPrivateDataCallbacks =3D { - .alloc =3D virCHDomainObjPrivateAlloc, - .free =3D virCHDomainObjPrivateFree, -}; - static int virCHDomainDefPostParseBasic(virDomainDef * def, void *opaque G_GNUC_UNUSE= D) { @@ -179,6 +174,45 @@ virCHDomainDefPostParseBasic(virDomainDef * def, void = *opaque G_GNUC_UNUSED) return 0; } =20 +static virClass *virCHDomainVcpuPrivateClass; +static void virCHDomainVcpuPrivateDispose(void *obj); + +static int +virCHDomainVcpuPrivateOnceInit(void) +{ + if (!VIR_CLASS_NEW(virCHDomainVcpuPrivate, virClassForObject())) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virCHDomainVcpuPrivate); + +static virObject * +virCHDomainVcpuPrivateNew(void) +{ + virCHDomainVcpuPrivate *priv; + + if (virCHDomainVcpuPrivateInitialize() < 0) + return NULL; + + if (!(priv =3D virObjectNew(virCHDomainVcpuPrivateClass))) + return NULL; + + return (virObject *) priv; +} + + +static void +virCHDomainVcpuPrivateDispose(void *obj) +{ + virCHDomainVcpuPrivate *priv =3D obj; + + priv->tid =3D 0; + + return; +} + static int virCHDomainDefPostParse(virDomainDef * def, unsigned int parseFlags G_GNUC_UNUSED, @@ -196,6 +230,12 @@ virCHDomainDefPostParse(virDomainDef * def, return 0; } =20 +virDomainXMLPrivateDataCallbacks virCHDriverPrivateDataCallbacks =3D { + .alloc =3D virCHDomainObjPrivateAlloc, + .free =3D virCHDomainObjPrivateFree, + .vcpuNew =3D virCHDomainVcpuPrivateNew, +}; + static int chValidateDomainDeviceDef(const virDomainDeviceDef * dev, const virDomainDef * def G_GNUC_UNUSED, diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 04d19398b4..75b9933130 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -62,6 +62,17 @@ struct _virCHDomainObjPrivate { =20 virCHMonitor *virCHDomainGetMonitor(virDomainObj *vm); =20 +typedef struct _virCHDomainVcpuPrivate virCHDomainVcpuPrivate; +struct _virCHDomainVcpuPrivate { + virObject parent; + + pid_t tid; /* vcpu thread id */ + virTristateBool halted; +}; + +#define CH_DOMAIN_VCPU_PRIVATE(vcpu) \ + ((virCHDomainVcpuPrivate *) (vcpu)->privateData) + extern virDomainXMLPrivateDataCallbacks virCHDriverPrivateDataCallbacks; extern virDomainDefParserConfig virCHDriverDomainDefParserConfig; =20 --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485838111326.2743154842217; Thu, 2 Dec 2021 14:57:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-A4S_f70DOnWKya6h1LzZKw-1; Thu, 02 Dec 2021 17:57:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9291801B22; Thu, 2 Dec 2021 22:57:10 +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 A976717D61; Thu, 2 Dec 2021 22:57:10 +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 7C0221802E2A; Thu, 2 Dec 2021 22:57:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuXZk015708 for ; Thu, 2 Dec 2021 17:56:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F5FB2166B41; Thu, 2 Dec 2021 22:56:33 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38A7C2166B3F for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B763805B0A for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-133-q-rofM9uOG67YRtht6W06A-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 992FD20E67BC; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: A4S_f70DOnWKya6h1LzZKw-1 X-MC-Unique: q-rofM9uOG67YRtht6W06A-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 992FD20E67BC From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/17] ch_driver: fix indentation in ch_driver Date: Thu, 2 Dec 2021 22:56:03 +0000 Message-Id: <20211202225614.1118066-7-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuXZk015708 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485839169100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/ch/ch_driver.c | 241 +++++++++++++++++++++++---------------------- 1 file changed, 121 insertions(+), 120 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 464bcef907..75c6a15dd6 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -50,7 +50,7 @@ VIR_LOG_INIT("ch.ch_driver"); virCHDriver *ch_driver =3D NULL; =20 static virDomainObj * -chDomObjFromDomain(virDomain *domain) +chDomObjFromDomain(virDomain * domain) { virDomainObj *vm; virCHDriver *driver =3D domain->conn->privateData; @@ -79,10 +79,10 @@ chConnectURIProbe(char **uri) return 1; } =20 -static virDrvOpenStatus chConnectOpen(virConnectPtr conn, - virConnectAuthPtr auth G_GNUC_UNUSED, - virConf *conf G_GNUC_UNUSED, - unsigned int flags) +static virDrvOpenStatus +chConnectOpen(virConnectPtr conn, + virConnectAuthPtr auth G_GNUC_UNUSED, + virConf * conf G_GNUC_UNUSED, unsigned int flags) { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 @@ -101,13 +101,15 @@ static virDrvOpenStatus chConnectOpen(virConnectPtr c= onn, return VIR_DRV_OPEN_SUCCESS; } =20 -static int chConnectClose(virConnectPtr conn) +static int +chConnectClose(virConnectPtr conn) { conn->privateData =3D NULL; return 0; } =20 -static const char *chConnectGetType(virConnectPtr conn) +static const char * +chConnectGetType(virConnectPtr conn) { if (virConnectGetTypeEnsureACL(conn) < 0) return NULL; @@ -115,8 +117,8 @@ static const char *chConnectGetType(virConnectPtr conn) return "CH"; } =20 -static int chConnectGetVersion(virConnectPtr conn, - unsigned long *version) +static int +chConnectGetVersion(virConnectPtr conn, unsigned long *version) { virCHDriver *driver =3D conn->privateData; =20 @@ -129,7 +131,8 @@ static int chConnectGetVersion(virConnectPtr conn, return 0; } =20 -static char *chConnectGetHostname(virConnectPtr conn) +static char * +chConnectGetHostname(virConnectPtr conn) { if (virConnectGetHostnameEnsureACL(conn) < 0) return NULL; @@ -137,7 +140,8 @@ static char *chConnectGetHostname(virConnectPtr conn) return virGetHostname(); } =20 -static int chConnectNumOfDomains(virConnectPtr conn) +static int +chConnectNumOfDomains(virConnectPtr conn) { virCHDriver *driver =3D conn->privateData; =20 @@ -148,7 +152,8 @@ static int chConnectNumOfDomains(virConnectPtr conn) virConnectNumOfDomainsCheckACL, co= nn); } =20 -static int chConnectListDomains(virConnectPtr conn, int *ids, int nids) +static int +chConnectListDomains(virConnectPtr conn, int *ids, int nids) { virCHDriver *driver =3D conn->privateData; =20 @@ -156,13 +161,12 @@ static int chConnectListDomains(virConnectPtr conn, i= nt *ids, int nids) return -1; =20 return virDomainObjListGetActiveIDs(driver->domains, ids, nids, - virConnectListDomainsCheckACL, conn); + virConnectListDomainsCheckACL, con= n); } =20 static int chConnectListAllDomains(virConnectPtr conn, - virDomainPtr **domains, - unsigned int flags) + virDomainPtr ** domains, unsigned int flags) { virCHDriver *driver =3D conn->privateData; =20 @@ -172,11 +176,11 @@ chConnectListAllDomains(virConnectPtr conn, return -1; =20 return virDomainObjListExport(driver->domains, conn, domains, - virConnectListAllDomainsCheckACL, flags); + virConnectListAllDomainsCheckACL, flags); } =20 -static int chNodeGetInfo(virConnectPtr conn, - virNodeInfoPtr nodeinfo) +static int +chNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) { if (virNodeGetInfoEnsureACL(conn) < 0) return -1; @@ -184,7 +188,8 @@ static int chNodeGetInfo(virConnectPtr conn, return virCapabilitiesGetNodeInfo(nodeinfo); } =20 -static char *chConnectGetCapabilities(virConnectPtr conn) +static char * +chConnectGetCapabilities(virConnectPtr conn) { virCHDriver *driver =3D conn->privateData; virCaps *caps; @@ -213,9 +218,7 @@ static char *chConnectGetCapabilities(virConnectPtr con= n) * Returns a new domain object or NULL in case of failure. */ static virDomainPtr -chDomainCreateXML(virConnectPtr conn, - const char *xml, - unsigned int flags) +chDomainCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { virCHDriver *driver =3D conn->privateData; virDomainDef *vmdef =3D NULL; @@ -240,8 +243,7 @@ chDomainCreateXML(virConnectPtr conn, &vmdef, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) goto cleanup; =20 if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0) @@ -343,8 +345,7 @@ chDomainDefineXML(virConnectPtr conn, const char *xml) } =20 static int -chDomainUndefineFlags(virDomainPtr dom, - unsigned int flags) +chDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { virCHDriver *driver =3D dom->conn->privateData; virDomainObj *vm; @@ -383,7 +384,8 @@ chDomainUndefine(virDomainPtr dom) return chDomainUndefineFlags(dom, 0); } =20 -static int chDomainIsActive(virDomainPtr dom) +static int +chDomainIsActive(virDomainPtr dom) { virCHDriver *driver =3D dom->conn->privateData; virDomainObj *vm; @@ -405,8 +407,7 @@ static int chDomainIsActive(virDomainPtr dom) } =20 static int -chDomainShutdownFlags(virDomainPtr dom, - unsigned int flags) +chDomainShutdownFlags(virDomainPtr dom, unsigned int flags) { virCHDomainObjPrivate *priv; virDomainObj *vm; @@ -437,7 +438,7 @@ chDomainShutdownFlags(virDomainPtr dom, } else { if (virCHMonitorShutdownVM(priv->monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to shutdown guest VM")); + _("failed to shutdown guest VM")); goto endjob; } } @@ -501,7 +502,8 @@ chDomainReboot(virDomainPtr dom, unsigned int flags) if (state =3D=3D VIR_DOMAIN_RUNNING) virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BO= OTED); else - virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UN= PAUSED); + virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, + VIR_DOMAIN_RUNNING_UNPAUSED); =20 ret =3D 0; =20 @@ -541,7 +543,7 @@ chDomainSuspend(virDomainPtr dom) } else { if (virCHMonitorSuspendVM(priv->monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to suspend domain")); + _("failed to suspend domain")); goto endjob; } } @@ -586,7 +588,7 @@ chDomainResume(virDomainPtr dom) } else { if (virCHMonitorResumeVM(priv->monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to resume domain")); + _("failed to resume domain")); goto endjob; } } @@ -651,8 +653,8 @@ chDomainDestroy(virDomainPtr dom) return chDomainDestroyFlags(dom, 0); } =20 -static virDomainPtr chDomainLookupByID(virConnectPtr conn, - int id) +static virDomainPtr +chDomainLookupByID(virConnectPtr conn, int id) { virCHDriver *driver =3D conn->privateData; virDomainObj *vm; @@ -678,8 +680,8 @@ static virDomainPtr chDomainLookupByID(virConnectPtr co= nn, return dom; } =20 -static virDomainPtr chDomainLookupByName(virConnectPtr conn, - const char *name) +static virDomainPtr +chDomainLookupByName(virConnectPtr conn, const char *name) { virCHDriver *driver =3D conn->privateData; virDomainObj *vm; @@ -705,8 +707,8 @@ static virDomainPtr chDomainLookupByName(virConnectPtr = conn, return dom; } =20 -static virDomainPtr chDomainLookupByUUID(virConnectPtr conn, - const unsigned char *uuid) +static virDomainPtr +chDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { virCHDriver *driver =3D conn->privateData; virDomainObj *vm; @@ -718,6 +720,7 @@ static virDomainPtr chDomainLookupByUUID(virConnectPtr = conn, =20 if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_DOMAIN, _("no domain with matching uuid '%s'"), uuidstr); @@ -735,10 +738,7 @@ static virDomainPtr chDomainLookupByUUID(virConnectPtr= conn, } =20 static int -chDomainGetState(virDomainPtr dom, - int *state, - int *reason, - unsigned int flags) +chDomainGetState(virDomainPtr dom, int *state, int *reason, unsigned int f= lags) { virDomainObj *vm; int ret =3D -1; @@ -759,8 +759,8 @@ chDomainGetState(virDomainPtr dom, return ret; } =20 -static char *chDomainGetXMLDesc(virDomainPtr dom, - unsigned int flags) +static char * +chDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { virCHDriver *driver =3D dom->conn->privateData; virDomainObj *vm; @@ -782,8 +782,8 @@ static char *chDomainGetXMLDesc(virDomainPtr dom, return ret; } =20 -static int chDomainGetInfo(virDomainPtr dom, - virDomainInfoPtr info) +static int +chDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) { virDomainObj *vm; int ret =3D -1; @@ -811,77 +811,76 @@ static int chDomainGetInfo(virDomainPtr dom, =20 static int chDomainOpenConsole(virDomainPtr dom, - const char *dev_name, - virStreamPtr st, - unsigned int flags) -{ - virDomainObj *vm =3D NULL; - int ret =3D -1; - size_t i; - virDomainChrDef *chr =3D NULL; - virCHDomainObjPrivate *priv; - - virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE | VIR_DOMAIN_CONSOLE_FORCE, -1); - - if (!(vm =3D chDomObjFromDomain(dom))) - goto cleanup; - - if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0) - goto cleanup; - - if (virDomainObjCheckActive(vm) < 0) - goto cleanup; - - priv =3D vm->privateData; - - if (dev_name) { - for (i =3D 0; !chr && i < vm->def->nconsoles; i++) { - if (vm->def->consoles[i]->info.alias && - STREQ(dev_name, vm->def->consoles[i]->info.alias)) - chr =3D vm->def->consoles[i]; - } - for (i =3D 0; !chr && i < vm->def->nserials; i++) { - if (STREQ(dev_name, vm->def->serials[i]->info.alias)) - chr =3D vm->def->serials[i]; - } - } else { - if (vm->def->nconsoles && - vm->def->consoles[0]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PTY) - chr =3D vm->def->consoles[0]; - else if (vm->def->nserials && - vm->def->serials[0]->source->type =3D=3D VIR_DOMAIN_CHR= _TYPE_PTY) - chr =3D vm->def->serials[0]; - } - - if (!chr) { - virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find character = device %s"), - NULLSTR(dev_name)); - goto cleanup; - } - - if (chr->source->type !=3D VIR_DOMAIN_CHR_TYPE_PTY) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("character device %s is not using a PTY"), - dev_name ? dev_name : NULLSTR(chr->info.alias)); - goto cleanup; - } - - /* handle mutually exclusive access to console devices */ - ret =3D virChrdevOpen(priv->chrdevs, chr->source, st, - (flags & VIR_DOMAIN_CONSOLE_FORCE) !=3D 0); - - if (ret =3D=3D 1) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("Active console session exists for this domain"= )); - ret =3D -1; - } + const char *dev_name, virStreamPtr st, unsigned int fl= ags) +{ + virDomainObj *vm =3D NULL; + int ret =3D -1; + size_t i; + virDomainChrDef *chr =3D NULL; + virCHDomainObjPrivate *priv; + + virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE | VIR_DOMAIN_CONSOLE_FORCE, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + priv =3D vm->privateData; + + if (dev_name) { + for (i =3D 0; !chr && i < vm->def->nconsoles; i++) { + if (vm->def->consoles[i]->info.alias && + STREQ(dev_name, vm->def->consoles[i]->info.alias)) + chr =3D vm->def->consoles[i]; + } + for (i =3D 0; !chr && i < vm->def->nserials; i++) { + if (STREQ(dev_name, vm->def->serials[i]->info.alias)) + chr =3D vm->def->serials[i]; + } + } else { + if (vm->def->nconsoles && + vm->def->consoles[0]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_= PTY) + chr =3D vm->def->consoles[0]; + else if (vm->def->nserials && + vm->def->serials[0]->source->type =3D=3D VIR_DOMAIN_CHR_T= YPE_PTY) + chr =3D vm->def->serials[0]; + } + + if (!chr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find character device %s"), NULLSTR(dev_n= ame)); + goto cleanup; + } + + if (chr->source->type !=3D VIR_DOMAIN_CHR_TYPE_PTY) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("character device %s is not using a PTY"), + dev_name ? dev_name : NULLSTR(chr->info.alias)); + goto cleanup; + } + + /* handle mutually exclusive access to console devices */ + ret =3D virChrdevOpen(priv->chrdevs, chr->source, st, + (flags & VIR_DOMAIN_CONSOLE_FORCE) !=3D 0); + + if (ret =3D=3D 1) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Active console session exists for this domain")); + ret =3D -1; + } =20 cleanup: - virDomainObjEndAPI(&vm); - return ret; + virDomainObjEndAPI(&vm); + return ret; } =20 -static int chStateCleanup(void) +static int +chStateCleanup(void) { if (ch_driver =3D=3D NULL) return -1; @@ -897,10 +896,11 @@ static int chStateCleanup(void) return 0; } =20 -static int chStateInitialize(bool privileged, - const char *root, - virStateInhibitCallback callback G_GNUC_UNUSE= D, - void *opaque G_GNUC_UNUSED) +static int +chStateInitialize(bool privileged, + const char *root, + virStateInhibitCallback callback G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) { int ret =3D VIR_DRV_STATE_INIT_ERROR; int rv; @@ -984,7 +984,7 @@ static virHypervisorDriver chHypervisorDriver =3D { =20 static virConnectDriver chConnectDriver =3D { .localOnly =3D true, - .uriSchemes =3D (const char *[]){"ch", NULL}, + .uriSchemes =3D (const char *[]) {"ch", NULL}, .hypervisorDriver =3D &chHypervisorDriver, }; =20 @@ -994,7 +994,8 @@ static virStateDriver chStateDriver =3D { .stateCleanup =3D chStateCleanup, }; =20 -int chRegister(void) +int +chRegister(void) { if (virRegisterConnectDriver(&chConnectDriver, true) < 0) return -1; --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638485827406605.2049730843404; Thu, 2 Dec 2021 14:57:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-373-4BjJ3kRDMq-EhGnyMG7ZoQ-1; Thu, 02 Dec 2021 17:57:03 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A96F6801B2A; Thu, 2 Dec 2021 22:56:56 +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 8DFEB45D6F; Thu, 2 Dec 2021 22:56:56 +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 56BDD1802E28; Thu, 2 Dec 2021 22:56:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSnd015595 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 36C8D401E56; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32B5F401E38 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19095185A79C for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-151-itJ2ufxCPZmn_bBuMfMWFA-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id AF54420E67C0; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: 4BjJ3kRDMq-EhGnyMG7ZoQ-1 X-MC-Unique: itJ2ufxCPZmn_bBuMfMWFA-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AF54420E67C0 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/17] ch_driver, ch_domain: vcpu info getter callbacks Date: Thu, 2 Dec 2021 22:56:04 +0000 Message-Id: <20211202225614.1118066-8-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSnd015595 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485829231100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.c | 25 +++++++++ src/ch/ch_domain.h | 4 ++ src/ch/ch_driver.c | 137 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 2769d758fe..d81221679e 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -334,3 +334,28 @@ virCHDomainGetMonitor(virDomainObj * vm) { return CH_DOMAIN_PRIVATE(vm)->monitor; } + +pid_t +virCHDomainGetVcpuPid(virDomainObj * vm, unsigned int vcpuid) +{ + virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, vcpuid); + + return CH_DOMAIN_VCPU_PRIVATE(vcpu)->tid; +} + +bool +virCHDomainHasVcpuPids(virDomainObj * vm) +{ + size_t i; + size_t maxvcpus =3D virDomainDefGetVcpusMax(vm->def); + virDomainVcpuDef *vcpu; + + for (i =3D 0; i < maxvcpus; i++) { + vcpu =3D virDomainDefGetVcpu(vm->def, i); + + if (CH_DOMAIN_VCPU_PRIVATE(vcpu)->tid > 0) + return true; + } + + return false; +} diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 75b9933130..d9c9d34a19 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -82,3 +82,7 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDomai= nJob job) =20 void virCHDomainObjEndJob(virDomainObj *obj); + +int virCHDomainRefreshVcpuInfo(virDomainObj *vm); +pid_t virCHDomainGetVcpuPid(virDomainObj *vm, unsigned int vcpuid); +bool virCHDomainHasVcpuPids(virDomainObj *vm); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 75c6a15dd6..52c88571af 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -944,6 +944,140 @@ chStateInitialize(bool privileged, return ret; } =20 +static int +chDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags) +{ + virDomainObj *vm; + virDomainDef *def; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_GUEST, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + return -1; + + if (virDomainGetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + if (!(def =3D virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) + ret =3D virDomainDefGetVcpusMax(def); + else + ret =3D virDomainDefGetVcpus(def); + + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +chDomainGetMaxVcpus(virDomainPtr dom) +{ + return chDomainGetVcpusFlags(dom, + (VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_VCPU_MAXIMUM)); +} + +static int +chDomainHelperGetVcpus(virDomainObj * vm, + virVcpuInfoPtr info, + unsigned long long *cpuwait, + int maxinfo, unsigned char *cpumaps, int maplen) +{ + size_t ncpuinfo =3D 0; + size_t i; + + if (maxinfo =3D=3D 0) + return 0; + + if (!virCHDomainHasVcpuPids(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + return -1; + } + + if (info) + memset(info, 0, sizeof(*info) * maxinfo); + + if (cpumaps) + memset(cpumaps, 0, sizeof(*cpumaps) * maxinfo); + + for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def) && ncpuinfo < maxin= fo; i++) { + virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, i); + pid_t vcpupid =3D virCHDomainGetVcpuPid(vm, i); + virVcpuInfoPtr vcpuinfo =3D info + ncpuinfo; + + if (!vcpu->online) + continue; + + if (info) { + vcpuinfo->number =3D i; + vcpuinfo->state =3D VIR_VCPU_RUNNING; + if (virProcessGetStatInfo(&vcpuinfo->cpuTime, + &vcpuinfo->cpu, NULL, + vm->pid, vcpupid) < 0) { + virReportSystemError(errno, "%s", + _ + ("cannot get vCPU placement & pCPU ti= me")); + return -1; + } + } + + if (cpumaps) { + unsigned char *cpumap =3D VIR_GET_CPUMAP(cpumaps, maplen, ncpu= info); + g_autoptr(virBitmap) map =3D NULL; + + if (!(map =3D virProcessGetAffinity(vcpupid))) + return -1; + + virBitmapToDataBuf(map, cpumap, maplen); + } + + if (cpuwait) { + if (virProcessGetSchedInfo(&(cpuwait[ncpuinfo]), vm->pid, vcpu= pid) < + 0) + return -1; + } + + ncpuinfo++; + } + + return ncpuinfo; +} + +static int +chDomainGetVcpus(virDomainPtr dom, + virVcpuInfoPtr info, + int maxinfo, unsigned char *cpumaps, int maplen) +{ + virDomainObj *vm; + int ret =3D -1; + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetVcpusEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _ + ("cannot retrieve vcpu information for inactive dom= ain")); + goto cleanup; + } + + ret =3D chDomainHelperGetVcpus(vm, info, NULL, maxinfo, cpumaps, maple= n); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + /* Function Tables */ static virHypervisorDriver chHypervisorDriver =3D { .name =3D "CH", @@ -980,6 +1114,9 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainIsActive =3D chDomainIsActive, /* 7.5.0 */ .domainOpenConsole =3D chDomainOpenConsole, /* 7.8.0 */ .nodeGetInfo =3D chNodeGetInfo, /* 7.5.0 */ + .domainGetVcpus =3D chDomainGetVcpus, /* 7.11.0 */ + .domainGetVcpusFlags =3D chDomainGetVcpusFlags, /* 7.11.0 */ + .domainGetMaxVcpus =3D chDomainGetMaxVcpus, /* 7.11.0 */ }; =20 static virConnectDriver chConnectDriver =3D { --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638485821259615.2965999891534; Thu, 2 Dec 2021 14:57:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-141-_J7IsiHJOv-C30uRripneA-1; Thu, 02 Dec 2021 17:56:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6787F344B1; Thu, 2 Dec 2021 22:56:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 487D019729; Thu, 2 Dec 2021 22:56:53 +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 170CF4A7CB; Thu, 2 Dec 2021 22:56:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuS0D015593 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0785840CFD10; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02B7140CFD0C for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DF64C803D7B for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-401-eqCZbIXzPseIYLuygbpx2Q-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id C515120E67C3; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: _J7IsiHJOv-C30uRripneA-1 X-MC-Unique: eqCZbIXzPseIYLuygbpx2Q-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C515120E67C3 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/17] ch_driver: domainGetVcpuPinInfo and nodeGetCPUMap Date: Thu, 2 Dec 2021 22:56:05 +0000 Message-Id: <20211202225614.1118066-9-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuS0D015593 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485822317100001 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Add domainGetVcpuPinInfo and nodeGetCPUMap callbacks to ch driver Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.h | 12 +++++++++-- src/ch/ch_driver.c | 54 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index d9c9d34a19..e35777a9ec 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -23,6 +23,7 @@ #include "ch_conf.h" #include "ch_monitor.h" #include "virchrdev.h" +#include "vircgroup.h" =20 /* Give up waiting for mutex after 30 seconds */ #define CH_JOB_WAIT_TIME (1000ull * 30) @@ -52,9 +53,16 @@ typedef struct _virCHDomainObjPrivate virCHDomainObjPriv= ate; struct _virCHDomainObjPrivate { struct virCHDomainJobObj job; =20 - virCHMonitor *monitor; + virChrdevs *chrdevs; + + virCgroup *cgroup; =20 - virChrdevs *chrdevs; + virCHDriver *driver; + virCHMonitor *monitor; + char *machineName; + virBitmap *autoNodeset; + virBitmap *autoCpuset; + virChrdevs *devs; }; =20 #define CH_DOMAIN_PRIVATE(vm) \ diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 52c88571af..86d2776354 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -984,7 +984,56 @@ chDomainGetMaxVcpus(virDomainPtr dom) } =20 static int -chDomainHelperGetVcpus(virDomainObj * vm, +chDomainGetVcpuPinInfo(virDomain * dom, + int ncpumaps, + unsigned char *cpumaps, int maplen, unsigned int fl= ags) +{ + virDomainObj *vm =3D NULL; + virDomainDef *def; + bool live; + int ret =3D -1; + + g_autoptr(virBitmap) hostcpus =3D NULL; + virBitmap *autoCpuset =3D NULL; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetVcpuPinInfoEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!(def =3D virDomainObjGetOneDefState(vm, flags, &live))) + goto cleanup; + + if (!(hostcpus =3D virHostCPUGetAvailableCPUsBitmap())) + goto cleanup; + + if (live) + autoCpuset =3D CH_DOMAIN_PRIVATE(vm)->autoCpuset; + + ret =3D virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumap= s, + hostcpus, autoCpuset); + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +chNodeGetCPUMap(virConnectPtr conn, + unsigned char **cpumap, + unsigned int *online, unsigned int flags) +{ + if (virNodeGetCPUMapEnsureACL(conn) < 0) + return -1; + + return virHostCPUGetMap(cpumap, online, flags); +} + + +static int +chDomainHelperGetVcpus(virDomainObj *vm, virVcpuInfoPtr info, unsigned long long *cpuwait, int maxinfo, unsigned char *cpumaps, int maplen) @@ -1030,6 +1079,7 @@ chDomainHelperGetVcpus(virDomainObj * vm, =20 if (cpumaps) { unsigned char *cpumap =3D VIR_GET_CPUMAP(cpumaps, maplen, ncpu= info); + g_autoptr(virBitmap) map =3D NULL; =20 if (!(map =3D virProcessGetAffinity(vcpupid))) @@ -1117,6 +1167,8 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainGetVcpus =3D chDomainGetVcpus, /* 7.11.0 */ .domainGetVcpusFlags =3D chDomainGetVcpusFlags, /* 7.11.0 */ .domainGetMaxVcpus =3D chDomainGetMaxVcpus, /* 7.11.0 */ + .domainGetVcpuPinInfo =3D chDomainGetVcpuPinInfo, /* 7.11.0 */ + .nodeGetCPUMap =3D chNodeGetCPUMap, /* 7.11.0 */ }; =20 static virConnectDriver chConnectDriver =3D { --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485804178689.9563381562554; Thu, 2 Dec 2021 14:56:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-402-PvwfJRv7OiGCkV0AsGeTQQ-1; Thu, 02 Dec 2021 17:56:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 347BF1023F4D; Thu, 2 Dec 2021 22:56:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C29E6ADD5; Thu, 2 Dec 2021 22:56:32 +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 AE2054BB7C; Thu, 2 Dec 2021 22:56:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSaE015594 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0EC401402408; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A2BE1402406 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E20F1805B9A for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-364-0R7RT7J7OgyabwOynhLYhA-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id DC81C20E67C8; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: PvwfJRv7OiGCkV0AsGeTQQ-1 X-MC-Unique: 0R7RT7J7OgyabwOynhLYhA-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DC81C20E67C8 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/17] ch_monitor: fix indentation in ch_monitor.c Date: Thu, 2 Dec 2021 22:56:06 +0000 Message-Id: <20211202225614.1118066-10-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSaE015594 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485806044100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/ch/ch_monitor.c | 301 +++++++++++++++++++++++--------------------- 1 file changed, 161 insertions(+), 140 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 12c10da874..68fa5b30aa 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -42,7 +42,8 @@ VIR_LOG_INIT("ch.ch_monitor"); static virClass *virCHMonitorClass; static void virCHMonitorDispose(void *obj); =20 -static int virCHMonitorOnceInit(void) +static int +virCHMonitorOnceInit(void) { if (!VIR_CLASS_NEW(virCHMonitor, virClassForObjectLockable())) return -1; @@ -52,11 +53,11 @@ static int virCHMonitorOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(virCHMonitor); =20 -int virCHMonitorShutdownVMM(virCHMonitor *mon); -int virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint); +int virCHMonitorShutdownVMM(virCHMonitor * mon); +int virCHMonitorPutNoContent(virCHMonitor * mon, const char *endpoint); =20 static int -virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef) +virCHMonitorBuildCPUJson(virJSONValue * content, virDomainDef * vmdef) { g_autoptr(virJSONValue) cpus =3D NULL; unsigned int maxvcpus =3D 0; @@ -64,7 +65,7 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomain= Def *vmdef) virDomainVcpuDef *vcpu; size_t i; =20 - /* count maximum allowed number vcpus and enabled vcpus when boot.*/ + /* count maximum allowed number vcpus and enabled vcpus when boot. */ maxvcpus =3D virDomainDefGetVcpusMax(vmdef); for (i =3D 0; i < maxvcpus; i++) { vcpu =3D virDomainDefGetVcpu(vmdef, i); @@ -76,7 +77,8 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomain= Def *vmdef) cpus =3D virJSONValueNewObject(); if (virJSONValueObjectAppendNumberInt(cpus, "boot_vcpus", nvcpus) = < 0) return -1; - if (virJSONValueObjectAppendNumberInt(cpus, "max_vcpus", vmdef->ma= xvcpus) < 0) + if (virJSONValueObjectAppendNumberInt + (cpus, "max_vcpus", vmdef->maxvcpus) < 0) return -1; if (virJSONValueObjectAppend(content, "cpus", &cpus) < 0) return -1; @@ -86,7 +88,7 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomain= Def *vmdef) } =20 static int -virCHMonitorBuildPTYJson(virJSONValue *content, virDomainDef *vmdef) +virCHMonitorBuildPTYJson(virJSONValue * content, virDomainDef * vmdef) { if (vmdef->nconsoles) { g_autoptr(virJSONValue) pty =3D virJSONValueNewObject(); @@ -108,7 +110,7 @@ virCHMonitorBuildPTYJson(virJSONValue *content, virDoma= inDef *vmdef) } =20 static int -virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vm= def) +virCHMonitorBuildKernelRelatedJson(virJSONValue * content, virDomainDef * = vmdef) { g_autoptr(virJSONValue) kernel =3D virJSONValueNewObject(); g_autoptr(virJSONValue) cmdline =3D virJSONValueNewObject(); @@ -119,21 +121,24 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *cont= ent, virDomainDef *vmdef) _("Kernel image path in this domain is not defined"= )); return -1; } else { - if (virJSONValueObjectAppendString(kernel, "path", vmdef->os.kerne= l) < 0) + if (virJSONValueObjectAppendString(kernel, "path", vmdef->os.kerne= l) < + 0) return -1; if (virJSONValueObjectAppend(content, "kernel", &kernel) < 0) return -1; } =20 if (vmdef->os.cmdline) { - if (virJSONValueObjectAppendString(cmdline, "args", vmdef->os.cmdl= ine) < 0) + if (virJSONValueObjectAppendString(cmdline, "args", vmdef->os.cmdl= ine) < + 0) return -1; if (virJSONValueObjectAppend(content, "cmdline", &cmdline) < 0) return -1; } =20 if (vmdef->os.initrd !=3D NULL) { - if (virJSONValueObjectAppendString(initramfs, "path", vmdef->os.in= itrd) < 0) + if (virJSONValueObjectAppendString(initramfs, "path", vmdef->os.in= itrd) + < 0) return -1; if (virJSONValueObjectAppend(content, "initramfs", &initramfs) < 0) return -1; @@ -143,14 +148,16 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *cont= ent, virDomainDef *vmdef) } =20 static int -virCHMonitorBuildMemoryJson(virJSONValue *content, virDomainDef *vmdef) +virCHMonitorBuildMemoryJson(virJSONValue * content, virDomainDef * vmdef) { - unsigned long long total_memory =3D virDomainDefGetMemoryInitial(vmdef= ) * 1024; + unsigned long long total_memory =3D + virDomainDefGetMemoryInitial(vmdef) * 1024; =20 if (total_memory !=3D 0) { g_autoptr(virJSONValue) memory =3D virJSONValueNewObject(); =20 - if (virJSONValueObjectAppendNumberUlong(memory, "size", total_memo= ry) < 0) + if (virJSONValueObjectAppendNumberUlong(memory, "size", total_memo= ry) < + 0) return -1; =20 if (virJSONValueObjectAppend(content, "memory", &memory) < 0) @@ -161,7 +168,7 @@ virCHMonitorBuildMemoryJson(virJSONValue *content, virD= omainDef *vmdef) } =20 static int -virCHMonitorBuildDiskJson(virJSONValue *disks, virDomainDiskDef *diskdef) +virCHMonitorBuildDiskJson(virJSONValue * disks, virDomainDiskDef * diskdef) { g_autoptr(virJSONValue) disk =3D virJSONValueNewObject(); =20 @@ -169,44 +176,47 @@ virCHMonitorBuildDiskJson(virJSONValue *disks, virDom= ainDiskDef *diskdef) return -1; =20 switch (diskdef->src->type) { - case VIR_STORAGE_TYPE_FILE: - if (!diskdef->src->path) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Missing disk file path in domain")); - return -1; - } - if (diskdef->bus !=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { - virReportError(VIR_ERR_INVALID_ARG, - _("Only virtio bus types are supported for '%s'= "), diskdef->src->path); - return -1; - } - if (virJSONValueObjectAppendString(disk, "path", diskdef->src->pat= h) < 0) - return -1; - if (diskdef->src->readonly) { - if (virJSONValueObjectAppendBoolean(disk, "readonly", true) < = 0) + case VIR_STORAGE_TYPE_FILE: + if (!diskdef->src->path) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Missing disk file path in domain")); + return -1; + } + if (diskdef->bus !=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { + virReportError(VIR_ERR_INVALID_ARG, + _ + ("Only virtio bus types are supported for '= %s'"), + diskdef->src->path); + return -1; + } + if (virJSONValueObjectAppendString(disk, "path", diskdef->src-= >path) + < 0) + return -1; + if (diskdef->src->readonly) { + if (virJSONValueObjectAppendBoolean(disk, "readonly", true= ) < 0) + return -1; + } + if (virJSONValueArrayAppend(disks, &disk) < 0) return -1; - } - if (virJSONValueArrayAppend(disks, &disk) < 0) - return -1; =20 - break; - case VIR_STORAGE_TYPE_NONE: - case VIR_STORAGE_TYPE_BLOCK: - case VIR_STORAGE_TYPE_DIR: - case VIR_STORAGE_TYPE_NETWORK: - case VIR_STORAGE_TYPE_VOLUME: - case VIR_STORAGE_TYPE_NVME: - case VIR_STORAGE_TYPE_VHOST_USER: - default: - virReportEnumRangeError(virStorageType, diskdef->src->type); - return -1; + break; + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_NETWORK: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: + case VIR_STORAGE_TYPE_VHOST_USER: + default: + virReportEnumRangeError(virStorageType, diskdef->src->type); + return -1; } =20 return 0; } =20 static int -virCHMonitorBuildDisksJson(virJSONValue *content, virDomainDef *vmdef) +virCHMonitorBuildDisksJson(virJSONValue * content, virDomainDef * vmdef) { g_autoptr(virJSONValue) disks =3D NULL; size_t i; @@ -226,76 +236,86 @@ virCHMonitorBuildDisksJson(virJSONValue *content, vir= DomainDef *vmdef) } =20 static int -virCHMonitorBuildNetJson(virJSONValue *nets, virDomainNetDef *netdef) +virCHMonitorBuildNetJson(virJSONValue * nets, virDomainNetDef * netdef) { virDomainNetType netType =3D virDomainNetGetActualType(netdef); char macaddr[VIR_MAC_STRING_BUFLEN]; + g_autoptr(virJSONValue) net =3D NULL; =20 // check net type at first net =3D virJSONValueNewObject(); =20 switch (netType) { - case VIR_DOMAIN_NET_TYPE_ETHERNET: - if (netdef->guestIP.nips =3D=3D 1) { - const virNetDevIPAddr *ip =3D netdef->guestIP.ips[0]; - g_autofree char *addr =3D NULL; - virSocketAddr netmask; - g_autofree char *netmaskStr =3D NULL; - if (!(addr =3D virSocketAddrFormat(&ip->address))) - return -1; - if (virJSONValueObjectAppendString(net, "ip", addr) < 0) - return -1; - - if (virSocketAddrPrefixToNetmask(ip->prefix, &netmask, AF_INET= ) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to translate net prefix %d to net= mask"), - ip->prefix); - return -1; + case VIR_DOMAIN_NET_TYPE_ETHERNET: + if (netdef->guestIP.nips =3D=3D 1) { + const virNetDevIPAddr *ip =3D netdef->guestIP.ips[0]; + g_autofree char *addr =3D NULL; + virSocketAddr netmask; + g_autofree char *netmaskStr =3D NULL; + + if (!(addr =3D virSocketAddrFormat(&ip->address))) + return -1; + if (virJSONValueObjectAppendString(net, "ip", addr) < 0) + return -1; + + if (virSocketAddrPrefixToNetmask(ip->prefix, &netmask, AF_= INET) + < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _ + ("Failed to translate net prefix %d to = netmask"), + ip->prefix); + return -1; + } + if (!(netmaskStr =3D virSocketAddrFormat(&netmask))) + return -1; + if (virJSONValueObjectAppendString(net, "mask", netmaskStr= ) < 0) + return -1; + } else if (netdef->guestIP.nips > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("ethernet type supports a single guest ip= ")); } - if (!(netmaskStr =3D virSocketAddrFormat(&netmask))) - return -1; - if (virJSONValueObjectAppendString(net, "mask", netmaskStr) < = 0) + break; + case VIR_DOMAIN_NET_TYPE_VHOSTUSER: + if ((virDomainChrType) netdef->data.vhostuser->type !=3D + VIR_DOMAIN_CHR_TYPE_UNIX) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _ + ("vhost_user type support UNIX socket in th= is CH")); return -1; - } else if (netdef->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("ethernet type supports a single guest ip")); - } - break; - case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - if ((virDomainChrType)netdef->data.vhostuser->type !=3D VIR_DOMAIN= _CHR_TYPE_UNIX) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("vhost_user type support UNIX socket in this = CH")); + } else { + if (virJSONValueObjectAppendString + (net, "vhost_socket", + netdef->data.vhostuser->data.nix.path) < 0) + return -1; + if (virJSONValueObjectAppendBoolean(net, "vhost_user", tru= e) < + 0) + return -1; + } + break; + case VIR_DOMAIN_NET_TYPE_BRIDGE: + case VIR_DOMAIN_NET_TYPE_NETWORK: + case VIR_DOMAIN_NET_TYPE_DIRECT: + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_SERVER: + case VIR_DOMAIN_NET_TYPE_CLIENT: + case VIR_DOMAIN_NET_TYPE_MCAST: + case VIR_DOMAIN_NET_TYPE_INTERNAL: + case VIR_DOMAIN_NET_TYPE_HOSTDEV: + case VIR_DOMAIN_NET_TYPE_UDP: + case VIR_DOMAIN_NET_TYPE_VDPA: + case VIR_DOMAIN_NET_TYPE_LAST: + default: + virReportEnumRangeError(virDomainNetType, netType); return -1; - } else { - if (virJSONValueObjectAppendString(net, "vhost_socket", netdef= ->data.vhostuser->data.nix.path) < 0) - return -1; - if (virJSONValueObjectAppendBoolean(net, "vhost_user", true) <= 0) - return -1; - } - break; - case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_NETWORK: - case VIR_DOMAIN_NET_TYPE_DIRECT: - case VIR_DOMAIN_NET_TYPE_USER: - case VIR_DOMAIN_NET_TYPE_SERVER: - case VIR_DOMAIN_NET_TYPE_CLIENT: - case VIR_DOMAIN_NET_TYPE_MCAST: - case VIR_DOMAIN_NET_TYPE_INTERNAL: - case VIR_DOMAIN_NET_TYPE_HOSTDEV: - case VIR_DOMAIN_NET_TYPE_UDP: - case VIR_DOMAIN_NET_TYPE_VDPA: - case VIR_DOMAIN_NET_TYPE_LAST: - default: - virReportEnumRangeError(virDomainNetType, netType); - return -1; } =20 if (netdef->ifname !=3D NULL) { if (virJSONValueObjectAppendString(net, "tap", netdef->ifname) < 0) return -1; } - if (virJSONValueObjectAppendString(net, "mac", virMacAddrFormat(&netde= f->mac, macaddr)) < 0) + if (virJSONValueObjectAppendString + (net, "mac", virMacAddrFormat(&netdef->mac, macaddr)) < 0) return -1; =20 =20 @@ -306,19 +326,24 @@ virCHMonitorBuildNetJson(virJSONValue *nets, virDomai= nNetDef *netdef) } } if (netdef->driver.virtio.queues) { - if (virJSONValueObjectAppendNumberInt(net, "num_queues", netdef->d= river.virtio.queues) < 0) + if (virJSONValueObjectAppendNumberInt + (net, "num_queues", netdef->driver.virtio.queues) < 0) return -1; } =20 - if (netdef->driver.virtio.rx_queue_size || netdef->driver.virtio.tx_qu= eue_size) { - if (netdef->driver.virtio.rx_queue_size !=3D netdef->driver.virtio= .tx_queue_size) { + if (netdef->driver.virtio.rx_queue_size + || netdef->driver.virtio.tx_queue_size) { + if (netdef->driver.virtio.rx_queue_size !=3D + netdef->driver.virtio.tx_queue_size) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("virtio rx_queue_size option %d is not same with tx_queue= _size %d"), - netdef->driver.virtio.rx_queue_size, - netdef->driver.virtio.tx_queue_size); + _ + ("virtio rx_queue_size option %d is not same wi= th tx_queue_size %d"), + netdef->driver.virtio.rx_queue_size, + netdef->driver.virtio.tx_queue_size); return -1; } - if (virJSONValueObjectAppendNumberInt(net, "queue_size", netdef->d= river.virtio.rx_queue_size) < 0) + if (virJSONValueObjectAppendNumberInt + (net, "queue_size", netdef->driver.virtio.rx_queue_size) < 0) return -1; } =20 @@ -329,7 +354,7 @@ virCHMonitorBuildNetJson(virJSONValue *nets, virDomainN= etDef *netdef) } =20 static int -virCHMonitorBuildNetsJson(virJSONValue *content, virDomainDef *vmdef) +virCHMonitorBuildNetsJson(virJSONValue * content, virDomainDef * vmdef) { g_autoptr(virJSONValue) nets =3D NULL; size_t i; @@ -349,13 +374,12 @@ virCHMonitorBuildNetsJson(virJSONValue *content, virD= omainDef *vmdef) } =20 static int -virCHMonitorBuildVMJson(virDomainDef *vmdef, char **jsonstr) +virCHMonitorBuildVMJson(virDomainDef * vmdef, char **jsonstr) { g_autoptr(virJSONValue) content =3D virJSONValueNewObject(); =20 if (vmdef =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("VM is not defined")); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("VM is not defined"= )); return -1; } =20 @@ -391,8 +415,7 @@ chMonitorCreateSocket(const char *socket_path) int fd; =20 if ((fd =3D socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create UNIX socket")); + virReportSystemError(errno, "%s", _("Unable to create UNIX socket"= )); goto error; } =20 @@ -400,19 +423,16 @@ chMonitorCreateSocket(const char *socket_path) addr.sun_family =3D AF_UNIX; if (virStrcpyStatic(addr.sun_path, socket_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("UNIX socket path '%s' too long"), - socket_path); + _("UNIX socket path '%s' too long"), socket_path); goto error; } =20 if (unlink(socket_path) < 0 && errno !=3D ENOENT) { - virReportSystemError(errno, - _("Unable to unlink %s"), - socket_path); + virReportSystemError(errno, _("Unable to unlink %s"), socket_path); goto error; } =20 - if (bind(fd, (struct sockaddr *)&addr, addrlen) < 0) { + if (bind(fd, (struct sockaddr *) &addr, addrlen) < 0) { virReportSystemError(errno, _("Unable to bind to UNIX socket path '%s'"), socket_path); @@ -440,7 +460,7 @@ chMonitorCreateSocket(const char *socket_path) } =20 virCHMonitor * -virCHMonitorNew(virDomainObj *vm, const char *socketdir) +virCHMonitorNew(virDomainObj * vm, const char *socketdir) { g_autoptr(virCHMonitor) mon =3D NULL; g_autoptr(virCommand) cmd =3D NULL; @@ -453,8 +473,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) return NULL; =20 if (!vm->def) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("VM is not defined")); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("VM is not defined"= )); return NULL; } =20 @@ -472,8 +491,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) socket_fd =3D chMonitorCreateSocket(mon->socketpath); if (socket_fd < 0) { virReportSystemError(errno, - _("Cannot create socket '%s'"), - mon->socketpath); + _("Cannot create socket '%s'"), mon->socketpa= th); return NULL; } =20 @@ -494,7 +512,8 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) return g_steal_pointer(&mon); } =20 -static void virCHMonitorDispose(void *opaque) +static void +virCHMonitorDispose(void *opaque) { virCHMonitor *mon =3D opaque; =20 @@ -502,7 +521,8 @@ static void virCHMonitorDispose(void *opaque) virObjectUnref(mon->vm); } =20 -void virCHMonitorClose(virCHMonitor *mon) +void +virCHMonitorClose(virCHMonitor * mon) { if (!mon) return; @@ -518,8 +538,7 @@ void virCHMonitorClose(virCHMonitor *mon) =20 if (mon->socketpath) { if (virFileRemove(mon->socketpath, -1, -1) < 0) { - VIR_WARN("Unable to remove CH socket file '%s'", - mon->socketpath); + VIR_WARN("Unable to remove CH socket file '%s'", mon->socketpa= th); } g_free(mon->socketpath); } @@ -528,7 +547,7 @@ void virCHMonitorClose(virCHMonitor *mon) } =20 static int -virCHMonitorCurlPerform(CURL *handle) +virCHMonitorCurlPerform(CURL * handle) { CURLcode errorCode; long responseCode =3D 0; @@ -547,8 +566,9 @@ virCHMonitorCurlPerform(CURL *handle) =20 if (errorCode !=3D CURLE_OK) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) return= ed an " - "error: %s (%d)"), curl_easy_strerror(errorCode), + _ + ("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returne= d an " + "error: %s (%d)"), curl_easy_strerror(errorCode), errorCode); return -1; } @@ -564,7 +584,7 @@ virCHMonitorCurlPerform(CURL *handle) } =20 int -virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint) +virCHMonitorPutNoContent(virCHMonitor * mon, const char *endpoint) { g_autofree char *url =3D NULL; int responseCode =3D 0; @@ -615,13 +635,14 @@ curl_callback(void *contents, size_t size, size_t nme= mb, void *userp) } =20 static int -virCHMonitorGet(virCHMonitor *mon, const char *endpoint, virJSONValue **re= sponse) +virCHMonitorGet(virCHMonitor * mon, const char *endpoint, + virJSONValue ** response) { g_autofree char *url =3D NULL; int responseCode =3D 0; int ret =3D -1; struct curl_slist *headers =3D NULL; - struct curl_data data =3D {0}; + struct curl_data data =3D { 0 }; =20 url =3D g_strdup_printf("%s/%s", URL_ROOT, endpoint); =20 @@ -638,7 +659,7 @@ virCHMonitorGet(virCHMonitor *mon, const char *endpoint= , virJSONValue **response headers =3D curl_slist_append(headers, "Content-Type: application/= json"); curl_easy_setopt(mon->handle, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(mon->handle, CURLOPT_WRITEFUNCTION, curl_callback= ); - curl_easy_setopt(mon->handle, CURLOPT_WRITEDATA, (void *)&data); + curl_easy_setopt(mon->handle, CURLOPT_WRITEDATA, (void *) &data); } =20 responseCode =3D virCHMonitorCurlPerform(mon->handle); @@ -665,13 +686,13 @@ virCHMonitorGet(virCHMonitor *mon, const char *endpoi= nt, virJSONValue **response } =20 int -virCHMonitorShutdownVMM(virCHMonitor *mon) +virCHMonitorShutdownVMM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VMM_SHUTDOWN); } =20 int -virCHMonitorCreateVM(virCHMonitor *mon) +virCHMonitorCreateVM(virCHMonitor * mon) { g_autofree char *url =3D NULL; int responseCode =3D 0; @@ -709,31 +730,31 @@ virCHMonitorCreateVM(virCHMonitor *mon) } =20 int -virCHMonitorBootVM(virCHMonitor *mon) +virCHMonitorBootVM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VM_BOOT); } =20 int -virCHMonitorShutdownVM(virCHMonitor *mon) +virCHMonitorShutdownVM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VM_SHUTDOWN); } =20 int -virCHMonitorRebootVM(virCHMonitor *mon) +virCHMonitorRebootVM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VM_REBOOT); } =20 int -virCHMonitorSuspendVM(virCHMonitor *mon) +virCHMonitorSuspendVM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VM_Suspend); } =20 int -virCHMonitorResumeVM(virCHMonitor *mon) +virCHMonitorResumeVM(virCHMonitor * mon) { return virCHMonitorPutNoContent(mon, URL_VM_RESUME); } @@ -748,7 +769,7 @@ virCHMonitorResumeVM(virCHMonitor *mon) * Returns 0 on success. */ int -virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info) +virCHMonitorGetInfo(virCHMonitor * mon, virJSONValue ** info) { return virCHMonitorGet(mon, URL_VM_INFO, info); } --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485833696946.4525878274312; Thu, 2 Dec 2021 14:57:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-548-N3bFI0FSMW6dWkJ_4C6QgQ-1; Thu, 02 Dec 2021 17:57:10 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2DB51023F4D; Thu, 2 Dec 2021 22:57:05 +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 A175D1972D; Thu, 2 Dec 2021 22:57:05 +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 70B43180C667; Thu, 2 Dec 2021 22:57:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuVXQ015659 for ; Thu, 2 Dec 2021 17:56:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 01C0E2026D60; Thu, 2 Dec 2021 22:56:31 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F092A2026D4D for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 026A385A5AA for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-364-FcWFrKA3P9KUiKxNpwUF_w-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id F2A5320E6932; Thu, 2 Dec 2021 14:56:24 -0800 (PST) X-MC-Unique: N3bFI0FSMW6dWkJ_4C6QgQ-1 X-MC-Unique: FcWFrKA3P9KUiKxNpwUF_w-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com F2A5320E6932 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/17] ch_monitor: Get nicindexes in prep for cgroup mgmt Date: Thu, 2 Dec 2021 22:56:07 +0000 Message-Id: <20211202225614.1118066-11-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuVXQ015659 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485834812100005 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_conf.h | 2 ++ src/ch/ch_domain.c | 27 +++++++++++++- src/ch/ch_domain.h | 4 +-- src/ch/ch_driver.c | 1 + src/ch/ch_monitor.c | 86 +++++++++++++++++++++++++++++++++++++++++---- src/ch/ch_monitor.h | 14 +++++++- src/ch/ch_process.c | 6 +++- src/ch/meson.build | 1 + 8 files changed, 129 insertions(+), 12 deletions(-) diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h index 37c36d9a09..8fe69c8545 100644 --- a/src/ch/ch_conf.h +++ b/src/ch/ch_conf.h @@ -44,6 +44,8 @@ struct _virCHDriver { virMutex lock; =20 + bool privileged; + /* Require lock to get a reference on the object, * lockless access thereafter */ virCaps *caps; diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index d81221679e..326c3802c3 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -21,10 +21,12 @@ #include =20 #include "ch_domain.h" +#include "domain_driver.h" #include "viralloc.h" #include "virchrdev.h" #include "virlog.h" #include "virtime.h" +#include "virsystemd.h" =20 #define VIR_FROM_THIS VIR_FROM_CH =20 @@ -129,7 +131,7 @@ virCHDomainObjEndJob(virDomainObj * obj) } =20 static void * -virCHDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED) +virCHDomainObjPrivateAlloc(void *opaque) { virCHDomainObjPrivate *priv; =20 @@ -145,6 +147,7 @@ virCHDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED) g_free(priv); return NULL; } + priv->driver =3D opaque; =20 return priv; } @@ -359,3 +362,25 @@ virCHDomainHasVcpuPids(virDomainObj * vm) =20 return false; } + +char * +virCHDomainGetMachineName(virDomainObj * vm) +{ + virCHDomainObjPrivate *priv =3D CH_DOMAIN_PRIVATE(vm); + virCHDriver *driver =3D priv->driver; + char *ret =3D NULL; + + if (vm->pid > 0) { + ret =3D virSystemdGetMachineNameByPID(vm->pid); + if (!ret) + virResetLastError(); + } + + if (!ret) + ret =3D virDomainDriverGenerateMachineName("ch", + NULL, + vm->def->id, vm->def->nam= e, + driver->privileged); + + return ret; +} diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index e35777a9ec..3ac3421015 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -54,9 +54,7 @@ struct _virCHDomainObjPrivate { struct virCHDomainJobObj job; =20 virChrdevs *chrdevs; - virCgroup *cgroup; - virCHDriver *driver; virCHMonitor *monitor; char *machineName; @@ -94,3 +92,5 @@ virCHDomainObjEndJob(virDomainObj *obj); int virCHDomainRefreshVcpuInfo(virDomainObj *vm); pid_t virCHDomainGetVcpuPid(virDomainObj *vm, unsigned int vcpuid); bool virCHDomainHasVcpuPids(virDomainObj *vm); + +char *virCHDomainGetMachineName(virDomainObj *vm); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 86d2776354..39e754d1ff 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -936,6 +936,7 @@ chStateInitialize(bool privileged, goto cleanup; } =20 + ch_driver->privileged =3D privileged; ret =3D VIR_DRV_STATE_INIT_COMPLETE; =20 cleanup: diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 68fa5b30aa..6bc7d035ad 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -236,7 +236,8 @@ virCHMonitorBuildDisksJson(virJSONValue * content, virD= omainDef * vmdef) } =20 static int -virCHMonitorBuildNetJson(virJSONValue * nets, virDomainNetDef * netdef) +virCHMonitorBuildNetJson(virJSONValue * nets, virDomainNetDef * netdef, + size_t *nnicindexes, int **nicindexes) { virDomainNetType netType =3D virDomainNetGetActualType(netdef); char macaddr[VIR_MAC_STRING_BUFLEN]; @@ -275,6 +276,18 @@ virCHMonitorBuildNetJson(virJSONValue * nets, virDomai= nNetDef * netdef) virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("ethernet type supports a single guest ip= ")); } + /* network and bridge use a tap device, and direct uses a + * macvtap device + */ + if (nicindexes && nnicindexes && netdef->ifname) { + int nicindex =3D 0; + + if (virNetDevGetIndex(netdef->ifname, &nicindex) < 0) + return -1; + + VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex); + } + break; case VIR_DOMAIN_NET_TYPE_VHOSTUSER: if ((virDomainChrType) netdef->data.vhostuser->type !=3D @@ -354,7 +367,8 @@ virCHMonitorBuildNetJson(virJSONValue * nets, virDomain= NetDef * netdef) } =20 static int -virCHMonitorBuildNetsJson(virJSONValue * content, virDomainDef * vmdef) +virCHMonitorBuildNetsJson(virJSONValue * content, virDomainDef * vmdef, + size_t *nnicindexes, int **nicindexes) { g_autoptr(virJSONValue) nets =3D NULL; size_t i; @@ -363,7 +377,8 @@ virCHMonitorBuildNetsJson(virJSONValue * content, virDo= mainDef * vmdef) nets =3D virJSONValueNewArray(); =20 for (i =3D 0; i < vmdef->nnets; i++) { - if (virCHMonitorBuildNetJson(nets, vmdef->nets[i]) < 0) + if (virCHMonitorBuildNetJson(nets, vmdef->nets[i], + nnicindexes, nicindexes) < 0) return -1; } if (virJSONValueObjectAppend(content, "net", &nets) < 0) @@ -374,7 +389,59 @@ virCHMonitorBuildNetsJson(virJSONValue * content, virD= omainDef * vmdef) } =20 static int -virCHMonitorBuildVMJson(virDomainDef * vmdef, char **jsonstr) +virCHMonitorBuildDeviceJson(virJSONValue * devices, + virDomainHostdevDef * hostdevdef) +{ + g_autoptr(virJSONValue) device =3D NULL; + + + if (hostdevdef->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdevdef->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TY= PE_PCI) { + g_autofree char *name =3D NULL; + g_autofree char *path =3D NULL; + virDomainHostdevSubsysPCI *pcisrc =3D &hostdevdef->source.subsys.u= .pci; + + device =3D virJSONValueNewObject(); + name =3D virPCIDeviceAddressAsString(&pcisrc->addr); + path =3D g_strdup_printf("/sys/bus/pci/devices/%s/", name); + if (!virFileExists(path)) { + virReportError(VIR_ERR_DEVICE_MISSING, + _("host pci device %s not found"), path); + return -1; + } + if (virJSONValueObjectAppendString(device, "path", path) < 0) + return -1; + if (virJSONValueArrayAppend(devices, &device) < 0) + return -1; + } + + return 0; +} + +static int +virCHMonitorBuildDevicesJson(virJSONValue * content, virDomainDef * vmdef) +{ + size_t i; + + g_autoptr(virJSONValue) devices =3D NULL; + + if (vmdef->nhostdevs =3D=3D 0) + return 0; + + devices =3D virJSONValueNewArray(); + for (i =3D 0; i < vmdef->nhostdevs; i++) { + if (virCHMonitorBuildDeviceJson(devices, vmdef->hostdevs[i]) < 0) + return -1; + } + if (virJSONValueObjectAppend(content, "devices", &devices) < 0) + return -1; + + return 0; +} + +static int +virCHMonitorBuildVMJson(virDomainDef * vmdef, char **jsonstr, + size_t *nnicindexes, int **nicindexes) { g_autoptr(virJSONValue) content =3D virJSONValueNewObject(); =20 @@ -398,7 +465,11 @@ virCHMonitorBuildVMJson(virDomainDef * vmdef, char **j= sonstr) if (virCHMonitorBuildDisksJson(content, vmdef) < 0) return -1; =20 - if (virCHMonitorBuildNetsJson(content, vmdef) < 0) + + if (virCHMonitorBuildNetsJson(content, vmdef, nnicindexes, nicindexes)= < 0) + return -1; + + if (virCHMonitorBuildDevicesJson(content, vmdef) < 0) return -1; =20 if (!(*jsonstr =3D virJSONValueToString(content, false))) @@ -692,7 +763,7 @@ virCHMonitorShutdownVMM(virCHMonitor * mon) } =20 int -virCHMonitorCreateVM(virCHMonitor * mon) +virCHMonitorCreateVM(virCHMonitor * mon, size_t *nnicindexes, int **nicind= exes) { g_autofree char *url =3D NULL; int responseCode =3D 0; @@ -704,7 +775,8 @@ virCHMonitorCreateVM(virCHMonitor * mon) headers =3D curl_slist_append(headers, "Accept: application/json"); headers =3D curl_slist_append(headers, "Content-Type: application/json= "); =20 - if (virCHMonitorBuildVMJson(mon->vm->def, &payload) !=3D 0) + if (virCHMonitorBuildVMJson(mon->vm->def, &payload, + nnicindexes, nicindexes) !=3D 0) return -1; =20 virObjectLock(mon); diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 0f684ca583..8ca9e17a9a 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -55,10 +55,22 @@ virCHMonitor *virCHMonitorNew(virDomainObj *vm, const c= har *socketdir); void virCHMonitorClose(virCHMonitor *mon); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose); =20 -int virCHMonitorCreateVM(virCHMonitor *mon); + +int virCHMonitorCreateVM(virCHMonitor *mon, + size_t *nnicindexes, int **nicindexes); int virCHMonitorBootVM(virCHMonitor *mon); int virCHMonitorShutdownVM(virCHMonitor *mon); int virCHMonitorRebootVM(virCHMonitor *mon); int virCHMonitorSuspendVM(virCHMonitor *mon); int virCHMonitorResumeVM(virCHMonitor *mon); int virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info); + +typedef struct _virCHMonitorCPUInfo virCHMonitorCPUInfo; +struct _virCHMonitorCPUInfo { + pid_t tid; + bool online; +}; +void virCHMonitorCPUInfoFree(virCHMonitorCPUInfo *cpus); +int virCHMonitorGetCPUInfo(virCHMonitor *mon, + virCHMonitorCPUInfo **vcpus, + size_t maxvcpus); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 1a01ca9384..3b7f6fcddf 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -149,6 +149,8 @@ int virCHProcessStart(virCHDriver *driver, { int ret =3D -1; virCHDomainObjPrivate *priv =3D vm->privateData; + g_autofree int *nicindexes =3D NULL; + size_t nnicindexes =3D 0; =20 if (!priv->monitor) { /* And we can get the first monitor connection now too */ @@ -158,7 +160,8 @@ int virCHProcessStart(virCHDriver *driver, goto cleanup; } =20 - if (virCHMonitorCreateVM(priv->monitor) < 0) { + if (virCHMonitorCreateVM(priv->monitor, + &nnicindexes, &nicindexes) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create guest VM")); goto cleanup; @@ -171,6 +174,7 @@ int virCHProcessStart(virCHDriver *driver, goto cleanup; } =20 + priv->machineName =3D virCHDomainGetMachineName(vm); vm->pid =3D priv->monitor->pid; vm->def->id =3D vm->pid; =20 diff --git a/src/ch/meson.build b/src/ch/meson.build index e34974d56c..e0afdb390a 100644 --- a/src/ch/meson.build +++ b/src/ch/meson.build @@ -29,6 +29,7 @@ if conf.has('WITH_CH') ], include_directories: [ conf_inc_dir, + hypervisor_inc_dir, ], ) =20 --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485838956754.4357929393498; Thu, 2 Dec 2021 14:57:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-10-R0oviqMfPTCrBbRZdtt42Q-1; Thu, 02 Dec 2021 17:57:16 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 713401018721; Thu, 2 Dec 2021 22:57:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BB385D9D5; Thu, 2 Dec 2021 22:57:10 +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 E01894A707; Thu, 2 Dec 2021 22:57:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSIx015599 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3DAD5404727A; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36DB24047272 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1673F100E658 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-181-B_Zw7LcbPR2vhONyJP1Ayw-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 17F5E20E6938; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: R0oviqMfPTCrBbRZdtt42Q-1 X-MC-Unique: B_Zw7LcbPR2vhONyJP1Ayw-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 17F5E20E6938 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/17] qemu, hypervisor: refactor some cgroup mgmt methods Date: Thu, 2 Dec 2021 22:56:08 +0000 Message-Id: <20211202225614.1118066-12-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSIx015599 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485839270100003 Content-Type: text/plain; charset="utf-8" Refactor some cgroup management methods from qemu into hypervisor. These methods will be shared by ch driver for cgroup management. Signed-off-by: Praveen K Paladugu --- src/hypervisor/domain_cgroup.c | 426 ++++++++++++++++++++++++++++++++- src/hypervisor/domain_cgroup.h | 52 ++++ src/libvirt_private.syms | 10 + src/qemu/qemu_cgroup.c | 410 +------------------------------ src/qemu/qemu_cgroup.h | 11 - src/qemu/qemu_driver.c | 14 +- src/qemu/qemu_hotplug.c | 4 +- src/qemu/qemu_process.c | 17 +- 8 files changed, 515 insertions(+), 429 deletions(-) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index 61b54f071c..eda46e3421 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -22,11 +22,12 @@ =20 #include "domain_cgroup.h" #include "domain_driver.h" - +#include "util/virnuma.h" +#include "virlog.h" #include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN - +VIR_LOG_INIT("domain.cgroup"); =20 int virDomainCgroupSetupBlkio(virCgroup *cgroup, virDomainBlkiotune blkio) @@ -269,3 +270,424 @@ virDomainCgroupSetMemoryLimitParameters(virCgroup *cg= roup, =20 return 0; } + + +int +virSetupBlkioCgroup(virDomainObj * vm, virCgroup * cgroup) +{ + + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { + if (vm->def->blkio.weight || vm->def->blkio.ndevices) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Block I/O tuning is not available on this ho= st")); + return -1; + } else { + return 0; + } + } + + return virDomainCgroupSetupBlkio(cgroup, vm->def->blkio); +} + + +int +virSetupMemoryCgroup(virDomainObj * vm, virCgroup * cgroup) +{ + + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_MEMORY)) { + if (virMemoryLimitIsSet(vm->def->mem.hard_limit) || + virMemoryLimitIsSet(vm->def->mem.soft_limit) || + virMemoryLimitIsSet(vm->def->mem.swap_hard_limit)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Memory cgroup is not available on this host"= )); + return -1; + } else { + return 0; + } + } + + return virDomainCgroupSetupMemtune(cgroup, vm->def->mem); +} + + +int +virSetupCpusetCgroup(virCgroup * cgroup) +{ + + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) + return 0; + + if (virCgroupSetCpusetMemoryMigrate(cgroup, true) < 0) + return -1; + + return 0; +} + + +int +virSetupCpuCgroup(virDomainObj * vm, virCgroup * cgroup) +{ + + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPU)) { + if (vm->def->cputune.sharesSpecified) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("CPU tuning is not available on this host")); + return -1; + } else { + return 0; + } + } + + if (vm->def->cputune.sharesSpecified) { + + if (virCgroupSetCpuShares(cgroup, vm->def->cputune.shares) < 0) + return -1; + + } + + return 0; +} + + +int +virInitCgroup(const char *prefix, + virDomainObj * vm, + size_t nnicindexes, int *nicindexes, + virCgroup * cgroup, int cgroupControllers, + unsigned int maxThreadsPerProc, + bool privileged, char *machineName) +{ + if (!privileged) + return 0; + + if (!virCgroupAvailable()) + return 0; + + virCgroupFree(cgroup); + cgroup =3D NULL; + + if (!vm->def->resource) + vm->def->resource =3D g_new0(virDomainResourceDef, 1); + + if (!vm->def->resource->partition) + vm->def->resource->partition =3D g_strdup("/machine"); + + if (!g_path_is_absolute(vm->def->resource->partition)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Resource partition '%s' must start with '/'"), + vm->def->resource->partition); + return -1; + } + + if (virCgroupNewMachine(machineName, + prefix, + vm->def->uuid, + NULL, + vm->pid, + false, + nnicindexes, nicindexes, + vm->def->resource->partition, + cgroupControllers, + maxThreadsPerProc, &cgroup) < 0) { + if (virCgroupNewIgnoreError()) + return 0; + + return -1; + } + + return 0; +} + + +void +virRestoreCgroupState(virDomainObj * vm, virCgroup * cgroup) +{ + g_autofree char *mem_mask =3D NULL; + size_t i =3D 0; + + g_autoptr(virBitmap) all_nodes =3D NULL; + + if (!virNumaIsAvailable() || + !virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) + return; + + if (!(all_nodes =3D virNumaGetHostMemoryNodeset())) + goto error; + + if (!(mem_mask =3D virBitmapFormat(all_nodes))) + goto error; + + if (virCgroupHasEmptyTasks(cgroup, VIR_CGROUP_CONTROLLER_CPUSET) <=3D = 0) + goto error; + + if (virCgroupSetCpusetMems(cgroup, mem_mask) < 0) + goto error; + + for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, i); + + if (!vcpu->online) + continue; + + if (virRestoreCgroupThread(cgroup, VIR_CGROUP_THREAD_VCPU, i) < 0) + return; + } + + for (i =3D 0; i < vm->def->niothreadids; i++) { + if (virRestoreCgroupThread(cgroup, VIR_CGROUP_THREAD_IOTHREAD, + vm->def->iothreadids[i]->iothread_id) <= 0) + return; + } + + if (virRestoreCgroupThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0) < 0) + return; + + return; + + error: + virResetLastError(); + VIR_DEBUG("Couldn't restore cgroups to meaningful state"); + return; +} + + +int +virRestoreCgroupThread(virCgroup * cgroup, virCgroupThreadName thread, int= id) +{ + g_autoptr(virCgroup) cgroup_temp =3D NULL; + g_autofree char *nodeset =3D NULL; + + if (virCgroupNewThread(cgroup, thread, id, false, &cgroup_temp) < 0) + return -1; + + if (virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0) + return -1; + + if (virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0) + return -1; + + if (virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) + return -1; + + return 0; +} + + +int +virConnectCgroup(const char *prefix, virDomainObj * vm, virCgroup * cgroup, + int cgroupControllers, bool privileged, char *machineName) +{ + if (privileged) + return 0; + + if (!virCgroupAvailable()) + return 0; + + virCgroupFree(cgroup); + + if (virCgroupNewDetectMachine(vm->def->name, + prefix, + vm->pid, + cgroupControllers, machineName, &cgroup)= < 0) + return -1; + + virRestoreCgroupState(vm, cgroup); + return 0; +} + + +int +virSetupCgroup(const char *prefix, + virDomainObj * vm, + size_t nnicindexes, int *nicindexes, + virCgroup * cgroup, + int cgroupControllers, + unsigned int maxThreadsPerProc, + bool privileged, char *machineName) +{ + if (!vm->pid) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot setup cgroups until process is started")); + return -1; + } + + if (virInitCgroup(prefix, vm, nnicindexes, nicindexes, + cgroup, cgroupControllers, + maxThreadsPerProc, privileged, machineName) < 0) + return -1; + + if (!cgroup) + return 0; + + if (virSetupBlkioCgroup(vm, cgroup) < 0) + return -1; + + if (virSetupMemoryCgroup(vm, cgroup) < 0) + return -1; + + if (virSetupCpuCgroup(vm, cgroup) < 0) + return -1; + + if (virSetupCpusetCgroup(cgroup) < 0) + return -1; + + return 0; +} + + +int +virSetupCgroupVcpuBW(virCgroup * cgroup, + unsigned long long period, long long quota) +{ + return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); +} + + +int +virSetupCgroupCpusetCpus(virCgroup * cgroup, virBitmap * cpumask) +{ + return virCgroupSetupCpusetCpus(cgroup, cpumask); +} + + +int +virSetupGlobalCpuCgroup(virDomainObj * vm, virCgroup * cgroup, + virBitmap * autoNodeset) +{ + unsigned long long period =3D vm->def->cputune.global_period; + long long quota =3D vm->def->cputune.global_quota; + g_autofree char *mem_mask =3D NULL; + virDomainNumatuneMemMode mem_mode; + + if ((period || quota) && + !virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPU)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cgroup cpu is required for scheduler tuning")); + return -1; + } + + /* + * If CPU cgroup controller is not initialized here, then we need + * neither period nor quota settings. And if CPUSET controller is + * not initialized either, then there's nothing to do anyway. + */ + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPU) && + !virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) + return 0; + + + if (virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) =3D=3D 0 && + mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT && + virDomainNumatuneMaybeFormatNodeset(vm->def->numa, + autoNodeset, &mem_mask, -1) < = 0) + return -1; + + if (period || quota) { + if (virSetupCgroupVcpuBW(cgroup, period, quota) < 0) + return -1; + } + + return 0; +} + + +int +virRemoveCgroup(virDomainObj * vm, virCgroup * cgroup, char *machineName) +{ + if (cgroup =3D=3D NULL) + return 0; /* Not supported, so claim success */ + + if (virCgroupTerminateMachine(machineName) < 0) { + if (!virCgroupNewIgnoreError()) + VIR_DEBUG("Failed to terminate cgroup for %s", vm->def->name); + } + + return virCgroupRemove(cgroup); +} + + +void +virCgroupEmulatorAllNodesDataFree(virCgroupEmulatorAllNodesData * data) +{ + if (!data) + return; + + virCgroupFree(data->emulatorCgroup); + g_free(data->emulatorMemMask); + g_free(data); +} + + +/** + * virCgroupEmulatorAllNodesAllow: + * @cgroup: domain cgroup pointer + * @retData: filled with structure used to roll back the operation + * + * Allows all NUMA nodes for the cloud hypervisor thread temporarily. This= is + * necessary when hotplugging cpus since it requires memory allocated in t= he + * DMA region. Afterwards the operation can be reverted by + * virCgroupEmulatorAllNodesRestore. + * + * Returns 0 on success -1 on error + */ +int +virCgroupEmulatorAllNodesAllow(virCgroup * cgroup, + virCgroupEmulatorAllNodesData ** retData) +{ + virCgroupEmulatorAllNodesData *data =3D NULL; + g_autofree char *all_nodes_str =3D NULL; + + g_autoptr(virBitmap) all_nodes =3D NULL; + int ret =3D -1; + + if (!virNumaIsAvailable() || + !virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) + return 0; + + if (!(all_nodes =3D virNumaGetHostMemoryNodeset())) + goto cleanup; + + if (!(all_nodes_str =3D virBitmapFormat(all_nodes))) + goto cleanup; + + data =3D g_new0(virCgroupEmulatorAllNodesData, 1); + + if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, + false, &data->emulatorCgroup) < 0) + goto cleanup; + + if (virCgroupGetCpusetMems(data->emulatorCgroup, &data->emulatorMemMas= k) < 0 + || virCgroupSetCpusetMems(data->emulatorCgroup, all_nodes_str) < 0) + goto cleanup; + + *retData =3D g_steal_pointer(&data); + ret =3D 0; + + cleanup: + virCgroupEmulatorAllNodesDataFree(data); + + return ret; +} + + +/** + * virCgroupEmulatorAllNodesRestore: + * @data: data structure created by virCgroupEmulatorAllNodesAllow + * + * Rolls back the setting done by virCgroupEmulatorAllNodesAllow and frees= the + * associated data. + */ +void +virCgroupEmulatorAllNodesRestore(virCgroupEmulatorAllNodesData * data) +{ + virError *err; + + if (!data) + return; + + virErrorPreserveLast(&err); + virCgroupSetCpusetMems(data->emulatorCgroup, data->emulatorMemMask); + virErrorRestore(&err); + + virCgroupEmulatorAllNodesDataFree(data); +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index f93e5f74fe..fd8b74a4ee 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -23,6 +23,11 @@ #include "vircgroup.h" #include "domain_conf.h" =20 +typedef struct _virCgroupEmulatorAllNodesData virCgroupEmulatorAllNodesDat= a; +struct _virCgroupEmulatorAllNodesData { + virCgroup *emulatorCgroup; + char *emulatorMemMask; +}; =20 int virDomainCgroupSetupBlkio(virCgroup *cgroup, virDomainBlkiotune blkio); int virDomainCgroupSetupMemtune(virCgroup *cgroup, virDomainMemtune mem); @@ -36,3 +41,50 @@ int virDomainCgroupSetMemoryLimitParameters(virCgroup *c= group, virDomainDef *persistentDef, virTypedParameterPtr params, int nparams); +int +virSetupBlkioCgroup(virDomainObj * vm, virCgroup *cgroup); +int +virSetupMemoryCgroup(virDomainObj * vm, virCgroup *cgroup); +int +virSetupCpusetCgroup(virCgroup *cgroup); +int +virSetupCpuCgroup(virDomainObj * vm, virCgroup *cgroup); +int +virInitCgroup(const char *prefix, virDomainObj * vm, + size_t nnicindexes, int *nicindexes, + virCgroup *cgroup, int cgroupControllers, + unsigned int maxThreadsPerProc, + bool privileged, + char *machineName); +void +virRestoreCgroupState(virDomainObj * vm, virCgroup *cgroup); +int +virConnectCgroup(const char *prefix, virDomainObj * vm, virCgroup *cgroup, + int cgroupControllers, bool privileged, char *machineName= ); +int +virSetupCgroup(const char *prefix, virDomainObj * vm, + size_t nnicindexes, int *nicindexes, + virCgroup *cgroup, int cgroupControllers, + unsigned int maxThreadsPerProc, + bool privileged, + char *machineName); +void +virCgroupEmulatorAllNodesDataFree(virCgroupEmulatorAllNodesData * data); +int +virCgroupEmulatorAllNodesAllow(virCgroup * cgroup, + virCgroupEmulatorAllNodesData ** retData); +void +virCgroupEmulatorAllNodesRestore(virCgroupEmulatorAllNodesData * data); +int +virSetupCgroupVcpuBW(virCgroup * cgroup, + unsigned long long period, long long quota); +int +virSetupCgroupCpusetCpus(virCgroup * cgroup, virBitmap * cpumask); +int +virSetupGlobalCpuCgroup(virDomainObj * vm, virCgroup * cgroup, + virBitmap *autoNodeset); +int +virRemoveCgroup(virDomainObj * vm, virCgroup * cgroup, char *machineName); +int +virRestoreCgroupThread(virCgroup *cgroup, virCgroupThreadName thread, + int id); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e0c4fba522..2e510f5b91 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1545,6 +1545,16 @@ virDomainCgroupSetMemoryLimitParameters; virDomainCgroupSetupBlkio; virDomainCgroupSetupDomainBlkioParameters; virDomainCgroupSetupMemtune; +virInitCgroup; +virRemoveCgroup; +virSetupBlkioCgroup; +virSetupCgroup; +virSetupCgroupCpusetCpus; +virSetupCgroupVcpuBW; +virSetupCpuCgroup; +virSetupCpusetCgroup; +virSetupGlobalCpuCgroup; +virSetupMemoryCgroup; =20 =20 # hypervisor/domain_driver.h diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 308be5b00f..b1d2875959 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -593,46 +593,6 @@ qemuSetupVideoCgroup(virDomainObj *vm, return ret; } =20 - -static int -qemuSetupBlkioCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - - if (!virCgroupHasController(priv->cgroup, - VIR_CGROUP_CONTROLLER_BLKIO)) { - if (vm->def->blkio.weight || vm->def->blkio.ndevices) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Block I/O tuning is not available on this ho= st")); - return -1; - } - return 0; - } - - return virDomainCgroupSetupBlkio(priv->cgroup, vm->def->blkio); -} - - -static int -qemuSetupMemoryCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_MEMORY= )) { - if (virMemoryLimitIsSet(vm->def->mem.hard_limit) || - virMemoryLimitIsSet(vm->def->mem.soft_limit) || - virMemoryLimitIsSet(vm->def->mem.swap_hard_limit)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Memory cgroup is not available on this host"= )); - return -1; - } - return 0; - } - - return virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem); -} - - static int qemuSetupFirmwareCgroup(virDomainObj *vm) { @@ -861,44 +821,6 @@ qemuSetupDevicesCgroup(virDomainObj *vm) } =20 =20 -static int -qemuSetupCpusetCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET= )) - return 0; - - if (virCgroupSetCpusetMemoryMigrate(priv->cgroup, true) < 0) - return -1; - - return 0; -} - - -static int -qemuSetupCpuCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { - if (vm->def->cputune.sharesSpecified) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("CPU tuning is not available on this host")); - return -1; - } - return 0; - } - - if (vm->def->cputune.sharesSpecified) { - if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) <= 0) - return -1; - } - - return 0; -} - - static int qemuSetupCgroupAppid(virDomainObj *vm) { @@ -927,166 +849,13 @@ qemuSetupCgroupAppid(virDomainObj *vm) } =20 =20 -static int -qemuInitCgroup(virDomainObj *vm, - size_t nnicindexes, - int *nicindexes) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); - - if (!priv->driver->privileged) - return 0; - - if (!virCgroupAvailable()) - return 0; - - virCgroupFree(priv->cgroup); - priv->cgroup =3D NULL; - - if (!vm->def->resource) - vm->def->resource =3D g_new0(virDomainResourceDef, 1); - - if (!vm->def->resource->partition) - vm->def->resource->partition =3D g_strdup("/machine"); - - if (!g_path_is_absolute(vm->def->resource->partition)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Resource partition '%s' must start with '/'"), - vm->def->resource->partition); - return -1; - } - - if (virCgroupNewMachine(priv->machineName, - "qemu", - vm->def->uuid, - NULL, - vm->pid, - false, - nnicindexes, nicindexes, - vm->def->resource->partition, - cfg->cgroupControllers, - cfg->maxThreadsPerProc, - &priv->cgroup) < 0) { - if (virCgroupNewIgnoreError()) - return 0; - - return -1; - } - - return 0; -} - -static int -qemuRestoreCgroupThread(virCgroup *cgroup, - virCgroupThreadName thread, - int id) -{ - g_autoptr(virCgroup) cgroup_temp =3D NULL; - g_autofree char *nodeset =3D NULL; - - if (virCgroupNewThread(cgroup, thread, id, false, &cgroup_temp) < 0) - return -1; - - if (virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0) - return -1; - - if (virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0) - return -1; - - if (virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) - return -1; - - return 0; -} - -static void -qemuRestoreCgroupState(virDomainObj *vm) -{ - g_autofree char *mem_mask =3D NULL; - qemuDomainObjPrivate *priv =3D vm->privateData; - size_t i =3D 0; - g_autoptr(virBitmap) all_nodes =3D NULL; - - if (!virNumaIsAvailable() || - !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET= )) - return; - - if (!(all_nodes =3D virNumaGetHostMemoryNodeset())) - goto error; - - if (!(mem_mask =3D virBitmapFormat(all_nodes))) - goto error; - - if (virCgroupHasEmptyTasks(priv->cgroup, - VIR_CGROUP_CONTROLLER_CPUSET) <=3D 0) - goto error; - - if (virCgroupSetCpusetMems(priv->cgroup, mem_mask) < 0) - goto error; - - for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { - virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, i); - - if (!vcpu->online) - continue; - - if (qemuRestoreCgroupThread(priv->cgroup, - VIR_CGROUP_THREAD_VCPU, i) < 0) - return; - } - - for (i =3D 0; i < vm->def->niothreadids; i++) { - if (qemuRestoreCgroupThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHRE= AD, - vm->def->iothreadids[i]->iothread_id) = < 0) - return; - } - - if (qemuRestoreCgroupThread(priv->cgroup, - VIR_CGROUP_THREAD_EMULATOR, 0) < 0) - return; - - return; - - error: - virResetLastError(); - VIR_DEBUG("Couldn't restore cgroups to meaningful state"); - return; -} - -int -qemuConnectCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); - - if (!priv->driver->privileged) - return 0; - - if (!virCgroupAvailable()) - return 0; - - virCgroupFree(priv->cgroup); - priv->cgroup =3D NULL; - - if (virCgroupNewDetectMachine(vm->def->name, - "qemu", - vm->pid, - cfg->cgroupControllers, - priv->machineName, - &priv->cgroup) < 0) - return -1; - - qemuRestoreCgroupState(vm); - return 0; -} - int qemuSetupCgroup(virDomainObj *vm, size_t nnicindexes, int *nicindexes) { qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); =20 if (!vm->pid) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1094,7 +863,12 @@ qemuSetupCgroup(virDomainObj *vm, return -1; } =20 - if (qemuInitCgroup(vm, nnicindexes, nicindexes) < 0) + if (virInitCgroup("qemu", vm, nnicindexes, nicindexes, + priv->cgroup, + cfg->cgroupControllers, + cfg->maxThreadsPerProc, + priv->driver->privileged, + priv->machineName) < 0) return -1; =20 if (!priv->cgroup) @@ -1103,16 +877,16 @@ qemuSetupCgroup(virDomainObj *vm, if (qemuSetupDevicesCgroup(vm) < 0) return -1; =20 - if (qemuSetupBlkioCgroup(vm) < 0) + if (virSetupBlkioCgroup(vm, priv->cgroup) < 0) return -1; =20 - if (qemuSetupMemoryCgroup(vm) < 0) + if (virSetupMemoryCgroup(vm, priv->cgroup) < 0) return -1; =20 - if (qemuSetupCpuCgroup(vm) < 0) + if (virSetupCpuCgroup(vm, priv->cgroup) < 0) return -1; =20 - if (qemuSetupCpusetCgroup(vm) < 0) + if (virSetupCpusetCgroup(priv->cgroup) < 0) return -1; =20 if (qemuSetupCgroupAppid(vm) < 0) @@ -1121,23 +895,6 @@ qemuSetupCgroup(virDomainObj *vm, return 0; } =20 -int -qemuSetupCgroupVcpuBW(virCgroup *cgroup, - unsigned long long period, - long long quota) -{ - return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); -} - - -int -qemuSetupCgroupCpusetCpus(virCgroup *cgroup, - virBitmap *cpumask) -{ - return virCgroupSetupCpusetCpus(cgroup, cpumask); -} - - int qemuSetupCgroupForExtDevices(virDomainObj *vm, virQEMUDriver *driver) @@ -1164,148 +921,3 @@ qemuSetupCgroupForExtDevices(virDomainObj *vm, =20 return qemuExtDevicesSetupCgroup(driver, vm, cgroup_temp); } - - -int -qemuSetupGlobalCpuCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - unsigned long long period =3D vm->def->cputune.global_period; - long long quota =3D vm->def->cputune.global_quota; - g_autofree char *mem_mask =3D NULL; - virDomainNumatuneMemMode mem_mode; - - if ((period || quota) && - !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("cgroup cpu is required for scheduler tuning")); - return -1; - } - - /* - * If CPU cgroup controller is not initialized here, then we need - * neither period nor quota settings. And if CPUSET controller is - * not initialized either, then there's nothing to do anyway. - */ - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU) && - !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET= )) - return 0; - - - if (virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) =3D=3D 0 && - mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT && - virDomainNumatuneMaybeFormatNodeset(vm->def->numa, - priv->autoNodeset, - &mem_mask, -1) < 0) - return -1; - - if (period || quota) { - if (qemuSetupCgroupVcpuBW(priv->cgroup, period, quota) < 0) - return -1; - } - - return 0; -} - - -int -qemuRemoveCgroup(virDomainObj *vm) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - - if (priv->cgroup =3D=3D NULL) - return 0; /* Not supported, so claim success */ - - if (virCgroupTerminateMachine(priv->machineName) < 0) { - if (!virCgroupNewIgnoreError()) - VIR_DEBUG("Failed to terminate cgroup for %s", vm->def->name); - } - - return virCgroupRemove(priv->cgroup); -} - - -static void -qemuCgroupEmulatorAllNodesDataFree(qemuCgroupEmulatorAllNodesData *data) -{ - if (!data) - return; - - virCgroupFree(data->emulatorCgroup); - g_free(data->emulatorMemMask); - g_free(data); -} - - -/** - * qemuCgroupEmulatorAllNodesAllow: - * @cgroup: domain cgroup pointer - * @retData: filled with structure used to roll back the operation - * - * Allows all NUMA nodes for the qemu emulator thread temporarily. This is - * necessary when hotplugging cpus since it requires memory allocated in t= he - * DMA region. Afterwards the operation can be reverted by - * qemuCgroupEmulatorAllNodesRestore. - * - * Returns 0 on success -1 on error - */ -int -qemuCgroupEmulatorAllNodesAllow(virCgroup *cgroup, - qemuCgroupEmulatorAllNodesData **retData) -{ - qemuCgroupEmulatorAllNodesData *data =3D NULL; - g_autofree char *all_nodes_str =3D NULL; - g_autoptr(virBitmap) all_nodes =3D NULL; - int ret =3D -1; - - if (!virNumaIsAvailable() || - !virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) - return 0; - - if (!(all_nodes =3D virNumaGetHostMemoryNodeset())) - goto cleanup; - - if (!(all_nodes_str =3D virBitmapFormat(all_nodes))) - goto cleanup; - - data =3D g_new0(qemuCgroupEmulatorAllNodesData, 1); - - if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, - false, &data->emulatorCgroup) < 0) - goto cleanup; - - if (virCgroupGetCpusetMems(data->emulatorCgroup, &data->emulatorMemMas= k) < 0 || - virCgroupSetCpusetMems(data->emulatorCgroup, all_nodes_str) < 0) - goto cleanup; - - *retData =3D g_steal_pointer(&data); - ret =3D 0; - - cleanup: - qemuCgroupEmulatorAllNodesDataFree(data); - - return ret; -} - - -/** - * qemuCgroupEmulatorAllNodesRestore: - * @data: data structure created by qemuCgroupEmulatorAllNodesAllow - * - * Rolls back the setting done by qemuCgroupEmulatorAllNodesAllow and free= s the - * associated data. - */ -void -qemuCgroupEmulatorAllNodesRestore(qemuCgroupEmulatorAllNodesData *data) -{ - virErrorPtr err; - - if (!data) - return; - - virErrorPreserveLast(&err); - virCgroupSetCpusetMems(data->emulatorCgroup, data->emulatorMemMask); - virErrorRestore(&err); - - qemuCgroupEmulatorAllNodesDataFree(data); -} diff --git a/src/qemu/qemu_cgroup.h b/src/qemu/qemu_cgroup.h index cd537ebd82..f09134947f 100644 --- a/src/qemu/qemu_cgroup.h +++ b/src/qemu/qemu_cgroup.h @@ -56,18 +56,11 @@ int qemuSetupChardevCgroup(virDomainObj *vm, virDomainChrDef *dev); int qemuTeardownChardevCgroup(virDomainObj *vm, virDomainChrDef *dev); -int qemuConnectCgroup(virDomainObj *vm); int qemuSetupCgroup(virDomainObj *vm, size_t nnicindexes, int *nicindexes); -int qemuSetupCgroupVcpuBW(virCgroup *cgroup, - unsigned long long period, - long long quota); -int qemuSetupCgroupCpusetCpus(virCgroup *cgroup, virBitmap *cpumask); -int qemuSetupGlobalCpuCgroup(virDomainObj *vm); int qemuSetupCgroupForExtDevices(virDomainObj *vm, virQEMUDriver *driver); -int qemuRemoveCgroup(virDomainObj *vm); =20 typedef struct _qemuCgroupEmulatorAllNodesData qemuCgroupEmulatorAllNodesD= ata; struct _qemuCgroupEmulatorAllNodesData { @@ -75,8 +68,4 @@ struct _qemuCgroupEmulatorAllNodesData { char *emulatorMemMask; }; =20 -int qemuCgroupEmulatorAllNodesAllow(virCgroup *cgroup, - qemuCgroupEmulatorAllNodesData **data); -void qemuCgroupEmulatorAllNodesRestore(qemuCgroupEmulatorAllNodesData *dat= a); - extern const char *const defaultDeviceACL[]; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a7088d3a66..316ea4642f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4438,7 +4438,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm, if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, v= cpu, false, &cgroup_vcpu) < 0) goto cleanup; - if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0) + if (virSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0) goto cleanup; } =20 @@ -4651,7 +4651,7 @@ qemuDomainPinEmulator(virDomainPtr dom, 0, false, &cgroup_emulator) < 0) goto endjob; =20 - if (qemuSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) { + if (virSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("failed to set cpuset.cpus in cgroup" " for emulator threads")); @@ -5062,7 +5062,7 @@ qemuDomainPinIOThread(virDomainPtr dom, if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHREA= D, iothread_id, false, &cgroup_iothread) <= 0) goto endjob; - if (qemuSetupCgroupCpusetCpus(cgroup_iothread, pcpumap) < 0) { + if (virSetupCgroupCpusetCpus(cgroup_iothread, pcpumap) < 0) { virReportError(VIR_ERR_OPERATION_INVALID, _("failed to set cpuset.cpus in cgroup" " for iothread %d"), iothread_id); @@ -8948,7 +8948,7 @@ qemuSetGlobalBWLive(virCgroup *cgroup, unsigned long = long period, if (period =3D=3D 0 && quota =3D=3D 0) return 0; =20 - if (qemuSetupCgroupVcpuBW(cgroup, period, quota) < 0) + if (virSetupCgroupVcpuBW(cgroup, period, quota) < 0) return -1; =20 return 0; @@ -9143,7 +9143,7 @@ qemuSetVcpusBWLive(virDomainObj *vm, virCgroup *cgrou= p, false, &cgroup_vcpu) < 0) return -1; =20 - if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0) + if (virSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0) return -1; } =20 @@ -9164,7 +9164,7 @@ qemuSetEmulatorBandwidthLive(virCgroup *cgroup, false, &cgroup_emulator) < 0) return -1; =20 - if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0) + if (virSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0) return -1; =20 return 0; @@ -9191,7 +9191,7 @@ qemuSetIOThreadsBWLive(virDomainObj *vm, virCgroup *c= group, false, &cgroup_iothread) < 0) return -1; =20 - if (qemuSetupCgroupVcpuBW(cgroup_iothread, period, quota) < 0) + if (virSetupCgroupVcpuBW(cgroup_iothread, period, quota) < 0) return -1; } =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 426710786b..f930a9eb7a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6634,7 +6634,7 @@ qemuDomainSetVcpusLive(virQEMUDriver *driver, ssize_t nextvcpu =3D -1; int ret =3D -1; =20 - if (qemuCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup) < 0) + if (virCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup) < 0) goto cleanup; =20 if (enable) { @@ -6655,7 +6655,7 @@ qemuDomainSetVcpusLive(virQEMUDriver *driver, ret =3D 0; =20 cleanup: - qemuCgroupEmulatorAllNodesRestore(emulatorCgroup); + virCgroupEmulatorAllNodesRestore(emulatorCgroup); =20 return ret; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c355a39e15..53662c3d52 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2756,7 +2756,7 @@ qemuProcessSetupPid(virDomainObj *vm, =20 if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU= SET)) { if (use_cpumask && - qemuSetupCgroupCpusetCpus(cgroup, use_cpumask) < 0) + virSetupCgroupCpusetCpus(cgroup, use_cpumask) < 0) goto cleanup; =20 if (mem_mask && virCgroupSetCpusetMems(cgroup, mem_mask) < 0) @@ -2765,7 +2765,7 @@ qemuProcessSetupPid(virDomainObj *vm, } =20 if ((period || quota) && - qemuSetupCgroupVcpuBW(cgroup, period, quota) < 0) + virSetupCgroupVcpuBW(cgroup, period, quota) < 0) goto cleanup; =20 /* Move the thread to the sub dir */ @@ -6100,7 +6100,7 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driv= er, qsort(bootHotplug, nbootHotplug, sizeof(*bootHotplug), qemuProcessVcpusSortOrder); =20 - if (qemuCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup) < 0) + if (virCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup) < 0) goto cleanup; =20 for (i =3D 0; i < nbootHotplug; i++) { @@ -6125,7 +6125,7 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driv= er, ret =3D 0; =20 cleanup: - qemuCgroupEmulatorAllNodesRestore(emulatorCgroup); + virCgroupEmulatorAllNodesRestore(emulatorCgroup); return ret; } =20 @@ -6887,7 +6887,7 @@ qemuProcessPrepareHost(virQEMUDriver *driver, /* Ensure no historical cgroup for this VM is lying around bogus * settings */ VIR_DEBUG("Ensuring no historical cgroup is lying around"); - qemuRemoveCgroup(vm); + virRemoveCgroup(vm, priv->cgroup, priv->machineName); =20 if (g_mkdir_with_parents(cfg->logDir, 0777) < 0) { virReportSystemError(errno, @@ -7505,7 +7505,7 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; =20 VIR_DEBUG("Setting global CPU cgroup (if required)"); - if (qemuSetupGlobalCpuCgroup(vm) < 0) + if (virSetupGlobalCpuCgroup(vm, priv->cgroup, priv->autoNodeset) < 0) goto cleanup; =20 VIR_DEBUG("Setting vCPU tuning/settings"); @@ -8119,7 +8119,7 @@ void qemuProcessStop(virQEMUDriver *driver, } =20 retry: - if ((ret =3D qemuRemoveCgroup(vm)) < 0) { + if ((ret =3D virRemoveCgroup(vm, priv->cgroup, priv->machineName)) < 0= ) { if (ret =3D=3D -EBUSY && (retries++ < 5)) { g_usleep(200*1000); goto retry; @@ -8686,7 +8686,8 @@ qemuProcessReconnect(void *opaque) if (!priv->machineName) goto error; =20 - if (qemuConnectCgroup(obj) < 0) + if (virConnectCgroup("qemu", obj, priv->cgroup, cfg->cgroupControllers, + priv->driver->privileged, priv->machineName) < 0) goto error; =20 if (qemuDomainPerfRestart(obj) < 0) --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485837667328.10351029564686; Thu, 2 Dec 2021 14:57:17 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-180-gAMpqVfrOESienpGAwnR2A-1; Thu, 02 Dec 2021 17:57:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CBEF192CC4A; Thu, 2 Dec 2021 22:57:08 +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 0E8EF60C05; Thu, 2 Dec 2021 22:57:08 +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 D221518033F6; Thu, 2 Dec 2021 22:57:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuXP9015706 for ; Thu, 2 Dec 2021 17:56:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F5662166B40; Thu, 2 Dec 2021 22:56:33 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 389E02166B26 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F0F3E811E76 for ; Thu, 2 Dec 2021 22:56:27 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-430-gjPOz7qtMn-5YE0mRcodsg-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 36B9E20E693A; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: gAMpqVfrOESienpGAwnR2A-1 X-MC-Unique: gjPOz7qtMn-5YE0mRcodsg-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 36B9E20E693A From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/17] ch: methods for cgroup mgmt in ch driver Date: Thu, 2 Dec 2021 22:56:09 +0000 Message-Id: <20211202225614.1118066-13-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuXP9015706 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485839168100001 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_conf.c | 2 + src/ch/ch_conf.h | 4 +- src/ch/ch_domain.c | 34 +++++ src/ch/ch_domain.h | 3 +- src/ch/ch_monitor.c | 96 ++++++++++++++ src/ch/ch_monitor.h | 54 +++++++- src/ch/ch_process.c | 306 ++++++++++++++++++++++++++++++++++++++++++-- src/ch/ch_process.h | 3 + 8 files changed, 484 insertions(+), 18 deletions(-) diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index ef6f4b5ba8..cfc1174354 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -129,6 +129,8 @@ virCHDriverConfigNew(bool privileged) if (!(cfg =3D virObjectNew(virCHDriverConfigClass))) return NULL; =20 + cfg->cgroupControllers =3D -1; /* Auto detect */ + if (privileged) { if (virGetUserID(CH_USER, &cfg->user) < 0) return NULL; diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h index 8fe69c8545..1790295ede 100644 --- a/src/ch/ch_conf.h +++ b/src/ch/ch_conf.h @@ -35,11 +35,13 @@ struct _virCHDriverConfig { =20 char *stateDir; char *logDir; - + int cgroupControllers; uid_t user; gid_t group; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHDriverConfig, virObjectUnref); + struct _virCHDriver { virMutex lock; diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 326c3802c3..0a0b1206d6 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -322,6 +322,40 @@ chValidateDomainDeviceDef(const virDomainDeviceDef * d= ev, _("Serial can only be enabled for a PTY")); return -1; } + return 0; +} + +int +virCHDomainRefreshThreadInfo(virDomainObj * vm) +{ + size_t maxvcpus =3D virDomainDefGetVcpusMax(vm->def); + virCHMonitorThreadInfo *info =3D NULL; + size_t nthreads, ncpus =3D 0; + size_t i; + + nthreads =3D virCHMonitorGetThreadInfo(virCHDomainGetMonitor(vm), + true, &info); + + for (i =3D 0; i < nthreads; i++) { + virCHDomainVcpuPrivate *vcpupriv; + virDomainVcpuDef *vcpu; + virCHMonitorCPUInfo *vcpuInfo; + + if (info[i].type !=3D virCHThreadTypeVcpu) + continue; + + // TODO: hotplug support + vcpuInfo =3D &info[i].vcpuInfo; + vcpu =3D virDomainDefGetVcpu(vm->def, vcpuInfo->cpuid); + vcpupriv =3D CH_DOMAIN_VCPU_PRIVATE(vcpu); + vcpupriv->tid =3D vcpuInfo->tid; + ncpus++; + } + + // TODO: Remove the warning when hotplug is implemented. + if (ncpus !=3D maxvcpus) + VIR_WARN("Mismatch in the number of cpus, expected: %ld, actual: %= ld", + maxvcpus, ncpus); =20 return 0; } diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 3ac3421015..2ce3e2cef3 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -89,7 +89,8 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDomai= nJob job) void virCHDomainObjEndJob(virDomainObj *obj); =20 -int virCHDomainRefreshVcpuInfo(virDomainObj *vm); +int virCHDomainRefreshThreadInfo(virDomainObj *vm); + pid_t virCHDomainGetVcpuPid(virDomainObj *vm, unsigned int vcpuid); bool virCHDomainHasVcpuPids(virDomainObj *vm); =20 diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 6bc7d035ad..d7593d4aa6 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -41,6 +41,7 @@ VIR_LOG_INIT("ch.ch_monitor"); =20 static virClass *virCHMonitorClass; static void virCHMonitorDispose(void *obj); +static void virCHMonitorThreadInfoFree(virCHMonitor * mon); =20 static int virCHMonitorOnceInit(void) @@ -589,6 +590,7 @@ virCHMonitorDispose(void *opaque) virCHMonitor *mon =3D opaque; =20 VIR_DEBUG("mon=3D%p", mon); + virCHMonitorThreadInfoFree(mon); virObjectUnref(mon->vm); } =20 @@ -756,6 +758,100 @@ virCHMonitorGet(virCHMonitor * mon, const char *endpo= int, return ret; } =20 +static void +virCHMonitorThreadInfoFree(virCHMonitor * mon) +{ + mon->nthreads =3D 0; + if (mon->threads) + VIR_FREE(mon->threads); +} + +static size_t +virCHMonitorRefreshThreadInfo(virCHMonitor * mon) +{ + virCHMonitorThreadInfo *info =3D NULL; + g_autofree pid_t *tids =3D NULL; + virDomainObj *vm =3D mon->vm; + size_t ntids =3D 0; + size_t i; + + + virCHMonitorThreadInfoFree(mon); + if (virProcessGetPids(vm->pid, &ntids, &tids) < 0) { + mon->threads =3D NULL; + return 0; + } + + info =3D g_new0(virCHMonitorThreadInfo, ntids); + for (i =3D 0; i < ntids; i++) { + g_autofree char *proc =3D NULL; + g_autofree char *data =3D NULL; + + proc =3D g_strdup_printf("/proc/%d/task/%d/comm", + (int) vm->pid, (int) tids[i]); + + if (virFileReadAll(proc, (1 << 16), &data) < 0) { + continue; + } + + VIR_DEBUG("VM PID: %d, TID %d, COMM: %s", + (int) vm->pid, (int) tids[i], data); + if (STRPREFIX(data, "vcpu")) { + int cpuid; + char *tmp; + + if (virStrToLong_i(data + 4, &tmp, 0, &cpuid) < 0) { + VIR_WARN("Index is not specified correctly"); + continue; + } + info[i].type =3D virCHThreadTypeVcpu; + info[i].vcpuInfo.tid =3D tids[i]; + info[i].vcpuInfo.online =3D true; + info[i].vcpuInfo.cpuid =3D cpuid; + VIR_DEBUG("vcpu%d -> tid: %d", cpuid, tids[i]); + } else if (STRPREFIX(data, "_disk") || STRPREFIX(data, "_net") || + STRPREFIX(data, "_rng")) { + /* Prefixes used by cloud-hypervisor for IO Threads are captur= ed at + * https://github.com/cloud-hypervisor/cloud-hypervisor/blob/m= ain/vmm/src/device_manager.rs */ + info[i].type =3D virCHThreadTypeIO; + info[i].ioInfo.tid =3D tids[i]; + virStrcpy(info[i].ioInfo.thrName, data, VIRCH_THREAD_NAME_LEN = - 1); + } else { + info[i].type =3D virCHThreadTypeEmulator; + info[i].emuInfo.tid =3D tids[i]; + virStrcpy(info[i].emuInfo.thrName, data, VIRCH_THREAD_NAME_LEN= - 1); + } + mon->nthreads++; + + } + mon->threads =3D info; + + return mon->nthreads; +} + +/** + * virCHMonitorGetThreadInfo: + * @mon: Pointer to the monitor + * @refresh: Refresh thread info or not + * + * Retrive thread info and store to @threads + * + * Returns count of threads on success. + */ +size_t +virCHMonitorGetThreadInfo(virCHMonitor * mon, bool refresh, + virCHMonitorThreadInfo ** threads) +{ + int nthreads =3D 0; + + if (refresh) + nthreads =3D virCHMonitorRefreshThreadInfo(mon); + + *threads =3D mon->threads; + + return nthreads; +} + int virCHMonitorShutdownVMM(virCHMonitor * mon) { diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 8ca9e17a9a..f8c3fa75e8 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -37,6 +37,50 @@ #define URL_VM_RESUME "vm.resume" #define URL_VM_INFO "vm.info" =20 +#define VIRCH_THREAD_NAME_LEN 16 + +typedef enum { + virCHThreadTypeEmulator, + virCHThreadTypeVcpu, + virCHThreadTypeIO, + virCHThreadTypeMax +} virCHThreadType; + +typedef struct _virCHMonitorCPUInfo virCHMonitorCPUInfo; + +struct _virCHMonitorCPUInfo { + int cpuid; + pid_t tid; + + bool online; +}; + +typedef struct _virCHMonitorEmuThreadInfo virCHMonitorEmuThreadInfo; + +struct _virCHMonitorEmuThreadInfo { + char thrName[VIRCH_THREAD_NAME_LEN]; + pid_t tid; +}; + +typedef struct _virCHMonitorIOThreadInfo virCHMonitorIOThreadInfo; + +struct _virCHMonitorIOThreadInfo { + char thrName[VIRCH_THREAD_NAME_LEN]; + pid_t tid; +}; + +typedef struct _virCHMonitorThreadInfo virCHMonitorThreadInfo; + +struct _virCHMonitorThreadInfo { + virCHThreadType type; + + union { + virCHMonitorCPUInfo vcpuInfo; + virCHMonitorEmuThreadInfo emuInfo; + virCHMonitorIOThreadInfo ioInfo; + }; +}; + typedef struct _virCHMonitor virCHMonitor; =20 struct _virCHMonitor { @@ -49,6 +93,9 @@ struct _virCHMonitor { pid_t pid; =20 virDomainObj *vm; + + size_t nthreads; + virCHMonitorThreadInfo *threads; }; =20 virCHMonitor *virCHMonitorNew(virDomainObj *vm, const char *socketdir); @@ -65,12 +112,9 @@ int virCHMonitorSuspendVM(virCHMonitor *mon); int virCHMonitorResumeVM(virCHMonitor *mon); int virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info); =20 -typedef struct _virCHMonitorCPUInfo virCHMonitorCPUInfo; -struct _virCHMonitorCPUInfo { - pid_t tid; - bool online; -}; void virCHMonitorCPUInfoFree(virCHMonitorCPUInfo *cpus); int virCHMonitorGetCPUInfo(virCHMonitor *mon, virCHMonitorCPUInfo **vcpus, size_t maxvcpus); +size_t virCHMonitorGetThreadInfo(virCHMonitor *mon, bool refresh, + virCHMonitorThreadInfo **threads); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 3b7f6fcddf..7a51531224 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -26,6 +26,8 @@ #include "ch_domain.h" #include "ch_monitor.h" #include "ch_process.h" +#include "domain_cgroup.h" +#include "virnuma.h" #include "viralloc.h" #include "virerror.h" #include "virjson.h" @@ -133,6 +135,254 @@ virCHProcessUpdateInfo(virDomainObj *vm) return 0; } =20 +static int +virCHProcessGetAllCpuAffinity(virBitmap ** cpumapRet) +{ + *cpumapRet =3D NULL; + + if (!virHostCPUHasBitmap()) + return 0; + + if (!(*cpumapRet =3D virHostCPUGetOnlineBitmap())) + return -1; + + return 0; +} + +#if defined(WITH_SCHED_GETAFFINITY) || defined(WITH_BSD_CPU_AFFINITY) +static int +virCHProcessInitCpuAffinity(virDomainObj * vm) +{ + g_autoptr(virBitmap) cpumapToSet =3D NULL; + virDomainNumatuneMemMode mem_mode; + virCHDomainObjPrivate *priv =3D vm->privateData; + + if (!vm->pid) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot setup CPU affinity until process is start= ed")); + return -1; + } + + if (virDomainNumaGetNodeCount(vm->def->numa) <=3D 1 && + virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) =3D=3D 0 && + mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { + virBitmap *nodeset =3D NULL; + + if (virDomainNumatuneMaybeGetNodeset(vm->def->numa, + priv->autoNodeset, + &nodeset, -1) < 0) + return -1; + + if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0) + return -1; + } else if (vm->def->cputune.emulatorpin) { + if (!(cpumapToSet =3D virBitmapNewCopy(vm->def->cputune.emulatorpi= n))) + return -1; + } else { + if (virCHProcessGetAllCpuAffinity(&cpumapToSet) < 0) + return -1; + } + + if (cpumapToSet && virProcessSetAffinity(vm->pid, cpumapToSet, false) = < 0) { + return -1; + } + + return 0; +} +#else /* !defined(WITH_SCHED_GETAFFINITY) && !defined(WITH_BSD_CPU_AFFINIT= Y) */ +static int +virCHProcessInitCpuAffinity(virDomainObj * vm G_GNUC_UNUSED) +{ + return 0; +} +#endif /* !defined(WITH_SCHED_GETAFFINITY) && !defined(WITH_BSD_CPU_AFFINI= TY) */ + +/** + * virCHProcessSetupPid: + * + * This function sets resource properties (affinity, cgroups, + * scheduler) for any PID associated with a domain. It should be used + * to set up emulator PIDs as well as vCPU and I/O thread pids to + * ensure they are all handled the same way. + * + * Returns 0 on success, -1 on error. + */ +static int +virCHProcessSetupPid(virDomainObj *vm, + pid_t pid, + virCgroupThreadName nameval, + int id, + virBitmap *cpumask, + unsigned long long period, + long long quota, + virDomainThreadSchedParam *sched) +{ + virCHDomainObjPrivate *priv =3D vm->privateData; + virDomainNumatuneMemMode mem_mode; + virCgroup *cgroup =3D NULL; + virBitmap *use_cpumask =3D NULL; + virBitmap *affinity_cpumask =3D NULL; + g_autoptr(virBitmap) hostcpumap =3D NULL; + g_autofree char *mem_mask =3D NULL; + int ret =3D -1; + + if ((period || quota) && + !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cgroup cpu is required for scheduler tuning")); + goto cleanup; + } + + /* Infer which cpumask shall be used. */ + if (cpumask) { + use_cpumask =3D cpumask; + } else if (vm->def->placement_mode =3D=3D VIR_DOMAIN_CPU_PLACEMENT_MOD= E_AUTO) { + use_cpumask =3D priv->autoCpuset; + } else if (vm->def->cpumask) { + use_cpumask =3D vm->def->cpumask; + } else { + /* we can't assume cloud-hypervisor itself is running on all pCPUs, + * so we need to explicitly set the spawned instance to all pCPUs.= */ + if (virCHProcessGetAllCpuAffinity(&hostcpumap) < 0) + goto cleanup; + affinity_cpumask =3D hostcpumap; + } + + /* + * If CPU cgroup controller is not initialized here, then we need + * neither period nor quota settings. And if CPUSET controller is + * not initialized either, then there's nothing to do anyway. + */ + if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU) || + virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)= ) { + + if (virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) =3D=3D = 0 && + mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT && + virDomainNumatuneMaybeFormatNodeset(vm->def->numa, + priv->autoNodeset, + &mem_mask, -1) < 0) + goto cleanup; + + if (virCgroupNewThread(priv->cgroup, nameval, id, true, &cgroup) <= 0) + goto cleanup; + + if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU= SET)) { + if (use_cpumask && + virSetupCgroupCpusetCpus(cgroup, use_cpumask) < 0) + goto cleanup; + + if (mem_mask && virCgroupSetCpusetMems(cgroup, mem_mask) < 0) + goto cleanup; + + } + + if ((period || quota) && + virSetupCgroupVcpuBW(cgroup, period, quota) < 0) + goto cleanup; + + /* Move the thread to the sub dir */ + VIR_INFO("Adding pid %d to cgroup", pid); + if (virCgroupAddThread(cgroup, pid) < 0) + goto cleanup; + + } + + if (!affinity_cpumask) + affinity_cpumask =3D use_cpumask; + + /* Setup legacy affinity. */ + if (affinity_cpumask + && virProcessSetAffinity(pid, affinity_cpumask, false) < 0) + goto cleanup; + + /* Set scheduler type and priority, but not for the main thread. */ + if (sched && + nameval !=3D VIR_CGROUP_THREAD_EMULATOR && + virProcessSetScheduler(pid, sched->policy, sched->priority) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + if (cgroup) { + if (ret < 0) + virCgroupRemove(cgroup); + virCgroupFree(cgroup); + } + + return ret; +} + +/** + * virCHProcessSetupVcpu: + * @vm: domain object + * @vcpuid: id of VCPU to set defaults + * + * This function sets resource properties (cgroups, affinity, scheduler) f= or a + * vCPU. This function expects that the vCPU is online and the vCPU pids w= ere + * correctly detected at the point when it's called. + * + * Returns 0 on success, -1 on error. + */ +int +virCHProcessSetupVcpu(virDomainObj * vm, unsigned int vcpuid) +{ + pid_t vcpupid =3D virCHDomainGetVcpuPid(vm, vcpuid); + virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, vcpuid); + + return virCHProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU, + vcpuid, vcpu->cpumask, + vm->def->cputune.period, + vm->def->cputune.quota, &vcpu->sched); +} + +static int +virCHProcessSetupVcpus(virDomainObj * vm) +{ + virDomainVcpuDef *vcpu; + unsigned int maxvcpus =3D virDomainDefGetVcpusMax(vm->def); + size_t i; + + if ((vm->def->cputune.period || vm->def->cputune.quota) && + !virCgroupHasController(((virCHDomainObjPrivate *) vm->privateData= )-> + cgroup, VIR_CGROUP_CONTROLLER_CPU)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cgroup cpu is required for scheduler tuning")); + return -1; + } + + if (!virCHDomainHasVcpuPids(vm)) { + /* If any CPU has custom affinity that differs from the + * VM default affinity, we must reject it */ + for (i =3D 0; i < maxvcpus; i++) { + vcpu =3D virDomainDefGetVcpu(vm->def, i); + + if (!vcpu->online) + continue; + + if (vcpu->cpumask && + !virBitmapEqual(vm->def->cpumask, vcpu->cpumask)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cpu affinity is not supported")); + return -1; + } + } + + return 0; + } + + for (i =3D 0; i < maxvcpus; i++) { + vcpu =3D virDomainDefGetVcpu(vm->def, i); + + if (!vcpu->online) + continue; + + if (virCHProcessSetupVcpu(vm, i) < 0) + return -1; + } + + return 0; +} + /** * virCHProcessStart: * @driver: pointer to driver structure @@ -143,12 +393,13 @@ virCHProcessUpdateInfo(virDomainObj *vm) * * Returns 0 on success or -1 in case of error */ -int virCHProcessStart(virCHDriver *driver, - virDomainObj *vm, - virDomainRunningReason reason) +int +virCHProcessStart(virCHDriver * driver, + virDomainObj * vm, virDomainRunningReason reason) { int ret =3D -1; virCHDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virCHDriverConfig) cfg =3D virCHDriverGetConfig(priv->driver= ); g_autofree int *nicindexes =3D NULL; size_t nnicindexes =3D 0; =20 @@ -168,18 +419,39 @@ int virCHProcessStart(virCHDriver *driver, } } =20 + vm->pid =3D priv->monitor->pid; + vm->def->id =3D vm->pid; + priv->machineName =3D virCHDomainGetMachineName(vm); + + if (virSetupCgroup("ch", vm, + nnicindexes, nicindexes, + priv->cgroup, + cfg->cgroupControllers, + 0, /*maxThreadsPerProc*/ + priv->driver->privileged, + priv->machineName) < 0) + goto cleanup; + + if (virCHProcessInitCpuAffinity(vm) < 0) + goto cleanup; + if (virCHMonitorBootVM(priv->monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to boot guest VM")); goto cleanup; } =20 - priv->machineName =3D virCHDomainGetMachineName(vm); - vm->pid =3D priv->monitor->pid; - vm->def->id =3D vm->pid; + virCHDomainRefreshThreadInfo(vm); =20 - virCHProcessUpdateInfo(vm); + VIR_DEBUG("Setting global CPU cgroup (if required)"); + if (virSetupGlobalCpuCgroup(vm, priv->cgroup, priv->autoNodeset) < 0) + goto cleanup; + + VIR_DEBUG("Setting vCPU tuning/settings"); + if (virCHProcessSetupVcpus(vm) < 0) + goto cleanup; =20 + virCHProcessUpdateInfo(vm); virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); =20 return 0; @@ -191,20 +463,32 @@ int virCHProcessStart(virCHDriver *driver, return ret; } =20 -int virCHProcessStop(virCHDriver *driver G_GNUC_UNUSED, - virDomainObj *vm, - virDomainShutoffReason reason) +int +virCHProcessStop(virCHDriver * driver G_GNUC_UNUSED, + virDomainObj * vm, virDomainShutoffReason reason) { + int ret; + int retries =3D 0; virCHDomainObjPrivate *priv =3D vm->privateData; =20 VIR_DEBUG("Stopping VM name=3D%s pid=3D%d reason=3D%d", - vm->def->name, (int)vm->pid, (int)reason); + vm->def->name, (int) vm->pid, (int) reason); =20 if (priv->monitor) { virCHMonitorClose(priv->monitor); priv->monitor =3D NULL; } =20 + retry: + if ((ret =3D virRemoveCgroup(vm, priv->cgroup, priv->machineName))= < 0) { + if (ret =3D=3D -EBUSY && (retries++ < 5)) { + g_usleep(200*1000); + goto retry; + } + VIR_WARN("Failed to remove cgroup for %s", + vm->def->name); + } + vm->pid =3D -1; vm->def->id =3D -1; =20 diff --git a/src/ch/ch_process.h b/src/ch/ch_process.h index abc4915979..800e3f4e23 100644 --- a/src/ch/ch_process.h +++ b/src/ch/ch_process.h @@ -29,3 +29,6 @@ int virCHProcessStart(virCHDriver *driver, int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, virDomainShutoffReason reason); + +int virCHProcessSetupVcpu(virDomainObj *vm, + unsigned int vcpuid); --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485831907928.1853570659101; Thu, 2 Dec 2021 14:57:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-gfp1L3y5Pzi38eoH6nM59g-1; Thu, 02 Dec 2021 17:57:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6DE1192CC46; Thu, 2 Dec 2021 22:57:01 +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 951965D9D5; Thu, 2 Dec 2021 22:57:01 +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 663C01806D2B; Thu, 2 Dec 2021 22:57:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSXN015612 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 72420492C3B; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DDCA492C38 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 555F98001EA for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-183-WXR6NGuON9O4hG82q0dLug-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 4C9F120E693B; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: gfp1L3y5Pzi38eoH6nM59g-1 X-MC-Unique: WXR6NGuON9O4hG82q0dLug-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4C9F120E693B From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/17] ch_driver, ch_domain: vcpupin callback in ch driver Date: Thu, 2 Dec 2021 22:56:10 +0000 Message-Id: <20211202225614.1118066-14-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSXN015612 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485834438100001 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_domain.c | 30 +++++++++ src/ch/ch_domain.h | 1 + src/ch/ch_driver.c | 151 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 0a0b1206d6..de084ca15e 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -20,6 +20,7 @@ =20 #include =20 +#include "datatypes.h" #include "ch_domain.h" #include "domain_driver.h" #include "viralloc.h" @@ -418,3 +419,32 @@ virCHDomainGetMachineName(virDomainObj * vm) =20 return ret; } + +/** + * virCHDomainObjFromDomain: + * @domain: Domain pointer that has to be looked up + * + * This function looks up @domain and returns the appropriate virDomainObj= Ptr + * that has to be released by calling virDomainObjEndAPI(). + * + * Returns the domain object with incremented reference counter which is l= ocked + * on success, NULL otherwise. + */ +virDomainObj * +virCHDomainObjFromDomain(virDomainPtr domain) +{ + virDomainObj *vm; + virCHDriver *driver =3D domain->conn->privateData; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + vm =3D virDomainObjListFindByUUID(driver->domains, domain->uuid); + if (!vm) { + virUUIDFormat(domain->uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, domain->name); + return NULL; + } + + return vm; +} diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 2ce3e2cef3..db1451405b 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -95,3 +95,4 @@ pid_t virCHDomainGetVcpuPid(virDomainObj *vm, unsigned in= t vcpuid); bool virCHDomainHasVcpuPids(virDomainObj *vm); =20 char *virCHDomainGetMachineName(virDomainObj *vm); +virDomainObj *virCHDomainObjFromDomain(virDomain *domain); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 39e754d1ff..400dfee766 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -25,6 +25,7 @@ #include "ch_driver.h" #include "ch_monitor.h" #include "ch_process.h" +#include "domain_cgroup.h" #include "datatypes.h" #include "driver.h" #include "viraccessapicheck.h" @@ -1129,6 +1130,154 @@ chDomainGetVcpus(virDomainPtr dom, return ret; } =20 +static int +chDomainPinVcpuLive(virDomainObj *vm, + virDomainDef *def, + int vcpu, + virCHDriver *driver, + virCHDriverConfig *cfg, + virBitmap *cpumap) +{ + virBitmap *tmpmap =3D NULL; + virDomainVcpuDef *vcpuinfo; + virCHDomainObjPrivate *priv =3D vm->privateData; + virCgroup *cgroup_vcpu =3D NULL; + g_autofree char *str =3D NULL; + int ret =3D -1; + + if (!virCHDomainHasVcpuPids(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + goto cleanup; + } + + if (!(vcpuinfo =3D virDomainDefGetVcpu(def, vcpu))) { + virReportError(VIR_ERR_INVALID_ARG, + _("vcpu %d is out of range of live cpu count %d"), + vcpu, virDomainDefGetVcpusMax(def)); + goto cleanup; + } + + if (!(tmpmap =3D virBitmapNewCopy(cpumap))) + goto cleanup; + + if (!(str =3D virBitmapFormat(cpumap))) + goto cleanup; + + if (vcpuinfo->online) { + /* Configure the corresponding cpuset cgroup before set affinity. = */ + if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU= SET)) { + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, v= cpu, + false, &cgroup_vcpu) < 0) + goto cleanup; + if (virSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0) + goto cleanup; + } + + if (virProcessSetAffinity(virCHDomainGetVcpuPid(vm, vcpu), cpumap,= false) < 0) + goto cleanup; + } + + virBitmapFree(vcpuinfo->cpumask); + vcpuinfo->cpumask =3D tmpmap; + tmpmap =3D NULL; + + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBitmapFree(tmpmap); + virCgroupFree(cgroup_vcpu); + return ret; +} + + +static int +chDomainPinVcpuFlags(virDomainPtr dom, + unsigned int vcpu, + unsigned char *cpumap, + int maplen, + unsigned int flags) +{ + virCHDriver *driver =3D dom->conn->privateData; + virDomainObj *vm; + virDomainDef *def; + virDomainDef *persistentDef; + int ret =3D -1; + virBitmap *pcpumap =3D NULL; + virDomainVcpuDef *vcpuinfo =3D NULL; + g_autoptr(virCHDriverConfig) cfg =3D NULL; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + cfg =3D virCHDriverGetConfig(driver); + + if (!(vm =3D virCHDomainObjFromDomain(dom))) + goto cleanup; + + if (virDomainPinVcpuFlagsEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + if (persistentDef && + !(vcpuinfo =3D virDomainDefGetVcpu(persistentDef, vcpu))) { + virReportError(VIR_ERR_INVALID_ARG, + _("vcpu %d is out of range of persistent cpu count = %d"), + vcpu, virDomainDefGetVcpus(persistentDef)); + goto endjob; + } + + if (!(pcpumap =3D virBitmapNewData(cpumap, maplen))) + goto endjob; + + if (virBitmapIsAllClear(pcpumap)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Empty cpu list for pinning")); + goto endjob; + } + + if (def && + chDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0) + goto endjob; + + if (persistentDef) { + virBitmapFree(vcpuinfo->cpumask); + vcpuinfo->cpumask =3D pcpumap; + pcpumap =3D NULL; + + // ret =3D virDomainDefSave(persistentDef, driver->xmlopt, cfg->co= nfigDir); + goto endjob; + } + + ret =3D 0; + + endjob: + virCHDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + virBitmapFree(pcpumap); + return ret; +} + +static int +chDomainPinVcpu(virDomainPtr dom, + unsigned int vcpu, + unsigned char *cpumap, + int maplen) +{ + return chDomainPinVcpuFlags(dom, vcpu, cpumap, maplen, + VIR_DOMAIN_AFFECT_LIVE); +} + /* Function Tables */ static virHypervisorDriver chHypervisorDriver =3D { .name =3D "CH", @@ -1169,6 +1318,8 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainGetVcpusFlags =3D chDomainGetVcpusFlags, /* 7.11.0 */ .domainGetMaxVcpus =3D chDomainGetMaxVcpus, /* 7.11.0 */ .domainGetVcpuPinInfo =3D chDomainGetVcpuPinInfo, /* 7.11.0 */ + .domainPinVcpu =3D chDomainPinVcpu, /* 7.11.0 */ + .domainPinVcpuFlags =3D chDomainPinVcpuFlags, /* 7.11.0 */ .nodeGetCPUMap =3D chNodeGetCPUMap, /* 7.11.0 */ }; =20 --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163848582765591.37587154174241; Thu, 2 Dec 2021 14:57:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-my0nPiQqO6yAc-ZeCflf1g-1; Thu, 02 Dec 2021 17:57:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0930585B6CA; Thu, 2 Dec 2021 22:56:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDE555D9D5; Thu, 2 Dec 2021 22:56:58 +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 AEB784A700; Thu, 2 Dec 2021 22:56:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuSe8015597 for ; Thu, 2 Dec 2021 17:56:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 405FEC08089; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BEFFC08086 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23E3C811E7F for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-183-BpgpCd0gOSCVZYkdK3UjqA-1; Thu, 02 Dec 2021 17:56:26 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 623D620E693D; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: my0nPiQqO6yAc-ZeCflf1g-1 X-MC-Unique: BpgpCd0gOSCVZYkdK3UjqA-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 623D620E693D From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 14/17] ch_driver: enable typed param string for numatune Date: Thu, 2 Dec 2021 22:56:11 +0000 Message-Id: <20211202225614.1118066-15-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuSe8015597 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485829229100001 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Enable support of VIR_DRV_FEATURE_TYPED_PARAM_STRING to enable numatune Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_driver.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 400dfee766..c6dcc33f5e 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -946,6 +946,36 @@ chStateInitialize(bool privileged, return ret; } =20 +/* Which features are supported by this driver? */ +static int +chConnectSupportsFeature(virConnectPtr conn, int feature) +{ + if (virConnectSupportsFeatureEnsureACL(conn) < 0) + return -1; + + switch ((virDrvFeature) feature) { + case VIR_DRV_FEATURE_TYPED_PARAM_STRING: + return 1; + case VIR_DRV_FEATURE_MIGRATION_V2: + case VIR_DRV_FEATURE_MIGRATION_V3: + case VIR_DRV_FEATURE_MIGRATION_P2P: + case VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION: + case VIR_DRV_FEATURE_FD_PASSING: + case VIR_DRV_FEATURE_XML_MIGRATABLE: + case VIR_DRV_FEATURE_MIGRATION_OFFLINE: + case VIR_DRV_FEATURE_MIGRATION_PARAMS: + case VIR_DRV_FEATURE_MIGRATION_DIRECT: + case VIR_DRV_FEATURE_MIGRATION_V1: + case VIR_DRV_FEATURE_PROGRAM_KEEPALIVE: + case VIR_DRV_FEATURE_REMOTE: + case VIR_DRV_FEATURE_REMOTE_CLOSE_CALLBACK: + case VIR_DRV_FEATURE_REMOTE_EVENT_CALLBACK: + case VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER: + default: + return 0; + } +} + static int chDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags) { @@ -1291,6 +1321,7 @@ static virHypervisorDriver chHypervisorDriver =3D { .connectListAllDomains =3D chConnectListAllDomains, /* 7.5.0 */ .connectListDomains =3D chConnectListDomains, /* 7.5.0 */ .connectGetCapabilities =3D chConnectGetCapabilities, /* 7.5.0 */ + .connectSupportsFeature =3D chConnectSupportsFeature, /* 7.11.0 */ .domainCreateXML =3D chDomainCreateXML, /* 7.5.0 */ .domainCreate =3D chDomainCreate, /* 7.5.0 */ .domainCreateWithFlags =3D chDomainCreateWithFlags, /* 7.5.0 */ --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485823689828.0448021311315; Thu, 2 Dec 2021 14:57:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-196-0iJRRA9EN2ebM0Mo0ZFbXg-1; Thu, 02 Dec 2021 17:56:59 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 531C9192CC41; Thu, 2 Dec 2021 22:56:54 +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 38ADA10016F5; Thu, 2 Dec 2021 22:56:54 +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 0B5211809CB9; Thu, 2 Dec 2021 22:56:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuTP2015641 for ; Thu, 2 Dec 2021 17:56:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 12E41401E5D; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D1A6401E38 for ; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E554A100E664 for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-133-CZpWaKuhPfiop0Q6KXAyEQ-3; Thu, 02 Dec 2021 17:56:27 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 78E3E20E693F; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: 0iJRRA9EN2ebM0Mo0ZFbXg-1 X-MC-Unique: CZpWaKuhPfiop0Q6KXAyEQ-3 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 78E3E20E693F From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/17] ch_driver: add numatune callbacks for CH driver Date: Thu, 2 Dec 2021 22:56:12 +0000 Message-Id: <20211202225614.1118066-16-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuTP2015641 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485824606100001 Content-Type: text/plain; charset="utf-8" From: Vineeth Pillai Signed-off-by: Vineeth Pillai Signed-off-by: Praveen K Paladugu --- src/ch/ch_driver.c | 316 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 297 insertions(+), 19 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index c6dcc33f5e..8c14829d2a 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -43,6 +43,7 @@ #include "viruri.h" #include "virutil.h" #include "viruuid.h" +#include "virnuma.h" =20 #define VIR_FROM_THIS VIR_FROM_CH =20 @@ -954,25 +955,25 @@ chConnectSupportsFeature(virConnectPtr conn, int feat= ure) return -1; =20 switch ((virDrvFeature) feature) { - case VIR_DRV_FEATURE_TYPED_PARAM_STRING: - return 1; - case VIR_DRV_FEATURE_MIGRATION_V2: - case VIR_DRV_FEATURE_MIGRATION_V3: - case VIR_DRV_FEATURE_MIGRATION_P2P: - case VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION: - case VIR_DRV_FEATURE_FD_PASSING: - case VIR_DRV_FEATURE_XML_MIGRATABLE: - case VIR_DRV_FEATURE_MIGRATION_OFFLINE: - case VIR_DRV_FEATURE_MIGRATION_PARAMS: - case VIR_DRV_FEATURE_MIGRATION_DIRECT: - case VIR_DRV_FEATURE_MIGRATION_V1: - case VIR_DRV_FEATURE_PROGRAM_KEEPALIVE: - case VIR_DRV_FEATURE_REMOTE: - case VIR_DRV_FEATURE_REMOTE_CLOSE_CALLBACK: - case VIR_DRV_FEATURE_REMOTE_EVENT_CALLBACK: - case VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER: - default: - return 0; + case VIR_DRV_FEATURE_TYPED_PARAM_STRING: + return 1; + case VIR_DRV_FEATURE_MIGRATION_V2: + case VIR_DRV_FEATURE_MIGRATION_V3: + case VIR_DRV_FEATURE_MIGRATION_P2P: + case VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION: + case VIR_DRV_FEATURE_FD_PASSING: + case VIR_DRV_FEATURE_XML_MIGRATABLE: + case VIR_DRV_FEATURE_MIGRATION_OFFLINE: + case VIR_DRV_FEATURE_MIGRATION_PARAMS: + case VIR_DRV_FEATURE_MIGRATION_DIRECT: + case VIR_DRV_FEATURE_MIGRATION_V1: + case VIR_DRV_FEATURE_PROGRAM_KEEPALIVE: + case VIR_DRV_FEATURE_REMOTE: + case VIR_DRV_FEATURE_REMOTE_CLOSE_CALLBACK: + case VIR_DRV_FEATURE_REMOTE_EVENT_CALLBACK: + case VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER: + default: + return 0; } } =20 @@ -1308,6 +1309,281 @@ chDomainPinVcpu(virDomainPtr dom, VIR_DOMAIN_AFFECT_LIVE); } =20 +#define CH_NB_NUMA_PARAM 2 + +static int +chDomainGetNumaParameters(virDomainPtr dom, + virTypedParameterPtr params, + int *nparams, + unsigned int flags) +{ + size_t i; + virDomainObj *vm =3D NULL; + virDomainNumatuneMemMode tmpmode =3D VIR_DOMAIN_NUMATUNE_MEM_STRICT; + virCHDomainObjPrivate *priv; + g_autofree char *nodeset =3D NULL; + int ret =3D -1; + virDomainDef *def =3D NULL; + bool live =3D false; + virBitmap *autoNodeset =3D NULL; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_TYPED_PARAM_STRING_OKAY, -1); + + if (!(vm =3D virCHDomainObjFromDomain(dom))) + return -1; + priv =3D vm->privateData; + + if (virDomainGetNumaParametersEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!(def =3D virDomainObjGetOneDefState(vm, flags, &live))) + goto cleanup; + + if (live) + autoNodeset =3D priv->autoNodeset; + + if ((*nparams) =3D=3D 0) { + *nparams =3D CH_NB_NUMA_PARAM; + ret =3D 0; + goto cleanup; + } + + for (i =3D 0; i < CH_NB_NUMA_PARAM && i < *nparams; i++) { + virMemoryParameterPtr param =3D ¶ms[i]; + + switch (i) { + case 0: /* fill numa mode here */ + ignore_value(virDomainNumatuneGetMode(def->numa, -1, &tmpmode)= ); + + if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_MODE, + VIR_TYPED_PARAM_INT, tmpmode) < 0) + goto cleanup; + + break; + + case 1: /* fill numa nodeset here */ + nodeset =3D virDomainNumatuneFormatNodeset(def->numa, autoNode= set, -1); + + if (!nodeset || + virTypedParameterAssign(param, VIR_DOMAIN_NUMA_NODESET, + VIR_TYPED_PARAM_STRING, nodeset) <= 0) + goto cleanup; + + nodeset =3D NULL; + break; + + /* coverity[dead_error_begin] */ + default: + break; + /* should not hit here */ + } + } + + if (*nparams > CH_NB_NUMA_PARAM) + *nparams =3D CH_NB_NUMA_PARAM; + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +chDomainSetNumaParamsLive(virDomainObj *vm, + virBitmap *nodeset) +{ + virCgroup *cgroup_temp =3D NULL; + virCHDomainObjPrivate *priv =3D vm->privateData; + g_autofree char *nodeset_str =3D NULL; + virDomainNumatuneMemMode mode; + size_t i =3D 0; + int ret =3D -1; + + if (virDomainNumatuneGetMode(vm->def->numa, -1, &mode) =3D=3D 0 && + mode !=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("change of nodeset for running domain " + "requires strict numa mode")); + goto cleanup; + } + + if (!virNumaNodesetIsAvailable(nodeset)) + goto cleanup; + + /* Ensure the cpuset string is formatted before passing to cgroup */ + if (!(nodeset_str =3D virBitmapFormat(nodeset))) + goto cleanup; + + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, + false, &cgroup_temp) < 0 || + virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) + goto cleanup; + virCgroupFree(cgroup_temp); + + for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, i); + + if (!vcpu->online) + continue; + + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, i, + false, &cgroup_temp) < 0 || + virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) + goto cleanup; + virCgroupFree(cgroup_temp); + } + + for (i =3D 0; i < vm->def->niothreadids; i++) { + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHREAD, + vm->def->iothreadids[i]->iothread_id, + false, &cgroup_temp) < 0 || + virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) + goto cleanup; + virCgroupFree(cgroup_temp); + } + + /* set nodeset for root cgroup */ + if (virCgroupSetCpusetMems(priv->cgroup, nodeset_str) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virCgroupFree(cgroup_temp); + + return ret; +} + +static int +chDomainSetNumaParameters(virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virCHDriver *driver =3D dom->conn->privateData; + size_t i; + virDomainDef *def; + virDomainDef *persistentDef; + virDomainObj *vm =3D NULL; + int ret =3D -1; + g_autoptr(virCHDriverConfig) cfg =3D NULL; + virCHDomainObjPrivate *priv; + virBitmap *nodeset =3D NULL; + virDomainNumatuneMemMode config_mode; + int mode =3D -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (virTypedParamsValidate(params, nparams, + VIR_DOMAIN_NUMA_MODE, + VIR_TYPED_PARAM_INT, + VIR_DOMAIN_NUMA_NODESET, + VIR_TYPED_PARAM_STRING, + NULL) < 0) + return -1; + + if (!(vm =3D virCHDomainObjFromDomain(dom))) + return -1; + + priv =3D vm->privateData; + cfg =3D virCHDriverGetConfig(driver); + + if (virDomainSetNumaParametersEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + for (i =3D 0; i < nparams; i++) { + virTypedParameterPtr param =3D ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_NUMA_MODE)) { + mode =3D param->value.i; + + if (mode < 0 || mode >=3D VIR_DOMAIN_NUMATUNE_MEM_LAST) { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported numatune mode: '%d'"), mode); + goto cleanup; + } + + } else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) { + if (virBitmapParse(param->value.s, &nodeset, + VIR_DOMAIN_CPUMASK_LEN) < 0) + goto cleanup; + + if (virBitmapIsAllClear(nodeset)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("Invalid nodeset of 'numatune': %s"), + param->value.s); + goto cleanup; + } + } + } + + if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + if (def) { + if (!driver->privileged) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("NUMA tuning is not available in session mode= ")); + goto endjob; + } + + if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CP= USET)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cgroup cpuset controller is not mounted")); + goto endjob; + } + + if (mode !=3D -1 && + virDomainNumatuneGetMode(def->numa, -1, &config_mode) =3D=3D 0= && + config_mode !=3D mode) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("can't change numatune mode for running domai= n")); + goto endjob; + } + + if (nodeset && + chDomainSetNumaParamsLive(vm, nodeset) < 0) + goto endjob; + + if (virDomainNumatuneSet(def->numa, + def->placement_mode =3D=3D + VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC, + -1, mode, nodeset) < 0) + goto endjob; + + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) + goto endjob; + } + + /* + if (persistentDef) { + if (virDomainNumatuneSet(persistentDef->numa, + persistentDef->placement_mode =3D=3D + VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC, + -1, mode, nodeset) < 0) + goto endjob; + + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) + goto endjob; + } + */ + + ret =3D 0; + + endjob: + virCHDomainObjEndJob(vm); + + cleanup: + virBitmapFree(nodeset); + virDomainObjEndAPI(&vm); + return ret; +} + /* Function Tables */ static virHypervisorDriver chHypervisorDriver =3D { .name =3D "CH", @@ -1352,6 +1628,8 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainPinVcpu =3D chDomainPinVcpu, /* 7.11.0 */ .domainPinVcpuFlags =3D chDomainPinVcpuFlags, /* 7.11.0 */ .nodeGetCPUMap =3D chNodeGetCPUMap, /* 7.11.0 */ + .domainSetNumaParameters =3D chDomainSetNumaParameters, /* 7.11.0 */ + .domainGetNumaParameters =3D chDomainGetNumaParameters, /* 7.11.0 */ }; =20 static virConnectDriver chConnectDriver =3D { --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485842224244.24374129472824; Thu, 2 Dec 2021 14:57:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-42-na2J8lzoMmmlZW0J0759Qg-1; Thu, 02 Dec 2021 17:57:19 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1425F344B4; Thu, 2 Dec 2021 22:57:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E65295F4ED; Thu, 2 Dec 2021 22:57:13 +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 B7D264A714; Thu, 2 Dec 2021 22:57:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuTKS015642 for ; Thu, 2 Dec 2021 17:56:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1760E401E38; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10B62401E56 for ; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC1128001EA for ; Thu, 2 Dec 2021 22:56:28 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-169-FIOPKgZoOtW-LSaqVKLv9A-1; Thu, 02 Dec 2021 17:56:27 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 917FF20E6941; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: na2J8lzoMmmlZW0J0759Qg-1 X-MC-Unique: FIOPKgZoOtW-LSaqVKLv9A-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 917FF20E6941 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/17] ch_process: Setup emulator and iothread settings Date: Thu, 2 Dec 2021 22:56:13 +0000 Message-Id: <20211202225614.1118066-17-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuTKS015642 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485843536100001 Content-Type: text/plain; charset="utf-8" using virCHProcessSetupPid Signed-off-by: Praveen K Paladugu --- src/ch/ch_monitor.c | 60 ++++++++++++++++++++++++++++++++++ src/ch/ch_monitor.h | 2 ++ src/ch/ch_process.c | 78 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 138 insertions(+), 2 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index d7593d4aa6..308487b4ff 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -941,3 +941,63 @@ virCHMonitorGetInfo(virCHMonitor * mon, virJSONValue *= * info) { return virCHMonitorGet(mon, URL_VM_INFO, info); } + +/** + * virCHMonitorGetIOThreads: + * @mon: Pointer to the monitor + * @iothreads: Location to return array of IOThreadInfo data + * + * Retrieve the list of iothreads defined/running for the machine + * + * Returns count of IOThreadInfo structures on success + * -1 on error. + */ +int virCHMonitorGetIOThreads(virCHMonitor *mon, + virDomainIOThreadInfo ***iothreads) +{ + size_t nthreads =3D 0, niothreads =3D 0; + int thd_index; + virDomainIOThreadInfo **iothreadinfolist =3D NULL, *iothreadinfo =3D N= ULL; + + *iothreads =3D NULL; + nthreads =3D virCHMonitorRefreshThreadInfo(mon); + + iothreadinfolist =3D g_new0(virDomainIOThreadInfo*, nthreads); + + for (thd_index =3D 0; thd_index < nthreads; thd_index++) { + virBitmap *map =3D NULL; + if (mon->threads[thd_index].type =3D=3D virCHThreadTypeIO) { + iothreadinfo =3D g_new0(virDomainIOThreadInfo, 1); + + iothreadinfo->iothread_id =3D mon->threads[thd_index].ioInfo.t= id; + + if (!(map =3D virProcessGetAffinity(iothreadinfo->iothread_id)= )) + goto cleanup; + + if (virBitmapToData(map, &(iothreadinfo->cpumap), + &(iothreadinfo->cpumaplen)) < 0) { + virBitmapFree(map); + goto cleanup; + } + virBitmapFree(map); + //Append to iothreadinfolist + iothreadinfolist[niothreads] =3D iothreadinfo; + niothreads++; + } + } + VIR_DELETE_ELEMENT_INPLACE(iothreadinfolist, + niothreads, nthreads); + *iothreads =3D iothreadinfolist; + VIR_DEBUG("niothreads =3D %ld", niothreads); + return niothreads; + + cleanup: + if (iothreadinfolist) { + for (thd_index =3D 0; thd_index < niothreads; thd_index++) + VIR_FREE(iothreadinfolist[thd_index]); + VIR_FREE(iothreadinfolist); + } + if (iothreadinfo) + VIR_FREE(iothreadinfo); + return -1; +} diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index f8c3fa75e8..98edb0faf9 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -118,3 +118,5 @@ int virCHMonitorGetCPUInfo(virCHMonitor *mon, size_t maxvcpus); size_t virCHMonitorGetThreadInfo(virCHMonitor *mon, bool refresh, virCHMonitorThreadInfo **threads); +int virCHMonitorGetIOThreads(virCHMonitor *mon, + virDomainIOThreadInfo ***iothreads); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 7a51531224..1c0f5d0818 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -41,7 +41,6 @@ VIR_LOG_INIT("ch.ch_process"); #define START_VM_POSTFIX ": starting up vm\n" =20 =20 - static virCHMonitor * virCHProcessConnectMonitor(virCHDriver *driver, virDomainObj *vm) @@ -131,7 +130,6 @@ virCHProcessUpdateInfo(virDomainObj *vm) virCHProcessUpdateConsole(vm, info); =20 virJSONValueFree(info); - return 0; } =20 @@ -312,6 +310,74 @@ virCHProcessSetupPid(virDomainObj *vm, return ret; } =20 +static int +virCHProcessSetupIOThread(virDomainObj *vm, + virDomainIOThreadInfo *iothread) +{ + virCHDomainObjPrivate *priv =3D vm->privateData; + return virCHProcessSetupPid(vm, iothread->iothread_id, + VIR_CGROUP_THREAD_IOTHREAD, + iothread->iothread_id, + priv->autoCpuset, // This should be updated= when CLH supports accepting + // iothread settings from input domai= n definition + vm->def->cputune.iothread_period, + vm->def->cputune.iothread_quota, + NULL); // CLH doesn't allow choosing a sche= duler for iothreads. +} + +static int +virCHProcessSetupIOThreads(virDomainObj *vm) +{ + virCHDomainObjPrivate *priv =3D vm->privateData; + virDomainIOThreadInfo **iothreads =3D NULL; + size_t i; + size_t niothreads; + + niothreads =3D virCHMonitorGetIOThreads(priv->monitor, &iothreads); + for (i =3D 0; i < niothreads; i++) { + VIR_DEBUG("IOThread index =3D %ld , tid =3D %d", i, iothreads[i]->= iothread_id); + if (virCHProcessSetupIOThread(vm, iothreads[i]) < 0) + return -1; + } + return 0; +} + + +static int +virCHProcessSetupEmulatorThread(virDomainObj *vm, + virCHMonitorEmuThreadInfo emuthread) +{ + return virCHProcessSetupPid(vm, emuthread.tid, VIR_CGROUP_THREAD_EMULA= TOR, + 0, vm->def->cputune.emulatorpin, + vm->def->cputune.emulator_period, + vm->def->cputune.emulator_quota, + vm->def->cputune.emulatorsched); +} + +static int +virCHProcessSetupEmulatorThreads(virDomainObj *vm) +{ + int thd_index =3D 0; + virCHDomainObjPrivate *priv =3D vm->privateData; + /* + * Cloud-hypervisor start 4 Emulator threads by default: + * vmm + * cloud-hypervisor + * http-server + * signal_handler + */ + for (thd_index =3D 0; thd_index < priv->monitor->nthreads; thd_index++= ) { + if (priv->monitor->threads[thd_index].type =3D=3D virCHThreadTypeE= mulator) { + VIR_DEBUG("Setup tid =3D %d (%s) Emulator thread", priv->monit= or->threads[thd_index].emuInfo.tid, + priv->monitor->threads[thd_index].emuInfo.thrName); + + if (virCHProcessSetupEmulatorThread(vm, priv->monitor->threads= [thd_index].emuInfo) < 0) + return -1; + } + } + return 0; +} + /** * virCHProcessSetupVcpu: * @vm: domain object @@ -443,6 +509,14 @@ virCHProcessStart(virCHDriver * driver, =20 virCHDomainRefreshThreadInfo(vm); =20 + VIR_DEBUG("Setting emulator tuning/settings"); + if (virCHProcessSetupEmulatorThreads(vm) < 0) + goto cleanup; + + VIR_DEBUG("Setting iothread tuning/settings"); + if (virCHProcessSetupIOThreads(vm) < 0) + goto cleanup; + VIR_DEBUG("Setting global CPU cgroup (if required)"); if (virSetupGlobalCpuCgroup(vm, priv->cgroup, priv->autoNodeset) < 0) goto cleanup; --=20 2.27.0 From nobody Sun Apr 28 04:55:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638485846865744.889302188653; Thu, 2 Dec 2021 14:57:26 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-18-f2HfjpRyOKmSqxeHzcyq6A-1; Thu, 02 Dec 2021 17:57:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D608B1018723; Thu, 2 Dec 2021 22:57:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8D3D45D6C; Thu, 2 Dec 2021 22:57:19 +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 86BC24A715; Thu, 2 Dec 2021 22:57:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2MuVDS015660 for ; Thu, 2 Dec 2021 17:56:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 00CC42026D5D; Thu, 2 Dec 2021 22:56:31 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFFAB2026D46 for ; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19DE0811E7F for ; Thu, 2 Dec 2021 22:56:29 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-401-dCkweaJyOyaOLMvhCpMOLQ-3; Thu, 02 Dec 2021 17:56:27 -0500 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id A961B20E67A0; Thu, 2 Dec 2021 14:56:25 -0800 (PST) X-MC-Unique: f2HfjpRyOKmSqxeHzcyq6A-1 X-MC-Unique: dCkweaJyOyaOLMvhCpMOLQ-3 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A961B20E67A0 From: Praveen K Paladugu To: libvir-list@redhat.com Subject: [libvirt PATCH v2 17/17] ch_driver: emulator threadinfo & pinning callbacks Date: Thu, 2 Dec 2021 22:56:14 +0000 Message-Id: <20211202225614.1118066-18-prapal@linux.microsoft.com> In-Reply-To: <20211202225614.1118066-1-prapal@linux.microsoft.com> References: <20211202225614.1118066-1-prapal@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2MuVDS015660 X-loop: libvir-list@redhat.com Cc: william.douglas@intel.com, viremana@linux.microsoft.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638485848052100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- src/ch/ch_driver.c | 154 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 8c14829d2a..100c54163e 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1309,6 +1309,158 @@ chDomainPinVcpu(virDomainPtr dom, VIR_DOMAIN_AFFECT_LIVE); } =20 + + +static int +chDomainGetEmulatorPinInfo(virDomainPtr dom, + unsigned char *cpumaps, + int maplen, + unsigned int flags) +{ + virDomainObj *vm =3D NULL; + virDomainDef *def; + virCHDomainObjPrivate *priv; + bool live; + int ret =3D -1; + virBitmap *cpumask =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; + virBitmap *autoCpuset =3D NULL; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetEmulatorPinInfoEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!(def =3D virDomainObjGetOneDefState(vm, flags, &live))) + goto cleanup; + + if (live) { + priv =3D vm->privateData; + autoCpuset =3D priv->autoCpuset; + } + if (def->cputune.emulatorpin) { + cpumask =3D def->cputune.emulatorpin; + } else if (def->cpumask) { + cpumask =3D def->cpumask; + } else if (vm->def->placement_mode =3D=3D VIR_DOMAIN_CPU_PLACEMENT_MOD= E_AUTO && + autoCpuset) { + cpumask =3D autoCpuset; + } else { + if (!(bitmap =3D virHostCPUGetAvailableCPUsBitmap())) + goto cleanup; + cpumask =3D bitmap; + } + + virBitmapToDataBuf(cpumask, cpumaps, maplen); + + ret =3D 1; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +chDomainPinEmulator(virDomainPtr dom, + unsigned char *cpumap, + int maplen, + unsigned int flags) +{ + virCHDriver *driver =3D dom->conn->privateData; + virDomainObj *vm; + virCgroup *cgroup_emulator =3D NULL; + virDomainDef *def; + virDomainDef *persistentDef; + int ret =3D -1; + virCHDomainObjPrivate *priv; + virBitmap *pcpumap =3D NULL; + g_autoptr(virCHDriverConfig) cfg =3D NULL; + g_autofree char *str =3D NULL; + virTypedParameterPtr eventParams =3D NULL; + int eventNparams =3D 0; + int eventMaxparams =3D 0; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + cfg =3D virCHDriverGetConfig(driver); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainPinEmulatorEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + priv =3D vm->privateData; + + if (!(pcpumap =3D virBitmapNewData(cpumap, maplen))) + goto endjob; + + if (virBitmapIsAllClear(pcpumap)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Empty cpu list for pinning")); + goto endjob; + } + + if (def) { + if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU= SET)) { + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATO= R, + 0, false, &cgroup_emulator) < 0) + goto endjob; + + if (virSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("failed to set cpuset.cpus in cgroup" + " for emulator threads")); + goto endjob; + } + } + + if (virProcessSetAffinity(vm->pid, pcpumap, false) < 0) + goto endjob; + + virBitmapFree(def->cputune.emulatorpin); + def->cputune.emulatorpin =3D NULL; + + if (!(def->cputune.emulatorpin =3D virBitmapNewCopy(pcpumap))) + goto endjob; + + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) + goto endjob; + + str =3D virBitmapFormat(pcpumap); + if (virTypedParamsAddString(&eventParams, &eventNparams, + &eventMaxparams, + VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN, + str) < 0) + goto endjob; + + } + + + ret =3D 0; + + endjob: + virCHDomainObjEndJob(vm); + + cleanup: + if (cgroup_emulator) + virCgroupFree(cgroup_emulator); + virBitmapFree(pcpumap); + virDomainObjEndAPI(&vm); + return ret; +} + #define CH_NB_NUMA_PARAM 2 =20 static int @@ -1627,6 +1779,8 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainGetVcpuPinInfo =3D chDomainGetVcpuPinInfo, /* 7.11.0 */ .domainPinVcpu =3D chDomainPinVcpu, /* 7.11.0 */ .domainPinVcpuFlags =3D chDomainPinVcpuFlags, /* 7.11.0 */ + .domainPinEmulator =3D chDomainPinEmulator, /* 7.11.0 */ + .domainGetEmulatorPinInfo =3D chDomainGetEmulatorPinInfo, /* 7.11.0 */ .nodeGetCPUMap =3D chNodeGetCPUMap, /* 7.11.0 */ .domainSetNumaParameters =3D chDomainSetNumaParameters, /* 7.11.0 */ .domainGetNumaParameters =3D chDomainGetNumaParameters, /* 7.11.0 */ --=20 2.27.0