VPP just won't work. God help
This commit is contained in:
150
vpp/patch.sh
Executable file
150
vpp/patch.sh
Executable file
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DOCKERFILE="${1:-Dockerfile}"
|
||||
SOURCE_DIR="${2:-}"
|
||||
|
||||
PATCH_DIR="patches/vpp"
|
||||
PATCH_FILE="${PATCH_DIR}/0001-buffer-fallback-log.patch"
|
||||
|
||||
mkdir -p "${PATCH_DIR}"
|
||||
|
||||
cat > "${PATCH_FILE}" <<'PATCH'
|
||||
--- a/src/vlib/buffer.c
|
||||
+++ b/src/vlib/buffer.c
|
||||
@@ -710,10 +710,10 @@
|
||||
if (!error)
|
||||
goto buffer_pool_create;
|
||||
|
||||
/* If alloc failed, retry without hugepages */
|
||||
- vlib_log_warn (bm->log_default,
|
||||
- "numa[%u] falling back to non-hugepage backed "
|
||||
- "buffer pool (%U)", numa_node, format_clib_error, error);
|
||||
+ fformat (stderr,
|
||||
+ "numa[%u] falling back to non-hugepage backed buffer pool\n",
|
||||
+ numa_node);
|
||||
clib_error_free (error);
|
||||
|
||||
error = vlib_physmem_shared_map_create
|
||||
PATCH
|
||||
|
||||
apply_one_patch() {
|
||||
local src_dir="$1"
|
||||
local patch_file="$2"
|
||||
|
||||
if patch -d "$src_dir" -p1 --dry-run --forward < "$patch_file" >/dev/null 2>&1; then
|
||||
echo "Applying $(basename "$patch_file") to $src_dir"
|
||||
patch -d "$src_dir" -p1 --forward < "$patch_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if patch -d "$src_dir" -p1 -R --dry-run < "$patch_file" >/dev/null 2>&1; then
|
||||
echo "Already applied: $(basename "$patch_file")"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "ERROR: could not apply $(basename "$patch_file") cleanly in $src_dir" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
apply_all_local() {
|
||||
local src_dir="$1"
|
||||
|
||||
[ -d "$src_dir" ] || {
|
||||
echo "Local source dir does not exist: $src_dir" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
local p
|
||||
for p in "${PATCH_DIR}"/*.patch; do
|
||||
[ -e "$p" ] || continue
|
||||
apply_one_patch "$src_dir" "$p"
|
||||
done
|
||||
}
|
||||
|
||||
patch_dockerfile() {
|
||||
local dockerfile="$1"
|
||||
|
||||
[ -f "$dockerfile" ] || {
|
||||
echo "Dockerfile skipped" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
python3 - "$dockerfile" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
dockerfile = Path(sys.argv[1])
|
||||
text = dockerfile.read_text()
|
||||
|
||||
begin = "# BEGIN LOCAL VPP PATCHES"
|
||||
end = "# END LOCAL VPP PATCHES"
|
||||
|
||||
block = r'''# BEGIN LOCAL VPP PATCHES
|
||||
COPY patches /tmp/patches
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends patch \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN set -eux; \
|
||||
if [ -d /tmp/patches/vpp ]; then \
|
||||
for p in /tmp/patches/vpp/*.patch; do \
|
||||
[ -e "$p" ] || continue; \
|
||||
if patch -p1 --dry-run --forward < "$p" >/dev/null 2>&1; then \
|
||||
patch -p1 --forward < "$p"; \
|
||||
elif patch -p1 -R --dry-run < "$p" >/dev/null 2>&1; then \
|
||||
echo "already applied: $p"; \
|
||||
else \
|
||||
echo "failed to apply patch: $p" >&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
done; \
|
||||
fi
|
||||
# END LOCAL VPP PATCHES
|
||||
'''
|
||||
|
||||
# Remove an older copy of the block if it exists.
|
||||
while begin in text and end in text:
|
||||
s = text.index(begin)
|
||||
e = text.index(end, s) + len(end)
|
||||
while e < len(text) and text[e] in "\r\n":
|
||||
e += 1
|
||||
text = text[:s] + text[e:]
|
||||
|
||||
needle = "WORKDIR /src/vpp"
|
||||
if needle not in text:
|
||||
raise SystemExit(f'Could not find insertion point: {needle}')
|
||||
|
||||
text = text.replace(needle, needle + "\n\n" + block, 1)
|
||||
dockerfile.write_text(text)
|
||||
PY
|
||||
|
||||
echo "Patched Dockerfile: $dockerfile"
|
||||
}
|
||||
|
||||
patch_dockerfile "$DOCKERFILE"
|
||||
|
||||
if [ -n "${SOURCE_DIR}" ]; then
|
||||
apply_all_local "$SOURCE_DIR"
|
||||
else
|
||||
echo "No local source dir given; only Dockerfile + patch files updated."
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
|
||||
Done.
|
||||
|
||||
Created:
|
||||
${PATCH_FILE}
|
||||
|
||||
Updated:
|
||||
${DOCKERFILE}
|
||||
|
||||
Usage:
|
||||
$(basename "$0") Dockerfile /path/to/extracted/vpp
|
||||
|
||||
Examples:
|
||||
$(basename "$0") Dockerfile /src/vpp
|
||||
$(basename "$0") path/to/Dockerfile ./vpp
|
||||
|
||||
EOF
|
||||
Reference in New Issue
Block a user