Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. The name of the author may not be used to endorse or promote products |
| 17 | * derived from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Dmitry V. Levin | b7dd5e6 | 2014-09-08 15:20:10 +0000 | [diff] [blame] | 32 | #ifdef HAVE_LIBAIO_H |
| 33 | # include <libaio.h> |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 36 | /* Not defined in libaio.h */ |
| 37 | #ifndef IOCB_RESFD |
| 38 | # define IOCB_RESFD (1 << 0) |
| 39 | #endif |
| 40 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 41 | SYS_FUNC(io_setup) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 42 | { |
| 43 | if (entering(tcp)) |
Elvira Khabirova | afac9f0 | 2015-08-18 18:02:20 +0300 | [diff] [blame] | 44 | tprintf("%u, ", (unsigned int) tcp->u_arg[0]); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 45 | else |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 46 | printnum_ulong(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 50 | SYS_FUNC(io_destroy) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 51 | { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 52 | tprintf("%lu", tcp->u_arg[0]); |
| 53 | |
| 54 | return RVAL_DECODED; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | #ifdef HAVE_LIBAIO_H |
| 58 | |
| 59 | enum iocb_sub { |
| 60 | SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR |
| 61 | }; |
| 62 | |
| 63 | static enum iocb_sub |
| 64 | tprint_lio_opcode(unsigned cmd) |
| 65 | { |
| 66 | static const struct { |
| 67 | const char *name; |
| 68 | enum iocb_sub sub; |
| 69 | } cmds[] = { |
| 70 | { "pread", SUB_COMMON }, |
| 71 | { "pwrite", SUB_COMMON }, |
| 72 | { "fsync", SUB_NONE }, |
| 73 | { "fdsync", SUB_NONE }, |
| 74 | { "op4", SUB_NONE }, |
| 75 | { "poll", SUB_POLL }, |
| 76 | { "noop", SUB_NONE }, |
| 77 | { "preadv", SUB_VECTOR }, |
| 78 | { "pwritev", SUB_VECTOR }, |
| 79 | }; |
| 80 | |
| 81 | if (cmd < ARRAY_SIZE(cmds)) { |
| 82 | tprints(cmds[cmd].name); |
| 83 | return cmds[cmd].sub; |
| 84 | } |
| 85 | tprintf("%u /* SUB_??? */", cmd); |
| 86 | return SUB_NONE; |
| 87 | } |
| 88 | |
| 89 | static void |
| 90 | print_common_flags(struct iocb *iocb) |
| 91 | { |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 92 | #ifdef HAVE_STRUCT_IOCB_U_C_FLAGS |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 93 | if (iocb->u.c.flags & IOCB_RESFD) |
| 94 | tprintf(", resfd=%d", iocb->u.c.resfd); |
| 95 | if (iocb->u.c.flags & ~IOCB_RESFD) |
| 96 | tprintf(", flags=%x", iocb->u.c.flags); |
Dmitry V. Levin | b7dd5e6 | 2014-09-08 15:20:10 +0000 | [diff] [blame] | 97 | #else |
| 98 | # warning "libaio.h is too old => limited io_submit decoding" |
| 99 | #endif |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #endif /* HAVE_LIBAIO_H */ |
| 103 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 104 | SYS_FUNC(io_submit) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 105 | { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 106 | #ifdef HAVE_LIBAIO_H |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 107 | long nr = tcp->u_arg[1]; |
| 108 | /* if nr <= 0, we end up printing just "[]" */ |
| 109 | tprintf("%lu, %ld, [", tcp->u_arg[0], tcp->u_arg[1]); |
| 110 | { |
| 111 | long i; |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 112 | long iocbs = tcp->u_arg[2]; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 113 | |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 114 | for (i = 0; i < nr; ++i, iocbs += current_wordsize) { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 115 | enum iocb_sub sub; |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 116 | long iocbp; |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 117 | struct iocb iocb; |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 118 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 119 | if (i) |
| 120 | tprints(", "); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 121 | |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 122 | if (umove_long_or_printaddr(tcp, iocbs, &iocbp)) { |
| 123 | /* |
| 124 | * No point in trying to read the whole array |
| 125 | * because nr can be ridiculously large. |
| 126 | */ |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 127 | break; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 128 | } |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 129 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 130 | tprints("{"); |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 131 | if (umove_or_printaddr(tcp, iocbp, &iocb)) { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 132 | tprints("}"); |
| 133 | continue; |
| 134 | } |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame^] | 135 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 136 | if (iocb.data) { |
| 137 | tprints("data="); |
| 138 | printaddr((long) iocb.data); |
| 139 | tprints(", "); |
| 140 | } |
| 141 | if (iocb.key) |
| 142 | tprintf("key=%u, ", iocb.key); |
| 143 | sub = tprint_lio_opcode(iocb.aio_lio_opcode); |
| 144 | if (iocb.aio_reqprio) |
| 145 | tprintf(", reqprio=%d", iocb.aio_reqprio); |
| 146 | tprintf(", filedes=%d", iocb.aio_fildes); |
| 147 | switch (sub) { |
| 148 | case SUB_COMMON: |
| 149 | #if HAVE_DECL_IO_CMD_PWRITE |
| 150 | if (iocb.aio_lio_opcode == IO_CMD_PWRITE) { |
| 151 | tprints(", str="); |
| 152 | printstr(tcp, (unsigned long)iocb.u.c.buf, |
| 153 | iocb.u.c.nbytes); |
| 154 | } else |
| 155 | #endif |
| 156 | { |
| 157 | tprints(", buf="); |
| 158 | printaddr((long) iocb.u.c.buf); |
| 159 | } |
| 160 | tprintf(", nbytes=%lu, offset=%lld", |
| 161 | iocb.u.c.nbytes, |
| 162 | iocb.u.c.offset); |
| 163 | print_common_flags(&iocb); |
| 164 | break; |
| 165 | case SUB_VECTOR: |
| 166 | tprintf(", %lld", iocb.u.v.offset); |
| 167 | print_common_flags(&iocb); |
| 168 | tprints(", "); |
| 169 | tprint_iov(tcp, iocb.u.v.nr, |
| 170 | (unsigned long)iocb.u.v.vec, |
| 171 | #if HAVE_DECL_IO_CMD_PWRITEV |
| 172 | iocb.aio_lio_opcode == IO_CMD_PWRITEV |
| 173 | #else |
| 174 | 0 |
| 175 | #endif |
| 176 | ); |
| 177 | break; |
| 178 | case SUB_POLL: |
| 179 | tprintf(", %x", iocb.u.poll.events); |
| 180 | break; |
| 181 | case SUB_NONE: |
| 182 | break; |
| 183 | } |
| 184 | tprints("}"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 185 | } |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 186 | } |
| 187 | tprints("]"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 188 | #else |
Dmitry V. Levin | b7dd5e6 | 2014-09-08 15:20:10 +0000 | [diff] [blame] | 189 | # warning "libaio.h is not available => no io_submit decoding" |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 190 | tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
| 191 | #endif |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 192 | return RVAL_DECODED; |
| 193 | } |
| 194 | |
| 195 | static int |
| 196 | print_io_event(struct tcb *tcp, const long addr) |
| 197 | { |
| 198 | #ifdef HAVE_LIBAIO_H |
| 199 | struct io_event event; |
| 200 | |
| 201 | if (umove_or_printaddr(tcp, addr, &event)) |
| 202 | return -1; |
| 203 | tprints("{data="); |
| 204 | printaddr((long) event.data); |
| 205 | tprints(", obj="); |
| 206 | printaddr((long) event.obj); |
| 207 | tprintf(", res=%ld, res2=%ld}", event.res, event.res2); |
| 208 | #else |
| 209 | printaddr(tcp->u_arg[2]); |
| 210 | #endif |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 214 | SYS_FUNC(io_cancel) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 215 | { |
| 216 | if (entering(tcp)) { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 217 | tprintf("%lu, ", tcp->u_arg[0]); |
| 218 | #ifdef HAVE_LIBAIO_H |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 219 | struct iocb iocb; |
| 220 | |
| 221 | if (!umove_or_printaddr(tcp, tcp->u_arg[1], &iocb)) { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 222 | tprintf("{%p, %u, %u, %u, %d}, ", |
| 223 | iocb.data, iocb.key, |
| 224 | (unsigned)iocb.aio_lio_opcode, |
| 225 | (unsigned)iocb.aio_reqprio, iocb.aio_fildes); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 226 | } |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 227 | #else |
| 228 | printaddr(tcp->u_arg[1]); |
| 229 | #endif |
| 230 | } else { |
| 231 | print_io_event(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 236 | SYS_FUNC(io_getevents) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 237 | { |
| 238 | if (entering(tcp)) { |
Dmitry V. Levin | 5687283 | 2015-08-26 16:15:46 +0000 | [diff] [blame] | 239 | tprintf("%lu, %ld, %ld, ", |
| 240 | tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 241 | } else { |
| 242 | if (tcp->u_rval == 0) { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 243 | tprints("[]"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 244 | } else { |
| 245 | #ifdef HAVE_LIBAIO_H |
| 246 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 247 | long i, nr = tcp->u_rval; |
| 248 | |
| 249 | for (i = 0; i < nr; i++, events++) { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 250 | if (i == 0) |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 251 | tprints("["); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 252 | else |
| 253 | tprints(", "); |
| 254 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 255 | if (print_io_event(tcp, (long)events)) |
| 256 | break; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 257 | } |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 258 | tprints("], "); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 259 | #else |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 260 | printaddr(tcp->u_arg[3]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 261 | #endif |
| 262 | } |
| 263 | |
| 264 | print_timespec(tcp, tcp->u_arg[4]); |
| 265 | } |
| 266 | return 0; |
| 267 | } |