]> granicus.if.org Git - strace/blob - sg_io_v4.c
sg_io: decode struct sg_io_hdr.flags and struct sg_io_v4.flags
[strace] / sg_io_v4.c
1 /*
2  * Copyright (c) 2015 Bart Van Assche <bart.vanassche@sandisk.com>
3  * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "defs.h"
30
31 #ifdef HAVE_LINUX_BSG_H
32
33 # include <linux/bsg.h>
34 # include "xlat/bsg_protocol.h"
35 # include "xlat/bsg_subprotocol.h"
36 # include "xlat/bsg_flags.h"
37
38 static void
39 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
40                    const unsigned int len)
41 {
42         printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
43 }
44
45 static int
46 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
47 {
48         struct sg_io_v4 sg_io;
49         static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
50
51         tprints("{guard='Q', ");
52         if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
53                                 &sg_io.protocol)) {
54                 tprints("}");
55                 return RVAL_DECODED | 1;
56         }
57
58         tprints("protocol=");
59         printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
60         tprints(", subprotocol=");
61         printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
62         tprintf(", request[%u]=", sg_io.request_len);
63         print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len);
64         tprintf(", request_tag=%" PRI__u64, sg_io.request_tag);
65         tprintf(", request_attr=%u", sg_io.request_attr);
66         tprintf(", request_priority=%u", sg_io.request_priority);
67         tprintf(", request_extra=%u", sg_io.request_extra);
68         tprintf(", max_response_len=%u", sg_io.max_response_len);
69
70         tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
71         tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
72         tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
73         tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
74         tprintf(", timeout=%u", sg_io.timeout);
75         tprints(", flags=");
76         printflags(bsg_flags, sg_io.flags, "BSG_FLAG_???");
77         tprintf(", usr_ptr=%" PRI__u64, sg_io.usr_ptr);
78         tprintf(", spare_in=%u", sg_io.spare_in);
79         tprintf(", dout[%u]=", sg_io.dout_xfer_len);
80         if (sg_io.dout_iovec_count)
81                 tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
82                                 IOV_DECODE_STR, sg_io.dout_xfer_len);
83         else
84                 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
85         return 1;
86 }
87
88 static int
89 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
90 {
91         struct sg_io_v4 sg_io;
92         uint32_t din_len;
93
94         if (umove(tcp, arg, &sg_io) < 0) {
95                 tprints(", ???");
96                 return RVAL_DECODED | 1;
97         }
98
99         if (sg_io.guard != (unsigned char) 'Q') {
100                 tprintf(" => guard=%u", sg_io.guard);
101                 return RVAL_DECODED | 1;
102         }
103
104         tprintf(", response[%u]=", sg_io.response_len);
105         print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len);
106         din_len = sg_io.din_xfer_len;
107         if (sg_io.din_resid > 0)
108                 din_len -= sg_io.din_resid;
109         tprintf(", din[%u]=", din_len);
110         if (sg_io.din_iovec_count)
111                 tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
112                                 syserror(tcp) ? IOV_DECODE_ADDR :
113                                 IOV_DECODE_STR, din_len);
114         else
115                 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
116         tprintf(", driver_status=%u", sg_io.driver_status);
117         tprintf(", transport_status=%u", sg_io.transport_status);
118         tprintf(", device_status=%u", sg_io.device_status);
119         tprintf(", retry_delay=%u", sg_io.retry_delay);
120         tprintf(", info=%u", sg_io.info);
121         tprintf(", duration=%u", sg_io.duration);
122         tprintf(", response_len=%u", sg_io.response_len);
123         tprintf(", din_resid=%u", sg_io.din_resid);
124         tprintf(", dout_resid=%u", sg_io.dout_resid);
125         tprintf(", generated_tag=%" PRI__u64, sg_io.generated_tag);
126         tprintf(", spare_out=%u", sg_io.spare_out);
127
128         return RVAL_DECODED | 1;
129 }
130
131 #else /* !HAVE_LINUX_BSG_H */
132
133 static int
134 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
135 {
136         tprints("{guard='Q', ...}");
137         return RVAL_DECODED | 1;
138 }
139
140 static int
141 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
142 {
143         return 0;
144 }
145
146 #endif
147
148 int
149 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
150 {
151         return entering(tcp) ? decode_request(tcp, arg)
152                              : decode_response(tcp, arg);
153 }