Repository navigation
src: stop using le32toh() and the like for better portability - #72482
Conversation
le16toh() and its siblings come from <endian.h>, which macOS does not have, and MinGW does not provide them either. boost::endian works on all of these platforms. native_to_little() and little_to_native() take their width from the argument, but some callers pass a size_t, e.g. HTOCEPH_16(this->obj_name.length()). So the macros become inline functions with fixed width parameters, and the argument is still narrowed before it is converted, as it was with htole16(). Signed-off-by: Kefu Chai <[email protected]>
| /* Pure C implementations of CRC, one byte at a time */ | ||
| unsigned int crc32c_le(uint32_t crc, unsigned char const *buf, unsigned len){ | ||
| crc = htole32(crc); | ||
| crc = __builtin_bswap32(crc); |
There was a problem hiding this comment.
I'd suggest adding a comment based on the commit message (i.e. - "this only builds on ,,, " etc)
dada106 to
c576c6c
Compare
|
This PR has been added to main integration testing by anuchaithra started 2026-10-08-10:48. |
b26a508 moved librbd/migration/QCOWFormat.cc to boost::endian, but the test still builds its QCOW2 headers with htobe32() and htobe64(). QCOWFormat.cc is why the __MINGW32__ block in include/compat.h defines these macros, and this test is now their only user in a Windows build. native_to_big() takes its width from the argument, and some of these calls pass an int or a size_t, e.g. htobe64(1<<30) or htobe16(id.size()). Those calls name the width of the macro they replace. Signed-off-by: Kefu Chai <[email protected]>
Replace htole64() with boost::endian::native_to_little(), and drop the <endian.h> include. The length goes into a 64-bit field of the journald native protocol, but size_t is only 32 bits wide on 32-bit hosts, so pass uint64_t explicitly. LogEntryEncoder also converted le.msg.size() twice; store the msg_len it already has instead. Signed-off-by: Kefu Chai <[email protected]>
The allocator file that BlueStore writes on umount keeps its extents and CRCs in little endian, using le32toh() and the like. Use boost::endian::native_to_little() and little_to_native() instead. Each argument is already a uint32_t or uint64_t matching the width of the old macro, so the on-disk format does not change. Also remove the "#if 1 ... #else" block that defined the macros. Its #else branch, which wrote big endian to debug the encoder, was never compiled. Signed-off-by: Kefu Chai <[email protected]>
crc32c_le() converts the CRC with htole32() and le32toh(). This file is C, so it cannot use boost::endian like the other callers. It is only built when HAVE_S390X is set, and s390x is always big endian, so both calls swap the bytes. Call __builtin_bswap32() directly instead. GCC and Clang both provide it, and <endian.h> is no longer needed. Signed-off-by: Kefu Chai <[email protected]>
057660a defined htobe16() and the rest for MinGW, because librbd/migration/QCOWFormat.cc used them and the rbd tool no longer built on Windows. b26a508 moved QCOWFormat.cc to boost::endian, and the earlier commits in this series moved everything else, so nothing uses these macros now. Signed-off-by: Kefu Chai <[email protected]>
c576c6c to
ae3fba1
Compare
|
changelog:
|
idryomov
left a comment
There was a problem hiding this comment.
Ack from the RBD perspective
|
This PR has been added to wip-bharath7-testing-20261012.100201-main. |
pr testing completed and approved by @ivancich, more details in https://tracker.ceph.com/issues/81545. |
|
This PR has been removed from wip-bharath7-testing-20261012.100201-main. |
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 test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.