# Migration prototype The evaluation of a direct RADOS object transfer and the native alternative through libcephfs are documented in [raw-transfer.md](raw-transfer.md). ## Snapshot identity: documented deviation Native snapshot IDs and Ceph birth times are assigned anew at the target. As agreed, this deviation does not block the migration. `inspect`, the transfer output and the persistent journal contain a note; the original and the new creation times are recorded for every transferred snapshot. An application that stores native IDs directly must account for the new values. The supported `ceph_mksnap` interface accepts a name, a mode and custom metadata, but no desired native ID or birth time. `ceph.snap.btime` is explicitly read-only in the client. CephFS mirroring also creates a new snapshot at the target and records the source ID as separate metadata. Sources: - [libcephfs interface](https://github.com/ceph/ceph/blob/main/src/include/cephfs/libcephfs.h) - [Client: virtual snapshot attributes](https://github.com/ceph/ceph/blob/main/src/client/Client.cc) - [Mirror: creating a target snapshot](https://github.com/ceph/ceph/blob/main/src/tools/cephfs_mirror/PeerReplayer.cc) In the local Ceph 21.2.0 lab, a snapshot of the same name had source ID 6 and target ID 2 and different birth times. An attempt to write the existing value of `ceph.snap.btime` on our own test snapshot was rejected with `EROFS`. The examined interfaces do not allow the native snapshot identity to be set. This limitation is accepted and explicitly recorded. Load tests and an automated production client cutover are still missing. ## Commands CephMig needs Linux, the Ceph CLI, libcephfs and a copier built with CGO and `-tags ceph`. It needs no operating system mounts and no privileged container. Preserving foreign UID/GID and protected xattrs requires the corresponding client and process privileges; the lab uses root. An rsync backend over mounted file systems existed earlier and was removed; a configuration with `backend: rsync` or `mount` is rejected. The subvolumes must already exist. For a new job, the data tree, snapshots and custom metadata of the target must be empty. No application may write to the target. The configuration in `dev/migration.example.json` applies to the lab service `native`. `backend` may be omitted; its only value is `native`. `workers` limits concurrent file copies and verification checks (default 8, at most 64), `bandwidth_kib` limits the total payload bytes written per second. Both values may be changed when resuming. The `transfer` statistics in the journal report the mode, the base snapshot, visited and copied files, bytes written and read for verification, the files transferred with blockdiff, the entries reported by snapdiff and the duration of the round in seconds. `bytes_copied` counts payload writes without skipped zero ranges; it does not measure the total network traffic including protocol and verification. ```sh make dev-native-build docker compose -f dev/compose.yaml up -d --wait native docker compose -f dev/compose.yaml exec native \ cephmig-native inspect --config /lab/migration.example.json ``` The read-only preflight compares the FSID from the CLI with the `ceph.cluster_fsid` read through the client, checks paths and subvolume state and reports the current data size and snapshot names. The data size is **not** a capacity forecast for all historical snapshots. The transfer commands are: ```sh cephmig sync --config /absolute/config.json --state /local-state/job.json cephmig status --state /local-state/job.json # Stop and flush all source writers, including other clients. cephmig finalize --config /absolute/config.json \ --state /local-state/job.json --writers-stopped # After the cutover has been checked: cephmig cleanup --config /absolute/config.json --state /local-state/job.json ``` `sync` processes known, unfinished states, newly discovered application snapshots and then a new source snapshot. Further changes are caught up by running `sync` again. CephMig uses snapdiff and the Ceph inode version, so it also detects data changes with the same size and mtime. ### Metadata scan Every round reads the metadata of all entries of its snapshot. This is the main cost of a round: in the [one-million-file test](million-local.md), even an unchanged finalization took 1 h 20 min and 19.3 million MDS requests. Snapdiff cannot replace this scan; in the lab it reported every directory and missed pure chmod, xattr changes and writes through a hardlink alias. An earlier version skipped a subdirectory in intermediate rounds when its inode version and its `ceph.dir.rctime` matched the previous round. It was removed because it missed changes. In the 10,000-file test on 2026-12-03, a round snapshot taken seconds after changes skipped the directory `tree/` with about 250 changed files in its subdirectories: the inode version of `tree/` changes only with its own entries, and Ceph had not yet propagated the rctime of the grandchildren to it. That target snapshot was incomplete, and its verification did not notice, because it skipped the same subtrees; only `finalize`, which always scanned everything, closed the gap. Base index entries that this version marked `carried` are never trusted; such files are copied in full in the next round. `finalize` relies solely on the operator's explicit confirmation of the write stop; it does not stop or lock any application itself. All writers must stay stopped until the cutover is complete. The job ends in `ready-for-cutover`. Remounts, application restarts and a migration back after writes to the target are not automated. ### Migration snapshots Each round creates a snapshot `cephmig--` at source and target. Only the newest one is needed, as base for the next round. As soon as a round is complete, `sync` deletes the older round snapshots on both sides. Users of the subvolume therefore see at most one migration snapshot at a time. `cleanup` deletes the remaining round snapshot, including the final one, after the job is `ready-for-cutover`. Afterwards the subvolumes hold only the snapshots of the application. Since the final snapshot is the immutable reference of the last round, run `cleanup` only after the cutover has been checked. As its last step, `cleanup` deletes the target claim (see below) and the directories `.cephmig/claims` and `.cephmig` if they are empty. The job is then finished: `cleanup` and `finalize` do nothing more, and `sync` is refused. `cleanup` is idempotent. Application snapshots are never deleted. The journal marks a snapshot as `removed` before deleting it, so an interrupted run completes the deletion next time. ## Workflow in detail The diagram shows one migration with the native backend: an intermediate `sync` round, `finalize` and `cleanup`. Application snapshots discovered at the source are transferred like a round, but are never deleted. ```mermaid sequenceDiagram autonumber actor Op as Operator participant M as cephmig participant J as Journal (local) participant I as Index (local bbolt) participant S as Source cluster participant T as Target cluster participant V as Verify client Op->>M: sync --config --state M->>S: fsid, subvolume info, snapshot ls M->>T: fsid, subvolume info, snapshot ls M->>T: lock claim in /.cephmig/claims M->>J: record intent for round snapshot R(n) M->>S: create snapshot R(n) M->>J: invalidate the confirmed base M->>I: open base R(n-1), create pending index M->>S: snapdiff R(n-1) to R(n) loop every entry, from the root down M->>I: record path inventory M->>T: mkdir, copy changed files (blockdiff or full), symlinks, FIFOs M->>T: xattrs and quotas, then setattr and ctime stamp end M->>T: hardlink aliases, prune surplus entries M->>T: restore directory metadata, deepest first M->>T: sync_fs M->>V: connect a fresh client, close the writing client V->>T: compare metadata, links and copied ranges with R(n) M->>T: create snapshot R(n), copy snapshot metadata V->>T: compare snapshot R(n) with R(n) M->>I: commit pending index as new base M->>J: mark R(n) done, base = R(n) M->>J: mark R(n-1) removed M->>S: remove snapshot R(n-1) M->>T: remove snapshot R(n-1) M-->>Op: journal as JSON Note over Op,S: all writers stopped Op->>M: finalize --writers-stopped M->>S: create final snapshot F Note over M,T: same steps as a sync round M->>J: mark F done, R(n) removed M->>S: remove snapshot R(n) M->>T: remove snapshot R(n) V->>T: verify complete inventory against F M->>J: phase = ready-for-cutover Note over Op,T: clients switched to the target and checked Op->>M: cleanup M->>J: mark F removed M->>S: remove snapshot F M->>T: remove snapshot F ``` ## Transferred data - Snapshot names and contents; existing snapshots are transferred in chronological order. - Numeric UID/GID, mode, POSIX ACLs including default ACLs. - Timestamps of every file, directory and symlink: | Timestamp | preserved | | --- | --- | | mtime (last modification) | yes | | btime (creation) | yes | | atime (last access) | yes | | ctime (last status change) | yes¹ | ¹ To the nanosecond, but never lower than the mtime: if the source mtime is newer than its ctime (mtime set into the future), the target gets ctime = mtime. No file system interface sets the ctime directly; Ceph 21.2.0 ignores `CEPH_SETATTR_CTIME`. The MDS does, however, take the ctime from the time stamp the client sends with each request, and libcephfs reads that stamp from `clock_gettime(CLOCK_REALTIME)`. The native backend replaces `clock_gettime` in its own process (symbol interposition, only in the calling thread and only for the duration of one libcephfs call; the Go runtime reads the clock through the vDSO and is not affected): - Every modifying call runs with the time stamp 1970-01-01T00:00:01Z. - As the last change to an entry, the backend creates and removes the xattr `user.cephmig.ctime`, stamped with the source ctime. The MDS then sets ctime = max(stamp, mtime), also backwards. Setattr and cap flushes, in contrast, only move the ctime forward. - Directories are stamped after all changes to their children, hardlinks after linking and after removing surplus names. - The writing client sometimes caches a different ctime for directories. The verification before publication therefore reads the target through a freshly connected client. The writing client is closed first and the fresh client writes from then on. Closing returns all caps of the writer at once; otherwise the MDS recalls them entry by entry, which in the lab cost about five seconds per lookup for the files written last. The claim lock is held through a client of its own, so it survives the change. This behaviour was measured in the lab and is not guaranteed by Ceph; the verification reports every deviation. The atime at the target subsequently changes through normal reads of the application. - User xattrs and other portable xattrs, including empty values and removals. - Hardlinks within the subvolume, symlinks and FIFOs. - Sparse file contents; the native path skips zero ranges or punches holes. The physical space usage is not guaranteed. - Directory quotas `ceph.quota.max_bytes` and `ceph.quota.max_files`, also at the data root. - Custom subvolume and snapshot metadata through the manager API. - Original and new snapshot creation times in the journal. Symlinks are kept as link text, even if their target does not exist. The native path also preserves hardlinks to symlinks and FIFOs; for symlinks it links the inode through the public low-level interface, so that the link itself and not its referent is linked. Absolute links are not rewritten; at cutover, the application's mount path must match them. Hardlinks across the boundary of the transferred subvolume are not migrated as a shared link. Cluster-internal layout, pool and other `ceph.*` attributes are not copied blindly; quotas are transferred separately. Pool and layout mappings, subvolume group quotas, pinning, authorizations, snapshot schedules, active clone jobs and other Ceph management state are not implemented. The migration transfers the snapshots listed by the subvolume API with their entire directory tree. CephFS supports directory snapshots in general, but the MDS refuses separate snapshots below a managed subvolume. In the Ceph 21.2.0 lab, a snapshot of a plain directory succeeded, while the same attempt in a subvolume subdirectory failed with `EPERM`. Inherited snapshot views visible in subdirectories are part of the parent subvolume snapshot. The earlier warning about separate subdirectory snapshots was too broad for this managed subvolume model. See [MDS check of the subvolume boundary](https://github.com/ceph/ceph/blob/main/src/mds/Server.cc). Original inode numbers and native snapshot IDs are assigned anew. Encrypted, normalized, case-insensitive or earmarked subvolumes are rejected. ## Resumption and verification The job keeps a JSON journal with mode 0600 that is replaced atomically and secured with fsync. It contains the configuration, the cluster FSIDs, the concrete subvolume data paths and per-snapshot intent and completion records. Recreating the same subvolume name with a different data UUID is rejected. A local flock lock prevents concurrent access to the same journal. A persistent claim under `/.cephmig/claims/` with an exclusive file/CephFS lock protects the target even across different local journal paths. A missing or incomplete journal is never replaced by automatically adopting existing target data. Each snapshot state is copied, verified including quotas, and only then created as a snapshot at the target. A target snapshot that was created but not yet confirmed in the journal is verified again against the immutable source on resumption. Replacement or loss of already completed snapshots is detected from the stored identity; snapshots the journal marks as `removed` are exempt. The native data path uses a local bbolt index with source inode, inode version, size and target inode per path. It contains no file contents. The confirmed base is invalidated in the JSON journal before any change to the target and confirmed again only after successful verification and an fsync of the index. Clusters, data UUID paths and snapshot name must match. After an interruption, the open state is reconstructed fully and natively; a partially applied blockdiff must not count as a base. An already published but unconfirmed target snapshot is verified again. After SIGKILL, the release of old Ceph client sessions can delay the restart. The index also contains the complete path inventory of the immutable source snapshot: files, directories, hardlink aliases and special files. It is marked complete only after it has been fully recorded. Pruning and the check for surplus target paths compare target paths with this local inventory and thus avoid another `stat` call for every source path. Incomplete or damaged inventories abort the run. Identical inode rows are not written to the index again during verification. Immutable paths under `.snap` are read with `AT_STATX_DONT_SYNC` for `stat` and `readdirplus`, as in Ceph's own mirror. This avoids requesting metadata locks just to resynchronize snapshot inodes that cannot change anyway. Live target paths keep their normal synchronization semantics. Details and measurements are in [smallfiles-local.md](smallfiles-local.md). For a full copy, the native verification compares all file contents. For later states, it checks copied files or the ranges reported by blockdiff. Unchanged bytes come from the previously verified base. The target tree must therefore belong exclusively to the copier for the entire job. Foreign changes to unchanged file ranges are not reliably detected this way. Metadata, quotas and hardlink topology are checked in every state. A full content comparison after the cutover is proposed in [verify-concept.md](verify-concept.md). A target snapshot created right after the verification is checked for metadata and links; the same immutable data is not read again. In addition, the hardlink topology is verified in both directions: all source paths of the same inode must belong together at the target, and independent source files must not accidentally share an inode at the target. The copier creates full copies atomically as new inodes and then sets the hardlink aliases. Old target snapshots stay unchanged. Symlinked directories are not followed. The verification walks the tree in order and checks directories itself; all other entries are checked by up to `workers` goroutines. The verification mappings live in a temporary bbolt index next to the journal; write transactions are committed after 4,096 observations. The index is discarded after every verification or repair run and rebuilt when needed. It is not a resumption journal. The native base index under `.native/base.bolt`, in contrast, is kept. Sufficient local disk space is required for it. Path depths beyond 128 directories are currently rejected. After a hard process abort during an index run, temporary index directories can remain; they are never used as checkpoints. Journal and claim must be kept for resumption; `cleanup` deletes the claim only after the job is finished, and only if it holds the job's own ID. The lock is an advisory CephFS `flock`: it excludes other cephmig processes, but does not block any application. An incomplete claim after a crash during its very first creation is deliberately not repaired automatically; that requires checking the original job ID. ## Tests and scale ```sh make check go test -race ./... make dev-native-test ``` The integration tests create their own subvolumes and check historical states, catching up with changes, metadata, removed files, copy errors and a SIGKILL after a target snapshot was created but before the journal commit. They also check the stored note about new snapshot identities, the resolution of previously existing hardlinks with unchanged file contents, the removal of older round snapshots during `sync` and the removal of all migration snapshots by `cleanup`. On success they remove only their own fixtures; on failure the reported test paths are kept for diagnosis. The native test uses a copier without a FUSE device, CephFS mounts or rsync. A separate FUSE application client independently checks all file contents with SHA-256, as well as metadata, links and snapshots. It checks a 4 KiB change in a 64 MiB file with the same mtime, growth and zero ranges, link groups that are split and rejoined, and changes between directory and symlink. Hardlinks to unresolvable symlinks and FIFOs are also compared independently by inode, including a later split of a FIFO group. Further checks cover cancellation during the copy, SIGKILL right after snapshot creation, restart and idempotent completion. Meanwhile, an application keeps writing to another source subvolume. Latest lab result, 2026-12-03 with Ceph 21.2.0 and code state `6dcb7b6`: the Go tests including the race detector for the Ceph build, `make dev-smoke`, `make dev-native-test` and `make dev-smallfiles-test` passed (results in [smallfiles-local.md](smallfiles-local.md)). Lab result of 2026-11-05 with Ceph 21.2.0: native integration test and the regression test of the since removed rsync backend passed; Go tests including the race detector and `go vet` for the Ceph build passed. The native test completed five states with `ready-for-cutover` and additionally checked them through the application client. For the 4 KiB change in the 64 MiB file, 4 KiB were written for this file and 4,128 payload bytes for the whole second state including other changed files. In the unchanged final state, 0 payload bytes were written. This is a functional proof, not a throughput benchmark. The read-only identity comparison for existing lab snapshots is: ```sh python3 /lab/snapshot-identity.py \ --config /absolute/lab-config.json --snapshot existing-snapshot ``` Changed large files can need considerable additional target space for new snapshots. File workers, data buffers and directory iteration are bounded; copy and compare buffers are at most 4 MiB and shrink for small files and short verification ranges. Unchanged owner, mode and timestamps do not trigger another `setattr` call; a target stat read just before is reused for the metadata check. Path and hardlink mappings live on local disk. Snapdiff and blockdiff avoid repeated full transfers and full reads of unchanged file contents. Every round, `finalize` included, still scans all metadata, including the full topology and quota check, so the write stop scales with the total number of entries. Renamed files may be copied again in full. Single transactions of the native index are not yet optimized for 200 million paths. 200 TB and more than 200 million files are therefore not yet proven. What is missing for that release in particular: a final round that avoids full scans, reliable memory and runtime measurements, a capacity model for historical versions and an automated client cutover. A fixed maximum write-stop duration is not guaranteed. Native API calls block; cancellation is checked between calls and waits for I/O already in progress.