From nobody Sun Apr 13 14:17:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601461645; cv=none; d=zohomail.com; s=zohoarc; b=Dt+areRNwvAwGaaogdrOUatJxzghVic8LNXE0lLanEL6HGUM5120iVgHJfsI2dt4lCKXY6d4h3zGGxHOj25LutE0LqTwmQ1c3SrCsa9I8g6nLzEnwNuQwcOjhnrSmNDhm/rK9w2oyJktGy+izr+q2xlgXVLbomMRbcc1Wzh2/VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601461645; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uVToW14prikmTBTqtQW06DlnWPzOorHLiU0ihmtRaSU=; b=RPko45JaDgT0R5Wsoyod7BbLZ5zRySuWd1C8Y1y11jvaw5d/Wlw6QditDyAdunZkuRUyjVBOm482JIunXqlDuEGrNoDTHlfw6YF6M+w2yxaQZjJQfAXQG462T6H89zAzzViIf7dY/rspkn2eHBJQqxv/VUz6en79wM4LNAw0Yp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601461645848377.392377088408; Wed, 30 Sep 2020 03:27:25 -0700 (PDT) Received: from localhost ([::1]:48884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNZKW-00042L-GK for importer@patchew.org; Wed, 30 Sep 2020 06:27:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNZ7j-0003o8-8E for qemu-devel@nongnu.org; Wed, 30 Sep 2020 06:14:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNZ7h-000652-4D for qemu-devel@nongnu.org; Wed, 30 Sep 2020 06:14:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-327-5sydBZK5OEywozdMlogq9g-1; Wed, 30 Sep 2020 06:14:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C159C109106B; Wed, 30 Sep 2020 10:14:04 +0000 (UTC) Received: from localhost (ovpn-114-33.ams2.redhat.com [10.36.114.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6487D78833; Wed, 30 Sep 2020 10:14:04 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601460848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uVToW14prikmTBTqtQW06DlnWPzOorHLiU0ihmtRaSU=; b=KjE42pTpCHZwy84xN4gnMZTldnwD/0M/XufApACyBG3Glo8RBRIELKumoBbpjmFcqbswma j25KV+ob/pgaT6kZTvSQxCsjnIh3fbB1qeCUY81HcvCbHL9FG7cohEMzV2UFVvi8NOc7nx Ah1/wFnJbEn/nLNEfuwPX0nAu0DC52I= X-MC-Unique: 5sydBZK5OEywozdMlogq9g-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 13/17] block/io: refactor save/load vmstate Date: Wed, 30 Sep 2020 11:13:01 +0100 Message-Id: <20200930101305.305302-14-stefanha@redhat.com> In-Reply-To: <20200930101305.305302-1-stefanha@redhat.com> References: <20200930101305.305302-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate(). Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Message-Id: <20200924185414.28642-8-vsementsov@virtuozzo.com> --- block/coroutines.h | 10 +++---- include/block/block.h | 6 ++-- block/io.c | 70 ++++++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 6c63a819c9..f69179f5ef 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -57,11 +57,9 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); -int generated_co_wrapper -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); +int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); +int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); =20 #endif /* BLOCK_COROUTINES_INT_H */ diff --git a/include/block/block.h b/include/block/block.h index eef4cceaf0..8b87df69a1 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -572,8 +572,10 @@ int path_has_protocol(const char *path); int path_is_absolute(const char *path); char *path_combine(const char *base_path, const char *filename); =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos); +int generated_co_wrapper +bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper +bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size); =20 diff --git a/block/io.c b/block/io.c index c3dc1db036..54f0968aee 100644 --- a/block/io.c +++ b/block/io.c @@ -2475,28 +2475,50 @@ int bdrv_is_allocated_above(BlockDriverState *top, } =20 int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { BlockDriver *drv =3D bs->drv; BlockDriverState *child_bs =3D bdrv_primary_bs(bs); int ret =3D -ENOTSUP; =20 + if (!drv) { + return -ENOMEDIUM; + } + bdrv_inc_in_flight(bs); =20 + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); + } else if (child_bs) { + ret =3D bdrv_co_readv_vmstate(child_bs, qiov, pos); + } + + bdrv_dec_in_flight(bs); + + return ret; +} + +int coroutine_fn +bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) +{ + BlockDriver *drv =3D bs->drv; + BlockDriverState *child_bs =3D bdrv_primary_bs(bs); + int ret =3D -ENOTSUP; + if (!drv) { - ret =3D -ENOMEDIUM; - } else if (drv->bdrv_load_vmstate) { - if (is_read) { - ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); - } else { - ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); - } + return -ENOMEDIUM; + } + + bdrv_inc_in_flight(bs); + + if (drv->bdrv_save_vmstate) { + ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); } else if (child_bs) { - ret =3D bdrv_co_rw_vmstate(child_bs, qiov, pos, is_read); + ret =3D bdrv_co_writev_vmstate(child_bs, qiov, pos); } =20 bdrv_dec_in_flight(bs); + return ret; } =20 @@ -2504,38 +2526,18 @@ int bdrv_save_vmstate(BlockDriverState *bs, const u= int8_t *buf, int64_t pos, int size) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + int ret =3D bdrv_writev_vmstate(bs, &qiov, pos); =20 - ret =3D bdrv_writev_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } - - return size; -} - -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos) -{ - return bdrv_rw_vmstate(bs, qiov, pos, false); + return ret < 0 ? ret : size; } =20 int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + int ret =3D bdrv_readv_vmstate(bs, &qiov, pos); =20 - ret =3D bdrv_readv_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } - - return size; -} - -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) -{ - return bdrv_rw_vmstate(bs, qiov, pos, true); + return ret < 0 ? ret : size; } =20 /**************************************************************/ --=20 2.26.2