Let's move those to their own newly created header (src/util/virmem.h)
as this will help us to easily start sharing the cgroup code that's
duplicated between QEMU and LXC.
Signed-off-by: Fabiano Fidêncio <fidencio(a)redhat.com>
---
src/conf/domain_conf.c | 11 +++----
src/conf/domain_conf.h | 43 ++-------------------------
src/qemu/qemu_command.c | 5 ++--
src/qemu/qemu_domain.c | 3 +-
src/util/virmem.h | 66 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 79 insertions(+), 49 deletions(-)
create mode 100644 src/util/virmem.h
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3384a36d76..78db2a6c2c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -60,6 +60,7 @@
#include "virhostdev.h"
#include "virmdev.h"
#include "virblkio.h"
+#include "virmem.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN
@@ -6174,7 +6175,7 @@ virDomainDefLifecycleActionValidate(const virDomainDef *def)
static int
virDomainDefMemtuneValidate(const virDomainDef *def)
{
- const virDomainMemtune *mem = &(def->mem);
+ const virMemTune *mem = &(def->mem);
size_t i;
ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
@@ -18188,7 +18189,7 @@ virDomainDefMaybeAddInput(virDomainDefPtr def,
static int
virDomainHugepagesParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt,
- virDomainHugePagePtr hugepage)
+ virMemHugePagePtr hugepage)
{
int ret = -1;
xmlNodePtr oldnode = ctxt->node;
@@ -26832,7 +26833,7 @@ virDomainResourceDefFormat(virBufferPtr buf,
static int
virDomainHugepagesFormatBuf(virBufferPtr buf,
- virDomainHugePagePtr hugepage)
+ virMemHugePagePtr hugepage)
{
int ret = -1;
@@ -26856,7 +26857,7 @@ virDomainHugepagesFormatBuf(virBufferPtr buf,
static void
virDomainHugepagesFormat(virBufferPtr buf,
- virDomainHugePagePtr hugepages,
+ virMemHugePagePtr hugepages,
size_t nhugepages)
{
size_t i;
@@ -27394,7 +27395,7 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
static int
virDomainMemtuneFormat(virBufferPtr buf,
- const virDomainMemtune *mem)
+ const virMemTune *mem)
{
virBuffer childBuf = VIR_BUFFER_INITIALIZER;
int ret = -1;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e9e6b6d6c4..10acc39861 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -58,6 +58,7 @@
# include "virsavecookie.h"
# include "virresctrl.h"
# include "virblkio.h"
+# include "virmem.h"
/* forward declarations of all device types, required by
* virDomainDeviceDef
@@ -2180,14 +2181,6 @@ struct _virDomainResourceDef {
char *partition;
};
-typedef struct _virDomainHugePage virDomainHugePage;
-typedef virDomainHugePage *virDomainHugePagePtr;
-
-struct _virDomainHugePage {
- virBitmapPtr nodemask; /* guest's NUMA node mask */
- unsigned long long size; /* hugepage size in KiB */
-};
-
# define VIR_DOMAIN_CPUMASK_LEN 1024
typedef struct _virDomainIOThreadIDDef virDomainIOThreadIDDef;
@@ -2247,38 +2240,6 @@ struct _virDomainVcpuDef {
virObjectPtr privateData;
};
-typedef struct _virDomainMemtune virDomainMemtune;
-typedef virDomainMemtune *virDomainMemtunePtr;
-
-struct _virDomainMemtune {
- /* total memory size including memory modules in kibibytes, this field
- * should be accessed only via accessors */
- unsigned long long total_memory;
- unsigned long long cur_balloon; /* in kibibytes, capped at ulong thanks
- to virDomainGetInfo */
-
- virDomainHugePagePtr hugepages;
- size_t nhugepages;
-
- /* maximum supported memory for a guest, for hotplugging */
- unsigned long long max_memory; /* in kibibytes */
- unsigned int memory_slots; /* maximum count of RAM memory slots */
-
- bool nosharepages;
- bool locked;
- int dump_core; /* enum virTristateSwitch */
- unsigned long long hard_limit; /* in kibibytes, limit at off_t bytes */
- unsigned long long soft_limit; /* in kibibytes, limit at off_t bytes */
- unsigned long long min_guarantee; /* in kibibytes, limit at off_t bytes */
- unsigned long long swap_hard_limit; /* in kibibytes, limit at off_t bytes */
-
- int source; /* enum virDomainMemorySource */
- int access; /* enum virDomainMemoryAccess */
- int allocation; /* enum virDomainMemoryAllocation */
-
- virTristateBool discard;
-};
-
typedef struct _virDomainPowerManagement virDomainPowerManagement;
typedef virDomainPowerManagement *virDomainPowerManagementPtr;
@@ -2380,7 +2341,7 @@ struct _virDomainDef {
char *description;
virBlkioTune blkio;
- virDomainMemtune mem;
+ virMemTune mem;
virDomainVcpuDefPtr *vcpus;
size_t maxvcpus;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0a353f87ba..968234b82a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -60,6 +60,7 @@
#include "virnuma.h"
#include "virgic.h"
#include "virmdev.h"
+#include "virmem.h"
#if defined(__linux__)
# include <linux/capability.h>
#endif
@@ -3202,8 +3203,8 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
if (pagesize == 0) {
- virDomainHugePagePtr master_hugepage = NULL;
- virDomainHugePagePtr hugepage = NULL;
+ virMemHugePagePtr master_hugepage = NULL;
+ virMemHugePagePtr hugepage = NULL;
bool thisHugepage = false;
/* Find the huge page size we want to use */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e12f05f9d1..661d78f77e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -54,6 +54,7 @@
#include "vircrypto.h"
#include "virrandom.h"
#include "virsystemd.h"
+#include "virmem.h"
#include "secret_util.h"
#include "logging/log_manager.h"
#include "locking/domain_lock.h"
@@ -3953,7 +3954,7 @@ static int
qemuDomainDefValidateMemory(const virDomainDef *def)
{
const long system_page_size = virGetSystemPageSizeKB();
- const virDomainMemtune *mem = &def->mem;
+ const virMemTune *mem = &def->mem;
if (mem->nhugepages == 0)
return 0;
diff --git a/src/util/virmem.h b/src/util/virmem.h
new file mode 100644
index 0000000000..1cd077f04b
--- /dev/null
+++ b/src/util/virmem.h
@@ -0,0 +1,66 @@
+/*
+ * virmem.h: Memory definitions and helpers
+ *
+ * Copyright (C) 2018 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
+ * <
http://www.gnu.org/licenses/>.
+ *
+ * Author: Fabiano Fidêncio <fidencio(a)redhat.com>
+ */
+
+#ifndef __VIR_MEM_H__
+# define __VIR_MEM_H__
+
+# include "virutil.h"
+
+typedef struct _virMemHugePage virMemHugePage;
+typedef virMemHugePage *virMemHugePagePtr;
+struct _virMemHugePage {
+ virBitmapPtr nodemask; /* guest's NUMA node mask */
+ unsigned long long size; /* hugepage size in KiB */
+};
+
+typedef struct _virMemTune virMemTune;
+typedef virMemTune *virMemTunePtr;
+struct _virMemTune {
+ /* total memory size including memory modules in kibibytes, this field
+ * should be accessed only via accessors */
+ unsigned long long total_memory;
+ unsigned long long cur_balloon; /* in kibibytes, capped at ulong thanks
+ to virDomainGetInfo */
+
+ virMemHugePagePtr hugepages;
+ size_t nhugepages;
+
+ /* maximum supported memory for a guest, for hotplugging */
+ unsigned long long max_memory; /* in kibibytes */
+ unsigned int memory_slots; /* maximum count of RAM memory slots */
+
+ bool nosharepages;
+ bool locked;
+ int dump_core; /* enum virTristateSwitch */
+ unsigned long long hard_limit; /* in kibibytes, limit at off_t bytes */
+ unsigned long long soft_limit; /* in kibibytes, limit at off_t bytes */
+ unsigned long long min_guarantee; /* in kibibytes, limit at off_t bytes */
+ unsigned long long swap_hard_limit; /* in kibibytes, limit at off_t bytes */
+
+ int source; /* enum virDomainMemorySource */
+ int access; /* enum virDomainMemoryAccess */
+ int allocation; /* enum virDomainMemoryAllocation */
+
+ virTristateBool discard;
+};
+
+#endif /* __VIR_MEM_H__ */
--
2.17.1