dencoding: check struct_v against DECODE_START(v, ...) at compile-time#60159
dencoding: check struct_v against DECODE_START(v, ...) at compile-time#60159rzarzynski merged 3 commits intoceph:mainfrom
Conversation
|
Do we have a framework for ensuring compilation failures? This isn't something GTest is able to do. CC: @gregsfortytwo. |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@rzarzynski please see my comment
| } | ||
| decode(attrs_to_read, bl); | ||
| if (struct_v > 2 && struct_v > struct_compat) { | ||
| if (struct_v > 2 && struct_v.v > struct_compat) { |
There was a problem hiding this comment.
please explain why you're adding the compare against struct_compat and v ? there are few other compares against compact that are still compared to struct_v and not struct_v.v
There was a problem hiding this comment.
The problem is comparing struct_compat against the struct_v which is not a regular integer but an instance of the CheckingWrapper. This wrapper is able to compare only against consteval expression but struct_compat is not like that. This leads to the following FTBFS:
ECMsgTypes.cc:223:34: error: the value of ‘struct_compat’ is not usable in a constant expression
@rzarzynski copying a suggestion from the cpplang slack:
|
|
Thanks, @cbodley! |
|
This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days. |
|
This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days. |
|
Unstale, please. |
|
jenkins test make check |
a734e99 to
e92eeec
Compare
6b80485 to
8a3ed71
Compare
|
@NitzanMordhai, @cbodley: implemented the unit testing. Would you mind re-review? |
|
Too bad this doesn't catch cases where Also, I'd fold "osd/osd_types: fix wrong DECODE_START version for pg_notify_t" commit into the commit which has all the other fixups. The fact that this one is recent (November 2024) and was caught after a rebase doesn't make it special. |
gregsfortytwo
left a comment
There was a problem hiding this comment.
CephFS changes look good and I like the compile-time checking. More explanation of how that works would be nice (this whole part of the code is really under-documented, I know) — I got confused a few times.
|
@rzarzynski do we need to backport the DECODE_START version changes? If we bump the compat_v in a future version to a version between correct struct_v and the bad DECODE_START(v) value, we could unexpectedly break things...but I don't think we've ever set compat_v to a value other than a newly-bumped struct_v, or that we have structures where it would make sense to do so. |
I think such a thing already exists -- it's our denc framework, where a developer typically writes just a single |
Hmm, perhaps knocking out the conversion operator could help in this aspect but at the price of increasing the code churn. |
Do you mean the fixes? My perception was that having them only since a major release makes thinking easier. Also, we tend to avoid schema changes between minors. |
1552c09 to
755ae72
Compare
|
Just squashed the recent fix for |
Just the random decoders that had the wrong value which you identified and fixed here. |
1 similar comment
Just the random decoders that had the wrong value which you identified and fixed here. |
chardan
left a comment
There was a problem hiding this comment.
I don't know this code well, so I don't have a lot to add-- mostly looks fine to me. Please see note about using identifiers that start with underscores. I have to wonder, also, if the whole enchilada could be done with templates, for the most part, but that is well out of the change scope.
|
Hey all, apologies for the delay in testing- the QA tracker was mislabeled. Reviews are ongoing now here: https://tracker.ceph.com/issues/70205 |
|
@yuriw: the checker has found a legit bug: introduced 2 weeks ago (#60746). |
`throw` in C++20's `consteval` function results in an ill-formed program. Useful as parameters of such functions aren't const- expressions, and thus are unsuitable for `static_assert`. Signed-off-by: Radoslaw Zarzynski <[email protected]>
755ae72 to
f0526be
Compare
Typical problem found in recent reviews of dencoding changes is missed increment of the version number passed to `DECODE_START()` macro in a decoder. It's easy to overlook and hard to find as the number is used for rarely happening explicit breaks of schema compatibility. This commit brings compile-time checks for `struct_v` in decoders (and for `denc` also in encoders) to find a situation when it's compared against version higher than declared using the `DECODE_START(v, ...)` macro. Additionally, the patch fixes the currently existing issues of this genre buried across the enitre code base. Signed-off-by: Radoslaw Zarzynski <[email protected]>
Signed-off-by: Radoslaw Zarzynski <[email protected]>
f0526be to
f983d75
Compare
|
In RGW as well: We really need the compile-time checking. @yuriw: this PR is particularly susceptible to catching undetected merge conflicts with other PRs. Let's get it in sooner than later. |
This commit fixes an undetected merge conflict between PRs ceph#61745 and ceph#60159. The dencoding problem has been introduced very recently, it is straightforward and causes failures of the make check bot everywhere, therefore -- if no objections -- I want to merge this patch without the Teuthology testing. Signed-off-by: Radoslaw Zarzynski <[email protected]>
Typical problem found in recent reviews of dencoding changes is missed increment of the version number passed to
DECODE_START()macro in a decoder.It's easy to overlook and hard to find as the number is used for rarely happening explicit breaks of schema compatibility.
This commit brings compile-time checks for
struct_vin decoders (and fordencalso in encoders) to find a situation when it's compared against version higher than declared using theDECODE_START(v, ...)macro.Additionally, the patch fixes the currently existing issues of this genre buried across the entire code base.
Signed-off-by: Radoslaw Zarzynski [email protected]
The goldbot snippet is available here.
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e