debian-forge/osbuild/util
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
..
__init__.py util: mark as module 2020-04-21 17:00:04 +02:00
checksum.py util: add new checksum related utilities 2021-05-12 14:26:16 +02:00
ctx.py util/ctx: extract suppress_oserror() 2020-05-11 18:05:12 +02:00
jsoncomm.py util/jsoncomm: add send_and_recv helper 2021-06-09 18:37:47 +01:00
linux.py util/linux: fix BLK_IOC_FLSBUF on ppc64le 2022-02-01 16:28:56 +01:00
lorax.py utils/lorax: add lorax template related helpers 2021-02-19 14:42:32 +00:00
lvm2.py utils: add lvm2 utility module 2021-08-13 12:20:54 +02:00
osrelease.py util/osrelease: add default os-release paths 2020-10-21 11:13:28 +02:00
ostree.py stages: add org.osbuild.ostree.passwd 2021-08-17 13:53:00 +02:00
path.py util/path: add path checker helper function 2021-06-28 19:07:42 +02:00
rhsm.py util/rhsm: Check if repositories is None before iterating 2021-09-03 20:52:17 +02:00
rmrf.py util/rmrf: handle broken symlinks 2021-12-02 11:38:30 +01:00
selinux.py util/selinux: add gefilecon helper 2020-06-15 20:36:48 +02:00
types.py util: add types module defining PathLike type 2020-07-27 12:50:38 +01:00
udev.py devices: add custom udev rule inhibitor mechanism 2021-12-09 00:44:21 +00:00