Skip to content

libcephfs: introduce snapdiff v2 API to fix ABI breakage - #70912

Merged
vshankar merged 7 commits into
ceph:mainfrom
vshankar:wip-snapdiff2
Sep 4, 2026
Merged

vshankar merged 7 commits into
ceph:mainfrom
vshankar:wip-snapdiff2

Conversation

@vshankar

@vshankar vshankar commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

https://tracker.ceph.com/issues/79154

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@vshankar
vshankar requested review from a team, anoopcs9 and ifed01 August 7, 2026 11:35
@vshankar vshankar added the cephfs Ceph File System label Aug 7, 2026
Comment thread src/test/pybind/test_cephfs.py Outdated
snap1id = cephfs.snap_info(b"/snapdiff_test/.snap/snap1")['id']
snap2id = cephfs.snap_info(b"/snapdiff_test/.snap/snap2")['id']
diff = cephfs.opensnapdiff(b"/snapdiff_test", b"/", b"snap2", b"snap1",
diff = cephfs.opensnapdiff2(b"/snapdiff_test", b"/", b"snap2", b"snap1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have test case for opensnapdiff binding too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. Will add that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -- kept test_snapdiff() and added test_snapdiff2()

@anoopcs9 anoopcs9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think the existing tests on the v1 APIs should stay as they are.

Comment thread src/include/cephfs/libcephfs.h Resolved
Comment thread src/pybind/cephfs/mock_cephfs.pxi Resolved
Comment thread src/libcephfs.cc Resolved
@vshankar

vshankar commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

In general, I think the existing tests on the v1 APIs should stay as they are.

Sure. For the C++ test, I will then branch the snapdiff call based on diff_mask (diff_mask=0 calls v1 API, else v2).

h.opened = 1
return h

def opensnapdiff2(self, root_path, rel_path, snap1name, snap2name, diff_mask) -> SnapDiffHandle2:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the Python binding need literally the same treatment as the C API? It seems like diff_mask parameter could just be added to the existing opensnapdiff() and defaulted to 0. The implementation could be switched to ceph_open_snapdiff2() under the hood as SnapDiffHandle in Python never exposed anything about the underlying struct ceph_snapdiff_info.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a fair point. I initially split it into opensnapdiff2 to maintain a strict 1:1 mapping with the C API and to follow the precedent set by mds_command and mds_command2.

However, since Python handles default keyword arguments gracefully without breaking downstream consumers, unifying them into a single opensnapdiff(..., diff_mask=0) method definitely keeps the Python surface area cleaner.

I do not have a strong opinion on this and willing to switch to this if required.

Comment thread src/include/cephfs/libcephfs.h Outdated
* @param rel_path subpath under the root to build delta for
* @param snap1 the first snapshot name
* @param snap2 the second snapshot name
* @param diff_mask file metadata change mask to apply for delta building

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's noted in other places but not where it matters the most -- on the public API:

Suggested change
* @param diff_mask file metadata change mask to apply for delta building
* @param diff_mask file metadata change mask to apply for delta building (CEPH_SNAPDIFF_*)

@vshankar
vshankar force-pushed the wip-snapdiff2 branch 2 times, most recently from 142a420 to ede6d63 Compare August 11, 2026 07:22
@vshankar

Copy link
Copy Markdown
Contributor Author

Change with latest push

  • src/test/libcephfs/snapdiff.cc invokes the v1 or v2 API depending of diff_mask
  • src/test/pybind/test_cephfs.py keeps test_snapdiff() and adds test_snapdiff2()
  • Comments addressed
  • Fixed a CI failure due to missing ceph_snapdiff_info2 declaration in src/pybind/cephfs/mock_cephfs.pxi

Comment thread src/libcephfs.cc Resolved
Comment thread src/libcephfs.cc Resolved
Comment thread src/libcephfs.cc Resolved

@anoopcs9 anoopcs9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment, otherwise lgtm.

Comment thread src/pybind/cephfs/cephfs.pyx Resolved
The previous addition of the `diff_mask` parameter to the snapdiff API
altered the signature of `ceph_open_snapdiff` and affected the public
`ceph_snapdiff_info` struct, breaking both API and ABI for downstream
consumers (such as go-ceph).

This commit restores the original v1 API and ABI to preserve backward
compatibility. To support passing the `diff_mask` to the Client layer,
this introduces a v2 API:
- `ceph_open_snapdiff2`
- `ceph_readdir_snapdiff2`
- `ceph_close_snapdiff2`

To future-proof the API, the v2 handle (`struct ceph_snapdiff_info2`)
is declared as an opaque pointer in the public header. Internally, the
v2 struct embeds the v1 struct to eliminate code duplication across the
public endpoints.

Fixes: https://tracker.ceph.com/issues/79154
Reported-by: Anoop C S <[email protected]>
Introduced-by: 9c958c6
Signed-off-by: Venky Shankar <[email protected]>
Updates the Cython bindings (`c_cephfs.pxd`, `mock_cephfs.pxi`, and
`cephfs.pyx`) to support the new `ceph_open_snapdiff2` C API.

Introduces a new `opensnapdiff2` method and a corresponding
`SnapDiffHandle2` class to allow Python consumers to pass the `diff_mask`
parameter. The original `opensnapdiff` and `SnapDiffHandle` implementations
are left untouched to ensure backward compatibility for existing scripts.

Fixes: https://tracker.ceph.com/issues/79154
Reported-by: Anoop C S <[email protected]>
Introduced-by: 9c958c6
Signed-off-by: Venky Shankar <[email protected]>
The C++ `ceph_close_snapdiff2` (and its v1 version) function
unconditionally deletes the allocated `ceph_snapdiff_info2` struct.
Previously, if this function returned an error code, the Cython
wrapper raised a Python exception before setting `self.opened = 0`
and `self.handle = NULL`.

Because the internal state remained "open" with a dangling pointer,
Python's garbage collector would eventually trigger `__dealloc__`. This
caused `close()` to be executed a second time on the already-freed
pointer, resulting in a double-free segmentation fault.

This commit fixes the issue by unconditionally updating the object's
internal state to closed and nullifying the pointer before evaluating
the return code and raising any exceptions.

Caught by @anoopcs9 during review.

Signed-off-by: Venky Shankar <[email protected]>
Update the libcephfs snapdiff test suite to validate both the restored
v1 ABI and the newly introduced v2 API.

- Introduced the `for_each_readdir_snapdiff2` helper to test the v2
  API using the opaque `ceph_snapdiff_info_v2` struct and `diff_mask`.
- Retained the original `for_each_readdir_snapdiff` helper to ensure
  the restored v1 API remains continuously tested for strict backward
  compatibility.
- Updated `readdir_snapdiff_and_compare` to  dynamically route to the
  v1 helper when `diff_mask == 0`, and to the v2 helper when a mask is
  actively being tested.
- Python tests: Added coverage for the `opensnapdiff2` binding and
  `SnapDiffHandle2` iteration.

Signed-off-by: Venky Shankar <[email protected]>
Updates the CephFS mirroring daemon to drop the `diff_mask` parameter
and revert to using the standard `ceph_open_snapdiff` API.

The mirror daemon does not use the new mask functionality righit now, it
can safely rely on the restored v1 ABI. This resolves compilation and
integration mismatches caused by the previous API breakage.

cephfs-mirror will rely on v2 API in a separate change.

Signed-off-by: Venky Shankar <[email protected]>
Credit to @idryomov for noticing this.

Signed-off-by: Venky Shankar <[email protected]>
Bump the libcephfs minor version to reflect the addition of the new
snapdiff v2 APIs (ceph_open_snapdiff2, ceph_readdir_snapdiff2, and
ceph_close_snapdiff2).

Since these functions introduce new functionality to the public API
while strictly maintaining backward compatibility with the existing v1
ABI, a minor version increment is required. The extra/patch version
has been reset to 0.

Signed-off-by: Venky Shankar <[email protected]>

@anoopcs9 anoopcs9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks.

@vshankar

Copy link
Copy Markdown
Contributor Author

This PR has been added to main integration testing by vshankar started 2026-08-31-13:37.

@vshankar vshankar left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants