From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDpj9-00040Z-3p for qemu-devel@nongnu.org; Wed, 02 May 2018 07:15:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDpj5-000687-6d for qemu-devel@nongnu.org; Wed, 02 May 2018 07:15:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42982 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDpj5-00067p-0J for qemu-devel@nongnu.org; Wed, 02 May 2018 07:15:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A97154022909 for ; Wed, 2 May 2018 11:15:10 +0000 (UTC) Date: Wed, 2 May 2018 12:15:07 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20180502111506.GC2679@work-vm> References: <20180502100422.8688-1-peterx@redhat.com> <20180502100422.8688-3-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180502100422.8688-3-peterx@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 2/4] monitor: protect mon->fds with mon_lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: qemu-devel@nongnu.org, Eric Blake , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Markus Armbruster , Stefan Hajnoczi * Peter Xu (peterx@redhat.com) wrote: > mon->fds were protected by BQL. Now protect it by mon_lock so that it > can even be used in monitor iothread. > > Signed-off-by: Peter Xu > --- > monitor.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/monitor.c b/monitor.c > index 48882d28ae..9f361ec21e 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -213,7 +213,6 @@ struct Monitor { > BlockCompletionFunc *password_completion_cb; > void *password_opaque; > mon_cmd_t *cmd_table; > - QLIST_HEAD(,mon_fd_t) fds; > QTAILQ_ENTRY(Monitor) entry; > > /* > @@ -225,6 +224,7 @@ struct Monitor { > /* > * Fields that are protected by the per-monitor lock. > */ > + QLIST_HEAD(, mon_fd_t) fds; > QString *outbuf; > guint out_watch; > /* Read under either BQL or mon_lock, written with BQL+mon_lock. */ > @@ -2207,6 +2207,7 @@ void qmp_getfd(const char *fdname, Error **errp) > return; > } > > + qemu_mutex_lock(&cur_mon->mon_lock); > QLIST_FOREACH(monfd, &cur_mon->fds, next) { > if (strcmp(monfd->name, fdname) != 0) { > continue; > @@ -2214,6 +2215,7 @@ void qmp_getfd(const char *fdname, Error **errp) > > close(monfd->fd); > monfd->fd = fd; > + qemu_mutex_unlock(&cur_mon->mon_lock); Why is it safe to have a close() in a mon_lock'd region? We've got to make sure everything that happens in it is non-blocking. Dave > return; > } > > @@ -2222,12 +2224,14 @@ void qmp_getfd(const char *fdname, Error **errp) > monfd->fd = fd; > > QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next); > + qemu_mutex_unlock(&cur_mon->mon_lock); > } > > void qmp_closefd(const char *fdname, Error **errp) > { > mon_fd_t *monfd; > > + qemu_mutex_lock(&cur_mon->mon_lock); > QLIST_FOREACH(monfd, &cur_mon->fds, next) { > if (strcmp(monfd->name, fdname) != 0) { > continue; > @@ -2237,9 +2241,11 @@ void qmp_closefd(const char *fdname, Error **errp) > close(monfd->fd); > g_free(monfd->name); > g_free(monfd); > + qemu_mutex_unlock(&cur_mon->mon_lock); > return; > } > > + qemu_mutex_unlock(&cur_mon->mon_lock); > error_setg(errp, QERR_FD_NOT_FOUND, fdname); > } > > @@ -2247,6 +2253,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) > { > mon_fd_t *monfd; > > + qemu_mutex_lock(&mon->mon_lock); > QLIST_FOREACH(monfd, &mon->fds, next) { > int fd; > > @@ -2260,10 +2267,12 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) > QLIST_REMOVE(monfd, next); > g_free(monfd->name); > g_free(monfd); > + qemu_mutex_unlock(&mon->mon_lock); > > return fd; > } > > + qemu_mutex_unlock(&mon->mon_lock); > error_setg(errp, "File descriptor named '%s' has not been found", fdname); > return -1; > } > -- > 2.14.3 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK