From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224072815497.28582534724217; Wed, 31 May 2017 02:47:52 -0700 (PDT) Received: from localhost ([::1]:58152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0EH-00061E-Vj for importer@patchew.org; Wed, 31 May 2017 05:47:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AG-0002R6-Bp for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AC-0001i2-Cs for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:40 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AC-0001hr-6u; Wed, 31 May 2017 05:43:36 -0400 Received: by mail-wm0-x244.google.com with SMTP id k15so2245866wmh.3; Wed, 31 May 2017 02:43:36 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:34 -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=Znw+xYLO5rc+ZG3Mq6P5qfE4jdg3+ORn+3YgVS0UxYA=; b=Lc8xaUXhkBxOm6gQ78lZJhKd1BzAtwgqloJlzoitcFXMF7UgTQoATyKfvm3oDp7IPe mYQghaFojIjkGOQw3Yc2L65p1QzjUVybXgGdIlsmzLjpOEATBOPwDtintU0isVNLeAlm meTmMVCZwkBFnKBKnbK9XCrtA7lFZYiJXc1NkYEiUvkR9d6QVheioIiDBvzwQFCd0Ge1 N5dlv5UPoTb/KifDrtcYRdTHkIXyEbZQjWapCDxCkCsVfpd2LlJv6WfC6xTSls/5uZ77 9mifOopDntoM7lz4gexnWd9cUSTb6JC9UNBkE7yoKoAg+KDozuVqFsnCMVayL5fUQelz gsEQ== 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=Znw+xYLO5rc+ZG3Mq6P5qfE4jdg3+ORn+3YgVS0UxYA=; b=fte0i87nCDwi5Z49otjIJJrSp18spOzxyGe0HKnnwM7kg3zXsttiwAtbUCfe1Sc+Q1 8c7b3VlEceJolYw1n2V8SBBH6FgsOHb/ddWeCauBKroJP/BTKCnJZVdMryVgKikmU5xA XDACBnmH0Mwvaiuy1cA/r8H0tjUKaRyXwLclnzvBJBexOv4c4yQOZR+GycrZcSPsBn/Y +PFsgjH78IWys7khkENklHYP/Db+WHk1DnhxQnzcqd7dTddl6zmGZaD2u26TGxILcw/S D8uyycB/gsBtxgZYqKer1M1+oRQHLBtlN7PA0UsYGEqxSA0NHGVeDT9nmKNtU3ch9jhw BtAw== X-Gm-Message-State: AODbwcBrwvxFBTvXJ9I+CwMdDvgnAFuPiOmsYS2AOwSEfhRAaNiAv+au TK80IRX8CCqzXLklKQA= X-Received: by 10.28.157.74 with SMTP id g71mr4539366wme.74.1496223814961; Wed, 31 May 2017 02:43:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:20 +0200 Message-Id: <20170531094330.1808-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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::244 Subject: [Qemu-devel] [PATCH 01/11] qcow2: call CoQueue APIs under CoMutex 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1c2697732b..c9193603b9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1696,8 +1696,6 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverS= tate *bs, uint64_t offset, ret =3D 0; =20 fail: - qemu_co_mutex_unlock(&s->lock); - while (l2meta !=3D NULL) { QCowL2Meta *next; =20 @@ -1711,6 +1709,8 @@ fail: l2meta =3D next; } =20 + qemu_co_mutex_unlock(&s->lock); + qemu_iovec_destroy(&hd_qiov); qemu_vfree(cluster_data); trace_qcow2_writev_done_req(qemu_coroutine_self(), ret); --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496223922589447.11727906652527; Wed, 31 May 2017 02:45:22 -0700 (PDT) Received: from localhost ([::1]:58135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Bt-0003ee-70 for importer@patchew.org; Wed, 31 May 2017 05:45:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AG-0002R8-CQ for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AD-0001iN-OL for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:40 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AD-0001i7-Hs; Wed, 31 May 2017 05:43:37 -0400 Received: by mail-wm0-x241.google.com with SMTP id g15so2247635wmc.2; Wed, 31 May 2017 02:43:37 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:35 -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=5n6qKNQUztHr53HxMwAHPhDfB7hc8qxkqDuvecM1/v0=; b=pPZ3D61CUHFmPuF95Mu6U++jdujDoi3XyCg7Eel4Fe4ZNBySSklhKkCjwap/xVG/Yd 8T47BErgFHR7zjK2+bW7ACsfUBP54zPpXBG0Prly7J92mnntiNdsN/9P2FEmATGBTO97 D0ZYEhZZ22Ll3L/omtHJRqbdjoNiuKKEf85spVW6nbIueK2xvrKu3Zj4o+FzvDEL/kkx bDjhDjemOGNVioQke9D6Hpw1GCa/xPGaIAdWhioAeBjawCGgWmvX3a0pOcF/Nob0nkWr JSiR03BjR0FMHGVEgZ7b2SEo61nV5gT8xJW/siT0rrm2l8XRZ8hz5BFInaj/r2HyU3iQ 6ZJA== 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=5n6qKNQUztHr53HxMwAHPhDfB7hc8qxkqDuvecM1/v0=; b=sOYfjRrDGq4rAyelSo+vyKuGhmD2RSsS75Z9HrLKfheeSfIFs55+seqXpDwNWmkiPS ilCVXaLnH4CvjWcz1teUP8VY//FdVF0n+zAy3le8Z41MP02maLDtGxTrQLlObYzJEzmp jkAm4Sg7otbMB54fwsgMSlSTsNoQP6bbZGGxhQyD2lqKEpGSuI2p613FGukcPmTii0+0 64MvwLCTa2Vxab82QUdgoZglE8EFoS7HwmvF6xwPRlSM5/knL/osYHSwpibPhhQmuiBP CZ1Y19Ry14jNG2DrCJ7oYMpOG9ghNeHDz6HAQ/GKfmGtUOycww8SLsXeXx++P5WxhIwY 417A== X-Gm-Message-State: AODbwcD0QOH25gpieVHFS3bQj4E8M3FDpKZOOdwHXkaCosxGD7tM8Kzw 8dlwufSBoBa/SkeEOk4= X-Received: by 10.28.22.12 with SMTP id 12mr4529746wmw.97.1496223816194; Wed, 31 May 2017 02:43:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:21 +0200 Message-Id: <20170531094330.1808-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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 02/11] coroutine-lock: add qemu_co_rwlock_downgrade and qemu_co_rwlock_upgrade 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" These functions are more efficient in the presence of contention. qemu_co_rwlock_downgrade also guarantees not to block, which may be useful in some algorithms too. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/qemu/coroutine.h | 19 +++++++++++++++++++ util/qemu-coroutine-lock.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index a4509bd977..0ca96fe3d3 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -229,6 +229,24 @@ void qemu_co_rwlock_init(CoRwlock *lock); void qemu_co_rwlock_rdlock(CoRwlock *lock); =20 /** + * Write Locks the CoRwlock from a reader. This is a bit more efficient t= han + * @qemu_co_rwlock_unlock followed by a separate @qemu_co_rwlock_wrlock. + * However, if the lock cannot be upgraded immediately, control is transfe= rred + * to the caller of the current coroutine. Also, @qemu_co_rwlock_upgrade + * only overrides CoRwlock's fairness if there are no concurrent readers; + * another writer might run while @qemu_co_rwlock_upgrade blocks. + */ +void qemu_co_rwlock_upgrade(CoRwlock *lock); + +/** + * Downgrades a write-side critical section to a reader. Downgrading with + * @qemu_co_rwlock_downgrade never blocks, unlike @qemu_co_rwlock_unlock + * followed by @qemu_co_rwlock_rdlock. This makes it more efficient, and + * may also sometimes be necessary for correctness. + */ +void qemu_co_rwlock_downgrade(CoRwlock *lock); + +/** * Write Locks the mutex. If the lock cannot be taken immediately because * of a parallel reader, control is transferred to the caller of the curre= nt * coroutine. diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 6328eed26b..bcdcb91ee1 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -387,6 +387,21 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) qemu_co_mutex_unlock(&lock->mutex); } =20 +void qemu_co_rwlock_downgrade(CoRwlock *lock) +{ + Coroutine *self =3D qemu_coroutine_self(); + + /* lock->mutex critical section started in qemu_co_rwlock_wrlock or + * qemu_co_rwlock_upgrade. + */ + assert(lock->reader =3D=3D 0); + lock->reader++; + qemu_co_mutex_unlock(&lock->mutex); + + /* The rest of the read-side critical section is run without the mutex= . */ + self->locks_held++; +} + void qemu_co_rwlock_wrlock(CoRwlock *lock) { qemu_co_mutex_lock(&lock->mutex); @@ -401,3 +416,23 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock) * There is no need to update self->locks_held. */ } + +void qemu_co_rwlock_upgrade(CoRwlock *lock) +{ + Coroutine *self =3D qemu_coroutine_self(); + + qemu_co_mutex_lock(&lock->mutex); + assert(lock->reader > 0); + lock->reader--; + lock->pending_writer++; + while (lock->reader) { + qemu_co_queue_wait(&lock->queue, &lock->mutex); + } + lock->pending_writer--; + + /* The rest of the write-side critical section is run with + * the mutex taken, similar to qemu_co_rwlock_wrlock. Do + * not account for the lock twice in self->locks_held. + */ + self->locks_held--; +} --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224283141477.3844194685249; Wed, 31 May 2017 02:51:23 -0700 (PDT) Received: from localhost ([::1]:58171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Hh-0000B6-FW for importer@patchew.org; Wed, 31 May 2017 05:51:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AG-0002RC-D2 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AF-0001jF-Fz for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:40 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:35696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AF-0001id-6m; Wed, 31 May 2017 05:43:39 -0400 Received: by mail-wr0-x242.google.com with SMTP id g76so1057095wrd.2; Wed, 31 May 2017 02:43:39 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:37 -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=2lOKiYU5BvIY+b6jaD36UDy07F0NjLRpC9hF5PX811o=; b=lu+yETotSeRfm5t2EM3XdeWnGyuomCRzDlSj6XR0mOcDTGWMaxOw69pRj1/dh8jpG4 lO7ZJF6bXhdSiCWK5G8Mk/2o3DTRzz3wvCueJjwW4JMH5+93+Kt7wr7Og1c5bHuu6Rl0 9QmpZBDV3NZ5QWbQ7xcnVe36XTv+4u3qruIniQgCGuIQRQLS5rriXoGEhX9TjeUYZlTp W6bP3VKhmFkJSTNiB2ztosjXIia1r9YAfs3CTWG6W8tZAPWsgFiXdKCMx8/Yq5kLrJmo zsbnXblRSvWxSlo44ZKT6UHeh9oaYLDTfUeg7jJJRz1RbVcK0Jwi3SGWXskSslCo/AHy 4AuQ== 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=2lOKiYU5BvIY+b6jaD36UDy07F0NjLRpC9hF5PX811o=; b=VpQgOI/427HpOrrw2R1IippJdOl91BcQgEGwwayuofNSr7qEosnxjVjIGAuZq9g/ND hgGEme1ounJ0U3cDEXyCnFD5rRZBok411pkSUA35P1jTRbHVnsOfxT0+UTcMIBuJlAw3 z2JD0kDe3aMJUiCebxq1N5vrbpMmXd0KjWtgCvAgP9g2CHoKNfkwYSnumOVZkkRSxVEf IBrZqS1jUB6L5c7PcXwi/BIzv/fA9UI1yQensnUXCQIiC4CCjfmsqkk0EtNl5xunYK5V 5hsV10opF1GixbSvbso5ZzrKcVe3YydWbn+vIEo632V2ON7N9uWclL2zl83dbalhlVyv CJcw== X-Gm-Message-State: AODbwcB3I8NyFe49q4kxGOpkus7759UbSGXiYDPsvO3KFKNwI3j+VhKP DXmGe+7CsDrlHVZh5E4= X-Received: by 10.223.171.77 with SMTP id r13mr10168298wrc.83.1496223817950; Wed, 31 May 2017 02:43:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:22 +0200 Message-Id: <20170531094330.1808-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH 03/11] vdi: make it thread-safe 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The VirtualBox driver is using a mutex to order all allocating writes, but it is not protecting accesses to the bitmap because they implicitly happen under the AioContext mutex. Change this to use a CoRwlock explicitly. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/vdi.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index d12d9cdc79..57f1a037c8 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -172,7 +172,7 @@ typedef struct { /* VDI header (converted to host endianness). */ VdiHeader header; =20 - CoMutex write_lock; + CoRwlock bmap_lock; =20 Error *migration_blocker; } BDRVVdiState; @@ -485,7 +485,7 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, goto fail_free_bmap; } =20 - qemu_co_mutex_init(&s->write_lock); + qemu_co_rwlock_init(&s->bmap_lock); =20 return 0; =20 @@ -557,7 +557,9 @@ vdi_co_preadv(BlockDriverState *bs, uint64_t offset, ui= nt64_t bytes, n_bytes, offset); =20 /* prepare next AIO request */ + qemu_co_rwlock_rdlock(&s->bmap_lock); bmap_entry =3D le32_to_cpu(s->bmap[block_index]); + qemu_co_rwlock_unlock(&s->bmap_lock); if (!VDI_IS_ALLOCATED(bmap_entry)) { /* Block not allocated, return zeros, no need to wait. */ qemu_iovec_memset(qiov, bytes_done, 0, n_bytes); @@ -595,6 +597,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset, u= int64_t bytes, uint32_t block_index; uint32_t offset_in_block; uint32_t n_bytes; + uint64_t data_offset; uint32_t bmap_first =3D VDI_UNALLOCATED; uint32_t bmap_last =3D VDI_UNALLOCATED; uint8_t *block =3D NULL; @@ -614,10 +617,19 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset,= uint64_t bytes, n_bytes, offset); =20 /* prepare next AIO request */ + qemu_co_rwlock_rdlock(&s->bmap_lock); bmap_entry =3D le32_to_cpu(s->bmap[block_index]); if (!VDI_IS_ALLOCATED(bmap_entry)) { /* Allocate new block and write to it. */ - uint64_t data_offset; + qemu_co_rwlock_upgrade(&s->bmap_lock); + bmap_entry =3D le32_to_cpu(s->bmap[block_index]); + if (VDI_IS_ALLOCATED(bmap_entry)) { + /* A concurrent allocation did the work for us. */ + qemu_co_rwlock_downgrade(&s->bmap_lock); + goto nonallocating_write; + } + bmap_entry =3D s->header.blocks_allocated; s->bmap[block_index] =3D cpu_to_le32(bmap_entry); s->header.blocks_allocated++; @@ -635,30 +647,18 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset,= uint64_t bytes, memset(block + offset_in_block + n_bytes, 0, s->block_size - n_bytes - offset_in_block); =20 - /* Note that this coroutine does not yield anywhere from readi= ng the - * bmap entry until here, so in regards to all the coroutines = trying - * to write to this cluster, the one doing the allocation will - * always be the first to try to acquire the lock. - * Therefore, it is also the first that will actually be able = to - * acquire the lock and thus the padded cluster is written bef= ore - * the other coroutines can write to the affected area. */ - qemu_co_mutex_lock(&s->write_lock); + /* Write the new block under CoRwLock write-side protection, + * so this full-cluster write does not overlap a partial write + * of the same cluster, issued from the "else" branch. + */ ret =3D bdrv_pwrite(bs->file, data_offset, block, s->block_siz= e); - qemu_co_mutex_unlock(&s->write_lock); + qemu_co_rwlock_unlock(&s->bmap_lock); } else { - uint64_t data_offset =3D s->header.offset_data + - (uint64_t)bmap_entry * s->block_size + - offset_in_block; - qemu_co_mutex_lock(&s->write_lock); - /* This lock is only used to make sure the following write ope= ration - * is executed after the write issued by the coroutine allocat= ing - * this cluster, therefore we do not need to keep it locked. - * As stated above, the allocating coroutine will always try t= o lock - * the mutex before all the other concurrent accesses to that - * cluster, therefore at this point we can be absolutely certa= in - * that that write operation has returned (there may be other = writes - * in flight, but they do not concern this very operation). */ - qemu_co_mutex_unlock(&s->write_lock); +nonallocating_write: + data_offset =3D s->header.offset_data + + (uint64_t)bmap_entry * s->block_size + + offset_in_block; + qemu_co_rwlock_unlock(&s->bmap_lock); =20 qemu_iovec_reset(&local_qiov); qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes); --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224420480721.0533780476749; Wed, 31 May 2017 02:53:40 -0700 (PDT) Received: from localhost ([::1]:58188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Jt-0001ym-Dn for importer@patchew.org; Wed, 31 May 2017 05:53:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AH-0002SI-GD for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AG-0001k3-NR for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:41 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34754) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AG-0001jQ-HK; Wed, 31 May 2017 05:43:40 -0400 Received: by mail-wm0-x242.google.com with SMTP id d127so2256862wmf.1; Wed, 31 May 2017 02:43:40 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:38 -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=T+wmK7N/Uznc2VxhwtB68JCCGo4695Z7O886C/vuOEY=; b=ltILr/jPvwiZ+VICpZrauf7AO4yT5xj36mGbjp1e8m0W+pSW63GHzSpwcK4E5xb9Co LjAluf7As+sO0kMwy1gkhMjhRZ7i/TJojjJVyOJzarf+BlX9Lhd2SdK5hXSlKgel49bg GmLbKg/clhYN32XrG5+uNWJyqsTPtLaTX9U7k9fVGQ1GFsRf7beTJr4mwU3EBXCh+c2v CTqqZH13gjJFMWE3qMNV1rFABUwLfZA8oAA4dB77LO4cBWJ08jJGHb2NaOLwlVGbYP4y 7jBCeTigl9iD9XNccwfhik96XHfj4pb+eEMns2aY+mJDSUegbsGxKIdX/gJATUoi72qv z7qw== 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=T+wmK7N/Uznc2VxhwtB68JCCGo4695Z7O886C/vuOEY=; b=hH/vUUqZVDFHqxaVHO56W8yCdifsS+6UBwIerEOtiaYOEiwYZ8qaPSFjWIbf4KRf2B WCvcQ1Mon9R0NuIMy2QOat9B1ntoB1IC11sjCPs/HL3Xsva+uLicfNXiNKaAQTiTDAkF JRxxqDzBQgCqkzwlJgCdpoh5XpJ9K2P07AlIw64dZ09bgUrFQaibTNWB062IFWddgtRs jmtgZNAN0aUXv6w4GXTeHTe7dVaGtlCMYZijYu4gb3Izs9ozYZ8Dptdhz4sERPXRp7n5 eMOVwPDHKPjt/yVf9GrPGxVc47baxh12KXzFJFJlEFp5VgsI+jOXlJmPvQqDGbrOCVF6 PCfQ== X-Gm-Message-State: AODbwcA7eJzKqwKim6dHlNo/ZSjJ3KFK7aNU6lkiI3GIojlMwiiEGyKg EQv7FfC5lAOBFhMvn/8= X-Received: by 10.28.197.11 with SMTP id v11mr4531562wmf.84.1496223819273; Wed, 31 May 2017 02:43:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:23 +0200 Message-Id: <20170531094330.1808-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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::242 Subject: [Qemu-devel] [PATCH 04/11] vpc: make it thread-safe 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/vpc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index ecfee77149..d61754d4d5 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -496,12 +496,6 @@ static inline int64_t get_image_offset(BlockDriverStat= e *bs, uint64_t offset, return block_offset; } =20 -static inline int64_t get_sector_offset(BlockDriverState *bs, - int64_t sector_num, bool write) -{ - return get_image_offset(bs, sector_num * BDRV_SECTOR_SIZE, write); -} - /* * Writes the footer to the end of the image file. This is needed when the * file grows as it overwrites the old footer @@ -696,6 +690,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, VHDFooter *footer =3D (VHDFooter*) s->footer_buf; int64_t start, offset; bool allocated; + int64_t ret; int n; =20 if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { @@ -705,10 +700,13 @@ static int64_t coroutine_fn vpc_co_get_block_status(B= lockDriverState *bs, (sector_num << BDRV_SECTOR_BITS); } =20 - offset =3D get_sector_offset(bs, sector_num, 0); + qemu_co_mutex_lock(&s->lock); + + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, 0); start =3D offset; allocated =3D (offset !=3D -1); *pnum =3D 0; + ret =3D 0; =20 do { /* All sectors in a block are contiguous (without using the bitmap= ) */ @@ -723,15 +721,17 @@ static int64_t coroutine_fn vpc_co_get_block_status(B= lockDriverState *bs, * sectors since there is always a bitmap in between. */ if (allocated) { *file =3D bs->file->bs; - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + break; } if (nb_sectors =3D=3D 0) { break; } - offset =3D get_sector_offset(bs, sector_num, 0); + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, 0); } while (offset =3D=3D -1); =20 - return 0; + qemu_co_mutex_unlock(&s->lock); + return ret; } =20 /* --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224199933103.43632906208938; Wed, 31 May 2017 02:49:59 -0700 (PDT) Received: from localhost ([::1]:58159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0GM-0007Ze-4B for importer@patchew.org; Wed, 31 May 2017 05:49:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AI-0002Sz-9O for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AH-0001ke-N6 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:42 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:34642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AH-0001k7-H6; Wed, 31 May 2017 05:43:41 -0400 Received: by mail-wr0-x244.google.com with SMTP id 6so1063434wrb.1; Wed, 31 May 2017 02:43:41 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:39 -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=JrBZIcFaXUkqQl2sT9u/MSkjfIAKR7Gy4HtY2do2lK0=; b=SbPfz+WFq965rasgTLY+T6yMB/D9TANwSGmdxttBBckGujuV0xl6cac/fIifkSd2jb Qy6Z2GzDuZGwl5HG5bFWS22GCfullJMmF1nbdTxpusjhR3+nVjk5K4w6I+yAm/TQ7h4+ zKXEIJ6T1a+PMAZ0ynEpFysW1TYegiKTv97K6/8S2YD8fWl2YxwSzHlP+Vc/yd1FLS24 qLIlXzNTdjaxPDRty0jM4Ncpgiap6QF8yvN/w6CLiTxauIEOVsJsR+rjNhJCVJd47BpC UF2RY2uU9tbwTjqtfuoP3PypdDpm2gu5frYp7Ie+4eJUX/gCMdQomz+m2x/RyxknI/rs NDYg== 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=JrBZIcFaXUkqQl2sT9u/MSkjfIAKR7Gy4HtY2do2lK0=; b=FMSkEf1tJeGRxB4PB7/spAMOsPqg7u3z1r7dsF5R5GN3Gda9Q0Fq80VP2giUg+M+bm y3E/3+RsevgrJ9OLarJ/greda748QxXkHBs5WzVNrSGS38INi2aDKPbtLk6ZSIO2jnxg 9392+PaPnLHWM2bGyL71V8wMQBFxyIdFg+c1u4lxb4gP3ZHkbh0RMNbAI6rZejl6bjNY AlrpNw0d1K8Km+BVIuQpOWWFO78RZifDVjLryzUeHhNCOcEJTFDQslejOlIKVviA2kdT iqlAChwjs+KchNX8P7x7ZatRMXxyOZC6znhxt7wZcJlSlKaoSyWZVro1JUhr1ylbcDGv Ee9A== X-Gm-Message-State: AODbwcCwQBUsPpifSm5IxgbtTaP2Kom9OP6DXm44FDisIjjMRt77ruqh dK4gK2LhmyhdqqM1N9w= X-Received: by 10.223.151.42 with SMTP id r39mr11290907wrb.189.1496223820290; Wed, 31 May 2017 02:43:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:24 +0200 Message-Id: <20170531094330.1808-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PATCH 05/11] vvfat: make it thread-safe 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/vvfat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index 9c82371360..457b73a35c 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2983,8 +2983,14 @@ static int coroutine_fn write_target_commit(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { + int ret; + BDRVVVFATState* s =3D *((BDRVVVFATState**) bs->opaque); - return try_commit(s); + qemu_co_mutex_lock(&s->lock); + ret =3D try_commit(s); + qemu_co_mutex_unlock(&s->lock); + + return ret; } =20 static void write_target_close(BlockDriverState *bs) { --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224033450756.9139207336603; Wed, 31 May 2017 02:47:13 -0700 (PDT) Received: from localhost ([::1]:58151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Dg-0005GR-4i for importer@patchew.org; Wed, 31 May 2017 05:47:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AJ-0002Uk-Tf for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AJ-0001lZ-4v for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:43 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35699) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AI-0001kn-Ow; Wed, 31 May 2017 05:43:42 -0400 Received: by mail-wr0-x243.google.com with SMTP id g76so1057193wrd.2; Wed, 31 May 2017 02:43:42 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:40 -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=vb1KVQsMDiu62H9MfN3KCI8VtQhYNDai1n0dNk5tGvw=; b=etLlpqkfZdgb1xRUFghgwNn5v1KEQ1VeTa4OQC+eyKuo83Fchf3ms+z+g3E1rBS9Bg tmWbaJ9zlbFNTkXOHPF/AQqZEXl4sbVGaKkmuYgao8NShg4QC8MesTks3Db1S3Xu08tH fwkRGqH8fdgWJf4GREkXwczwBxmk2uWJJ1IM+cR06SGeg8H9ZFe3gfchZ60DOnqWTCRg Z9ZEY0RFAYCUF1/zxwpnlNm4SZBzbtvHdrhkNfftFLwFecHLR2qMA/3uJN5wJFEIaqaQ hlta7TUy2cH6Mhqe72UiCHSUE2bmsiF8FmSxjCGeRRh2XQMxbJDsPVK5tFPIyJne3e03 +uUg== 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=vb1KVQsMDiu62H9MfN3KCI8VtQhYNDai1n0dNk5tGvw=; b=ek+SaRSS5P/uVT0KSMJPW8TWRDUDVanaOlYejvterLtXOmVLW4KSkaX5Z5mS+lDx4Y dPQtZl001Y6vtPGR1mH1YN1xBNZrow0v+Gan+eMOthKZbcuk7odKT3p5ZAwAvJhvCvW6 TQY9VJx8e6qscmFJJQnkk75nzwUGVc6R8ENaC4olRnerbZ7g3WQulQE3PS9lIyMsalm5 zJygRPh2ZW0QgHyxDe0K7q3V7qfGYC+PWClarFASH8lSi46m4pY6qT8cqzw3vbAL9kVC W/tJncXsTN04ig4q0EM3LlmfdEOnHvtA8dzqbCI5QJkqHfXfB1NovDHCOQciop/cnljG nrFg== X-Gm-Message-State: AODbwcBZM1afa4g8TolFkhEFXyfRpc+J8PRskRR4fsQ6qIvotFFTf0fh z5Cur1ETdlW9iPMGfsY= X-Received: by 10.223.161.65 with SMTP id r1mr20193053wrr.114.1496223821385; Wed, 31 May 2017 02:43:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:25 +0200 Message-Id: <20170531094330.1808-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH 06/11] nbd: make it thread-safe 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/nbd-client.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 1e2952fdae..43e0292ac1 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -114,6 +114,10 @@ static int nbd_co_send_request(BlockDriverState *bs, int rc, ret, i; =20 qemu_co_mutex_lock(&s->send_mutex); + while (s->in_flight =3D=3D MAX_NBD_REQUESTS) { + qemu_co_queue_wait(&s->free_sema, &s->send_mutex); + } + s->in_flight++; =20 for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i] =3D=3D NULL) { @@ -176,20 +180,6 @@ static void nbd_co_receive_reply(NBDClientSession *s, } } =20 -static void nbd_coroutine_start(NBDClientSession *s, - NBDRequest *request) -{ - /* Poor man semaphore. The free_sema is locked when no other request - * can be accepted, and unlocked after receiving one reply. */ - if (s->in_flight =3D=3D MAX_NBD_REQUESTS) { - qemu_co_queue_wait(&s->free_sema, NULL); - assert(s->in_flight < MAX_NBD_REQUESTS); - } - s->in_flight++; - - /* s->recv_coroutine[i] is set as soon as we get the send_lock. */ -} - static void nbd_coroutine_end(BlockDriverState *bs, NBDRequest *request) { @@ -197,13 +187,16 @@ static void nbd_coroutine_end(BlockDriverState *bs, int i =3D HANDLE_TO_INDEX(s, request->handle); =20 s->recv_coroutine[i] =3D NULL; - s->in_flight--; - qemu_co_queue_next(&s->free_sema); =20 /* Kick the read_reply_co to get the next reply. */ if (s->read_reply_co) { aio_co_wake(s->read_reply_co); } + + qemu_co_mutex_lock(&s->send_mutex); + s->in_flight--; + qemu_co_queue_next(&s->free_sema); + qemu_co_mutex_unlock(&s->send_mutex); } =20 int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, @@ -221,7 +214,6 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -251,7 +243,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, =20 assert(bytes <=3D NBD_MAX_BUFFER_SIZE); =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, qiov); if (ret < 0) { reply.error =3D -ret; @@ -286,7 +277,6 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -311,7 +301,6 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from =3D 0; request.len =3D 0; =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; @@ -337,7 +326,6 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int count) return 0; } =20 - nbd_coroutine_start(client, &request); ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error =3D -ret; --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224160827633.7995356539582; Wed, 31 May 2017 02:49:20 -0700 (PDT) Received: from localhost ([::1]:58158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Fj-00075z-9Q for importer@patchew.org; Wed, 31 May 2017 05:49:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AL-0002W6-1L for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AJ-0001mD-WA for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:45 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AJ-0001lf-Po; Wed, 31 May 2017 05:43:43 -0400 Received: by mail-wm0-x241.google.com with SMTP id d127so2257069wmf.1; Wed, 31 May 2017 02:43:43 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:41 -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=m3Ken3+7w57u7rzo1JRocuhLxUkHyGNAPlfq2VfTqgw=; b=vXJ2aKi7tCvF7V+NEOkfnFopSL9pl19dzzAYltXBgPtlvyk2pNNm8DxU09EKVNbQE3 Y+SMznF65Hr5m8SlUKkmpioudYc6vofn4LOb0vnLtLos4ZVYpCWgGdZzJdBpUPf87j8s hujmMjNZSlkEIRTnfd785XPqPvxxGPep/40q2SISlmCQSHDMgSwXVIUH9Z9PpwN9jLhj 47aMLrp2sAzFsItk40zk7Oa3UNwxZ/jlDsFCyAx5WVaKSfu7Eqs60CymulzfRiwecmad ADy5UYecVGuW4cPG5b2X4Pn7LeuruhDQ4FDzj4f8vVKclm01frlFUYI2AgfUX0xNAkmo xy1A== 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=m3Ken3+7w57u7rzo1JRocuhLxUkHyGNAPlfq2VfTqgw=; b=BKRQLzYw77WHuPO9OAsYhHJDVLwnXgszyWcCDkxQhUhYj63G56LtmVNoM3fQyG4Y1o vNUvrNnj2pFdXCYo9PDaqvDgEMpUwNgCSlvTLWyhVUYk1C8ZOt8GkQBXNIjAfh1H1nVW D3Uzr/3ZSQ1L2cfqTX+AMTlTfY9kqIHdqMNar0T2LWyEYiNVdaQ0BvTpuVs9zoPPmNBD Kg8KFUHnXxsdH6zWG9nZX9/T3xgYRIs2DRfzPxaJ1iryit+Wd/ZtTrU2CM3lOIop24M6 rue2jZYrS2cHOkEvEBfXud7zQ2x80htbJWsB4kffHN6FBiHL8z47UyIEn3qDNxLbpBbM DJRA== X-Gm-Message-State: AODbwcC6ATy8z/+17As1ngNoC2Tn7EzHBrMIyi5gfKvkLkwG+jMN9Cva 7GKiRuJ+ybxDF5ttQhg= X-Received: by 10.28.14.205 with SMTP id 196mr4977250wmo.13.1496223822570; Wed, 31 May 2017 02:43:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:26 +0200 Message-Id: <20170531094330.1808-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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 07/11] qed: move tail of qed_aio_write_main to qed_aio_write_{cow, alloc} 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This part is never called for in-place writes, move it away to avoid the "backwards" coding style typical of callback-based code. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/qed.c | 68 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/block/qed.c b/block/qed.c index ab505faa84..83a0973cfb 100644 --- a/block/qed.c +++ b/block/qed.c @@ -981,39 +981,11 @@ static int qed_aio_write_main(QEDAIOCB *acb) BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); - int ret; =20 trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size); =20 BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); - ret =3D bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov); - if (ret < 0) { - return ret; - } - - if (acb->find_cluster_ret !=3D QED_CLUSTER_FOUND) { - if (s->bs->backing) { - /* - * Flush new data clusters before updating the L2 table - * - * This flush is necessary when a backing file is in use. A c= rash - * during an allocating write could result in empty clusters i= n the - * image. If the write only touched a subregion of the cluste= r, - * then backing image sectors have been lost in the untouched - * region. The solution is to flush after writing a new data - * cluster and before updating the L2 table. - */ - ret =3D bdrv_flush(s->bs->file->bs); - if (ret < 0) { - return ret; - } - } - ret =3D qed_aio_write_l2_update(acb, acb->cur_cluster); - if (ret < 0) { - return ret; - } - } - return 0; + return bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov); } =20 /** @@ -1048,7 +1020,29 @@ static int qed_aio_write_cow(QEDAIOCB *acb) return ret; } =20 - return qed_aio_write_main(acb); + ret =3D qed_aio_write_main(acb); + if (ret < 0) { + return ret; + } + + if (s->bs->backing) { + /* + * Flush new data clusters before updating the L2 table + * + * This flush is necessary when a backing file is in use. A crash + * during an allocating write could result in empty clusters in the + * image. If the write only touched a subregion of the cluster, + * then backing image sectors have been lost in the untouched + * region. The solution is to flush after writing a new data + * cluster and before updating the L2 table. + */ + ret =3D bdrv_flush(s->bs->file->bs); + if (ret < 0) { + return ret; + } + } + + return 0; } =20 /** @@ -1101,6 +1095,7 @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t = len) if (acb->find_cluster_ret =3D=3D QED_CLUSTER_ZERO) { return 0; } + acb->cur_cluster =3D 1; } else { acb->cur_cluster =3D qed_alloc_clusters(s, acb->cur_nclusters); } @@ -1113,15 +1108,14 @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_= t len) } } =20 - if (acb->flags & QED_AIOCB_ZERO) { - ret =3D qed_aio_write_l2_update(acb, 1); - } else { + if (!(acb->flags & QED_AIOCB_ZERO)) { ret =3D qed_aio_write_cow(acb); + if (ret < 0) { + return ret; + } } - if (ret < 0) { - return ret; - } - return 0; + + return qed_aio_write_l2_update(acb, acb->cur_cluster); } =20 /** --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224574386457.7195092976774; Wed, 31 May 2017 02:56:14 -0700 (PDT) Received: from localhost ([::1]:58212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0MN-0004Ig-Lo for importer@patchew.org; Wed, 31 May 2017 05:56:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AM-0002Xp-C4 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AL-0001oL-71 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:46 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33389) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AL-0001n1-0Y; Wed, 31 May 2017 05:43:45 -0400 Received: by mail-wm0-x244.google.com with SMTP id b84so2264092wmh.0; Wed, 31 May 2017 02:43:44 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:43 -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=2+DuydxWdK8NwVLM3O6tFEQ2TO9znVjWH3rgLfkZG3U=; b=sCMraupEZO7alVgnBoscpqiveMopClTwFrjxKRxW5U3OnkghYcRQPnFy5nsTxMSMZI ax3PbN/bFgnc53xJ0BTiDFBdlQ+pFaQ3wTU6XP+MkYMwcXvynlqGeooH1kLi1gC5kYTI 0EGqJQYpojfYk/kh4IXfaBdDS+da/t/zSAch+KBnLxRSExhPKmWjiRsZBimSF01yd8V3 x913U+TkwiZfhqHr/k5Y4ZZEILMGFk0KEZSp2UW4XIKasWT2BOCqB7u6KzVVHrBusZE/ fHfG9clpWYTCGU7JvbkjEweh8b/tijWUjANynui1o37VXrGQudGaudMkmUFRN0gmrDnl 5qrA== 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=2+DuydxWdK8NwVLM3O6tFEQ2TO9znVjWH3rgLfkZG3U=; b=ugh/xML1KmVGB4vYZ+okamNt+gCoA5A19H20uQaS0gLQtPI9+WwxfLx3UvlT9UtwXK t8m604DZn4OOpjfMrCmWn1emfN9R5Ha7A63ZlOMHYslb9g8jw95+lWyMdUGIHaSr9cuY IemIQ2pZHs5+qZ8hOWZmMK6ykTzXX13eJXRCfq5kwiMXZRXSWl+0dpSo2Fj3sSJBBFbg cSOky70cDDX2qCUb8ViyNIAy4owsT6XTYqGzZ85rudt/H1u2CI76JtuQxykDZGOHTeyy Updw6JZuAKKPDE6xbYUb7A5DRja/WIuvEOo2UmCD38T/bavWYhSPt9A9jt6n5wcPxepg K32A== X-Gm-Message-State: AODbwcDub5PQa655/h4Oi+Qc2AEYS+Aj1/Lfh/09Y9BV6eoHo4BNOKhw IrfIj6UsJ/03nhclB2Y= X-Received: by 10.28.35.8 with SMTP id j8mr4438592wmj.96.1496223823722; Wed, 31 May 2017 02:43:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:27 +0200 Message-Id: <20170531094330.1808-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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::244 Subject: [Qemu-devel] [PATCH 08/11] block: invoke .bdrv_drain callback in coroutine context and from AioContext 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will let the callback take a CoMutex in the next patch. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/io.c | 42 +++++++++++++++++++++++++++++++++--------- block/qed.c | 6 +++--- include/block/block_int.h | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/block/io.c b/block/io.c index 03c77da66f..d5d9107885 100644 --- a/block/io.c +++ b/block/io.c @@ -157,6 +157,37 @@ bool bdrv_requests_pending(BlockDriverState *bs) return false; } =20 +typedef struct { + Coroutine *co; + BlockDriverState *bs; + bool done; +} BdrvCoDrainData; + +static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) +{ + BdrvCoDrainData *data =3D opaque; + BlockDriverState *bs =3D data->bs; + + bs->drv->bdrv_co_drain(bs); + + /* Set data->done before reading bs->wakeup. */ + atomic_mb_set(&data->done, true); + bdrv_wakeup(bs); +} + +static void bdrv_drain_invoke(BlockDriverState *bs) +{ + BdrvCoDrainData data =3D { .bs =3D bs, .done =3D false }; + + if (!bs->drv || !bs->drv->bdrv_co_drain) { + return; + } + + data.co =3D qemu_coroutine_create(bdrv_drain_invoke_entry, &data); + bdrv_coroutine_enter(bs, data.co); + BDRV_POLL_WHILE(bs, !data.done); +} + static bool bdrv_drain_recurse(BlockDriverState *bs) { BdrvChild *child, *tmp; @@ -164,9 +195,8 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) =20 waited =3D BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); =20 - if (bs->drv && bs->drv->bdrv_drain) { - bs->drv->bdrv_drain(bs); - } + /* Ensure any pending metadata writes are submitted to bs->file. */ + bdrv_drain_invoke(bs); =20 QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { BlockDriverState *bs =3D child->bs; @@ -192,12 +222,6 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) return waited; } =20 -typedef struct { - Coroutine *co; - BlockDriverState *bs; - bool done; -} BdrvCoDrainData; - static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data =3D opaque; diff --git a/block/qed.c b/block/qed.c index 83a0973cfb..990210cd9c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -351,7 +351,7 @@ static void bdrv_qed_attach_aio_context(BlockDriverStat= e *bs, } } =20 -static void bdrv_qed_drain(BlockDriverState *bs) +static void coroutine_fn bdrv_qed_co_drain(BlockDriverState *bs) { BDRVQEDState *s =3D bs->opaque; =20 @@ -360,7 +360,7 @@ static void bdrv_qed_drain(BlockDriverState *bs) */ if (s->need_check_timer && timer_pending(s->need_check_timer)) { qed_cancel_need_check_timer(s); - qed_need_check_timer_cb(s); + qed_need_check_timer_entry(s); } } =20 @@ -1544,7 +1544,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_check =3D bdrv_qed_check, .bdrv_detach_aio_context =3D bdrv_qed_detach_aio_context, .bdrv_attach_aio_context =3D bdrv_qed_attach_aio_context, - .bdrv_drain =3D bdrv_qed_drain, + .bdrv_co_drain =3D bdrv_qed_co_drain, }; =20 static void bdrv_qed_init(void) diff --git a/include/block/block_int.h b/include/block/block_int.h index a150791f0f..b14340d751 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -314,7 +314,7 @@ struct BlockDriver { * Drain and stop any internal sources of requests in the driver, and * remain so until next I/O callback (e.g. bdrv_co_writev) is called. */ - void (*bdrv_drain)(BlockDriverState *bs); + void coroutine_fn (*bdrv_co_drain)(BlockDriverState *bs); =20 void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *chi= ld, Error **errp); --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224357315645.1002497330476; Wed, 31 May 2017 02:52:37 -0700 (PDT) Received: from localhost ([::1]:58176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0It-00013k-Mi for importer@patchew.org; Wed, 31 May 2017 05:52:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AR-0002dL-2D for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AN-0001qh-DK for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:51 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34823) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AN-0001pC-1Q; Wed, 31 May 2017 05:43:47 -0400 Received: by mail-wm0-x241.google.com with SMTP id g15so2248268wmc.2; Wed, 31 May 2017 02:43:46 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:44 -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=5V5iYWvvF3Xk+VjefFfmY9pL4REPLtGEPsNS+WdvFEU=; b=Hq6Z+8ylX2J6aGmzNwTpoys9rGvXlQMIcNw1Lzxcf19e7dNOgN//855qUMtrNvKinq hhRpDyMDcOhhjYZSh4po8xOWdl78UN4zVizsajhAa9CtuBtqmSRUQEf447l3HUsxrSSE Nk0XH+I7Es0cwNHDgDCclWBIccIRrkSS+/y7xtcpDhpg/Bq3HQ83PWnCdloUtOBP/Ia9 N4Xs3nN3YpvryfYpHfZmjjP5IyYP04p3BwNnBq0ElBlHV/VoxUA8wt2zIpkyXBO1qxmV 3M5NX+nrjUcBvB64s/NmF76YcVJ5TXmXouxZmp4VHpvMvpArZrEXN6kOgOpxkX+r3sYi 19ew== 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=5V5iYWvvF3Xk+VjefFfmY9pL4REPLtGEPsNS+WdvFEU=; b=sCLnlUpZQNO+tMCSux8f04nLpWw2FLTCelNzPNHRjL19UdA6Kh9rBafEjpkOrdiYeU a7V2D7Fb5XVLIezUh7lT5SdAvZAD/1gOkbSAmGUaiXzxvEgXRqOwGw3Hjb4HIqgxEecu /8wPU42f3sWlNGKK/3/sCTHohZaFocTk4qYMEQlBiILEZP48Wh4yTPlZQrdPDVatsTxB XVhxECO942WawOAJZWwrYgGQ+5SQ+5HMOh2DMQkdj3hMTs9iw2b9zgpQM3YQoWUCdXmR MJN6KoxnSoPSg8PvwU1kt6C9Q7dCcMu5BHWQgevoMaq/C1RpQpNynguJeNT9YIv3XbzS akYA== X-Gm-Message-State: AODbwcBK1+Q0axtBb8QEfyzXOJv2lLrAHQG4AB48Irh1lgd3a4vCovar jRIwGs0LjHvdGmdnFAU= X-Received: by 10.28.63.9 with SMTP id m9mr4934512wma.87.1496223825398; Wed, 31 May 2017 02:43:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:28 +0200 Message-Id: <20170531094330.1808-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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 09/11] qed: protect table cache with CoMutex 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This makes the driver thread-safe. The CoMutex is dropped temporarily while accessing the data clusters or the backing file. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/qed-cluster.c | 4 +- block/qed-l2-cache.c | 6 +++ block/qed-table.c | 24 +++++++--- block/qed.c | 131 ++++++++++++++++++++++++++++++++++-------------= ---- block/qed.h | 11 +++-- 5 files changed, 121 insertions(+), 55 deletions(-) diff --git a/block/qed-cluster.c b/block/qed-cluster.c index 88dc979d8c..fd8722e08f 100644 --- a/block/qed-cluster.c +++ b/block/qed-cluster.c @@ -85,6 +85,8 @@ static unsigned int qed_count_contiguous_clusters(BDRVQED= State *s, * * On failure QED_CLUSTER_L2 or QED_CLUSTER_L1 is returned for missing L2 = or L1 * table offset, respectively. len is number of contiguous unallocated byt= es. + * + * Called with table_lock held. */ int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, size_t *len, uint64_t *img_offset) @@ -111,7 +113,6 @@ int qed_find_cluster(BDRVQEDState *s, QEDRequest *reque= st, uint64_t pos, } =20 ret =3D qed_read_l2_table(s, request, l2_offset); - qed_acquire(s); if (ret) { goto out; } @@ -136,6 +137,5 @@ int qed_find_cluster(BDRVQEDState *s, QEDRequest *reque= st, uint64_t pos, =20 out: *img_offset =3D offset; - qed_release(s); return ret; } diff --git a/block/qed-l2-cache.c b/block/qed-l2-cache.c index 5cba794650..b548362398 100644 --- a/block/qed-l2-cache.c +++ b/block/qed-l2-cache.c @@ -101,6 +101,8 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l= 2_cache) /** * Decrease an entry's reference count and free if necessary when the refe= rence * count drops to zero. + * + * Called with table_lock held. */ void qed_unref_l2_cache_entry(CachedL2Table *entry) { @@ -122,6 +124,8 @@ void qed_unref_l2_cache_entry(CachedL2Table *entry) * * For a cached entry, this function increases the reference count and ret= urns * the entry. + * + * Called with table_lock held. */ CachedL2Table *qed_find_l2_cache_entry(L2TableCache *l2_cache, uint64_t of= fset) { @@ -150,6 +154,8 @@ CachedL2Table *qed_find_l2_cache_entry(L2TableCache *l2= _cache, uint64_t offset) * N.B. This function steals a reference to the l2_table from the caller s= o the * caller must obtain a new reference by issuing a call to * qed_find_l2_cache_entry(). + * + * Called with table_lock held. */ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_t= able) { diff --git a/block/qed-table.c b/block/qed-table.c index ebee2c50f0..eead8b0fc7 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -18,6 +18,7 @@ #include "qed.h" #include "qemu/bswap.h" =20 +/* Called either from qed_check or with table_lock held. */ static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tabl= e) { QEMUIOVector qiov; @@ -32,18 +33,22 @@ static int qed_read_table(BDRVQEDState *s, uint64_t off= set, QEDTable *table) =20 trace_qed_read_table(s, offset, table); =20 + if (qemu_in_coroutine()) { + qemu_co_mutex_unlock(&s->table_lock); + } ret =3D bdrv_preadv(s->bs->file, offset, &qiov); + if (qemu_in_coroutine()) { + qemu_co_mutex_lock(&s->table_lock); + } if (ret < 0) { goto out; } =20 /* Byteswap offsets */ - qed_acquire(s); noffsets =3D qiov.size / sizeof(uint64_t); for (i =3D 0; i < noffsets; i++) { table->offsets[i] =3D le64_to_cpu(table->offsets[i]); } - qed_release(s); =20 ret =3D 0; out: @@ -61,6 +66,8 @@ out: * @index: Index of first element * @n: Number of elements * @flush: Whether or not to sync to disk + * + * Called either from qed_check or with table_lock held. */ static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *tab= le, unsigned int index, unsigned int n, bool flush) @@ -97,16 +104,20 @@ static int qed_write_table(BDRVQEDState *s, uint64_t o= ffset, QEDTable *table, /* Adjust for offset into table */ offset +=3D start * sizeof(uint64_t); =20 + if (qemu_in_coroutine()) { + qemu_co_mutex_unlock(&s->table_lock); + } ret =3D bdrv_pwritev(s->bs->file, offset, &qiov); + if (qemu_in_coroutine()) { + qemu_co_mutex_lock(&s->table_lock); + } trace_qed_write_table_cb(s, table, flush, ret); if (ret < 0) { goto out; } =20 if (flush) { - qed_acquire(s); ret =3D bdrv_flush(s->bs); - qed_release(s); if (ret < 0) { goto out; } @@ -123,6 +134,7 @@ int qed_read_l1_table_sync(BDRVQEDState *s) return qed_read_table(s, s->header.l1_table_offset, s->l1_table); } =20 +/* Called either from qed_check or with table_lock held. */ int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n) { BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE); @@ -136,6 +148,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned i= nt index, return qed_write_l1_table(s, index, n); } =20 +/* Called either from qed_check or with table_lock held. */ int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offse= t) { int ret; @@ -154,7 +167,6 @@ int qed_read_l2_table(BDRVQEDState *s, QEDRequest *requ= est, uint64_t offset) BLKDBG_EVENT(s->bs->file, BLKDBG_L2_LOAD); ret =3D qed_read_table(s, offset, request->l2_table->table); =20 - qed_acquire(s); if (ret) { /* can't trust loaded L2 table anymore */ qed_unref_l2_cache_entry(request->l2_table); @@ -170,7 +182,6 @@ int qed_read_l2_table(BDRVQEDState *s, QEDRequest *requ= est, uint64_t offset) request->l2_table =3D qed_find_l2_cache_entry(&s->l2_cache, offset= ); assert(request->l2_table !=3D NULL); } - qed_release(s); =20 return ret; } @@ -180,6 +191,7 @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest = *request, uint64_t offset return qed_read_l2_table(s, request, offset); } =20 +/* Called either from qed_check or with table_lock held. */ int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush) { diff --git a/block/qed.c b/block/qed.c index 990210cd9c..3e93ef7873 100644 --- a/block/qed.c +++ b/block/qed.c @@ -94,6 +94,8 @@ int qed_write_header_sync(BDRVQEDState *s) * * This function only updates known header fields in-place and does not af= fect * extra data after the QED header. + * + * No new allocating reqs can start while this function runs. */ static int qed_write_header(BDRVQEDState *s) { @@ -110,6 +112,8 @@ static int qed_write_header(BDRVQEDState *s) QEMUIOVector qiov; int ret; =20 + assert(s->allocating_acb || s->allocating_write_reqs_plugged); + buf =3D qemu_blockalign(s->bs, len); iov =3D (struct iovec) { .iov_base =3D buf, @@ -220,6 +224,8 @@ static int qed_read_string(BdrvChild *file, uint64_t of= fset, size_t n, * This function only produces the offset where the new clusters should be * written. It updates BDRVQEDState but does not make any changes to the = image * file. + * + * Called with table_lock held. */ static uint64_t qed_alloc_clusters(BDRVQEDState *s, unsigned int n) { @@ -237,6 +243,8 @@ QEDTable *qed_alloc_table(BDRVQEDState *s) =20 /** * Allocate a new zeroed L2 table + * + * Called with table_lock held. */ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s) { @@ -250,19 +258,32 @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *= s) return l2_table; } =20 -static void qed_plug_allocating_write_reqs(BDRVQEDState *s) +static bool qed_plug_allocating_write_reqs(BDRVQEDState *s) { + qemu_co_mutex_lock(&s->table_lock); + + /* No reentrancy is allowed. */ assert(!s->allocating_write_reqs_plugged); + if (s->allocating_acb !=3D NULL) { + /* Another allocating write came concurrently. This cannot happen + * from bdrv_qed_co_drain, but it can happen when the timer runs. + */ + qemu_co_mutex_unlock(&s->table_lock); + return false; + } =20 s->allocating_write_reqs_plugged =3D true; + qemu_co_mutex_unlock(&s->table_lock); + return true; } =20 static void qed_unplug_allocating_write_reqs(BDRVQEDState *s) { + qemu_co_mutex_lock(&s->table_lock); assert(s->allocating_write_reqs_plugged); - s->allocating_write_reqs_plugged =3D false; - qemu_co_enter_next(&s->allocating_write_reqs); + qemu_co_queue_next(&s->allocating_write_reqs); + qemu_co_mutex_unlock(&s->table_lock); } =20 static void qed_need_check_timer_entry(void *opaque) @@ -270,17 +291,14 @@ static void qed_need_check_timer_entry(void *opaque) BDRVQEDState *s =3D opaque; int ret; =20 - /* The timer should only fire when allocating writes have drained */ - assert(!s->allocating_acb); - trace_qed_need_check_timer_cb(s); =20 - qed_acquire(s); - qed_plug_allocating_write_reqs(s); + if (!qed_plug_allocating_write_reqs(s)) { + return; + } =20 /* Ensure writes are on disk before clearing flag */ ret =3D bdrv_co_flush(s->bs->file->bs); - qed_release(s); if (ret < 0) { goto out; } @@ -302,16 +320,6 @@ static void qed_need_check_timer_cb(void *opaque) qemu_coroutine_enter(co); } =20 -void qed_acquire(BDRVQEDState *s) -{ - aio_context_acquire(bdrv_get_aio_context(s->bs)); -} - -void qed_release(BDRVQEDState *s) -{ - aio_context_release(bdrv_get_aio_context(s->bs)); -} - static void qed_start_need_check_timer(BDRVQEDState *s) { trace_qed_start_need_check_timer(s); @@ -373,6 +381,7 @@ static int bdrv_qed_do_open(BlockDriverState *bs, QDict= *options, int flags, int ret; =20 s->bs =3D bs; + qemu_co_mutex_init(&s->table_lock); qemu_co_queue_init(&s->allocating_write_reqs); =20 ret =3D bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); @@ -682,6 +691,7 @@ typedef struct { BlockDriverState **file; } QEDIsAllocatedCB; =20 +/* Called with table_lock held. */ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, si= ze_t len) { QEDIsAllocatedCB *cb =3D opaque; @@ -729,6 +739,7 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_statu= s(BlockDriverState *bs, uint64_t offset; int ret; =20 + qemu_co_mutex_lock(&s->table_lock); ret =3D qed_find_cluster(s, &request, cb.pos, &len, &offset); qed_is_allocated_cb(&cb, ret, offset, len); =20 @@ -736,6 +747,7 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_statu= s(BlockDriverState *bs, assert(cb.status !=3D BDRV_BLOCK_OFFSET_MASK); =20 qed_unref_l2_cache_entry(request.l2_table); + qemu_co_mutex_unlock(&s->table_lock); =20 return cb.status; } @@ -865,6 +877,8 @@ out: * * The cluster offset may be an allocated byte offset in the image file, t= he * zero cluster marker, or the unallocated cluster marker. + * + * Called with table_lock held. */ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int inde= x, unsigned int n, uint64_t cluster) @@ -879,6 +893,7 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTab= le *table, int index, } } =20 +/* Called with table_lock held. */ static void qed_aio_complete(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); @@ -902,7 +917,7 @@ static void qed_aio_complete(QEDAIOCB *acb) if (acb =3D=3D s->allocating_acb) { s->allocating_acb =3D NULL; if (!qemu_co_queue_empty(&s->allocating_write_reqs)) { - qemu_co_enter_next(&s->allocating_write_reqs); + qemu_co_queue_next(&s->allocating_write_reqs); } else if (s->header.features & QED_F_NEED_CHECK) { qed_start_need_check_timer(s); } @@ -911,6 +926,8 @@ static void qed_aio_complete(QEDAIOCB *acb) =20 /** * Update L1 table with new L2 table offset and write it out + * + * Called with table_lock held. */ static int qed_aio_write_l1_update(QEDAIOCB *acb) { @@ -939,6 +956,8 @@ static int qed_aio_write_l1_update(QEDAIOCB *acb) =20 /** * Update L2 table with new cluster offsets and write them out + * + * Called with table_lock held. */ static int qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset) { @@ -975,6 +994,8 @@ static int qed_aio_write_l2_update(QEDAIOCB *acb, uint6= 4_t offset) =20 /** * Write data to the image file + * + * Called with table_lock *not* held. */ static int qed_aio_write_main(QEDAIOCB *acb) { @@ -990,6 +1011,8 @@ static int qed_aio_write_main(QEDAIOCB *acb) =20 /** * Populate untouched regions of new data cluster + * + * Called with table_lock held. */ static int qed_aio_write_cow(QEDAIOCB *acb) { @@ -997,6 +1020,8 @@ static int qed_aio_write_cow(QEDAIOCB *acb) uint64_t start, len, offset; int ret; =20 + qemu_co_mutex_unlock(&s->table_lock); + /* Populate front untouched region of new data cluster */ start =3D qed_start_of_cluster(s, acb->cur_pos); len =3D qed_offset_into_cluster(s, acb->cur_pos); @@ -1004,7 +1029,7 @@ static int qed_aio_write_cow(QEDAIOCB *acb) trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster); ret =3D qed_copy_from_backing_file(s, start, len, acb->cur_cluster); if (ret < 0) { - return ret; + goto out; } =20 /* Populate back untouched region of new data cluster */ @@ -1017,12 +1042,12 @@ static int qed_aio_write_cow(QEDAIOCB *acb) trace_qed_aio_write_postfill(s, acb, start, len, offset); ret =3D qed_copy_from_backing_file(s, start, len, offset); if (ret < 0) { - return ret; + goto out; } =20 ret =3D qed_aio_write_main(acb); if (ret < 0) { - return ret; + goto out; } =20 if (s->bs->backing) { @@ -1037,12 +1062,11 @@ static int qed_aio_write_cow(QEDAIOCB *acb) * cluster and before updating the L2 table. */ ret =3D bdrv_flush(s->bs->file->bs); - if (ret < 0) { - return ret; - } } =20 - return 0; +out: + qemu_co_mutex_lock(&s->table_lock); + return ret; } =20 /** @@ -1065,6 +1089,8 @@ static bool qed_should_set_need_check(BDRVQEDState *s) * @len: Length in bytes * * This path is taken when writing to previously unallocated clusters. + * + * Called with table_lock held. */ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { @@ -1079,7 +1105,7 @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t = len) /* Freeze this request if another allocating write is in progress */ if (s->allocating_acb !=3D acb || s->allocating_write_reqs_plugged) { if (s->allocating_acb !=3D NULL) { - qemu_co_queue_wait(&s->allocating_write_reqs, NULL); + qemu_co_queue_wait(&s->allocating_write_reqs, &s->table_lock); assert(s->allocating_acb =3D=3D NULL); } s->allocating_acb =3D acb; @@ -1126,9 +1152,16 @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) * @len: Length in bytes * * This path is taken when writing to already allocated clusters. + * + * Called with table_lock held. */ static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t le= n) { + BDRVQEDState *s =3D acb_to_s(acb); + int r; + + qemu_co_mutex_unlock(&s->table_lock); + /* Allocate buffer for zero writes */ if (acb->flags & QED_AIOCB_ZERO) { struct iovec *iov =3D acb->qiov->iov; @@ -1136,7 +1169,8 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint6= 4_t offset, size_t len) if (!iov->iov_base) { iov->iov_base =3D qemu_try_blockalign(acb->bs, iov->iov_len); if (iov->iov_base =3D=3D NULL) { - return -ENOMEM; + r =3D -ENOMEM; + goto out; } memset(iov->iov_base, 0, iov->iov_len); } @@ -1146,8 +1180,11 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint= 64_t offset, size_t len) acb->cur_cluster =3D offset; qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); =20 - /* Do the actual write */ - return qed_aio_write_main(acb); + /* Do the actual write. */ + r =3D qed_aio_write_main(acb); +out: + qemu_co_mutex_lock(&s->table_lock); + return r; } =20 /** @@ -1158,7 +1195,7 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint6= 4_t offset, size_t len) * @offset: Cluster offset in bytes * @len: Length in bytes * - * Callback from qed_find_cluster(). + * Called with table_lock held. */ static int qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len) @@ -1191,13 +1228,16 @@ static int qed_aio_write_data(void *opaque, int ret, * @offset: Cluster offset in bytes * @len: Length in bytes * - * Callback from qed_find_cluster(). + * Called with table_lock held. */ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_= t len) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); BlockDriverState *bs =3D acb->bs; + int r; + + qemu_co_mutex_unlock(&s->table_lock); =20 /* Adjust offset into cluster */ offset +=3D qed_offset_into_cluster(s, acb->cur_pos); @@ -1206,21 +1246,22 @@ static int qed_aio_read_data(void *opaque, int ret,= uint64_t offset, size_t len) =20 qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); =20 - /* Handle zero cluster and backing file reads */ + /* Handle zero cluster and backing file reads, otherwise read + * data cluster directly. + */ if (ret =3D=3D QED_CLUSTER_ZERO) { qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size); - return 0; + r =3D 0; } else if (ret !=3D QED_CLUSTER_FOUND) { - return qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, - &acb->backing_qiov); + r =3D qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, + &acb->backing_qiov); + } else { + BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); + r =3D bdrv_preadv(bs->file, offset, &acb->cur_qiov); } =20 - BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_preadv(bs->file, offset, &acb->cur_qiov); - if (ret < 0) { - return ret; - } - return 0; + qemu_co_mutex_lock(&s->table_lock); + return r; } =20 /** @@ -1233,6 +1276,7 @@ static int qed_aio_next_io(QEDAIOCB *acb) size_t len; int ret; =20 + qemu_co_mutex_lock(&s->table_lock); while (1) { trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size= ); =20 @@ -1272,6 +1316,7 @@ static int qed_aio_next_io(QEDAIOCB *acb) =20 trace_qed_aio_complete(s, acb, ret); qed_aio_complete(acb); + qemu_co_mutex_unlock(&s->table_lock); return ret; } =20 diff --git a/block/qed.h b/block/qed.h index fb80943c2d..21a338cdd5 100644 --- a/block/qed.h +++ b/block/qed.h @@ -151,15 +151,21 @@ typedef struct QEDAIOCB { =20 typedef struct { BlockDriverState *bs; /* device */ - uint64_t file_size; /* length of image file, in bytes */ =20 + /* Written only by an allocating write or the timer handler (the latter + * while allocating reqs are plugged). + */ QEDHeader header; /* always cpu-endian */ + + /* Protected by table_lock. */ + CoMutex table_lock; QEDTable *l1_table; L2TableCache l2_cache; /* l2 table cache */ uint32_t table_nelems; uint32_t l1_shift; uint32_t l2_shift; uint32_t l2_mask; + uint64_t file_size; /* length of image file, in bytes */ =20 /* Allocating write request queue */ QEDAIOCB *allocating_acb; @@ -177,9 +183,6 @@ enum { QED_CLUSTER_L1, /* cluster missing in L1 */ }; =20 -void qed_acquire(BDRVQEDState *s); -void qed_release(BDRVQEDState *s); - /** * Header functions */ --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224692712901.2656715500765; Wed, 31 May 2017 02:58:12 -0700 (PDT) Received: from localhost ([::1]:58222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0OJ-0005vQ-Av for importer@patchew.org; Wed, 31 May 2017 05:58:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AR-0002dK-1u for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AO-0001sJ-Kh for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:51 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AO-0001qf-08; Wed, 31 May 2017 05:43:48 -0400 Received: by mail-wm0-x244.google.com with SMTP id k15so2246620wmh.3; Wed, 31 May 2017 02:43:47 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:45 -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=0BtUnoFgU6wKPipylaoZOGRXm6R+6809Er4ddxEyGQY=; b=Kb8ySZKCuYOBBRud0UW2DhB8yKjoN3xfONs2jNhaysVnigm9IoUJuJAYE+HrVkLMpq a4EbliDf1PtuX/PoHVLnaYjgY7f1uTYnFnVUesAhT369MAw8X3Mh0SjgFi9ZS7WqDSh8 xIh6h6Z/ZsEwl2qBU5jv4haJQy8Cv/tEzC6x6073vZJkOSBxemGTcHmIaimSyOWYEavk WomShzF/55/L/NP9xOork2hQfOQ81yiq0CeaVfQzS00cgWswusDw3vzpkt4BPENEM3x6 BHbJ+JDrtt7YfrLTf9fJVhWopohqnFMVUZEsmEDa3QjgPSe9qep20AOjqYnO9245vq3c 07Fg== 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=0BtUnoFgU6wKPipylaoZOGRXm6R+6809Er4ddxEyGQY=; b=lQOTKwGcXBupfB0k8FyCzSQeey2FEJfuHICwPYXBd6Syj54eqzu+82Yrehv5LP8jjt iM7PZ80uZVvpwe2gt7ja+no/TqYTUvB7trq6EYjTX0WCDvF3szUsToD6nCZaDqHVkbHL w9LR72UbMhIsPRlz2wv+3aiQtlgYifNwTqJuhiNS1/OWWA8dwkgwmQrPkpJvPGEw24mM NtxDdmB01loeKi+jEHizVObKO4CRU+6mvQ/5Ca9ilVO5+DuCdVQLa6T9aB0LWj7vwZZt 54fsS2D8Lp4EdNaARq3Eqby6y2gGKHUg12yrwGxvf3jeZTAN6Px70hS81h135TIcjaZD dt0A== X-Gm-Message-State: AODbwcBiT2NlY6XZnrMbnjFir+GZVC8KIse6oowW7DjL1M4sjyrye59/ sCHRpnimMspmvHBinLY= X-Received: by 10.28.107.7 with SMTP id g7mr4523916wmc.74.1496223826564; Wed, 31 May 2017 02:43:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:29 +0200 Message-Id: <20170531094330.1808-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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::244 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/sheepdog.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 5ebf5d9fbb..551db7cd17 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -391,6 +391,7 @@ struct BDRVSheepdogState { QLIST_HEAD(inflight_aio_head, AIOReq) inflight_aio_head; QLIST_HEAD(failed_aio_head, AIOReq) failed_aio_head; =20 + CoMutex queue_lock; CoQueue overlapping_queue; QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; }; @@ -489,7 +490,7 @@ static void wait_for_overlapping_aiocb(BDRVSheepdogStat= e *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; } } @@ -526,8 +527,10 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheep= dogState *s, return; } =20 + 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); } =20 static SocketAddress *sd_socket_address(const char *path, @@ -786,6 +789,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); @@ -795,8 +799,11 @@ static coroutine_fn void reconnect_to_sdog(void *opaqu= e) while (!QLIST_EMPTY(&s->failed_aio_head)) { aio_req =3D 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); } =20 /* @@ -888,7 +895,10 @@ static void coroutine_fn aio_read_response(void *opaqu= e) */ s->co_recv =3D NULL; =20 + 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; @@ -1308,7 +1318,9 @@ static void coroutine_fn add_aio_request(BDRVSheepdog= State *s, AIOReq *aio_req, uint64_t old_oid =3D aio_req->base_oid; bool create =3D aio_req->create; =20 + 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); =20 if (!nr_copies) { error_report("bug"); @@ -1679,6 +1691,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, bs->total_sectors =3D 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); @@ -2432,12 +2445,16 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAI= OCB *acb) =20 static void sd_aio_complete(SheepdogAIOCB *acb) { + BDRVSheepdogState *s; if (acb->aiocb_type =3D=3D AIOCB_FLUSH_CACHE) { return; } =20 + s =3D 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); } =20 static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_= num, --=20 2.13.0 From nobody Mon Apr 29 00:53:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224305554360.7751521935969; Wed, 31 May 2017 02:51:45 -0700 (PDT) Received: from localhost ([::1]:58173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0I4-0000Ti-5W for importer@patchew.org; Wed, 31 May 2017 05:51:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AR-0002dM-2B for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AP-0001sm-AH for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:51 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34825) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AP-0001sF-40; Wed, 31 May 2017 05:43:49 -0400 Received: by mail-wm0-x242.google.com with SMTP id g15so2248412wmc.2; Wed, 31 May 2017 02:43:48 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:47 -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=a+/or5faELN2YqTvtnHS0jj0l9ZdmfRx3s8XotsjETo=; b=kq/8DII0+VaQgfeYUD9NkExFtBNdC5G7NfDX2MUCfE+6TeCSMxSK5WdPqmPhQU41Tr Qz2DLUu8dl11AQkGJL46WD44q9LmHuwFgk6TvIjYpFKPfFW1X1lwmnjWxf7Iu1z4+Uzm h1p1b1buz80tVgLvnfpbX0sjEqryBAMdteAii++rFpA+Z1qZmYWPGe9qFOtjvXklbuZ2 pQMaOtzKcRJlyT4+wk/n0ampGAPZli6JaFtDqnYEJRqc9mBomuaJAVM1yDpq1joSlt+P flqGTbJemwLilCZcvrodNZbuIaRXlv+AG4oDFX0pGnzs9KdJUqvhPky3fbkVnI+7GO5i FKMg== 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=a+/or5faELN2YqTvtnHS0jj0l9ZdmfRx3s8XotsjETo=; b=Wke/GLCxSctAdHqCOEdq9J2CCtuWYASscDvSHgxtYTiJOILw0yCx9Yx4hhqCxXVrNt ZvXp7opRF5e7rhX9C3QwpiYftv91ikvpZ4OyovyxqB//DSroXBIhHiaQ7olMTbTjvafy TOzEJvPWGlvgM7FqiWmOF8R/WnMSQ9SV3hgr9cyX/6Jhp4/QiCwKl7ABS+o/uP2b7eTD SoMTykayoyrNOHtcyEqZG0hjw3jaFs0q4Wy5cpeyjaAyB4H2IV28DL9/bdrxwovv4cMC 0HZAZlaWnlGIPBGM5W2n5ceJ+IYeGlGrGdlgKSFQrdZ3miCuCs5WR839qW+3bIbsdeX1 0Eaw== X-Gm-Message-State: AODbwcAYbGrj7PX02ZMQ3KxA2/fTACXEHQ3aWjreGGVTPaCYziKo42SO g8hVWTWTbnJ0c4gk63E= X-Received: by 10.28.207.207 with SMTP id f198mr4417012wmg.85.1496223827903; Wed, 31 May 2017 02:43:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:30 +0200 Message-Id: <20170531094330.1808-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-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::242 Subject: [Qemu-devel] [PATCH 11/11] ssh: support I/O from any AioContext 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The coroutine may run in a different AioContext, causing the fd handler to busy wait. Fix this by resetting the handler in restart_coroutine, before the coroutine is restarted. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/ssh.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 11203fc5a2..b5a35824d7 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -889,13 +889,22 @@ static int ssh_has_zero_init(BlockDriverState *bs) return has_zero_init; } =20 +typedef struct BDRVSSHRestart { + BlockDriverState *bs; + Coroutine *co; +} BDRVSSHRestart; + static void restart_coroutine(void *opaque) { - Coroutine *co =3D opaque; + BDRVSSHRestart *restart =3D opaque; + BlockDriverState *bs =3D restart->bs; + BDRVSSHState *s =3D bs->opaque; + AioContext *ctx =3D bdrv_get_aio_context(bs); =20 - DPRINTF("co=3D%p", co); + DPRINTF("co=3D%p", restart->co); + aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL); =20 - aio_co_wake(co); + aio_co_wake(restart->co); } =20 /* A non-blocking call returned EAGAIN, so yield, ensuring the @@ -906,7 +915,10 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Blo= ckDriverState *bs) { int r; IOHandler *rd_handler =3D NULL, *wr_handler =3D NULL; - Coroutine *co =3D qemu_coroutine_self(); + BDRVSSHRestart restart =3D { + .bs =3D bs, + .co =3D qemu_coroutine_self() + }; =20 r =3D libssh2_session_block_directions(s->session); =20 @@ -921,11 +933,9 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Blo= ckDriverState *bs) rd_handler, wr_handler); =20 aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, - false, rd_handler, wr_handler, NULL, co); + false, rd_handler, wr_handler, NULL, &restart); qemu_coroutine_yield(); DPRINTF("s->sock=3D%d - back", s->sock); - aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false, - NULL, NULL, NULL, NULL); } =20 /* SFTP has a function `libssh2_sftp_seek64' which seeks to a position --=20 2.13.0