LCOV - code coverage report
Current view: top level - control - tap-ctl-xen.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 39 0.0 %
Date: 2025-02-07 10:27:58 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2016, Citrix Systems, Inc.
       3                 :            :  *
       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 are met:
       8                 :            :  * 
       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. Neither the name of the copyright holder nor the names of its 
      15                 :            :  *     contributors may be used to endorse or promote products derived from 
      16                 :            :  *     this software without specific prior written permission.
      17                 :            :  *
      18                 :            :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      19                 :            :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      20                 :            :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      21                 :            :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
      22                 :            :  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
      23                 :            :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      24                 :            :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
      25                 :            :  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
      26                 :            :  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
      27                 :            :  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      28                 :            :  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      29                 :            :  */
      30                 :            : 
      31                 :            : #ifdef HAVE_CONFIG_H
      32                 :            : #include "config.h"
      33                 :            : #endif
      34                 :            : 
      35                 :            : /*
      36                 :            :  * required by the Xen headers
      37                 :            :  */
      38                 :            : #include <inttypes.h>
      39                 :            : 
      40                 :            : #include <xen/xen.h>
      41                 :            : #include <xen/grant_table.h>
      42                 :            : #include <xen/event_channel.h>
      43                 :            : 
      44                 :            : #include <stdio.h>
      45                 :            : #include <string.h>
      46                 :            : #include <unistd.h>
      47                 :            : 
      48                 :            : #include "tap-ctl.h"
      49                 :            : #include "compiler.h"
      50                 :            : #include "util.h"
      51                 :            : 
      52                 :            : int
      53                 :          0 : tap_ctl_connect_xenblkif(const pid_t pid, const domid_t domid, const int devid, int poll_duration,
      54                 :            :                 int poll_idle_threshold,
      55                 :            :                 const grant_ref_t * grefs, const int order, const evtchn_port_t port,
      56                 :            :                 int proto, const char *pool, const int minor)
      57                 :            : {
      58                 :            :     tapdisk_message_t message;
      59                 :            :     int i, err;
      60                 :            : 
      61                 :            :         memset(&message, 0, sizeof(message));
      62                 :          0 :     message.type = TAPDISK_MESSAGE_XENBLKIF_CONNECT;
      63                 :          0 :     message.cookie = minor;
      64                 :            : 
      65                 :          0 :     message.u.blkif.domid = domid;
      66                 :          0 :     message.u.blkif.devid = devid;
      67                 :          0 :     for (i = 0; i < 1 << order; i++)
      68                 :          0 :         message.u.blkif.gref[i] = grefs[i];
      69                 :          0 :     message.u.blkif.order = order;
      70                 :          0 :     message.u.blkif.port = port;
      71                 :          0 :     message.u.blkif.proto = proto;
      72                 :          0 :     message.u.blkif.poll_duration = poll_duration;
      73                 :          0 :     message.u.blkif.poll_idle_threshold = poll_idle_threshold;
      74                 :          0 :     if (pool) {
      75                 :          0 :         if (unlikely(strlen(pool) > (sizeof(message.u.blkif.pool) - 1))) {
      76                 :            :             EPRINTF("pool name too long: %s\n", pool);
      77                 :          0 :             return -ENAMETOOLONG;
      78                 :            :         }
      79                 :          0 :         safe_strncpy(message.u.blkif.pool, pool, sizeof(message.u.blkif.pool));
      80                 :            :     } else {
      81                 :          0 :         message.u.blkif.pool[0] = 0;
      82                 :            :     }
      83                 :            : 
      84                 :          0 :     err = tap_ctl_connect_send_and_receive(pid, &message, NULL);
      85                 :          0 :     if (err || message.type == TAPDISK_MESSAGE_ERROR) {
      86                 :          0 :                 if (!err)
      87                 :          0 :                         err = -message.u.response.error;
      88                 :          0 :         if (err == -EALREADY)
      89                 :          0 :             EPRINTF("failed to connect tapdisk[%d] to the ring: %s\n", pid,
      90                 :            :                     strerror(-err));
      91                 :            :         }
      92                 :          0 :     return err;
      93                 :            : }
      94                 :            : 
      95                 :            : int
      96                 :          0 : tap_ctl_disconnect_xenblkif(const pid_t pid, const domid_t domid,
      97                 :            :         const int devid, struct timeval *timeout)
      98                 :            : {
      99                 :            :     int err;
     100                 :            :         tapdisk_message_t message;
     101                 :            : 
     102                 :            :         memset(&message, 0, sizeof(message));
     103                 :          0 :         message.type = TAPDISK_MESSAGE_XENBLKIF_DISCONNECT;
     104                 :          0 :         message.u.blkif.domid = domid;
     105                 :          0 :         message.u.blkif.devid = devid;
     106                 :            : 
     107                 :          0 :         err = tap_ctl_connect_send_and_receive(pid, &message, timeout);
     108                 :          0 :         if (err)
     109                 :            :                 goto out;
     110                 :            : 
     111                 :          0 :         if (message.type == TAPDISK_MESSAGE_XENBLKIF_DISCONNECT_RSP
     112                 :          0 :                         || message.type == TAPDISK_MESSAGE_ERROR)
     113                 :          0 :                 err = -message.u.response.error;
     114                 :            :         else {
     115                 :          0 :                 EPRINTF("got unexpected result '%s' from tapdisk[%d]\n",
     116                 :            :                                 tapdisk_message_name(message.type), pid);
     117                 :            :                 err = -EINVAL;
     118                 :            :         }
     119                 :            : 
     120                 :            : out:
     121                 :          0 :         if (err) {
     122                 :          0 :                 if (likely(err == -ENOENT))
     123                 :          0 :                         DPRINTF("failed to disconnect tapdisk[%d] from the ring: %s\n",
     124                 :            :                                         pid, strerror(-err));
     125                 :            :                 else
     126                 :          0 :                         EPRINTF("failed to disconnect tapdisk[%d] from the ring: %s\n",
     127                 :            :                                         pid, strerror(-err));
     128                 :            :         }
     129                 :          0 :         return err;
     130                 :            : }

Generated by: LCOV version 1.13