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"
21 #include "nbd-internal.h"
23 /* Discard length bytes from channel. Return -errno on failure and 0 on
25 int nbd_drop(QIOChannel
*ioc
, size_t size
, Error
**errp
)
31 buffer
= sizeof(small
) >= size
? small
: g_malloc(MIN(65536, size
));
33 ssize_t count
= MIN(65536, size
);
34 ret
= nbd_read(ioc
, buffer
, MIN(65536, size
), errp
);
43 if (buffer
!= small
) {
50 void nbd_tls_handshake(QIOTask
*task
,
53 struct NBDTLSHandshakeData
*data
= opaque
;
55 qio_task_propagate_error(task
, &data
->error
);
56 data
->complete
= true;
57 g_main_loop_quit(data
->loop
);
61 const char *nbd_opt_lookup(uint32_t opt
)
64 case NBD_OPT_EXPORT_NAME
:
70 case NBD_OPT_STARTTLS
:
76 case NBD_OPT_STRUCTURED_REPLY
:
77 return "structured reply";
78 case NBD_OPT_LIST_META_CONTEXT
:
79 return "list meta context";
80 case NBD_OPT_SET_META_CONTEXT
:
81 return "set meta context";
88 const char *nbd_rep_lookup(uint32_t rep
)
97 case NBD_REP_META_CONTEXT
:
98 return "meta context";
99 case NBD_REP_ERR_UNSUP
:
100 return "unsupported";
101 case NBD_REP_ERR_POLICY
:
102 return "denied by policy";
103 case NBD_REP_ERR_INVALID
:
105 case NBD_REP_ERR_PLATFORM
:
106 return "platform lacks support";
107 case NBD_REP_ERR_TLS_REQD
:
108 return "TLS required";
109 case NBD_REP_ERR_UNKNOWN
:
110 return "export unknown";
111 case NBD_REP_ERR_SHUTDOWN
:
112 return "server shutting down";
113 case NBD_REP_ERR_BLOCK_SIZE_REQD
:
114 return "block size required";
121 const char *nbd_info_lookup(uint16_t info
)
124 case NBD_INFO_EXPORT
:
128 case NBD_INFO_DESCRIPTION
:
129 return "description";
130 case NBD_INFO_BLOCK_SIZE
:
138 const char *nbd_cmd_lookup(uint16_t cmd
)
153 case NBD_CMD_WRITE_ZEROES
:
154 return "write zeroes";
155 case NBD_CMD_BLOCK_STATUS
:
156 return "block status";
163 const char *nbd_reply_type_lookup(uint16_t type
)
166 case NBD_REPLY_TYPE_NONE
:
168 case NBD_REPLY_TYPE_OFFSET_DATA
:
170 case NBD_REPLY_TYPE_OFFSET_HOLE
:
172 case NBD_REPLY_TYPE_BLOCK_STATUS
:
173 return "block status";
174 case NBD_REPLY_TYPE_ERROR
:
175 return "generic error";
176 case NBD_REPLY_TYPE_ERROR_OFFSET
:
177 return "error at offset";
179 if (type
& (1 << 15)) {
180 return "<unknown error>";
187 const char *nbd_err_lookup(int err
)
212 int nbd_errno_to_system_errno(int err
)
238 trace_nbd_unknown_error(err
);