Skip to content

Commit

Permalink
io_uring: work aroung struct io_uring_rsrc_register field name change
Browse files Browse the repository at this point in the history
resv field has been renamed to flags in Linux commit v5.19-rc1~251^2~20,
provide a shim to support old decoding syntax.

* configure.ac (AC_CHECK_TYPES): Add struct io_uring_rsrc_register
and struct io_uring_rsrc_register.resv checks.
* src/io_uring.c [HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV] (RESV):
Define as resv.
[!HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV] (RESV): Define as flags.
(print_io_uring_register_rsrc): Use RESV instead of resv;  print "resv"
field name explicitly and use PRINT_VAL_X instead of PRINT_FIELD_X.
* tests/io_uring_register.c [HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV] (RESV):
Define as resv.
[!HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV] (RESV): Define as flags.
(main): Use RESV to access struct io_uring_rsrc_register.resv field.
  • Loading branch information
esyr authored and ldv-alt committed Jun 12, 2022
1 parent 505de19 commit aeb29a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ AC_CHECK_MEMBERS(m4_normalize([
struct iocb.aio_rw_flags
]),,, [#include <linux/aio_abi.h>])

AC_CHECK_TYPES([struct io_uring_rsrc_register], [
AC_CHECK_MEMBERS(m4_normalize([
struct io_uring_rsrc_register.resv
]),,, [#include <linux/io_uring.h>])
],, [#include <linux/io_uring.h>])

CPPFLAGS="$saved_CPPFLAGS"

st_CHECK_ENUMS
Expand Down
16 changes: 13 additions & 3 deletions src/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,20 @@ print_io_uring_rsrc_tags(struct tcb *tcp, const uint64_t tags,
tfetch_mem, print_xint_array_member, NULL);
}

/* Work around field name change in Linux commit v5.19-rc1~251^2~20. */
#ifdef HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV
# define RESV resv
#else
# define RESV flags
#endif

static void
print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
const unsigned int size, const unsigned int opcode)
{
struct io_uring_rsrc_register arg;
CHECK_TYPE_SIZE(arg, 32);
CHECK_TYPE_SIZE(arg.resv, sizeof(uint32_t));
CHECK_TYPE_SIZE(arg.RESV, sizeof(uint32_t));
CHECK_TYPE_SIZE(arg.resv2, sizeof(uint64_t));

if (size < 32) {
Expand All @@ -405,9 +412,10 @@ print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
tprint_struct_begin();
PRINT_FIELD_U(arg, nr);

if (arg.resv) {
if (arg.RESV) {
tprint_struct_next();
PRINT_FIELD_X(arg, resv);
tprints_field_name("resv");
PRINT_VAL_X(arg.RESV);
}

if (arg.resv2) {
Expand All @@ -427,6 +435,8 @@ print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
tprint_struct_end();
}

#undef RESV

static void
print_io_uring_update_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
const unsigned int size, const unsigned int opcode)
Expand Down
9 changes: 8 additions & 1 deletion tests/io_uring_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@

#define ARR_ITEM(arr_, idx_) ((arr_)[(idx_) % ARRAY_SIZE(arr_)])

/* Work around field name change in Linux commit v5.19-rc1~251^2~20. */
#ifdef HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV
# define RESV resv
#else
# define RESV flags
#endif

static const char path_null[] = "/dev/null";
static const char path_full[] = "/dev/full";

Expand Down Expand Up @@ -702,7 +709,7 @@ main(void)
rsrc_reg->nr += !!(j & 16);
rsrc_reg->nr &= ~-!(j & 32);

rsrc_reg->resv = j & 64 ? 0xbadc0ded : 0;
rsrc_reg->RESV = j & 64 ? 0xbadc0ded : 0;
rsrc_reg->resv2 = j & 128 ? 0xfacecafebeeffeedULL : 0;

memcpy(big_rsrc_reg, rsrc_reg, sizeof(*rsrc_reg));
Expand Down

0 comments on commit aeb29a3

Please sign in to comment.