LCOV - code coverage report
Current view: top level - include - tapdisk-message.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 31 0.0 %
Date: 2025-01-09 17:56:42 Functions: 0 1 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                 :            : #ifndef _TAPDISK_MESSAGE_H_
      32                 :            : #define _TAPDISK_MESSAGE_H_
      33                 :            : 
      34                 :            : #include <inttypes.h>
      35                 :            : #include <sys/types.h>
      36                 :            : 
      37                 :            : /*
      38                 :            :  * TODO This is quite small since we don't allow path bigger than 256 chars. If
      39                 :            :  * we ever increase this, make sure tapdisk_message_t structures are not
      40                 :            :  * allocated on the stack.
      41                 :            :  */
      42                 :            : #define TAPDISK_MESSAGE_MAX_PATH_LENGTH  256
      43                 :            : #define TAPDISK_MESSAGE_STRING_LENGTH    256
      44                 :            : 
      45                 :            : #define TAPDISK_MESSAGE_MAX_MINORS \
      46                 :            :         ((TAPDISK_MESSAGE_MAX_PATH_LENGTH / sizeof(int)) - 1)
      47                 :            : 
      48                 :            : #define TAPDISK_MESSAGE_FLAG_SHARED      0x001
      49                 :            : #define TAPDISK_MESSAGE_FLAG_RDONLY      0x002
      50                 :            : #define TAPDISK_MESSAGE_FLAG_ADD_CACHE   0x004
      51                 :            : #define TAPDISK_MESSAGE_FLAG_VHD_INDEX   0x008
      52                 :            : #define TAPDISK_MESSAGE_FLAG_ADD_LOG     0x010
      53                 :            : #define TAPDISK_MESSAGE_FLAG_ADD_LCACHE  0x020
      54                 :            : #define TAPDISK_MESSAGE_FLAG_REUSE_PRT   0x040
      55                 :            : #define TAPDISK_MESSAGE_FLAG_SECONDARY   0x080
      56                 :            : #define TAPDISK_MESSAGE_FLAG_STANDBY     0x100
      57                 :            : #define TAPDISK_MESSAGE_FLAG_NO_O_DIRECT 0x200
      58                 :            : #define TAPDISK_MESSAGE_FLAG_OPEN_ENCRYPTED 0x400
      59                 :            : 
      60                 :            : typedef struct tapdisk_message           tapdisk_message_t;
      61                 :            : typedef uint32_t                         tapdisk_message_flag_t;
      62                 :            : typedef struct tapdisk_message_image     tapdisk_message_image_t;
      63                 :            : typedef struct tapdisk_message_params    tapdisk_message_params_t;
      64                 :            : typedef struct tapdisk_message_string    tapdisk_message_string_t;
      65                 :            : typedef struct tapdisk_message_response  tapdisk_message_response_t;
      66                 :            : typedef struct tapdisk_message_minors    tapdisk_message_minors_t;
      67                 :            : typedef struct tapdisk_message_list      tapdisk_message_list_t;
      68                 :            : typedef struct tapdisk_message_stat      tapdisk_message_stat_t;
      69                 :            : 
      70                 :            : struct tapdisk_message_params {
      71                 :            :         tapdisk_message_flag_t           flags;
      72                 :            : 
      73                 :            :         uint32_t                         devnum;
      74                 :            :         uint32_t                         domid;
      75                 :            :         char                             path[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
      76                 :            :         uint32_t                         prt_devnum;
      77                 :            :         uint16_t                         req_timeout;
      78                 :            :         char                             secondary[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
      79                 :            : };
      80                 :            : 
      81                 :            : struct tapdisk_message_image {
      82                 :            :         uint64_t                         sectors;
      83                 :            :         uint32_t                         sector_size;
      84                 :            :         uint32_t                         info;
      85                 :            : };
      86                 :            : 
      87                 :            : struct tapdisk_message_string {
      88                 :            :         char                             text[TAPDISK_MESSAGE_STRING_LENGTH];
      89                 :            : };
      90                 :            : 
      91                 :            : struct tapdisk_message_response {
      92                 :            :         int                              error;
      93                 :            :         char                             message[TAPDISK_MESSAGE_STRING_LENGTH];
      94                 :            : };
      95                 :            : 
      96                 :            : struct tapdisk_message_minors {
      97                 :            :         int                              count;
      98                 :            :         int                              list[TAPDISK_MESSAGE_MAX_MINORS];
      99                 :            : };
     100                 :            : 
     101                 :            : struct tapdisk_message_list {
     102                 :            :         int                              count;
     103                 :            :         int                              minor;
     104                 :            :         int                              state;
     105                 :            :         char                             path[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
     106                 :            : };
     107                 :            : 
     108                 :            : struct tapdisk_message_stat {
     109                 :            :         uint16_t                         type;
     110                 :            :         uint16_t                         cookie;
     111                 :            :         size_t                           length;
     112                 :            : };
     113                 :            : 
     114                 :            : /**
     115                 :            :  * Tapdisk message containing all the necessary information required for the
     116                 :            :  * tapdisk to connect to a guest's blkfront.
     117                 :            :  */
     118                 :            : typedef struct tapdisk_message_blkif {
     119                 :            :         /**
     120                 :            :          * The domain ID of the guest to connect to.
     121                 :            :          */
     122                 :            :         uint32_t domid;
     123                 :            : 
     124                 :            :         /**
     125                 :            :          * The device ID of the virtual block device.
     126                 :            :          */
     127                 :            :         uint32_t devid;
     128                 :            : 
     129                 :            :         /**
     130                 :            :          * Grant references for the shared ring.
     131                 :            :          * TODO Why 8 specifically?
     132                 :            :          */
     133                 :            :         uint32_t gref[8];
     134                 :            : 
     135                 :            :         /**
     136                 :            :          * Number of pages in the ring, expressed as a page order.
     137                 :            :          */
     138                 :            :         uint32_t order;
     139                 :            : 
     140                 :            :         /**
     141                 :            :          * Protocol to use: native, 32 bit, or 64 bit. Used for supporting a
     142                 :            :          * 32-bit domU talking to a 64-bit dom0/domU and vice versa.
     143                 :            :          */
     144                 :            :         uint32_t proto;
     145                 :            : 
     146                 :            :         /**
     147                 :            :          * TODO Page pool? Can be NULL.
     148                 :            :          */
     149                 :            :         char pool[TAPDISK_MESSAGE_STRING_LENGTH];
     150                 :            : 
     151                 :            :         /**
     152                 :            :          * The event channel port.
     153                 :            :          */
     154                 :            :         uint32_t port;
     155                 :            : 
     156                 :            :         /**
     157                 :            :          * Polling duration in microseconds. 0 means no polling.
     158                 :            :          */
     159                 :            :         uint32_t poll_duration;
     160                 :            : 
     161                 :            :         /**
     162                 :            :          * Idle CPU threshold above which polling is permitted.
     163                 :            :          */
     164                 :            :         uint32_t poll_idle_threshold;
     165                 :            : } tapdisk_message_blkif_t;
     166                 :            : 
     167                 :            : /**
     168                 :            :  * Contains parameters for resuming a previously paused VBD.
     169                 :            :  */
     170                 :            : typedef struct tapdisk_message_resume {
     171                 :            :     /**
     172                 :            :      * TODO
     173                 :            :      */
     174                 :            :         tapdisk_message_flag_t flags;
     175                 :            : 
     176                 :            :     /**
     177                 :            :      * A new VDI to use instead of the old one. Optional.
     178                 :            :      */
     179                 :            :     char new_params[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
     180                 :            : 
     181                 :            :     /**
     182                 :            :      * TODO
     183                 :            :      */
     184                 :            :     char secondary[TAPDISK_MESSAGE_MAX_PATH_LENGTH];
     185                 :            : } tapdisk_message_resume_t;
     186                 :            : 
     187                 :            : struct tapdisk_message {
     188                 :            :         uint16_t                       type;
     189                 :            :         uint16_t                         cookie;
     190                 :            : 
     191                 :            :         union {
     192                 :            :                 pid_t                      tapdisk_pid;
     193                 :            :                 tapdisk_message_image_t    image;
     194                 :            :                 tapdisk_message_params_t   params;
     195                 :            :                 tapdisk_message_string_t   string;
     196                 :            :                 tapdisk_message_minors_t   minors;
     197                 :            :                 tapdisk_message_response_t response;
     198                 :            :                 tapdisk_message_list_t     list;
     199                 :            :                 tapdisk_message_stat_t     info;
     200                 :            :                 tapdisk_message_blkif_t    blkif;
     201                 :            :         tapdisk_message_resume_t   resume;
     202                 :            :         } u;
     203                 :            : };
     204                 :            : 
     205                 :            : enum tapdisk_message_id {
     206                 :            :         TAPDISK_MESSAGE_ERROR = 1,
     207                 :            :         TAPDISK_MESSAGE_RUNTIME_ERROR,
     208                 :            :         TAPDISK_MESSAGE_PID, /* 3 */
     209                 :            :         TAPDISK_MESSAGE_PID_RSP,
     210                 :            :         TAPDISK_MESSAGE_ATTACH,
     211                 :            :         TAPDISK_MESSAGE_ATTACH_RSP,
     212                 :            :         TAPDISK_MESSAGE_OPEN,
     213                 :            :         TAPDISK_MESSAGE_OPEN_RSP,
     214                 :            :         TAPDISK_MESSAGE_PAUSE, /* 9 */
     215                 :            :         TAPDISK_MESSAGE_PAUSE_RSP,
     216                 :            :         TAPDISK_MESSAGE_RESUME, /* 11 */
     217                 :            :         TAPDISK_MESSAGE_RESUME_RSP,
     218                 :            :         TAPDISK_MESSAGE_CLOSE,
     219                 :            :         TAPDISK_MESSAGE_CLOSE_RSP,
     220                 :            :         TAPDISK_MESSAGE_DETACH,
     221                 :            :         TAPDISK_MESSAGE_DETACH_RSP,
     222                 :            :         TAPDISK_MESSAGE_LIST_MINORS,
     223                 :            :         TAPDISK_MESSAGE_LIST_MINORS_RSP,
     224                 :            :         TAPDISK_MESSAGE_LIST, /* 19 */
     225                 :            :         TAPDISK_MESSAGE_LIST_RSP,
     226                 :            :         TAPDISK_MESSAGE_STATS,
     227                 :            :         TAPDISK_MESSAGE_STATS_RSP,
     228                 :            :         TAPDISK_MESSAGE_FORCE_SHUTDOWN,
     229                 :            :         TAPDISK_MESSAGE_XENBLKIF_CONNECT,
     230                 :            :         TAPDISK_MESSAGE_XENBLKIF_CONNECT_RSP,
     231                 :            :         TAPDISK_MESSAGE_XENBLKIF_DISCONNECT, /* 26 */
     232                 :            :         TAPDISK_MESSAGE_XENBLKIF_DISCONNECT_RSP,
     233                 :            :         TAPDISK_MESSAGE_DISK_INFO,
     234                 :            :         TAPDISK_MESSAGE_DISK_INFO_RSP,
     235                 :            :         TAPDISK_MESSAGE_EXIT,
     236                 :            : };
     237                 :            : 
     238                 :            : #define TAPDISK_MESSAGE_MAX TAPDISK_MESSAGE_EXIT
     239                 :            : 
     240                 :            : static inline char *
     241                 :          0 : tapdisk_message_name(enum tapdisk_message_id id)
     242                 :            : {
     243                 :          0 :         switch (id) {
     244                 :            :         case TAPDISK_MESSAGE_ERROR:
     245                 :            :                 return "error";
     246                 :            : 
     247                 :            :         case TAPDISK_MESSAGE_PID:
     248                 :          0 :                 return "pid";
     249                 :            : 
     250                 :            :         case TAPDISK_MESSAGE_PID_RSP:
     251                 :          0 :                 return "pid response";
     252                 :            : 
     253                 :            :         case TAPDISK_MESSAGE_OPEN:
     254                 :          0 :                 return "open";
     255                 :            : 
     256                 :            :         case TAPDISK_MESSAGE_OPEN_RSP:
     257                 :          0 :                 return "open response";
     258                 :            : 
     259                 :            :         case TAPDISK_MESSAGE_PAUSE:
     260                 :          0 :                 return "pause";
     261                 :            : 
     262                 :            :         case TAPDISK_MESSAGE_PAUSE_RSP:
     263                 :          0 :                 return "pause response";
     264                 :            : 
     265                 :            :         case TAPDISK_MESSAGE_RESUME:
     266                 :          0 :                 return "resume";
     267                 :            : 
     268                 :            :         case TAPDISK_MESSAGE_RESUME_RSP:
     269                 :          0 :                 return "resume response";
     270                 :            : 
     271                 :            :         case TAPDISK_MESSAGE_CLOSE:
     272                 :          0 :                 return "close";
     273                 :            : 
     274                 :            :         case TAPDISK_MESSAGE_FORCE_SHUTDOWN:
     275                 :          0 :                 return "force shutdown";
     276                 :            : 
     277                 :            :         case TAPDISK_MESSAGE_CLOSE_RSP:
     278                 :          0 :                 return "close response";
     279                 :            : 
     280                 :            :         case TAPDISK_MESSAGE_ATTACH:
     281                 :          0 :                 return "attach";
     282                 :            : 
     283                 :            :         case TAPDISK_MESSAGE_ATTACH_RSP:
     284                 :          0 :                 return "attach response";
     285                 :            : 
     286                 :            :         case TAPDISK_MESSAGE_DETACH:
     287                 :          0 :                 return "detach";
     288                 :            : 
     289                 :            :         case TAPDISK_MESSAGE_DETACH_RSP:
     290                 :          0 :                 return "detach response";
     291                 :            : 
     292                 :            :         case TAPDISK_MESSAGE_LIST_MINORS:
     293                 :          0 :                 return "list minors";
     294                 :            : 
     295                 :            :         case TAPDISK_MESSAGE_LIST_MINORS_RSP:
     296                 :          0 :                 return "list minors response";
     297                 :            : 
     298                 :            :         case TAPDISK_MESSAGE_LIST:
     299                 :          0 :                 return "list";
     300                 :            : 
     301                 :            :         case TAPDISK_MESSAGE_LIST_RSP:
     302                 :          0 :                 return "list response";
     303                 :            : 
     304                 :            :         case TAPDISK_MESSAGE_STATS:
     305                 :          0 :                 return "stats";
     306                 :            : 
     307                 :            :         case TAPDISK_MESSAGE_STATS_RSP:
     308                 :          0 :                 return "stats response";
     309                 :            : 
     310                 :            :         case TAPDISK_MESSAGE_XENBLKIF_CONNECT:
     311                 :          0 :                 return "sring connect";
     312                 :            : 
     313                 :            :         case TAPDISK_MESSAGE_XENBLKIF_CONNECT_RSP:
     314                 :          0 :                 return "sring connect rsp";
     315                 :            : 
     316                 :            :         case TAPDISK_MESSAGE_XENBLKIF_DISCONNECT:
     317                 :          0 :                 return "sring disconnect";
     318                 :            : 
     319                 :            :         case TAPDISK_MESSAGE_XENBLKIF_DISCONNECT_RSP:
     320                 :          0 :                 return "sring disconnect rsp";
     321                 :            : 
     322                 :            :         case TAPDISK_MESSAGE_DISK_INFO:
     323                 :          0 :                 return "disk info";
     324                 :            : 
     325                 :            :         case TAPDISK_MESSAGE_DISK_INFO_RSP:
     326                 :          0 :                 return "disk info rsp";
     327                 :            : 
     328                 :            :         case TAPDISK_MESSAGE_EXIT:
     329                 :          0 :                 return "exit";
     330                 :            : 
     331                 :            :         default:
     332                 :          0 :                 return "unknown";
     333                 :            :         }
     334                 :            : }
     335                 :            : 
     336                 :            : #endif

Generated by: LCOV version 1.13