From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643836426325.3859809384362; Fri, 21 Jul 2017 06:30:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E59C08E3E9; Fri, 21 Jul 2017 13:30:31 +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 3E86317B8F; Fri, 21 Jul 2017 13:30:31 +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 D1487180B467; Fri, 21 Jul 2017 13:30:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDUO2Z023794 for ; Fri, 21 Jul 2017 09:30:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id EAAF88BE20; Fri, 21 Jul 2017 13:30:24 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B2A58B33A for ; Fri, 21 Jul 2017 13:30:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E59C08E3E9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E59C08E3E9 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:09 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/7] util: introduce virFileCache 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Jul 2017 13:30:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new virFileCache will nicely handle the caching logic for any data that we would like to cache. For each type of data we will just need to implement few handlers that will take care of creating, validating, loading and saving the cached data. The cached data must be an instance of virObject. Currently we cache QEMU capabilities which will start using virFileCache. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: Changes in v2: - added suffix argument into virFileCacheNew() - fixed locking for virFileCache APIs - moved virObjectUnref() into virFileCacheLoad() po/POTFILES.in | 1 + src/Makefile.am | 1 + src/libvirt_private.syms | 9 + src/util/virfilecache.c | 439 +++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virfilecache.h | 137 +++++++++++++++ 5 files changed, 587 insertions(+) create mode 100644 src/util/virfilecache.c create mode 100644 src/util/virfilecache.h diff --git a/po/POTFILES.in b/po/POTFILES.in index b3891b5877..c1fa23427e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -211,6 +211,7 @@ src/util/vireventpoll.c src/util/virfcp.c src/util/virfdstream.c src/util/virfile.c +src/util/virfilecache.c src/util/virfirewall.c src/util/virfirmware.c src/util/virhash.c diff --git a/src/Makefile.am b/src/Makefile.am index e637dfd910..d86b282519 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -194,6 +194,7 @@ UTIL_SOURCES =3D \ util/virxdrdefs.h \ util/virxml.c util/virxml.h \ util/virmdev.c util/virmdev.h \ + util/virfilecache.c util/virfilecache.h \ $(NULL) =20 EXTRA_DIST +=3D \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a35ad0f859..28dad7149b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1711,6 +1711,15 @@ virFileWriteStr; virFindFileInPath; =20 =20 +# util/virfilecache.h +virFileCacheGetPriv; +virFileCacheInsertData; +virFileCacheLookup; +virFileCacheLookupByFunc; +virFileCacheNew; +virFileCacheSetPriv; + + # util/virfirewall.h virFirewallAddRuleFull; virFirewallApply; diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c new file mode 100644 index 0000000000..0401253146 --- /dev/null +++ b/src/util/virfilecache.c @@ -0,0 +1,439 @@ +/* + * virfilecache.c: file caching for data + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + + +#include + +#include "internal.h" + +#include "viralloc.h" +#include "virbuffer.h" +#include "vircrypto.h" +#include "virerror.h" +#include "virfile.h" +#include "virfilecache.h" +#include "virhash.h" +#include "virlog.h" +#include "virobject.h" +#include "virstring.h" + +#include +#include +#include + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("util.filecache") + + +struct _virFileCache { + virObjectLockable object; + + virHashTablePtr table; + + char *dir; + char *suffix; + + void *priv; + + virFileCacheHandlers handlers; +}; + + +static virClassPtr virFileCacheClass; + + +static void +virFileCachePrivFree(virFileCachePtr cache) +{ + if (cache->priv && cache->handlers.privFree) + cache->handlers.privFree(cache->priv); +} + + +static void +virFileCacheDispose(void *obj) +{ + virFileCachePtr cache =3D obj; + + VIR_FREE(cache->dir); + VIR_FREE(cache->suffix); + + virHashFree(cache->table); + + virFileCachePrivFree(cache); +} + + +static int +virFileCacheOnceInit(void) +{ + if (!(virFileCacheClass =3D virClassNew(virClassForObjectLockable(), + "virFileCache", + sizeof(virFileCache), + virFileCacheDispose))) + return -1; + + return 0; +} + + +VIR_ONCE_GLOBAL_INIT(virFileCache) + + +static char * +virFileCacheGetFileName(virFileCachePtr cache, + const char *name) +{ + char *file =3D NULL; + char *namehash =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &namehash) < 0) + goto cleanup; + + if (virFileMakePath(cache->dir) < 0) { + virReportSystemError(errno, + _("Unable to create directory '%s'"), + cache->dir); + goto cleanup; + } + + virBufferAsprintf(&buf, "%s/%s", cache->dir, namehash); + + if (cache->suffix) + virBufferAsprintf(&buf, ".%s", cache->suffix); + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + file =3D virBufferContentAndReset(&buf); + + cleanup: + VIR_FREE(namehash); + return file; +} + + +static int +virFileCacheLoad(virFileCachePtr cache, + const char *name, + void **data) +{ + char *file =3D NULL; + int ret =3D -1; + void *loadData =3D NULL; + + *data =3D NULL; + + if (!(file =3D virFileCacheGetFileName(cache, name))) + return ret; + + if (!virFileExists(file)) { + if (errno =3D=3D ENOENT) { + VIR_DEBUG("No cached data '%s' for '%s'", file, name); + ret =3D 0; + goto cleanup; + } + virReportSystemError(errno, + _("Unable to access cache '%s' for '%s'"), + file, name); + goto cleanup; + } + + if (!(loadData =3D cache->handlers.loadFile(file, name, cache->priv)))= { + virErrorPtr err =3D virGetLastError(); + VIR_WARN("Failed to load cached data from '%s' for '%s': %s", + file, name, err ? NULLSTR(err->message) : "unknown error"= ); + virResetLastError(); + ret =3D 0; + goto cleanup; + } + + if (!cache->handlers.isValid(loadData, cache->priv)) { + VIR_DEBUG("Outdated cached capabilities '%s' for '%s'", file, name= ); + ignore_value(unlink(file)); + ret =3D 0; + goto cleanup; + } + + VIR_DEBUG("Loaded cached data '%s' for '%s'", file, name); + + ret =3D 1; + VIR_STEAL_PTR(*data, loadData); + + cleanup: + virObjectUnref(loadData); + VIR_FREE(file); + return ret; +} + + +static int +virFileCacheSave(virFileCachePtr cache, + const char *name, + void *data) +{ + char *file =3D NULL; + int ret =3D -1; + + if (!(file =3D virFileCacheGetFileName(cache, name))) + return ret; + + if (cache->handlers.saveFile(data, file, cache->priv) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(file); + return ret; +} + + +static void * +virFileCacheNewData(virFileCachePtr cache, + const char *name) +{ + void *data =3D NULL; + int rv; + + if ((rv =3D virFileCacheLoad(cache, name, &data)) < 0) + return NULL; + + if (rv =3D=3D 0) { + if (!(data =3D cache->handlers.newData(name, cache->priv))) + return NULL; + + if (virFileCacheSave(cache, name, data) < 0) { + virObjectUnref(data); + data =3D NULL; + } + } + + return data; +} + + +/** + * virFileCacheNew: + * @dir: the cache directory where all the cache files will be stored + * @suffix: the cache file suffix or NULL if no suffix is required + * @handlers: filled structure with all required handlers + * + * Creates a new cache object which handles caching any data to files + * stored on a filesystem. + * + * Returns new cache object or NULL on error. + */ +virFileCachePtr +virFileCacheNew(const char *dir, + const char *suffix, + virFileCacheHandlers handlers) +{ + virFileCachePtr cache; + + if (virFileCacheInitialize() < 0) + return NULL; + + if (!(cache =3D virObjectNew(virFileCacheClass))) + return NULL; + + if (!(cache->table =3D virHashCreate(10, virObjectFreeHashData))) + goto cleanup; + + if (VIR_STRDUP(cache->dir, dir) < 0) + goto cleanup; + + if (VIR_STRDUP(cache->suffix, suffix) < 0) + goto cleanup; + + cache->handlers =3D handlers; + + return cache; + + cleanup: + virObjectUnref(cache); + return NULL; +} + + +static void +virFileCacheValidate(virFileCachePtr cache, + const char *name, + void **data) +{ + if (*data && !cache->handlers.isValid(*data, cache->priv)) { + VIR_DEBUG("Cached data '%p' no longer valid for '%s'", + *data, NULLSTR(name)); + if (name) + virHashRemoveEntry(cache->table, name); + *data =3D NULL; + } + + if (!*data && name) { + VIR_DEBUG("Creating data for '%s'", name); + *data =3D virFileCacheNewData(cache, name); + if (*data) { + VIR_DEBUG("Caching data '%p' for '%s'", *data, name); + if (virHashAddEntry(cache->table, name, *data) < 0) { + virObjectUnref(*data); + *data =3D NULL; + } + } + } +} + + +/** + * virFileCacheLookup: + * @cache: existing cache object + * @name: name of the data stored in a cache + * + * Lookup a data specified by name. This tries to find a file with + * cached data, if it doesn't exist or is no longer valid new data + * is created. + * + * Returns data object or NULL on error. The caller is responsible for + * unrefing the data. + */ +void * +virFileCacheLookup(virFileCachePtr cache, + const char *name) +{ + void *data =3D NULL; + + virObjectLock(cache); + + data =3D virHashLookup(cache->table, name); + virFileCacheValidate(cache, name, &data); + + virObjectRef(data); + virObjectUnlock(cache); + + return data; +} + + +/** + * virFileCacheLookupByFunc: + * @cache: existing cache object + * @iter: an iterator to identify the desired data + * @iterData: extra opaque information passed to the @iter + * + * Similar to virFileCacheLookup() except it search by @iter. + * + * Returns data object or NULL on error. The caller is responsible for + * unrefing the data. + */ +void * +virFileCacheLookupByFunc(virFileCachePtr cache, + virHashSearcher iter, + const void *iterData) +{ + void *data =3D NULL; + char *name =3D NULL; + + virObjectLock(cache); + + data =3D virHashSearch(cache->table, iter, iterData, (void **)&name); + virFileCacheValidate(cache, name, &data); + + virObjectRef(data); + virObjectUnlock(cache); + + VIR_FREE(name); + + return data; +} + + +/** + * virFileCacheGetPriv: + * @cache: existing cache object + * + * Returns private data used by @handlers. + */ +void * +virFileCacheGetPriv(virFileCachePtr cache) +{ + void *priv; + + virObjectLock(cache); + + priv =3D cache->priv; + + virObjectUnlock(cache); + + return priv; +} + + +/** + * virFileCacheSetPriv: + * @cache: existing cache object + * @priv: private data to set + * + * Sets private data used by @handlers. If there is already some @priv + * set, privFree() will be called on the old @priv before setting a new on= e. + */ +void +virFileCacheSetPriv(virFileCachePtr cache, + void *priv) +{ + virObjectLock(cache); + + virFileCachePrivFree(cache); + + cache->priv =3D priv; + + virObjectUnlock(cache); +} + + +/** + * virFileCacheInsertData: + * @cache: existing cache object + * @name: name of the new data + * @data: the actual data object to store in cache + * + * Adds a new data into a cache but doesn't store the data into + * a file. This function should be used only by testing code. + * + * Returns 0 on success, -1 on error. + */ +int +virFileCacheInsertData(virFileCachePtr cache, + const char *name, + void *data) +{ + int rc; + + virObjectLock(cache); + + rc =3D virHashUpdateEntry(cache->table, name, data); + + virObjectUnlock(cache); + + if (rc < 0) + return -1; + return 0; +} diff --git a/src/util/virfilecache.h b/src/util/virfilecache.h new file mode 100644 index 0000000000..ae53841fd9 --- /dev/null +++ b/src/util/virfilecache.h @@ -0,0 +1,137 @@ +/* + * virfilecache.h: file caching for data + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef __VIR_FILE_CACHE_H__ +# define __VIR_FILE_CACHE_H__ + +# include "internal.h" + +# include "virobject.h" +# include "virhash.h" + +typedef struct _virFileCache virFileCache; +typedef virFileCache *virFileCachePtr; + +/** + * virFileCacheIsValidPtr: + * @data: data object to validate + * @priv: private data created together with cache + * + * Validates the cached data whether it needs to be refreshed + * or no. + * + * Returns *true* if it's valid or *false* if not valid. + */ +typedef bool +(*virFileCacheIsValidPtr)(void *data, + void *priv); + +/** + * virFileCacheNewDataPtr: + * @name: name of the new data + * @priv: private data created together with cache + * + * Creates a new data based on the @name. The returned data must be + * an instance of virObject. + * + * Returns data object or NULL on error. + */ +typedef void * +(*virFileCacheNewDataPtr)(const char *name, + void *priv); + +/** + * virFileCacheLoadFilePtr: + * @filename: name of a file with cached data + * @name: name of the cached data + * @priv: private data created together with cache + * + * Loads the cached data from a file @filename. + * + * Returns cached data object or NULL on error. + */ +typedef void * +(*virFileCacheLoadFilePtr)(const char *filename, + const char *name, + void *priv); + +/** + * virFileCacheSaveFilePtr: + * @data: data object to save into a file + * @filename: name of the file where to store the cached data + * @priv: private data created together with cache + * + * Stores the cached to a file @filename. + * + * Returns 0 on success, -1 on error. + */ +typedef int +(*virFileCacheSaveFilePtr)(void *data, + const char *filename, + void *priv); + +/** + * virFileCachePrivFreePtr: + * @priv: private data created together with cache + * + * This is used to free the private data when the cache object + * is removed. + */ +typedef void +(*virFileCachePrivFreePtr)(void *priv); + +typedef struct _virFileCacheHandlers virFileCacheHandlers; +typedef virFileCacheHandlers *virFileCacheHandlersPtr; +struct _virFileCacheHandlers { + virFileCacheIsValidPtr isValid; + virFileCacheNewDataPtr newData; + virFileCacheLoadFilePtr loadFile; + virFileCacheSaveFilePtr saveFile; + virFileCachePrivFreePtr privFree; +}; + +virFileCachePtr +virFileCacheNew(const char *dir, + const char *suffix, + virFileCacheHandlers handlers); + +void * +virFileCacheLookup(virFileCachePtr cache, + const char *name); + +void * +virFileCacheLookupByFunc(virFileCachePtr cache, + virHashSearcher iter, + const void *iterData); + +void * +virFileCacheGetPriv(virFileCachePtr cache); + +void +virFileCacheSetPriv(virFileCachePtr cache, + void *priv); + +int +virFileCacheInsertData(virFileCachePtr cache, + const char *name, + void *data); + +#endif /* __VIR_FILE_CACHE_H__ */ --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643836759185.60835111182905; Fri, 21 Jul 2017 06:30:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4DB83C0467D5; Fri, 21 Jul 2017 13:30:32 +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 E1265900AB; Fri, 21 Jul 2017 13:30:31 +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 EF8D84BB79; Fri, 21 Jul 2017 13:30:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDUT7A023813 for ; Fri, 21 Jul 2017 09:30:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6A1A8B306; Fri, 21 Jul 2017 13:30:29 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CB288B304 for ; Fri, 21 Jul 2017 13:30:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4DB83C0467D5 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4DB83C0467D5 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:10 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/7] tests: add virfilecachetest 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Jul 2017 13:30:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Implements 3 test cases that covers how the cache is used. We have to mock unlink() function because the caching code unlinks files that are no longer valid and we don't want to do it in our tests. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: Changes in v2: - added tests/virfilecachemock.c - specify suffix for virFileCacheNew() tests/Makefile.am | 12 ++ ...a15b1658aa16923e46497dd8deeb6be287ddb0ca0.cache | 1 + ...ae4bc3a28e75bc3e262757001e8b953580f5e75ef.cache | 1 + tests/virfilecachemock.c | 31 +++ tests/virfilecachetest.c | 238 +++++++++++++++++= ++++ 5 files changed, 283 insertions(+) create mode 100644 tests/virfilecachedata/5f3154560c130108b282a2aa15b1658a= a16923e46497dd8deeb6be287ddb0ca0.cache create mode 120000 tests/virfilecachedata/9ca150bf3119b75dcac8e8bae4bc3a28= e75bc3e262757001e8b953580f5e75ef.cache create mode 100644 tests/virfilecachemock.c create mode 100644 tests/virfilecachetest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 5be81d2213..562c1c7717 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -182,6 +182,7 @@ test_programs =3D virshtest sockettest \ virpcitest \ virendiantest \ virfiletest \ + virfilecachetest \ virfirewalltest \ viriscsitest \ virkeycodetest \ @@ -211,6 +212,7 @@ test_libraries =3D libshunload.la \ virrandommock.la \ virhostcpumock.la \ domaincapsmock.la \ + virfilecachemock.la \ $(NULL) =20 if WITH_REMOTE @@ -1137,6 +1139,12 @@ virhostcpumock_la_CFLAGS =3D $(AM_CFLAGS) virhostcpumock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) virhostcpumock_la_LIBADD =3D $(MOCKLIBS_LIBS) =20 +virfilecachemock_la_SOURCES =3D \ + virfilecachemock.c +virfilecachemock_la_CFLAGS =3D $(AM_CFLAGS) +virfilecachemock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) +virfilecachemock_la_LIBADD =3D $(MOCKLIBS_LIBS) + if WITH_LINUX vircaps2xmltest_SOURCES =3D \ vircaps2xmltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper= .c @@ -1369,6 +1377,10 @@ virfiletest_SOURCES =3D \ virfiletest.c testutils.h testutils.c virfiletest_LDADD =3D $(LDADDS) =20 +virfilecachetest_SOURCES =3D \ + virfilecachetest.c testutils.h testutils.c +virfilecachetest_LDADD =3D $(LDADDS) + virfirewalltest_SOURCES =3D \ virfirewalltest.c testutils.h testutils.c virfirewalltest_LDADD =3D $(LDADDS) $(DBUS_LIBS) diff --git a/tests/virfilecachedata/5f3154560c130108b282a2aa15b1658aa16923e= 46497dd8deeb6be287ddb0ca0.cache b/tests/virfilecachedata/5f3154560c130108b2= 82a2aa15b1658aa16923e46497dd8deeb6be287ddb0ca0.cache new file mode 100644 index 0000000000..72943a16fb --- /dev/null +++ b/tests/virfilecachedata/5f3154560c130108b282a2aa15b1658aa16923e46497dd= 8deeb6be287ddb0ca0.cache @@ -0,0 +1 @@ +aaa diff --git a/tests/virfilecachedata/9ca150bf3119b75dcac8e8bae4bc3a28e75bc3e= 262757001e8b953580f5e75ef.cache b/tests/virfilecachedata/9ca150bf3119b75dca= c8e8bae4bc3a28e75bc3e262757001e8b953580f5e75ef.cache new file mode 120000 index 0000000000..94df26de63 --- /dev/null +++ b/tests/virfilecachedata/9ca150bf3119b75dcac8e8bae4bc3a28e75bc3e2627570= 01e8b953580f5e75ef.cache @@ -0,0 +1 @@ +5f3154560c130108b282a2aa15b1658aa16923e46497dd8deeb6be287ddb0ca0.cache \ No newline at end of file diff --git a/tests/virfilecachemock.c b/tests/virfilecachemock.c new file mode 100644 index 0000000000..a7476bce2e --- /dev/null +++ b/tests/virfilecachemock.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#include + +#include + +#include "internal.h" + + +int +unlink(const char *path ATTRIBUTE_UNUSED) +{ + return 0; +} diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c new file mode 100644 index 0000000000..1a6ff62109 --- /dev/null +++ b/tests/virfilecachetest.c @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#include + +#include "testutils.h" +#include "virfile.h" +#include "virfilecache.h" + + +#define VIR_FROM_THIS VIR_FROM_NONE + + +struct _testFileCacheObj { + virObject object; + char *data; +}; +typedef struct _testFileCacheObj testFileCacheObj; +typedef testFileCacheObj *testFileCacheObjPtr; + + +static virClassPtr testFileCacheObjClass; + + +static void +testFileCacheObjDispose(void *opaque) +{ + testFileCacheObjPtr obj =3D opaque; + VIR_FREE(obj->data); +} + + +static int +testFileCacheObjOnceInit(void) +{ + if (!(testFileCacheObjClass =3D virClassNew(virClassForObject(), + "testFileCacheObj", + sizeof(testFileCacheObj), + testFileCacheObjDispose))) + return -1; + + return 0; +} + + +VIR_ONCE_GLOBAL_INIT(testFileCacheObj) + + +static testFileCacheObjPtr +testFileCacheObjNew(const char *data) +{ + testFileCacheObjPtr obj; + + if (testFileCacheObjInitialize() < 0) + return NULL; + + if (!(obj =3D virObjectNew(testFileCacheObjClass))) + return NULL; + + if (VIR_STRDUP(obj->data, data) < 0) + goto error; + + return obj; + + error: + virObjectUnref(obj); + return NULL; +} + + +struct _testFileCachePriv { + bool dataSaved; + const char *newData; + const char *expectData; +}; +typedef struct _testFileCachePriv testFileCachePriv; +typedef testFileCachePriv *testFileCachePrivPtr; + + +static bool +testFileCacheIsValid(void *data, + void *priv) +{ + testFileCachePrivPtr testPriv =3D priv; + testFileCacheObjPtr obj =3D data; + + return STREQ(testPriv->expectData, obj->data); +} + + +static void * +testFileCacheNewData(const char *name ATTRIBUTE_UNUSED, + void *priv) +{ + testFileCachePrivPtr testPriv =3D priv; + + return testFileCacheObjNew(testPriv->newData); +} + + +static void * +testFileCacheLoadFile(const char *filename, + const char *name ATTRIBUTE_UNUSED, + void *priv ATTRIBUTE_UNUSED) +{ + testFileCacheObjPtr obj; + char *data; + + if (virFileReadAll(filename, 20, &data) < 0) + return NULL; + + obj =3D testFileCacheObjNew(data); + + VIR_FREE(data); + return obj; +} + + +static int +testFileCacheSaveFile(void *data ATTRIBUTE_UNUSED, + const char *filename ATTRIBUTE_UNUSED, + void *priv) +{ + testFileCachePrivPtr testPriv =3D priv; + + testPriv->dataSaved =3D true; + + return 0; +} + + +virFileCacheHandlers testFileCacheHandlers =3D { + .isValid =3D testFileCacheIsValid, + .newData =3D testFileCacheNewData, + .loadFile =3D testFileCacheLoadFile, + .saveFile =3D testFileCacheSaveFile +}; + + +struct _testFileCacheData { + virFileCachePtr cache; + const char *name; + const char *newData; + const char *expectData; + bool expectSave; +}; +typedef struct _testFileCacheData testFileCacheData; +typedef testFileCacheData *testFileCacheDataPtr; + + +static int +testFileCache(const void *opaque) +{ + int ret =3D -1; + const testFileCacheData *data =3D opaque; + testFileCacheObjPtr obj =3D NULL; + testFileCachePrivPtr testPriv =3D virFileCacheGetPriv(data->cache); + + testPriv->dataSaved =3D false; + testPriv->newData =3D data->newData; + testPriv->expectData =3D data->expectData; + + if (!(obj =3D virFileCacheLookup(data->cache, data->name))) { + fprintf(stderr, "Getting cached data failed.\n"); + goto cleanup; + } + + if (!obj->data || STRNEQ(data->expectData, obj->data)) { + fprintf(stderr, "Expect data '%s', loaded data '%s'.\n", + data->expectData, NULLSTR(obj->data)); + goto cleanup; + } + + if (data->expectSave !=3D testPriv->dataSaved) { + fprintf(stderr, "Expect data to be saved '%s', data saved '%s'.\n", + data->expectSave ? "yes" : "no", + testPriv->dataSaved ? "yes" : "no"); + goto cleanup; + } + + ret =3D 0; + + cleanup: + virObjectUnref(obj); + return ret; +} + + +static int +mymain(void) +{ + int ret =3D 0; + testFileCachePriv testPriv =3D {0}; + virFileCachePtr cache =3D NULL; + + if (!(cache =3D virFileCacheNew(abs_srcdir "/virfilecachedata", + "cache", testFileCacheHandlers))) + return EXIT_FAILURE; + + virFileCacheSetPriv(cache, &testPriv); + +#define TEST_RUN(name, newData, expectData, expectSave) = \ + do { = \ + testFileCacheData data =3D { = \ + cache, name, newData, expectData, expectSave = \ + }; = \ + if (virTestRun(name, testFileCache, &data) < 0) = \ + ret =3D -1; = \ + } while (0) + + /* The cache file name is created using: + * '$ echo -n $TEST_NAME | sha256sum' */ + TEST_RUN("cacheValid", NULL, "aaa\n", false); + TEST_RUN("cacheInvalid", "bbb\n", "bbb\n", true); + TEST_RUN("cacheMissing", "ccc\n", "ccc\n", true); + + virObjectUnref(cache); + + return ret !=3D 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} + +VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virfilecachemock.so") --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643871271527.4862410291822; Fri, 21 Jul 2017 06:31:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83F13C0467C1; Fri, 21 Jul 2017 13:31: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 5CE5C80B2B; Fri, 21 Jul 2017 13:31: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 1B70B14B20; Fri, 21 Jul 2017 13:31:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDUe0X023828 for ; Fri, 21 Jul 2017 09:30:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3854E8B304; Fri, 21 Jul 2017 13:30:40 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B48758BE3C for ; Fri, 21 Jul 2017 13:30:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83F13C0467C1 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 83F13C0467C1 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:11 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/7] qemu: introduce struct _virQEMUCapsCachePriv 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Jul 2017 13:31:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will store private data that will be used by following patches when switching to virFileCache. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++--------------= ---- src/qemu/qemu_capspriv.h | 12 ++++++++--- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b7351322bc..c310e97f61 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3764,6 +3764,14 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps, } =20 =20 +static void +virQEMUCapsCachePrivFree(virQEMUCapsCachePrivPtr priv) +{ + VIR_FREE(priv->libDir); + VIR_FREE(priv); +} + + /* * Parsing a doc that looks like * @@ -4252,8 +4260,7 @@ virQEMUCapsRememberCached(virQEMUCapsPtr qemuCaps, co= nst char *cacheDir) =20 static bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - uid_t runUid, - gid_t runGid) + virQEMUCapsCachePrivPtr priv) { bool kvmUsable; struct stat sb; @@ -4290,7 +4297,7 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, } =20 kvmUsable =3D virFileAccessibleAs("/dev/kvm", R_OK | W_OK, - runUid, runGid) =3D=3D 0; + priv->runUid, priv->runGid) =3D=3D 0; =20 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) && @@ -4318,8 +4325,7 @@ virQEMUCapsInitCached(virCapsPtr caps, virQEMUCapsPtr *qemuCaps, const char *binary, const char *cacheDir, - uid_t runUid, - gid_t runGid) + virQEMUCapsCachePrivPtr priv) { char *capsdir =3D NULL; char *capsfile =3D NULL; @@ -4370,7 +4376,7 @@ virQEMUCapsInitCached(virCapsPtr caps, goto discard; } =20 - if (!virQEMUCapsIsValid(qemuCapsNew, runUid, runGid)) + if (!virQEMUCapsIsValid(qemuCapsNew, priv)) goto discard; =20 VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=3D%d", @@ -5275,22 +5281,21 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, static virQEMUCapsPtr virQEMUCapsNewForBinary(virCapsPtr caps, const char *binary, - const char *libDir, const char *cacheDir, - uid_t runUid, - gid_t runGid) + virQEMUCapsCachePrivPtr priv) { int rv; virQEMUCapsPtr qemuCaps =3D NULL; =20 - if ((rv =3D virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir, - runUid, runGid)) < 0) + if ((rv =3D virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir, p= riv)) < 0) goto error; =20 if (rv =3D=3D 0) { if (!(qemuCaps =3D virQEMUCapsNewForBinaryInternal(caps, binary, - libDir, runUid, - runGid, false))) { + priv->libDir, + priv->runUid, + priv->runGid, + false))) { goto error; } =20 @@ -5364,13 +5369,17 @@ virQEMUCapsCacheNew(const char *libDir, =20 if (!(cache->binaries =3D virHashCreate(10, virObjectFreeHashData))) goto error; - if (VIR_STRDUP(cache->libDir, libDir) < 0) - goto error; if (VIR_STRDUP(cache->cacheDir, cacheDir) < 0) goto error; =20 - cache->runUid =3D runUid; - cache->runGid =3D runGid; + if (VIR_ALLOC(cache->priv) < 0) + goto error; + + if (VIR_STRDUP(cache->priv->libDir, libDir) < 0) + goto error; + + cache->priv->runUid =3D runUid; + cache->priv->runGid =3D runGid; =20 return cache; =20 @@ -5387,7 +5396,7 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, virQEMUCapsPtr *qemuCaps) { if (*qemuCaps && - !virQEMUCapsIsValid(*qemuCaps, cache->runUid, cache->runGid)) { + !virQEMUCapsIsValid(*qemuCaps, cache->priv)) { VIR_DEBUG("Cached capabilities %p no longer valid for %s", *qemuCaps, binary); virHashRemoveEntry(cache->binaries, binary); @@ -5397,8 +5406,8 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, if (!*qemuCaps) { VIR_DEBUG("Creating capabilities for %s", binary); *qemuCaps =3D virQEMUCapsNewForBinary(caps, binary, - cache->libDir, cache->cacheDir, - cache->runUid, cache->runGid); + cache->cacheDir, + cache->priv); if (*qemuCaps) { VIR_DEBUG("Caching capabilities %p for %s", *qemuCaps, binary); if (virHashAddEntry(cache->binaries, binary, *qemuCaps) < 0) { @@ -5517,7 +5526,7 @@ virQEMUCapsCacheFree(virQEMUCapsCachePtr cache) if (!cache) return; =20 - VIR_FREE(cache->libDir); + virQEMUCapsCachePrivFree(cache->priv); VIR_FREE(cache->cacheDir); virHashFree(cache->binaries); virMutexDestroy(&cache->lock); diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 3458fc0700..61e7c34d12 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -28,13 +28,19 @@ #ifndef __QEMU_CAPSPRIV_H__ # define __QEMU_CAPSPRIV_H__ =20 +struct _virQEMUCapsCachePriv { + char *libDir; + uid_t runUid; + gid_t runGid; +}; +typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; +typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; + struct _virQEMUCapsCache { virMutex lock; virHashTablePtr binaries; - char *libDir; char *cacheDir; - uid_t runUid; - gid_t runGid; + virQEMUCapsCachePrivPtr priv; }; =20 virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643852838435.24043479383397; Fri, 21 Jul 2017 06:30:52 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B93B0C00DB80; Fri, 21 Jul 2017 13:30:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 976E48B304; Fri, 21 Jul 2017 13:30: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 4BF3D180B467; Fri, 21 Jul 2017 13:30:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDUk5F023838 for ; Fri, 21 Jul 2017 09:30:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B4A788B320; Fri, 21 Jul 2017 13:30:46 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C4938BE29 for ; Fri, 21 Jul 2017 13:30:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B93B0C00DB80 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B93B0C00DB80 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:12 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/7] tests: rewrite host CPU mocking 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Jul 2017 13:30:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move all the host CPU data into a separate file and rewrite qemucpumock to not use passed @caps. This is preparation for following patch which will replace virCaps argument with virArch. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: New in v2 tests/domaincapstest.c | 55 +---------------- tests/qemucpumock.c | 13 ++-- tests/testutilshostcpus.h | 148 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/testutilsqemu.c | 93 +++-------------------------- tests/testutilsxen.c | 29 +-------- 5 files changed, 167 insertions(+), 171 deletions(-) create mode 100644 tests/testutilshostcpus.h diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 5a36fcf29d..e17aa8ade3 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -117,38 +117,7 @@ fillAllCaps(virDomainCapsPtr domCaps) =20 #if WITH_QEMU # include "testutilsqemu.h" - -static virCPUDef aarch64Cpu =3D { - .sockets =3D 1, - .cores =3D 1, - .threads =3D 1, -}; - -static virCPUDef ppc64leCpu =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_PPC64LE, - .model =3D (char *) "POWER8", - .sockets =3D 1, - .cores =3D 1, - .threads =3D 1, -}; - -static virCPUDef x86Cpu =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_X86_64, - .model =3D (char *) "Broadwell", - .sockets =3D 1, - .cores =3D 1, - .threads =3D 1, -}; - -static virCPUDef s390Cpu =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_S390X, - .sockets =3D 1, - .cores =3D 1, - .threads =3D 1, -}; +# include "testutilshostcpus.h" =20 static int fakeHostCPU(virCapsPtr caps, @@ -156,32 +125,14 @@ fakeHostCPU(virCapsPtr caps, { virCPUDefPtr cpu; =20 - switch (arch) { - case VIR_ARCH_AARCH64: - cpu =3D &aarch64Cpu; - break; - - case VIR_ARCH_PPC64LE: - cpu =3D &ppc64leCpu; - break; - - case VIR_ARCH_X86_64: - cpu =3D &x86Cpu; - break; - - case VIR_ARCH_S390X: - cpu =3D &s390Cpu; - break; - - default: + if (!(cpu =3D testUtilsHostCpusGetDefForArch(arch))) { virReportError(VIR_ERR_INTERNAL_ERROR, "cannot fake host CPU for arch %s", virArchToString(arch)); return -1; } =20 - if (!(caps->host.cpu =3D virCPUDefCopy(cpu))) - return -1; + qemuTestSetHostCPU(caps, cpu); =20 return 0; } diff --git a/tests/qemucpumock.c b/tests/qemucpumock.c index f0a113ffce..38827584ea 100644 --- a/tests/qemucpumock.c +++ b/tests/qemucpumock.c @@ -16,20 +16,23 @@ =20 #include =20 -#include "internal.h" +#include + +#include "conf/cpu_conf.h" +#include "cpu/cpu.h" #include "qemu/qemu_capabilities.h" #define __QEMU_CAPSPRIV_H_ALLOW__ #include "qemu/qemu_capspriv.h" #undef __QEMU_CAPSPRIV_H_ALLOW__ +#include "testutilshostcpus.h" =20 =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps, +virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps ATTRIBUTE_UNUSED, virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSE= D, virDomainVirtType type ATTRIBUTE_UNUSED) { - if (!caps || !caps->host.cpu || !caps->host.cpu->model) - return NULL; + const char *model =3D getenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); =20 - return virCPUDefCopy(caps->host.cpu); + return testUtilsHostCpusGetDefForModel(model); } diff --git a/tests/testutilshostcpus.h b/tests/testutilshostcpus.h new file mode 100644 index 0000000000..f0ab23b962 --- /dev/null +++ b/tests/testutilshostcpus.h @@ -0,0 +1,148 @@ +#include "conf/cpu_conf.h" +#include "internal.h" +#include "util/virarch.h" + +static virCPUFeatureDef cpuDefaultFeatures[] =3D { + { (char *) "ds", -1 }, + { (char *) "acpi", -1 }, + { (char *) "ss", -1 }, + { (char *) "ht", -1 }, + { (char *) "tm", -1 }, + { (char *) "pbe", -1 }, + { (char *) "ds_cpl", -1 }, + { (char *) "vmx", -1 }, + { (char *) "est", -1 }, + { (char *) "tm2", -1 }, + { (char *) "cx16", -1 }, + { (char *) "xtpr", -1 }, + { (char *) "lahf_lm", -1 }, +}; +static virCPUDef cpuDefaultData =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_X86_64, + .model =3D (char *) "core2duo", + .vendor =3D (char *) "Intel", + .sockets =3D 1, + .cores =3D 2, + .threads =3D 1, + .nfeatures =3D ARRAY_CARDINALITY(cpuDefaultFeatures), + .nfeatures_max =3D ARRAY_CARDINALITY(cpuDefaultFeatures), + .features =3D cpuDefaultFeatures, +}; + +static virCPUFeatureDef cpuHaswellFeatures[] =3D { + { (char *) "vme", -1 }, + { (char *) "ds", -1 }, + { (char *) "acpi", -1 }, + { (char *) "ss", -1 }, + { (char *) "ht", -1 }, + { (char *) "tm", -1 }, + { (char *) "pbe", -1 }, + { (char *) "dtes64", -1 }, + { (char *) "monitor", -1 }, + { (char *) "ds_cpl", -1 }, + { (char *) "vmx", -1 }, + { (char *) "smx", -1 }, + { (char *) "est", -1 }, + { (char *) "tm2", -1 }, + { (char *) "xtpr", -1 }, + { (char *) "pdcm", -1 }, + { (char *) "osxsave", -1 }, + { (char *) "f16c", -1 }, + { (char *) "rdrand", -1 }, + { (char *) "cmt", -1 }, + { (char *) "pdpe1gb", -1 }, + { (char *) "abm", -1 }, + { (char *) "invtsc", -1 }, + { (char *) "lahf_lm", -1 }, +}; +static virCPUDef cpuHaswellData =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_X86_64, + .model =3D (char *) "Haswell", + .vendor =3D (char *) "Intel", + .sockets =3D 1, + .cores =3D 2, + .threads =3D 2, + .nfeatures =3D ARRAY_CARDINALITY(cpuHaswellFeatures), + .nfeatures_max =3D ARRAY_CARDINALITY(cpuHaswellFeatures), + .features =3D cpuHaswellFeatures, +}; + +static virCPUDef cpuBroadwellData =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_X86_64, + .model =3D (char *) "Broadwell", + .sockets =3D 1, + .cores =3D 2, + .threads =3D 2, +}; + +static virCPUDef cpuPower8Data =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_PPC64, + .model =3D (char *) "POWER8", + .sockets =3D 1, + .cores =3D 8, + .threads =3D 8, +}; + +static virCPUDef cpuPower9Data =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_PPC64, + .model =3D (char *) "POWER9", + .sockets =3D 1, + .cores =3D 16, + .threads =3D 1, +}; + +static virCPUDef cpuAarch64Data =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_AARCH64, + .sockets =3D 1, + .cores =3D 4, + .threads =3D 1, +}; + +static virCPUDef cpuS390Data =3D { + .type =3D VIR_CPU_TYPE_HOST, + .arch =3D VIR_ARCH_S390X, + .sockets =3D 2, + .cores =3D 1, + .threads =3D 1, +}; + +static inline virCPUDefPtr +testUtilsHostCpusGetDefForModel(const char *model) +{ + if (!model) + return NULL; + + if (STREQ(model, "core2duo")) + return virCPUDefCopy(&cpuDefaultData); + else if (STREQ(model, "Haswell")) + return virCPUDefCopy(&cpuHaswellData); + else if (STREQ(model, "Broadwell")) + return virCPUDefCopy(&cpuBroadwellData); + else if (STREQ(model, "POWER8")) + return virCPUDefCopy(&cpuPower8Data); + else if (STREQ(model, "POWER9")) + return virCPUDefCopy(&cpuPower9Data); + + return NULL; +} + +static inline virCPUDefPtr +testUtilsHostCpusGetDefForArch(virArch arch) +{ + if (ARCH_IS_X86(arch)) + return virCPUDefCopy(&cpuBroadwellData); + else if (ARCH_IS_PPC64(arch)) + return virCPUDefCopy(&cpuPower8Data); + else if (ARCH_IS_S390(arch)) + return virCPUDefCopy(&cpuS390Data); + else if (arch =3D=3D VIR_ARCH_AARCH64) + return virCPUDefCopy(&cpuAarch64Data); + + return NULL; +} diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 88e11ba14a..67b21c9893 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -3,6 +3,7 @@ # include =20 # include "testutilsqemu.h" +# include "testutilshostcpus.h" # include "testutils.h" # include "viralloc.h" # include "cpu_conf.h" @@ -19,91 +20,6 @@ virCPUDefPtr cpuHaswell; virCPUDefPtr cpuPower8; virCPUDefPtr cpuPower9; =20 -static virCPUFeatureDef cpuDefaultFeatures[] =3D { - { (char *) "ds", -1 }, - { (char *) "acpi", -1 }, - { (char *) "ss", -1 }, - { (char *) "ht", -1 }, - { (char *) "tm", -1 }, - { (char *) "pbe", -1 }, - { (char *) "ds_cpl", -1 }, - { (char *) "vmx", -1 }, - { (char *) "est", -1 }, - { (char *) "tm2", -1 }, - { (char *) "cx16", -1 }, - { (char *) "xtpr", -1 }, - { (char *) "lahf_lm", -1 }, -}; -static virCPUDef cpuDefaultData =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_X86_64, - .model =3D (char *) "core2duo", - .vendor =3D (char *) "Intel", - .sockets =3D 1, - .cores =3D 2, - .threads =3D 1, - .nfeatures =3D ARRAY_CARDINALITY(cpuDefaultFeatures), - .nfeatures_max =3D ARRAY_CARDINALITY(cpuDefaultFeatures), - .features =3D cpuDefaultFeatures, -}; - -static virCPUFeatureDef cpuHaswellFeatures[] =3D { - { (char *) "vme", -1 }, - { (char *) "ds", -1 }, - { (char *) "acpi", -1 }, - { (char *) "ss", -1 }, - { (char *) "ht", -1 }, - { (char *) "tm", -1 }, - { (char *) "pbe", -1 }, - { (char *) "dtes64", -1 }, - { (char *) "monitor", -1 }, - { (char *) "ds_cpl", -1 }, - { (char *) "vmx", -1 }, - { (char *) "smx", -1 }, - { (char *) "est", -1 }, - { (char *) "tm2", -1 }, - { (char *) "xtpr", -1 }, - { (char *) "pdcm", -1 }, - { (char *) "osxsave", -1 }, - { (char *) "f16c", -1 }, - { (char *) "rdrand", -1 }, - { (char *) "cmt", -1 }, - { (char *) "pdpe1gb", -1 }, - { (char *) "abm", -1 }, - { (char *) "invtsc", -1 }, - { (char *) "lahf_lm", -1 }, -}; -static virCPUDef cpuHaswellData =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_X86_64, - .model =3D (char *) "Haswell", - .vendor =3D (char *) "Intel", - .sockets =3D 1, - .cores =3D 2, - .threads =3D 2, - .nfeatures =3D ARRAY_CARDINALITY(cpuHaswellFeatures), - .nfeatures_max =3D ARRAY_CARDINALITY(cpuHaswellFeatures), - .features =3D cpuHaswellFeatures, -}; - -static virCPUDef cpuPower8Data =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_PPC64, - .model =3D (char *) "POWER8", - .sockets =3D 1, - .cores =3D 8, - .threads =3D 8, -}; - -static virCPUDef cpuPower9Data =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_PPC64, - .model =3D (char *) "POWER9", - .sockets =3D 1, - .cores =3D 16, - .threads =3D 1, -}; - typedef enum { TEST_UTILS_QEMU_BIN_I686, TEST_UTILS_QEMU_BIN_X86_64, @@ -557,8 +473,13 @@ qemuTestSetHostCPU(virCapsPtr caps, cpu =3D cpuPower8; } =20 - if (cpu) + if (cpu) { caps->host.arch =3D cpu->arch; + if (cpu->model) + setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, 1); + else + unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); + } caps->host.cpu =3D cpu; } =20 diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index c4fc1465e7..4328441b79 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -4,36 +4,9 @@ #include =20 #include "testutilsxen.h" +#include "testutilshostcpus.h" #include "domain_conf.h" =20 -static virCPUFeatureDef cpuDefaultFeatures[] =3D { - { (char *) "ds", -1 }, - { (char *) "acpi", -1 }, - { (char *) "ss", -1 }, - { (char *) "ht", -1 }, - { (char *) "tm", -1 }, - { (char *) "pbe", -1 }, - { (char *) "ds_cpl", -1 }, - { (char *) "vmx", -1 }, - { (char *) "est", -1 }, - { (char *) "tm2", -1 }, - { (char *) "cx16", -1 }, - { (char *) "xtpr", -1 }, - { (char *) "lahf_lm", -1 }, -}; -static virCPUDef cpuDefaultData =3D { - .type =3D VIR_CPU_TYPE_HOST, - .arch =3D VIR_ARCH_X86_64, - .model =3D (char *) "core2duo", - .vendor =3D (char *) "Intel", - .sockets =3D 1, - .cores =3D 2, - .threads =3D 1, - .nfeatures =3D ARRAY_CARDINALITY(cpuDefaultFeatures), - .nfeatures_max =3D ARRAY_CARDINALITY(cpuDefaultFeatures), - .features =3D cpuDefaultFeatures, -}; - virCapsPtr testXenCapsInit(void) { struct utsname utsname; --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643872457384.4131606167841; Fri, 21 Jul 2017 06:31:12 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 24A5C356FD; Fri, 21 Jul 2017 13:31:10 +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 00F6D8BE36; Fri, 21 Jul 2017 13:31: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 B4BEA14B24; Fri, 21 Jul 2017 13:31:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDUui4023854 for ; Fri, 21 Jul 2017 09:30:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05AF48B304; Fri, 21 Jul 2017 13:30:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49F7F8BE23 for ; Fri, 21 Jul 2017 13:30:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 24A5C356FD Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 24A5C356FD From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:13 +0200 Message-Id: <6182eda93304d134d9c2147efdce8b115d340aaa.1500643455.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/7] qemu: pass only host arch instead of the whole virCaps 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Jul 2017 13:31:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a preparation for following patches where we switch to virFileCache for QEMU capabilities cache The host arch will always remain the same but virCaps may change. Now the host arch is stored while creating new qemu capabilities cache. It removes the need to pass virCaps into virQEMUCapsCache*() functions. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: New in v2 src/qemu/qemu_capabilities.c | 61 +++++++++++++++++++++-------------------= ---- src/qemu/qemu_capabilities.h | 9 +++---- src/qemu/qemu_capspriv.h | 11 +++++--- src/qemu/qemu_domain.c | 17 +++++------- src/qemu/qemu_driver.c | 8 +++--- src/qemu/qemu_process.c | 9 +++---- tests/qemucapsprobe.c | 3 ++- tests/qemucpumock.c | 3 ++- tests/qemuxml2argvtest.c | 9 +++++-- tests/testutilsqemu.c | 5 +++- 10 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c310e97f61..603ce18ac3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -972,7 +972,7 @@ virQEMUCapsInitGuest(virCapsPtr caps, =20 /* Ignore binary if extracting version info fails */ if (binary) { - if (!(qemubinCaps =3D virQEMUCapsCacheLookup(caps, cache, binary))= ) { + if (!(qemubinCaps =3D virQEMUCapsCacheLookup(cache, binary))) { virResetLastError(); VIR_FREE(binary); } @@ -1012,7 +1012,7 @@ virQEMUCapsInitGuest(virCapsPtr caps, if (!kvmbin) continue; =20 - if (!(kvmbinCaps =3D virQEMUCapsCacheLookup(caps, cache, kvmbi= n))) { + if (!(kvmbinCaps =3D virQEMUCapsCacheLookup(cache, kvmbin))) { virResetLastError(); VIR_FREE(kvmbin); continue; @@ -1152,7 +1152,7 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, =20 =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps, +virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, virQEMUCapsPtr qemuCaps, virDomainVirtType type) { @@ -1163,7 +1163,7 @@ virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps, if (virQEMUCapsGetCPUDefinitions(qemuCaps, type, &models, &nmodels) < = 0) return NULL; =20 - cpu =3D virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_GUEST, NULL, + cpu =3D virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL, (const char **) models, nmodels); =20 virStringListFreeCount(models, nmodels); @@ -2182,7 +2182,7 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr caps, return -1; } =20 - qemucaps =3D virQEMUCapsCacheLookup(caps, capsCache, capsdata->emulato= r); + qemucaps =3D virQEMUCapsCacheLookup(capsCache, capsdata->emulator); VIR_FREE(capsdata); if (!qemucaps) return -1; @@ -3484,7 +3484,7 @@ virQEMUCapsNewHostCPUModel(void) =20 void virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, - virCapsPtr caps, + virArch hostArch, virDomainVirtType type) { virCPUDefPtr cpu =3D NULL; @@ -3494,7 +3494,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, size_t i; int rc; =20 - if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch= )) + if (!virQEMUCapsGuestIsNative(hostArch, qemuCaps->arch)) return; =20 if (!(cpu =3D virQEMUCapsNewHostCPUModel())) @@ -3505,7 +3505,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, } else if (rc =3D=3D 1) { VIR_DEBUG("No host CPU model info from QEMU; probing host CPU dire= ctly"); =20 - hostCPU =3D virQEMUCapsProbeHostCPUForEmulator(caps, qemuCaps, typ= e); + hostCPU =3D virQEMUCapsProbeHostCPUForEmulator(hostArch, qemuCaps,= type); if (!hostCPU || virCPUDefCopyModelFilter(cpu, hostCPU, true, virQEMUCapsCPUFilterFeatures, @@ -3790,7 +3790,7 @@ virQEMUCapsCachePrivFree(virQEMUCapsCachePrivPtr priv) * */ int -virQEMUCapsLoadCache(virCapsPtr caps, +virQEMUCapsLoadCache(virArch hostArch, virQEMUCapsPtr qemuCaps, const char *filename) { @@ -4007,8 +4007,8 @@ virQEMUCapsLoadCache(virCapsPtr caps, } VIR_FREE(nodes); =20 - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_KVM); - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_QEMU); + virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM); + virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU); =20 ret =3D 0; cleanup: @@ -4321,8 +4321,7 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, =20 =20 static int -virQEMUCapsInitCached(virCapsPtr caps, - virQEMUCapsPtr *qemuCaps, +virQEMUCapsInitCached(virQEMUCapsPtr *qemuCaps, const char *binary, const char *cacheDir, virQEMUCapsCachePrivPtr priv) @@ -4369,7 +4368,7 @@ virQEMUCapsInitCached(virCapsPtr caps, if (VIR_STRDUP(qemuCapsNew->binary, binary) < 0) goto discard; =20 - if (virQEMUCapsLoadCache(caps, qemuCapsNew, capsfile) < 0) { + if (virQEMUCapsLoadCache(priv->hostArch, qemuCapsNew, capsfile) < 0) { VIR_WARN("Failed to load cached caps from '%s' for '%s': %s", capsfile, qemuCapsNew->binary, virGetLastErrorMessage()); virResetLastError(); @@ -5207,7 +5206,7 @@ virQEMUCapsLogProbeFailure(const char *binary) =20 =20 virQEMUCapsPtr -virQEMUCapsNewForBinaryInternal(virCapsPtr caps, +virQEMUCapsNewForBinaryInternal(virArch hostArch, const char *binary, const char *libDir, uid_t runUid, @@ -5265,8 +5264,8 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; =20 - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_KVM); - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_QEMU); + virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM); + virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU); =20 cleanup: VIR_FREE(qmperr); @@ -5279,19 +5278,19 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, } =20 static virQEMUCapsPtr -virQEMUCapsNewForBinary(virCapsPtr caps, - const char *binary, +virQEMUCapsNewForBinary(const char *binary, const char *cacheDir, virQEMUCapsCachePrivPtr priv) { int rv; virQEMUCapsPtr qemuCaps =3D NULL; =20 - if ((rv =3D virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir, p= riv)) < 0) + if ((rv =3D virQEMUCapsInitCached(&qemuCaps, binary, cacheDir, priv)) = < 0) goto error; =20 if (rv =3D=3D 0) { - if (!(qemuCaps =3D virQEMUCapsNewForBinaryInternal(caps, binary, + if (!(qemuCaps =3D virQEMUCapsNewForBinaryInternal(priv->hostArch, + binary, priv->libDir, priv->runUid, priv->runGid, @@ -5378,6 +5377,8 @@ virQEMUCapsCacheNew(const char *libDir, if (VIR_STRDUP(cache->priv->libDir, libDir) < 0) goto error; =20 + cache->priv->hostArch =3D virArchFromHost(); + cache->priv->runUid =3D runUid; cache->priv->runGid =3D runGid; =20 @@ -5392,7 +5393,6 @@ virQEMUCapsCacheNew(const char *libDir, static void ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, const char *binary, - virCapsPtr caps, virQEMUCapsPtr *qemuCaps) { if (*qemuCaps && @@ -5405,7 +5405,7 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, =20 if (!*qemuCaps) { VIR_DEBUG("Creating capabilities for %s", binary); - *qemuCaps =3D virQEMUCapsNewForBinary(caps, binary, + *qemuCaps =3D virQEMUCapsNewForBinary(binary, cache->cacheDir, cache->priv); if (*qemuCaps) { @@ -5420,8 +5420,7 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookup(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary) { virQEMUCapsPtr ret =3D NULL; @@ -5429,7 +5428,7 @@ virQEMUCapsCacheLookup(virCapsPtr caps, virMutexLock(&cache->lock); =20 ret =3D virHashLookup(cache->binaries, binary); - virQEMUCapsCacheValidate(cache, binary, caps, &ret); + virQEMUCapsCacheValidate(cache, binary, &ret); virObjectRef(ret); =20 virMutexUnlock(&cache->lock); @@ -5440,12 +5439,11 @@ virQEMUCapsCacheLookup(virCapsPtr caps, =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookupCopy(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, const char *binary, const char *machineType) { - virQEMUCapsPtr qemuCaps =3D virQEMUCapsCacheLookup(caps, cache, binary= ); + virQEMUCapsPtr qemuCaps =3D virQEMUCapsCacheLookup(cache, binary); virQEMUCapsPtr ret; =20 if (!qemuCaps) @@ -5475,8 +5473,7 @@ virQEMUCapsCompareArch(const void *payload, =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookupByArch(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache, virArch arch) { virQEMUCapsPtr ret =3D NULL; @@ -5502,7 +5499,7 @@ virQEMUCapsCacheLookupByArch(virCapsPtr caps, if (VIR_STRDUP(binary, ret->binary) < 0) { ret =3D NULL; } else { - virQEMUCapsCacheValidate(cache, binary, caps, &ret); + virQEMUCapsCacheValidate(cache, binary, &ret); VIR_FREE(binary); } } else { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index bd44b90002..0aa8106191 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -501,15 +501,12 @@ void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qe= muCaps, virQEMUCapsCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, uid_t uid, gid_t gid); -virQEMUCapsPtr virQEMUCapsCacheLookup(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary); -virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, const char *binary, const char *machineType); -virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virCapsPtr caps, - virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache, virArch arch); void virQEMUCapsCacheFree(virQEMUCapsCachePtr cache); =20 diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 61e7c34d12..5b7d544806 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -28,10 +28,13 @@ #ifndef __QEMU_CAPSPRIV_H__ # define __QEMU_CAPSPRIV_H__ =20 +# include "virarch.h" + struct _virQEMUCapsCachePriv { char *libDir; uid_t runUid; gid_t runGid; + virArch hostArch; }; typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; @@ -46,14 +49,14 @@ struct _virQEMUCapsCache { virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); =20 virQEMUCapsPtr -virQEMUCapsNewForBinaryInternal(virCapsPtr caps, +virQEMUCapsNewForBinaryInternal(virArch hostArch, const char *binary, const char *libDir, uid_t runUid, gid_t runGid, bool qmpOnly); =20 -int virQEMUCapsLoadCache(virCapsPtr caps, +int virQEMUCapsLoadCache(virArch hostArch, virQEMUCapsPtr qemuCaps, const char *filename); char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps); @@ -76,7 +79,7 @@ virQEMUCapsSetVersion(virQEMUCapsPtr qemuCaps, =20 void virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, - virCapsPtr caps, + virArch hostArch, virDomainVirtType type); =20 int @@ -94,7 +97,7 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps, qemuMonitorCPUModelInfoPtr modelInfo); =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps, +virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, virQEMUCapsPtr qemuCaps, virDomainVirtType type) ATTRIBUTE_NOINL= INE; =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ede761e6ef..4412ba629a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2962,8 +2962,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, if (qemuCaps) { virObjectRef(qemuCaps); } else { - if (!(qemuCaps =3D virQEMUCapsCacheLookup(caps, - driver->qemuCapsCache, + if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; } @@ -3076,7 +3075,7 @@ qemuDomainDefValidateVideo(const virDomainDef *def) =20 static int qemuDomainDefValidate(const virDomainDef *def, - virCapsPtr caps, + virCapsPtr caps ATTRIBUTE_UNUSED, void *opaque) { virQEMUDriverPtr driver =3D opaque; @@ -3084,8 +3083,7 @@ qemuDomainDefValidate(const virDomainDef *def, unsigned int topologycpus; int ret =3D -1; =20 - if (!(qemuCaps =3D virQEMUCapsCacheLookup(caps, - driver->qemuCapsCache, + if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; =20 @@ -3548,7 +3546,7 @@ qemuDomainControllerDefPostParse(virDomainControllerD= efPtr cont, static int qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps, + virCapsPtr caps ATTRIBUTE_UNUSED, unsigned int parseFlags, void *opaque, void *parseOpaque) @@ -3561,7 +3559,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr de= v, if (qemuCaps) { virObjectRef(qemuCaps); } else { - qemuCaps =3D virQEMUCapsCacheLookup(caps, driver->qemuCapsCache, + qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator); } =20 @@ -3681,7 +3679,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr de= v, =20 static int qemuDomainDefAssignAddresses(virDomainDef *def, - virCapsPtr caps, + virCapsPtr caps ATTRIBUTE_UNUSED, unsigned int parseFlags ATTRIBUTE_UNUSED, void *opaque, void *parseOpaque) @@ -3694,8 +3692,7 @@ qemuDomainDefAssignAddresses(virDomainDef *def, if (qemuCaps) { virObjectRef(qemuCaps); } else { - if (!(qemuCaps =3D virQEMUCapsCacheLookup(caps, - driver->qemuCapsCache, + if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6568def156..c5839e5cb5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15929,7 +15929,7 @@ static virDomainPtr qemuDomainQemuAttach(virConnect= Ptr conn, virAsprintf(&def->name, "attach-pid-%u", pid_value) < 0) goto cleanup; =20 - if (!(qemuCaps =3D virQEMUCapsCacheLookup(caps, driver->qemuCapsCache, + if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; =20 @@ -18979,8 +18979,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, if (emulatorbin) { virArch arch_from_caps; =20 - if (!(qemuCaps =3D virQEMUCapsCacheLookup(caps, - driver->qemuCapsCache, + if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, emulatorbin))) goto cleanup; =20 @@ -18999,8 +18998,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, goto cleanup; } } else { - if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(caps, - driver->qemuCapsCach= e, + if (!(qemuCaps =3D virQEMUCapsCacheLookupByArch(driver->qemuCapsCa= che, arch))) goto cleanup; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 525521aaf0..095c781bd7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4696,8 +4696,7 @@ qemuProcessInit(virQEMUDriverPtr driver, =20 VIR_DEBUG("Determining emulator version"); virObjectUnref(priv->qemuCaps); - if (!(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(caps, - driver->qemuCapsCach= e, + if (!(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(driver->qemuCapsCa= che, vm->def->emulator, vm->def->os.machine)= )) goto cleanup; @@ -6478,8 +6477,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UN= USED, =20 VIR_DEBUG("Determining emulator version"); virObjectUnref(priv->qemuCaps); - if (!(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(caps, - driver->qemuCapsCach= e, + if (!(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(driver->qemuCapsCa= che, vm->def->emulator, vm->def->os.machine)= )) goto error; @@ -6863,8 +6861,7 @@ qemuProcessReconnect(void *opaque) * caps in the domain status, so re-query them */ if (!priv->qemuCaps && - !(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(caps, - driver->qemuCapsCach= e, + !(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(driver->qemuCapsCa= che, obj->def->emulator, obj->def->os.machine= ))) goto error; diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c index 581ac38465..4b8d6229b4 100644 --- a/tests/qemucapsprobe.c +++ b/tests/qemucapsprobe.c @@ -22,6 +22,7 @@ =20 #include "testutils.h" #include "internal.h" +#include "virarch.h" #include "virthread.h" #include "qemu/qemu_capabilities.h" #define __QEMU_CAPSPRIV_H_ALLOW__ 1 @@ -70,7 +71,7 @@ main(int argc, char **argv) if (virThreadCreate(&thread, false, eventLoop, NULL) < 0) return EXIT_FAILURE; =20 - if (!(caps =3D virQEMUCapsNewForBinaryInternal(NULL, argv[1], "/tmp", + if (!(caps =3D virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1],= "/tmp", -1, -1, true))) return EXIT_FAILURE; =20 diff --git a/tests/qemucpumock.c b/tests/qemucpumock.c index 38827584ea..74dcfa6291 100644 --- a/tests/qemucpumock.c +++ b/tests/qemucpumock.c @@ -25,10 +25,11 @@ #include "qemu/qemu_capspriv.h" #undef __QEMU_CAPSPRIV_H_ALLOW__ #include "testutilshostcpus.h" +#include "virarch.h" =20 =20 virCPUDefPtr -virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps ATTRIBUTE_UNUSED, +virQEMUCapsProbeHostCPUForEmulator(virArch hostArch ATTRIBUTE_UNUSED, virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSE= D, virDomainVirtType type ATTRIBUTE_UNUSED) { diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b95ea46be0..ef59b364f0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -377,6 +377,9 @@ testUpdateQEMUCaps(const struct testInfo *info, { int ret =3D -1; =20 + if (!caps) + goto cleanup; + virQEMUCapsSetArch(info->qemuCaps, vm->def->os.arch); =20 virQEMUCapsInitQMPBasicArch(info->qemuCaps); @@ -389,8 +392,10 @@ testUpdateQEMUCaps(const struct testInfo *info, if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0) goto cleanup; =20 - virQEMUCapsInitHostCPUModel(info->qemuCaps, caps, VIR_DOMAIN_VIRT_KVM); - virQEMUCapsInitHostCPUModel(info->qemuCaps, caps, VIR_DOMAIN_VIRT_QEMU= ); + virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch, + VIR_DOMAIN_VIRT_KVM); + virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch, + VIR_DOMAIN_VIRT_QEMU); =20 virQEMUCapsFilterByMachineType(info->qemuCaps, vm->def->os.machine); =20 diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 67b21c9893..5766e183df 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -490,8 +490,11 @@ qemuTestParseCapabilities(virCapsPtr caps, { virQEMUCapsPtr qemuCaps =3D NULL; =20 + if (!caps) + return NULL; + if (!(qemuCaps =3D virQEMUCapsNew()) || - virQEMUCapsLoadCache(caps, qemuCaps, capsFile) < 0) + virQEMUCapsLoadCache(caps->host.arch, qemuCaps, capsFile) < 0) goto error; =20 return qemuCaps; --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643867880537.2473948815868; Fri, 21 Jul 2017 06:31:07 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C5794C0B2A32; Fri, 21 Jul 2017 13:31: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 A46EA8BE23; Fri, 21 Jul 2017 13:31: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 5FA70180B467; Fri, 21 Jul 2017 13:31:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDV0Iq023866 for ; Fri, 21 Jul 2017 09:31:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D1238BE23; Fri, 21 Jul 2017 13:31:00 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id D02C88BE24 for ; Fri, 21 Jul 2017 13:30:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5794C0B2A32 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C5794C0B2A32 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:14 +0200 Message-Id: <331266183ff72783ab19e7d8177c4d708d58b965.1500643455.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/7] qemu: switch QEMU capabilities to use virFileCache 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Jul 2017 13:31:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The switch contains considerable amount of changes: virQEMUCapsRememberCached() is removed because this is now handled by virFileCacheSave(). virQEMUCapsInitCached() is removed because this is now handled by virFileCacheLoad(). virQEMUCapsNewForBinary() is split into two functions, virQEMUCapsNewData() which creates new data if there is nothing cached and virQEMUCapsLoadFile() which loads the cached data. This is now handled by virFileCacheNewData(). virQEMUCapsCacheValidate() is removed because this is now handled by virFileCacheValidate(). virQEMUCapsCacheFree() is removed because it's no longer required. Add virCapsPtr into virQEMUCapsCachePriv because for each call of virFileCacheLookup*() we need to use current virCapsPtr. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: Changes in v2: - removed the need to set/unset virCaps before calling virFileCache= Lookup* src/qemu/qemu_capabilities.c | 316 +++++++++++----------------------------= ---- src/qemu/qemu_capabilities.h | 17 +-- src/qemu/qemu_capspriv.h | 6 - src/qemu/qemu_conf.h | 3 +- src/qemu/qemu_driver.c | 2 +- tests/testutilsqemu.c | 9 +- tests/testutilsqemu.h | 3 +- 7 files changed, 96 insertions(+), 260 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 603ce18ac3..9f327bccb4 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -29,6 +29,7 @@ #include "virlog.h" #include "virerror.h" #include "virfile.h" +#include "virfilecache.h" #include "virpidfile.h" #include "virprocess.h" #include "cpu/cpu.h" @@ -954,7 +955,7 @@ virQEMUCapsFindBinaryForArch(virArch hostarch, =20 static int virQEMUCapsInitGuest(virCapsPtr caps, - virQEMUCapsCachePtr cache, + virFileCachePtr cache, virArch hostarch, virArch guestarch) { @@ -1171,7 +1172,8 @@ virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, } =20 =20 -virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache) +virCapsPtr +virQEMUCapsInit(virFileCachePtr cache) { virCapsPtr caps; size_t i; @@ -2162,7 +2164,7 @@ virQEMUCapsExtractDeviceStr(const char *qemu, =20 =20 int virQEMUCapsGetDefaultVersion(virCapsPtr caps, - virQEMUCapsCachePtr capsCache, + virFileCachePtr capsCache, unsigned int *version) { virQEMUCapsPtr qemucaps; @@ -3765,8 +3767,10 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps, =20 =20 static void -virQEMUCapsCachePrivFree(virQEMUCapsCachePrivPtr priv) +virQEMUCapsCachePrivFree(void *privData) { + virQEMUCapsCachePrivPtr priv =3D privData; + VIR_FREE(priv->libDir); VIR_FREE(priv); } @@ -4195,8 +4199,11 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) =20 =20 static int -virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename) +virQEMUCapsSaveFile(void *data, + const char *filename, + void *privData ATTRIBUTE_UNUSED) { + virQEMUCapsPtr qemuCaps =3D data; char *xml =3D NULL; int ret =3D -1; =20 @@ -4220,48 +4227,13 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const= char *filename) return ret; } =20 -static int -virQEMUCapsRememberCached(virQEMUCapsPtr qemuCaps, const char *cacheDir) -{ - char *capsdir =3D NULL; - char *capsfile =3D NULL; - int ret =3D -1; - char *binaryhash =3D NULL; - - if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0) - goto cleanup; - - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, - qemuCaps->binary, - &binaryhash) < 0) - goto cleanup; - - if (virAsprintf(&capsfile, "%s/%s.xml", capsdir, binaryhash) < 0) - goto cleanup; - - if (virFileMakePath(capsdir) < 0) { - virReportSystemError(errno, - _("Unable to create directory '%s'"), - capsdir); - goto cleanup; - } - - if (virQEMUCapsSaveCache(qemuCaps, capsfile) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(binaryhash); - VIR_FREE(capsfile); - VIR_FREE(capsdir); - return ret; -} - =20 static bool -virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - virQEMUCapsCachePrivPtr priv) +virQEMUCapsIsValid(void *data, + void *privData) { + virQEMUCapsPtr qemuCaps =3D data; + virQEMUCapsCachePrivPtr priv =3D privData; bool kvmUsable; struct stat sb; =20 @@ -4320,86 +4292,6 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, } =20 =20 -static int -virQEMUCapsInitCached(virQEMUCapsPtr *qemuCaps, - const char *binary, - const char *cacheDir, - virQEMUCapsCachePrivPtr priv) -{ - char *capsdir =3D NULL; - char *capsfile =3D NULL; - int ret =3D -1; - char *binaryhash =3D NULL; - struct stat sb; - virQEMUCapsPtr qemuCapsNew =3D NULL; - - if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0) - goto cleanup; - - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, binary, &binaryhash) <= 0) - goto cleanup; - - if (virAsprintf(&capsfile, "%s/%s.xml", capsdir, binaryhash) < 0) - goto cleanup; - - if (virFileMakePath(capsdir) < 0) { - virReportSystemError(errno, - _("Unable to create directory '%s'"), - capsdir); - goto cleanup; - } - - if (stat(capsfile, &sb) < 0) { - if (errno =3D=3D ENOENT) { - VIR_DEBUG("No cached capabilities '%s' for '%s'", - capsfile, binary); - ret =3D 0; - goto cleanup; - } - virReportSystemError(errno, - _("Unable to access cache '%s' for '%s'"), - capsfile, binary); - goto cleanup; - } - - if (!(qemuCapsNew =3D virQEMUCapsNew())) - goto cleanup; - - if (VIR_STRDUP(qemuCapsNew->binary, binary) < 0) - goto discard; - - if (virQEMUCapsLoadCache(priv->hostArch, qemuCapsNew, capsfile) < 0) { - VIR_WARN("Failed to load cached caps from '%s' for '%s': %s", - capsfile, qemuCapsNew->binary, virGetLastErrorMessage()); - virResetLastError(); - goto discard; - } - - if (!virQEMUCapsIsValid(qemuCapsNew, priv)) - goto discard; - - VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=3D%d", - capsfile, qemuCapsNew->binary, - (long long)qemuCapsNew->ctime, qemuCapsNew->usedQMP); - - ret =3D 1; - *qemuCaps =3D qemuCapsNew; - cleanup: - VIR_FREE(binaryhash); - VIR_FREE(capsfile); - VIR_FREE(capsdir); - return ret; - - discard: - VIR_DEBUG("Dropping cached capabilities '%s' for '%s'", - capsfile, qemuCapsNew->binary); - ignore_value(unlink(capsfile)); - virObjectUnref(qemuCapsNew); - ret =3D 0; - goto cleanup; -} - - #define QEMU_SYSTEM_PREFIX "qemu-system-" =20 static int @@ -5277,36 +5169,45 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, goto cleanup; } =20 -static virQEMUCapsPtr -virQEMUCapsNewForBinary(const char *binary, - const char *cacheDir, - virQEMUCapsCachePrivPtr priv) +static void * +virQEMUCapsNewData(const char *binary, + void *privData) { - int rv; - virQEMUCapsPtr qemuCaps =3D NULL; + virQEMUCapsCachePrivPtr priv =3D privData; =20 - if ((rv =3D virQEMUCapsInitCached(&qemuCaps, binary, cacheDir, priv)) = < 0) - goto error; + return virQEMUCapsNewForBinaryInternal(priv->hostArch, + binary, + priv->libDir, + priv->runUid, + priv->runGid, + false); +} + + +static void * +virQEMUCapsLoadFile(const char *filename, + const char *binary, + void *privData) +{ + virQEMUCapsPtr qemuCaps =3D virQEMUCapsNew(); + virQEMUCapsCachePrivPtr priv =3D privData; =20 - if (rv =3D=3D 0) { - if (!(qemuCaps =3D virQEMUCapsNewForBinaryInternal(priv->hostArch, - binary, - priv->libDir, - priv->runUid, - priv->runGid, - false))) { - goto error; - } + if (!qemuCaps) + return NULL; =20 - if (virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0) - goto error; - } + if (VIR_STRDUP(qemuCaps->binary, binary) < 0) + goto error; + + if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) < 0) + goto error; =20 + cleanup: return qemuCaps; =20 error: virObjectUnref(qemuCaps); - return NULL; + qemuCaps =3D NULL; + goto cleanup; } =20 =20 @@ -5348,90 +5249,61 @@ virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuC= aps, } =20 =20 -virQEMUCapsCachePtr +virFileCacheHandlers qemuCapsCacheHandlers =3D { + .isValid =3D virQEMUCapsIsValid, + .newData =3D virQEMUCapsNewData, + .loadFile =3D virQEMUCapsLoadFile, + .saveFile =3D virQEMUCapsSaveFile, + .privFree =3D virQEMUCapsCachePrivFree, +}; + + +virFileCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, uid_t runUid, gid_t runGid) { - virQEMUCapsCachePtr cache; + char *capsCacheDir =3D NULL; + virFileCachePtr cache =3D NULL; + virQEMUCapsCachePrivPtr priv =3D NULL; =20 - if (VIR_ALLOC(cache) < 0) - return NULL; - - if (virMutexInit(&cache->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); - VIR_FREE(cache); - return NULL; - } - - if (!(cache->binaries =3D virHashCreate(10, virObjectFreeHashData))) + if (virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir) < 0) goto error; - if (VIR_STRDUP(cache->cacheDir, cacheDir) < 0) + + if (!(cache =3D virFileCacheNew(capsCacheDir, "xml", qemuCapsCacheHand= lers))) goto error; =20 - if (VIR_ALLOC(cache->priv) < 0) + if (VIR_ALLOC(priv) < 0) goto error; + virFileCacheSetPriv(cache, priv); =20 - if (VIR_STRDUP(cache->priv->libDir, libDir) < 0) + if (VIR_STRDUP(priv->libDir, libDir) < 0) goto error; =20 - cache->priv->hostArch =3D virArchFromHost(); + priv->hostArch =3D virArchFromHost(); =20 - cache->priv->runUid =3D runUid; - cache->priv->runGid =3D runGid; + priv->runUid =3D runUid; + priv->runGid =3D runGid; =20 + cleanup: + VIR_FREE(capsCacheDir); return cache; =20 error: - virQEMUCapsCacheFree(cache); - return NULL; -} - - -static void ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) -virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, - const char *binary, - virQEMUCapsPtr *qemuCaps) -{ - if (*qemuCaps && - !virQEMUCapsIsValid(*qemuCaps, cache->priv)) { - VIR_DEBUG("Cached capabilities %p no longer valid for %s", - *qemuCaps, binary); - virHashRemoveEntry(cache->binaries, binary); - *qemuCaps =3D NULL; - } - - if (!*qemuCaps) { - VIR_DEBUG("Creating capabilities for %s", binary); - *qemuCaps =3D virQEMUCapsNewForBinary(binary, - cache->cacheDir, - cache->priv); - if (*qemuCaps) { - VIR_DEBUG("Caching capabilities %p for %s", *qemuCaps, binary); - if (virHashAddEntry(cache->binaries, binary, *qemuCaps) < 0) { - virObjectUnref(*qemuCaps); - *qemuCaps =3D NULL; - } - } - } + virObjectUnref(cache); + cache =3D NULL; + goto cleanup; } =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookup(virFileCachePtr cache, const char *binary) { virQEMUCapsPtr ret =3D NULL; =20 - virMutexLock(&cache->lock); - - ret =3D virHashLookup(cache->binaries, binary); - virQEMUCapsCacheValidate(cache, binary, &ret); - virObjectRef(ret); - - virMutexUnlock(&cache->lock); + ret =3D virFileCacheLookup(cache, binary); =20 VIR_DEBUG("Returning caps %p for %s", ret, binary); return ret; @@ -5439,7 +5311,7 @@ virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookupCopy(virFileCachePtr cache, const char *binary, const char *machineType) { @@ -5473,64 +5345,36 @@ virQEMUCapsCompareArch(const void *payload, =20 =20 virQEMUCapsPtr -virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache, +virQEMUCapsCacheLookupByArch(virFileCachePtr cache, virArch arch) { virQEMUCapsPtr ret =3D NULL; virArch target; struct virQEMUCapsSearchData data =3D { .arch =3D arch }; =20 - virMutexLock(&cache->lock); - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data, = NULL); + ret =3D virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data); if (!ret) { /* If the first attempt at finding capabilities has failed, try * again using the QEMU target as lookup key instead */ target =3D virQEMUCapsFindTarget(virArchFromHost(), data.arch); if (target !=3D data.arch) { data.arch =3D target; - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, - &data, NULL); + ret =3D virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch= , &data); } } =20 - if (ret) { - char *binary; - - if (VIR_STRDUP(binary, ret->binary) < 0) { - ret =3D NULL; - } else { - virQEMUCapsCacheValidate(cache, binary, &ret); - VIR_FREE(binary); - } - } else { + if (!ret) { virReportError(VIR_ERR_INVALID_ARG, _("unable to find any emulator to serve '%s' " "architecture"), virArchToString(arch)); } =20 - virObjectRef(ret); - virMutexUnlock(&cache->lock); - VIR_DEBUG("Returning caps %p for arch %s", ret, virArchToString(arch)); =20 return ret; } =20 =20 -void -virQEMUCapsCacheFree(virQEMUCapsCachePtr cache) -{ - if (!cache) - return; - - virQEMUCapsCachePrivFree(cache->priv); - VIR_FREE(cache->cacheDir); - virHashFree(cache->binaries); - virMutexDestroy(&cache->lock); - VIR_FREE(cache); -} - - bool virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps, const virDomainDef *def) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 0aa8106191..aca98b3a06 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -30,6 +30,7 @@ # include "qemu_monitor.h" # include "domain_capabilities.h" # include "virfirmware.h" +# include "virfilecache.h" =20 /* * Internal flags to keep track of qemu command line capabilities @@ -424,9 +425,6 @@ typedef enum { typedef struct _virQEMUCaps virQEMUCaps; typedef virQEMUCaps *virQEMUCapsPtr; =20 -typedef struct _virQEMUCapsCache virQEMUCapsCache; -typedef virQEMUCapsCache *virQEMUCapsCachePtr; - virQEMUCapsPtr virQEMUCapsNew(void); =20 void virQEMUCapsSet(virQEMUCapsPtr qemuCaps, @@ -498,22 +496,21 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qem= uCaps, void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, const char *machineType); =20 -virQEMUCapsCachePtr virQEMUCapsCacheNew(const char *libDir, +virFileCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, uid_t uid, gid_t gid); -virQEMUCapsPtr virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache, const char *binary); -virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache, const char *binary, const char *machineType); -virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache, +virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virFileCachePtr cache, virArch arch); -void virQEMUCapsCacheFree(virQEMUCapsCachePtr cache); =20 -virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache); +virCapsPtr virQEMUCapsInit(virFileCachePtr cache); =20 int virQEMUCapsGetDefaultVersion(virCapsPtr caps, - virQEMUCapsCachePtr capsCache, + virFileCachePtr capsCache, unsigned int *version); =20 VIR_ENUM_DECL(virQEMUCaps); diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 5b7d544806..78f7e4ab39 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -39,12 +39,6 @@ struct _virQEMUCapsCachePriv { typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; =20 -struct _virQEMUCapsCache { - virMutex lock; - virHashTablePtr binaries; - char *cacheDir; - virQEMUCapsCachePrivPtr priv; -}; =20 virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 1407eef4d4..3013f24ed4 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -48,6 +48,7 @@ # include "virclosecallbacks.h" # include "virhostdev.h" # include "virfile.h" +# include "virfilecache.h" # include "virfirmware.h" =20 # ifdef CPU_SETSIZE /* Linux */ @@ -245,7 +246,7 @@ struct _virQEMUDriver { virDomainXMLOptionPtr xmlopt; =20 /* Immutable pointer, self-locking APIs */ - virQEMUCapsCachePtr qemuCapsCache; + virFileCachePtr qemuCapsCache; =20 /* Immutable pointer, self-locking APIs */ virObjectEventStatePtr domainEventState; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c5839e5cb5..9a30ff450a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1079,7 +1079,7 @@ qemuStateCleanup(void) virObjectUnref(qemu_driver->hostdevMgr); virHashFree(qemu_driver->sharedDevices); virObjectUnref(qemu_driver->caps); - virQEMUCapsCacheFree(qemu_driver->qemuCapsCache); + virObjectUnref(qemu_driver->qemuCapsCache); =20 virObjectUnref(qemu_driver->domains); virObjectUnref(qemu_driver->remotePorts); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 5766e183df..2c7124bf26 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -12,6 +12,7 @@ # define __QEMU_CAPSPRIV_H_ALLOW__ # include "qemu/qemu_capspriv.h" # include "virstring.h" +# include "virfilecache.h" =20 # define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -511,14 +512,14 @@ void qemuTestDriverFree(virQEMUDriver *driver) virFileDeleteTree(driver->config->stateDir); virFileDeleteTree(driver->config->configDir); } - virQEMUCapsCacheFree(driver->qemuCapsCache); + virObjectUnref(driver->qemuCapsCache); virObjectUnref(driver->xmlopt); virObjectUnref(driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); } =20 -int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, +int qemuTestCapsCacheInsert(virFileCachePtr cache, virQEMUCapsPtr caps) { size_t i; @@ -533,9 +534,7 @@ int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, =20 for (i =3D 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) { virObjectRef(tmpCaps); - if (virHashUpdateEntry(cache->binaries, - QEMUBinList[i], - tmpCaps) < 0) { + if (virFileCacheInsertData(cache, QEMUBinList[i], tmpCaps) < 0) { virObjectUnref(tmpCaps); return -1; } diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 05e5651ae8..f29c6e5d62 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -1,6 +1,7 @@ #ifdef WITH_QEMU =20 # include "capabilities.h" +# include "virfilecache.h" # include "domain_conf.h" # include "qemu/qemu_capabilities.h" # include "qemu/qemu_conf.h" @@ -30,7 +31,7 @@ void qemuTestSetHostCPU(virCapsPtr caps, =20 int qemuTestDriverInit(virQEMUDriver *driver); void qemuTestDriverFree(virQEMUDriver *driver); -int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, +int qemuTestCapsCacheInsert(virFileCachePtr cache, virQEMUCapsPtr caps); =20 int testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps, --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 23:06:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500643876763146.2112939038734; Fri, 21 Jul 2017 06:31:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E556C008282; Fri, 21 Jul 2017 13:31:13 +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 73B8418253; Fri, 21 Jul 2017 13:31: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 090B3180BA82; Fri, 21 Jul 2017 13:31:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6LDV6Yq023878 for ; Fri, 21 Jul 2017 09:31:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A75D8B304; Fri, 21 Jul 2017 13:31:06 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id A67B88BE22 for ; Fri, 21 Jul 2017 13:31:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E556C008282 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9E556C008282 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 21 Jul 2017 15:30:15 +0200 Message-Id: <4e43ccfad43d59c4c12bc6abd0964e75aa060048.1500643455.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 7/7] qemu: privatize _virQEMUCapsCachePriv struct 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 21 Jul 2017 13:31:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- Notes: Changes in v2: - the body of structure was changed src/qemu/qemu_capabilities.c | 10 ++++++++++ src/qemu/qemu_capspriv.h | 12 ------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 9f327bccb4..3e6b503de5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3766,6 +3766,16 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps, } =20 =20 +struct _virQEMUCapsCachePriv { + char *libDir; + uid_t runUid; + gid_t runGid; + virArch hostArch; +}; +typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; +typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; + + static void virQEMUCapsCachePrivFree(void *privData) { diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 78f7e4ab39..d05256bd35 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -28,18 +28,6 @@ #ifndef __QEMU_CAPSPRIV_H__ # define __QEMU_CAPSPRIV_H__ =20 -# include "virarch.h" - -struct _virQEMUCapsCachePriv { - char *libDir; - uid_t runUid; - gid_t runGid; - virArch hostArch; -}; -typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; -typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; - - virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); =20 virQEMUCapsPtr --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list