blob: 7caccddf128b51c4aea2f0bb304de1d6e7aa641f [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. Levinf56046e2015-08-26 17:48:40 +000032#include <linux/aio_abi.h>
Dmitry V. Levin2b640342013-11-11 15:06:18 +000033
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000034SYS_FUNC(io_setup)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000035{
36 if (entering(tcp))
Elvira Khabirovaafac9f02015-08-18 18:02:20 +030037 tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000038 else
Dmitry V. Levined292f62016-09-07 11:22:51 +000039 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +000040 return 0;
41}
42
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000043SYS_FUNC(io_destroy)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000044{
Dmitry V. Levined292f62016-09-07 11:22:51 +000045 printaddr(tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000046
47 return RVAL_DECODED;
Dmitry V. Levin2b640342013-11-11 15:06:18 +000048}
49
Dmitry V. Levin2b640342013-11-11 15:06:18 +000050enum iocb_sub {
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000051 SUB_NONE, SUB_COMMON, SUB_VECTOR
Dmitry V. Levin2b640342013-11-11 15:06:18 +000052};
53
54static enum iocb_sub
55tprint_lio_opcode(unsigned cmd)
56{
57 static const struct {
58 const char *name;
59 enum iocb_sub sub;
60 } cmds[] = {
61 { "pread", SUB_COMMON },
62 { "pwrite", SUB_COMMON },
63 { "fsync", SUB_NONE },
64 { "fdsync", SUB_NONE },
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000065 { "preadx", SUB_NONE },
66 { "poll", SUB_NONE },
Dmitry V. Levin2b640342013-11-11 15:06:18 +000067 { "noop", SUB_NONE },
68 { "preadv", SUB_VECTOR },
69 { "pwritev", SUB_VECTOR },
70 };
71
72 if (cmd < ARRAY_SIZE(cmds)) {
73 tprints(cmds[cmd].name);
74 return cmds[cmd].sub;
75 }
76 tprintf("%u /* SUB_??? */", cmd);
77 return SUB_NONE;
78}
79
80static void
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +030081print_common_flags(struct tcb *tcp, const struct iocb *cb)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000082{
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000083/* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
84#ifdef IOCB_FLAG_RESFD
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +030085 if (cb->aio_flags & IOCB_FLAG_RESFD) {
86 tprints(", resfd=");
87 printfd(tcp, cb->aio_resfd);
88 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000089 if (cb->aio_flags & ~IOCB_FLAG_RESFD)
90 tprintf(", flags=%x", cb->aio_flags);
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +000091#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +000092}
93
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000094static bool
95iocb_is_valid(const struct iocb *cb)
96{
97 return cb->aio_buf == (unsigned long) cb->aio_buf &&
98 cb->aio_nbytes == (size_t) cb->aio_nbytes &&
99 (ssize_t) cb->aio_nbytes >= 0;
100}
101
102static enum iocb_sub
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300103print_iocb_header(struct tcb *tcp, const struct iocb *cb)
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000104{
105 enum iocb_sub sub;
106
107 if (cb->aio_data)
108 tprintf("data=%#" PRIx64 ", ",
109 (uint64_t) cb->aio_data);
110
111 if (cb->aio_key)
112 tprintf("key=%u, ", cb->aio_key);
113
114 sub = tprint_lio_opcode(cb->aio_lio_opcode);
115 if (cb->aio_reqprio)
116 tprintf(", reqprio=%hd", cb->aio_reqprio);
117
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300118 tprints(", fildes=");
119 printfd(tcp, cb->aio_fildes);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000120
121 return sub;
122}
123
124static void
125print_iocb(struct tcb *tcp, const struct iocb *cb)
126{
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300127 enum iocb_sub sub = print_iocb_header(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000128
129 switch (sub) {
130 case SUB_COMMON:
131 if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
132 tprints(", str=");
133 printstr(tcp, (unsigned long) cb->aio_buf,
134 (unsigned long) cb->aio_nbytes);
135 } else {
136 tprintf(", buf=%#" PRIx64, (uint64_t) cb->aio_buf);
137 }
138 tprintf(", nbytes=%" PRIu64 ", offset=%" PRId64,
139 (uint64_t) cb->aio_nbytes, (int64_t) cb->aio_offset);
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300140 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000141 break;
142 case SUB_VECTOR:
143 if (iocb_is_valid(cb)) {
144 tprints(", iovec=");
145 tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
Fabien Siron2a54d8b2016-06-22 13:27:03 +0000146 cb->aio_lio_opcode == 8
147 ? IOV_DECODE_STR
148 : IOV_DECODE_ADDR);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000149 } else {
150 tprintf(", buf=%#" PRIx64 ", nbytes=%" PRIu64,
151 (uint64_t) cb->aio_buf,
152 (uint64_t) cb->aio_nbytes);
153 }
154 tprintf(", offset=%" PRId64, (int64_t) cb->aio_offset);
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300155 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000156 break;
157 case SUB_NONE:
158 break;
159 }
160}
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000161
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000162static bool
163print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
164{
165 unsigned long addr;
166 struct iocb cb;
167
168 if (elem_size < sizeof(long)) {
169 addr = * (unsigned int *) elem_buf;
170 } else {
171 addr = * (unsigned long *) elem_buf;
172 }
173
174 tprints("{");
175 if (!umove_or_printaddr(tcp, addr, &cb))
176 print_iocb(tcp, &cb);
177 tprints("}");
178
179 return true;
180}
181
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000182SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000183{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000184 const long nr = widen_to_long(tcp->u_arg[1]);
185 const unsigned long addr = tcp->u_arg[2];
186 unsigned long iocbp;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000187
Dmitry V. Levined292f62016-09-07 11:22:51 +0000188 printaddr(tcp->u_arg[0]);
189 tprintf(", %ld, ", nr);
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000190
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000191 if (nr < 0)
192 printaddr(addr);
193 else
194 print_array(tcp, addr, nr, &iocbp, current_wordsize,
195 umoven_or_printaddr, print_iocbp, 0);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000196
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000197 return RVAL_DECODED;
198}
199
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000200static bool
201print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000202{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000203 struct io_event *event = elem_buf;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000204
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000205 tprintf("{data=%#" PRIx64 ", obj=%#" PRIx64
206 ", res=%" PRId64 ", res2=%" PRId64 "}",
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000207 (uint64_t) event->data, (uint64_t) event->obj,
208 (int64_t) event->res, (int64_t) event->res2);
209
210 return true;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000211}
212
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000213SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000214{
215 if (entering(tcp)) {
Dmitry V. Levined292f62016-09-07 11:22:51 +0000216 printaddr(tcp->u_arg[0]);
217 tprints(", ");
218
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000219 struct iocb cb;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000220
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000221 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
222 tprints("{");
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300223 print_iocb_header(tcp, &cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000224 tprints("}");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000225 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000226 tprints(", ");
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000227 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000228 struct io_event event;
229
230 if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
231 print_io_event(tcp, &event, sizeof(event), 0);
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. Levined292f62016-09-07 11:22:51 +0000239 printaddr(tcp->u_arg[0]);
240 tprintf(", %ld, %ld, ",
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000241 widen_to_long(tcp->u_arg[1]),
242 widen_to_long(tcp->u_arg[2]));
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000243 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000244 struct io_event buf;
245 print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
246 umoven_or_printaddr, print_io_event, 0);
247 tprints(", ");
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000248 /*
249 * Since the timeout parameter is read by the kernel
250 * on entering syscall, it has to be decoded the same way
251 * whether the syscall has failed or not.
252 */
253 temporarily_clear_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000254 print_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000255 restore_cleared_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000256 }
257 return 0;
258}