]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
include/ceph_fs: do not use anonymous aggregate with member having ctor
authorKefu Chai <kchai@redhat.com>
Fri, 22 May 2020 09:53:33 +0000 (17:53 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 22 May 2020 13:19:36 +0000 (21:19 +0800)
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::<unnamed union>::<unnamed struct>::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::<unnamed union>::<unnamed struct>::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::<unnamed union>::<unnamed struct>::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::<unnamed union>::<unnamed struct>::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 <kchai@redhat.com>
src/include/ceph_fs.h
src/include/types.h
src/messages/MClientCaps.h

index f7bf65c066248f3d39ca4af7775e999aac72f7e7..b01b09adda56a98a9802e32f5a876803f4fa4221 100644 (file)
@@ -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 */
index c2d3c6216009cf422abec77f687ae4ad78047aef..9723564b5eb9ee4c9f091f373986da8d4ac764f9 100644 (file)
@@ -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)
index 8b441b185a4f063b000b3efaa95299616dbd87af..9d77adb03ff69207c836e7fff9f937dfb0822344 100644 (file)
@@ -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;