]> git.proxmox.com Git - mirror_qemu.git/blame - nbd/common.c
target-arm: Add PMUSERENR_EL0 register
[mirror_qemu.git] / nbd / common.c
CommitLineData
798bfe00
FZ
1/*
2 * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
3 *
4 * Network Block Device Common Code
5 *
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.
9 *
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.
14 *
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/>.
17 */
18
d38ea87a 19#include "qemu/osdep.h"
798bfe00
FZ
20#include "nbd-internal.h"
21
1c778ef7
DB
22ssize_t nbd_wr_syncv(QIOChannel *ioc,
23 struct iovec *iov,
24 size_t niov,
25 size_t offset,
26 size_t length,
27 bool do_read)
798bfe00 28{
1c778ef7
DB
29 ssize_t done = 0;
30 Error *local_err = NULL;
31 struct iovec *local_iov = g_new(struct iovec, niov);
32 struct iovec *local_iov_head = local_iov;
33 unsigned int nlocal_iov = niov;
798bfe00 34
1c778ef7
DB
35 nlocal_iov = iov_copy(local_iov, nlocal_iov,
36 iov, niov,
37 offset, length);
798bfe00 38
1c778ef7 39 while (nlocal_iov > 0) {
798bfe00 40 ssize_t len;
798bfe00 41 if (do_read) {
1c778ef7 42 len = qio_channel_readv(ioc, local_iov, nlocal_iov, &local_err);
798bfe00 43 } else {
1c778ef7 44 len = qio_channel_writev(ioc, local_iov, nlocal_iov, &local_err);
798bfe00 45 }
1c778ef7
DB
46 if (len == QIO_CHANNEL_ERR_BLOCK) {
47 if (qemu_in_coroutine()) {
48 /* XXX figure out if we can create a variant on
49 * qio_channel_yield() that works with AIO contexts
50 * and consider using that in this branch */
51 qemu_coroutine_yield();
52 } else {
53 qio_channel_wait(ioc,
54 do_read ? G_IO_IN : G_IO_OUT);
798bfe00 55 }
1c778ef7
DB
56 continue;
57 }
58 if (len < 0) {
59 TRACE("I/O error: %s", error_get_pretty(local_err));
60 error_free(local_err);
61 /* XXX handle Error objects */
62 done = -EIO;
63 goto cleanup;
798bfe00
FZ
64 }
65
1c778ef7 66 if (do_read && len == 0) {
798bfe00
FZ
67 break;
68 }
69
1c778ef7
DB
70 iov_discard_front(&local_iov, &nlocal_iov, len);
71 done += len;
798bfe00
FZ
72 }
73
1c778ef7
DB
74 cleanup:
75 g_free(local_iov_head);
76 return done;
798bfe00 77}
f95910fe
DB
78
79
80void nbd_tls_handshake(Object *src,
81 Error *err,
82 void *opaque)
83{
84 struct NBDTLSHandshakeData *data = opaque;
85
86 if (err) {
87 TRACE("TLS failed %s", error_get_pretty(err));
88 data->error = error_copy(err);
89 }
90 data->complete = true;
91 g_main_loop_quit(data->loop);
92}