]> granicus.if.org Git - strace/blob - sg_io_v4.c
Split scsi.c
[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
37 static void
38 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
39                    const unsigned int len)
40 {
41         printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
42 }
43
44 static int
45 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
46 {
47         struct sg_io_v4 sg_io;
48         static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
49
50         tprints("{guard='Q', ");
51         if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
52                                 &sg_io.protocol)) {
53                 tprints("}");
54                 return RVAL_DECODED | 1;
55         }
56
57         tprints("protocol=");
58         printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
59         tprints(", subprotocol=");
60         printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
61         tprintf(", request[%u]=", sg_io.request_len);
62         print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len);
63         tprintf(", request_tag=%" PRI__u64, sg_io.request_tag);
64         tprintf(", request_attr=%u", sg_io.request_attr);
65         tprintf(", request_priority=%u", sg_io.request_priority);
66         tprintf(", request_extra=%u", sg_io.request_extra);
67         tprintf(", max_response_len=%u", sg_io.max_response_len);
68
69         tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
70         tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
71         tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
72         tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
73         tprintf(", timeout=%u", sg_io.timeout);
74         tprintf(", flags=%u", sg_io.flags);
75         tprintf(", usr_ptr=%" PRI__u64, sg_io.usr_ptr);
76         tprintf(", spare_in=%u", sg_io.spare_in);
77         tprintf(", dout[%u]=", sg_io.dout_xfer_len);
78         if (sg_io.dout_iovec_count)
79                 tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
80                                 IOV_DECODE_STR, sg_io.dout_xfer_len);
81         else
82                 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
83         return 1;
84 }
85
86 static int
87 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
88 {
89         struct sg_io_v4 sg_io;
90         uint32_t din_len;
91
92         if (umove(tcp, arg, &sg_io) < 0) {
93                 tprints(", ???");
94                 return RVAL_DECODED | 1;
95         }
96
97         if (sg_io.guard != (unsigned char) 'Q') {
98                 tprintf(" => guard=%u", sg_io.guard);
99                 return RVAL_DECODED | 1;
100         }
101
102         tprintf(", response[%u]=", sg_io.response_len);
103         print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len);
104         din_len = sg_io.din_xfer_len;
105         if (sg_io.din_resid > 0)
106                 din_len -= sg_io.din_resid;
107         tprintf(", din[%u]=", din_len);
108         if (sg_io.din_iovec_count)
109                 tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
110                                 syserror(tcp) ? IOV_DECODE_ADDR :
111                                 IOV_DECODE_STR, din_len);
112         else
113                 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
114         tprintf(", driver_status=%u", sg_io.driver_status);
115         tprintf(", transport_status=%u", sg_io.transport_status);
116         tprintf(", device_status=%u", sg_io.device_status);
117         tprintf(", retry_delay=%u", sg_io.retry_delay);
118         tprintf(", info=%u", sg_io.info);
119         tprintf(", duration=%u", sg_io.duration);
120         tprintf(", response_len=%u", sg_io.response_len);
121         tprintf(", din_resid=%u", sg_io.din_resid);
122         tprintf(", dout_resid=%u", sg_io.dout_resid);
123         tprintf(", generated_tag=%" PRI__u64, sg_io.generated_tag);
124         tprintf(", spare_out=%u", sg_io.spare_out);
125
126         return RVAL_DECODED | 1;
127 }
128
129 #else /* !HAVE_LINUX_BSG_H */
130
131 static int
132 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
133 {
134         tprints("{guard='Q', ...}");
135         return RVAL_DECODED | 1;
136 }
137
138 static int
139 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
140 {
141         return 0;
142 }
143
144 #endif
145
146 int
147 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
148 {
149         return entering(tcp) ? decode_request(tcp, arg)
150                              : decode_response(tcp, arg);
151 }