From 864830d0441f5ff5b599ebe434c9dbe388a1fd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Fri, 4 Dec 2026 07:45:09 +0100 Subject: [PATCH] docs: explain why the copier binds libcephfs through CGO Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- docs/raw-transfer.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9953212..5d7b453 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ and [docs/million-local.md](docs/million-local.md). - [docs/migration.md](docs/migration.md): commands, limits and evidence - [docs/lab.md](docs/lab.md): the lab in detail, Ceph version, known warnings -- [docs/raw-transfer.md](docs/raw-transfer.md): direct RADOS import and limits of the native implementation +- [docs/raw-transfer.md](docs/raw-transfer.md): direct RADOS import, why libcephfs through CGO, limits of the native implementation - [docs/verify-concept.md](docs/verify-concept.md): concept for a full content verification after the cutover - API documentation of the Go packages: `go doc -all ./internal/migration` diff --git a/docs/raw-transfer.md b/docs/raw-transfer.md index 4431290..0acf688 100644 --- a/docs/raw-transfer.md +++ b/docs/raw-transfer.md @@ -120,6 +120,50 @@ to public Ceph interfaces in `internal/cephfsnative`. Activation: `make dev-native-test` builds these dependencies in a container and checks the transport between the independent lab clusters. +### Why a C binding and not a Go library + +No CephFS client is written in pure Go. Every Go route ends in the C library +libcephfs or in a kernel mount: + +- **go-ceph** (`github.com/ceph/go-ceph`) is itself a CGO wrapper around + libcephfs and librados. It would keep CGO, `-lcephfs` and the build + dependency, and add a layer between the copier and the library. +- **A CephFS client in Go** would have to implement msgr2, cephx, the MDS + protocol with its capability handling and direct object I/O against the + OSDs. That is a large, error-prone project; the cap handling alone decides + whether verification waits seconds per entry (see the client replacement + in [migration.md](migration.md)). +- **A kernel mount and the Go standard library** was the former rsync + backend. It cannot do what the copier needs (list below). + +What the copier uses from libcephfs and gets nowhere else: + +- `ceph_open_snapdiff`/`ceph_readdir_snapdiff`: changed directory entries + between two snapshots. +- `ceph_file_blockdiff_*`: changed data ranges of one file between two + snapshots. +- `ceph_setattrx` with the birth time; POSIX interfaces cannot set btime. +- `ceph_ll_walk`/`ceph_ll_link`: inode-level operations for hardlinks. +- The ctime: libcephfs stamps each request with `clock_gettime`, and the + backend replaces that function in its own process (see + [migration.md](migration.md)). This works only with the client library + inside the process. +- Separate client instances per purpose (writer, verifier, claim), so caps + are returned together when a client closes. On a kernel mount all callers + share one client. +- Both clusters in one process, without mounts and without root privileges. + +The binding in `internal/cephfsnative` is our own instead of go-ceph. It +wraps only the roughly 45 functions the copier calls, and it can call a new +interface such as snapdiff or blockdiff as soon as the installed libcephfs +provides it, without waiting for a wrapper release. In return, we maintain it +ourselves. + +Costs of CGO: the copier build needs a C compiler, the libcephfs headers and +the build tag `ceph`; the binary links dynamically against libcephfs; cross +compiling is harder. A build without libcephfs supports only `doctor` and +`status`. + Snapdiff marks changed inodes; in addition, comparing the Ceph inode version ensures that data changes with the same size and mtime are not missed. Blockdiff is used from 16 MiB on, provided a confirmed base with matching