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"
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";
84 const char *nbd_rep_lookup(uint32_t rep
)
93 case NBD_REP_ERR_UNSUP
:
95 case NBD_REP_ERR_POLICY
:
96 return "denied by policy";
97 case NBD_REP_ERR_INVALID
:
99 case NBD_REP_ERR_PLATFORM
:
100 return "platform lacks support";
101 case NBD_REP_ERR_TLS_REQD
:
102 return "TLS required";
103 case NBD_REP_ERR_UNKNOWN
:
104 return "export unknown";
105 case NBD_REP_ERR_SHUTDOWN
:
106 return "server shutting down";
107 case NBD_REP_ERR_BLOCK_SIZE_REQD
:
108 return "block size required";
115 const char *nbd_info_lookup(uint16_t info
)
118 case NBD_INFO_EXPORT
:
122 case NBD_INFO_DESCRIPTION
:
123 return "description";
124 case NBD_INFO_BLOCK_SIZE
:
132 const char *nbd_cmd_lookup(uint16_t cmd
)
145 case NBD_CMD_WRITE_ZEROES
:
146 return "write zeroes";