blob: 29562d2d6b37ed034e3747b61d750af3f1e205b8 [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. Levin2479ef02015-08-18 14:58:27 +000039 printnum_ulong(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. Levin07eaf502015-07-20 18:40:46 +000045 tprintf("%lu", tcp->u_arg[0]);
46
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
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000081print_common_flags(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
85 if (cb->aio_flags & IOCB_FLAG_RESFD)
86 tprintf(", resfd=%d", cb->aio_resfd);
87 if (cb->aio_flags & ~IOCB_FLAG_RESFD)
88 tprintf(", flags=%x", cb->aio_flags);
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +000089#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +000090}
91
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000092static bool
93iocb_is_valid(const struct iocb *cb)
94{
95 return cb->aio_buf == (unsigned long) cb->aio_buf &&
96 cb->aio_nbytes == (size_t) cb->aio_nbytes &&
97 (ssize_t) cb->aio_nbytes >= 0;
98}
99
100static enum iocb_sub
101print_iocb_header(const struct iocb *cb)
102{
103 enum iocb_sub sub;
104
105 if (cb->aio_data)
106 tprintf("data=%#" PRIx64 ", ",
107 (uint64_t) cb->aio_data);
108
109 if (cb->aio_key)
110 tprintf("key=%u, ", cb->aio_key);
111
112 sub = tprint_lio_opcode(cb->aio_lio_opcode);
113 if (cb->aio_reqprio)
114 tprintf(", reqprio=%hd", cb->aio_reqprio);
115
116 tprintf(", fildes=%d", cb->aio_fildes);
117
118 return sub;
119}
120
121static void
122print_iocb(struct tcb *tcp, const struct iocb *cb)
123{
124 enum iocb_sub sub = print_iocb_header(cb);
125
126 switch (sub) {
127 case SUB_COMMON:
128 if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
129 tprints(", str=");
130 printstr(tcp, (unsigned long) cb->aio_buf,
131 (unsigned long) cb->aio_nbytes);
132 } else {
133 tprintf(", buf=%#" PRIx64, (uint64_t) cb->aio_buf);
134 }
135 tprintf(", nbytes=%" PRIu64 ", offset=%" PRId64,
136 (uint64_t) cb->aio_nbytes, (int64_t) cb->aio_offset);
137 print_common_flags(cb);
138 break;
139 case SUB_VECTOR:
140 if (iocb_is_valid(cb)) {
141 tprints(", iovec=");
142 tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
Fabien Siron2a54d8b2016-06-22 13:27:03 +0000143 cb->aio_lio_opcode == 8
144 ? IOV_DECODE_STR
145 : IOV_DECODE_ADDR);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000146 } else {
147 tprintf(", buf=%#" PRIx64 ", nbytes=%" PRIu64,
148 (uint64_t) cb->aio_buf,
149 (uint64_t) cb->aio_nbytes);
150 }
151 tprintf(", offset=%" PRId64, (int64_t) cb->aio_offset);
152 print_common_flags(cb);
153 break;
154 case SUB_NONE:
155 break;
156 }
157}
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000158
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000159static bool
160print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
161{
162 unsigned long addr;
163 struct iocb cb;
164
165 if (elem_size < sizeof(long)) {
166 addr = * (unsigned int *) elem_buf;
167 } else {
168 addr = * (unsigned long *) elem_buf;
169 }
170
171 tprints("{");
172 if (!umove_or_printaddr(tcp, addr, &cb))
173 print_iocb(tcp, &cb);
174 tprints("}");
175
176 return true;
177}
178
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000179SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000180{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000181 const long nr = widen_to_long(tcp->u_arg[1]);
182 const unsigned long addr = tcp->u_arg[2];
183 unsigned long iocbp;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000184
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000185 tprintf("%lu, %ld, ", tcp->u_arg[0], nr);
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000186
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000187 if (nr < 0)
188 printaddr(addr);
189 else
190 print_array(tcp, addr, nr, &iocbp, current_wordsize,
191 umoven_or_printaddr, print_iocbp, 0);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000192
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000193 return RVAL_DECODED;
194}
195
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000196static bool
197print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000198{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000199 struct io_event *event = elem_buf;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000200
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000201 tprintf("{data=%#" PRIx64 ", obj=%#" PRIx64
202 ", res=%" PRId64 ", res2=%" PRId64 "}",
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000203 (uint64_t) event->data, (uint64_t) event->obj,
204 (int64_t) event->res, (int64_t) event->res2);
205
206 return true;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000207}
208
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000209SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000210{
211 if (entering(tcp)) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000212 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000213 struct iocb cb;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000214
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000215 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
216 tprints("{");
217 print_iocb_header(&cb);
218 tprints("}");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000219 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000220 tprints(", ");
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000221 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000222 struct io_event event;
223
224 if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
225 print_io_event(tcp, &event, sizeof(event), 0);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000226 }
227 return 0;
228}
229
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000230SYS_FUNC(io_getevents)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000231{
232 if (entering(tcp)) {
Dmitry V. Levin56872832015-08-26 16:15:46 +0000233 tprintf("%lu, %ld, %ld, ",
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000234 tcp->u_arg[0],
235 widen_to_long(tcp->u_arg[1]),
236 widen_to_long(tcp->u_arg[2]));
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000237 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000238 struct io_event buf;
239 print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
240 umoven_or_printaddr, print_io_event, 0);
241 tprints(", ");
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000242 /*
243 * Since the timeout parameter is read by the kernel
244 * on entering syscall, it has to be decoded the same way
245 * whether the syscall has failed or not.
246 */
247 temporarily_clear_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000248 print_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000249 restore_cleared_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000250 }
251 return 0;
252}