From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376430; cv=none; d=zohomail.com; s=zohoarc; b=aeLaOwYdVqDl20e6iUj7mlFhY2eMS8eTQJvxX1GStXK5xsgOj9e5uDDmgAx1Tf2h14tsUlfoHKnJ7ROsF0eVo8wNj56W953kM0Rn8SgxQ3l/PvUR/6QRVy40XneE/3J+53/1IbV1LhkBhs6xNEnUDvPi2ZxYCgCUd60c/D10tqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376430; h=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=7tNdbLBzRKOlUlgc8g7K1sMB89Nl+L+jwQpxvFRcsBc=; b=S1IfSXbPXKX2JggYnikrpAnU6qjk9Vbacu1gOHjYgWl1Us3PT0h80hXv8Vky4wkgBuzyU81D1+Pl5UYZg9062xSCQoMpilqEo19iKhzNHFbDLQIupFfPGsPzNDZ51vKEoPTuYtub5PCLdTBa48F8jww/wKtULUL4/U2Vn4h3SZo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376430324222.8180629121092; Thu, 16 Jun 2022 03:47:10 -0700 (PDT) Received: from localhost ([::1]:54436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n1p-0006OO-5e for importer@patchew.org; Thu, 16 Jun 2022 06:47:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjc-0001Yj-EK for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:20 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]:36538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mja-0001sk-FC for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:20 -0400 Received: by mail-lj1-x234.google.com with SMTP id h23so1010679ljl.3 for ; Thu, 16 Jun 2022 03:28:17 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7tNdbLBzRKOlUlgc8g7K1sMB89Nl+L+jwQpxvFRcsBc=; b=SpgcQLwaX0AeEce1nwBSNmHN6UxPq7YrDQ+TaQYXr3NEnbh99yFQrapylvjw+BRW7i R9bO9C16d7OOuAXRPFDuGaz4KSovSEy+mgXt3s15+plzG5sjr3idnVKbtWCc3pDtN1Xl VNre9/VAA9Md7V1crfktBaUNGck0qcSPtzZWQm6OXshib1ETrLcEhPXjXHIF92aFZN+0 WPfsY9RDUKkUJlHDd26F1ms5NCQh69y9DxtLN+hd9xP0duw8QJB3X0RJ+lRnOhK2rN1A K/4XBAF5ICdSAWQSp+1LONGbqLPEgqaumjH4pedA1TiyBdSfbM9EX1pAcmKkY/3bz4BY 62MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7tNdbLBzRKOlUlgc8g7K1sMB89Nl+L+jwQpxvFRcsBc=; b=39TNcDN4JTizEXFjwvD4uzG86aJgX+dvekvwRnpJSFxgAa1kOy/gb/+yfoRI9AXRmF JduL581UhimRVExMo9q0wLSHMly2FC0mQFQepdzZjQt1VHR5SnSL3T3GnW1Or1bUjxw4 GuvBvmWuM4qLWvS+od1KnlwoKHRVIoB7aZz/l42moOW/MvOBayz8tzK1BQNbWY2hBRnB 1NcxTKtFZddYcu9Rht3Yn26Xb1+V5m+rRCab/QoQntELjt/HB+NKQlo8weQ5jjY5Feat 7rxDIJYHhBDftP/Wvw6h0gMOBZHr+FUZJjEFwAdB0yDTK+vd0HB0arN9VHe9+1qxelex mZqA== X-Gm-Message-State: AJIora9lylaRU9cvMZdPGmgK7JCuH7ZMFKYAnl7TH7NdmkSi+BZV+WF9 hXf/kL+KyWFlfb+ojHd69Q3lxU7ypzRE6RjO X-Google-Smtp-Source: AGRyM1sy6TKK5U/ZlxPmqodnE/huwnOmO+EuppB4lwusAdREYCHCy0ief+4dCulU/so5dkabgI5rgA== X-Received: by 2002:a05:651c:1a20:b0:25a:2f43:1d2 with SMTP id by32-20020a05651c1a2000b0025a2f4301d2mr2140996ljb.65.1655375296150; Thu, 16 Jun 2022 03:28:16 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 01/17] migration: Implemented new parameter stream_content Date: Thu, 16 Jun 2022 13:27:55 +0300 Message-Id: <20220616102811.219007-2-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::234; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x234.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376432504100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin This new optional parameter contains inormation about migration stream parts to be sent (such as RAM, block, bitmap). This looks better than using capabilities to solve problem of dividing migration stream. Signed-off-by: Nikita Lapshin --- migration/migration.c | 47 ++++++++++++++++++++++++++++++++++++++++++- migration/migration.h | 2 ++ qapi/migration.json | 21 ++++++++++++++++--- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 695f0f2900..4adcc87d1d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1334,6 +1334,12 @@ void qmp_migrate_set_capabilities(MigrationCapabilit= yStatusList *params, } } =20 +static bool check_stream_parts(strList *stream_content_list) +{ + /* To be implemented in ext commits */ + return true; +} + /* * Check whether the parameters are valid. Error will be put into errp * (if provided). Return true if valid, otherwise false. @@ -1482,7 +1488,12 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) return false; } =20 - return true; + if (params->has_stream_content_list && + !check_stream_parts(params->stream_content_list)) { + error_setg(errp, "Invalid parts of stream given for stream-content= "); + } + + return true; } =20 static void migrate_params_test_apply(MigrateSetParameters *params, @@ -1581,6 +1592,11 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, dest->has_block_bitmap_mapping =3D true; dest->block_bitmap_mapping =3D params->block_bitmap_mapping; } + + if (params->has_stream_content_list) { + dest->has_stream_content_list =3D true; + dest->stream_content_list =3D params->stream_content_list; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1703,6 +1719,13 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) QAPI_CLONE(BitmapMigrationNodeAliasList, params->block_bitmap_mapping); } + + if (params->has_stream_content_list) { + qapi_free_strList(s->parameters.stream_content_list); + s->parameters.has_stream_content_list =3D true; + s->parameters.stream_content_list =3D + QAPI_CLONE(strList, params->stream_content_list); + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) @@ -2620,6 +2643,28 @@ bool migrate_background_snapshot(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; } =20 +/* Checks if stream-content parameter has section_name in list */ +bool migrate_find_stream_content(const char *section_name) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + if (!s->parameters.has_stream_content_list) { + return false; + } + + strList *list =3D s->parameters.stream_content_list; + + for (; list; list =3D list->next) { + if (!strcmp(list->value, section_name)) { + return true; + } + } + + return false; +} + /* migration thread support */ /* * Something bad happened to the RP stream, mark an error diff --git a/migration/migration.h b/migration/migration.h index 2de861df01..411c58e919 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -396,6 +396,8 @@ bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); bool migrate_background_snapshot(void); =20 +bool migrate_find_stream_content(const char *section_name); + /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, uint32_t value); diff --git a/qapi/migration.json b/qapi/migration.json index 18e2610e88..80acf6dbc3 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -760,6 +760,12 @@ # block device name if there is one, and to their n= ode name # otherwise. (Since 5.2) # +# @stream-content-list: Parameter control content of migration stream such= as RAM, +# vmstate, block and dirty-bitmaps. This is optional= parameter +# so migration will work correctly without it. +# This parameter takes string list as description of= content +# and include that part of migration stream. (Since = 7.0) +# # Features: # @unstable: Member @x-checkpoint-delay is experimental. # @@ -780,7 +786,8 @@ 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-compression', 'multifd-zlib-level' ,'multifd-zstd-level', - 'block-bitmap-mapping' ] } + 'block-bitmap-mapping', + 'stream-content-list' ] } =20 ## # @MigrateSetParameters: @@ -925,6 +932,12 @@ # block device name if there is one, and to their n= ode name # otherwise. (Since 5.2) # +# @stream-content-list: Parameter control content of migration stream such= as RAM, +# vmstate, block and dirty-bitmaps. This is optional= parameter +# so migration will work correctly without it. +# This parameter takes string list as description of= content +# and include that part of migration stream. (Since = 7.0) +# # Features: # @unstable: Member @x-checkpoint-delay is experimental. # @@ -960,7 +973,8 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], + '*stream-content-list': [ 'str' ] } } =20 ## # @migrate-set-parameters: @@ -1158,7 +1172,8 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], + '*stream-content-list': [ 'str' ] } } =20 ## # @query-migrate-parameters: --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376494; cv=none; d=zohomail.com; s=zohoarc; b=kBwFONaP9m1EEMKGMP6n/nDN57BjOT1XenbwCnejUKrfBhDFKbhFLM6HawjQ7tgCvX1m+i6uuLO245SX7cXxP9Vgy2JhHohPtt6e3yH6V61JK9zI+Y7QKPrbLmUiObsZSdXEGPN0baXizvOakJY4J2rCTbI6HIwcQ7dE8iccyrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376494; h=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=7IlllWalbol55jcjJ2c0idnBkF17iN1AJ6PBWM49+f8=; b=HliYlesYiyTGPFq7C43riPl8x1L1gYDsr1H6Wx1WzkoPNKGLWXT2Rg9kwr3sVv0G6T0PHp3Uv57dUqA9LQadNUzoqahx38aCI1KlJT2BpbrLm//KLgDpctheF5M/6eOrNA8uq3K09InTq48YQRR6Ewfir6rvApvvlNCOj8HOseI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376494933943.4434167168612; Thu, 16 Jun 2022 03:48:14 -0700 (PDT) Received: from localhost ([::1]:55586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n2r-0007Bq-RQ for importer@patchew.org; Thu, 16 Jun 2022 06:48:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjd-0001b6-OU for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:22 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:42589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjb-0001ss-Ld for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:21 -0400 Received: by mail-lf1-x12e.google.com with SMTP id h36so1515248lfv.9 for ; Thu, 16 Jun 2022 03:28:19 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7IlllWalbol55jcjJ2c0idnBkF17iN1AJ6PBWM49+f8=; b=yyVhZy8bklF/2igjopLiG2+6KGpqYpafIqoFN6DUnPylZZT2MkvpVjhza1qzvytPjU 8bSaI/jUJzuhgKho35egdnRTPTC09zdjwszZTYSEDg0MEC7LTZptWiZ7oOvaggtpySZr 76RR1YompvtD0wtVG2nKiBw4hDoc0lsIOS/sLZnsWPA1bpgKuiYVzszJkkLxK4ewfAc1 aXTHTv7QEtOcxtTvTTLvRfhWhJHJfzIKox17ApHK2jIwDVaWEFfrF+OOkx/tEETaAvuT vrPZ8AjvOTJBjRs9foM2X9RO9a+Dt+ViOHPtwFzgR8+A980BbdrmNOLo1gW/HNxid3xW vD2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7IlllWalbol55jcjJ2c0idnBkF17iN1AJ6PBWM49+f8=; b=Yix8aWIQ91WUmZD5oKMh5KXJIPjwhTTqtfvJsdoPU9iL+ZxuVavm0+12zVjlmeNfd2 KGKSvyznbf7LoULvtV+PM9XOOaslIdq5FriLab5G9zFnA3WQJi0n2JtHd4SAmOWscE1q G1jHJqbGhPaVMn3fJA/Er3f+03h5CvU4mH06F8XgNSbLT4sYaiHIALOXxo5viStgfymc P6UMmcT7tyuz8QwZdSZY5Z0CiNhJTXFU/6PKqFen0/y+rYWDrqYQbQEyhVCSj/WC8Fc6 9E7fUhHlo6o2P7bg4iMCV9AulrTUwHrgIVxfdQBaw7Harlj2/M/oi4MkXPnRt06nVzOh Jo/w== X-Gm-Message-State: AJIora9p6nBLwRsZRxnBmwDPqZ9QKodwB/BzQgIkCfKJJ+qHvrjszNJ1 zZuZ7OfcVUn043oq2m3XC0QbJbtw8G6BL15N X-Google-Smtp-Source: AGRyM1ueFA/ATV8qMHUgFyV5Iv0lVDeGpSt1XIJkxYWCAsPLVSaQG8hnMwXmyZ94d75ND/7mXrgtTA== X-Received: by 2002:a05:6512:3e24:b0:479:40e9:292a with SMTP id i36-20020a0565123e2400b0047940e9292amr2283186lfv.190.1655375297735; Thu, 16 Jun 2022 03:28:17 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 02/17] migration: should_skip() implemented Date: Thu, 16 Jun 2022 13:27:56 +0300 Message-Id: <20220616102811.219007-3-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::12e; envelope-from=nikita.lapshin@openvz.org; helo=mail-lf1-x12e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376496765100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin For next changes it is convenient to make all decisions about sections skipping in one function. Signed-off-by: Nikita Lapshin --- migration/savevm.c | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 02ed94c180..c68f187ef7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -943,6 +943,15 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *s= e, return vmstate_save_state(f, se->vmsd, se->opaque, vmdesc); } =20 +static bool should_skip(SaveStateEntry *se) +{ + if (se->ops && se->ops->is_active && !se->ops->is_active(se->opaque)) { + return true; + } + + return false; +} + /* * Write the header for device section (QEMU_VM_SECTION START/END/PART/FUL= L) */ @@ -1207,10 +1216,8 @@ void qemu_savevm_state_setup(QEMUFile *f) if (!se->ops || !se->ops->save_setup) { continue; } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } save_section_header(f, se, QEMU_VM_SECTION_START); =20 @@ -1238,10 +1245,8 @@ int qemu_savevm_state_resume_prepare(MigrationState = *s) if (!se->ops || !se->ops->resume_prepare) { continue; } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } ret =3D se->ops->resume_prepare(s, se->opaque); if (ret < 0) { @@ -1268,8 +1273,7 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postc= opy) if (!se->ops || !se->ops->save_live_iterate) { continue; } - if (se->ops->is_active && - !se->ops->is_active(se->opaque)) { + if (should_skip(se)) { continue; } if (se->ops->is_active_iterate && @@ -1337,10 +1341,8 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f) if (!se->ops || !se->ops->save_live_complete_postcopy) { continue; } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } trace_savevm_section_start(se->idstr, se->section_id); /* Section type */ @@ -1374,10 +1376,8 @@ int qemu_savevm_state_complete_precopy_iterable(QEMU= File *f, bool in_postcopy) continue; } =20 - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } trace_savevm_section_start(se->idstr, se->section_id); =20 @@ -1417,6 +1417,9 @@ int qemu_savevm_state_complete_precopy_non_iterable(Q= EMUFile *f, trace_savevm_section_skip(se->idstr, se->section_id); continue; } + if (should_skip(se)) { + continue; + } =20 trace_savevm_section_start(se->idstr, se->section_id); =20 @@ -1522,10 +1525,8 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t= threshold_size, if (!se->ops || !se->ops->save_live_pending) { continue; } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } se->ops->save_live_pending(f, se->opaque, threshold_size, res_precopy_only, res_compatible, @@ -1635,6 +1636,9 @@ int qemu_save_device_state(QEMUFile *f) if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) { continue; } + if (should_skip(se)) { + continue; + } =20 save_section_header(f, se, QEMU_VM_SECTION_FULL); =20 @@ -2542,10 +2546,8 @@ static int qemu_loadvm_state_setup(QEMUFile *f) if (!se->ops || !se->ops->load_setup) { continue; } - if (se->ops->is_active) { - if (!se->ops->is_active(se->opaque)) { - continue; - } + if (should_skip(se)) { + continue; } =20 ret =3D se->ops->load_setup(f, se->opaque); --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655375652; cv=none; d=zohomail.com; s=zohoarc; b=aK9V+73Oy7jqnT7V5iZcMtKUwLMlK7HlVjeslW+hI2nCUvFocmpUEoP4DXJONzlwjEfeWTSeRDbCvIePEeo4rRQSXDV/1r9lMhzvNI6f1oRdCZQtUVTQpYbEw4VPYtsD8mtCdSYZbEoXTbe28FnbaZfXda2nc+6iLMrowfezdvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655375652; h=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=Tr3zUpzB0GffCzKr/MY5AoUXPXUzW4B6SXMURDobjpE=; b=VqkTTYFCo/1b5o1IqO9EOeFWR+gIBvJqR6RFvEeA8xWLawkeUGFqXag+bHzQmqu1NfRq+TuTFMvA7jIFAiZ5G9YJ5m8EkFfxCeX/MvJBtFJHX8TpSH/lTKDPhxBQIgA7TLx2lnQsJmvmzeZxrm79R/6AmONkma0yPjs3JwgY6BA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655375652355388.33195955978897; Thu, 16 Jun 2022 03:34:12 -0700 (PDT) Received: from localhost ([::1]:59666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1mpG-0006yY-6T for importer@patchew.org; Thu, 16 Jun 2022 06:34:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mje-0001b8-5j for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:22 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:44690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjc-0001sz-OQ for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:21 -0400 Received: by mail-lj1-x22d.google.com with SMTP id m25so984715lji.11 for ; Thu, 16 Jun 2022 03:28:20 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tr3zUpzB0GffCzKr/MY5AoUXPXUzW4B6SXMURDobjpE=; b=Hn0tpZpyuRFG4Q40ydhih5z7Jtn8B4RfZbd91/0bBvcjByw+E9FBxj9YqCEwi3SnJQ bQO6LQkq6usWq+mno8+GrXgHmdSC8FLbDf4NnMFJnc+xDQpYUM+mynUYVHbiuyqVK5WH D/ZzJShoKcxpJK3kyyFFrZdfPUiBIye1KBKaWaPxzCID0gtOuAz54HVV17LcaBRuGcIz qCYROXese0C8PHxGRcLU6bsj4Fe8Qo78eKrG5BF3d0/sPBadx1W5Q1rUvaih80KZbCM7 HqCurAfVkoywsRuSEgn4rR3QW56OYs0aO+GLxehRG8NHQ17TrGqr09C4MpCPNwcUPHaC mylQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tr3zUpzB0GffCzKr/MY5AoUXPXUzW4B6SXMURDobjpE=; b=vp7r0RIAeUPjmsnNoC6pR3AyGuAs17wymZmDCe8uewK9H8BEzZcD3sywURyqjAl1Vc Av2TERI2VaZQzYCF901eUViCtbe0OWmY7MU28mF8Pbmr+4IAOESVTZJliNprAH4ZZIAs DKLfznPx0E0yoVYTiRt5F7fZvy59KSsOtDTiigruniWXQ6bwqr8x3XSsC2kNZ7K6g1S6 FI4j90KiusvLBxIeIQUpfYw+2x12SZP4KtvNd8gK+dr5mEmQSP6HTl+b4XoltzmddIId C5DRUOjyJURVtnAFWhL8hPQKQCOGa4ikK/D6FTTjW1mz0P/wo+IE/RJ9t1hy+Hq62Yc+ ZzDA== X-Gm-Message-State: AJIora/tzFJxYY7SRHFPxnOrqP0X8zPvlz3Ziq4LCZPTjUcU6K6EpPZS Nb1C6A8KH9GoXaxtBper43fVsUiZaSQxVan+ X-Google-Smtp-Source: AGRyM1st/hCUahe5ItptuXeXHzh+jMPlC4akiCWhCmRvokhhBA/bJkfD36WXnA66KISv1NQCziGtvA== X-Received: by 2002:a05:651c:1798:b0:25a:42f4:3360 with SMTP id bn24-20020a05651c179800b0025a42f43360mr2222901ljb.335.1655375298965; Thu, 16 Jun 2022 03:28:18 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 03/17] migration: Add vmstate part of migration stream Date: Thu, 16 Jun 2022 13:27:57 +0300 Message-Id: <20220616102811.219007-4-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::22d; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x22d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655375654507100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Now we can disable and enable vmstate part by stream_content parameter. Signed-off-by: Nikita Lapshin --- migration/migration.c | 10 ++++++++-- migration/savevm.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 4adcc87d1d..bbf9b6aad1 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1334,9 +1334,15 @@ void qmp_migrate_set_capabilities(MigrationCapabilit= yStatusList *params, } } =20 -static bool check_stream_parts(strList *stream_content_list) +static bool check_stream_parts(strList *stream_list) { - /* To be implemented in ext commits */ + for (; stream_list; stream_list =3D stream_list->next) { + if (!strcmp(stream_list->value, "vmstate")) { + continue; + } + + return false; + } return true; } =20 diff --git a/migration/savevm.c b/migration/savevm.c index c68f187ef7..48603517ba 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -949,6 +949,21 @@ static bool should_skip(SaveStateEntry *se) return true; } =20 + /* + * Assume that any SaveStateEntry with non-null vmsd is + * part of vmstate. + * + * + * Vmstate is included by default so firstly check if + * stream-content-list is enabled. + */ + + if (se->vmsd && + migrate_get_current()->parameters.has_stream_content_list && + !migrate_find_stream_content("vmstate")) { + return true; + } + return false; } =20 --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655375881; cv=none; d=zohomail.com; s=zohoarc; b=Kdj+IxQDf19jxeNJQbBwXLLUQ+5Dni3caX8ohebU6OYW+nfy8KOlJmr4hbC0RQLCLZ8YT9DE/rAEaByOeBcoqFyO3jJpvcKC5oDymC7NlxD6eNWXjK+hrc8kq/cDO5ARrT8gRNcB+fZteWic/EmmiMxRzNFzMTJpkkbNO5/oUaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655375881; h=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=lUdRuVSrMtGHmkbRHa9MrI5I5UiON+MjCIoGMZGrKdw=; b=mrB59ez3pWU4Eo66vkF9SNkg+B2DHYjLLgvaizQ95awgXIFkmGGVtFmb11u9jwsnj6Im2OJ2fYXZwvyuXr0MXymggkpPXPYjc5CqrTOFzudO6W0sTuYjlWvV9Ww88lCiqZjA40rLkUbR0mvmuVWxVcP7YJ+o6DibyPw+KSNFh00= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655375881962545.7073825482672; Thu, 16 Jun 2022 03:38:01 -0700 (PDT) Received: from localhost ([::1]:37358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1msy-0002lp-TP for importer@patchew.org; Thu, 16 Jun 2022 06:38:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjg-0001da-Nz for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:25 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]:34730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mje-0001tJ-MZ for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:24 -0400 Received: by mail-lj1-x233.google.com with SMTP id e4so1018897ljl.1 for ; Thu, 16 Jun 2022 03:28:22 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lUdRuVSrMtGHmkbRHa9MrI5I5UiON+MjCIoGMZGrKdw=; b=ZtRLxkre0IdttOeRRe3ScTnCThUurNZt+ZKaEcppASu7/9JFwbjePtdg2pecDxsDAy Xv3G6+QR2NZCoCcy780U7qRIR2mPWibY0Y8I4vrHZo6oO8+MOENRjOWjm6fK29it1+Im OKQvdVjhZNpjK76HQSOpSuUhBV+uhLuDJM2e8uaMmCdrgot3LGVt3usCs+YTuZLHEYCf QomIEjVeJMlJv1AmYArWbmxnGPgUw1+P1doQtY83QzFQ+yvkhkMAW3V17kUKe7cRC/c8 6XYhf0VscLYH64sP4TJ139VwPUZABluSIVD23p6WwTMSaMq+d5xN9cMRfgRXxpcOcPp7 s5fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lUdRuVSrMtGHmkbRHa9MrI5I5UiON+MjCIoGMZGrKdw=; b=iMmA6BXtgCqae+KWKW5StvU7A9hmtfYcgB3O9qo9mg6VxO0wALhtJXavcYtt1cAAHJ f09k0s/xC/mNveZbMXEWBKyQ+mPmrYD2MvIcZaBXfQBCCHKKJrdQWuTuDzXjcb62UB4j kgjLvYQuduezjF1U8Q62uoWajJuhClQvg2Qsr4f8/1zCHBmngfW9KdxAT36zBVLdztWr axCnLX6AN0FWrLZ598ae77uobJW5llJf4JDRhVw97dMP5Gt9v3oOpwyMVt27I1MvNuBG fhgTZxeeDKT96PdXdYIY6T5nM9tDEPTrsHQumCJTrfpGTUYON8eHbw7xTiGU0jhBaY/T tPHg== X-Gm-Message-State: AJIora870tKBNcPdpbB+wJpzyQXBioBil21YiuL8qm1jfy8ZCSBkq7A9 olvoxu8SD6Rxuqw4ntQ4NHmzW00J2sReIZ3C X-Google-Smtp-Source: AGRyM1vuflsq3TwUyYqRcyrI6k0R7AaWGwXM0HTv1Vbk7HGcq7dYqCsoYWnb35xqcuoWn86cBQgDDA== X-Received: by 2002:a05:651c:19a2:b0:255:9fc6:c12 with SMTP id bx34-20020a05651c19a200b002559fc60c12mr2040433ljb.457.1655375300634; Thu, 16 Jun 2022 03:28:20 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 04/17] migration: Add dirty-bitmaps part of migration stream Date: Thu, 16 Jun 2022 13:27:58 +0300 Message-Id: <20220616102811.219007-5-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::233; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x233.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655375883622100003 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin This patch enables and disable dirty-bitmaps in migration stream. Signed-off-by: Nikita Lapshin --- migration/migration.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bbf9b6aad1..ad789915ce 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1337,7 +1337,8 @@ void qmp_migrate_set_capabilities(MigrationCapability= StatusList *params, static bool check_stream_parts(strList *stream_list) { for (; stream_list; stream_list =3D stream_list->next) { - if (!strcmp(stream_list->value, "vmstate")) { + if (!strcmp(stream_list->value, "vmstate") || + !strcmp(stream_list->value, "dirty-bitmaps")) { continue; } =20 @@ -2501,7 +2502,8 @@ bool migrate_dirty_bitmaps(void) =20 s =3D migrate_get_current(); =20 - return s->enabled_capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS]; + return s->enabled_capabilities[MIGRATION_CAPABILITY_DIRTY_BITMAPS] || + migrate_find_stream_content("dirty-bitmaps"); } =20 bool migrate_ignore_shared(void) --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655375951; cv=none; d=zohomail.com; s=zohoarc; b=ZYVCwaOF4TJ8iJVMhFI4n8ohCoI+AASa5SSaPQMo56q8B3ejOpe9HO9tOt7XcxeQo4TzpdV6xTgX7swLdOQZwgvln+eQi8/V+i0U8UcVvh2Q8kJgtzEWh+CYK7o0LoIzSDkU4WBM0ip+yYfFtiyPSqYtu/7snJRS46H6G47oSHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655375951; h=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=DSeTt1QB5HDWqFVTnSya2l9lA2ROxRGP0qePz5aGaP4=; b=fI49Kcv44GNVaWh5UBRhTd1o0d1lscYec597GgmjxVzMxwX4NARXRKjUE/58gbj2EcbRzNt0oFeIgZLZIvyiOieOSGOwn5sx+1uxSfTm6p7fl4bSeUhCog5rXMZMAvMtIflqEYMiVaIhTEk0RfBE2NS1qkarTBWEqiisuWVVZbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655375951515657.9828170120926; Thu, 16 Jun 2022 03:39:11 -0700 (PDT) Received: from localhost ([::1]:39502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1mu3-0004Qy-FE for importer@patchew.org; Thu, 16 Jun 2022 06:39:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjf-0001cy-Tn for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:24 -0400 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]:35524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mje-0001sh-Fq for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:23 -0400 Received: by mail-lj1-x230.google.com with SMTP id r24so1014042ljn.2 for ; Thu, 16 Jun 2022 03:28:22 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DSeTt1QB5HDWqFVTnSya2l9lA2ROxRGP0qePz5aGaP4=; b=4qee0fVtj65lw2VRmj5huBbxCW5kniUSmpivuNXpmmKbzLReH4PagdRA00Wd+ADxZO ViO6/yb/8COC5WTr1pQ8OrZq3ySEP7cmdvkm+rlp3bNiq5fR9QmC3OW9gA/jFl2kEY28 9oLFHtbdajw5Zgd2vQgABGjVsv+R33kDlX1atxLhl4Vt+DLlMcmtcNxyAu0vBfg249iR VwnXNsUS7guUBFC6Ccr4L7Gk1MUA0pxxA1IEu9LlDlbOxURctK2uggrlAZzhYt6MRxg9 kTmV+uZyuMJrO8LD2Or1fjs1wWspwxz5bFKHXjdCjGfczCEuJ9ZTLSdRvQ/IWBv3rXii ywdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DSeTt1QB5HDWqFVTnSya2l9lA2ROxRGP0qePz5aGaP4=; b=tpWQQmkAzkYkdMykpxGAoej/6ScVXLCL1Y5jIuikGoul8Zxv9/gtak04HyoGq7Wq1c lxWjpvTcsnLTR5fbcjC4spfL1/N8QyXbbyR5zoHM+mJPm0aPZiRQywmdbuZcNdzYuJ7a YoISMFBOraT5XOTf8rb2QppGJOB5BkmZW4vfig6627g1Pa1U77w64P4+1ZP2olg7bsbJ BUIFnksjFjIMYFL9UKDazZd42MgLxcqfsnKL+ozdjL1tZ5zbI2hSWZhtAzocZYARCqet rFMDF3K8EbUTo434eFpagN2xaNfUvCnChbJr7Q2nR4NJovmmQHSVcjYtti78d19NdFMv UtBQ== X-Gm-Message-State: AJIora+PRoHW041aDpiFZ+TSTLswdeO2pb7cmlKwlNrl7/IWeGHVfZkc al9glxIUSjl06WJ/KM2/oPGU+Fyq/haKvGnA X-Google-Smtp-Source: AGRyM1t141GP+xPsMR171BCDC5yao7J8fHkYa4zEMSP88SkEun7S7mzOA/j0wO5hriJx5gjGl20Okg== X-Received: by 2002:a2e:3315:0:b0:258:dfff:e252 with SMTP id d21-20020a2e3315000000b00258dfffe252mr2172335ljc.141.1655375301573; Thu, 16 Jun 2022 03:28:21 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 05/17] migration: Add block part of migration stream Date: Thu, 16 Jun 2022 13:27:59 +0300 Message-Id: <20220616102811.219007-6-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::230; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x230.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655375951954100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin This patch enables and disable block in migration stream. Signed-off-by: Nikita Lapshin --- migration/migration.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ad789915ce..d81f3c6891 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1338,7 +1338,8 @@ static bool check_stream_parts(strList *stream_list) { for (; stream_list; stream_list =3D stream_list->next) { if (!strcmp(stream_list->value, "vmstate") || - !strcmp(stream_list->value, "dirty-bitmaps")) { + !strcmp(stream_list->value, "dirty-bitmaps") || + !strcmp(stream_list->value, "block")) { continue; } =20 @@ -2621,7 +2622,8 @@ bool migrate_use_block(void) =20 s =3D migrate_get_current(); =20 - return s->enabled_capabilities[MIGRATION_CAPABILITY_BLOCK]; + return s->enabled_capabilities[MIGRATION_CAPABILITY_BLOCK] || + migrate_find_stream_content("block"); } =20 bool migrate_use_return_path(void) --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376891; cv=none; d=zohomail.com; s=zohoarc; b=RUpALXT4S+enF3wLSfdP0aJEX7WYnlox6XPWwcmBEmOiZFTsgVXPIuPNPO1+XIadgiaQJUFlQ9e3PKzC/rXI2dqjEYuUruZVbCJId1g4bGwFUY4wHJ0CYn2OxXbC87J8Aa+8QpSDmqNmgmxzjEJMY1Cu8DnVrcsvQef79PMZW5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376891; h=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=oK8v0UyddkjpSuECXSazJBzWB9ix/qZIBfYgHUOu/4I=; b=WRa76k4JnlYea4bLSi3td8RHrEFkhEPPvP8II/5fXliWRO16LakeGttIDKJ3qCwgm3cz/HVTx7DoUjX2mE0Gply0UifQxHFAze5CgGn6U3WKO71sjjxnmJbN17XHLrfMpmA8IAVQEf4oDp9lvH4FtCaT2zFxNjfmJzZAuicRpFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376891834525.8490417548545; Thu, 16 Jun 2022 03:54:51 -0700 (PDT) Received: from localhost ([::1]:34590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n9G-00043v-F4 for importer@patchew.org; Thu, 16 Jun 2022 06:54:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjh-0001gQ-Vu for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:26 -0400 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]:35525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjg-0001tc-4u for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:25 -0400 Received: by mail-lj1-x230.google.com with SMTP id r24so1014353ljn.2 for ; Thu, 16 Jun 2022 03:28:23 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oK8v0UyddkjpSuECXSazJBzWB9ix/qZIBfYgHUOu/4I=; b=sTJuRmkp5sXbFB48qA2bSxSO6moOwRYIoiwJk/aW+SNdRQ2W2waPh/X1Zb4cL7NLjW R2n73sqYHMXXVgmOyWSaB6RISyoHk8GwL16rRkP2vqoBrjPpovmUnnv0LXJo7TB7erx0 WuMPb9y/z2pAtbzwwpBJWSsIP3S4jNt3bS4fP6LO5H+EVad5Hst39swJgF/0vugeOA9o NMmabQLFwUwyCzJxp+PPm62GyWnwBxdRUdx7GkT5T7C1fR0KColSPP7ODfC9I1sp88Jb BrPpSJ/Q5wSurKA1w2GDaVahyc+ihcDloSrM+3bnn92ivacOoqCm9uhr2ZT9HJK5vpRC wbhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oK8v0UyddkjpSuECXSazJBzWB9ix/qZIBfYgHUOu/4I=; b=KJ5cHYzFZsG570MAkGBWFETJsK4UJ+UJzgiDY9G6juNJWuI4BUfSskZBHibW8eKwC2 NC2OdvsiaGavNMf+R/SSLqUlir45IyAoTp5O5AC/wpp4nKsYNCtp0CDD+jXC50CoRwoE mGlUyq+a3Od+qPJoXhV0WHKYtiPoFY6R/QAyDTNUm2KKGE6q4dvKD0Wb3l++zsoMK0Vx 6WeQe4uicm/79jw/NIPWwPbgnKbT9ePdxsMfkCqE3R6UWlpXdavvaUplkT0uvH5YbCm0 9j5zb7KFWOPBUfQ1CXeqsmKwgUKDHsCg13RyE6WhPRzStHEwPh8fCqhyW2YinXRq4joZ FqUA== X-Gm-Message-State: AJIora8hYKqrCXvI+rl/VibsiqhfT1okJiuGdiRXHO6YEHVLM7xk1xJc EkmlzVoBqkXYCWGx0UoOqwoZULFsa9J4WB8f X-Google-Smtp-Source: AGRyM1saB8BylyeIopcZnAmtrgggK9IF8p2+ukxRSBj9Lp8gcmwMb8McfeZRgBXirO2n/6MBJcwPYw== X-Received: by 2002:a2e:80d8:0:b0:255:8307:1c87 with SMTP id r24-20020a2e80d8000000b0025583071c87mr2166655ljg.169.1655375302511; Thu, 16 Jun 2022 03:28:22 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 06/17] migration: Add RAM part of migration stream Date: Thu, 16 Jun 2022 13:28:00 +0300 Message-Id: <20220616102811.219007-7-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::230; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x230.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376893675100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin 'ram' parameter enable RAM sections in migration stream. If it isn't specified it will be skipped. Signed-off-by: Nikita Lapshin --- migration/migration.c | 17 ++++++++++++++++- migration/migration.h | 1 + migration/ram.c | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index d81f3c6891..6528b3ad41 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1339,7 +1339,8 @@ static bool check_stream_parts(strList *stream_list) for (; stream_list; stream_list =3D stream_list->next) { if (!strcmp(stream_list->value, "vmstate") || !strcmp(stream_list->value, "dirty-bitmaps") || - !strcmp(stream_list->value, "block")) { + !strcmp(stream_list->value, "block") || + !strcmp(stream_list->value, "ram")) { continue; } =20 @@ -2653,6 +2654,20 @@ bool migrate_background_snapshot(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; } =20 +bool migrate_ram(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + /* + * By default RAM is enabled so if stream-content-list disabled + * RAM will be passed. + */ + return !s->parameters.has_stream_content_list || + migrate_find_stream_content("ram"); +} + /* Checks if stream-content parameter has section_name in list */ bool migrate_find_stream_content(const char *section_name) { diff --git a/migration/migration.h b/migration/migration.h index 411c58e919..5c43788a2b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -395,6 +395,7 @@ int migrate_decompress_threads(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); bool migrate_background_snapshot(void); +bool migrate_ram(void); =20 bool migrate_find_stream_content(const char *section_name); =20 diff --git a/migration/ram.c b/migration/ram.c index 170e522a1f..ddc7abd08a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4263,6 +4263,11 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +static bool is_ram_active(void *opaque) +{ + return migrate_ram(); +} + static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, @@ -4275,6 +4280,7 @@ static SaveVMHandlers savevm_ram_handlers =3D { .load_setup =3D ram_load_setup, .load_cleanup =3D ram_load_cleanup, .resume_prepare =3D ram_resume_prepare, + .is_active =3D is_ram_active, }; =20 static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host, --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376183; cv=none; d=zohomail.com; s=zohoarc; b=Es7hKzy8Rl72szTpuGrL9ZHfJ3VjByVXUjtfKzjMz+Dr+1yKmC2gtk0IDJXFVsMW01rS3XsXMEm9CNLLyHqVhoufCOpVjKRYurmTnO8APSX8KKkhUvGs4kjy/IB0y4HT7lVsHBbZgETAQ+RnfuhAjTfUAG3LQpMSHMkYbPbPcP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376183; h=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=ph3j4rH0WZ7c2HoYuVqV3UOm1O3CpslfaOVdfqGvGvE=; b=OEDevlOCrAdcT4e3P+75YBJGQaABj64buYLY0cVe+S9KtBvlzjZcOVodm1ueMEY8nAIpbaar/OcNXqOkndMq/F0BNqzeEUHy3kM1Ppep/qQuL1ReauvSc7fHoXhAWs2/Rw2ioZldy6v6XQ7R0bwi+fpGeI4lX0gtU5AM1JvULvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376183938135.9830200831566; Thu, 16 Jun 2022 03:43:03 -0700 (PDT) Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1mxq-0000ob-Iz for importer@patchew.org; Thu, 16 Jun 2022 06:43:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjk-0001jt-I7 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:28 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:35362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjh-0001tn-57 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:27 -0400 Received: by mail-lj1-x243.google.com with SMTP id r24so1014395ljn.2 for ; Thu, 16 Jun 2022 03:28:24 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ph3j4rH0WZ7c2HoYuVqV3UOm1O3CpslfaOVdfqGvGvE=; b=c90Ma7x1oX3XWMLQ2qlJtb1EvLFpA7NTncR3Qwwhr6Imuwtt88oSJrPVKYx7xN8VU8 K2pZK/YAIw4iQibQg689Hgvm8VYcRP63Q6egyUED4AEVq3cBrRiTCdOR9UFwe3vv/8wj FGSnsv9+harRiwwa24FVc4lehQdmYmyVs+sLcKy5zJTRg051Z8g1dtAoUgbgd8Lcc5X4 tJ+71hk2yuEnEfd32NIVdZBKDxDTJhFufV6jXHIChmiF8aFJHL5cCukwdlbG7Lm9/nM0 CTqHIXgp6kcw8PbqR/xHOd/P0YIbNlkHfUdzqA0MmJAySzeqCRI0/QNY2m19b/wK9c14 xycw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ph3j4rH0WZ7c2HoYuVqV3UOm1O3CpslfaOVdfqGvGvE=; b=qkk9xDG2tKOLJFDkeaPHzIvxi1Soe2N3MWqha+tb8YEaEqLmIejKtiPv0M6zEBHJfT JzliJQN7ZvBLoNH81oW0qbv2P4ctxKJtnz1upmDOBTEEjI2LTHOTTDAP5fCP+1kGN4ms AS6ERC3IImokpYVWRwGcEHB12yfOfiJJKs8nwbWVORjUmtIipxrHvT4Dgajns8BA8WzV tu0minPA+V3eq33NbjmA+jB/E8KnNnNn2j0vEd8pfRda69B3P3NDP8Z4YX9g1xhdTlqn DxppRNKlvNml4Ref69LzWT6CKo1Sm+0uqWhtdnYxm1RFXtBidDJLmHy7bKFMalZFF06f fusg== X-Gm-Message-State: AJIora8Mztd0GooXQ+blYmaEoLxLxd4G1cHwtcz2G85f+gmaFWbZpwFx yah6vE7DIpqTTmhmfJT7cKvukXe2fJSnlUAx X-Google-Smtp-Source: AGRyM1sXSCCpesdK4mmVQrU6dehinhSBueJnJdfzYrTSf3NGgrSYf3GSdJfDQ86DAhdo2lqQuiuu2g== X-Received: by 2002:a2e:7813:0:b0:255:8e6e:1988 with SMTP id t19-20020a2e7813000000b002558e6e1988mr2071442ljc.107.1655375303434; Thu, 16 Jun 2022 03:28:23 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 07/17] migration: analyze-migration script changed Date: Thu, 16 Jun 2022 13:28:01 +0300 Message-Id: <20220616102811.219007-8-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::243; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x243.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376184490100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin This script is used for RAM capabilities test. But it cannot work in case of no vm description in migration stream. So new flag is added to allow work this script with ram-only migration stream. Signed-off-by: Nikita Lapshin --- scripts/analyze-migration.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index b82a1b0c58..80077a09bc 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -495,7 +495,7 @@ def __init__(self, filename): self.filename =3D filename self.vmsd_desc =3D None =20 - def read(self, desc_only =3D False, dump_memory =3D False, write_memor= y =3D False): + def read(self, ram_only, desc_only =3D False, dump_memory =3D False, w= rite_memory =3D False): # Read in the whole file file =3D MigrationFile(self.filename) =20 @@ -509,7 +509,8 @@ def read(self, desc_only =3D False, dump_memory =3D Fal= se, write_memory =3D False): if data !=3D self.QEMU_VM_FILE_VERSION: raise Exception("Invalid version number %d" % data) =20 - self.load_vmsd_json(file) + if not ram_only: + self.load_vmsd_json(file) =20 # Read sections self.sections =3D collections.OrderedDict() @@ -518,7 +519,10 @@ def read(self, desc_only =3D False, dump_memory =3D Fa= lse, write_memory =3D False): return =20 ramargs =3D {} - ramargs['page_size'] =3D self.vmsd_desc['page_size'] + if ram_only: + ramargs['page_size'] =3D 4096 + else: + ramargs['page_size'] =3D self.vmsd_desc['page_size'] ramargs['dump_memory'] =3D dump_memory ramargs['write_memory'] =3D write_memory self.section_classes[('ram',0)][1] =3D ramargs @@ -579,6 +583,7 @@ def default(self, o): parser.add_argument("-m", "--memory", help=3D'dump RAM contents as well', = action=3D'store_true') parser.add_argument("-d", "--dump", help=3D'what to dump ("state" or "desc= ")', default=3D'state') parser.add_argument("-x", "--extract", help=3D'extract contents into indiv= idual files', action=3D'store_true') +parser.add_argument("--ram-only", help=3D'parse migration dump containing = only RAM', action=3D'store_true') args =3D parser.parse_args() =20 jsonenc =3D JSONEncoder(indent=3D4, separators=3D(',', ': ')) @@ -586,14 +591,14 @@ def default(self, o): if args.extract: dump =3D MigrationDump(args.file) =20 - dump.read(desc_only =3D True) + dump.read(desc_only =3D True, ram_only =3D args.ram_only) print("desc.json") f =3D open("desc.json", "w") f.truncate() f.write(jsonenc.encode(dump.vmsd_desc)) f.close() =20 - dump.read(write_memory =3D True) + dump.read(write_memory =3D True, ram_only =3D args.ram_only) dict =3D dump.getDict() print("state.json") f =3D open("state.json", "w") @@ -602,12 +607,12 @@ def default(self, o): f.close() elif args.dump =3D=3D "state": dump =3D MigrationDump(args.file) - dump.read(dump_memory =3D args.memory) + dump.read(dump_memory =3D args.memory, ram_only =3D args.ram_only) dict =3D dump.getDict() print(jsonenc.encode(dict)) elif args.dump =3D=3D "desc": dump =3D MigrationDump(args.file) - dump.read(desc_only =3D True) + dump.read(desc_only =3D True, ram_only =3D args.ram_only) print(jsonenc.encode(dump.vmsd_desc)) else: raise Exception("Please specify either -x, -d state or -d desc") --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376438; cv=none; d=zohomail.com; s=zohoarc; b=iJ5dGU9KRmztFgvQnr+D5h7SkA4TpFN7xz4f8wXIqC6ifC3HQfUYA5WoSMPkAxPdElgPKSoGA6r+/9qU+Ky+ATsNAMi3q4F6CXC8jcNuWPxa3HctUGmPf1y5xo9X7FfpbbxSpnopkgH1L9AMTp0qYTjqKxOsRRPU7FqD1Y1aWOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376438; h=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=7QiRPB+DwgPdQ5tbpC7RSf9cTa8Nua9jBz5J8RJizgs=; b=Tj6ZSVBR51mry2CWI+hbUsUuRCTwxCWiGMkymQEkJX1JHCi/mQiV4kQOqQm1V7dRi12hF5NoaX0bGtlctcdYqga3gORfyqRN0o+slpU7EOS/T0VUgWhC1SDb3q3msiBgGipwQf1M4SyWWDbZ+wYhxP8g8xEeAiVyUAE3ePcKAPY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376438296343.8947898085363; Thu, 16 Jun 2022 03:47:18 -0700 (PDT) Received: from localhost ([::1]:54720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n1x-0006Zs-3d for importer@patchew.org; Thu, 16 Jun 2022 06:47:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjk-0001ju-I5 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:28 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:46684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mji-0001tz-2W for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:27 -0400 Received: by mail-lj1-x22a.google.com with SMTP id l18so979852lje.13 for ; Thu, 16 Jun 2022 03:28:25 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7QiRPB+DwgPdQ5tbpC7RSf9cTa8Nua9jBz5J8RJizgs=; b=WK0cgAOG7m1jo6wcRVt2ECYthCET1Sy9tzZorHKV8x+8DMLbJh2KwoAjO8AzojWGwM fUvS+LB3raOLscHwAXrgI0+Ovurnq1XpfAunZ5zoxrx71KD2NSKGuJJtd5WRKThVYGnD L00k9rXDgxyOef47nwKzXZaVFfPVg7OR25H1PcF6iGqZKklbMeLdRpb1+LgmKIkOQ3PE lh3YFsTFrDFULZIccHN+axeY6MMQLopxjJcqkNIbC5UuUFVS/zu90+hNfTDyJELYpLLr //eI/fmfV0aCubPcDI0bZ+k4tm3S7yozFAa8ORx1Ris6sS3lDXWZ/XoohLMxRhQxu2y1 9Tlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7QiRPB+DwgPdQ5tbpC7RSf9cTa8Nua9jBz5J8RJizgs=; b=i1zvizQrRfFZXAc6a+y4Y9i92eGdWX6MINxfAOYi0Jr1Bv2Ims5NLnkO8OEq8AAxEO nSeqtjm+kbVoU0R7me7GjKChBGHvGQXK+DnOrWV+jDhaDRdTfqKwq6AXDcqPqV9fqY90 1HAZvyJ9o9hLByZt3rwSxZcx8+yAa9PQPqUWXnmuHeohnmwoe4xHJN5u1We3wxBp5LWW 9eV7ZjgOBowKbElmNDp6ZRxMqTmqjNusqeBdnIFe6BOrC5n+CH6vI087fuNKOgH8jb5q MgZPwuQYUdVxVseMQywxj7Is2l7qx0BlB1iIb1eZPnZlpdIdaA5naC35/oAphcM14plM c7+w== X-Gm-Message-State: AJIora+tt2D61yuePO1v9OSropfVMnIy4T16kesxkcNz4sv1OVeBrSmg OdjOHJj5r+/avW0QcxWG+o3KTNS4y8PahJoj X-Google-Smtp-Source: AGRyM1sWpAUJPhJ2dFltnoqhCZnW/ZnOwvQxiJK0Tl9gwUDI7HRGPgWL6GJlnYt1UBWKg5Pw63eihg== X-Received: by 2002:a2e:881a:0:b0:255:7c2c:46d8 with SMTP id x26-20020a2e881a000000b002557c2c46d8mr2161717ljh.364.1655375304355; Thu, 16 Jun 2022 03:28:24 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 08/17] migration: Test for RAM and vmstate parts Date: Thu, 16 Jun 2022 13:28:02 +0300 Message-Id: <20220616102811.219007-9-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::22a; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x22a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376440547100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin All other parts works just like existed capabilities. Thus there is no need to make new tests. Though RAM and vmstate are new so here is new test for that parts. Signed-off-by: Nikita Lapshin --- .../tests/migrate-ram-stream-content-test | 96 +++++++++++++++++++ .../tests/migrate-ram-stream-content-test.out | 5 + 2 files changed, 101 insertions(+) create mode 100755 tests/qemu-iotests/tests/migrate-ram-stream-content-test create mode 100644 tests/qemu-iotests/tests/migrate-ram-stream-content-tes= t.out diff --git a/tests/qemu-iotests/tests/migrate-ram-stream-content-test b/tes= ts/qemu-iotests/tests/migrate-ram-stream-content-test new file mode 100755 index 0000000000..2855ca4a64 --- /dev/null +++ b/tests/qemu-iotests/tests/migrate-ram-stream-content-test @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# group: rw migration +# +# Tests for 'no-ram' and 'ram-only' capabilities +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import json +import subprocess +import iotests + +img =3D os.path.join(iotests.test_dir, 'disk.img') + +class TestRamCapabilities(iotests.QMPTestCase): + def setUp(self): + iotests.qemu_img('create', '-f', iotests.imgfmt, img, '10M') + self.vm =3D iotests.VM() + self.vm.launch() + self.vm.qmp('migrate-set-capabilities', capabilities=3D[ + { + 'capability': 'events', + 'state': True + } + ]) + + def tearDown(self): + self.vm.shutdown() + os.remove(img) + + def check_ram_only(self, output): + str_json =3D output.decode() + json_obj =3D json.loads(str_json) + + success =3D False + for key in json_obj: + self.assertTrue("ram" in key) + success =3D True + self.assertTrue(success) + + def run_migration(self, no_ram, tmp_stream): + if no_ram: + output =3D self.vm.qmp('migrate-set-parameters', + stream_content_list =3D ['vmstate']) + else: + self.vm.qmp('migrate-set-parameters', + stream_content_list =3D ['ram']) + + self.vm.qmp('migrate', uri=3D'exec:cat>' + tmp_stream) + + while True: + event =3D self.vm.event_wait('MIGRATION') + + if event['data']['status'] =3D=3D 'completed': + break + + + def test_no_ram(self): + with iotests.FilePath('tmp_stream') as tmp_stream: + self.run_migration(True, tmp_stream) + output =3D subprocess.run( + ['../../../scripts/analyze-migration.py', '-f', tmp_stream= ], + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + check=3DFalse).stdout + + self.assertFalse('ram' in output.decode()) + + def test_ram_only(self): + with iotests.FilePath('tmp_stream') as tmp_stream: + self.run_migration(False, tmp_stream) + output =3D subprocess.run( + ['../../../scripts/analyze-migration.py', '-f', tmp_stream, + '--ram-only'], + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + check=3DFalse).stdout + + self.check_ram_only(output) + +if __name__ =3D=3D '__main__': + iotests.main(supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/migrate-ram-stream-content-test.out b= /tests/qemu-iotests/tests/migrate-ram-stream-content-test.out new file mode 100644 index 0000000000..fbc63e62f8 --- /dev/null +++ b/tests/qemu-iotests/tests/migrate-ram-stream-content-test.out @@ -0,0 +1,5 @@ +.. +---------------------------------------------------------------------- +Ran 2 tests + +OK --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655377216; cv=none; d=zohomail.com; s=zohoarc; b=Ofzg91pomNTJsKNBswz6KH0eMZ6gc5Y8RkYx4gwFf0YJCY7R9IFjA/7w3yJoTdPF1oNyjMqMVIZSe4uDVupXT02IHlcGd1oKaV/spJM7tFzatqHMjPbkahXx4YkOVMambmzAlJT8jtFFVBQuStoVb4Vcl5x6fp8NJsZxh5R0k5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655377216; h=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=ggHIetbBfH5Ls8v05ui9WNYhBnpUF8zUCpogjlFp/yI=; b=CG1P+fsGjdJK55NVQQmOjsznLDrfKD7K1NpEJ8CEwbF4IZ/Hnw5n0K+pto5vtRV2YO33u8mtHsel3FxeSNoD5CQkABOzzFAWwrvrh7cMKWA4h9YniENGnPUAC9vDfKIFFPQcm4rwOUUxVYfiG44I2hk2EXgXt9XaJk/Rr5vKB+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655377216592353.67290471747276; Thu, 16 Jun 2022 04:00:16 -0700 (PDT) Received: from localhost ([::1]:43138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nEV-0001Us-2R for importer@patchew.org; Thu, 16 Jun 2022 07:00:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjm-0001md-Jo for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:30 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:41887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjk-0001uL-9i for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:30 -0400 Received: by mail-lj1-x22a.google.com with SMTP id v8so996111ljj.8 for ; Thu, 16 Jun 2022 03:28:27 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ggHIetbBfH5Ls8v05ui9WNYhBnpUF8zUCpogjlFp/yI=; b=HHVGGbSDiqaaLtWv4MkRWxF2j3LE8WKm+eK5l4dAXAirDV/yQxGhH940dIEdN5DaTr VguN+EO6h+BjJ1QT9ql+XCrL8WyLmydvcLnCPMSZgsKtut8k1bP40QaMXWQ8ZQIe/KcO AkFXKPx7Hj9pms6Wv3N0nuQV1asmBLWzbZRkxqSeFOrATXJ83yEIcX+1Kdpvofh5YAGL +Xq28e0JeMdwc4T0wfjlpB0II6g2XBSA7/vf00WgPfZtAH/HeLJdq9JpW9oPjJuy3shM qNrPbrZ4r7Vvg2FRzQYP+kVlaVIB9vncNh/PoLQ3dA0zlQXhjb+oaVWTbD+gn6yatgKY hY7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ggHIetbBfH5Ls8v05ui9WNYhBnpUF8zUCpogjlFp/yI=; b=mS3e5X6AmmAJgiPF30bLOf8XmawyvsaTg6gFKaYM8TcILfEdfwJrpY94/UjPjysBv3 8uqMaLjjISVTP/Q1e9jfdnExXb1ct4RMZ+NBcw4XW25xF3HMrQBWL9X+tEdPNM4mCbe5 PUdH/xZ/Kf8IIwy6VuhjrShrpwt2Gv8CSrYCQgwtnEKf1+lOnTnYn/QcMEU8TJ/w1xRd xm55iHU1GPQt0OSM7X5/1yyM11HNZSapMiN6BOcPkYMe393hO5jjBI5hFT9J2UPCuoag G5NYrnojhjF1U/Go81Wmjp8eZWMDJTZhibMtJvLNSXX4avjn2RxIq1+bn8sYCCDvaaFA aknQ== X-Gm-Message-State: AJIora+t9hdbRMpSkVdmkTr+1vJueoLOHqtwj3fFxrW1IBkriPB56yyN +5NMGfnkAU99ptyGNq2awfqFJmc5xSiLAhwC X-Google-Smtp-Source: AGRyM1sPNwk7s9f/92Cc/1DowOQqvFWxMlvDVxgSQ5/RAWcRhTDzMDvl9jeFyt9A1tBSf6kI0Q5DOA== X-Received: by 2002:a05:651c:1143:b0:25a:3e5:7b6a with SMTP id h3-20020a05651c114300b0025a03e57b6amr2154160ljo.163.1655375305658; Thu, 16 Jun 2022 03:28:25 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 09/17] migration/snapshot: Introduce qemu-snapshot tool Date: Thu, 16 Jun 2022 13:28:03 +0300 Message-Id: <20220616102811.219007-10-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::22a; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x22a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655377218382100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Execution environment, command-line argument parsing, usage/version info et= c. Signed-off-by: Nikita Lapshin --- include/qemu-snapshot.h | 65 ++++++ migration/qemu-snapshot.c | 57 +++++ qemu-snapshot.c | 433 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 555 insertions(+) create mode 100644 include/qemu-snapshot.h create mode 100644 migration/qemu-snapshot.c create mode 100644 qemu-snapshot.c diff --git a/include/qemu-snapshot.h b/include/qemu-snapshot.h new file mode 100644 index 0000000000..8e548e7630 --- /dev/null +++ b/include/qemu-snapshot.h @@ -0,0 +1,65 @@ +/* + * QEMU External Snapshot Utility + * + * Copyright Virtuozzo GmbH, 2021 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_SNAPSHOT_H +#define QEMU_SNAPSHOT_H + +/* Invalid offset */ +#define INVALID_OFFSET -1 +/* Maximum byte count for qemu_get_buffer_in_place() */ +#define INPLACE_READ_MAX (32768 - 4096) + +/* Backing cluster size */ +#define BDRV_CLUSTER_SIZE (1024 * 1024) + +/* Minimum supported target page size */ +#define PAGE_SIZE_MIN 4096 +/* + * Maximum supported target page size. The limit is caused by using + * QEMUFile and qemu_get_buffer_in_place() on migration channel. + * IO_BUF_SIZE is currently 32KB. + */ +#define PAGE_SIZE_MAX 16384 +/* RAM slice size for snapshot saving */ +#define SLICE_SIZE PAGE_SIZE_MAX +/* RAM slice size for snapshot revert */ +#define SLICE_SIZE_REVERT (16 * PAGE_SIZE_MAX) + +typedef struct StateInfo { + int64_t page_size; + int64_t page_mask; + int page_bits; + int64_t slice_size; + int64_t slice_mask; + int slice_bits; +} StateInfo; + +typedef struct StateSaveCtx { + BlockBackend *blk; /* Block backend */ + + StateInfo state_parameters; /* Migration state info*/ +} StateSaveCtx; + +typedef struct StateLoadCtx { + BlockBackend *blk; /* Block backend */ + + StateInfo state_parameters; /* Migration state info*/ +} StateLoadCtx; + +void ram_init_state(void); +void ram_destroy_state(void); +StateSaveCtx *get_save_context(void); +StateLoadCtx *get_load_context(void); +int coroutine_fn save_state_main(StateSaveCtx *s); +int coroutine_fn load_state_main(StateLoadCtx *s); + +#endif /* QEMU_SNAPSHOT_H */ diff --git a/migration/qemu-snapshot.c b/migration/qemu-snapshot.c new file mode 100644 index 0000000000..f7695e75c7 --- /dev/null +++ b/migration/qemu-snapshot.c @@ -0,0 +1,57 @@ +/* + * QEMU External Snapshot Utility + * + * Copyright Virtuozzo GmbH, 2021 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/block-backend.h" +#include "qemu/coroutine.h" +#include "qemu/cutils.h" +#include "qemu/bitmap.h" +#include "qemu/error-report.h" +#include "io/channel-buffer.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/ram.h" +#include "qemu-snapshot.h" + +/* RAM transfer context */ +typedef struct RAMCtx { + int64_t normal_pages; /* Total number of normal pages */ +} RAMCtx; + +static RAMCtx ram_ctx; + +int coroutine_fn save_state_main(StateSaveCtx *s) +{ + /* TODO: implement */ + return 0; +} + +int coroutine_fn load_state_main(StateLoadCtx *s) +{ + /* TODO: implement */ + return 0; +} + +/* Initialize snapshot RAM state */ +void ram_init_state(void) +{ + RAMCtx *ram =3D &ram_ctx; + + memset(ram, 0, sizeof(ram_ctx)); +} + +/* Destroy snapshot RAM state */ +void ram_destroy_state(void) +{ + /* TODO: implement */ +} diff --git a/qemu-snapshot.c b/qemu-snapshot.c new file mode 100644 index 0000000000..683f1b265a --- /dev/null +++ b/qemu-snapshot.c @@ -0,0 +1,433 @@ +/* + * QEMU External Snapshot Utility + * + * Copyright Virtuozzo GmbH, 2021 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#include "qemu/memalign.h" +#include "qemu-common.h" +#include "qemu-version.h" +#include "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "sysemu/sysemu.h" +#include "sysemu/block-backend.h" +#include "qemu/cutils.h" +#include "qemu/coroutine.h" +#include "qemu/error-report.h" +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/option_int.h" +#include "qemu/main-loop.h" +#include "trace/control.h" +#include "io/channel-util.h" +#include "io/channel-buffer.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/savevm.h" +#include "migration/misc.h" +#include "qemu-snapshot.h" + +int64_t page_size; +int64_t page_mask; +int page_bits; +int64_t slice_size; +int64_t slice_mask; +int slice_bits; + +static QemuOptsList snap_blk_optslist =3D { + .name =3D "blockdev", + .implied_opt_name =3D "file.filename", + .head =3D QTAILQ_HEAD_INITIALIZER(snap_blk_optslist.head), + .desc =3D { + { /*End of the list */ } + }, +}; + +static struct { + bool revert; /* Operation is snapshot revert */ + + int fd; /* Migration channel fd */ + int rp_fd; /* Return path fd (for postcopy) */ + + const char *blk_optstr; /* Command-line options for vmstate blockd= ev */ + QDict *blk_options; /* Blockdev options */ + int blk_flags; /* Blockdev flags */ + + bool postcopy; /* Use postcopy */ + bool save_vmstate; /* If true tool will get onle vmstate part= */ +} params; + +static StateSaveCtx state_save_ctx; +static StateLoadCtx state_load_ctx; + +static enum { + RUNNING =3D 0, + TERMINATED +} state; + +StateSaveCtx *get_save_context(void) +{ + return &state_save_ctx; +} + +StateLoadCtx *get_load_context(void) +{ + return &state_load_ctx; +} + +static void init_save_context(void) +{ + memset(&state_save_ctx, 0, sizeof(state_save_ctx)); +} + +static void destroy_save_context(void) +{ + /* TODO: implement */ +} + +static void init_load_context(void) +{ + memset(&state_load_ctx, 0, sizeof(state_load_ctx)); +} + +static void destroy_load_context(void) +{ + /* TODO: implement */ +} + +static BlockBackend *image_open_opts(const char *optstr, QDict *options, + int flags) +{ + BlockBackend *blk; + Error *local_err =3D NULL; + + /* Open image and create block backend */ + blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); + if (!blk) { + error_reportf_err(local_err, "Failed to open image '%s': ", optstr= ); + return NULL; + } + + blk_set_enable_write_cache(blk, true); + + return blk; +} + +/* Use BH to enter coroutine from the main loop */ +static void enter_co_bh(void *opaque) +{ + Coroutine *co =3D (Coroutine *) opaque; + qemu_coroutine_enter(co); +} + +static void coroutine_fn snapshot_save_co(void *opaque) +{ + StateSaveCtx *s =3D get_save_context(); + int res =3D -1; + init_save_context(); + + /* Block backend */ + s->blk =3D image_open_opts(params.blk_optstr, params.blk_options, + params.blk_flags); + if (!s->blk) { + goto fail; + } + + res =3D save_state_main(s); + if (res) { + error_report("Failed to save snapshot: %s", strerror(-res)); + +fail: + destroy_save_context(); + state =3D TERMINATED; +} + +static void coroutine_fn snapshot_load_co(void *opaque) +{ + StateLoadCtx *s =3D get_load_context(); + int res =3D -1; + + init_load_context(); + + /* Block backend */ + s->blk =3D image_open_opts(params.blk_optstr, params.blk_options, + params.blk_flags); + if (!s->blk) { + goto fail; + } + + res =3D load_state_main(s); + if (res) { + error_report("Failed to load snapshot: %s", strerror(-res)); + } + +fail: + destroy_load_context(); + state =3D TERMINATED; +} + +static void usage(const char *name) +{ + printf( + "Usage: %s [options] \n" + "QEMU External Snapshot Utility\n" + "\n" + "'image-blockspec' is a block device specification for vmstate ima= ge\n" + "\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n" + "\n" + "Options:\n" + " -T, --trace [[enable=3D]][,events=3D][,file=3D]\n" + " specify tracing options\n" + " -r, --revert revert to snapshot\n" + " --uri=3Dfd: specify migration fd\n" + " --page-size=3D specify target page size\n" + " --postcopy load ram in postcopy mode\n" + "\n" + QEMU_HELP_BOTTOM "\n", name); +} + +static void version(const char *name) +{ + printf( + "%s " QEMU_FULL_VERSION "\n" + "Written by Andrey Gruzdev.\n" + "\n" + QEMU_COPYRIGHT "\n" + "This is free software; see the source for copying conditions. Th= ere is NO\n" + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULA= R PURPOSE.\n", + name); +} + +enum { + OPTION_PAGE_SIZE =3D 256, + OPTION_POSTCOPY, + OPTION_URI, +}; + +static void process_options(int argc, char *argv[], StateInfo *si) +{ + static const char *s_opt =3D "rhVT:"; + static const struct option l_opt[] =3D { + { "page-size", required_argument, NULL, OPTION_PAGE_SIZE }, + { "postcopy", no_argument, NULL, OPTION_POSTCOPY }, + { "uri", required_argument, NULL, OPTION_URI }, + { "revert", no_argument, NULL, 'r' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { "trace", required_argument, NULL, 'T' }, + { "save-vmstate", no_argument, NULL, 'S' }, + { NULL, 0, NULL, 0 } + }; + + bool has_page_size =3D false; + bool has_uri =3D false; + + long target_page_size =3D qemu_real_host_page_size; + int uri_fd =3D -1; + bool revert =3D false; + bool postcopy =3D false; + const char *blk_optstr; + QemuOpts *blk_opts; + QDict *blk_options; + int c; + + while ((c =3D getopt_long(argc, argv, s_opt, l_opt, NULL)) !=3D -1) { + switch (c) { + case '?': + exit(EXIT_FAILURE); + + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + + case 'V': + version(argv[0]); + exit(EXIT_SUCCESS); + + case 'T': + trace_opt_parse(optarg); + break; + + case 'r': + if (revert) { + error_report("-r and --revert can only be specified once"); + exit(EXIT_FAILURE); + } + revert =3D true; + + break; + + case 'S': + params.save_vmstate =3D true; + + break; + + case OPTION_POSTCOPY: + { + if (postcopy) { + error_report("--postcopy can only be specified once"); + exit(EXIT_FAILURE); + } + postcopy =3D true; + + break; + } + + case OPTION_PAGE_SIZE: + { + const char *r; + + if (has_page_size) { + error_report("--page-size can only be specified once"); + exit(EXIT_FAILURE); + } + has_page_size =3D true; + + qemu_strtol(optarg, &r, 0, &target_page_size); + if (*r !=3D '\0' || + (target_page_size & (target_page_size - 1)) !=3D 0 || + target_page_size < PAGE_SIZE_MIN || + target_page_size > PAGE_SIZE_MAX) { + error_report("Invalid argument to --page-size"); + exit(EXIT_FAILURE); + } + + break; + } + + case OPTION_URI: + { + const char *p; + + if (has_uri) { + error_report("--uri can only be specified once"); + exit(EXIT_FAILURE); + } + has_uri =3D true; + + /* Only "--uri=3Dfd:" is currently supported */ + if (strstart(optarg, "fd:", &p)) { + const char *r; + long fd; + + qemu_strtol(p, &r, 10, &fd); + if (*r !=3D '\0' || fd <=3D STDERR_FILENO) { + error_report("Invalid FD value"); + exit(EXIT_FAILURE); + } + + uri_fd =3D qemu_dup_flags(fd, O_CLOEXEC); + if (uri_fd < 0) { + error_report("Could not dup FD %ld", fd); + exit(EXIT_FAILURE); + } + + /* Close original fd */ + close(fd); + } else { + error_report("Invalid argument to --uri"); + exit(EXIT_FAILURE); + } + + break; + } + + default: + g_assert_not_reached(); + } + } + + if ((argc - optind) !=3D 1) { + error_report("Invalid number of arguments"); + exit(EXIT_FAILURE); + } + + blk_optstr =3D argv[optind]; + + blk_opts =3D qemu_opts_parse_noisily(&snap_blk_optslist, blk_optstr, t= rue); + if (!blk_opts) { + exit(EXIT_FAILURE); + } + blk_options =3D qemu_opts_to_qdict(blk_opts, NULL); + qemu_opts_reset(&snap_blk_optslist); + + /* Enforced block layer options */ + qdict_put_str(blk_options, "driver", "qcow2"); + qdict_put_null(blk_options, "backing"); + qdict_put_str(blk_options, "overlap-check", "none"); + qdict_put_str(blk_options, "auto-read-only", "off"); + qdict_put_str(blk_options, "detect-zeroes", "off"); + qdict_put_str(blk_options, "lazy-refcounts", "on"); + qdict_put_str(blk_options, "file.auto-read-only", "off"); + qdict_put_str(blk_options, "file.detect-zeroes", "off"); + + params.revert =3D revert; + + if (uri_fd !=3D -1) { + params.fd =3D params.rp_fd =3D uri_fd; + } else { + params.fd =3D revert ? STDOUT_FILENO : STDIN_FILENO; + params.rp_fd =3D revert ? STDIN_FILENO : -1; + } + params.blk_optstr =3D blk_optstr; + params.blk_options =3D blk_options; + params.blk_flags =3D revert ? 0 : BDRV_O_RDWR; + params.postcopy =3D postcopy; + + si->page_size =3D target_page_size; + si->page_mask =3D ~(target_page_size - 1); + si->page_bits =3D ctz64(target_page_size); + si->slice_size =3D SLICE_SIZE; + si->slice_mask =3D ~(si->slice_size - 1); + si->slice_bits =3D ctz64(si->slice_size); +} + +int main(int argc, char **argv) +{ + Coroutine *co; + StateInfo state_info; + + os_setup_early_signal_handling(); + os_setup_signal_handling(); + error_init(argv[0]); + qemu_init_exec_dir(argv[0]); + module_call_init(MODULE_INIT_QOM); + qemu_init_main_loop(&error_fatal); + qemu_init_subsystems(); + + migration_object_init(); + qemu_add_opts(&qemu_trace_opts); + process_options(argc, argv, &state_info); + + if (!trace_init_backends()) { + exit(EXIT_FAILURE); + } + trace_init_file(); + qemu_set_log(LOG_TRACE); + + ram_init_state(); + + if (params.revert) { + co =3D qemu_coroutine_create(snapshot_load_co, &state_info); + } else { + co =3D qemu_coroutine_create(snapshot_save_co, &state_info); + } + aio_bh_schedule_oneshot(qemu_get_aio_context(), enter_co_bh, co); + + do { + main_loop_wait(false); + } while (state !=3D TERMINATED); + + exit(EXIT_SUCCESS); +} --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376225; cv=none; d=zohomail.com; s=zohoarc; b=AyLaG+2qkiP6Bk4srVaFGOQd8+icVL+0JxFjHSxDvsW1JD6h9yIYEjSLkGmwakkPGk+1nIVNpUnBNsuBBqHh2X2ZnE76eZze7TfaowDD2S49DD/vCn+tZYc2Pvu5SVWF8fNnaYrKHZl9eB22/2Oz4q0iXa7jGJ3p9f9H79eIEMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376225; h=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=ducfZ4paWMGIqaT6FCEcSnD0dMfGs217Vzqx2VvEnlI=; b=MWiXV7q6Ct6WC74GHKnkxpvEpGzHrhshXpkDqVKbN1g0JLNVHoWq6JobrRiknBwJzerUHHxTwzyyhAtENPSrjl1zthHORj/dgr1nBRpBWGnpunxaRhFdIkLhm3HaEqUltMdKuhAaJ6qmGepppOfeZesueuGMQ0VvEdk4WkgTWX4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376225217479.55178026564056; Thu, 16 Jun 2022 03:43:45 -0700 (PDT) Received: from localhost ([::1]:48172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1myW-0002AG-0K for importer@patchew.org; Thu, 16 Jun 2022 06:43:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjm-0001mb-2A for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:30 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]:36538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjk-0001sk-9r for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:29 -0400 Received: by mail-lj1-x234.google.com with SMTP id h23so1010679ljl.3 for ; Thu, 16 Jun 2022 03:28:27 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ducfZ4paWMGIqaT6FCEcSnD0dMfGs217Vzqx2VvEnlI=; b=A075IN1DaGyrPn2Mx34pUcHyL0RVFBA5UQJNmLatFrLa59iCRthazLvhakcGdn6u6O G8uiZ/tmC33WG1mIzN1aRQ+deOy6KktAMJsZkRho+XkaLvi3yDk3aT4RsNscmJeHTKXt SNKq1lD7K3X5X5LApnYnnuVkFtN8KlD3sU203URX4Lvp7Q1NsZfRic/vhlhH7tHI0zdj 6ewtvDbWljv08j/TCmVc/3+EYEfsGuPJ9PLwqCNB06ORd2fGlIKa3Bgli3orAafwJWv6 xLnBwNge3oS0nSOdk9Eog1aHkui5q85y14qWj2xvGhhdakPlc+42t6IBEbPdABEl/BNV ShDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ducfZ4paWMGIqaT6FCEcSnD0dMfGs217Vzqx2VvEnlI=; b=Nx2+TW+BC8nX4bXJf/ekclacs8yZjreWJNkgwdJ9Hzqm/sAEcnFqH1zSvssT7iilpo /X+Q20ppGZqpP+YLEgmIb6VrX7uARjbyYVMfSjEhcwo8XLHKsl9kS3TDVyduyeJp2D+T /ZTmlcWkmJBdZwTQd1wWvkhc9yPBhVhDHAs1Rg/V8wmimu596P4d2hha1nN/VVcMIGdz biY0wN/kE5qXUGEPtyQ1Tu7NUlfWKjGHGoCl1d/ZdKVMtVYJ25dxGEgdjaGuXOVSw7Wn H5eCbgKiBYLdTcZwtfJqiCZUQSjtNb6ufDVLfO2I6uuxsXEXNUz2gYakENd7LeAb/P5G 26cg== X-Gm-Message-State: AJIora8e9N0JJdDzd1MEEFlS+QGxy0yGmFJtLKkRqv0tbTtsU+bP68EN KbUD+jOmgvVyFAQGHLf4zioGdLxqgv8E6st8 X-Google-Smtp-Source: AGRyM1uB9WC8CRW/diHiWSTC6ByZNd4C6kpgHarJUyqT1d8Z+8gdfvF37AZWtNIEl9YuxGZWtjdHJA== X-Received: by 2002:a2e:9815:0:b0:255:be2d:2fae with SMTP id a21-20020a2e9815000000b00255be2d2faemr2087031ljj.435.1655375306650; Thu, 16 Jun 2022 03:28:26 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 10/17] migration/snapshot: Build changes for qemu-snapshot-tool Date: Thu, 16 Jun 2022 13:28:04 +0300 Message-Id: <20220616102811.219007-11-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::234; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x234.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376226484100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Tool uses part of migration code thus new lib with stubs for migration code is added here. Signed-off-by: Nikita Lapshin --- meson.build | 18 ++++++++++++++++++ migration/meson.build | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 2d6601467f..ba3b9ab4bd 100644 --- a/meson.build +++ b/meson.build @@ -3287,6 +3287,16 @@ if xkbcommon.found() endif =20 if have_tools + tool_inc =3D include_directories('include/hw/core', 'include') + lib_tool =3D static_library('snapshot-tool', + sources: [migration_files], + dependencies: arch_deps, + include_directories: [tool_inc, target_inc], + name_suffix: 'fa', + build_by_default: false) + snapshot_tool =3D declare_dependency(link_with: lib_tool, + dependencies: [zlib, qom, io]) + qemu_img =3D executable('qemu-img', [files('qemu-img.c'), hxdep], dependencies: [authz, block, crypto, io, qom, qemuutil], inst= all: true) qemu_io =3D executable('qemu-io', files('qemu-io.c'), @@ -3294,6 +3304,14 @@ if have_tools qemu_nbd =3D executable('qemu-nbd', files('qemu-nbd.c'), dependencies: [blockdev, qemuutil, gnutls, selinux], install: true) + qemu_snapshot =3D executable('qemu-snapshot', + files('qemu-snapshot.c'), + dependencies: [snapshot_tool] + arch_deps + d= eps, + objects: lib.extract_all_objects(recursive: t= rue), + link_depends: [block_syms, qemu_syms], + link_args: link_args, + + install: true) =20 subdir('storage-daemon') subdir('contrib/rdmacm-mux') diff --git a/migration/meson.build b/migration/meson.build index 8b5ca5c047..13498a6db3 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -7,6 +7,8 @@ migration_files =3D files( 'qemu-file-channel.c', 'qemu-file.c', 'yank_functions.c', + 'migration.c', + 'qemu-snapshot.c', ) softmmu_ss.add(migration_files) =20 @@ -18,7 +20,6 @@ softmmu_ss.add(files( 'exec.c', 'fd.c', 'global_state.c', - 'migration.c', 'multifd.c', 'multifd-zlib.c', 'postcopy-ram.c', --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376897; cv=none; d=zohomail.com; s=zohoarc; b=aRMiF6qbegawZcjb0k5ee8xMsLcMEXn44ZNAT+0KAoc9zJibl147dD37fDrhxR6e4X3xjtUtTXtsZnwz8kZv7unbWCEgj3fkh5PIYRtdrQkIqxRah5l+QEXpz3PuZZqlRw8iDmFgqE98BsBDs/gVKHhWFm4ZPMbFXYB2hPly+rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376897; h=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=k/hGN5VojSTuOV/b5lvNLOT0NN3UmseiinK0nUtnYSI=; b=nknwdvxm5yQy3VcD/Xld9O3u4pUGDWEuLhbWE7NJe+VFER4o1f9ZeeeOd1JQHfS5FA2gg1OlfO2+CLGX4sBB0PWxAWL113SdOmxBUD6aF8vNNdg+YpeKkDoQzUE5nHc+sak2h/TGibrOqfbcfSYcyXePw6WDQ8YJ1EKruitkz+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376897317964.1544494422976; Thu, 16 Jun 2022 03:54:57 -0700 (PDT) Received: from localhost ([::1]:35006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n9M-0004Kn-5q for importer@patchew.org; Thu, 16 Jun 2022 06:54:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjo-0001p0-BC for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:33 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]:33749) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjl-0001uw-QD for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:31 -0400 Received: by mail-lf1-x130.google.com with SMTP id c2so1578973lfk.0 for ; Thu, 16 Jun 2022 03:28:29 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k/hGN5VojSTuOV/b5lvNLOT0NN3UmseiinK0nUtnYSI=; b=RqdFyHIOImshae9f91jFeJrTxr/yiUMF1MEuCjHBWuCGyzDjBQQf01HXwbAcl7t08s sGY2ZP448lHqotWFbcrXicK5qENUO7jzfMGSxOQMPeYTWHEvQgMXIWG9OTrmjlVbVofJ MMbNGT7IBm1eKbHqbUGQgIr/h18mv2NyMd6+DxUpu3YNKjyM38ibp6d2n+HAE2jX/pom iuMrcbb5lCSVBlMWNKHurTd667Kdvw5MZe2UJardj4nd9BwOqeMiZ029VcA0g+p172th 7bNfrPHdRdveghwnzrTG2F2EnrWbI0tnJ4yGfhKuJ/Xpay1+hFEpT146E4qMXz7pc60j 6xWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k/hGN5VojSTuOV/b5lvNLOT0NN3UmseiinK0nUtnYSI=; b=64heXtyuPml8d9OJjaW0OU+v4W7PHsNQGDxlTR7WCSV2osn9Gkdu2YpgukH8TmzejV ejSRWYodzFhopE4ZPLkho4NsQbH03V2mUh/Sr6qG8Da+jUgHXmAOoEURBze51/t3uT2I p+iykifuOxd4P8/AreaeAtauQc0SUUmJvaDeGYRdrV/Bb8q4wpS4d1tKevkkS/5OmiAV av9QLFf5e2+fx6ZzAskI+5gt3ROTpig42oelulECf/PBzA06KrrCPlll0iIhmlJp4W8X ws5d0lirUoqGV0w03RScZpi+ZtdM6KQEK73bBzgJiFZ228Ct5fbMyO4tEU1yJR0z9iqo FI8A== X-Gm-Message-State: AJIora+Hn+fbo1qjp0AxkXK0ZtLPaS9Jrd4mzfn7z+QqF71+2EgFZ1u7 k7H6Z7sV70I+sAbRhpccviSTuidm6zET1Y3y X-Google-Smtp-Source: AGRyM1vmIp3aXeGW7aYlAeS83h8H5l7Kdw5Sm5h87A1tjP96KIZxdsJDOfYwAHGR5ZVELZpN0ClDqg== X-Received: by 2002:a05:6512:3130:b0:479:385f:e2ac with SMTP id p16-20020a056512313000b00479385fe2acmr2268847lfd.575.1655375307841; Thu, 16 Jun 2022 03:28:27 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 11/17] migration/qemu-file: Fix qemu_ftell() for non-writable file Date: Thu, 16 Jun 2022 13:28:05 +0300 Message-Id: <20220616102811.219007-12-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::130; envelope-from=nikita.lapshin@openvz.org; helo=mail-lf1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376899708100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin qemu_ftell() will return wrong value for non-writable QEMUFile. This happens due to call qemu_fflush() inside qemu_ftell(), this function won't flush if file is readable. Signed-off-by: Nikita Lapshin --- migration/qemu-file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 1479cddad9..53ccef80ac 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -663,7 +663,8 @@ int64_t qemu_ftell_fast(QEMUFile *f) int64_t qemu_ftell(QEMUFile *f) { qemu_fflush(f); - return f->pos; + /* Consider that qemu_fflush() won't work if file is non-writable */ + return f->pos + f->buf_index; } =20 int qemu_file_rate_limit(QEMUFile *f) --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376918; cv=none; d=zohomail.com; s=zohoarc; b=oEhFb8oFn3nlnOh2cqfz83XG2GHMjEolMYJihc2P6JPE0IEdLBmmMnZ+L/tbHLqU6gyvvL6XsZHl3jEVLyCN3fn0EtOQ+Ncq+MbQIhqzvBq/T5aLLth6gBv1DXXObRzOhgpJtGMXVIvdhqY/KuqaO0xT6HpemXdHZWeLA8V0hCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376918; h=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=A+vAUD5r+ra5troGbu4m4n5hv4XEb2YdZlgZ0icNGgs=; b=fCyMO8uLoFzrDNlbumnyJQToWi/PmukMyTn9lx9OJqvM6vaL4fbeIg0PGdzbhJSCtViD7XRvm9+sj3zXSyDVQCYmjWvQMcxJC6fIE8fPf0HnHCwdZ0JVteCxUUDAxGyshiC0GjwqUCqAf4y+2CejBvLrWJFMyTBh5FqWAOJJaq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376918968619.6754279775001; Thu, 16 Jun 2022 03:55:18 -0700 (PDT) Received: from localhost ([::1]:35994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n9h-000515-8d for importer@patchew.org; Thu, 16 Jun 2022 06:55:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjo-0001p1-Bh for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:33 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:42517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjm-0001v3-Hu for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:31 -0400 Received: by mail-lj1-x236.google.com with SMTP id c30so992422ljr.9 for ; Thu, 16 Jun 2022 03:28:30 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A+vAUD5r+ra5troGbu4m4n5hv4XEb2YdZlgZ0icNGgs=; b=WuTIUa89yOUjicF6h1P+zrFlp0GJSArDtlB4QqmYNWeT7PDdChyLmW6vjGDj/XQGBD 651hWb7iy1ESuKHt0Oo6SxU0wIHKyekmABa+3Vf17WwMtWS0dAr+ZXJvGTdFQuhCQ3XO DNQIZvOs0bDczn3qZ5qPP02p+J6pL2Zk1H0atgVGs2VuMGySQFI646+qoNg7pVGiwiQK MxFhG+HTGTb0L6SaVWIjDS2C4Z5AQJxy/csMAW9IBOAd7NEgwVkTsfa9Li+IiJhmkR9a BynLn3N7Gid7h+km3tV3BmG0ZLWqVCCjQ+wMgm9nBltd/RPbGocdKdp43ZS/3BjLrri6 6kbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A+vAUD5r+ra5troGbu4m4n5hv4XEb2YdZlgZ0icNGgs=; b=Yg0NlcbJYJ361WVHHVtmRYpkDWBjUQAoqVIoqzgzldDCZLIIDVcx9eyjUNIvp3Unuu HbCZojQCP2IIeSOboPjYvQ1+a6vApH+NlKJqCgM2MoLWFtR1NraNKoDTY2vtasTOBQtL WaXVww/trlkAXGnPAxDalyYbyGrDCEbEeWdcMC0aG9UmavB3peDaKXssSnvwxvKHV1sn Q9L36spoD8jteYAHXVmaVFT2XrdkbL2PLbN4cLqE/cHTuXEHFUV8b7Sd7hPsTDhkODzv +1CwACFo2tONo1kV+y32cxj9BL+2HzQXVQO7KSjq3t01szHF1jd+jYThDZi0DwIEen4u dyaQ== X-Gm-Message-State: AJIora9ECOHdsQbCVZP/MFqfg2ANrNX416GFWPzERJNP0Wssz9InFeJV A702UXIv1Jn8chjNbW8PMQA6AxftfrUSDvQy X-Google-Smtp-Source: AGRyM1sjcqqr6wa28eikzPE+S4DNfTic7PmkrMttoB1RQn6jNQVQb4CUcV9bw21dxHjDjhAJUarsiQ== X-Received: by 2002:a2e:3a16:0:b0:255:7811:2827 with SMTP id h22-20020a2e3a16000000b0025578112827mr2152565lja.130.1655375308820; Thu, 16 Jun 2022 03:28:28 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 12/17] migration/snapshot: Move RAM_SAVE_FLAG_xxx defines to migration/ram.h Date: Thu, 16 Jun 2022 13:28:06 +0300 Message-Id: <20220616102811.219007-13-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::236; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x236.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376920636100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Move RAM_SAVE_FLAG_xxx defines from migration/ram.c to migration/ram.h Signed-off-by: Nikita Lapshin --- migration/ram.c | 16 ---------------- migration/ram.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index ddc7abd08a..da7c7ec0e5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -66,22 +66,6 @@ /***********************************************************/ /* ram save/restore */ =20 -/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it - * worked for pages that where filled with the same char. We switched - * it to only search for the zero value. And to avoid confusion with - * RAM_SSAVE_FLAG_COMPRESS_PAGE just rename it. - */ - -#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ -#define RAM_SAVE_FLAG_ZERO 0x02 -#define RAM_SAVE_FLAG_MEM_SIZE 0x04 -#define RAM_SAVE_FLAG_PAGE 0x08 -#define RAM_SAVE_FLAG_EOS 0x10 -#define RAM_SAVE_FLAG_CONTINUE 0x20 -#define RAM_SAVE_FLAG_XBZRLE 0x40 -/* 0x80 is reserved in migration.h start with 0x100 next */ -#define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 - XBZRLECacheStats xbzrle_counters; =20 /* struct contains XBZRLE cache and a static page diff --git a/migration/ram.h b/migration/ram.h index 2c6dc3675d..9dddfd381a 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -33,6 +33,22 @@ #include "exec/cpu-common.h" #include "io/channel.h" =20 +/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it + * worked for pages that where filled with the same char. We switched + * it to only search for the zero value. And to avoid confusion with + * RAM_SSAVE_FLAG_COMPRESS_PAGE just rename it. + */ + +#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ +#define RAM_SAVE_FLAG_ZERO 0x02 +#define RAM_SAVE_FLAG_MEM_SIZE 0x04 +#define RAM_SAVE_FLAG_PAGE 0x08 +#define RAM_SAVE_FLAG_EOS 0x10 +#define RAM_SAVE_FLAG_CONTINUE 0x20 +#define RAM_SAVE_FLAG_XBZRLE 0x40 +/* 0x80 is reserved in migration.h start with 0x100 next */ +#define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 + extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; extern CompressionStats compression_counters; --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655377230; cv=none; d=zohomail.com; s=zohoarc; b=GVSYW7sqsT9i4nTyGCSxoE9lf8AeyBcYvjO9Zvi4iWV8yP/PaOmuz80lQ5Xjl7l8+1h9Z3gsVRpFyWskcAizcrHmZwN1nQAZa+nvtgajMYicUJ1h9dJkwMvJXHzvZSUcOjvIPzLqRJqu/qJk0hTNjEK3sbRuH0fMwuWGO3iyq5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655377230; h=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=pWGCHW+lQRAJRjV07RDQFguV/KMNn0rs6neHhcaYk04=; b=RWjNPU7CbqXDdUdSM9dfWStZTdJuIRWlwE5l8U/cqOlZJ8Hmiopsz2lN7cAGGx2dCXPyPsHc2aWF5xKWjhAkXBlxiQTH7lqld2CRItCMmD7yANtX1QwwOCo9D38lG8Sv+X4UnNLScqoLwe8O2s5ZRt4sNXxdXZLGd5JYgbakzmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655377230143935.0815894991031; Thu, 16 Jun 2022 04:00:30 -0700 (PDT) Received: from localhost ([::1]:43472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nEj-0001iJ-0l for importer@patchew.org; Thu, 16 Jun 2022 07:00:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjq-0001qX-C9 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:34 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:33746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjo-0001vR-3f for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:33 -0400 Received: by mail-lf1-x12c.google.com with SMTP id c2so1579095lfk.0 for ; Thu, 16 Jun 2022 03:28:31 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pWGCHW+lQRAJRjV07RDQFguV/KMNn0rs6neHhcaYk04=; b=8DbDXN7G445MA2lSQqCCcpR5QjleIGwltnWZfl0wrNPbmxaEuHaOL3lEwpI45a7iYj J9xzHRm/H7PgUfVt9gCODinKmoMHbqpKBFiBtd++anPQxkZTAqlGTRWfJH/ABDbQTjNw 8u2jTA4GDFimzb8jWpAyAHbHspgzPxzMwkV13O63sU47WmUX+uV9tncicRHvOY2gVKBx VV7Bpiyvk9snbonKkuHdMiH8VVFJNH3P8/u8/i1nVNJMvwY09kFSmItY9MpEXLaL1533 8OhCSsLqLceM3VrlNpu1TnSoVmEn+cpkTq/MCTp9a7dItauguM431QvHWSpUiOKwYHA3 hr4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pWGCHW+lQRAJRjV07RDQFguV/KMNn0rs6neHhcaYk04=; b=GqWeKtHMYjXrIutdxoKFWZHBNvwSXTq2GPRUO8napeMsfHUdG/fUojdFIubK9/Hz9e cLKc4he+95/xx6/I9WkFoV1f3hCOh4baTtKcNudcqTvVSw5C7CKu2J+ZYb4mffT3wt8N SnFyflCI6QBbbBVpVJ2cadabIlSkR+I6Gth1ipv2ojcekloKV/mf9n0T+2a4gYij98vx Y+SjMNKHRLGSITnDtPbMrVpuQVbWTJlRJ5C63OGQRR/YPQJfSCOsQYGT+eB5QpKw0EdT AXHwzSPjfD86SRi9yz8Plia4WFKAxackQ+ArIJ62gYpnPO6sCvz3+esc/IbRNx3YvEAW s4Yg== X-Gm-Message-State: AJIora/qVF4rnwRtf55bzvLi7Xm7fRWIZB6vt4fA0fAA4b/0cAImrztC jaKDH/zMJ4Zyojddwh9rKJ73V9takiJZldas X-Google-Smtp-Source: AGRyM1tZSzWWx4jHGOoQMv2tPqvCxNkY2RLTbk8ZmEfWKw9Oy7TqT5BlJp/hMl1NrNvnu2R3pZe4Qg== X-Received: by 2002:a19:a417:0:b0:479:15ef:4ded with SMTP id q23-20020a19a417000000b0047915ef4dedmr2192149lfc.225.1655375309718; Thu, 16 Jun 2022 03:28:29 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 13/17] migration/snapshot: Block layer support in qemu-snapshot Date: Thu, 16 Jun 2022 13:28:07 +0300 Message-Id: <20220616102811.219007-14-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::12c; envelope-from=nikita.lapshin@openvz.org; helo=mail-lf1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655377232298100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin This commit enables few functions to simplify block layer work for qemu-snapshot tool. Signed-off-by: Nikita Lapshin --- include/qemu-snapshot.h | 3 + migration/meson.build | 1 + migration/qemu-snapshot-io.c | 112 +++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 migration/qemu-snapshot-io.c diff --git a/include/qemu-snapshot.h b/include/qemu-snapshot.h index 8e548e7630..be2557f6a0 100644 --- a/include/qemu-snapshot.h +++ b/include/qemu-snapshot.h @@ -62,4 +62,7 @@ StateLoadCtx *get_load_context(void); int coroutine_fn save_state_main(StateSaveCtx *s); int coroutine_fn load_state_main(StateLoadCtx *s); =20 +QEMUFile *qemu_fopen_bdrv_vmstate(BlockDriverState *bs, int is_writable); +void qemu_fsplice(QEMUFile *f_dst, QEMUFile *f_src, size_t size); +size_t qemu_fsplice_tail(QEMUFile *f_dst, QEMUFile *f_src); #endif /* QEMU_SNAPSHOT_H */ diff --git a/migration/meson.build b/migration/meson.build index 13498a6db3..3a04576c30 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -9,6 +9,7 @@ migration_files =3D files( 'yank_functions.c', 'migration.c', 'qemu-snapshot.c', + 'qemu-snapshot-io.c' ) softmmu_ss.add(migration_files) =20 diff --git a/migration/qemu-snapshot-io.c b/migration/qemu-snapshot-io.c new file mode 100644 index 0000000000..904cb92c84 --- /dev/null +++ b/migration/qemu-snapshot-io.c @@ -0,0 +1,112 @@ +/* + * QEMU External Snapshot Utility + * + * Copyright Virtuozzo GmbH, 2021 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/coroutine.h" +#include "sysemu/block-backend.h" +#include "migration/qemu-file.h" +#include "qemu-snapshot.h" + +static ssize_t bdrv_vmstate_get_buffer(void *opaque, uint8_t *buf, int64_t= pos, + size_t size, Error **errp) +{ + return bdrv_load_vmstate((BlockDriverState *) opaque, buf, pos, size); +} + +static ssize_t bdrv_vmstate_writev_buffer(void *opaque, struct iovec *iov, + int iovcnt, int64_t pos, Error **errp) +{ + QEMUIOVector qiov; + int res; + + qemu_iovec_init_external(&qiov, iov, iovcnt); + + res =3D bdrv_writev_vmstate((BlockDriverState *) opaque, &qiov, pos); + if (res < 0) { + return res; + } + + return qiov.size; +} + +static int bdrv_vmstate_fclose(void *opaque, Error **errp) +{ + return bdrv_flush((BlockDriverState *) opaque); +} + +static const QEMUFileOps bdrv_vmstate_read_ops =3D { + .get_buffer =3D bdrv_vmstate_get_buffer, + .close =3D bdrv_vmstate_fclose, +}; + +static const QEMUFileOps bdrv_vmstate_write_ops =3D { + .writev_buffer =3D bdrv_vmstate_writev_buffer, + .close =3D bdrv_vmstate_fclose, +}; + +/* Create QEMUFile to access vmstate stream on QCOW2 image */ +QEMUFile *qemu_fopen_bdrv_vmstate(BlockDriverState *bs, int is_writable) +{ + if (is_writable) { + return qemu_fopen_ops(bs, &bdrv_vmstate_write_ops, true); + } + + return qemu_fopen_ops(bs, &bdrv_vmstate_read_ops, true); +} + +/* Move number of bytes from the source QEMUFile to destination */ +void qemu_fsplice(QEMUFile *f_dst, QEMUFile *f_src, size_t size) +{ + size_t rest =3D size; + + while (rest) { + uint8_t *ptr =3D NULL; + size_t req_size; + size_t count; + + req_size =3D MIN(rest, INPLACE_READ_MAX); + count =3D qemu_peek_buffer(f_src, &ptr, req_size, 0); + qemu_file_skip(f_src, count); + + qemu_put_buffer(f_dst, ptr, count); + rest -=3D count; + } +} + +/* + * Move data from source QEMUFile to destination + * until EOF is reached on source. + */ +size_t qemu_fsplice_tail(QEMUFile *f_dst, QEMUFile *f_src) +{ + bool eof =3D false; + size_t res =3D 0; + + while (!eof) { + const size_t size =3D INPLACE_READ_MAX; + uint8_t *buffer =3D NULL; + size_t count; + + count =3D qemu_peek_buffer(f_src, &buffer, size, 0); + qemu_file_skip(f_src, count); + + /* Reached EOF on source? */ + if (count !=3D size) { + eof =3D true; + } + + qemu_put_buffer(f_dst, buffer, count); + res +=3D count; + } + + return res; +} --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655376589; cv=none; d=zohomail.com; s=zohoarc; b=UYQcdcizC0Ove8xKIg5sIwpmNIUnLbdikzobSBjouY0shoywmdP2L7t4ZhAsRPq/Tk1IZz4AKVgdWjwvYDG+s03WyOcm8g3QkGt7djk6DctssYhP92nzqj+XGKEJyM2Ey43H/IjHNpckwTr7cjxoWpXpJQO/dcDa/eBy0MXSSKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655376589; h=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=WJ7+MX4Kqnm+nK5yrjeUKJvlApxuSFy4g1bDKgqMtkM=; b=S4xIigqY5wY5kzMu3KcMyCV9CpjBr/Bx7UlvBt6Fx5xoR8uJbgt2FUSPYIK+8yMsdlfEeFY8aOsf3dLdcEh74YNgj9mfPA7Fn+6CpZ0VydayOBTyEtz0efGjJ6mNMxUlBHS6Y1YjqxhwQI92mLBvNj3173BESljYsrPv4sxRt7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655376589139661.5080040380003; Thu, 16 Jun 2022 03:49:49 -0700 (PDT) Received: from localhost ([::1]:56724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1n4N-0007zP-C9 for importer@patchew.org; Thu, 16 Jun 2022 06:49:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjq-0001rg-QI for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:34 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]:40570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjo-0001ve-IT for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:34 -0400 Received: by mail-lj1-x232.google.com with SMTP id y29so1002409ljd.7 for ; Thu, 16 Jun 2022 03:28:32 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WJ7+MX4Kqnm+nK5yrjeUKJvlApxuSFy4g1bDKgqMtkM=; b=7Qf9jQEMlBgMKVaWrCX5RNsqPY9Dt8n1CgZ0nSfSPVkIwnRCxqWg+StKjtHCUHe50n aowB2iwXdUUTv99QuyeeecdvsxU6wWssFrWVc7SGXYjxdrr+J4nw2ze9mzK0aH4VZGiQ tt/1SfHr9yoKa8YSXy083etzTJC0lmQ0Wr7MydH2L/z4oDazc7oGHVTyS5rN0WIDDlh8 DOkEUGq5ubR5UvfUhE5sKZanIQNNKo3uXpBpmnFsl3VKsOOZNqtMvjcLTYZPiYkg+Na4 i1PDFeNQvS2JGwKpGLpF4w7IIQOgRu0UDkuz/izfPy6/kmPc9Y3p5YeQ1b35fGOMVOvB sZtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WJ7+MX4Kqnm+nK5yrjeUKJvlApxuSFy4g1bDKgqMtkM=; b=oaSzW55UFYvr7dY41wx/OxrlDmk/ge5zp4tpJejMCuygX0mlhmCZ/MujSmLiHDlv3e XgmQV6vwmElwVZ2l/RdRecv7LnP2nKRxxK2ZcPC1vToogb5FnxhgpMNY/O4OWlxKeP+I qPEgbV0KXqof1e+IB1A19zZdpbUOORmVtPhYGkwf0SfP/Egi3aPEZ+1CF8E4GtN9jpsv 3N9UUzxDVZkZFEjW7iKTvy24A7/O6QNXZbQ6htEzV8J/F9JwiMYKCIukIWSWbCQ+f7c2 y/7xVlAwuTH5U7qjRzGdgBNnHRzsp5xNRYkVSfFTkCfay+h8ALWwFY8dhV93n5C3FSoA 5vxw== X-Gm-Message-State: AJIora8pd4jQpZQvChOwss+PgfA8ELS8u0qYhFUws8geKjRzHiHkhHA2 SMbwCA5rehZ+fFfzXMAE7VRpuGWU9M7Z48m0 X-Google-Smtp-Source: AGRyM1vu1Ab4oFkM5jMh/0T5xIhCWDlRW8p0IdWxtACQ4+A0HriJOdxQWzqT1efAXPprQOKhm6b1ag== X-Received: by 2002:a2e:819a:0:b0:255:615c:6570 with SMTP id e26-20020a2e819a000000b00255615c6570mr2062917ljg.17.1655375310852; Thu, 16 Jun 2022 03:28:30 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 14/17] migration/snpashot: Implement API for RAMBlock Date: Thu, 16 Jun 2022 13:28:08 +0300 Message-Id: <20220616102811.219007-15-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::232; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x232.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655376591287100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Implemented RAMBlock is used for managing ram block from VM. This structure is close to existing RAMBlock in migration but has few differences. May be it should be replaced with existing RAMBlock it can lead to lots of reuses. Signed-off-by: Nikita Lapshin --- migration/qemu-snapshot.c | 180 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/migration/qemu-snapshot.c b/migration/qemu-snapshot.c index f7695e75c7..394c6acb77 100644 --- a/migration/qemu-snapshot.c +++ b/migration/qemu-snapshot.c @@ -23,13 +23,193 @@ #include "migration/ram.h" #include "qemu-snapshot.h" =20 +/* RAM block */ +/* TODO RAMBlock should be replace with existing struct RAMBlock in ram.c = */ +typedef struct RAMBlock { + int64_t bdrv_offset; /* Offset on backing storage */ + int64_t length; /* Length */ + int64_t nr_pages; /* Page count */ + int64_t nr_slices; /* Number of slices (for bitmap bookkeepin= g) */ + int64_t discard_offset; /* Used for postcopy dicarding of ram bloc= ks */ + + unsigned long *bitmap; /* Bitmap of RAM slices */ + + /* Link into ram_list */ + QSIMPLEQ_ENTRY(RAMBlock) next; + + char idstr[256]; /* RAM block id string */ +} RAMBlock; + /* RAM transfer context */ typedef struct RAMCtx { int64_t normal_pages; /* Total number of normal pages */ + + /* RAM block list head */ + QSIMPLEQ_HEAD(, RAMBlock) ram_block_list; + } RAMCtx; =20 static RAMCtx ram_ctx; =20 +static inline +bool ram_offset_in_block(RAMBlock *block, int64_t offset) +{ + return block && offset < block->length; +} + +static inline +bool ram_bdrv_offset_in_block(RAMBlock *block, int64_t bdrv_offset) +{ + return block && bdrv_offset >=3D block->bdrv_offset && + bdrv_offset < block->bdrv_offset + block->length; +} + +static inline +int64_t ram_bdrv_from_block_offset(RAMBlock *block, int64_t offset) +{ + if (!ram_offset_in_block(block, offset)) { + return INVALID_OFFSET; + } + + return block->bdrv_offset + offset; +} + +static inline +int64_t ram_block_offset_from_bdrv(RAMBlock *block, int64_t bdrv_offset) +{ + int64_t offset; + + if (!block) { + return INVALID_OFFSET; + } + + offset =3D bdrv_offset - block->bdrv_offset; + return offset >=3D 0 ? offset : INVALID_OFFSET; +} + +static RAMBlock *ram_block_by_idstr(const char *idstr) +{ + RAMBlock *block; + + QSIMPLEQ_FOREACH(block, &ram_ctx.ram_block_list, next) { + if (!strcmp(idstr, block->idstr)) { + return block; + } + } + + return NULL; +} + +/* + * Assume QEMUFile is migration stream and try to get ram block from it. + * Also check if this ram block exists. + */ +static RAMBlock *ram_block_from_stream(QEMUFile *f, int flags) +{ + static RAMBlock *block; + char idstr[256]; + + if (flags & RAM_SAVE_FLAG_CONTINUE) { + if (!block) { + error_report("RAM_SAVE_FLAG_CONTINUE outside RAM block"); + return NULL; + } + + return block; + } + + if (!qemu_get_counted_string(f, idstr)) { + error_report("Failed to get RAM block name"); + return NULL; + } + + block =3D ram_block_by_idstr(idstr); + if (!block) { + error_report("Can't find RAM block %s", idstr); + return NULL; + } + + return block; +} + +static int64_t ram_block_next_bdrv_offset(void) +{ + RAMBlock *last_block; + int64_t offset; + + last_block =3D QSIMPLEQ_LAST(&ram_ctx.ram_block_list, RAMBlock, next); + if (!last_block) { + return 0; + } + + offset =3D last_block->bdrv_offset + last_block->length; + return ROUND_UP(offset, BDRV_CLUSTER_SIZE); +} + +static void ram_block_add(const char *idstr, int64_t size) +{ + RAMBlock *block; + + block =3D g_new0(RAMBlock, 1); + block->length =3D size; + block->bdrv_offset =3D ram_block_next_bdrv_offset(); + strcpy(block->idstr, idstr); + + QSIMPLEQ_INSERT_TAIL(&ram_ctx.ram_block_list, block, next); +} + +/* + * Assume that QEMUFile is migration stream and try to get + * from f_src ram blocks list. mem_size is a total amount of bytes of whole + * ram blocks. + */ +static int ram_block_list_from_stream(QEMUFile *f_src, int64_t mem_size) +{ + int64_t total_ram_bytes; + + total_ram_bytes =3D mem_size; + while (total_ram_bytes > 0) { + char idstr[256]; + int64_t size; + + if (!qemu_get_counted_string(f_src, idstr)) { + error_report("Failed to get RAM block list"); + return -EINVAL; + } + + size =3D qemu_get_be64(f_src); + + ram_block_add(idstr, size); + total_ram_bytes -=3D size; + } + + if (total_ram_bytes !=3D 0) { + error_report("Corrupted RAM block list"); + return -EINVAL; + } + + return 0; +} + +/* Send ram block list using migration rule */ +static int ram_block_list_to_stream(QEMUFile *f_dest) +{ + RAMBlock *block; + uint64_t total =3D 0; + + QSIMPLEQ_FOREACH(block, &ram_ctx.ram_block_list, next) { + total +=3D block->length; + } + qemu_put_be64(f_dest, total | RAM_SAVE_FLAG_MEM_SIZE); + + QSIMPLEQ_FOREACH(block, &ram_ctx.ram_block_list, next) { + qemu_put_counted_string(f_dest, block->idstr); + qemu_put_be64(f_dest, block->length); + } + + return qemu_file_get_error(f_dest); +} + int coroutine_fn save_state_main(StateSaveCtx *s) { /* TODO: implement */ --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655377313; cv=none; d=zohomail.com; s=zohoarc; b=jlO1iHn9L/Bi/plnf8MmXZk+9WuBnpgnDhkeGsNs/nZPqAFr94CXn3Nz38P17i7eGnd2Gjd/IuAHWYNrU9iv9JRJux7Zhq7AvxgGGvo2gdBu9ckoFg8+KtbV1Pbo8Sx1aPbOzPozFJQ+kxC4MU/D41UBYweiVQfAH3j+Gv8dG2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655377313; h=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=NVimrfo1WRRp/eG3/ytGXha95uSKgbpn29KOe/rszUE=; b=X3p7jY8HilT8vPrb45Sr/ajRau5El3nryMMyVOAirJ9dMXUlZBy8zqX+HKZOWgzJO54pjc70QiAw996I7nrnHBXA2hAm550qQTwpbsX/+AThcfbCm1Q1jg6yJ0L+XmjC2BliJBgcoMKHnM47Zv97q4zbhUq4j0c1rimFE74oPLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655377313054343.9133056741574; Thu, 16 Jun 2022 04:01:53 -0700 (PDT) Received: from localhost ([::1]:44560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nG3-0002SQ-E1 for importer@patchew.org; Thu, 16 Jun 2022 07:01:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjs-0001xA-Nl for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:36 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:40574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjq-0001vt-4B for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:36 -0400 Received: by mail-lj1-x236.google.com with SMTP id y29so1002468ljd.7 for ; Thu, 16 Jun 2022 03:28:33 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NVimrfo1WRRp/eG3/ytGXha95uSKgbpn29KOe/rszUE=; b=m4+1Fh9OQjF/7sTQ5ma1DrKT887sfNIIxvzyPVcHaFmM4sb2otAHbX+RJtOpJHDn90 t54Kyzvba0eNaO9V2tFfDyW52MngkT/CdBfRdZy3dpKwXQs/g3g83FK3H7lHd1lOrMbS sMEW7IC3OJ5jPbSJDZ2Sbox0pnHF+Ca7cRfq+i+Zk74TnAQMkmCO4of+uJrKynQQlI82 ulet5wuOLn8xDNeKUrFq9mQslnNCm34X/k4Zc+10/0SeKcIPT40LJnTZTe+p7PiDmRbD cq41fQ//aboJEOcIZ4ftYd1ULfkuLxoI+TYhJIFjX5sRWtsWo2eQg1U5YSQZAzEu8veI q6sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NVimrfo1WRRp/eG3/ytGXha95uSKgbpn29KOe/rszUE=; b=5+WAER2nAvkDhcjUCaRdagqn8A+F2YLxLgBhLrT6iEMdgbW+ck9VfXjqRVvBXByCmr z19f42MkE15mOfik2UwuSCIIkKwY2NJvTwYNiDa4Ah1d7iz71GHUCBL7QpzMicYqzUD5 huectgAu/vbw7iLB6Te+rkh/E3+/j3EyQZ8ydyo736e7TnvpPT8KXO5Dh2FraKk2nU9T PTo4QD2vjR5FxfCS8QoNh4R/VO4Poqf2VjT0s+6d8ISygAzWLj1fn01DqbfCyI1Apku0 3vmiYA7tStj2yorRuY+OkHRNpDNqxaqAriwOP8j3k6zGt7E5jpmi+23m18CW9Q2q5D8B 7tYQ== X-Gm-Message-State: AJIora/ydH/v1J2236e0Yr4Rk3ljOCqevPEf2IuBAY1+gI+a2L9Ym1VQ gsxtL4JOYCrpa92N4J0/K6qwTsxllGlsPKRt X-Google-Smtp-Source: AGRyM1vE88JZ6Iz8FesJQIC7xWwtmggOd/pWdwcH6EwLkQLOhDOkE2ZO1UuBTioLUpxM8pfQHY21Bw== X-Received: by 2002:a2e:8404:0:b0:250:cde7:e9e3 with SMTP id z4-20020a2e8404000000b00250cde7e9e3mr2159195ljg.289.1655375311967; Thu, 16 Jun 2022 03:28:31 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 15/17] migration/snapshot: Save part implement Date: Thu, 16 Jun 2022 13:28:09 +0300 Message-Id: <20220616102811.219007-16-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::236; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x236.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655377314847100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Snapshot save are done in two stages. First tool save vmstate part. It must be guaranteed that tool will get vmstate part only. This is because tool won't parse this stream and will just save it non-modified. Second stage is ram sending. Also it must be guarantee that ram part only w= ill be passed. Ram will be saved in qcow2 file. The goal was to avoid duplicate same part of already existed migration code so in this patch savevm handlers were used. Tool replace existed ram handler with its own and after that call existed functions. It is work correctly because algorithm of tool saving is similar to loadvm algorithm. I think this isn't obvious part so it should be described here. Signed-off-by: Nikita Lapshin --- include/qemu-snapshot.h | 16 +- migration/qemu-snapshot.c | 323 +++++++++++++++++++++++++++++++++++++- migration/savevm.c | 22 ++- migration/savevm.h | 4 + qemu-snapshot.c | 82 +++++++++- 5 files changed, 435 insertions(+), 12 deletions(-) diff --git a/include/qemu-snapshot.h b/include/qemu-snapshot.h index be2557f6a0..a97abd9f25 100644 --- a/include/qemu-snapshot.h +++ b/include/qemu-snapshot.h @@ -21,6 +21,7 @@ /* Backing cluster size */ #define BDRV_CLUSTER_SIZE (1024 * 1024) =20 +#define VMSTATE_SIZE (1024 * 1024) /* Minimum supported target page size */ #define PAGE_SIZE_MIN 4096 /* @@ -34,6 +35,8 @@ /* RAM slice size for snapshot revert */ #define SLICE_SIZE_REVERT (16 * PAGE_SIZE_MAX) =20 +typedef struct QIOChannelBuffer QIOChannelBuffer; + typedef struct StateInfo { int64_t page_size; int64_t page_mask; @@ -44,9 +47,17 @@ typedef struct StateInfo { } StateInfo; =20 typedef struct StateSaveCtx { - BlockBackend *blk; /* Block backend */ + BlockBackend *blk; /* Block backend */ =20 - StateInfo state_parameters; /* Migration state info*/ + QEMUFile *f_fd; /* QEMUFile for incoming stream */ + QEMUFile *f_vmstate; /* QEMUFile for vmstate backing */ + + QIOChannelBuffer *ioc_vmstate; /* Buffer for vmstate */ + QIOChannelBuffer *ioc_pages; /* Page coalescing buffer */ + + StateInfo state_parameters; /* Migration state info*/ + + size_t vmstate_len; /* vmstate len */ } StateSaveCtx; =20 typedef struct StateLoadCtx { @@ -60,6 +71,7 @@ void ram_destroy_state(void); StateSaveCtx *get_save_context(void); StateLoadCtx *get_load_context(void); int coroutine_fn save_state_main(StateSaveCtx *s); +void save_vmstate(StateSaveCtx *s); int coroutine_fn load_state_main(StateLoadCtx *s); =20 QEMUFile *qemu_fopen_bdrv_vmstate(BlockDriverState *bs, int is_writable); diff --git a/migration/qemu-snapshot.c b/migration/qemu-snapshot.c index 394c6acb77..2c9909fc8e 100644 --- a/migration/qemu-snapshot.c +++ b/migration/qemu-snapshot.c @@ -22,6 +22,8 @@ #include "migration/savevm.h" #include "migration/ram.h" #include "qemu-snapshot.h" +#include "migration/savevm.h" +#include "migration/register.h" =20 /* RAM block */ /* TODO RAMBlock should be replace with existing struct RAMBlock in ram.c = */ @@ -40,6 +42,11 @@ typedef struct RAMBlock { char idstr[256]; /* RAM block id string */ } RAMBlock; =20 +typedef struct RAMPage { + RAMBlock *block; /* RAM block containing the page */ + int64_t offset; /* Page offset in RAM block */ +} RAMPage; + /* RAM transfer context */ typedef struct RAMCtx { int64_t normal_pages; /* Total number of normal pages */ @@ -51,6 +58,26 @@ typedef struct RAMCtx { =20 static RAMCtx ram_ctx; =20 +static int64_t page_size; +static int page_bits; +static int64_t page_mask; +static int64_t slice_size; +static int slice_bits; +static int64_t slice_mask; +/* + * Init sufficient global variables + * TODO: These variables should be removed or add to existing global struc= tures + */ +static void init_global_var(StateInfo *si) +{ + page_size =3D si->page_size; + page_bits =3D si->page_bits; + page_mask =3D si->page_mask; + slice_size =3D si->slice_size; + slice_bits =3D si->slice_bits; + slice_mask =3D si->slice_mask; +} + static inline bool ram_offset_in_block(RAMBlock *block, int64_t offset) { @@ -158,6 +185,19 @@ static void ram_block_add(const char *idstr, int64_t s= ize) QSIMPLEQ_INSERT_TAIL(&ram_ctx.ram_block_list, block, next); } =20 +static void ram_block_list_init_bitmaps(void) +{ + RAMBlock *block; + + QSIMPLEQ_FOREACH(block, &ram_ctx.ram_block_list, next) { + block->nr_pages =3D block->length >> page_bits; + block->nr_slices =3D ROUND_UP(block->length, slice_size) >> slice_= bits; + + block->bitmap =3D bitmap_new(block->nr_slices); + bitmap_set(block->bitmap, 0, block->nr_slices); + } +} + /* * Assume that QEMUFile is migration stream and try to get * from f_src ram blocks list. mem_size is a total amount of bytes of whole @@ -188,6 +228,9 @@ static int ram_block_list_from_stream(QEMUFile *f_src, = int64_t mem_size) return -EINVAL; } =20 + /* Initialize per-block bitmaps */ + ram_block_list_init_bitmaps(); + return 0; } =20 @@ -210,12 +253,276 @@ static int ram_block_list_to_stream(QEMUFile *f_dest) return qemu_file_get_error(f_dest); } =20 -int coroutine_fn save_state_main(StateSaveCtx *s) +static void save_state_check_errors(StateSaveCtx *s, int *res) { - /* TODO: implement */ + /* Check for -EIO which indicates input stream EOF */ + if (*res =3D=3D -EIO) { + *res =3D 0; + } + + /* + * Check for file errors on success. Replace generic -EINVAL + * retcode with file error if possible. + */ + if (*res >=3D 0 || *res =3D=3D -EINVAL) { + int f_res =3D qemu_file_get_error(s->f_fd); + + f_res =3D (f_res =3D=3D -EIO) ? 0 : f_res; + if (!f_res) { + f_res =3D qemu_file_get_error(s->f_vmstate); + } + if (f_res) { + *res =3D f_res; + } + } +} + +static int ram_save_page(StateSaveCtx *s, RAMPage *page, uint8_t *data) +{ + int64_t bdrv_offset; + int res =3D 0; + + bdrv_offset =3D ram_bdrv_from_block_offset(page->block, page->offset); + if (bdrv_offset =3D=3D INVALID_OFFSET) { + error_report("Corrupted RAM page"); + return -EINVAL; + } + + res =3D blk_pwrite(s->blk, bdrv_offset, data, page_size, 0); + + res =3D MIN(res, 0); + return res; +} + +static int ram_save(QEMUFile *f, void *opaque, int version_id) +{ + StateSaveCtx *s =3D (StateSaveCtx *) opaque; + int incompat_flags =3D RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZ= RLE; + int flags =3D 0; + int res =3D 0; + + if (version_id !=3D 4) { + error_report("Unsupported version %d for 'ram' handler v4", versio= n_id); + return -EINVAL; + } + + while (!res && !(flags & RAM_SAVE_FLAG_EOS)) { + RAMBlock *block =3D NULL; + int64_t offset; + + offset =3D qemu_get_be64(f); + flags =3D offset & ~page_mask; + offset &=3D page_mask; + + if (flags & incompat_flags) { + error_report("Incompatible RAM page flags 0x%x", flags); + res =3D -EINVAL; + break; + } + + /* Lookup RAM block for the page */ + if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE)) { + block =3D ram_block_from_stream(f, flags); + if (!block) { + error_report("Failed to get ram block form stream"); + res =3D -EINVAL; + break; + } + } + + switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { + case RAM_SAVE_FLAG_MEM_SIZE: + /* Get RAM block list */ + if (ram_block_list_from_stream(f, offset) || + ram_block_list_to_stream(s->f_vmstate)) { + error_report("Failed to get ram block list"); + res =3D -EINVAL; + } + break; + + case RAM_SAVE_FLAG_ZERO: + /* Nothing to do with zero page */ + qemu_get_byte(f); + break; + + case RAM_SAVE_FLAG_PAGE: + { + RAMPage page =3D { .block =3D block, .offset =3D offset }; + uint8_t *data; + ssize_t count; + + count =3D qemu_peek_buffer(f, &data, page_size, 0); + qemu_file_skip(f, count); + if (count !=3D page_size) { + /* I/O error */ + res =3D -EINVAL; + break; + } + + res =3D ram_save_page(s, &page, data); + + /* Update normal page count */ + ram_ctx.normal_pages++; + break; + } + + case RAM_SAVE_FLAG_EOS: + /* Normal exit */ + break; + + default: + error_report("RAM page with unknown combination of flags 0x%x", + flags); + res =3D -EINVAL; + + } + + /* Make additional check for file errors */ + if (!res) { + res =3D qemu_file_get_error(f); + } + } + + return res; +} + +static int save_section_config(StateSaveCtx *s) +{ + QEMUFile *f =3D s->f_fd; + uint32_t id_len; + uint8_t buf[256]; + + qemu_put_byte(s->f_vmstate, QEMU_VM_CONFIGURATION); + + id_len =3D qemu_get_be32(f); + qemu_put_be32(s->f_vmstate, id_len); + + if (id_len > 255) { + error_report("Corrupted configuration section"); + return -EINVAL; + } + + qemu_get_buffer(f, buf, id_len); + qemu_put_buffer(s->f_vmstate, buf, id_len); + + buf[id_len] =3D '\0'; + return 0; +} + +static int save_state_header(StateSaveCtx *s) +{ + QEMUFile *f =3D s->f_fd; + QEMUFile *f_vmstate =3D s->f_vmstate; + uint32_t v; + + /* Validate qemu magic */ + v =3D qemu_get_be32(f); + if (v !=3D QEMU_VM_FILE_MAGIC) { + error_report("Not a migration stream"); + return -EINVAL; + } + qemu_put_be32(f_vmstate, v); + + v =3D qemu_get_be32(f); + if (v =3D=3D QEMU_VM_FILE_VERSION_COMPAT) { + error_report("SaveVM v2 format is obsolete"); + return -EINVAL; + } + + if (v !=3D QEMU_VM_FILE_VERSION) { + error_report("Unsupported migration stream version"); + return -EINVAL; + } + + qemu_put_be32(f_vmstate, v); return 0; } =20 +static int save_completion(StateSaveCtx *s) +{ + uint8_t *ptr; + ptr =3D s->ioc_vmstate->data; + qemu_put_be64(s->f_vmstate, s->vmstate_len); + qemu_put_buffer(s->f_vmstate, ptr, s->vmstate_len); + return 0; +} + +int coroutine_fn save_state_main(StateSaveCtx *s) +{ + QEMUFile *f =3D s->f_fd; + uint8_t section_type; + int res =3D 0; + SaveVMHandlers ram_ops; + + init_global_var(&s->state_parameters); + + ram_ops.load_state =3D ram_save; + + res =3D qemu_replace_ram_handler((void *) &ram_ops, (void *) s); + if (res) { + error_report("Error replacing ram handler"); + return res; + } + + /* Deal with migration stream header */ + res =3D save_state_header(s); + if (res) { + /* Check for file errors in case we have -EINVAL */ + save_state_check_errors(s, &res); + return res; + } + + while (!res) { + /* Read section type token */ + section_type =3D qemu_get_byte(f); + + switch (section_type) { + case QEMU_VM_CONFIGURATION: + res =3D save_section_config(s); + break; + + /* We use already existed function which will call our handler */ + case QEMU_VM_SECTION_FULL: + case QEMU_VM_SECTION_START: + res =3D qemu_loadvm_section_start_full(f, NULL); + break; + + case QEMU_VM_SECTION_PART: + case QEMU_VM_SECTION_END: + res =3D qemu_loadvm_section_part_end(f, NULL); + break; + + case QEMU_VM_EOF: + /* End of migration stream */ + save_completion(s); + return res; + + default: + error_report("Unknown section type %d", section_type); + res =3D -EINVAL; + + } + + /* Additional check for file errors */ + save_state_check_errors(s, &res); + } + + /* Replace positive retcode with 0 */ + return MIN(res, 0); +} + +void save_vmstate(StateSaveCtx *s) +{ + size_t res; + + qemu_put_be64(s->f_vmstate, 0); + res =3D qemu_fsplice_tail(s->f_vmstate, s->f_fd); + + qemu_fclose(s->f_vmstate); + s->f_vmstate =3D qemu_fopen_bdrv_vmstate(blk_bs(s->blk), 1); + qemu_put_be64(s->f_vmstate, res); +} + int coroutine_fn load_state_main(StateLoadCtx *s) { /* TODO: implement */ @@ -228,10 +535,20 @@ void ram_init_state(void) RAMCtx *ram =3D &ram_ctx; =20 memset(ram, 0, sizeof(ram_ctx)); + + /* Initialize RAM block list head */ + QSIMPLEQ_INIT(&ram->ram_block_list); } =20 /* Destroy snapshot RAM state */ void ram_destroy_state(void) { - /* TODO: implement */ + RAMBlock *block; + RAMBlock *next_block; + + /* Free RAM blocks */ + QSIMPLEQ_FOREACH_SAFE(block, &ram_ctx.ram_block_list, next, next_block= ) { + g_free(block->bitmap); + g_free(block); + } } diff --git a/migration/savevm.c b/migration/savevm.c index 48603517ba..b722e51163 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2409,8 +2409,7 @@ static bool check_section_footer(QEMUFile *f, SaveSta= teEntry *se) return true; } =20 -static int -qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) +int qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mi= s) { uint32_t instance_id, version_id, section_id; SaveStateEntry *se; @@ -2474,8 +2473,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, Migration= IncomingState *mis) return 0; } =20 -static int -qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) +int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) { uint32_t section_id; SaveStateEntry *se; @@ -2645,6 +2643,22 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) return true; } =20 +int qemu_replace_ram_handler(void *ram_ops, void *opaque) +{ + /* Find savevm section and change it to tools handler */ + SaveStateEntry *se =3D find_se("ram", 0); + if (se) { + unregister_savevm(NULL, se->idstr, se->opaque); + } + + if (register_savevm_live("ram", 0, 4, (SaveVMHandlers *) ram_ops, opaq= ue)) { + error_report("Error register snapshot tool ram handlers"); + return -EINVAL; + } + + return 0; +} + int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis) { uint8_t section_type; diff --git a/migration/savevm.h b/migration/savevm.h index 6461342cb4..9abfcd88e5 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -67,5 +67,9 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncoming= State *mis); int qemu_load_device_state(QEMUFile *f); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks); +int qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mi= s); +int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis); + +int qemu_replace_ram_handler(void *ram_ops, void *opaque); =20 #endif diff --git a/qemu-snapshot.c b/qemu-snapshot.c index 683f1b265a..172a9596df 100644 --- a/qemu-snapshot.c +++ b/qemu-snapshot.c @@ -20,6 +20,7 @@ #include "qapi/qmp/qdict.h" #include "sysemu/sysemu.h" #include "sysemu/block-backend.h" +#include "sysemu/runstate.h" #include "qemu/cutils.h" #include "qemu/coroutine.h" #include "qemu/error-report.h" @@ -91,7 +92,22 @@ static void init_save_context(void) =20 static void destroy_save_context(void) { - /* TODO: implement */ + StateSaveCtx *s =3D get_save_context(); + + if (s->f_vmstate) { + qemu_fclose(s->f_vmstate); + } + if (s->blk) { + blk_flush(s->blk); + blk_unref(s->blk); + } + if (s->ioc_pages) { + object_unref(OBJECT(s->ioc_pages)); + } + if (s->ioc_vmstate) { + object_unref(OBJECT(s->ioc_vmstate)); + } + } =20 static void init_load_context(void) @@ -132,7 +148,11 @@ static void enter_co_bh(void *opaque) static void coroutine_fn snapshot_save_co(void *opaque) { StateSaveCtx *s =3D get_save_context(); - int res =3D -1; + QIOChannel *ioc_fd; + int res =3D 0; + size_t conf_size =3D 0; + size_t size; + init_save_context(); =20 /* Block backend */ @@ -142,9 +162,65 @@ static void coroutine_fn snapshot_save_co(void *opaque) goto fail; } =20 - res =3D save_state_main(s); + /* + * Check if we are saving vmstate or ram. We need ram to be separate + * from anything else. + */ + if (!params.save_vmstate) { + /* + * We assume that we have saved vmstate stream. + * So now we need to remove some useless parts like header, magic + * number and conf section if it was saved. + */ + s->ioc_vmstate =3D qio_channel_buffer_new(VMSTATE_SIZE); + qio_channel_set_name(QIO_CHANNEL(s->ioc_vmstate), + "migration-vmstate-buffer"); + + s->f_vmstate =3D qemu_fopen_bdrv_vmstate(blk_bs(s->blk), 0); + + qemu_file_set_blocking(s->f_vmstate, false); + size =3D qemu_get_be64(s->f_vmstate); + + /* Here we will skip magic and version and check these numbers lat= er */ + qemu_get_be64(s->f_vmstate); + + if (qemu_peek_byte(s->f_vmstate, 0) =3D=3D QEMU_VM_CONFIGURATION) { + qemu_get_byte(s->f_vmstate); + /* + * 4 bytes are string length and last is string itself. + * That's why we need to add 5 to conf_size. + */ + conf_size =3D qemu_get_be32(s->f_vmstate); + qemu_file_skip(s->f_vmstate, conf_size); + conf_size +=3D 5; + } + + /* 8 is 4+4 bytes - migration magic number and migration header. */ + s->vmstate_len =3D size - 8 - conf_size; + qemu_get_buffer(s->f_vmstate, s->ioc_vmstate->data, s->vmstate_len= ); + qemu_fclose(s->f_vmstate); + } + + s->f_vmstate =3D qemu_fopen_bdrv_vmstate(blk_bs(s->blk), 1); + qemu_file_set_blocking(s->f_vmstate, false); + + /* QEMUFile on migration fd */ + ioc_fd =3D qio_channel_new_fd(params.fd, &error_fatal); + qio_channel_set_name(QIO_CHANNEL(ioc_fd), "migration-channel-incoming"= ); + s->f_fd =3D qemu_fopen_channel_input(ioc_fd); + object_unref(OBJECT(ioc_fd)); + /* Use non-blocking mode in coroutine */ + qemu_file_set_blocking(s->f_fd, false); + + s->state_parameters =3D *((StateInfo *) opaque); + if (params.save_vmstate) { + save_vmstate(s); + } else { + res =3D save_state_main(s); + } if (res) { error_report("Failed to save snapshot: %s", strerror(-res)); + } =20 fail: destroy_save_context(); --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655377823; cv=none; d=zohomail.com; s=zohoarc; b=P3qw+fO1X1eVJJmX8FLHq4JyCVcBGzOxKEo0cimU41w3bu9Qm99e0kggFvhPcBwshY55KYT/ftx6iF+f9FkZOGAZg8uSkd7I6YGyEGgBdfnSTkJO+xvaFbHwGobCKcB2HA9bktmwLUgOHZcf0CKWmmif++na5dh4dZipCnD7CNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655377823; h=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=rtfwv5FW5SYi1oLqpOCVVCwtMJInI2gPXO7aN4ubWYU=; b=W9qRInz5B5OXUXhuIzp+OlbMOAEOXMqWTZZ6JLxvPpT5MDXh/NSNJ2/jUJSLe7K1rjfdyeq8f8QR+1XOdWv1BRTN2e3bqj5TiZEO/MT6gPQ+2g0PtVfLaMIU0A9Z+ZNDyQkPfAovqeN3vXMqs5LfsVz6oo9ek2ygcEFdNTtv+Kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655377823602411.0529743047406; Thu, 16 Jun 2022 04:10:23 -0700 (PDT) Received: from localhost ([::1]:51978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nOI-0008An-Do for importer@patchew.org; Thu, 16 Jun 2022 07:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjs-0001xt-TX for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:36 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:46843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjq-0001vx-LF for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:36 -0400 Received: by mail-lf1-x12e.google.com with SMTP id s6so1499864lfo.13 for ; Thu, 16 Jun 2022 03:28:34 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rtfwv5FW5SYi1oLqpOCVVCwtMJInI2gPXO7aN4ubWYU=; b=F2UnB8vV9dB7wm7Dq/e0nHMu+v46318MtA4KOhtsYli0JN1gamvdKGWM+VecjsIQBJ YJvwS1n5hb83OxQuBlyU23J7OputXDziWzhusmWOQyF3Gh5z8jt4/vjtpPnJsx7DcOcj CxWfGS8Rk42vpwbgIHcUIfqftAsPuBFqbKjiQd0v1AWi2Ve81t7BA7b9uuCHephNB7la totjsQYatylfR41aj7pmoav+tNQx5cNJSeNncvESeiyueCuSBGnmKRRFMc0IYrB2GIX7 z82gHRqIc1Y4Q2++1DLGQaLYliPyuCoNvQDg1e2CRSuh8f4/sj3MzUp//ZGxqUG24bN6 ZKeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rtfwv5FW5SYi1oLqpOCVVCwtMJInI2gPXO7aN4ubWYU=; b=0C39dWljJMgNlxVTzvYnFeLIRMS/GrhB3jAqxUKaVxiLpMfuATDiz9qeDUVZc3kwC3 s4exrl1JpR2vxQ2qdos6kEYtjQTs/lB67WsrXE+2LB0GMVZDzxBq+Ncy3YGCblT9eKGg jDH0KWKnwiuv3J+2iqn+qV2sHg7isEavR9T9oT3dHfy31uq9XybBMf5gFm+X3Fz3/fyj YOVj2hpmnvVyjtruDGeBlOaOfuP5P4mGxzhfhh+Jcd1L+Jia+AnM6o/w2rxZJcXCFdkr kz9hjQMA1kiKv4Ii7CnpNtVspMAShHRz9GGRxVBDyEtlKHTn+yGt8C+sZ6xMt8qwuDtC vADw== X-Gm-Message-State: AJIora+lQWihFaMrbTYXKGCX+PsBINisroMXhYfRp+aX7XzAsJGXDSas TsA4BriqBdGu9eNeFH65AnWh8yiJOKq5JjYC X-Google-Smtp-Source: AGRyM1vzVPDxcH0L+M68xzQwml/Kg5K0wPvaJl23zZOnh9E1ffY4Be7OHWdiXCcjFAxWZuydnltq/Q== X-Received: by 2002:a05:6512:2304:b0:47c:5268:5021 with SMTP id o4-20020a056512230400b0047c52685021mr2363741lfu.369.1655375312888; Thu, 16 Jun 2022 03:28:32 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 16/17] migration/snapshot: Precopy load implemented Date: Thu, 16 Jun 2022 13:28:10 +0300 Message-Id: <20220616102811.219007-17-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::12e; envelope-from=nikita.lapshin@openvz.org; helo=mail-lf1-x12e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655377825890100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin Load snapshot from qcow2 file. This part also work only with ram part and send vmstate part as it was saved previously without parsing. Here also migration code was reused but now it is savevm part. Tool replace ram handlers as it did before in tool save part but now it is also needed to avoid using another handlers. That is where stream-content-list is used it helps to "disable" all handlers except ram. Also here slices were used to increase efficiency of reading from disk. So when tool will need to read a page from block it will read a number of pages and send them all. Signed-off-by: Nikita Lapshin --- include/qemu-snapshot.h | 4 +- migration/qemu-snapshot.c | 333 +++++++++++++++++++++++++++++++++++++- qemu-snapshot.c | 25 ++- 3 files changed, 356 insertions(+), 6 deletions(-) diff --git a/include/qemu-snapshot.h b/include/qemu-snapshot.h index a97abd9f25..74885c03bb 100644 --- a/include/qemu-snapshot.h +++ b/include/qemu-snapshot.h @@ -62,8 +62,10 @@ typedef struct StateSaveCtx { =20 typedef struct StateLoadCtx { BlockBackend *blk; /* Block backend */ + QEMUFile *f_fd; + QEMUFile *f_vmstate; =20 - StateInfo state_parameters; /* Migration state info*/ + StateInfo state_parameters; } StateLoadCtx; =20 void ram_init_state(void); diff --git a/migration/qemu-snapshot.c b/migration/qemu-snapshot.c index 2c9909fc8e..280f5be25c 100644 --- a/migration/qemu-snapshot.c +++ b/migration/qemu-snapshot.c @@ -21,9 +21,11 @@ #include "migration/qemu-file.h" #include "migration/savevm.h" #include "migration/ram.h" +#include "migration/migration.h" #include "qemu-snapshot.h" #include "migration/savevm.h" #include "migration/register.h" +#include "qapi/qapi-types-migration.h" =20 /* RAM block */ /* TODO RAMBlock should be replace with existing struct RAMBlock in ram.c = */ @@ -53,7 +55,8 @@ typedef struct RAMCtx { =20 /* RAM block list head */ QSIMPLEQ_HEAD(, RAMBlock) ram_block_list; - + RAMPage last_page; + RAMBlock *last_sent_block; } RAMCtx; =20 static RAMCtx ram_ctx; @@ -523,12 +526,336 @@ void save_vmstate(StateSaveCtx *s) qemu_put_be64(s->f_vmstate, res); } =20 -int coroutine_fn load_state_main(StateLoadCtx *s) +static void load_state_check_errors(StateLoadCtx *s, int *res) +{ + /* + * Check for file errors on success. Replace generic -EINVAL + * retcode with file error if possible. + */ + if (*res >=3D 0 || *res =3D=3D -EINVAL) { + int f_res =3D qemu_file_get_error(s->f_fd); + + if (!f_res) { + f_res =3D qemu_file_get_error(s->f_vmstate); + } + if (f_res) { + *res =3D f_res; + } + } +} + +static int send_conf(StateLoadCtx *s) +{ + QEMUFile *f =3D s->f_vmstate; + uint32_t id_len; + uint8_t buf[256]; + + qemu_put_byte(s->f_fd, QEMU_VM_CONFIGURATION); + id_len =3D qemu_get_be32(f); + qemu_put_be32(s->f_fd, id_len); + + if (id_len > 255) { + error_report("Corrupted configuration section"); + return -EINVAL; + } + + qemu_get_buffer(f, buf, id_len); + qemu_put_buffer(s->f_fd, buf, id_len); + buf[id_len] =3D '\0'; + + return 0; +} + +static int send_header(StateLoadCtx *s) +{ + QEMUFile *f =3D s->f_vmstate; + uint32_t v; + + /* Validate magic */ + v =3D qemu_get_be32(f); + if (v !=3D QEMU_VM_FILE_MAGIC) { + error_report("Not a valid snapshot"); + return -EINVAL; + } + qemu_put_be32(s->f_fd, v); + + v =3D qemu_get_be32(f); + if (v =3D=3D QEMU_VM_FILE_VERSION_COMPAT) { + error_report("SaveVM v2 format is obsolete"); + return -EINVAL; + } + qemu_put_be32(s->f_fd, v); + + return 0; +} + +static int load_state_ramlist(StateLoadCtx *s) { - /* TODO: implement */ + uint64_t size =3D qemu_get_be64(s->f_vmstate); + size =3D size & (~RAM_SAVE_FLAG_MEM_SIZE); + return ram_block_list_from_stream(s->f_vmstate, size); +} + +static int send_setup(StateLoadCtx *s) +{ + /* We need to enable only ram using parameter stream-content-list */ + qemu_savevm_state_setup(s->f_fd); + + ram_block_list_init_bitmaps(); + return 0; } =20 +/* No need to parse vmstate part, we just send it using known offset */ +static int send_vmstate(QEMUFile *f_vmstate, QEMUFile *f_dest) +{ + /* Send vmstate without last byte because it is QEMU_VM_EOF */ + size_t len; + len =3D qemu_get_be64(f_vmstate); + qemu_fsplice(f_dest, f_vmstate, len); + + return 0; +} + +static int ram_send_setup(QEMUFile *f, void *opaque) +{ + int res =3D ram_block_list_to_stream(f); + + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + + return res; +} + +static bool find_next_page(RAMPage *page) +{ + RAMCtx *ram =3D &ram_ctx; + RAMBlock *block =3D ram->last_page.block; + int64_t slice =3D ram->last_page.offset >> slice_bits; + bool full_round =3D false; + bool found =3D false; + + if (!block) { +restart: + block =3D QSIMPLEQ_FIRST(&ram->ram_block_list); + slice =3D 0; + full_round =3D true; + } + + while (!found && block) { + slice =3D find_next_bit(block->bitmap, block->nr_slices, slice); + /* Can't find unsent slice in block? */ + if (slice >=3D block->nr_slices) { + /* Try next block */ + block =3D QSIMPLEQ_NEXT(block, next); + slice =3D 0; + + continue; + } + + found =3D true; + } + + /* + * Re-start from the beginning if couldn't find unsent slice, + * but do it only once. + */ + if (!found && !full_round) { + goto restart; + } + + if (found) { + page->block =3D block; + page->offset =3D slice << slice_bits; + } + + return found; +} + +static void get_page_range(RAMPage *page, int64_t *length) +{ + int64_t start_slice; + int64_t end_slice; + int64_t tmp; + + assert(QEMU_IS_ALIGNED(page->offset, slice_size)); + + start_slice =3D page->offset >> slice_bits; + end_slice =3D find_next_zero_bit(page->block->bitmap, page->block->nr_= slices, + page->offset >> slice_bits); + + tmp =3D (end_slice - start_slice) << slice_bits; + *length =3D page->block->length - page->offset; + *length =3D MIN(*length, tmp); + + /* + * Length is always aligned to slice_size with the exception of case + * when it is the last slice in RAM block. + */ + *length =3D MIN(slice_size, *length); +} + +static inline +void clear_page_range(RAMPage *page, int64_t length) +{ + assert(QEMU_IS_ALIGNED(page->offset, slice_size)); + assert(length); + + /* + * Page offsets are aligned to the slice boundary so we only need + * to round up length for the case when we load last slice in the bloc= k. + */ + bitmap_clear(page->block->bitmap, page->offset >> slice_bits, + ((length - 1) >> slice_bits) + 1); +} + +static int coroutine_fn ram_load_pages(StateLoadCtx *s) +{ + RAMCtx *ram =3D &ram_ctx; + RAMPage page; + int64_t length; + uint8_t *data; + int64_t blk_offset, slice_offset, bdrv_offset; + ssize_t res; + int64_t flags =3D RAM_SAVE_FLAG_CONTINUE; + + if (!find_next_page(&page)) { + return 0; + } + + /* Get range of contiguous pages that were not transferred yet */ + get_page_range(&page, &length); + /* Clear range of pages to be queued for I/O */ + clear_page_range(&page, length); + + /* Used by find_next_page() */ + ram->last_page.block =3D page.block; + ram->last_page.offset =3D page.offset + length; + + /* Read found slice from block */ + bdrv_offset =3D ram_bdrv_from_block_offset(page.block, page.offset); + data =3D (uint8_t *) qemu_blockalign(blk_bs(s->blk), length); + res =3D blk_pread(s->blk, bdrv_offset, data, length); + + if (res < 0) { + error_report("Read from file failed"); + return res; + } + + /* Send slice to destination */ + slice_offset =3D 0; + while (length > slice_offset) { + if (!ram_bdrv_offset_in_block(ram->last_sent_block, bdrv_offset)) { + ram->last_sent_block =3D page.block; + flags =3D 0; + } + + blk_offset =3D ram_block_offset_from_bdrv(ram->last_sent_block, + slice_offset + bdrv_offset= ); + qemu_put_be64(s->f_fd, blk_offset | RAM_SAVE_FLAG_PAGE | flags); + if (!flags) { + qemu_put_counted_string(s->f_fd, page.block->idstr); + } + qemu_put_buffer(s->f_fd, data + slice_offset, page_size); + slice_offset +=3D page_size; + qemu_fflush(s->f_fd); + } + qemu_fflush(s->f_fd); + return 1; +} + +static int ram_load_iterate(QEMUFile *f, void *opaque) +{ + StateLoadCtx *s =3D (StateLoadCtx *) opaque; + int res; + + res =3D ram_load_pages(s); + + /* Zero retcode means that there're no more pages to load */ + if (res >=3D 0) { + res =3D res ? 0 : 1; + } + + /* Send EOS flag before section footer */ + qemu_put_be64(s->f_fd, RAM_SAVE_FLAG_EOS); + qemu_fflush(s->f_fd); + + return res; +} + +static bool is_active_ram(void *opaque) +{ + return true; +} + +int coroutine_fn load_state_main(StateLoadCtx *s) +{ + int res; + MigrationState *ms =3D migrate_get_current(); + SaveVMHandlers ram_ops; + + init_global_var(&s->state_parameters); + + strList *list =3D g_malloc(sizeof(strList)); + list->value =3D g_malloc(sizeof("ram")); + list->next =3D NULL; + memcpy(list->value, "ram", sizeof("ram")); + + ms->parameters.has_stream_content_list =3D true; + ms->parameters.stream_content_list =3D list; + ms->send_section_footer =3D true; + + ram_ops.save_setup =3D ram_send_setup; + ram_ops.save_live_iterate =3D ram_load_iterate; + ram_ops.is_active =3D is_active_ram; + ram_ops.is_active_iterate =3D NULL; + + res =3D qemu_replace_ram_handler((void *) &ram_ops, (void *) s); + + res =3D send_header(s); + if (res) { + goto fail; + } + if (qemu_peek_byte(s->f_vmstate, 0) =3D=3D QEMU_VM_CONFIGURATION) { + qemu_get_byte(s->f_vmstate); + res =3D send_conf(s); + if (res) { + goto fail; + } + } + + res =3D load_state_ramlist(s); + if (res) { + goto fail; + } + + res =3D send_setup(s); + if (res) { + error_report("Send setup failed"); + goto fail; + } + + do { + res =3D qemu_savevm_state_iterate(s->f_fd, false); + /* Check for file errors */ + load_state_check_errors(s, &res); + } while (!res); + + if (res < 0) { + goto fail; + } + + + send_vmstate(s->f_vmstate, s->f_fd); + qemu_put_byte(s->f_fd, QEMU_VM_EOF); + qemu_fflush(s->f_fd); +fail: + load_state_check_errors(s, &res); + + /* Replace positive retcode with 0 */ + return MIN(res, 0); +} + /* Initialize snapshot RAM state */ void ram_init_state(void) { diff --git a/qemu-snapshot.c b/qemu-snapshot.c index 172a9596df..04bda74fb4 100644 --- a/qemu-snapshot.c +++ b/qemu-snapshot.c @@ -117,7 +117,14 @@ static void init_load_context(void) =20 static void destroy_load_context(void) { - /* TODO: implement */ + StateLoadCtx *s =3D get_load_context(); + + if (s->f_vmstate) { + qemu_fclose(s->f_vmstate); + } + if (s->blk) { + blk_unref(s->blk); + } } =20 static BlockBackend *image_open_opts(const char *optstr, QDict *options, @@ -230,7 +237,8 @@ fail: static void coroutine_fn snapshot_load_co(void *opaque) { StateLoadCtx *s =3D get_load_context(); - int res =3D -1; + int res; + QIOChannel *ioc_fd; =20 init_load_context(); =20 @@ -241,6 +249,19 @@ static void coroutine_fn snapshot_load_co(void *opaque) goto fail; } =20 + /* QEMUFile on vmstate */ + s->f_vmstate =3D qemu_fopen_bdrv_vmstate(blk_bs(s->blk), 0); + qemu_file_set_blocking(s->f_vmstate, false); + + /* QEMUFile on migration fd */ + ioc_fd =3D qio_channel_new_fd(params.fd, NULL); + qio_channel_set_name(QIO_CHANNEL(ioc_fd), "migration-channel-outgoing"= ); + s->f_fd =3D qemu_fopen_channel_output(ioc_fd); + object_unref(OBJECT(ioc_fd)); + qemu_file_set_blocking(s->f_fd, false); + + s->state_parameters =3D *((StateInfo *) opaque); + res =3D load_state_main(s); if (res) { error_report("Failed to load snapshot: %s", strerror(-res)); --=20 2.31.1 From nobody Fri May 17 05:54:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1655378187; cv=none; d=zohomail.com; s=zohoarc; b=L1dz1q8pOVTN8CshpGV+4fLUeoLt3pzNMuOghwoSp3e+9P05SWoC4U00lHWXtCBxH0iWEN9RpIhRcBWJdrE+j9XjsYdB/oDULR0jeu9ZsA3WbIt8w5tEZ83j6S7uwSQ2Vq5wssuwkV+6641ADTMSfva/2XzRktareI77/AZjMf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655378187; h=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=GzYRRbvWfvhUQ0rCQp3mdxovXYJ7cK6kJcdswbCzh2g=; b=iRVus1vnwZI2JCfEXrwi7ZpgRRJmetIDQ/nrmCJjc2Ehh6dhRKp/l6u0YzgFf7pYWSbHNQuZeDhBkIHt3siGjFrxI1SNegm4ZfTFOkv5FGYADjteaDz1vEAvfEy58jUjheKxxNiTfVD3PKrgE3I3Ywn7Jfw+VxpbXhIUZhref1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655378187106525.9283310986175; Thu, 16 Jun 2022 04:16:27 -0700 (PDT) Received: from localhost ([::1]:60614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nU9-0006PY-W4 for importer@patchew.org; Thu, 16 Jun 2022 07:16:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1mjv-00024q-3D for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:39 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]:45577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1mjr-0001wF-OS for qemu-devel@nongnu.org; Thu, 16 Jun 2022 06:28:38 -0400 Received: by mail-lj1-x22f.google.com with SMTP id s10so976995ljh.12 for ; Thu, 16 Jun 2022 03:28:35 -0700 (PDT) Received: from localhost.localdomain ([93.175.28.49]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0047255d21128sm182581lfj.87.2022.06.16.03.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 03:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GzYRRbvWfvhUQ0rCQp3mdxovXYJ7cK6kJcdswbCzh2g=; b=dUOR/Zi6m8EeUW2MGBY1iabkXLKJAyuczuRIydjeb8uGPH1yJO4dcrotqxSE6SpNYV ElcgDooMORtpwzBqrrunJP7Kc2YVCSEeXKVuhF8Dx2gHa2qhizBTrbbpJZDFu1Whl9pp oH06FXgUFIPocKBr66GANGOAf+A5itVQeCGsINsDKEDuGhSuxL7ilFm15ARxal2nYFXq +qVyllVuK+ZuVMmKQshIsOn2wvHrAV1hU87fI1kS3HinmZxYSvHCaQ8HvTTpvc5X/T5G JFD1p12ipY5CeeBTlJRDGFlSL4hj8FPs1OM1hH2fgBJqZ7EGKsj1X3XXDJZ9wfblNFu3 MUTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GzYRRbvWfvhUQ0rCQp3mdxovXYJ7cK6kJcdswbCzh2g=; b=H/KAO9r5Ea8dYTaVjfJmMojSU55IB5oE/BDNxnEOaDZ3vr4tcYT2sabjzOF6NYYN5M Ie0XbRue/kd5qSUPnUNqsSJbtTqxJ+gMo98nVd54VJMs+ScTJiAHNcAaVddezV/bMGZN 4ha/1emgCQKt9BNbN50+uyQkEP6HqUghC0t60/jMfceWp5nQeY/bE6K8b7cBRmFogSUj 2Tcsl8zupwmswqT1MeLJetMIfR22I9SET9kIJ6l9zE4Dx8obsGW0vttTQe9hTbWfDPw+ AnHk58+qqWKHs/q6Bq2GjZAhxEmYrf/kz1yfL+ku0+oRofEL9mqWEpaTcJfoz2Gopta+ VxTw== X-Gm-Message-State: AJIora/RmesnfT+3b83KfUm9RRTSbeE7xM18hEMvI+rw8wpsiKSrrmyX VtfNtBKyscm7jKw96bpXxT4abTxAN1U9cYUh X-Google-Smtp-Source: AGRyM1sMwy552W/s3mC+jTsBe8oLCB3QVU14c77Sjt2XfoBZs7YFEevkm2aCPpSed6Y2mpywHj5sfQ== X-Received: by 2002:a2e:9047:0:b0:255:70eb:9634 with SMTP id n7-20020a2e9047000000b0025570eb9634mr2120565ljg.521.1655375313732; Thu, 16 Jun 2022 03:28:33 -0700 (PDT) From: nikita.lapshin@openvz.org To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, andrey.drobyshev@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, nikita.lapshin@openvz.org Subject: [PATCH v3 17/17] migration/snapshot: Postcopy load implemented Date: Thu, 16 Jun 2022 13:28:11 +0300 Message-Id: <20220616102811.219007-18-nikita.lapshin@openvz.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220616102811.219007-1-nikita.lapshin@openvz.org> References: <20220616102811.219007-1-nikita.lapshin@openvz.org> MIME-Version: 1.0 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=2a00:1450:4864:20::22f; envelope-from=nikita.lapshin@openvz.org; helo=mail-lj1-x22f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @openvz-org.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1655378188870100001 Content-Type: text/plain; charset="utf-8" From: Nikita Lapshin It is a modified load part from previous patch. Implemented new rp listen thread for snapshot-tool. Also implemented functions for starting postcopy. This mode can be turned on by specifying --postcopy flag. Signed-off-by: Nikita Lapshin --- include/qemu-snapshot.h | 12 ++ migration/migration.c | 123 +++++++++++++++++++ migration/migration.h | 1 + migration/qemu-snapshot.c | 249 +++++++++++++++++++++++++++++++++++++- migration/savevm.c | 25 ++++ migration/savevm.h | 4 + qemu-snapshot.c | 10 ++ 7 files changed, 422 insertions(+), 2 deletions(-) diff --git a/include/qemu-snapshot.h b/include/qemu-snapshot.h index 74885c03bb..b0f235747f 100644 --- a/include/qemu-snapshot.h +++ b/include/qemu-snapshot.h @@ -65,6 +65,15 @@ typedef struct StateLoadCtx { QEMUFile *f_fd; QEMUFile *f_vmstate; =20 + /* Postcopy part */ + bool postcopy; + bool in_postcopy; + + /* Return path part */ + QemuThread rp_listen_thread; + QEMUFile *f_rp_fd; + bool has_rp_listen_thread; + StateInfo state_parameters; } StateLoadCtx; =20 @@ -76,6 +85,9 @@ int coroutine_fn save_state_main(StateSaveCtx *s); void save_vmstate(StateSaveCtx *s); int coroutine_fn load_state_main(StateLoadCtx *s); =20 +int queue_page_request(const char *idstr, uint64_t offset, + uint32_t size); + QEMUFile *qemu_fopen_bdrv_vmstate(BlockDriverState *bs, int is_writable); void qemu_fsplice(QEMUFile *f_dst, QEMUFile *f_src, size_t size); size_t qemu_fsplice_tail(QEMUFile *f_dst, QEMUFile *f_src); diff --git a/migration/migration.c b/migration/migration.c index 6528b3ad41..6f82e8ea48 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -61,6 +61,7 @@ #include "sysemu/cpus.h" #include "yank_functions.h" #include "sysemu/qtest.h" +#include "qemu-snapshot.h" =20 #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttl= ing */ =20 @@ -3517,6 +3518,128 @@ static MigThrError postcopy_pause(MigrationState *s) } } =20 +/* + * Return-path message processing thread for qemu-snapshot tool + */ +void *qemu_snapshot_rp_listen_thread(void *opaque) +{ + QEMUFile *f =3D (QEMUFile *) opaque; + int res =3D 0; + uint64_t pages =3D 0; + + while (!res) { + uint8_t h_buf[512]; + const int h_max_len =3D sizeof(h_buf); + int h_type; + int h_len; + size_t count; + + h_type =3D qemu_get_be16(f); + h_len =3D qemu_get_be16(f); + + /* Make early check for input errors */ + res =3D qemu_file_get_error(f); + if (res) { + break; + } + + /* Check message type */ + if (h_type >=3D MIG_RP_MSG_MAX || h_type =3D=3D MIG_RP_MSG_INVALID= ) { + error_report("RP: received invalid message type %d length %d", + h_type, h_len); + res =3D -EINVAL; + break; + } + + /* Check message length */ + if (rp_cmd_args[h_type].len !=3D -1 && h_len !=3D rp_cmd_args[h_ty= pe].len) { + error_report("RP: received %s message len %d expected %ld", + rp_cmd_args[h_type].name, + h_len, rp_cmd_args[h_type].len); + res =3D -EINVAL; + break; + } else if (h_len > h_max_len) { + error_report("RP: received %s message len %d max_len %d", + rp_cmd_args[h_type].name, h_len, h_max_len); + res =3D -EINVAL; + break; + } + + count =3D qemu_get_buffer(f, h_buf, h_len); + if (count !=3D h_len) { + break; + } + + switch (h_type) { + case MIG_RP_MSG_SHUT: + { + int shut_error; + + shut_error =3D be32_to_cpu(*(uint32_t *) h_buf); + if (shut_error) { + error_report("RP: sibling shutdown, error %d", shut_error); + } + + /* Exit processing loop */ + res =3D 1; + break; + } + + case MIG_RP_MSG_REQ_PAGES: + case MIG_RP_MSG_REQ_PAGES_ID: + { + pages++; + uint64_t offset; + uint32_t size; + char *id_str =3D NULL; + + offset =3D be64_to_cpu(*(uint64_t *) (h_buf + 0)); + size =3D be32_to_cpu(*(uint32_t *) (h_buf + 8)); + + if (h_type =3D=3D MIG_RP_MSG_REQ_PAGES_ID) { + int h_parsed_len =3D rp_cmd_args[MIG_RP_MSG_REQ_PAGES].len; + + if (h_len > h_parsed_len) { + int id_len; + + /* RAM block id string */ + id_len =3D h_buf[h_parsed_len]; + id_str =3D (char *) &h_buf[h_parsed_len + 1]; + id_str[id_len] =3D 0; + + h_parsed_len +=3D id_len + 1; + } + + if (h_parsed_len !=3D h_len) { + error_report("RP: received %s message len %d expected = %d", + rp_cmd_args[MIG_RP_MSG_REQ_PAGES_ID].name, + h_len, h_parsed_len); + res =3D -EINVAL; + break; + } + } + + res =3D queue_page_request(id_str, offset, size); + break; + } + + default: + error_report("RP: received unexpected message type %d len %d", + h_type, h_len); + res =3D -EINVAL; + } + } + + if (res >=3D 0) { + res =3D qemu_file_get_error(f); + } + if (res) { + error_report("RP: listen thread exit, error %d", res); + } + + return NULL; +} + static MigThrError migration_detect_error(MigrationState *s) { int ret; diff --git a/migration/migration.h b/migration/migration.h index 5c43788a2b..fd6f8d3083 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -433,4 +433,5 @@ void migration_cancel(const Error *error); void populate_vfio_info(MigrationInfo *info); void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page); =20 +void *qemu_snapshot_rp_listen_thread(void *opaque); #endif diff --git a/migration/qemu-snapshot.c b/migration/qemu-snapshot.c index 280f5be25c..8090c7032d 100644 --- a/migration/qemu-snapshot.c +++ b/migration/qemu-snapshot.c @@ -44,6 +44,16 @@ typedef struct RAMBlock { char idstr[256]; /* RAM block id string */ } RAMBlock; =20 +/* Page request from destination in postcopy */ +typedef struct RAMPageRequest { + RAMBlock *block; + int64_t offset; + unsigned size; + + /* Link into ram_ctx.page_req */ + QSIMPLEQ_ENTRY(RAMPageRequest) next; +} RAMPageRequest; + typedef struct RAMPage { RAMBlock *block; /* RAM block containing the page */ int64_t offset; /* Page offset in RAM block */ @@ -57,6 +67,11 @@ typedef struct RAMCtx { QSIMPLEQ_HEAD(, RAMBlock) ram_block_list; RAMPage last_page; RAMBlock *last_sent_block; + + /* Page request queue for postcopy */ + QemuMutex page_req_mutex; + QSIMPLEQ_HEAD(, RAMPageRequest) page_req; + RAMBlock *last_req_block; } RAMCtx; =20 static RAMCtx ram_ctx; @@ -627,6 +642,143 @@ static int ram_send_setup(QEMUFile *f, void *opaque) return res; } =20 +static int send_each_ram_block_discard(QEMUFile *f) +{ + RAMBlock *block; + int res =3D 0; + uint64_t start; + uint64_t len; + + QSIMPLEQ_FOREACH(block, &ram_ctx.ram_block_list, next) { + start =3D block->discard_offset; + len =3D block->length - block->discard_offset; + qemu_savevm_send_postcopy_ram_discard(f, block->idstr, 1, &start, = &len); + + res =3D qemu_file_get_error(f); + if (res) { + break; + } + } + + return res; +} + +static int prepare_postcopy(StateLoadCtx *s) +{ + int res =3D 0; + + res =3D qemu_snapshot_postcopy_prepare(s->f_fd, page_size, page_size); + + if (!res) { + qemu_thread_create(&s->rp_listen_thread, "rp_thread", + qemu_snapshot_rp_listen_thread, s->f_rp_fd, + QEMU_THREAD_JOINABLE); + s->has_rp_listen_thread =3D true; + } + + return res; +} + +static int start_postcopy(StateLoadCtx *s) +{ + QIOChannelBuffer *bioc; + QEMUFile *fb; + int eof_pos; + int res =3D 0; + + /* + * Send RAM discards for each block's unsent part. Without discards, + * the userfault_fd code on destination will not trigger page requests + * as expected. Also, the UFFDIO_COPY ioctl that is used to place inco= ming + * page in postcopy would give an error if that page has not faulted + * with MISSING reason. + */ + res =3D send_each_ram_block_discard(s->f_fd); + if (res) { + error_report("here"); + return res; + } + + /* + * To perform a switch to postcopy on destination, we need to send + * commands and the device state data in the following order: + * * MIG_CMD_POSTCOPY_LISTEN + * * Non-iterable device state sections + * * MIG_CMD_POSTCOPY_RUN + * + * All this has to be packaged into a single blob using MIG_CMD_PACKAG= ED + * command. While loading the device state we may trigger page transfer + * requests and the fd must be free to process those, thus the destina= tion + * must read the whole device state off the fd before it starts + * processing it. To wrap it up in a package, QEMU buffer channel is u= sed. + */ + bioc =3D qio_channel_buffer_new(512 * 1024); + qio_channel_set_name(QIO_CHANNEL(bioc), "migration-postcopy-buffer"); + fb =3D qemu_fopen_channel_output(QIO_CHANNEL(bioc)); + object_unref(OBJECT(bioc)); + + /* MIG_CMD_POSTCOPY_LISTEN command */ + qemu_savevm_send_postcopy_listen(fb); + + /* The rest of non-iterable device state with an optional vmdesc secti= on */ + send_vmstate(s->f_vmstate, fb); + qemu_fflush(fb); + + /* + * vmdesc section may optionally be present at the end of the stream + * so we'll try to locate it and truncate the trailer. + */ + eof_pos =3D bioc->usage - 1; + + for (int offset =3D (bioc->usage - 11); offset >=3D 0; offset--) { + if (bioc->data[offset] =3D=3D QEMU_VM_SECTION_FOOTER && + bioc->data[offset + 5] =3D=3D QEMU_VM_EOF && + bioc->data[offset + 6] =3D=3D QEMU_VM_VMDESCRIPTION) { + uint32_t expected_length =3D bioc->usage - (offset + 11); + uint32_t json_length; + + json_length =3D be32_to_cpu(*(uint32_t *) &bioc->data[offset = + 7]); + if (json_length !=3D expected_length) { + error_report("Corrupted vmdesc trailer: length %" PRIu32 + " expected %" PRIu32, + json_length, expected_length); + res =3D -EINVAL; + goto fail; + } + + eof_pos =3D offset + 5; + break; + } + } + + /* + * When switching to postcopy we need to skip QEMU_VM_EOF token which + * normally is placed after the last non-iterable device state section + * (but before the vmdesc section). + * + * Skipping QEMU_VM_EOF is required to allow migration process to + * continue in postcopy. Vmdesc section also has to be skipped here. + */ + if (eof_pos >=3D 0 && bioc->data[eof_pos] =3D=3D QEMU_VM_EOF) { + bioc->usage =3D eof_pos; + bioc->offset =3D eof_pos; + } + + /* Finally is the MIG_CMD_POSTCOPY_RUN command */ + qemu_savevm_send_postcopy_run(fb); + + /* Now send that blob */ + qemu_savevm_send_packaged(s->f_fd, bioc->data, bioc->usage); + qemu_fflush(s->f_fd); + + s->in_postcopy =3D true; +fail: + qemu_fclose(fb); + load_state_check_errors(s, &res); + + return res; +} + static bool find_next_page(RAMPage *page) { RAMCtx *ram =3D &ram_ctx; @@ -709,6 +861,74 @@ void clear_page_range(RAMPage *page, int64_t length) ((length - 1) >> slice_bits) + 1); } =20 +int queue_page_request(const char *idstr, uint64_t offset, + uint32_t size) +{ + RAMCtx *ram =3D &ram_ctx; + RAMBlock *block; + RAMPageRequest *new_entry; + + if (!idstr) { + block =3D ram->last_req_block; + if (!block) { + error_report("RP-REQ_PAGES: no previous block"); + return -EINVAL; + } + } else { + block =3D ram_block_by_idstr(idstr); + if (!block) { + error_report("RP-REQ_PAGES: cannot find block %s", idstr); + return -EINVAL; + } + + ram->last_req_block =3D block; + } + + if (!ram_offset_in_block(block, offset)) { + error_report("RP-REQ_PAGES: offset 0x%" PRIx64 " out of RAM block = %s", + offset, idstr); + return -EINVAL; + } + + new_entry =3D g_new0(RAMPageRequest, 1); + new_entry->block =3D block; + new_entry->offset =3D offset; + new_entry->size =3D size; + + qemu_mutex_lock(&ram->page_req_mutex); + QSIMPLEQ_INSERT_TAIL(&ram->page_req, new_entry, next); + qemu_mutex_unlock(&ram->page_req_mutex); + + return 0; +} + +static bool get_queued_page(RAMPage *page) { + RAMCtx *ram =3D &ram_ctx; + + if (QSIMPLEQ_EMPTY_ATOMIC(&ram->page_req)) { + return false; + } + + QEMU_LOCK_GUARD(&ram->page_req_mutex); + if (!QSIMPLEQ_EMPTY(&ram->page_req)) { + RAMPageRequest *entry =3D QSIMPLEQ_FIRST(&ram->page_req); + RAMBlock *block =3D entry->block; + int64_t slice =3D entry->offset >> slice_bits; + + QSIMPLEQ_REMOVE_HEAD(&ram->page_req, next); + g_free(entry); + + if (test_bit(slice, block->bitmap)) { + page->block =3D block; + page->offset =3D slice << slice_bits; + + return true; + } + } + + return false; +} + static int coroutine_fn ram_load_pages(StateLoadCtx *s) { RAMCtx *ram =3D &ram_ctx; @@ -718,8 +938,9 @@ static int coroutine_fn ram_load_pages(StateLoadCtx *s) int64_t blk_offset, slice_offset, bdrv_offset; ssize_t res; int64_t flags =3D RAM_SAVE_FLAG_CONTINUE; + bool urgent =3D get_queued_page(&page); =20 - if (!find_next_page(&page)) { + if (!urgent && !find_next_page(&page)) { return 0; } =20 @@ -835,6 +1056,20 @@ int coroutine_fn load_state_main(StateLoadCtx *s) goto fail; } =20 + if (s->postcopy) { + res =3D prepare_postcopy(s); + if (res) { + error_report("Prepare postcopy failed"); + goto fail; + } + /* TODO: Add condition to start postcopy during the cycle below */ + res =3D start_postcopy(s); + if (res) { + error_report("Postcopy start failed"); + goto fail; + } + } + do { res =3D qemu_savevm_state_iterate(s->f_fd, false); /* Check for file errors */ @@ -845,8 +1080,11 @@ int coroutine_fn load_state_main(StateLoadCtx *s) goto fail; } =20 + /* If tool is in posctopy mode then vmstate have been already sent */ + if (!s->in_postcopy) { + send_vmstate(s->f_vmstate, s->f_fd); + } =20 - send_vmstate(s->f_vmstate, s->f_fd); qemu_put_byte(s->f_fd, QEMU_VM_EOF); qemu_fflush(s->f_fd); fail: @@ -865,6 +1103,10 @@ void ram_init_state(void) =20 /* Initialize RAM block list head */ QSIMPLEQ_INIT(&ram->ram_block_list); + + /* Initialize postcopy page request queue */ + qemu_mutex_init(&ram->page_req_mutex); + QSIMPLEQ_INIT(&ram->page_req); } =20 /* Destroy snapshot RAM state */ @@ -878,4 +1120,7 @@ void ram_destroy_state(void) g_free(block->bitmap); g_free(block); } + + /* Destroy page request mutex */ + qemu_mutex_destroy(&ram_ctx.page_req_mutex); } diff --git a/migration/savevm.c b/migration/savevm.c index b722e51163..b1320bd813 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3356,3 +3356,28 @@ void qmp_snapshot_delete(const char *job_id, =20 job_start(&s->common); } + +/* Do preparation before qemu-snapshot tool start postcopy */ +int qemu_snapshot_postcopy_prepare(QEMUFile *f_dest, + uint64_t sps, + uint64_t tps) +{ + uint64_t tmp[2]; + int res; + + /* Send POSTCOPY_ADVISE */ + tmp[0] =3D cpu_to_be64(sps); + tmp[1] =3D cpu_to_be64(tps); + qemu_savevm_command_send(f_dest, MIG_CMD_POSTCOPY_ADVISE, 16, (uint8_t= *) tmp); + + /* Open return path on destination */ + qemu_savevm_command_send(f_dest, MIG_CMD_OPEN_RETURN_PATH, 0, NULL); + + /* + * Check for file errors after sending POSTCOPY_ADVISE command + * since destination may already have closed input pipe in case + * postcopy had not been enabled in advance. + */ + res =3D qemu_file_get_error(f_dest); + return res; +} diff --git a/migration/savevm.h b/migration/savevm.h index 9abfcd88e5..94b6f60496 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -72,4 +72,8 @@ int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIn= comingState *mis); =20 int qemu_replace_ram_handler(void *ram_ops, void *opaque); =20 +int qemu_snapshot_postcopy_prepare(QEMUFile *f_dest, + uint64_t sps, + uint64_t tps); + #endif diff --git a/qemu-snapshot.c b/qemu-snapshot.c index 04bda74fb4..893086eb8a 100644 --- a/qemu-snapshot.c +++ b/qemu-snapshot.c @@ -239,6 +239,7 @@ static void coroutine_fn snapshot_load_co(void *opaque) StateLoadCtx *s =3D get_load_context(); int res; QIOChannel *ioc_fd; + QIOChannel *ioc_rp_fd; =20 init_load_context(); =20 @@ -260,8 +261,17 @@ static void coroutine_fn snapshot_load_co(void *opaque) object_unref(OBJECT(ioc_fd)); qemu_file_set_blocking(s->f_fd, false); =20 + /* qemufile on return path fd if we are going to use postcopy */ + if (params.postcopy) { + ioc_rp_fd =3D qio_channel_new_fd(params.rp_fd, NULL); + qio_channel_set_name(QIO_CHANNEL(ioc_fd), "migration-channel-rp"); + s->f_rp_fd =3D qemu_fopen_channel_input(ioc_rp_fd); + object_unref(OBJECT(ioc_rp_fd)); + } + s->state_parameters =3D *((StateInfo *) opaque); =20 + s->postcopy =3D params.postcopy; res =3D load_state_main(s); if (res) { error_report("Failed to load snapshot: %s", strerror(-res)); --=20 2.31.1