Refuse to revive an NBD device with another image #155
Open
koolkhel
wants to merge 5 commits from
koolkhel/vitastor:nbd-backend-identifier into master
pull from: koolkhel/vitastor:nbd-backend-identifier
merge into: vitalif:master
vitalif:master
vitalif:primary-stickiness
vitalif:libvfn
vitalif:canceling
vitalif:immediate-repeering
vitalif:rdma-close-tcp
vitalif:use-degraded-writes
vitalif:fix-write-delete-flow
vitalif:openssl-3.0.12
vitalif:openssl-capture-secrets
vitalif:ignore-small-rdma-end
vitalif:encrypt-batch
vitalif:faster-peering-calc
vitalif:http-hello
vitalif:xxh3-bench
vitalif:create-user-etcd-based
vitalif:aesxts_streaming_nosupport
vitalif:refactor-heap-continue-write
vitalif:ston3lu-patch-0127
vitalif:rdma-credits
vitalif:heap-meta
vitalif:sendmsg-zc-no-more-error
vitalif:fix-clear-refs
vitalif:veeam-trick
vitalif:test-etcd-schizo
vitalif:test
vitalif:test1
vitalif:test2
vitalif:cow-meta
vitalif:kv-readahead
vitalif:qemu-fix-crash-idea
vitalif:eventloop-auto-init-trigger
vitalif:hugo-docs
vitalif:node-mutex-and-postpone
vitalif:check-writeback
vitalif:msgr-iothreads-v2
vitalif:antietcd
vitalif:rel-1.4
vitalif:test-fix-ec-unknown-state-51
vitalif:kv-update
vitalif:kv-debug
vitalif:hotfix-1.2.0
vitalif:rdma-simple-nodp
vitalif:zerocopy-tcp-send
vitalif:csi-staging
vitalif:hotfix-1.1.0
vitalif:hotfix-1.0.0
vitalif:fsync-feedback
vitalif:cached-reads
vitalif:qemu-send-loop
vitalif:test-double-alloc
vitalif:hier-failure-domains
vitalif:mon-self-restart
vitalif:epoch-deletions
vitalif:rdma-flow-control
vitalif:csi-use-vitastor-cli
vitalif:rdma-v2
vitalif:etcd-hide-base64
vitalif:lrc-matrix
vitalif:rm-left-on-dead
vitalif:nfs-proxy-old
vitalif:non-odp-rdma
vitalif:test-zctr
vitalif:separate-data-connections
vitalif:sec_osd_msgr
vitalif:test-assert
vitalif:nbd-vmsplice
vitalif:allow-etcd-address-option
vitalif:rdma-zerocopy
vitalif:rel-0.5
vitalif:openonload
vitalif:sync-io-test
vitalif:trace-sync
vitalif:trace-sqes
vitalif:test-submit-and-wait
vitalif:test-sq-poll
vitalif:blocking-uring-test
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "koolkhel/vitastor:nbd-backend-identifier"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
netlink-revive /dev/nbdN --image othersilently attached a dead netlink device to another image: it exited 0, the device read the other image, and writes went there. A filesystem mounted from the device ends up corrupting both images.The kernel already guards against this. A RECONFIGURE whose
NBD_ATTR_BACKEND_IDENTIFIERdiffers from the one given on CONNECT fails withbackend image doesn't match with ..., and one without it fails withmust specify backend. But vitastor-nbd never sent the attribute. The code was under#ifdef NBD_ATTR_BACKEND_IDENTIFIER, which is an enum value inlinux/nbd-netlink.hand never defined, and the caller passedNULLanyway.This PR:
check_c_source_compiles(HAVE_NBD_BACKEND_IDENTIFIER), since#ifdefcan't see an enum value. Headers older than Linux 5.14 build without it, as before;--image, and"<pool>:<inode>"with--pool --inode, onnetlink-mapandnetlink-revive;netlink-revivesection ofdocs/usage/nbd.*.md;tests/test_nbd_netlink_revive.sh: map an image,kill -9the daemon, check that a revive with another image fails and one with the same image restores the data.A live snapshot of a mapped image, then a server restart (fourth commit, Use the image name as the NBD backend identifier with --image).
snap-create img@smoves the nameimgto a new inode, and the running vitastor-nbd follows the name. The first version of this PR sent"<pool>:<inode>"of the inode at map time. So after the snapshot, the kernel kept the old inode's identifier and refused everynetlink-revive --image imgwithbackend image doesn't match with 1:1, untilnetlink-unmap. Reproduced on kernel 6.8.So the identifier now follows the way the device was mapped: the image name with
--image,"<pool>:<inode>"with--pool --inode. This is the one-line switch the first version offered. The costs, also in the docs:--imageis not revived with--pool --inodeof the same image, nor the other way round;--imagethe kernel compares the name, not the image: after a rename of a mapped image, the new name is refused, and the old name revives the device with whatever image has that name by then (fifth commit, docs only);1:5passes for--pool 1 --inode 5.Compatibility, checked on kernel 6.8:
must specify backend. I don't see a way around that short of not sending the identifier.The second commit, Show netlink-revived devices in vitastor-nbd ls, is about the same command: after
netlink-revivethe device works, butlsprinted nothing.lstook the device's server from/sys/block/nbdN/pid, which the kernel sets on CONNECT and keeps on RECONFIGURE, so after a revive it names the killed process. It also accepted onlymapandnetlink-mapcommand lines. Now a device whose sysfs pid isn't a runningmap/netlink-mapis looked up among the runningnetlink-reviveprocesses in/proc(only then, solsdoesn't scan/procotherwise). The help and docs said netlink devices never show up inls, which stopped being true whennetlink-mapwas added there; they now say that the sysfs pid of a revived device stays the old one. The test checksls --jsonafter the revive.The third commit fixes the kernel version in the docs (the attribute appeared in Linux 5.14, not 5.6; older kernels ignore it), logs vitastor-nbd in the test, and ends the test's wait for the killed daemon once it is a zombie:
kill -0succeeds on a zombie, and pid 1 of a container may never reap it.Found: the wrong-image revive was reproduced on kernel 6.8 as described below; the empty
lsafter a revive was seen in a test run (ddfrom the revived device worked,lsprinted nothing,/sys/block/nbdN/pidstill had the killed pid); the snapshot case came up in a review of this PR and was then reproduced on kernel 6.8 as described above.Tested as root on kernel 6.8 against a local 3-OSD cluster (
tests/run_3osds.sh):netlink-revive attached /dev/nbd0 of testimg to testimg2.snap-createstep, fails with the first three commits (netlink-revive ... --image testimg:backend image doesn't match with 1:1) and passes with the fourth, kernel 6.8.0-142.backend image doesn't match with testimg. Revive with the same image by--image, also after a livesnap-create: exit 0, the device reads the image.--pool 1 --inode 1 --size ...: revive with--image testimgfails (backend image doesn't match with 1:1), revive with the same--pool --inode --sizeworks and reads the image.map,netlink-map, busy devices, resize, revive afterkill -9andunmapwork as before.lscheck of the test fails with the first commit alone (ls doesn't show the revived /dev/nbd0) and passes with the second, kernel 6.8.0-142.Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.