From patchwork Thu Jun 29 13:27:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 782264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wz0sB3zSbz9s3T for ; Thu, 29 Jun 2017 23:30:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FmEkxcTz"; dkim-atps=neutral Received: from localhost ([::1]:39366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZWW-0007ZN-3o for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 09:30:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUM-0005rf-OM for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUL-0001SC-HL for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:06 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33700) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUL-0001RY-Ad; Thu, 29 Jun 2017 09:28:05 -0400 Received: by mail-wm0-x241.google.com with SMTP id j85so2590161wmj.0; Thu, 29 Jun 2017 06:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=iZp8iRBtV30v7Am8q34TPtUBhPatdWBhHE+s8lUlgAw=; b=FmEkxcTzTMAew+9qmM2VmWVZMA7AWv9SvL2XCnZ3U4foRSZc/ffFyhaHdES2siEqh9 bh0BM795k/yy1OByereyeLMTdycSqapuK5kcWgRiDiX33WbSL6NN71i15WfU4Rmr7jL5 JvF0pTB8e4UrF7iV9kRIOnu4URxLhXC7pKG3qb1oQC0KRWWjEjW5/5/E7NLn4gM3nfiW l/l8fkONajnh2o9c9gbSVXOSGHRsFTkaVzno+dmrcYl91bU91KZvMTi04tWZjtqGwWHo LvJrJS0XMb1XNflyBVqA0GM/y+fb6NG4CtkY+Uvw7uvGiv6ObFZaQGoOgYZD2yl0af5u e1sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=iZp8iRBtV30v7Am8q34TPtUBhPatdWBhHE+s8lUlgAw=; b=fyraF6fuUzHa3yuYLsNtKuB1yWYhk1SMh4+1BwapUL5y/cu4vFU4NMq+ZIhu9LGJLA DRe9pzp/6TVtZ6CqgJWtX2+tj61TU6gRIqt3X8BFaLBOHdeQqUcKR/qiciYKu7CnvSmP sVAW0VgLHKNFMTOUnXjhUhSvKjAQcoOb6Z+StKDJfhkgtNqeMe3OU++W2JPNCdTqZ66F 55tEpJj0NQTgXdxysqIQRKagYp+cyCrA3g8Zzrd1MMAYqqBrs4/6XvY+CXE/azun9ZU+ 1xC6cV3ceb9fp6JxMqV1kEbsWz7Sr/UCC7EnqdcWTJg263ytmHK+V1cd3H53Ox+8kkwC r07w== X-Gm-Message-State: AKS2vOxdZud6DWTxvGJ1QIBFXRUw/8Abke9/r2vtziaFxifYBRJw1PVq w4AmZSnXO+y22nITDwE= X-Received: by 10.28.147.202 with SMTP id v193mr1786898wmd.37.1498742884062; Thu, 29 Jun 2017 06:28:04 -0700 (PDT) Received: from localhost.localdomain (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id i22sm4087691wrb.30.2017.06.29.06.28.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:28:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:48 +0200 Message-Id: <20170629132749.997-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629132749.997-1-pbonzini@redhat.com> References: <20170629132749.997-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 10/11] sheepdog: add queue_lock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/sheepdog.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 08d7b11e9d..a6013f0f17 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -390,6 +390,7 @@ struct BDRVSheepdogState { QLIST_HEAD(inflight_aio_head, AIOReq) inflight_aio_head; QLIST_HEAD(failed_aio_head, AIOReq) failed_aio_head; + CoMutex queue_lock; CoQueue overlapping_queue; QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; }; @@ -488,7 +489,7 @@ static void wait_for_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *acb) retry: QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) { if (AIOCBOverlapping(acb, cb)) { - qemu_co_queue_wait(&s->overlapping_queue, NULL); + qemu_co_queue_wait(&s->overlapping_queue, &s->queue_lock); goto retry; } } @@ -525,8 +526,10 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, return; } + qemu_co_mutex_lock(&s->queue_lock); wait_for_overlapping_aiocb(s, acb); QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); + qemu_co_mutex_unlock(&s->queue_lock); } static SocketAddress *sd_socket_address(const char *path, @@ -785,6 +788,7 @@ static coroutine_fn void reconnect_to_sdog(void *opaque) * have to move all the inflight requests to the failed queue before * resend_aioreq() is called. */ + qemu_co_mutex_lock(&s->queue_lock); QLIST_FOREACH_SAFE(aio_req, &s->inflight_aio_head, aio_siblings, next) { QLIST_REMOVE(aio_req, aio_siblings); QLIST_INSERT_HEAD(&s->failed_aio_head, aio_req, aio_siblings); @@ -794,8 +798,11 @@ static coroutine_fn void reconnect_to_sdog(void *opaque) while (!QLIST_EMPTY(&s->failed_aio_head)) { aio_req = QLIST_FIRST(&s->failed_aio_head); QLIST_REMOVE(aio_req, aio_siblings); + qemu_co_mutex_unlock(&s->queue_lock); resend_aioreq(s, aio_req); + qemu_co_mutex_lock(&s->queue_lock); } + qemu_co_mutex_unlock(&s->queue_lock); } /* @@ -887,7 +894,10 @@ static void coroutine_fn aio_read_response(void *opaque) */ s->co_recv = NULL; + qemu_co_mutex_lock(&s->queue_lock); QLIST_REMOVE(aio_req, aio_siblings); + qemu_co_mutex_unlock(&s->queue_lock); + switch (rsp.result) { case SD_RES_SUCCESS: break; @@ -1307,7 +1317,9 @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, uint64_t old_oid = aio_req->base_oid; bool create = aio_req->create; + qemu_co_mutex_lock(&s->queue_lock); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); + qemu_co_mutex_unlock(&s->queue_lock); if (!nr_copies) { error_report("bug"); @@ -1678,6 +1690,7 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags, bs->total_sectors = s->inode.vdi_size / BDRV_SECTOR_SIZE; pstrcpy(s->name, sizeof(s->name), vdi); qemu_co_mutex_init(&s->lock); + qemu_co_mutex_init(&s->queue_lock); qemu_co_queue_init(&s->overlapping_queue); qemu_opts_del(opts); g_free(buf); @@ -2431,12 +2444,16 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) static void sd_aio_complete(SheepdogAIOCB *acb) { + BDRVSheepdogState *s; if (acb->aiocb_type == AIOCB_FLUSH_CACHE) { return; } + s = acb->s; + qemu_co_mutex_lock(&s->queue_lock); QLIST_REMOVE(acb, aiocb_siblings); - qemu_co_queue_restart_all(&acb->s->overlapping_queue); + qemu_co_queue_restart_all(&s->overlapping_queue); + qemu_co_mutex_unlock(&s->queue_lock); } static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,