Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3168 from devimc/2020-01-14/2.0/pmemTest
Browse files Browse the repository at this point in the history
integration: Add PMEM test for 2.0
  • Loading branch information
Julio Montes authored Jan 19, 2021
2 parents b7ba1ac + e1f442f commit 5e68339
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif
# union for 'make test'
UNION := functional debug-console $(DOCKER_DEPENDENCY) openshift crio docker-compose network \
docker-stability oci netmon kubernetes swarm vm-factory \
entropy ramdisk shimv2 tracing time-drift compatibility vcpus $(PODMAN_DEPENDENCY)
entropy ramdisk shimv2 tracing time-drift compatibility vcpus $(PODMAN_DEPENDENCY) pmem

# filter scheme script for docker integration test suites
FILTER_FILE = .ci/filter/filter_docker_test.sh
Expand Down Expand Up @@ -229,6 +229,9 @@ vcpus:
ipv6:
bash -f integration/ipv6/ipv6.sh

pmem:
bash -f integration/pmem/pmem_test.sh

test: ${UNION}

check: checkcommits log-parser
Expand Down Expand Up @@ -277,4 +280,5 @@ help:
tracing \
vcpus \
vfio \
vm-factory
vm-factory \
pmem
139 changes: 139 additions & 0 deletions cmd/pmemctl/pmemctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash
#
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

FILE=""
FS=""
MNT_DIR=""
SIZE=""

die() {
echo "ERROR: $*" >&2
exit 1
}

warn() {
echo -e "WARNING: $*" >&2
}

info() {
echo -e "INFO: $*"
}

help() {
cat << EOF
$0 is a command line tool to create raw files that can be used as pmem
volumes that support DAX[1] in Kata Containers.
USAGE:
$0 [OPTIONS] FILE
EXAMPLE:
$0 -s 10G -f xfs -m ~/dax_volume ~/file.dax
OPTIONS:
-f FS filesystem, only xfs(5) and ext4(5) support DAX[1]
-m DIR mount point in the host. Create a loop device for the file
and mount it in the DIR specified, DIR can be used as a volume
and Kata Containers will use it as a pmem volume that support DAX
-s SIZE file size. SIZE must be aligned to 128M, hence the minimum
supported size for a file is 128M
[1]- https://www.kernel.org/doc/Documentation/filesystems/dax.txt
EOF
}

create_file() {
local reserved_blocks_percentage=3
local block_size=4096
local data_offset=$((1024*1024*2))
local dax_alignment=$((1024*1024*2))
local nsdax_src_url="https://raw.githubusercontent.com/kata-containers/kata-containers/2.0-dev/tools/osbuilder/image-builder/nsdax.gpl.c"

truncate -s "${SIZE}" "${FILE}"
if [ $((($(stat -c '%s' "${FILE}")/1024/1024)%128)) -ne 0 ]; then
rm -f "${FILE}"
die "SIZE must be aligned to 128M"
fi

if [ ! -x nsdax ]; then
curl -Ls "${nsdax_src_url}" | gcc -x c -o nsdax -
fi
./nsdax "${FILE}" ${data_offset} ${dax_alignment}
sync

device=$(sudo losetup --show -Pf --offset ${data_offset} "${FILE}")
if [ "${FS}" == "xfs" ]; then
# DAX and reflink cannot be used together!
# Explicitly disable reflink, if reflink is listed in the metadata (-m) option
if mkfs.xfs 2>&1 | grep "\-m" | grep "reflink"; then
sudo mkfs.xfs -m reflink=0 -q -f -b size="${block_size}" "${device}"
else
sudo mkfs.xfs -q -f -b size="${block_size}" "${device}"
fi
else
sudo mkfs.ext4 -q -F -b "${block_size}" "${device}"
info "Set filesystem reserved blocks percentage to ${reserved_blocks_percentage}%"
sudo tune2fs -m "${reserved_blocks_percentage}" "${device}"
fi

if [ -z "${MNT_DIR}" ]; then
info "pmem volume will not be mounted"
info "It can be mounted later running: sudo mount \$(sudo losetup --show -Pf --offset ${data_offset} ${FILE}) \$MNT_DIR"
sudo losetup -d "${device}"
else
info "Mounting pmem volume at ${MNT_DIR}"
sudo mount "${device}" "${MNT_DIR}"
fi
}

