From: "Marc-André Lureau" <mlureau@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: marcandre lureau <marcandre.lureau@redhat.com>,
pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/3] socket: unlink unix socket on remove
Date: Thu, 23 Jun 2016 05:08:03 -0400 (EDT) [thread overview]
Message-ID: <934708551.1342481.1466672883154.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20160623074849-mutt-send-email-mst@redhat.com>
Hi
----- Original Message -----
> On Thu, Jun 23, 2016 at 07:41:55AM +0300, Michael S. Tsirkin wrote:
> > On Thu, Jun 16, 2016 at 09:28:52PM +0200, marcandre.lureau@redhat.com
> > wrote:
> > > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> > >
> > > qemu leaves unix socket files behind when removing a listening chardev
> > > or leaving. qemu could clean that up, even if doing so isn't race-free.
> > >
> > > Fixes:
> > > https://bugzilla.redhat.com/show_bug.cgi?id=1347077
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > We normally only unlink what we created.
What do you mean by "we", qemu currently unlink before creating the unix socket. No further cleanup.
> >
> > unlinking files we didn't create
> > looks like a silent change that might easily break
> > existing users.
That shouldn't remove files we didn't create. But a bad user could recreate the unix socket after qemu did, and that would remove it. I don't think that's a valid use case though, so it should be fine.
> Maybe what you want is a need_unlink feature.
> Set it for unix sockets only, that would make some sense.
Oh perhaps what you mean is that if the fd was passed, we should cleanup the unix socket? Yes, I think we should do that then. I'll update the series.
thanks
>
> >
> > > ---
> > > include/qemu/sockets.h | 1 +
> > > io/channel-socket.c | 10 ++++++++++
> > > tests/test-io-channel-socket.c | 2 +-
> > > util/qemu-sockets.c | 18 ++++++++++++++++++
> > > 4 files changed, 30 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
> > > index 1bd9218..5dd2648 100644
> > > --- a/include/qemu/sockets.h
> > > +++ b/include/qemu/sockets.h
> > > @@ -51,6 +51,7 @@ SocketAddress *socket_parse(const char *str, Error
> > > **errp);
> > > int socket_connect(SocketAddress *addr, Error **errp,
> > > NonBlockingConnectHandler *callback, void *opaque);
> > > int socket_listen(SocketAddress *addr, Error **errp);
> > > +void socket_listen_cleanup(int fd, Error **errp);
> > > int socket_dgram(SocketAddress *remote, SocketAddress *local, Error
> > > **errp);
> > >
> > > /* Old, ipv4 only bits. Don't use for new code. */
> > > diff --git a/io/channel-socket.c b/io/channel-socket.c
> > > index 1cd5848..6ec87f8 100644
> > > --- a/io/channel-socket.c
> > > +++ b/io/channel-socket.c
> > > @@ -400,7 +400,17 @@ static void qio_channel_socket_init(Object *obj)
> > > static void qio_channel_socket_finalize(Object *obj)
> > > {
> > > QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj);
> > > +
> > > if (ioc->fd != -1) {
> > > + if (QIO_CHANNEL(ioc)->features & QIO_CHANNEL_FEATURE_LISTEN) {
> > > + Error *err = NULL;
> > > +
> > > + socket_listen_cleanup(ioc->fd, &err);
> > > + if (err) {
> > > + error_report_err(err);
> > > + err = NULL;
> > > + }
> > > + }
> > > #ifdef WIN32
> > > WSAEventSelect(ioc->fd, NULL, 0);
> > > #endif
> > > diff --git a/tests/test-io-channel-socket.c
> > > b/tests/test-io-channel-socket.c
> > > index 855306b..f73e063 100644
> > > --- a/tests/test-io-channel-socket.c
> > > +++ b/tests/test-io-channel-socket.c
> > > @@ -383,7 +383,7 @@ static void test_io_channel_unix(bool async)
> > >
> > > qapi_free_SocketAddress(listen_addr);
> > > qapi_free_SocketAddress(connect_addr);
> > > - unlink(TEST_SOCKET);
> > > + g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) == FALSE);
> > > }
> > >
> > >
> > > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> > > index 0d6cd1f..5d03695 100644
> > > --- a/util/qemu-sockets.c
> > > +++ b/util/qemu-sockets.c
> > > @@ -997,6 +997,24 @@ int socket_listen(SocketAddress *addr, Error **errp)
> > > return fd;
> > > }
> > >
> > > +void socket_listen_cleanup(int fd, Error **errp)
> > > +{
> > > + SocketAddress *addr;
> > > +
> > > + addr = socket_local_address(fd, errp);
> > > +
> > > + if (addr->type == SOCKET_ADDRESS_KIND_UNIX
> > > + && addr->u.q_unix.data->path) {
> > > + if (unlink(addr->u.q_unix.data->path) < 0 && errno != ENOENT) {
> > > + error_setg_errno(errp, errno,
> > > + "Failed to unlink socket %s",
> > > + addr->u.q_unix.data->path);
> > > + }
> > > + }
> > > +
> > > + g_free(addr);
> > > +}
> > > +
> > > int socket_dgram(SocketAddress *remote, SocketAddress *local, Error
> > > **errp)
> > > {
> > > int fd;
> > > --
> > > 2.7.4
> > >
>
next prev parent reply other threads:[~2016-06-23 9:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 19:28 [Qemu-devel] [PATCH v2 0/3] chardev cleanups marcandre.lureau
2016-06-16 19:28 ` [Qemu-devel] [PATCH v2 1/3] char: clean up remaining chardevs when leaving marcandre.lureau
2016-06-23 9:34 ` Daniel P. Berrange
2016-06-29 10:53 ` Paolo Bonzini
2016-06-29 11:40 ` Marc-André Lureau
2016-06-16 19:28 ` [Qemu-devel] [PATCH v2 2/3] socket: add listen feature marcandre.lureau
2016-06-23 9:35 ` Daniel P. Berrange
2016-06-16 19:28 ` [Qemu-devel] [PATCH v2 3/3] socket: unlink unix socket on remove marcandre.lureau
2016-06-23 4:41 ` Michael S. Tsirkin
2016-06-23 4:51 ` Michael S. Tsirkin
2016-06-23 9:08 ` Marc-André Lureau [this message]
2016-06-23 17:01 ` Michael S. Tsirkin
2016-06-24 12:08 ` Marc-André Lureau
2016-06-24 12:13 ` Daniel P. Berrange
2016-06-24 22:07 ` Michael S. Tsirkin
2016-06-27 8:10 ` Daniel P. Berrange
2016-06-23 9:36 ` Daniel P. Berrange
2016-06-17 12:34 ` [Qemu-devel] [PATCH v2 0/3] chardev cleanups Paolo Bonzini
2016-06-23 9:36 ` Daniel P. Berrange
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=934708551.1342481.1466672883154.JavaMail.zimbra@redhat.com \
--to=mlureau@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--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).