git: e6f5aeddaf16 - main - emulators/qemu: Use system dtc from ports

From: Muhammad Moinur Rahman <bofh_at_FreeBSD.org>
Date: Fri, 10 Dec 2021 20:39:46 UTC
The branch main has been updated by bofh:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e6f5aeddaf1655f5fb55cc50541c10f814dc14d1

commit e6f5aeddaf1655f5fb55cc50541c10f814dc14d1
Author:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
AuthorDate: 2021-12-10 20:36:20 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2021-12-10 20:39:32 +0000

    emulators/qemu: Use system dtc from ports
    
    - elf2dmp depends on CURL [1]
    - Fix build when fusefs-libs3 is installed [2]
    
    PR:     260315 [2]
    Reported by: kostikbel@gmail.com [1] d8zNeCFG@aon.at [2]
---
 emulators/qemu/Makefile                        | 11 +--
 emulators/qemu/files/patch-block_export_fuse.c | 51 +++++++++++++
 emulators/qemu/files/patch-configure           |  6 +-
 emulators/qemu/files/patch-meson.build         | 20 ++++++
 emulators/qemu/pkg-message                     | 99 ++------------------------
 emulators/qemu/pkg-plist                       |  2 +-
 6 files changed, 88 insertions(+), 101 deletions(-)

diff --git a/emulators/qemu/Makefile b/emulators/qemu/Makefile
index b63ebed17fe2..fa573051e78a 100644
--- a/emulators/qemu/Makefile
+++ b/emulators/qemu/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	qemu
 PORTVERSION=	6.1.0
+PORTREVISION=	1
 CATEGORIES=	emulators
 MASTER_SITES=	https://download.qemu.org/
 DIST_SUBDIR=	qemu/${PORTVERSION}
@@ -11,16 +12,16 @@ COMMENT?=	QEMU CPU Emulator
 
 LICENSE=	GPLv2
 
-BUILD_DEPENDS=	sphinx-build:textproc/py-sphinx \
+BUILD_DEPENDS=	sphinx-build:textproc/py-sphinx@${PY_FLAVOR}\
 		${PYTHON_PKGNAMEPREFIX}sphinx_rtd_theme>0:textproc/py-sphinx_rtd_theme@${PY_FLAVOR} \
 		bash:shells/bash
 LIB_DEPENDS?=	libepoxy.so:graphics/libepoxy \
+		libfdt.so:sysutils/dtc \
 		libfontconfig.so:x11-fonts/fontconfig \
 		libfreetype.so:print/freetype2 \
 		libnettle.so:security/nettle \
 		libpcre2-8.so:devel/pcre2 \
 		libzstd.so:archivers/zstd
-#		libfdt.so:sysutils/dtc
 
 .if !defined(PKGNAMESUFFIX) || (${PKGNAMESUFFIX} != "-utils" && ${PKGNAMESUFFIX} != "-guest-agent")
 ONLY_FOR_ARCHS=	amd64 powerpc powerpc64 powerpc64 powerpc64le
