From nobody Sun May 5 09:07:49 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 149874298103423.791194859196594; Thu, 29 Jun 2017 06:29:41 -0700 (PDT) Received: from localhost ([::1]:39361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZVp-0007Cv-Ee for importer@patchew.org; Thu, 29 Jun 2017 09:29:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUD-0005hv-De for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUB-0001Gw-5I for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:57 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33672) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUA-0001FZ-V4; Thu, 29 Jun 2017 09:27:55 -0400 Received: by mail-wm0-x244.google.com with SMTP id j85so2589392wmj.0; Thu, 29 Jun 2017 06:27:54 -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.27.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:53 -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=aioqgUZVb+2UsuYUR7mNXJXrmYVZqIGzeGjnXNMj1Dc=; b=pMCCsjsdUBbl1kdloOxUP2YRXXg1OAybcU1qcT8cZwhER7TH+Ij9jrSNz69e6LnKUt i2EcmGm6018fu6Dn0T+PpBPXbrINfrj2ct0vJdlMpbc9s+/L4IR8PzkF3BwJdNs40y/s QkjcKlLIWlJovjgvpGeBQiJRNqghSKeU1NYz/KdseFzXsYSIYRmb90JkeQ1d/9K2Y1Qo 0V0RuB29JzaNdBa1NMTElt5tJkmXm0BNrX4VKy9QcYvbuOJggvNl6YZuITxjfpRAK4eJ tW4UFJOo930r7n518oJLBRAEf5e0I+KnDjvfMTyKhoTHqSwEWVSsuWzlo41mwlj/GZyC MQ6w== 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=aioqgUZVb+2UsuYUR7mNXJXrmYVZqIGzeGjnXNMj1Dc=; b=Fve8pEIPdVoVde95/+AqV66nFkQ33L+WfXKTdYcP0p9KCXYRprhZ6CTXpkvYlmjDIx PctN7uE3uoyGHcS7SzM61DME5/ntzTB1Np2pUq8W/jj8CC1solGfJ30f/luO8Va4qbiO b/veHHAX306qacWTdM5r3Zmwx+r4Eqqssr8PXe+3izI15dU0UMki97B8GoozMcA4rlNK ruiNgb3dwnomKiIGihsbzA/EN1lcF0fpkoQhajJYLAhTaJrRVZ07kr20BC+I0tblsmlr 393bJUelnjCShbuONZK7px/Q3QsCRFn8jvtcX5Y09of1WmYAmIjjzK/vQf1/Nml4KVJA pz+Q== X-Gm-Message-State: AKS2vOwoQUv/5GByPH54AQ5NVn82xaVGyipx5m9IyVecZXdTfBLLNh4Z ea6ydoC3dUosVFxLWRk= X-Received: by 10.28.71.76 with SMTP id u73mr11081241wma.105.1498742873644; Thu, 29 Jun 2017 06:27:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:39 +0200 Message-Id: <20170629132749.997-2-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::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, qemu-block@nongnu.org, stefanha@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" Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/qcow2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 2f94f0326e..70d3f4a18e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1741,8 +1741,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 @@ -1756,6 +1754,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 Sun May 5 09:07:49 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 1498743137086303.9478657126414; Thu, 29 Jun 2017 06:32:17 -0700 (PDT) Received: from localhost ([::1]:39379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZYI-0001H8-Ld for importer@patchew.org; Thu, 29 Jun 2017 09:32:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUD-0005hx-FB for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUC-0001Iu-DW for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:57 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:33443) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUC-0001Hg-73; Thu, 29 Jun 2017 09:27:56 -0400 Received: by mail-wr0-x243.google.com with SMTP id x23so36841328wrb.0; Thu, 29 Jun 2017 06:27:56 -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.27.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:54 -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=KBeaj3aYqi8JMNfs0DSXKShI7jN8gQe+HkV6nGVLTvg=; b=NUd6/B6tlygiOlW0N1jHTDjxW3e0RsQ6hw/C/4yMLBCQKwVo2ox8/HZXJ+xR57RWMJ 4Y7N0+JyLyAwfKA+vvx0v6YDZmqjhXmF8ZS/WBx8vjWfqX7fUIVqBjYQwdSMv0zUl2s9 6P0fj+LenZ1O5JV0q8P7AP8FLNxbVd4wyQfReJgMnH02oEMMv6sPlTEsbfUbwmSJXLPv 2C0KjSWuvuijGag2cn/0XR9o8yugY8Yqx9e5Y7f27Lpc2AiGxGjMDqx3jcH0YNFVzafe zNWAGniKr3wU0ruHO3qpBW+0+mVoBeAxo40hKEjxW2GI3B3B5OKang8tMlm3QGyUMN+I AXcg== 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=KBeaj3aYqi8JMNfs0DSXKShI7jN8gQe+HkV6nGVLTvg=; b=oIoYIZ8ZlP4KJvyO5VbnENOtUiaKeIlVYnxF49QMZzmoAYZmdWE29ZdQTBlW9NkMwm Lcz6e69+V1g7KNV+AZoDHBZPT9cd2IZALULHQcl3KmSbbMPA6VYGUNEO298IXF8h3PRa oE74xl+Btm3yCA6GJObxdnTUug26fv/F5CnBC4fqzcP1KmoncuK7esR5rNg5qQ9LyOuK I7mfV11M+fjMAHXE6n1ECVWb7MUe/ikYFs2zaKyWVa0F6m1FoKEetVCSFtBGO69l/SE+ sbtBQ18jJsWB0QYH5QbZQBSM+DFTvVN6fIBYgNJIrjDpbdoOUPmjXleRwB/c8leaAXUv EnrA== X-Gm-Message-State: AKS2vOyaH8tcrclQwLXZBNsBsu2OpUgd3YKAxToc9oO1uuiti2yJpFMT l1TesDrPEWWUWbOOo3o= X-Received: by 10.223.170.138 with SMTP id h10mr11069040wrc.153.1498742874994; Thu, 29 Jun 2017 06:27:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:40 +0200 Message-Id: <20170629132749.997-3-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:c0c::243 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, qemu-block@nongnu.org, stefanha@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. Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 18 ++++++++++++++++++ util/qemu-coroutine-lock.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index a4509bd977..9aff9a735e 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 fairness if there are no concurrent readers, so + * 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, but + * 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 b44b5d55eb..846ff9167f 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -402,6 +402,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); @@ -416,3 +431,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 Sun May 5 09:07:49 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 1498743447115795.1297865265062; Thu, 29 Jun 2017 06:37:27 -0700 (PDT) Received: from localhost ([::1]:39409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZdK-0005rB-1q for importer@patchew.org; Thu, 29 Jun 2017 09:37:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUF-0005jO-3R for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUD-0001KP-Te for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:59 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:33444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUD-0001JV-JN; Thu, 29 Jun 2017 09:27:57 -0400 Received: by mail-wr0-x243.google.com with SMTP id x23so36841359wrb.0; Thu, 29 Jun 2017 06:27:57 -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.27.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:55 -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=IQ3sP7ulf32JJI7A5vtAWHEchGXMEn+1mxgYn0v4IcA=; b=A/Oplq56/+Az3m0NiW7Y7VtjuBLTDCHzd39oFGTOVARWgWjAn9sj9wULie8qvzlatl 5PBropw8Y0kFeCRkXzdltZcqV1qjX7lMl9/C6DtqGOggim6QHxYoX7EOWUJQ7zC6eIeC /jrkPq/R7TJUd5kXYPFBZ73rGzCao9lAxTyG1lh7u0ISuUYICrQZFmylMPKkbwYV6Zom SUeZdIi0LkmlmDJXV8iK/4pshhvsLiWDpvDag7MvQJ5zhhKJsWshi1XIUp/D0nxZmBIo BOyRFqVk7PLRUQJ8wq+IDvCM9VEQQsEF9ytbmc2Jtrj//axCEFvAzl+MlYBoMyo+mnp3 HwiQ== 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=IQ3sP7ulf32JJI7A5vtAWHEchGXMEn+1mxgYn0v4IcA=; b=Prm1wKhdqzyzbFGZpUjlnHoOiomteep49q5aZNmU95FlSeXPdem/zIE3VosbZ20eaN /NQzpU5rwG7ze1eufvX5FbqHjSe2h9hOhgYCMAslOMnxvgfOfEVqXB4zRQ99MIbO/VEE 1LJn02CRmFsNjzaHjNAqSTp7/57arZkD/vkWG2DSM+hCVAi0bReiM9ZZ2sKE8yPcYSd2 uI4XuNXofaUoSMkTfTw+xKYUQSq626uYfJ8AwEVEp7ueJtH8GcsCAglNLHoDi52n6cmI qrt73TrTVI4g9CxOeojT5PUZ5KB8XGOWKOF1y3flEIVnsIkjRaY0uZ5YBl4ersOaDAho 1E5w== X-Gm-Message-State: AKS2vOximChyWLps8lQdStQJ7OWeHXfVPBGluIzrxI13IOkplbqnXuWW cQLKP+6eyaf3vwUdnjI= X-Received: by 10.223.128.177 with SMTP id 46mr12165322wrl.150.1498742876315; Thu, 29 Jun 2017 06:27:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:41 +0200 Message-Id: <20170629132749.997-4-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:c0c::243 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, qemu-block@nongnu.org, stefanha@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. Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/vdi.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 79af47763b..080e1562e3 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 Sun May 5 09:07:49 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 1498743275409721.6125821290657; Thu, 29 Jun 2017 06:34:35 -0700 (PDT) Received: from localhost ([::1]:39393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZaX-0003kn-U9 for importer@patchew.org; Thu, 29 Jun 2017 09:34:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUF-0005jh-Et for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUE-0001LO-I5 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:27:59 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:34606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUE-0001KI-Bw; Thu, 29 Jun 2017 09:27:58 -0400 Received: by mail-wr0-x243.google.com with SMTP id k67so36687139wrc.1; Thu, 29 Jun 2017 06:27:58 -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.27.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:56 -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=2ofn5mafspPfKMfrmyUrwHUxyf4r9kXdbN4S+5It7R4=; b=fJPH7KWyefC12kj2lRdHfEgbir8O5ZSKmn+VSJ9mwpOvX+wp2T8UDfyiYDXzJmbia+ JYVTvc1dz9GciLjvK4g9/DvtrhzBYDerKHCIwijS3H+suFI8KGUcXcdQ6Ojr7gyOBl28 vdY+54BTG5jBenL1DPTpVAYUWbigaQfkV9hcCQdx7+rXjy5qQCiddsBCq4H210qGNicK lomg1hO6h+O++7Mpu0zha9DIXtkQn1U6qg+41ELTXA+Ty8zoZUWwnevciZJCcDg1pYjK zXjvVag0F9b/12fDACz1hskEqSak2zWsZ2poCK5Pu6h//ZRmQDp5SHfIStbcHIeAfyv/ hAUg== 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=2ofn5mafspPfKMfrmyUrwHUxyf4r9kXdbN4S+5It7R4=; b=El4tTQNz0AUBiQ8BcaxhxpuTfmA2MHTWimHmwXjCNBEUzW4k1Lr9fgw09nGSam6WQX mgV+RbZpGO0P25WZnfN17vUPzeMPGkH7jSQMywn9A/MbJVlejnESy/8xtuMfim7neKvp GHp4dvq5Dir0IRA1oHmioyhveLII/rViiP/T5rAnzlKZhQ/8hMB7jWBVvGnj88JfE7CU Te1evADy/ai7gfHWHvLFgrvqTm5sajdzn9T1Nt4yRunBBvCZxPmW2DrqYaKGsz3c7Z99 2jZz75D4qNu2GKiw9hRg7ZO4S6119TWm8XWw1DPRK716uApqSJqxwbteLoAwEK0jrstT LU9A== X-Gm-Message-State: AKS2vOwscj0qEnP+YBqn6JaepVR/NAiXSHE4qT+E5YAx60txlU6K/egn dbTDXgoaQSGLAv5o57M= X-Received: by 10.223.169.117 with SMTP id u108mr23388955wrc.17.1498742877219; Thu, 29 Jun 2017 06:27:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:42 +0200 Message-Id: <20170629132749.997-5-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:c0c::243 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, qemu-block@nongnu.org, stefanha@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" Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/vpc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 4240ba9d1c..0ff686540a 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 Sun May 5 09:07:49 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 1498743562343984.4810934721135; Thu, 29 Jun 2017 06:39:22 -0700 (PDT) Received: from localhost ([::1]:39415 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZfD-0007bI-Nw for importer@patchew.org; Thu, 29 Jun 2017 09:39:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUG-0005kn-Ei for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUF-0001Nr-Ir for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:00 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35281) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUF-0001Li-Cc; Thu, 29 Jun 2017 09:27:59 -0400 Received: by mail-wm0-x243.google.com with SMTP id u23so2590194wma.2; Thu, 29 Jun 2017 06:27:59 -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.27.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:57 -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=u+OSKaL5i36r5vBS7rLFWKZAMH5AxgFyL7GtzdyOBng=; b=o7hncRAcls5dNeu/1Xq3hEfG3VY0GCL7e8hXOnS3x25n33QnG+fcIED6zkjbsMjLKa JCSh5Ph9qmRNJcZre0SrLdPM0xHcgiiMGlGHF9gFlMvHMmmhcdtHHpBIf2+lEV/I6GHk Ylm/2I2ByTFDOsaLFOdecU3RcX9T8B/+JFYhn7PU2mzfj1CNgRMyhVJUECDfM03Wwxnp PI2q5amZZHWKgEcvXiX9yIrQMTmwYB+tBDruU4PuV2OgOD5kZZZu+KPtDT2PPcDHBaeu 7IczrQ94K0mOHOwEhb1jrs+grzloJQEszaSBzcNBIjmbr51lQAjUFyl7TyjnGMtt3pJw 25fQ== 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=u+OSKaL5i36r5vBS7rLFWKZAMH5AxgFyL7GtzdyOBng=; b=QbEg1N7Usm6PeTiLzwWwK3NveNeNN4GdCGQhfAwp0aAcBvyEL9LqEJneqXd3r1EWHh R0iXs9FuZ0TEeNvc1+PubVoB0GZiLNK4VEb9QQEugLEDALSZDK80XQ0zkqF8g4xVCR8X BHVadoWCJXXYgaJ9hwfTmfZ4G58RmrbO4zj5gczXaYnZh2QTwpI/Q7w5++tS2UYQDLl0 xgpzzMjXD87GdAYhIDEhe0S2OvVCn+uTuEGYiUKMXmOXyhKJ3Gg3YX9q+XO9xafxarXm 9Q7MFKGMD5olKx9Lf+3sQ8qvT2HxtRvffGrZfOE1uA+NfEarWemIg+qVQQjmSMzR2c0M UO8w== X-Gm-Message-State: AKS2vOxY5OQp4ijDpDHoQWp3d4xdLFqpgqdRdOf1Z4coL5vOxj+z91EN JdJQ2P8DwqV8MX5xEt4= X-Received: by 10.28.173.10 with SMTP id w10mr11026544wme.98.1498742878174; Thu, 29 Jun 2017 06:27:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:43 +0200 Message-Id: <20170629132749.997-6-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::243 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, qemu-block@nongnu.org, stefanha@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" Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/vvfat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index 8ab647c0c6..d2679c2ff5 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2982,8 +2982,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 Sun May 5 09:07:49 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 1498743670406981.1079642022701; Thu, 29 Jun 2017 06:41:10 -0700 (PDT) Received: from localhost ([::1]:39430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZgw-00014V-1a for importer@patchew.org; Thu, 29 Jun 2017 09:41:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUI-0005mE-3H for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUG-0001Op-SZ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:02 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:35270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUG-0001OK-Lh; Thu, 29 Jun 2017 09:28:00 -0400 Received: by mail-wr0-x242.google.com with SMTP id z45so36903914wrb.2; Thu, 29 Jun 2017 06:28:00 -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.27.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:58 -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=TkrxAMVt1BjhdWLaJpV2BUGGLTWwMpPbhtzFoaLeSkQ=; b=cDyjAxCenl6W8uXri6/gAJvyEB9ORo79pGDAeXNmYzEDpf3lZ8ytoIa53Zdb1Y6Q/K RfPTK+SrO5SeF6uzbESUpOmU9yTAoH8vZHd+Vs8oGVp1Le7A9Vx9tr2PCLYo678pHR/I gT4qYJviQ/lzLoKxalDBIK9McA63Erawr3Q2vogpCEYHK370mfyhwWKBbCq09DtemYd+ gWLTWxRoPCrdmdGeM86OFU9gc0gYFL8Le4B6/x+UzesU1TBIzcx7JCvRBFQ+EYJJyOwv 0lzeyTErFM2KAgJ6kxTD2orA7mz9tv1d0JgEWRmM3HAFmY1/SQzgJ4p/5gAtw/RLKf+/ arUA== 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=TkrxAMVt1BjhdWLaJpV2BUGGLTWwMpPbhtzFoaLeSkQ=; b=uBEhC8wm4EmAVrmghAKFRlkQVlRGRSuRWdfY6pEu7hoTkGGBNMp3DxLjkX5mzPSEnQ ghR3E0lJEjqOq5xw2xsUHhTMDS8CPDWk7k8+pFbB49kcxzx8t8eBi1rgYPBOFODi0HZX mnAW6ZhL/1agJSYOMKrtVFGWz77fVZb8X7eu3WbFZf10MQDSZt7ZzJ7stYpR5PQpU6n0 DM/iVWMYWIa/YRm0coPiQ0Hf5LsUNIK0VPi9/dfRQPNgLGbBGYxgUgI/z6f5IgToe3d5 he4xx8WkQnACP1q/erqv/2AlgfmgA3gv+H4FoRZbqLZybiVkNyoteIkqvFbSDKDhizpq 2xMw== X-Gm-Message-State: AKS2vOzhQZ2C25VvevsEQNSNVGUsZqrWyUNnon17xz1SEXNyA1KMELYA Z/zoFSLiQfFaxdOF110= X-Received: by 10.223.178.143 with SMTP id g15mr21081857wrd.144.1498742879388; Thu, 29 Jun 2017 06:27:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:44 +0200 Message-Id: <20170629132749.997-7-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:c0c::242 Subject: [Qemu-devel] [PATCH 06/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, qemu-block@nongnu.org, stefanha@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. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/qed.c | 70 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/block/qed.c b/block/qed.c index 385381a78a..d593557522 100644 --- a/block/qed.c +++ b/block/qed.c @@ -982,40 +982,12 @@ static int coroutine_fn 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_co_pwritev(s->bs->file, offset, acb->cur_qiov.size, - &acb->cur_qiov, 0); - 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_co_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_co_pwritev(s->bs->file, offset, acb->cur_qiov.size, + &acb->cur_qiov, 0); } =20 /** @@ -1050,7 +1022,29 @@ static int coroutine_fn 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_co_flush(s->bs->file->bs); + if (ret < 0) { + return ret; + } + } + + return 0; } =20 /** @@ -1103,6 +1097,7 @@ static int coroutine_fn 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); } @@ -1115,15 +1110,14 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOC= B *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 Sun May 5 09:07:49 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 149874313244293.61803889830037; Thu, 29 Jun 2017 06:32:12 -0700 (PDT) Received: from localhost ([::1]:39378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZYH-0001G6-OB for importer@patchew.org; Thu, 29 Jun 2017 09:32:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUM-0005r0-4B for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUH-0001QE-Ul for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:06 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUH-0001Ov-O8; Thu, 29 Jun 2017 09:28:01 -0400 Received: by mail-wm0-x243.google.com with SMTP id p204so2589017wmg.1; Thu, 29 Jun 2017 06:28:01 -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.27.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:59 -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=N/t4JDiKMTqgPRix3GHOJbjLov8haF6aRgl167+ui3g=; b=Eo0BwHbetSHkAsGepZQRTXmWCxFmdccQVjHvh/M5PTZzPcExXEJ9QNWseVE3qhTrtH rFXWAb8aHJomGOkaFOxD50D/80YpwNPo2+Xp3Qu0LwawcGn+5nTLW+5CfI20r37p5CTn YsVyQcQxrZjtOB9ai0yK6dhBq9mNSVd9597eTvco+7vRBy010Rq8FybVY8OOnEIgCnQM 3LQUJM5wPvbfrKRklmxQ9hA0jAg8+0riHa4BnERxl9m/K+ls8Rr+cbxlIywatCVM58Sj Cq9Oi/AKrHtubcz4sbx36pFSVeCiErzt+hSIDjkPdLBiSJvLw505gWle56p5PU5wcNJ2 3O1Q== 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=N/t4JDiKMTqgPRix3GHOJbjLov8haF6aRgl167+ui3g=; b=DNVHAVtckHGM8HmXk6szGBVbpQwjY1Neea5Ctak6xhgqC5l3Gqu/MxFFcn2EFgEaPR VyQVuM1bk0AyC8ydvaz9Nk5Y7AMbgDfJs0ZO9gVXvwRJlttOMF7V2i9+Xdvs1wtx2XBh sI47KjWfkoQhygudjuB2C8ETGXJprrPNSANe9CK4MCRLiHxiHE3o58kaZM9U7mR7Z2D0 Tn+RpvYf+1aCi/joT9J/ytqtRF5gHSgKXDZbA93jqfOPkg1/RTyG8Scp9ab3xzutvbAI HeJnGjfKo6qygzc+SxukjsEc2WIfiabK15mxGL43XvINArWIctUTdVf51tpivUMqIbqE JoKg== X-Gm-Message-State: AIVw1102qMOyWtnGxUz7bTUib+xP+Epnpr4KmbYoNPKerg1Ogp2Mnvcd C5/yQfCYJAvbvvcIUkw= X-Received: by 10.28.211.10 with SMTP id k10mr1910731wmg.117.1498742880496; Thu, 29 Jun 2017 06:28:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:45 +0200 Message-Id: <20170629132749.997-8-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::243 Subject: [Qemu-devel] [PATCH 07/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, qemu-block@nongnu.org, stefanha@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. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- 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 9bba730a7e..68f19bbe69 100644 --- a/block/io.c +++ b/block/io.c @@ -149,6 +149,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; @@ -156,9 +187,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; @@ -184,12 +214,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 d593557522..db390efdbd 100644 --- a/block/qed.c +++ b/block/qed.c @@ -350,7 +350,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 @@ -359,7 +359,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 @@ -1541,7 +1541,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 15fa602150..6d3fbbfc1e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -321,7 +321,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 Sun May 5 09:07:49 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 1498743400058952.3560149230942; Thu, 29 Jun 2017 06:36:40 -0700 (PDT) Received: from localhost ([::1]:39407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZcY-0005GX-Lx for importer@patchew.org; Thu, 29 Jun 2017 09:36:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUJ-0005oI-My for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUI-0001Qg-TP for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:03 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUI-0001QL-NF; Thu, 29 Jun 2017 09:28:02 -0400 Received: by mail-wr0-x241.google.com with SMTP id 77so36757321wrb.3; Thu, 29 Jun 2017 06:28:02 -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.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:28:00 -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=WorzgVJ1i8RCc0LnXfyXOmo1mju19lNEfKSrjv02cqs=; b=rnjV5Le+EDI8xGkavfojGl3Exa40yc9m4NUqsgcPLSZE4rT0bkJaKHxzexQ6c+ApPu oqL4Fr0zQKEYIu372QeE9LW7qsY0thrhOxzWzoxquipdXDXyi59Fen4BkpqOKE0vEiiY h3favNfIqhW3UnDn8T80E0sttlF5J2Wu35E9b+TpBKWsIRTfsSK5TU0seYwT6fxcbsQ9 FUKN6KHRHiErdLNGlRKBDNEMO0rVXSzRk+tdTpSS4gb/BtF3Ui6nm6+8szd2kfO3KurY +SpRvc+efmxCsD4x99VVI7ciYRlmk7w/PZPKrGL/XT5vIRT8fOI4VcJVvhoqnax3eCK7 GlPg== 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=WorzgVJ1i8RCc0LnXfyXOmo1mju19lNEfKSrjv02cqs=; b=Ze7rto35Cn9H5iacsJTrUHSIITY+sJFYrdZoTIVjzk/KTzs7TnSRjr++S/ezBM46eS NGniTGUemW8+j6Vp6QmmQ/bauWgC171rZrZKWNXykYyktCsFP4WPPBziidvwamJKX1ro ILsy2oXmx+mFj++N5cf9rtKhL/QP7+eNLdQ91bdggxl9PcPuqRrOA37H60iVje66r/ps eEi1KSPYmCr3IGPJ2104CcxwRnbsEIsZaKOzKoUBIZ36uzGzg6/pZL4KRjzKZFpuq+P6 4FidYhsjv87TVY9mpDbA7bq6l5T94bq8zXTcgz2lIxloQEBHTezeUBcnryk0ue4E0jL4 zlTQ== X-Gm-Message-State: AKS2vOyKc2S9xpBuoFK7FkIFVIR5TObO5zdH9JfrXIrbTdakj0tCN+gH N1Ck7DRDLdApyMXDbWI= X-Received: by 10.223.153.114 with SMTP id x105mr24967664wrb.18.1498742881384; Thu, 29 Jun 2017 06:28:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:46 +0200 Message-Id: <20170629132749.997-9-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:c0c::241 Subject: [Qemu-devel] [PATCH 08/11] qed: introduce bdrv_qed_init_state 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+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 be used in the next patch, which will call bdrv_qed_do_open with a CoMutex taken. bdrv_qed_init_state provides a nice place to initialize it. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- RFC->v2: new block/qed.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/block/qed.c b/block/qed.c index db390efdbd..8228a50f68 100644 --- a/block/qed.c +++ b/block/qed.c @@ -363,6 +363,15 @@ static void coroutine_fn bdrv_qed_co_drain(BlockDriver= State *bs) } } =20 +static void bdrv_qed_init_state(BlockDriverState *bs) +{ + BDRVQEDState *s =3D bs->opaque; + + memset(s, 0, sizeof(BDRVQEDState)); + s->bs =3D bs; + qemu_co_queue_init(&s->allocating_write_reqs); +} + static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flag= s, Error **errp) { @@ -371,9 +380,6 @@ static int bdrv_qed_do_open(BlockDriverState *bs, QDict= *options, int flags, int64_t file_size; int ret; =20 - s->bs =3D bs; - qemu_co_queue_init(&s->allocating_write_reqs); - ret =3D bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); if (ret < 0) { return ret; @@ -507,6 +513,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *o= ptions, int flags, return -EINVAL; } =20 + bdrv_qed_init_state(bs); return bdrv_qed_do_open(bs, options, flags, errp); } =20 @@ -1461,7 +1468,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverStat= e *bs, Error **errp) =20 bdrv_qed_close(bs); =20 - memset(s, 0, sizeof(BDRVQEDState)); + bdrv_qed_init_state(bs); ret =3D bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); if (local_err) { error_propagate(errp, local_err); --=20 2.13.0 From nobody Sun May 5 09:07:49 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 14987435196391013.0733840820483; Thu, 29 Jun 2017 06:38:39 -0700 (PDT) Received: from localhost ([::1]:39413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZeW-0006rD-QQ for importer@patchew.org; Thu, 29 Jun 2017 09:38:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUQ-0005x8-Rr for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUL-0001Rw-AK for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:10 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36706) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUK-0001RQ-Vc; Thu, 29 Jun 2017 09:28:05 -0400 Received: by mail-wm0-x242.google.com with SMTP id y5so2579208wmh.3; 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.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:28:02 -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=Cogfn2xgfJc1cS/EklL4IvoZhAk5aK7KdhG9CUQvOs8=; b=FU31hHUKTyucNcdDWM4/1aSrn/D6vuCD2tlAc9yoWSD5wm2nbbNBjgDUG5iocuyxH8 KezTRAOSqD5+WLe+kbJA2szSGSafb2toUMUOu0+7FyUv+8Hd2uJ1uPd1p+12UwJpGfrX g0Fenve6UF3PGgnU29/AJsoP7WwFDDOZB/bruSP1bifM3MINHbbkMjhHmj4nMXeqyWo4 oLOjrHrg9wK0UlYq0RsPdssgFG3BzyyC1gBCa6WJQYtA/ebCP3jPqi8uRqUNrO1kvo4i 8g4xMF1iilU7HjaBRd0UKdHACSkBgHCiymYWUF0K7IaL0CkWaO2u4b+PDzQOGcUuWhv9 p0mw== 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=Cogfn2xgfJc1cS/EklL4IvoZhAk5aK7KdhG9CUQvOs8=; b=gpa+8KNRlm58dXmLwVLnwtikY3T3+Kwt9VhsQVzsR4Gn1GSOkpKZJs9e0m2pUKiP2H 2jb/ww7y5KEeHEdEAKYoBdWwil6+xOmvasEaA3DFhgvvSKKi8Yi5b/ThzijBrg7JWAhP 0QAq5NEpKHDuKENXkzPcNPb+Ow7nVS6M5RtsRQbrAJW7V1u2iXvhgrP00pVUJTMeHydX RmqfWVoZF86wknS1gLJ55/EvADVHGlnnBCyd3rNeoaO9OY0XKxJZabNL26UHZde/CbSI aDXewREwlZdnAE31s9ffEYoaSISnEKsWG3P3lRGLggTTrABopey9PxxlooOgvoQF3amO MbMA== X-Gm-Message-State: AKS2vOyXiyox2imDat2UOmmSVFEDjqSkfleHIFFX1MrmKQd05WhADK4c TxtpQlK6CRqXnL1Y/54= X-Received: by 10.28.169.5 with SMTP id s5mr2159287wme.90.1498742883185; Thu, 29 Jun 2017 06:28:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:47 +0200 Message-Id: <20170629132749.997-10-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::242 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, qemu-block@nongnu.org, stefanha@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 --- RFC->v2: add bdrv_qed_invalidate_cache change; invalidate_cache can run in a coroutine when called by block migration. block/qed-cluster.c | 4 +- block/qed-l2-cache.c | 6 +++ block/qed-table.c | 24 +++++++--- block/qed.c | 133 +++++++++++++++++++++++++++++++++++------------= ---- block/qed.h | 11 +++-- 5 files changed, 124 insertions(+), 54 deletions(-) diff --git a/block/qed-cluster.c b/block/qed-cluster.c index d8d6e66a0f..672e2e654b 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 coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, size_t *len, @@ -112,7 +114,6 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, } =20 ret =3D qed_read_l2_table(s, request, l2_offset); - qed_acquire(s); if (ret) { goto out; } @@ -137,6 +138,5 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, =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 8228a50f68..afad14fc01 100644 --- a/block/qed.c +++ b/block/qed.c @@ -93,6 +93,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 coroutine_fn qed_write_header(BDRVQEDState *s) { @@ -109,6 +111,8 @@ static int coroutine_fn 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, @@ -219,6 +223,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) { @@ -236,6 +242,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) { @@ -249,19 +257,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 coroutine_fn qed_need_check_timer_entry(void *opaque) @@ -269,17 +290,14 @@ static void coroutine_fn qed_need_check_timer_entry(v= oid *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) { qed_unplug_allocating_write_reqs(s); return; @@ -301,16 +319,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); @@ -369,6 +377,7 @@ static void bdrv_qed_init_state(BlockDriverState *bs) =20 memset(s, 0, sizeof(BDRVQEDState)); s->bs =3D bs; + qemu_co_mutex_init(&s->table_lock); qemu_co_queue_init(&s->allocating_write_reqs); } =20 @@ -688,6 +697,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; @@ -735,6 +745,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 @@ -742,6 +753,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; } @@ -872,6 +884,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 coroutine_fn qed_update_l2_table(BDRVQEDState *s, QEDTable *ta= ble, int index, unsigned int n, @@ -887,6 +901,7 @@ static void coroutine_fn qed_update_l2_table(BDRVQEDSta= te *s, QEDTable *table, } } =20 +/* Called with table_lock held. */ static void coroutine_fn qed_aio_complete(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); @@ -910,7 +925,7 @@ static void coroutine_fn 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); } @@ -919,6 +934,8 @@ static void coroutine_fn 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 coroutine_fn qed_aio_write_l1_update(QEDAIOCB *acb) { @@ -947,6 +964,8 @@ static int coroutine_fn qed_aio_write_l1_update(QEDAIOC= B *acb) =20 /** * Update L2 table with new cluster offsets and write them out + * + * Called with table_lock held. */ static int coroutine_fn qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t of= fset) { @@ -983,6 +1002,8 @@ static int coroutine_fn qed_aio_write_l2_update(QEDAIO= CB *acb, uint64_t offset) =20 /** * Write data to the image file + * + * Called with table_lock *not* held. */ static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb) { @@ -999,6 +1020,8 @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *a= cb) =20 /** * Populate untouched regions of new data cluster + * + * Called with table_lock held. */ static int coroutine_fn qed_aio_write_cow(QEDAIOCB *acb) { @@ -1006,6 +1029,8 @@ static int coroutine_fn qed_aio_write_cow(QEDAIOCB *a= cb) 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); @@ -1013,7 +1038,7 @@ static int coroutine_fn qed_aio_write_cow(QEDAIOCB *a= cb) 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 */ @@ -1026,12 +1051,12 @@ static int coroutine_fn 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) { @@ -1046,12 +1071,11 @@ static int coroutine_fn qed_aio_write_cow(QEDAIOCB = *acb) * cluster and before updating the L2 table. */ ret =3D bdrv_co_flush(s->bs->file->bs); - if (ret < 0) { - return ret; - } } =20 - return 0; +out: + qemu_co_mutex_lock(&s->table_lock); + return ret; } =20 /** @@ -1074,6 +1098,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 coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { @@ -1088,7 +1114,7 @@ static int coroutine_fn 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; @@ -1135,10 +1161,17 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOC= B *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 coroutine_fn qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offs= et, size_t len) { + 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; @@ -1146,7 +1179,8 @@ static int coroutine_fn qed_aio_write_inplace(QEDAIOC= B *acb, uint64_t offset, 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); } @@ -1156,8 +1190,11 @@ static int coroutine_fn qed_aio_write_inplace(QEDAIO= CB *acb, uint64_t offset, 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 /** @@ -1167,6 +1204,8 @@ static int coroutine_fn qed_aio_write_inplace(QEDAIOC= B *acb, uint64_t offset, * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1 * @offset: Cluster offset in bytes * @len: Length in bytes + * + * Called with table_lock held. */ static int coroutine_fn qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len) @@ -1198,6 +1237,8 @@ static int coroutine_fn qed_aio_write_data(void *opaq= ue, int ret, * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1 * @offset: Cluster offset in bytes * @len: Length in bytes + * + * Called with table_lock held. */ static int coroutine_fn qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) @@ -1205,6 +1246,9 @@ static int coroutine_fn qed_aio_read_data(void *opaqu= e, int ret, 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); @@ -1213,22 +1257,23 @@ static int coroutine_fn qed_aio_read_data(void *opa= que, int ret, =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_co_preadv(bs->file, offset, acb->cur_qiov.size, + &acb->cur_qiov, 0); } =20 - BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_preadv(bs->file, offset, acb->cur_qiov.size, - &acb->cur_qiov, 0); - if (ret < 0) { - return ret; - } - return 0; + qemu_co_mutex_lock(&s->table_lock); + return r; } =20 /** @@ -1241,6 +1286,7 @@ static int coroutine_fn 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 @@ -1280,6 +1326,7 @@ static int coroutine_fn 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 @@ -1469,7 +1516,13 @@ static void bdrv_qed_invalidate_cache(BlockDriverSta= te *bs, Error **errp) bdrv_qed_close(bs); =20 bdrv_qed_init_state(bs); + if (qemu_in_coroutine()) { + qemu_co_mutex_lock(&s->table_lock); + } ret =3D bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); + if (qemu_in_coroutine()) { + qemu_co_mutex_unlock(&s->table_lock); + } if (local_err) { error_propagate(errp, local_err); error_prepend(errp, "Could not reopen qed layer: "); diff --git a/block/qed.h b/block/qed.h index dd3a2d5519..f35341f134 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 Sun May 5 09:07:50 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 1498743086427459.3804856759058; Thu, 29 Jun 2017 06:31:26 -0700 (PDT) Received: from localhost ([::1]:39376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZXX-0000gg-VF for importer@patchew.org; Thu, 29 Jun 2017 09:31:24 -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) 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) 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) 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+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" 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; =20 + 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(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; } } @@ -525,8 +526,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, @@ -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 *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 /* @@ -887,7 +894,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; @@ -1307,7 +1317,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"); @@ -1678,6 +1690,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); @@ -2431,12 +2444,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 Sun May 5 09:07:50 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 1498743765830634.1830910877254; Thu, 29 Jun 2017 06:42:45 -0700 (PDT) Received: from localhost ([::1]:39438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZiT-00025a-Ad for importer@patchew.org; Thu, 29 Jun 2017 09:42:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUQ-0005xA-SO for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUM-0001Tc-Nc for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:10 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUM-0001T1-Fh; Thu, 29 Jun 2017 09:28:06 -0400 Received: by mail-wm0-x241.google.com with SMTP id u23so2590731wma.2; Thu, 29 Jun 2017 06:28:06 -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.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:28:04 -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=OxJ4SUtUOhPcvEiqes/sd5XvBopHOTVBC/35a9AXaxY=; b=LSKwDg2/HhDf9Do1AgkNX3WYFmx/o1TsXuqYwRHGs8iOqSWwC97FeXt+LB3T63b+GI 7WAWod7Orm6AbkeZHPj/cMYgZC8/0zCTCoI85xcDOLch3K9pNosiU1LLbUttgmxtiHcM OtKaedHPU4vEOTkhd2bMaXbWtKiXPShLSx9TeEyrZ85QOGb7tUC3lb5Jk+lpaQJ+KfnM E+9unoH2LUAaStzM52d+JI40q8j3xXJ7R4RtznAj4ca7UJYdkk3/F7mPUisigTmK+w5Q 0QuYM1tB3XXWYu6orBpysDKUrP7mOWVLobBCPqih2tAs0svXZ3iFYbVYO4jhqje+2PsK I9OA== 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=OxJ4SUtUOhPcvEiqes/sd5XvBopHOTVBC/35a9AXaxY=; b=Cb499+sZqQQVHFiOni7naNtTdX24ZTDiSNopxefbgnRrZ8qyq+2MZlAy0Y2/B5+kh1 5tu327Kx5GHIa+U+KKvsYIpjtwFdMRde2GLvvor3Sd3piYEPzzjizpQ8FdMfd7HSla4x m4ceN7QpurC/a+LvWYuiSis9wvmtQKChpXyqEs39Hsgi7/OSjnENJMxcp0OUNHIgx33C Ah4fU4e83JjzKWEup6NNlR3COYw5B4Yn6sjqAF2STSkHDpsbuFAclEe8Ipozxk0CMmBi 7ZxDZhiJUhuNlE84zj0dBtcifTxd4Bf3Yx67kvCX+oFiMx+Xg+HgqCz8SiNlSt29AQM2 +adQ== X-Gm-Message-State: AIVw112KF2A45fRvIa1jxlZw9aOQzoyJ1GhisIvZtsBftZx24qbH6H0o OUKe2uRd0IgaUvlkk2U= X-Received: by 10.28.132.13 with SMTP id g13mr2082315wmd.58.1498742885285; Thu, 29 Jun 2017 06:28:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:49 +0200 Message-Id: <20170629132749.997-12-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 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, qemu-block@nongnu.org, stefanha@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. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/ssh.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 52964416da..e6a5b08de3 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -888,13 +888,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 @@ -905,7 +914,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 @@ -920,11 +932,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