LCOV - code coverage report
Current view: top level - strace_git - sg_io_v4.c (source / functions) Hit Total Coverage
Test: strace-4.16.0.69.f1ea-dirty Code Coverage Lines: 63 70 90.0 %
Date: 2017-03-18 00:38:52 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 16 75.0 %

           Branch data     Line data    Source code
       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                 :         40 : print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
      40                 :            :                    const unsigned int data_size, const unsigned int iovec_count)
      41                 :            : {
      42         [ +  + ]:         40 :         if (iovec_count) {
      43                 :         15 :                 tprint_iov_upto(tcp, iovec_count, addr, IOV_DECODE_STR,
      44                 :            :                                 data_size);
      45                 :            :         } else {
      46                 :         25 :                 printstr_ex(tcp, addr, data_size, QUOTE_FORCE_HEX);
      47                 :            :         }
      48                 :         40 : }
      49                 :            : 
      50                 :            : static int
      51                 :         15 : decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
      52                 :            : {
      53                 :            :         struct sg_io_v4 sg_io;
      54                 :            :         static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
      55                 :            : 
      56                 :         15 :         tprints("{guard='Q', ");
      57         [ +  + ]:         15 :         if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
      58                 :            :                                 &sg_io.protocol)) {
      59                 :          5 :                 tprints("}");
      60                 :          5 :                 return RVAL_DECODED | 1;
      61                 :            :         }
      62                 :            : 
      63                 :         10 :         tprints("protocol=");
      64                 :         10 :         printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
      65                 :         10 :         tprints(", subprotocol=");
      66                 :         10 :         printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
      67                 :         10 :         tprintf(", request_len=%u, request=", sg_io.request_len);
      68                 :         10 :         print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len, 0);
      69                 :         10 :         tprintf(", request_tag=%#" PRI__x64, sg_io.request_tag);
      70                 :         10 :         tprintf(", request_attr=%u", sg_io.request_attr);
      71                 :         10 :         tprintf(", request_priority=%u", sg_io.request_priority);
      72                 :         10 :         tprintf(", request_extra=%u", sg_io.request_extra);
      73                 :         10 :         tprintf(", max_response_len=%u", sg_io.max_response_len);
      74                 :            : 
      75                 :         10 :         tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
      76                 :         10 :         tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
      77                 :         10 :         tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
      78                 :         10 :         tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
      79                 :         10 :         tprints(", dout_xferp=");
      80                 :         10 :         print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len,
      81                 :            :                            sg_io.dout_iovec_count);
      82                 :            : 
      83                 :         10 :         tprintf(", timeout=%u", sg_io.timeout);
      84                 :         10 :         tprints(", flags=");
      85                 :         10 :         printflags(bsg_flags, sg_io.flags, "BSG_FLAG_???");
      86                 :         10 :         tprintf(", usr_ptr=%#" PRI__x64, sg_io.usr_ptr);
      87                 :            : 
      88                 :         10 :         struct sg_io_v4 *entering_sg_io = malloc(sizeof(*entering_sg_io));
      89         [ +  - ]:         10 :         if (entering_sg_io) {
      90                 :         10 :                 memcpy(entering_sg_io, &sg_io, sizeof(sg_io));
      91                 :         10 :                 entering_sg_io->guard = (unsigned char) 'Q';
      92                 :         10 :                 set_tcb_priv_data(tcp, entering_sg_io, free);
      93                 :            :         }
      94                 :            : 
      95                 :         15 :         return 1;
      96                 :            : }
      97                 :            : 
      98                 :            : static int
      99                 :         10 : decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
     100                 :            : {
     101                 :         10 :         struct sg_io_v4 *entering_sg_io = get_tcb_priv_data(tcp);
     102                 :            :         struct sg_io_v4 sg_io;
     103                 :            :         uint32_t din_len;
     104                 :            : 
     105         [ -  + ]:         10 :         if (umove(tcp, arg, &sg_io) < 0) {
     106                 :            :                 /* print i/o fields fetched on entering syscall */
     107                 :          0 :                 tprints(", response=");
     108                 :          0 :                 printaddr(entering_sg_io->response);
     109                 :          0 :                 tprints(", din_xferp=");
     110                 :          0 :                 printaddr(entering_sg_io->din_xferp);
     111                 :          0 :                 return RVAL_DECODED | 1;
     112                 :            :         }
     113                 :            : 
     114         [ -  + ]:         10 :         if (sg_io.guard != entering_sg_io->guard) {
     115                 :          0 :                 tprintf(" => guard=%u", sg_io.guard);
     116                 :          0 :                 return RVAL_DECODED | 1;
     117                 :            :         }
     118                 :            : 
     119                 :         10 :         tprintf(", response_len=%u, response=", sg_io.response_len);
     120                 :         10 :         print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len, 0);
     121                 :         10 :         din_len = sg_io.din_xfer_len;
     122 [ +  + ][ +  - ]:         10 :         if (sg_io.din_resid > 0 && (unsigned int) sg_io.din_resid <= din_len)
     123                 :          5 :                 din_len -= sg_io.din_resid;
     124                 :         10 :         tprints(", din_xferp=");
     125                 :         10 :         print_sg_io_buffer(tcp, sg_io.din_xferp, din_len,
     126                 :            :                            sg_io.din_iovec_count);
     127                 :         10 :         tprintf(", driver_status=%#x", sg_io.driver_status);
     128                 :         10 :         tprintf(", transport_status=%#x", sg_io.transport_status);
     129                 :         10 :         tprintf(", device_status=%#x", sg_io.device_status);
     130                 :         10 :         tprintf(", retry_delay=%u", sg_io.retry_delay);
     131                 :         10 :         tprints(", info=");
     132                 :         10 :         printflags(sg_io_info, sg_io.info, "SG_INFO_???");
     133                 :         10 :         tprintf(", duration=%u", sg_io.duration);
     134                 :         10 :         tprintf(", response_len=%u", sg_io.response_len);
     135                 :         10 :         tprintf(", din_resid=%d", sg_io.din_resid);
     136                 :         10 :         tprintf(", dout_resid=%d", sg_io.dout_resid);
     137                 :         10 :         tprintf(", generated_tag=%#" PRI__x64, sg_io.generated_tag);
     138                 :            : 
     139                 :         10 :         return RVAL_DECODED | 1;
     140                 :            : }
     141                 :            : 
     142                 :            : #else /* !HAVE_LINUX_BSG_H */
     143                 :            : 
     144                 :            : static int
     145                 :            : decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
     146                 :            : {
     147                 :            :         tprints("{guard='Q', ...}");
     148                 :            :         return RVAL_DECODED | 1;
     149                 :            : }
     150                 :            : 
     151                 :            : static int
     152                 :            : decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
     153                 :            : {
     154                 :            :         return 0;
     155                 :            : }
     156                 :            : 
     157                 :            : #endif
     158                 :            : 
     159                 :            : int
     160                 :         25 : decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
     161                 :            : {
     162                 :         25 :         return entering(tcp) ? decode_request(tcp, arg)
     163         [ +  + ]:         25 :                              : decode_response(tcp, arg);
     164                 :            : }

Generated by: LCOV version 1.12