debian-forge/osbuild
Christian Kellner 0f670829a3 util/linux: fix BLK_IOC_FLSBUF on ppc64le
ioctl contants are platform dependent. It should be the same on
x86, aarch64 and s390x but it is indeed different on ppc64le.
This lead to the call to `ioctl_blockdev_flushbuf` actually
raising an exception of `OSError: [Errno 22] Invalid argument`.

The constant was calculated with a little python snippet that
in theory could also go directly into the code, but for now
the simpler condition in this patch is enough.

The snippet is a port of the defines from the Linux kernel,
specifically /usr/include/asm-generic/ioctl.h.

    class IOConstants:
        """IO Commands for Linux"""
        if platform.machine() == "ppc64le":
            NRBITS = 8
            TYPEBITS = 8
            SIZEBITS = 13

            DIR_NONE = 1
        else:
            NRBITS = 8
            TYPEBITS = 8
            SIZEBITS = 14

            DIR_NONE = 0

        NRSHIFT = 0
        TYPESHIFT = NRSHIFT+NRBITS
        SIZESHIFT = TYPESHIFT+TYPEBITS
        DIRSHIFT = SIZESHIFT+SIZEBITS

        @classmethod
        def make(cls, directory, iotype, nr, size):
            return ((directory << cls.DIRSHIFT) |
                    (iotype << cls.TYPESHIFT) |
                    (nr << cls.NRSHIFT) |
                    (size << cls.SIZESHIFT))

        @classmethod
        def make_dir_none(cls, iotype, nr):
            return cls.make(cls.DIR_NONE, iotype, nr, 0)

This is used to get the value for `BLKFLSBUF` taken from the
include `/usr/include/linux/fs.h`:

    #define BLKFLSBUF  _IO(0x12,97)	/* flush buffer cache */

The value is then obtained via:

    print("0x%x" % IOConstants.make_dir_none(0x12,97))
    0x20001261
2022-02-01 16:28:56 +01:00
..
formats osbuild: on-demand building of pipelines 2021-12-02 12:51:30 +00:00
util util/linux: fix BLK_IOC_FLSBUF on ppc64le 2022-02-01 16:28:56 +01:00
__init__.py pipeline: remove Assembler class 2021-01-19 10:42:26 +01:00
__main__.py osbuild: always return exit code 2020-10-27 22:04:09 +01:00
api.py api: remove host side arguments facility 2021-07-08 15:01:33 +01:00
buildroot.py buildroot: set container env variable 2021-12-09 13:14:27 +01:00
devices.py devices: add device path helper functions 2021-10-30 15:32:44 +01:00
host.py host: check reply_fds before sending them 2021-09-24 12:14:04 +01:00
inputs.py inputs: convert to host service 2021-06-09 18:37:47 +01:00
loop.py loop: add setup callback to loop_for_fd 2021-12-09 00:44:21 +00:00
main_cli.py osbuild: make monitor configurable via comandline 2021-12-09 00:44:21 +00:00
meta.py meta: allow mounts for all stages 2021-10-30 15:32:44 +01:00
monitor.py monitor/log: print pipeline information 2021-02-12 15:55:43 +01:00
mounts.py mounts: include tree directory in arguments 2021-10-30 15:32:44 +01:00
objectstore.py objectstore: don't store objects by their treesum 2021-12-16 16:44:07 +00:00
pipeline.py pipeline: fix small whitespace issue 2021-12-07 09:47:01 +00:00
remoteloop.py remoteloop: close loop device controller 2021-08-11 20:59:51 +02:00
sources.py sources: pass items via temporary file 2021-09-24 08:27:19 +01:00