Initial import of the existing CephFS subvolume migration prototype, including the native libcephfs transport, rsync backend, local Ceph lab environment and integration tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
4.1 KiB
Bash
112 lines
4.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
umask 077
|
|
: "${CLUSTER_NAME:?set CLUSTER_NAME}"
|
|
CEPHMIG_OSD_GIB=${CEPHMIG_OSD_GIB:-4}
|
|
if [[ ! $CEPHMIG_OSD_GIB =~ ^[0-9]+$ ]] || ((10#$CEPHMIG_OSD_GIB < 4 || 10#$CEPHMIG_OSD_GIB > 64)); then
|
|
echo 'CEPHMIG_OSD_GIB must be an integer between 4 and 64' >&2; exit 1
|
|
fi
|
|
block_bytes=$((10#$CEPHMIG_OSD_GIB * 1024 * 1024 * 1024))
|
|
rm -f /run/cephmig-ready
|
|
mkdir -p /state/{mon,osd,mgr,mds} /etc/ceph /run/ceph
|
|
pids=()
|
|
cleanup() {
|
|
trap - EXIT TERM INT
|
|
rm -f /run/cephmig-ready
|
|
if ((${#pids[@]})); then
|
|
kill "${pids[@]}" 2>/dev/null || true
|
|
wait "${pids[@]}" 2>/dev/null || true
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
trap 'exit 0' TERM INT
|
|
start() { "$@" & pids+=("$!"); }
|
|
retry() {
|
|
local attempt
|
|
for ((attempt=0; attempt<90; attempt++)); do
|
|
if "$@"; then return 0; fi
|
|
sleep 2
|
|
done
|
|
echo "Timeout: $*" >&2
|
|
return 1
|
|
}
|
|
if [[ ! -f /state/fsid ]]; then cat /proc/sys/kernel/random/uuid > /state/fsid; fi
|
|
ip=$(hostname -i | awk '{print $1}')
|
|
cat > /etc/ceph/ceph.conf <<EOF
|
|
[global]
|
|
fsid = $(cat /state/fsid)
|
|
mon initial members = a
|
|
mon host = $CLUSTER_NAME
|
|
auth cluster required = cephx
|
|
auth service required = cephx
|
|
auth client required = cephx
|
|
auth allow insecure global id reclaim = false
|
|
log to stderr = true
|
|
log to file = false
|
|
mon allow pool size one = true
|
|
osd pool default size = 1
|
|
osd pool default min size = 1
|
|
osd pool default pg num = 8
|
|
osd pool default pgp num = 8
|
|
osd crush chooseleaf type = 0
|
|
osd memory target = 1073741824
|
|
bluestore block size = $block_bytes
|
|
bluestore block create = true
|
|
bluestore block db size = 0
|
|
bluestore block wal size = 0
|
|
[client]
|
|
client acl type = posix_acl
|
|
[mon.a]
|
|
mon data = /state/mon
|
|
[osd.0]
|
|
osd data = /state/osd
|
|
[mgr.a]
|
|
mgr data = /state/mgr
|
|
[mds.a]
|
|
mds data = /state/mds
|
|
mds cache memory limit = ${CEPHMIG_MDS_CACHE_BYTES:-1073741824}
|
|
EOF
|
|
if [[ ! -d /state/mon/store.db ]]; then
|
|
ceph-authtool --create-keyring /state/mon.keyring --gen-key -n mon.
|
|
ceph-authtool --create-keyring /etc/ceph/ceph.client.admin.keyring \
|
|
--gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' \
|
|
--cap mds 'allow *' --cap mgr 'allow *'
|
|
ceph-authtool /state/mon.keyring --import-keyring /etc/ceph/ceph.client.admin.keyring
|
|
monmaptool --create --clobber --addv a "[v2:$ip:3300,v1:$ip:6789]" --fsid "$(cat /state/fsid)" /state/monmap
|
|
ceph-mon --mkfs -i a --monmap /state/monmap --keyring /state/mon.keyring
|
|
else
|
|
# Compose can assign a different address after down/up.
|
|
ceph-mon -i a --extract-monmap /run/ceph/monmap
|
|
monmaptool --rm a /run/ceph/monmap
|
|
monmaptool --addv a "[v2:$ip:3300,v1:$ip:6789]" /run/ceph/monmap
|
|
ceph-mon -i a --inject-monmap /run/ceph/monmap
|
|
fi
|
|
start ceph-mon -i a -f --public-addr "$ip"
|
|
retry ceph status
|
|
ceph auth get-or-create mgr.a mon 'allow profile mgr' osd 'allow *' mds 'allow *' \
|
|
-o /state/mgr/keyring
|
|
start ceph-mgr -i a -f
|
|
if [[ ! -f /state/osd/whoami ]]; then
|
|
if [[ ! -f /state/osd-uuid ]]; then cat /proc/sys/kernel/random/uuid > /state/osd-uuid; fi
|
|
ceph osd new "$(cat /state/osd-uuid)" 0
|
|
ceph-osd -i 0 --mkfs --mkkey --osd-uuid "$(cat /state/osd-uuid)" --no-mon-config
|
|
fi
|
|
ceph auth add osd.0 osd 'allow *' mon 'allow profile osd' mgr 'allow profile osd' \
|
|
-i /state/osd/keyring
|
|
start ceph-osd -i 0 -f
|
|
retry bash -c 'ceph osd stat --format json | python3 -c '\''import json,sys; s=json.load(sys.stdin); sys.exit(s["num_up_osds"] != 1)'\'''
|
|
ceph auth get-or-create mds.a mon 'allow profile mds' mgr 'allow profile mds' \
|
|
osd 'allow rw tag cephfs *=*' mds 'allow' -o /state/mds/keyring
|
|
start ceph-mds -i a -f
|
|
# Explicit PG counts avoid an EINVAL in Umbrella's volume-create pool defaults.
|
|
retry ceph osd pool create cephfs.cephfs.meta 8
|
|
retry ceph osd pool create cephfs.cephfs.data 8
|
|
retry ceph fs new cephfs cephfs.cephfs.meta cephfs.cephfs.data
|
|
retry ceph fs subvolumegroup create cephfs migration
|
|
retry ceph fs subvolume create cephfs demo --group_name migration
|
|
ceph fs subvolume getpath cephfs demo --group_name migration > /etc/ceph/subvolume-path
|
|
touch /run/cephmig-ready
|
|
echo "Cluster $CLUSTER_NAME ready"
|
|
wait -n "${pids[@]}"
|
|
exit 1
|