blob: 5822a4fd94d5e7a5547e6fc1c96d311ed171bce8 [file] [log] [blame]
Dmitry V. Levin2b640342013-11-11 15:06:18 +00001/*
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. Levinb7dd5e62014-09-08 15:20:10 +000032#ifdef HAVE_LIBAIO_H
33# include <libaio.h>
Dmitry V. Levin2b640342013-11-11 15:06:18 +000034#endif
35
Dmitry V. Levin2b640342013-11-11 15:06:18 +000036/* Not defined in libaio.h */
37#ifndef IOCB_RESFD
38# define IOCB_RESFD (1 << 0)
39#endif
40
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000041SYS_FUNC(io_setup)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000042{
43 if (entering(tcp))
Elvira Khabirovaafac9f02015-08-18 18:02:20 +030044 tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000045 else
Dmitry V. Levin2479ef02015-08-18 14:58:27 +000046 printnum_ulong(tcp, tcp->u_arg[1]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +000047 return 0;
48}
49
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000050SYS_FUNC(io_destroy)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000051{
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000052 tprintf("%lu", tcp->u_arg[0]);
53
54 return RVAL_DECODED;
Dmitry V. Levin2b640342013-11-11 15:06:18 +000055}
56
57#ifdef HAVE_LIBAIO_H
58
59enum iocb_sub {
60 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
61};
62
63static enum iocb_sub
64tprint_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
89static void
90print_common_flags(struct iocb *iocb)
91{
Dmitry V. Levind93c4e82015-06-17 20:09:13 +000092#ifdef HAVE_STRUCT_IOCB_U_C_FLAGS
Dmitry V. Levin2b640342013-11-11 15:06:18 +000093 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. Levinb7dd5e62014-09-08 15:20:10 +000097#else
98# warning "libaio.h is too old => limited io_submit decoding"
99#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000100}
101
102#endif /* HAVE_LIBAIO_H */
103
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000104SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000105{
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000106#ifdef HAVE_LIBAIO_H
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000107 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. Levin13c21732015-08-26 12:49:07 +0000112 long iocbs = tcp->u_arg[2];
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000113
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000114 for (i = 0; i < nr; ++i, iocbs += current_wordsize) {
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000115 enum iocb_sub sub;
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000116 long iocbp;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000117 struct iocb iocb;
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000118
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000119 if (i)
120 tprints(", ");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000121
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000122 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. Levin07eaf502015-07-20 18:40:46 +0000127 break;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000128 }
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000129
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000130 tprints("{");
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000131 if (umove_or_printaddr(tcp, iocbp, &iocb)) {
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000132 tprints("}");
133 continue;
134 }
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000135
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000136 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. Levin2b640342013-11-11 15:06:18 +0000185 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000186 }
187 tprints("]");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000188#else
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000189# warning "libaio.h is not available => no io_submit decoding"
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000190 tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
191#endif
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000192 return RVAL_DECODED;
193}
194
195static int
196print_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. Levin2b640342013-11-11 15:06:18 +0000211 return 0;
212}
213
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000214SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000215{
216 if (entering(tcp)) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000217 tprintf("%lu, ", tcp->u_arg[0]);
218#ifdef HAVE_LIBAIO_H
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000219 struct iocb iocb;
220
221 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &iocb)) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000222 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. Levin2b640342013-11-11 15:06:18 +0000226 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000227#else
228 printaddr(tcp->u_arg[1]);
229#endif
230 } else {
231 print_io_event(tcp, tcp->u_arg[2]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000232 }
233 return 0;
234}
235
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000236SYS_FUNC(io_getevents)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000237{
238 if (entering(tcp)) {
Dmitry V. Levin56872832015-08-26 16:15:46 +0000239 tprintf("%lu, %ld, %ld, ",
240 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000241 } else {
242 if (tcp->u_rval == 0) {
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000243 tprints("[]");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000244 } 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. Levin2b640342013-11-11 15:06:18 +0000250 if (i == 0)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000251 tprints("[");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000252 else
253 tprints(", ");
254
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000255 if (print_io_event(tcp, (long)events))
256 break;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000257 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000258 tprints("], ");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000259#else
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000260 printaddr(tcp->u_arg[3]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000261#endif
262 }
263
264 print_timespec(tcp, tcp->u_arg[4]);
265 }
266 return 0;
267}