From 0b2d8daeecec5ad569999baa72f9b4565a535db7 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Mon, 1 Aug 2022 20:42:09 +0200 Subject: [PATCH] Add support for local SSDs Add a systemd service which, on boot, partitions local SSD and installs Rustup and Cargo on it for NayDuck to use. Since the disk is quite a bit larger than what we need, use part of it for swap which should help with Docker tests sometimes failing. --- automation/setup-host.sh | 6 ++-- systemd/nayduck-fuzzer.service | 2 +- systemd/nayduck-local-ssd.service | 8 +++++ systemd/nayduck-worker.service | 2 +- systemd/setup-local-ssd.sh | 57 +++++++++++++++++++++++++++++++ workers/utils.py | 15 +++++--- 6 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 systemd/nayduck-local-ssd.service create mode 100644 systemd/setup-local-ssd.sh diff --git a/automation/setup-host.sh b/automation/setup-host.sh index 69785dd0..30206978 100644 --- a/automation/setup-host.sh +++ b/automation/setup-host.sh @@ -36,7 +36,7 @@ set -x apt-get -y update apt-get -y upgrade -apt-get -y install git python3-pip libpq-dev lld libclang-dev +apt-get -y install fdisk git python3-pip libpq-dev lld libclang-dev grep -q ^nayduck: /etc/passwd || adduser --disabled-login --gecos NayDuck nayduck @@ -89,8 +89,8 @@ else fi case $type in -frontend) services=ui ;; -worker) services='worker fuzzer' ;; +frontend) services=ui ;; +worker) services='local-ssd worker fuzzer' ;; *) services=$type esac for service in $services; do diff --git a/systemd/nayduck-fuzzer.service b/systemd/nayduck-fuzzer.service index 1f8cb826..348e97b1 100644 --- a/systemd/nayduck-fuzzer.service +++ b/systemd/nayduck-fuzzer.service @@ -1,6 +1,6 @@ [Unit] Description=NayDuck Fuzzer -After=network.target +After=network.target local-ssd.service [Service] Restart=always diff --git a/systemd/nayduck-local-ssd.service b/systemd/nayduck-local-ssd.service new file mode 100644 index 00000000..8595fee6 --- /dev/null +++ b/systemd/nayduck-local-ssd.service @@ -0,0 +1,8 @@ +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/home/nayduck/nayduck +ExecStart=/bin/sh systemd/setup-local-ssd.sh + +[Install] +WantedBy=multi-user.target diff --git a/systemd/nayduck-worker.service b/systemd/nayduck-worker.service index d29204df..8afa1fce 100644 --- a/systemd/nayduck-worker.service +++ b/systemd/nayduck-worker.service @@ -1,6 +1,6 @@ [Unit] Description=NayDuck Worker -After=network.target nayduck-fuzzer.service +After=network.target nayduck-fuzzer.service local-ssd.service [Service] Restart=always diff --git a/systemd/setup-local-ssd.sh b/systemd/setup-local-ssd.sh new file mode 100644 index 00000000..92d4540e --- /dev/null +++ b/systemd/setup-local-ssd.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +set -eux + +dev=/dev/nvme0n1 +dir=/datadrive + +# Sanity checks +if ! [ -e "$dev" ]; then + echo "$dev: device does not exist; nothing to do" + exit 0 +fi + +if ! [ -e "${dev}p1" ]; then + # Partition the disk: + # - p1 → data partition, will become /datadrive + # - p2 → swap partition + sfdisk "$dev" <$dir/README < str: def setup_environ() -> None: """Configures environment variables for workers and builders.""" + # Look for Cargo. + path = WORKDIR / 'home/cargo' + if (path / 'bin/cargo').is_file(): + os.environb[b'CARGO_HOME'] = os.fsencode(path) + os.environb[b'RUSTUP_HOME'] = os.fsencode(WORKDIR / 'home/rustup') + cargo_bin = path / 'bin' + else: + cargo_bin = pathlib.Path.home() / '.cargo/bin' + # Add Cargo to PATH and remove various unnecessary directories pathsep = os.fsencode(os.pathsep) paths = os.environb.get(b'PATH', os.fsencode(os.defpath)).split(pathsep) @@ -285,14 +294,12 @@ def setup_environ() -> None: path for path in paths if path.startswith(b'/') and not path.endswith(b'/sbin') ] - - cargo_bin = pathlib.Path.home() / '.cargo/bin' if cargo_bin.exists(): paths.insert(0, os.fsencode(cargo_bin)) - os.environb[b'PATH'] = pathsep.join(paths) - # Configure Cargo builds + # Configure Cargo builds to make compilation faster. We don’t need + # super-optimised builds thus disabling LTO and using lld. os.environb[b'CARGO_PROFILE_RELEASE_LTO'] = b'false' os.environb[b'CARGO_PROFILE_DEV_DEBUG'] = b'0' os.environb[b'CARGO_PROFILE_TEST_DEBUG'] = b'0'