main() {
local OPTIND
while getopts "f:hm:s:" opt;do
case ${opt} in
f)
FS="${OPTARG}"
;;
h)
help
exit 0
;;
m)
MNT_DIR="${OPTARG}"
;;
s)
SIZE="${OPTARG}"
;;
?)
# parse failure
help
die "Failed to parse arguments"
;;
esac
done
shift $((OPTIND-1))

FILE=$1

if [ -z "${FILE}" ]; then
die "mandatory FILE not supplied"
fi

if [ -z "${FS}" ]; then
FS="xfs"
warn "filesystem not supplied, using ${FS}"
elif [ "${FS}" != "xfs" ] && [ "${FS}" != "ext4" ]; then
die "Unsupported filesystem ${FS}"
fi

if [ -z "${SIZE}" ]; then
SIZE="128M"
warn "size not supplied, using ${SIZE}"
fi

create_file
}

main $@
58 changes: 58 additions & 0 deletions integration/pmem/data/dbinsert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
#
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
# This script is intended to run in a postgres container

script_dir="$(realpath $(dirname $0))"
source "${script_dir}/lib.sh"

rows=${1:-500}
script_dir="$(dirname $(realpath $0))"
sql_file="/var/lib/postgresql/data/sql.sql"
cat > "${sql_file}" <<EOF
CREATE TABLE ${db_table_name} (
id serial PRIMARY KEY,
name varchar NOT NULL,
age int NOT NULL,
phone varchar NOT NULL,
birth varchar NOT NULL,
country varchar NOT NULL,
company varchar NOT NULL,
email varchar NOT NULL
);
EOF

# to avoid jenkins kills the process due to inactivity
for i in $(seq 1 1000); do echo -n .; sleep 5; done &
dots_pid=$!
trap "kill -9 ${dots_pid}" EXIT

echo "generating sql file"
count=0
stop=false

export IFS=$'\n'
users=($(cat "${script_dir}/users.txt"));
while [ "${stop}" != "true" ]; do
for line in ${users[*]}; do
if [ ${count} -ge ${rows} ]; then
stop=true
break;
fi

