2 * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
4 * Network Block Device Common Code
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
20 #include "qapi/error.h"
22 #include "nbd-internal.h"
24 /* Discard length bytes from channel. Return -errno on failure and 0 on
26 int nbd_drop(QIOChannel
*ioc
, size_t size
, Error
**errp
)
32 buffer
= sizeof(small
) >= size
? small
: g_malloc(MIN(65536, size
));
34 ssize_t count
= MIN(65536, size
);
35 ret
= nbd_read(ioc
, buffer
, MIN(65536, size
), errp
);
44 if (buffer
!= small
) {
51 void nbd_tls_handshake(QIOTask
*task
,
54 struct NBDTLSHandshakeData
*data
= opaque
;
56 qio_task_propagate_error(task
, &data
->error
);
57 data
->complete
= true;
58 g_main_loop_quit(data
->loop
);
62 const char *nbd_opt_lookup(uint32_t opt
)
65 case NBD_OPT_EXPORT_NAME
:
71 case NBD_OPT_STARTTLS
:
77 case NBD_OPT_STRUCTURED_REPLY
:
78 return "structured reply";
85 const char *nbd_rep_lookup(uint32_t rep
)
94 case NBD_REP_ERR_UNSUP
:
96 case NBD_REP_ERR_POLICY
:
97 return "denied by policy";
98 case NBD_REP_ERR_INVALID
:
100 case NBD_REP_ERR_PLATFORM
:
101 return "platform lacks support";
102 case NBD_REP_ERR_TLS_REQD
:
103 return "TLS required";
104 case NBD_REP_ERR_UNKNOWN
:
105 return "export unknown";
106 case NBD_REP_ERR_SHUTDOWN
:
107 return "server shutting down";
108 case NBD_REP_ERR_BLOCK_SIZE_REQD
:
109 return "block size required";
116 const char *nbd_info_lookup(uint16_t info
)
119 case NBD_INFO_EXPORT
:
123 case NBD_INFO_DESCRIPTION
:
124 return "description";
125 case NBD_INFO_BLOCK_SIZE
:
133 const char *nbd_cmd_lookup(uint16_t cmd
)
146 case NBD_CMD_WRITE_ZEROES
:
147 return "write zeroes";
154 const char *nbd_reply_type_lookup(uint16_t type
)
157 case NBD_REPLY_TYPE_NONE
:
159 case NBD_REPLY_TYPE_OFFSET_DATA
:
161 case NBD_REPLY_TYPE_OFFSET_HOLE
:
163 case NBD_REPLY_TYPE_ERROR
:
164 return "generic error";
165 case NBD_REPLY_TYPE_ERROR_OFFSET
:
166 return "error at offset";
168 if (type
& (1 << 15)) {
169 return "<unknown error>";
176 const char *nbd_err_lookup(int err
)
201 int nbd_errno_to_system_errno(int err
)
227 trace_nbd_unknown_error(err
);