LCOV - code coverage report
Current view: top level - strace - sg_io_v4.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 56 61 91.8 %
Date: 2017-07-31 03:46:08 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 "print_fields.h"
      34                 :            : # include <linux/bsg.h>
      35                 :            : # include "xlat/bsg_protocol.h"
      36                 :            : # include "xlat/bsg_subprotocol.h"
      37                 :            : # include "xlat/bsg_flags.h"
      38                 :            : 
      39                 :            : static void
      40                 :         16 : print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
      41                 :            :                    const unsigned int data_size, const unsigned int iovec_count)
      42                 :            : {
      43         [ +  + ]:         16 :         if (iovec_count) {
      44                 :          6 :                 tprint_iov_upto(tcp, iovec_count, addr, IOV_DECODE_STR,
      45                 :            :                                 data_size);
      46                 :            :         } else {
      47                 :         10 :                 printstr_ex(tcp, addr, data_size, QUOTE_FORCE_HEX);
      48                 :            :         }
      49                 :         16 : }
      50                 :            : 
      51                 :            : #define PRINT_FIELD_SG_IO_BUFFER(prefix_, where_, field_, size_, count_, tcp_)  \
      52                 :            :         do {                                                                    \
      53                 :            :                 STRACE_PRINTF("%s%s=", (prefix_), #field_);                   \
      54                 :            :                 print_sg_io_buffer((tcp_), (where_).field_, (size_), (count_)); \
      55                 :            :         } while (0)
      56                 :            : 
      57                 :            : static int
      58                 :          6 : decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
      59                 :            : {
      60                 :            :         struct sg_io_v4 sg_io;
      61                 :            :         static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
      62                 :            : 
      63                 :          6 :         tprints("{guard='Q', ");
      64         [ +  + ]:          6 :         if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
      65                 :            :                                 &sg_io.protocol)) {
      66                 :          2 :                 tprints("}");
      67                 :          2 :                 return RVAL_DECODED | 1;
      68                 :            :         }
      69                 :            : 
      70                 :          4 :         PRINT_FIELD_XVAL("", sg_io, protocol, bsg_protocol, "BSG_PROTOCOL_???");
      71                 :          4 :         PRINT_FIELD_XVAL(", ", sg_io, subprotocol, bsg_subprotocol,
      72                 :            :                          "BSG_SUB_PROTOCOL_???");
      73                 :          4 :         PRINT_FIELD_U(", ", sg_io, request_len);
      74                 :          4 :         PRINT_FIELD_SG_IO_BUFFER(", ", sg_io, request, sg_io.request_len,
      75                 :            :                                  0, tcp);
      76                 :          4 :         PRINT_FIELD_X(", ", sg_io, request_tag);
      77                 :          4 :         PRINT_FIELD_U(", ", sg_io, request_attr);
      78                 :          4 :         PRINT_FIELD_U(", ", sg_io, request_priority);
      79                 :          4 :         PRINT_FIELD_U(", ", sg_io, request_extra);
      80                 :          4 :         PRINT_FIELD_U(", ", sg_io, max_response_len);
      81                 :            : 
      82                 :          4 :         PRINT_FIELD_U(", ", sg_io, dout_iovec_count);
      83                 :          4 :         PRINT_FIELD_U(", ", sg_io, dout_xfer_len);
      84                 :          4 :         PRINT_FIELD_U(", ", sg_io, din_iovec_count);
      85                 :          4 :         PRINT_FIELD_U(", ", sg_io, din_xfer_len);
      86                 :          4 :         PRINT_FIELD_SG_IO_BUFFER(", ", sg_io, dout_xferp, sg_io.dout_xfer_len,
      87                 :            :                                  sg_io.dout_iovec_count, tcp);
      88                 :            : 
      89                 :          4 :         PRINT_FIELD_U(", ", sg_io, timeout);
      90                 :          4 :         PRINT_FIELD_FLAGS(", ", sg_io, flags, bsg_flags, "BSG_FLAG_???");
      91                 :          4 :         PRINT_FIELD_X(", ", sg_io, usr_ptr);
      92                 :            : 
      93                 :          4 :         struct sg_io_v4 *entering_sg_io = malloc(sizeof(*entering_sg_io));
      94         [ +  - ]:          4 :         if (entering_sg_io) {
      95                 :          4 :                 memcpy(entering_sg_io, &sg_io, sizeof(sg_io));
      96                 :          4 :                 entering_sg_io->guard = (unsigned char) 'Q';
      97                 :          4 :                 set_tcb_priv_data(tcp, entering_sg_io, free);
      98                 :            :         }
      99                 :            : 
     100                 :            :         return 1;
     101                 :            : }
     102                 :            : 
     103                 :            : static int
     104                 :          4 : decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
     105                 :            : {
     106                 :          4 :         struct sg_io_v4 *entering_sg_io = get_tcb_priv_data(tcp);
     107                 :            :         struct sg_io_v4 sg_io;
     108                 :            :         uint32_t din_len;
     109                 :            : 
     110         [ -  + ]:          4 :         if (umove(tcp, arg, &sg_io) < 0) {
     111                 :            :                 /* print i/o fields fetched on entering syscall */
     112                 :          0 :                 PRINT_FIELD_X(", ", *entering_sg_io, response);
     113                 :          0 :                 PRINT_FIELD_X(", ", *entering_sg_io, din_xferp);
     114                 :          0 :                 return RVAL_DECODED | 1;
     115                 :            :         }
     116                 :            : 
     117         [ -  + ]:          4 :         if (sg_io.guard != entering_sg_io->guard) {
     118                 :          0 :                 PRINT_FIELD_U(" => ", sg_io, guard);
     119                 :          0 :                 return RVAL_DECODED | 1;
     120                 :            :         }
     121                 :            : 
     122                 :          4 :         PRINT_FIELD_U(", ", sg_io, response_len);
     123                 :          4 :         PRINT_FIELD_SG_IO_BUFFER(", ", sg_io, response, sg_io.response_len,
     124                 :            :                                  0, tcp);
     125                 :          4 :         din_len = sg_io.din_xfer_len;
     126 [ +  + ][ +  - ]:          4 :         if (sg_io.din_resid > 0 && (unsigned int) sg_io.din_resid <= din_len)
     127                 :          2 :                 din_len -= sg_io.din_resid;
     128                 :          4 :         PRINT_FIELD_SG_IO_BUFFER(", ", sg_io, din_xferp, din_len,
     129                 :            :                                  sg_io.din_iovec_count, tcp);
     130                 :          4 :         PRINT_FIELD_X(", ", sg_io, driver_status);
     131                 :          4 :         PRINT_FIELD_X(", ", sg_io, transport_status);
     132                 :          4 :         PRINT_FIELD_X(", ", sg_io, device_status);
     133                 :          4 :         PRINT_FIELD_U(", ", sg_io, retry_delay);
     134                 :          4 :         PRINT_FIELD_FLAGS(", ", sg_io, info, sg_io_info, "SG_INFO_???");
     135                 :          4 :         PRINT_FIELD_U(", ", sg_io, duration);
     136                 :          4 :         PRINT_FIELD_U(", ", sg_io, response_len);
     137                 :          4 :         PRINT_FIELD_D(", ", sg_io, din_resid);
     138                 :          4 :         PRINT_FIELD_D(", ", sg_io, dout_resid);
     139                 :          4 :         PRINT_FIELD_X(", ", sg_io, generated_tag);
     140                 :            : 
     141                 :          4 :         return RVAL_DECODED | 1;
     142                 :            : }
     143                 :            : 
     144                 :            : #else /* !HAVE_LINUX_BSG_H */
     145                 :            : 
     146                 :            : static int
     147                 :            : decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
     148                 :            : {
     149                 :            :         tprints("{guard='Q', ...}");
     150                 :            :         return RVAL_DECODED | 1;
     151                 :            : }
     152                 :            : 
     153                 :            : static int
     154                 :            : decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
     155                 :            : {
     156                 :            :         return 0;
     157                 :            : }
     158                 :            : 
     159                 :            : #endif
     160                 :            : 
     161                 :            : int
     162                 :         10 : decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
     163                 :            : {
     164                 :         20 :         return entering(tcp) ? decode_request(tcp, arg)
     165         [ +  + ]:         10 :                              : decode_response(tcp, arg);
     166                 :            : }

Generated by: LCOV version 1.11