aboutsummaryrefslogtreecommitdiff
path: root/nbd/common.c
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2016-01-14 16:41:02 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2016-01-15 18:58:02 +0100
commit798bfe00063ceaa90aa2bf6e4e5c569c80fb4e92 (patch)
tree1389023d3237be76713630c50f8147d722b5984d /nbd/common.c
parentee7d7aabdaea4484e069cb99c9fc54e8cb24b56f (diff)
nbd: Split nbd.c
We have NBD server code and client code, all mixed in a file. Now split them into separate files under nbd/, and update MAINTAINERS. filter_nbd for iotest 083 is updated to keep the log filtered out. Signed-off-by: Fam Zheng <famz@redhat.com> Message-Id: <1452760863-25350-3-git-send-email-famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'nbd/common.c')
-rw-r--r--nbd/common.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/nbd/common.c b/nbd/common.c
new file mode 100644
index 0000000000..7b089b0f3b
--- /dev/null
+++ b/nbd/common.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
+ *
+ * Network Block Device Common Code
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "nbd-internal.h"
+
+ssize_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
+{
+ size_t offset = 0;
+ int err;
+
+ if (qemu_in_coroutine()) {
+ if (do_read) {
+ return qemu_co_recv(fd, buffer, size);
+ } else {
+ return qemu_co_send(fd, buffer, size);
+ }
+ }
+
+ while (offset < size) {
+ ssize_t len;
+
+ if (do_read) {
+ len = qemu_recv(fd, buffer + offset, size - offset, 0);
+ } else {
+ len = send(fd, buffer + offset, size - offset, 0);
+ }
+
+ if (len < 0) {
+ err = socket_error();
+
+ /* recoverable error */
+ if (err == EINTR || (offset > 0 && (err == EAGAIN || err == EWOULDBLOCK))) {
+ continue;
+ }
+
+ /* unrecoverable error */
+ return -err;
+ }
+
+ /* eof */
+ if (len == 0) {
+ break;
+ }
+
+ offset += len;
+ }
+
+ return offset;
+}