From d822ffe1fa3e45716bedd3153b9d89b75409df45 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 22 May 2020 17:53:33 +0800 Subject: [PATCH] include/ceph_fs: do not use anonymous aggregate with member having ctor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit GCC-10 fails to compile ceph_fs.h, with following error: In file included from ../src/include/types.h:27, from ../src/msg/msg_types.h:23, from ../src/common/ipaddr.cc:16: ../src/include/ceph_fs.h:891:11: error: member ‘ceph_le32 ceph_mds_caps_body_legacy::::::truncate_seq’ with constructor not allowed in anonymous aggregate 891 | __le32 truncate_seq; | ^~~~~~~~~~~~ ../src/include/ceph_fs.h:892:25: error: member ‘ceph_timespec ceph_mds_caps_body_legacy::::::mtime’ with constructor not allowed in anonymous aggregate 892 | struct ceph_timespec mtime, atime, ctime; | ^~~~~ ../src/include/ceph_fs.h:892:32: error: member ‘ceph_timespec ceph_mds_caps_body_legacy::::::atime’ with constructor not allowed in anonymous aggregate 892 | struct ceph_timespec mtime, atime, ctime; | ^~~~~ ../src/include/ceph_fs.h:892:39: error: member ‘ceph_timespec ceph_mds_caps_body_legacy::::::ctime’ with constructor not allowed in anonymous aggregate 892 | struct ceph_timespec mtime, atime, ctime; | ^~~~~ because, for instance, `ceph_timespec` has compiler generated constructor, and it's not allowed by C++17 standard. Signed-off-by: Kefu Chai --- src/include/ceph_fs.h | 27 +++++++++++++-------------- src/include/types.h | 3 ++- src/messages/MClientCaps.h | 19 ++++++++++++++----- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index f7bf65c0662..b01b09adda5 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -882,20 +882,19 @@ struct ceph_mds_caps_head { __le64 xattr_version; } __attribute__ ((packed)); -struct ceph_mds_caps_body_legacy { - union { - /* all except export */ - struct { - /* filelock */ - __le64 size, max_size, truncate_size; - __le32 truncate_seq; - struct ceph_timespec mtime, atime, ctime; - struct ceph_file_layout layout; - __le32 time_warp_seq; - } __attribute__ ((packed)); - /* export message */ - struct ceph_mds_cap_peer peer; - } __attribute__ ((packed)); +struct ceph_mds_caps_non_export_body { + /* all except export */ + /* filelock */ + __le64 size, max_size, truncate_size; + __le32 truncate_seq; + struct ceph_timespec mtime, atime, ctime; + struct ceph_file_layout layout; + __le32 time_warp_seq; +} __attribute__ ((packed)); + +struct ceph_mds_caps_export_body { + /* export message */ + struct ceph_mds_cap_peer peer; } __attribute__ ((packed)); /* cap release msg head */ diff --git a/src/include/types.h b/src/include/types.h index c2d3c621600..9723564b5eb 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -324,7 +324,8 @@ WRITE_RAW_ENCODER(ceph_mds_request_head) WRITE_RAW_ENCODER(ceph_mds_request_release) WRITE_RAW_ENCODER(ceph_filelock) WRITE_RAW_ENCODER(ceph_mds_caps_head) -WRITE_RAW_ENCODER(ceph_mds_caps_body_legacy) +WRITE_RAW_ENCODER(ceph_mds_caps_export_body) +WRITE_RAW_ENCODER(ceph_mds_caps_non_export_body) WRITE_RAW_ENCODER(ceph_mds_cap_peer) WRITE_RAW_ENCODER(ceph_mds_cap_release) WRITE_RAW_ENCODER(ceph_mds_cap_item) diff --git a/src/messages/MClientCaps.h b/src/messages/MClientCaps.h index 8b441b185a4..9d77adb03ff 100644 --- a/src/messages/MClientCaps.h +++ b/src/messages/MClientCaps.h @@ -205,11 +205,15 @@ public: using ceph::decode; auto p = payload.cbegin(); decode(head, p); - ceph_mds_caps_body_legacy body; - decode(body, p); if (head.op == CEPH_CAP_OP_EXPORT) { + ceph_mds_caps_export_body body; + decode(body, p); peer = body.peer; + p += (sizeof(ceph_mds_caps_non_export_body) - + sizeof(ceph_mds_caps_export_body)); } else { + ceph_mds_caps_non_export_body body; + decode(body, p); size = body.size; max_size = body.max_size; truncate_size = body.truncate_size; @@ -274,11 +278,16 @@ public: head.xattr_len = xattrbl.length(); encode(head, payload); - ceph_mds_caps_body_legacy body; + static_assert(sizeof(ceph_mds_caps_non_export_body) > + sizeof(ceph_mds_caps_export_body)); if (head.op == CEPH_CAP_OP_EXPORT) { - memset(&body, 0, sizeof(body)); + ceph_mds_caps_export_body body; body.peer = peer; + encode(body, payload); + payload.append_zero(sizeof(ceph_mds_caps_non_export_body) - + sizeof(ceph_mds_caps_export_body)); } else { + ceph_mds_caps_non_export_body body; body.size = size; body.max_size = max_size; body.truncate_size = truncate_size; @@ -288,8 +297,8 @@ public: ctime.encode_timeval(&body.ctime); layout.to_legacy(&body.layout); body.time_warp_seq = time_warp_seq; + encode(body, payload); } - encode(body, payload); ceph::encode_nohead(snapbl, payload); middle = xattrbl; -- 2.47.3