From nobody Wed Nov 27 15:32:47 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=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1698263159; cv=none; d=zohomail.com; s=zohoarc; b=KAeXjynV/vuDbz20Fpr5w3XsQGJh/K8JxSAinZjpjc+qyYEvGIFf3OSnt6f+4Y7fvWh4Sv9QZ+d6EvfKYY5eTe7heB9Tt7eExEouVgPFoV1wAzUKPve5J7mABxvHCBTMUTPviEJiTUksWJl2x0gn6BvKxSGd6g54o6GXO82jELM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698263159; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D/fwwIW1ANeTA1KdqAle5D+G6L4iCHzY6a0qgjXAmrg=; b=JBDNXEuK1IemO+vSFJuWjw7ASQoO5swKACAS0U5bfgDYDjNR+JvVqrDZ7jBJTPtXRBiZTjRqwwFaHe+ten+0GdcbsX5QrANItNBw0eDIR4A3zunW6KdxTslXXGKB2mnED3DKnRLzI7HJgFn85mVxxrnMBRrJnPZr1OYWxr+6K1U= 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=pass 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 1698263159166997.6289319477597; Wed, 25 Oct 2023 12:45:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvjo4-0002zv-Oz; Wed, 25 Oct 2023 15:44:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvjny-0002tQ-Io for qemu-devel@nongnu.org; Wed, 25 Oct 2023 15:44:38 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvjnu-00074E-Fj for qemu-devel@nongnu.org; Wed, 25 Oct 2023 15:44:38 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39PEwIUY026237; Wed, 25 Oct 2023 19:44:33 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tv52e0p41-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Oct 2023 19:44:33 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39PIjFRs034583; Wed, 25 Oct 2023 19:44:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3tv5374bsh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Oct 2023 19:44:32 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39PJiUNP037154; Wed, 25 Oct 2023 19:44:31 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3tv5374bqp-3; Wed, 25 Oct 2023 19:44:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=D/fwwIW1ANeTA1KdqAle5D+G6L4iCHzY6a0qgjXAmrg=; b=nSVTiCxYQgaBVH7nEAm4DEd2EH1hGdXabprP3YtBTl/+sCUc9TIOTzCYB1v+HZIu2h5W Gh2XYScrh6GadC9x+lFVCzRcfshXQLtO8lr8FcarRMsUqNqVZ6a3EpIgVBV5zVoz0EYv FbsSf4jKo5X8IpIHmJ9/monJeoZRD/56p73NxHsrqhsE5XM7SSQMGBWedjemG7VqcPqd +NJEivRuARu21qdTuvPUMNNn32NHdK/RfIesKtLXhXbltDQcU6j1+TgG0c9Q+OSSV2CU S97eCOUyKDjLj6QhtC+mROww8ONtMrEyhkihxeQxnjFMNcdIiBDo+WAz5p48U1n0pSxC /A== From: Steve Sistare To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , "Daniel P. Berrange" , Steve Sistare Subject: [PATCH V2 2/6] migration: per-mode blockers Date: Wed, 25 Oct 2023 12:44:25 -0700 Message-Id: <1698263069-406971-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1698263069-406971-1-git-send-email-steven.sistare@oracle.com> References: <1698263069-406971-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-25_09,2023-10-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310250169 X-Proofpoint-ORIG-GUID: V_mVtryPa9-K0aMHo-grndFv9W1fZaO3 X-Proofpoint-GUID: V_mVtryPa9-K0aMHo-grndFv9W1fZaO3 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=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1698263159655100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Extend the blocker interface so that a blocker can be registered for one or more migration modes. The existing interfaces register a blocker for all modes, and the new interfaces take a varargs list of modes. Internally, maintain a separate blocker list per mode. The same Error object may be added to multiple lists. When a block is deleted, it is removed from every list, and the Error is freed. No functional change until a new mode is added. Signed-off-by: Steve Sistare Reviewed-by: Juan Quintela --- include/migration/blocker.h | 44 +++++++++++++++++++-- migration/migration.c | 95 ++++++++++++++++++++++++++++++++++++++---= ---- stubs/migr-blocker.c | 10 +++++ 3 files changed, 132 insertions(+), 17 deletions(-) diff --git a/include/migration/blocker.h b/include/migration/blocker.h index b048f30..a687ac0 100644 --- a/include/migration/blocker.h +++ b/include/migration/blocker.h @@ -14,8 +14,12 @@ #ifndef MIGRATION_BLOCKER_H #define MIGRATION_BLOCKER_H =20 +#include "qapi/qapi-types-migration.h" + +#define MIG_MODE_ALL MIG_MODE__MAX + /** - * @migrate_add_blocker - prevent migration from proceeding + * @migrate_add_blocker - prevent all modes of migration from proceeding * * @reasonp - address of an error to be returned whenever migration is att= empted * @@ -30,8 +34,8 @@ int migrate_add_blocker(Error **reasonp, Error **errp); =20 /** - * @migrate_add_blocker_internal - prevent migration from proceeding witho= ut - * only-migrate implications + * @migrate_add_blocker_internal - prevent all modes of migration from + * proceeding, but ignore -only-migratable * * @reasonp - address of an error to be returned whenever migration is att= empted * @@ -50,7 +54,7 @@ int migrate_add_blocker(Error **reasonp, Error **errp); int migrate_add_blocker_internal(Error **reasonp, Error **errp); =20 /** - * @migrate_del_blocker - remove a blocking error from migration and free = it. + * @migrate_del_blocker - remove a migration blocker from all modes and fr= ee it. * * @reasonp - address of the error blocking migration * @@ -58,4 +62,36 @@ int migrate_add_blocker_internal(Error **reasonp, Error = **errp); */ void migrate_del_blocker(Error **reasonp); =20 +/** + * @migrate_add_blocker_normal - prevent normal migration mode from procee= ding + * + * @reasonp - address of an error to be returned whenever migration is att= empted + * + * @errp - [out] The reason (if any) we cannot block migration right now. + * + * @returns - 0 on success, -EBUSY/-EACCES on failure, with errp set. + * + * *@reasonp is freed and set to NULL if failure is returned. + * On success, the caller must not free @reasonp, except by + * calling migrate_del_blocker. + */ +int migrate_add_blocker_normal(Error **reasonp, Error **errp); + +/** + * @migrate_add_blocker_modes - prevent some modes of migration from proce= eding + * + * @reasonp - address of an error to be returned whenever migration is att= empted + * + * @errp - [out] The reason (if any) we cannot block migration right now. + * + * @mode - one or more migration modes to be blocked. The list is termina= ted + * by -1 or MIG_MODE_ALL. For the latter, all modes are blocked. + * + * @returns - 0 on success, -EBUSY/-EACCES on failure, with errp set. + * + * *@reasonp is freed and set to NULL if failure is returned. + * On success, the caller must not free *@reasonp before the blocker is re= moved. + */ +int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode,= ...); + #endif diff --git a/migration/migration.c b/migration/migration.c index 67547eb..b8b54e6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -92,7 +92,7 @@ enum mig_rp_message_type { static MigrationState *current_migration; static MigrationIncomingState *current_incoming; =20 -static GSList *migration_blockers; +static GSList *migration_blockers[MIG_MODE__MAX]; =20 static bool migration_object_check(MigrationState *ms, Error **errp); static int migration_maybe_pause(MigrationState *s, @@ -1011,7 +1011,7 @@ static void fill_source_migration_info(MigrationInfo = *info) { MigrationState *s =3D migrate_get_current(); int state =3D qatomic_read(&s->state); - GSList *cur_blocker =3D migration_blockers; + GSList *cur_blocker =3D migration_blockers[migrate_mode()]; =20 info->blocked_reasons =3D NULL; =20 @@ -1475,38 +1475,105 @@ int migrate_init(MigrationState *s, Error **errp) return 0; } =20 -int migrate_add_blocker_internal(Error **reasonp, Error **errp) +static bool is_busy(Error **reasonp, Error **errp) { + ERRP_GUARD(); + /* Snapshots are similar to migrations, so check RUN_STATE_SAVE_VM too= . */ if (runstate_check(RUN_STATE_SAVE_VM) || !migration_is_idle()) { error_propagate_prepend(errp, *reasonp, "disallowing migration blocker " "(migration/snapshot in progress) for: "); *reasonp =3D NULL; - return -EBUSY; + return true; } - - migration_blockers =3D g_slist_prepend(migration_blockers, *reasonp); - return 0; + return false; } =20 -int migrate_add_blocker(Error **reasonp, Error **errp) +static bool is_only_migratable(Error **reasonp, Error **errp, int modes) { - if (only_migratable) { + ERRP_GUARD(); + + if (only_migratable && (modes & BIT(MIG_MODE_NORMAL))) { error_propagate_prepend(errp, *reasonp, "disallowing migration blocker " "(--only-migratable) for: "); *reasonp =3D NULL; + return true; + } + return false; +} + +static int get_modes(MigMode mode, va_list ap) +{ + int modes =3D 0; + + while (mode !=3D -1 && mode !=3D MIG_MODE_ALL) { + assert(mode >=3D MIG_MODE_NORMAL && mode < MIG_MODE__MAX); + modes |=3D BIT(mode); + mode =3D va_arg(ap, MigMode); + } + if (mode =3D=3D MIG_MODE_ALL) { + modes =3D BIT(MIG_MODE__MAX) - 1; + } + return modes; +} + +static int add_blockers(Error **reasonp, Error **errp, int modes) +{ + for (MigMode mode =3D 0; mode < MIG_MODE__MAX; mode++) { + if (modes & BIT(mode)) { + migration_blockers[mode] =3D g_slist_prepend(migration_blocker= s[mode], + *reasonp); + } + } + return 0; +} + +int migrate_add_blocker(Error **reasonp, Error **errp) +{ + return migrate_add_blocker_modes(reasonp, errp, MIG_MODE_ALL); +} + +int migrate_add_blocker_normal(Error **reasonp, Error **errp) +{ + return migrate_add_blocker_modes(reasonp, errp, MIG_MODE_NORMAL, -1); +} + +int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode,= ...) +{ + int modes; + va_list ap; + + va_start(ap, mode); + modes =3D get_modes(mode, ap); + va_end(ap); + + if (is_only_migratable(reasonp, errp, modes)) { return -EACCES; + } else if (is_busy(reasonp, errp)) { + return -EBUSY; } + return add_blockers(reasonp, errp, modes); +} =20 - return migrate_add_blocker_internal(reasonp, errp); +int migrate_add_blocker_internal(Error **reasonp, Error **errp) +{ + int modes =3D BIT(MIG_MODE__MAX) - 1; + + if (is_busy(reasonp, errp)) { + return -EBUSY; + } + return add_blockers(reasonp, errp, modes); } =20 void migrate_del_blocker(Error **reasonp) { if (*reasonp) { - migration_blockers =3D g_slist_remove(migration_blockers, *reasonp= ); + for (MigMode mode =3D 0; mode < MIG_MODE__MAX; mode++) { + migration_blockers[mode] =3D g_slist_remove(migration_blockers= [mode], + *reasonp); + } error_free(*reasonp); *reasonp =3D NULL; } @@ -1602,12 +1669,14 @@ void qmp_migrate_pause(Error **errp) =20 bool migration_is_blocked(Error **errp) { + GSList *blockers =3D migration_blockers[migrate_mode()]; + if (qemu_savevm_state_blocked(errp)) { return true; } =20 - if (migration_blockers) { - error_propagate(errp, error_copy(migration_blockers->data)); + if (blockers) { + error_propagate(errp, error_copy(blockers->data)); return true; } =20 diff --git a/stubs/migr-blocker.c b/stubs/migr-blocker.c index 17a5dbf..11cbff2 100644 --- a/stubs/migr-blocker.c +++ b/stubs/migr-blocker.c @@ -6,6 +6,16 @@ int migrate_add_blocker(Error **reasonp, Error **errp) return 0; } =20 +int migrate_add_blocker_normal(Error **reasonp, Error **errp) +{ + return 0; +} + +int migrate_add_blocker_modes(Error **reasonp, Error **errp, MigMode mode,= ...) +{ + return 0; +} + void migrate_del_blocker(Error **reasonp) { } --=20 1.8.3.1