Show NBD devices above a numbering gap in vitastor-nbd ls #193

Closed
koolkhel wants to merge 1 commits from koolkhel/vitastor:nbd-ls-gap into master
4 changed files with 50 additions and 4 deletions

View File

@@ -329,6 +329,24 @@ jobs:
echo ""
done
test_nbd_ls:
runs-on: ubuntu-latest
needs: build
container: ${{env.TEST_IMAGE}}:${{github.sha}}
steps:
- name: Run test
id: test
timeout-minutes: 3
run: /root/vitastor/tests/test_nbd_ls.sh
- name: Print logs
if: always() && steps.test.outcome == 'failure'
run: |
for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do
echo "-------- $i --------"
cat $i
echo ""
done
test_img_online_resize:
runs-on: ubuntu-latest
needs: build

View File

@@ -14,6 +14,7 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <dirent.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -887,12 +888,18 @@ help:
json11::Json::object mapped;
int dev_num = -1;
int pid;
while (true)
// Not a counter: netlink devices can sit above nbds_max or above a destroyed device
DIR *sys_block = opendir("/sys/block");
while (sys_block)
{
dev_num++;
snprintf(path, sizeof(path), "/sys/block/nbd%d", dev_num);
if (access(path, F_OK) != 0)
dirent *ent = readdir(sys_block);
if (!ent)
{
closedir(sys_block);
break;
}
if (sscanf(ent->d_name, "nbd%d", &dev_num) != 1)
continue;
snprintf(path, sizeof(path), "/sys/block/nbd%d/pid", dev_num);
std::string pid_str = read_file(path);
if (pid_str == "")

View File

@@ -27,6 +27,7 @@ ETCD_SCHEME=https ./test_etcd_fail.sh
ETCD_SCHEME=https ANTIETCD=1 ./test_etcd_fail.sh
ETCD_SCHEME=https ./test_snapshot.sh
./test_nbd_ls.sh
./test_img_online_resize.sh
./test_no_uring.sh

20
tests/test_nbd_ls.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash -ex
. `dirname $0`/run_3osds.sh
$VITASTOR_CLI create -s 16M testimg
if ! (mount | grep '/dev type devtmpfs'); then
sudo bash -c 'mount udev /dev/ -t devtmpfs && mount devpts /dev/pts -t devpts'
fi
# A device number above nbds_max: netlink-map creates it, with a gap below it
NBD_NUM=$((1000 + RANDOM % 30000))
while [[ -e /sys/block/nbd$NBD_NUM ]]; do NBD_NUM=$((NBD_NUM+1)); done
NBD_DEV=$(sudo build/src/client/vitastor-nbd --config_path $VITASTOR_CFG netlink-map /dev/nbd$NBD_NUM --image testimg --nbd_destroy_on_disconnect 1)
trap "sudo build/src/client/vitastor-nbd netlink-unmap $NBD_DEV"' || true; kill -9 $(jobs -p)' EXIT
LS_PID=$(sudo build/src/client/vitastor-nbd ls --json | jq -r '.["'$NBD_DEV'"].pid')
[[ "$LS_PID" == "$(cat /sys/block/nbd$NBD_NUM/pid)" ]] || format_error "ls doesn't show $NBD_DEV"
format_green OK