IFS=' ' a=(${line//|/ }); IFS=$'\n'
echo "INSERT INTO ${db_table_name} (name, age, phone, birth, country, company, email) VALUES ('${a[0]}', ${a[1]}, '${a[2]}', '${a[3]}', '${a[4]}', '${a[5]}', '${a[6]}');" >> \
"${sql_file}"

((count++))
done
done
unset IFS

createdb "${db_name}"
echo "running sql file"
time psql -d "${db_name}" -f "${sql_file}" > /dev/null
rm -f "${sql_file}"
8 changes: 8 additions & 0 deletions integration/pmem/data/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

db_name="test"
db_table_name="users"
50 changes: 50 additions & 0 deletions integration/pmem/data/users.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Mia|8|1-878-506-7293|09-12-06|San Marino|Erat Vitae Risus Industries|[email protected]
April|9|1-476-475-4935|06-23-13|Congo, the Democratic Republic of the|Dui Ltd|[email protected]
Desirae|4|1-323-211-1417|05-22-17|Saint Pierre and Miquelon|Dictum Eu Placerat Consulting|[email protected]
Keaton|3|1-731-750-8259|01-31-20|Samoa|Nibh Institute|[email protected]
Fulton|6|1-839-967-2181|05-29-17|Chile|Orci Corp.|[email protected]
Conan|8|1-947-556-4165|03-05-12|Nauru|In Dolor Fusce Foundation|[email protected]
Isaiah|3|1-979-982-1576|10-11-20|Norway|Rutrum Fusce Corp.|[email protected]
Dolan|5|1-731-522-4184|07-20-19|New Caledonia|Libero Est Corp.|[email protected]
Colt|3|1-104-481-3139|10-11-00|Netherlands|Consequat Nec Ltd|[email protected]
Jenna|8|1-392-845-1268|09-16-19|South Sudan|Ac Arcu Institute|[email protected]
Roth|7|1-282-966-7511|09-21-06|Algeria|Diam Dictum Sapien Foundation|[email protected]
Ciaran|8|1-568-638-7495|07-17-02|Kazakhstan|Auctor PC|[email protected]
Heidi|1|1-838-317-9035|09-18-05|El Salvador|Nunc Mauris Sapien Associates|[email protected]
David|5|1-495-952-2285|08-22-18|Swaziland|Sit Amet Dapibus PC|[email protected]
Bethany|6|1-224-887-6250|02-07-14|Grenada|Diam Sed Company|[email protected]
Ryan|10|1-433-743-3598|05-03-18|Macao|Vestibulum Associates|[email protected]
Kimberley|3|1-414-236-8418|07-18-12|Christmas Island|Sociis Natoque Penatibus Associates|[email protected]
Shelley|1|1-600-985-2890|06-05-11|Norfolk Island|Maecenas Malesuada Fringilla LLC|[email protected]
Timothy|5|1-861-196-7838|11-14-06|Egypt|Nascetur LLC|[email protected]
Jasper|9|1-850-517-0401|05-29-15|Holy See (Vatican City State)|Parturient Montes Nascetur Limited|[email protected]
Jordan|2|1-670-715-6431|02-03-18|Netherlands|Enim Company|[email protected]
Heather|1|1-141-274-3979|05-21-17|Japan|Nulla Dignissim Maecenas LLC|[email protected]
Darius|4|1-137-939-6498|12-15-05|Georgia|Accumsan Sed LLC|[email protected]
Hadley|2|1-687-457-7782|09-18-14|Kuwait|Sagittis Duis Gravida PC|[email protected]
Gloria|1|1-287-641-5914|09-15-10|Guinea-Bissau|Sed Et Libero Corporation|[email protected]
Barry|2|1-846-581-1886|05-22-18|Luxembourg|Odio Phasellus Incorporated|[email protected]
Shad|2|1-639-780-2457|05-01-20|Senegal|Nec Tellus Corporation|[email protected]
Hilary|4|1-591-123-0234|11-23-09|Gabon|Tempor Diam Associates|[email protected]
Burton|5|1-475-741-3332|08-16-16|Costa Rica|Nunc Inc.|[email protected]
Adrian|5|1-467-133-2165|09-28-20|Marshall Islands|Vitae Industries|[email protected]
Baxter|8|1-240-908-5513|02-01-03|Malawi|Integer Foundation|[email protected]
Elliott|10|1-237-956-0542|10-16-14|Uganda|Nec Ante Corporation|[email protected]
Olivia|7|1-506-903-7178|09-29-00|Vanuatu|Aenean Eget Metus PC|[email protected]
Lucian|7|1-622-647-9202|07-24-17|Albania|At Velit Consulting|[email protected]
Jena|10|1-182-376-8455|03-27-13|Thailand|Et Magnis Dis Company|[email protected]
Jocelyn|4|1-519-152-6133|08-09-14|New Zealand|Magna Corporation|[email protected]
Melissa|10|1-106-662-9720|12-14-12|Ecuador|Sed Est LLP|[email protected]
Shana|5|1-340-840-0262|03-07-07|Cayman Islands|Amet Lorem Semper Limited|[email protected]
Lillian|5|1-373-254-6047|06-19-05|Czech Republic|Mattis Incorporated|[email protected]
Cruz|9|1-759-816-4647|10-17-01|Dominica|In Lobortis Tellus Inc.|[email protected]
Cassandra|8|1-813-754-6078|09-30-09|New Caledonia|Cras Lorem Lorem Ltd|[email protected]
Luke|10|1-350-972-1874|10-22-13|Botswana|Eleifend Cras Industries|[email protected]
Jared|10|1-136-782-5495|04-27-21|Algeria|Neque Institute|[email protected]
Denise|10|1-372-600-8336|09-10-10|Venezuela|Non Lobortis PC|[email protected]
Shannon|5|1-799-868-2692|10-18-19|Qatar|Mauris Integer Sem Corp.|[email protected]
Clarke|9|1-636-409-6331|02-17-06|Central African Republic|Sagittis Limited|[email protected]
Fletcher|2|1-701-579-5420|09-06-14|Lithuania|Nulla Ltd|[email protected]
Scott|5|1-405-626-4008|12-06-17|Brazil|Donec Company|[email protected]
Theodore|8|1-350-456-9220|04-07-20|Turkey|Aliquam Tincidunt LLC|[email protected]
Vivien|4|1-310-936-6729|11-12-20|Zambia|Tempor Augue Ac Corporation|[email protected]
Loading

0 comments on commit 5e68339

Please sign in to comment.