@@ -108,11 +109,11 @@ PORTDOCS?=	.buildinfo _static/* about/* devel/* docs genindex.html \
 
 WITHOUT_CPU_CFLAGS=yes	#to avoid problems with register allocation
 CFLAGS:=	${CFLAGS:C/-fno-tree-vrp//}
-CONFIGURE_ARGS?=--localstatedir=/var --extra-ldflags=-L\"/usr/lib\" \
-		--extra-ldflags=-L\"${LOCALBASE}/lib\" \
+CONFIGURE_ARGS?=--localstatedir=/var --extra-ldflags=-L/usr/lib \
+		--extra-ldflags=-L${LOCALBASE}/lib \
 		--prefix=${PREFIX} --cc=${CC} --enable-netmap --disable-kvm \
 		--disable-linux-user --disable-linux-aio --disable-xen \
-		--python=${PYTHON_CMD} \
+		--python=${PYTHON_CMD} --enable-fdt=system \
 		--extra-cflags=-I${WRKSRC}\ -I${LOCALBASE}/include\ -DPREFIX=\\\"\"${PREFIX}\\\"\"
 
 .include <bsd.port.options.mk>
diff --git a/emulators/qemu/files/patch-block_export_fuse.c b/emulators/qemu/files/patch-block_export_fuse.c
new file mode 100644
index 000000000000..af18e3c3d9f0
--- /dev/null
+++ b/emulators/qemu/files/patch-block_export_fuse.c
@@ -0,0 +1,51 @@
+--- block/export/fuse.c.orig	2021-12-10 19:29:04 UTC
++++ block/export/fuse.c
+@@ -618,47 +618,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t 
+         return;
+     }
+ 
+-    if (mode & FALLOC_FL_KEEP_SIZE) {
+-        length = MIN(length, blk_len - offset);
+-    }
+-
+-    if (mode & FALLOC_FL_PUNCH_HOLE) {
+-        if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+-            fuse_reply_err(req, EINVAL);
+-            return;
+-        }
+-
+-        do {
+-            int size = MIN(length, BDRV_REQUEST_MAX_BYTES);
+-
+-            ret = blk_pdiscard(exp->common.blk, offset, size);
+-            offset += size;
+-            length -= size;
+-        } while (ret == 0 && length > 0);
+-    }
+-#ifdef CONFIG_FALLOCATE_ZERO_RANGE
+-    else if (mode & FALLOC_FL_ZERO_RANGE) {
+-        if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + length > blk_len) {
+-            /* No need for zeroes, we are going to write them ourselves */
+-            ret = fuse_do_truncate(exp, offset + length, false,
+-                                   PREALLOC_MODE_OFF);
+-            if (ret < 0) {
+-                fuse_reply_err(req, -ret);
+-                return;
+-            }
+-        }
+-
+-        do {
+-            int size = MIN(length, BDRV_REQUEST_MAX_BYTES);
+-
+-            ret = blk_pwrite_zeroes(exp->common.blk,
+-                                    offset, size, 0);
+-            offset += size;
+-            length -= size;
+-        } while (ret == 0 && length > 0);
+-    }
+-#endif /* CONFIG_FALLOCATE_ZERO_RANGE */
+-    else if (!mode) {
++    if (!mode) {
+         /* We can only fallocate at the EOF with a truncate */
+         if (offset < blk_len) {
+             fuse_reply_err(req, EOPNOTSUPP);
diff --git a/emulators/qemu/files/patch-configure b/emulators/qemu/files/patch-configure
index 0137de386d62..4e00150cb80e 100644
--- a/emulators/qemu/files/patch-configure
+++ b/emulators/qemu/files/patch-configure
@@ -1,6 +1,6 @@
---- configure.orig	2021-09-27 14:03:42 UTC
+--- configure.orig	2021-08-24 17:35:40 UTC
 +++ configure
-@@ -1635,7 +1635,7 @@ if test "$mingw32" = "yes" ; then
+@@ -1640,7 +1640,7 @@ if test "$mingw32" = "yes" ; then
  else
      bindir="${bindir:-$prefix/bin}"
  fi
@@ -9,7 +9,7 @@
  datadir="${datadir:-$prefix/share}"
  docdir="${docdir:-$prefix/share/doc}"
  sysconfdir="${sysconfdir:-$prefix/etc}"
-@@ -4607,6 +4607,9 @@ echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $confi
+@@ -4612,6 +4612,9 @@ echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $confi
  # if this macro is set.
  if test "$have_fsxattr" = "yes" ; then
      echo "HAVE_FSXATTR=y" >> $config_host_mak
diff --git a/emulators/qemu/files/patch-meson.build b/emulators/qemu/files/patch-meson.build
new file mode 100644
index 000000000000..5359dd16ef0e
--- /dev/null
+++ b/emulators/qemu/files/patch-meson.build
@@ -0,0 +1,20 @@
+--- meson.build.orig	2021-12-10 18:55:23 UTC
++++ meson.build
+@@ -1901,14 +1901,10 @@ fdt_opt = get_option('fdt')
+ if have_system
+   if fdt_opt in ['enabled', 'auto', 'system']
+     have_internal = fs.exists(meson.current_source_dir() / 'dtc/libfdt/Makefile.libfdt')
+-    fdt = cc.find_library('fdt', kwargs: static_kwargs,
++    fdt = cc.find_library('fdt', kwargs: static_kwargs, dirs: '/usr/local/lib/',
+                           required: fdt_opt == 'system' or
+-                                    fdt_opt == 'enabled' and not have_internal)
+-    if fdt.found() and cc.links('''
+-       #include <libfdt.h>
+-       #include <libfdt_env.h>
+-       int main(void) { fdt_check_full(NULL, 0); return 0; }''',
+-         dependencies: fdt)
++                                    fdt_opt == 'enabled' )
++    if fdt.found()
+       fdt_opt = 'system'
+     elif have_internal
+       fdt_opt = 'internal'
diff --git a/emulators/qemu/pkg-message b/emulators/qemu/pkg-message
index 4ce5e9a61853..54a7ebc05d6d 100644
--- a/emulators/qemu/pkg-message
+++ b/emulators/qemu/pkg-message
@@ -8,51 +8,18 @@ FreeBSD host notes
   networking as non-root.  Don't forget to adjust device node permissions in
   /etc/devfs.rules.
 
-- slirp (usermode networking) is fixed now in cvs, on FreeSBIE 1.0 guests you
-  still have to manually do: echo nameserver 10.0.2.3 >/etc/resolv.conf but
-  i've been told that that's normal.  (fixed on FreeSBIE 1.1.) And you have
-  to wait a bit for dhclient to do its thing; traffic to address 10.0.2.2 is
-  routed to 127.1 on the host.
-
-- Expect timer problems when guest kernel HZ is > hosts, for example time
-  sleep 1 takes 49 seconds and booting sleeps for minutes at the acd0 probe
-  with a FreeSBIE 1.0 guest, thats because its kernel is built with HZ=5000,
-  and FreeBSD's default is 100...  (no longer a problem with FreeSBIE 1.1.)
-  The linux 2.6 kernel uses 1000 by default btw.  (changed to 250 later, and
-  recent linux kernels now no longer have a fixed HZ, aka `tickless
-  kernel'...)  Enabling /dev/rtc doesn't seem to help either (not included
-  since it needs a patch to emulators/rtc.)
-
-- Update: the above problem has gotten worse with FreeBSD guests
-  somewhere before 8.0, mainly since the kernel now usually wants
-  double or even quadruple number of timer irqs compared to HZ if
-  it detects an apic (and at least early versions of FreeBSD 8 had
-  a bug that essentially halved qemu's clock rate too); the only
-  reason you usually don't see symptoms of this with FreeBSD 8
-  guests is they automatically reduce their HZ to 100 when running
-  in a VM while the default for the host kernel is still HZ=1000.
-  Workaround: you can disable the apic clock in the guest by setting
-
-	hint.apic.0.clock="0"
-
-  in loader.conf(5) (or manually at the loader prompt), if that
-  doesn't work the only things you can do is either reduce the
-  guest's HZ to, say, 100 by setting e.g.
-
-	kern.hz="100"
-
-  from the loader as above (which usually is a good idea in a VM
-  anyway and FreeBSD 8 now does by itself as mentioned), or otherwise
-  increase the host's HZ to 2000 or even 4000 from the loader in
-  the same way.
+- Expect timer problems when guest kernel HZ is > hosts.  The linux 2.6
+  kernel uses 1000 by default btw.  (changed to 250 later, and recent linux
+  kernels now no longer have a fixed HZ, aka `tickless kernel'...)
+  Enabling /dev/rtc doesn't seem to help either (not included since it needs
+  a patch to emulators/rtc.)
 
 - The -smb option (smb-export local dir to guest using the default
   slirp networking) needs the samba port/package installed
   in addition to qemu. (SAMBA knob.)
 
 - If you want to use usb devices connected to the host in the guest
-  yot need either recent 10-current (not tested yet much) or you can
-  use usbredir over the network (see below); also unless you are
+  yot can use usbredir over the network (see below); also unless you are
   running qemu as root you then need to fix permissions for /dev/ugen*
   device nodes: if you are on 5.x or later (devfs) put a rule in
   /etc/devfs.rules, activate it in /etc/rc.conf and run /etc/rc.d/devfs
@@ -65,35 +32,6 @@ FreeBSD host notes
 
 	devfs_system_ruleset="ugen_ruleset"
 
-- If you want to test the new (in 0.15.0) usb network redirection (USBREDIR
-  option) see this thread by Hans de Goede <hdegoede <at> redhat.com>:
-
-	http://thread.gmane.org/gmane.comp.emulators.qemu/110176/focus=110183
-
-  Quote:
-
-  Example usage:
-
-  1) Start usbredirserver for a usb device:
-  sudo usbredirserver 045e:0772
-  2) Start qemu with usb2 support + a chardev talking to usbredirserver +
-     a usb-redir device using this chardev:
-  qemu -usb \
-    -readconfig docs/ich9-ehci-uhci.cfg \
-    -chardev socket,id=usbredirchardev,host=localhost,port=4000 \
-    -device usb-redir,chardev=usbredirchardev,id=usbredirdev ...
-
-  [you would replace docs/ich9-ehci-uhci.cfg with e.g.
-  /usr/local/share/doc/qemu/docs/ich9-ehci-uhci.cfg, but turns out
-  ehci was broken for me here with FreeBSD guests and the previous
-  qemu version at least, I got:
-
-	FETCHENTRY: entry at 22C5484 is of type 2 which is not supported yet
-processing error - resetting ehci HC
-	Assertion failed: (0), function ehci_advance_state, file /data/ports/emulators/qemu-devel/work/qemu-0.15.0/hw/usb-ehci.c, line 2045.
-
-  The new qemu version works better tho.]
-
 - Still usb: since the hub is no longer attached to the uchi controller and
   the wakeup mechanism, resume interrupt is not implemented yet linux guests
   will suspend the bus, i.e. they wont see devices usb_add'ed after its
@@ -105,7 +43,7 @@ processing error - resetting ehci HC
 - If you get repeated `atapi_poll called!' console messages with FreeBSD
   guests or other weird cdrom problems then thats probably because the guest
   has atapicam loaded, which for reasons still to be determined has problems
-  with qemu's now by default enabled cdrom dma.  You can build the port with
+  with qemu's now by default enabled cdrom dma. You can build the port with
   CDROM_DMA disabled to disable it.  [Looks like this is fixed in recent
   FreeBSD guest versions.]
 
@@ -160,29 +98,6 @@ processing error - resetting ehci HC
   /dev/acd0' in the monitor after taking out the disc if a guest cannot eject
   it itself.)
 
-- The default configuration location (qemu-ifup script etc.) has been changed
-  from /etc to PREFIX/etc (usually /usr/local/etc).  Move your files
-  accordingly.
-
-- The pcap code (-net nic... -net pcap,ifname=...) should work properly now,
-  with only one exception:  Advanced features like TSO used on the host
-  interface can cause oversize packets which now do get truncated to avoid
-  confusing/panicing guests but of course still will cause retransmissions.
-  So if you see slow throughput and `pcap_send: packet size > ..., truncating'
-  messages on qemu's tty try disabling TSO etc on the host interface at least
-  while using pcap.
-
-- kqemu is no longer supported in qemu upstream after the 0.11 branch
-  was created, which means also not in this version.  (Linux has moved
-  on to kvm now for qemu(-like) virtualization needs, so if you want qemu
-  to go faster and don't want to switch to virtualbox or stick to the older
-  emulators/qemu port which is at 0.11.1 atm and as such still supports
-  kqemu you should help getting the FreeBSD kvm port updated and
-  completed:
-
-	http://wiki.freebsd.org/FabioChecconi/PortingLinuxKVMToFreeBSD
-
-  )
 EOM
 }
 ]
diff --git a/emulators/qemu/pkg-plist b/emulators/qemu/pkg-plist
index 7b1e0a6161bf..91a3cfabc794 100644
--- a/emulators/qemu/pkg-plist
+++ b/emulators/qemu/pkg-plist
@@ -1,4 +1,4 @@
-bin/elf2dmp
+%%CURL%%bin/elf2dmp
 bin/qemu-edid
 bin/qemu-ga
 bin/qemu-i386