• James Simmons's avatar
    LU-12822 uapi: properly pack data structures · 4751e4a9
    James Simmons authored
    Linux UAPI headers use the gcc attributre __packed__ to ensure
    that the data structures are the exact same size on all platforms.
    This comes at the cost of potential misaligned accesses to these
    data structures which at best cost performance and at worst cause
    a bus error on some platforms. To detect potential misaligned
    access starting with gcc version 9 a new compile flags was
    introduced which is now impacting builds with Lustre.
    Examining the build failures shows most of the problems are due to
    packed data structures in the Lustre UAPI header containing
    unpacked data structure fields. Packing those missed structures
    resolved many of the build issues. The second problem is that the
    lustre utilities tend to cast some of its UAPI data structure.
    A good example is struct lov_user_md being cast to
    struct lov_user_md_v3. To ensure this is properly handled with
    packed data structures we need to use the __may_alias__ compiler
    attribute. The one exception is struct statx which is defined out
    side of Lustre and its unpacked. This requires extra special
    handling in user land code due to the described issues in this
    Fixing this problem exposed an incorrect wiretest for
    struct update_op
    Last problem address is the use of __swabXXp() on packed data
    structure fields. Because of the potential alignment issues we
    have to use __swabXX() functions instead.
    Change-Id: I149c55d3361e893bd890f9c5e9c77c15f81acc1b
    Signed-off-by: default avatarJames Simmons <jsimmons@infradead.org>
    Reviewed-on: https://review.whamcloud.com/36798
    Tested-by: default avatarjenkins <devops@whamcloud.com>
    Reviewed-by: default avatarAndreas Dilger <adilger@whamcloud.com>
    Reviewed-by: default avatarQuentin Bouget <quentin.bouget@cea.fr>
    Tested-by: default avatarMaloo <maloo@whamcloud.com>
    Reviewed-by: default avatarOleg Drokin <green@whamcloud.com>