From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, berrange@redhat.com,
mreitz@redhat.com, den@openvz.org
Subject: [Qemu-devel] [PATCH 1/2] io/channel: add qio_channel_set_keepalive
Date: Wed, 5 Jun 2019 13:09:12 +0300 [thread overview]
Message-ID: <20190605100913.34972-2-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20190605100913.34972-1-vsementsov@virtuozzo.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
include/io/channel.h | 13 +++++++++++++
io/channel-socket.c | 19 +++++++++++++++++++
io/channel.c | 14 ++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/include/io/channel.h b/include/io/channel.h
index 59460cb1ec..34d871a414 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -124,6 +124,9 @@ struct QIOChannelClass {
int (*io_set_blocking)(QIOChannel *ioc,
bool enabled,
Error **errp);
+ int (*io_set_keepalive)(QIOChannel *ioc,
+ bool enabled,
+ Error **errp);
/* Optional callbacks */
int (*io_shutdown)(QIOChannel *ioc,
@@ -490,6 +493,16 @@ int qio_channel_set_blocking(QIOChannel *ioc,
bool enabled,
Error **errp);
+/*
+ * qio_channel_set_keepalive:
+ * @ioc: the channel object
+ * @enabled: the keepalive flag state
+ * @errp: pointer to a NULL-initialized error object
+ */
+int qio_channel_set_keepalive(QIOChannel *ioc,
+ bool enabled,
+ Error **errp);
+
/**
* qio_channel_close:
* @ioc: the channel object
diff --git a/io/channel-socket.c b/io/channel-socket.c
index bc5f80e780..5c1ea08660 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -656,6 +656,24 @@ qio_channel_socket_set_blocking(QIOChannel *ioc,
}
+static int
+qio_channel_socket_set_keepalive(QIOChannel *ioc,
+ bool enabled,
+ Error **errp)
+{
+ QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
+ int val = enabled;
+ int ret = qemu_setsockopt(sioc->fd, SOL_SOCKET, SO_KEEPALIVE,
+ &val, sizeof(val));
+
+ if (ret < 0) {
+ error_setg_errno(errp, errno, "Unable to set KEEPALIVE");
+ }
+
+ return ret;
+}
+
+
static void
qio_channel_socket_set_delay(QIOChannel *ioc,
bool enabled)
@@ -762,6 +780,7 @@ static void qio_channel_socket_class_init(ObjectClass *klass,
ioc_klass->io_writev = qio_channel_socket_writev;
ioc_klass->io_readv = qio_channel_socket_readv;
ioc_klass->io_set_blocking = qio_channel_socket_set_blocking;
+ ioc_klass->io_set_keepalive = qio_channel_socket_set_keepalive;
ioc_klass->io_close = qio_channel_socket_close;
ioc_klass->io_shutdown = qio_channel_socket_shutdown;
ioc_klass->io_set_cork = qio_channel_socket_set_cork;
diff --git a/io/channel.c b/io/channel.c
index 2a26c2a2c0..0f0b2b7b65 100644
--- a/io/channel.c
+++ b/io/channel.c
@@ -265,6 +265,20 @@ int qio_channel_set_blocking(QIOChannel *ioc,
return klass->io_set_blocking(ioc, enabled, errp);
}
+int qio_channel_set_keepalive(QIOChannel *ioc,
+ bool enabled,
+ Error **errp)
+{
+ QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
+
+ if (!klass->io_set_keepalive) {
+ error_setg(errp, "KEEPALIVE is not supported by IO channel");
+ return -ENOTSUP;
+ }
+
+ return klass->io_set_keepalive(ioc, enabled, errp);
+}
+
int qio_channel_close(QIOChannel *ioc,
Error **errp)
--
2.18.0
next prev parent reply other threads:[~2019-06-05 10:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-05 10:09 [Qemu-devel] [PATCH 0/2] nbd: enable keepalive Vladimir Sementsov-Ogievskiy
2019-06-05 10:09 ` Vladimir Sementsov-Ogievskiy [this message]
2019-06-05 14:38 ` [Qemu-devel] [PATCH 1/2] io/channel: add qio_channel_set_keepalive Eric Blake
2019-06-05 16:07 ` Daniel P. Berrangé
2019-06-05 16:02 ` Daniel P. Berrangé
2019-06-05 16:10 ` Vladimir Sementsov-Ogievskiy
2019-06-05 10:09 ` [Qemu-devel] [PATCH 2/2] nbd-client: enable TCP keepalive Vladimir Sementsov-Ogievskiy
2019-06-05 14:39 ` Eric Blake
2019-06-05 14:43 ` Denis V. Lunev
2019-06-05 16:37 ` Daniel P. Berrangé
2019-06-05 17:05 ` Vladimir Sementsov-Ogievskiy
2019-06-05 17:12 ` Eric Blake
2019-06-05 17:28 ` Vladimir Sementsov-Ogievskiy
2019-06-05 17:36 ` Daniel P. Berrangé
2019-06-05 19:48 ` Eric Blake
2019-06-05 20:11 ` [Qemu-devel] nbd-server-add [was: [PATCH 2/2] nbd-client: enable TCP keepalive] Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190605100913.34972-2-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=berrange@redhat.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).