From nobody Sat Nov 23 18:01:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1723160576; cv=none; d=zohomail.com; s=zohoarc; b=jgDAMtNjPgXbcgb1RukaVkmqqBy9xg7CA55ecTw/8aSEeZyyqMdV5ZxDz0IT01hFuxklT+gtP56G6zUUVX7o2GnaHFxr8L7qQfJu8aOYUCMmY3Jm6OeERcjjGhev28Sawg3PxS+2WofJ6Qn4WIVHhQnSGlajOKkFcDkgQvjL8AY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723160576; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=FUCuRG7CLAhDtvV/UG391msEWZyysfpKIacpg2gjxPg=; b=CiMxkLstWENoBgU0p42f143NQKVaqy6uKp45nq17c8nF+GNGN6h0228UwZ11OThTJtwJb2mAoKr5bh46dQABzpy2nuezuB37KO2QbdK1v5yBvi/iRvWthhgkJQ/YjPtXork3C9Ujg0qtCEtAtozknFBBxu1nqdiuMGOtdpAikYU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723160576066966.8648045621877; Thu, 8 Aug 2024 16:42:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EEA221472; Thu, 8 Aug 2024 19:42:54 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2186314A2; Thu, 8 Aug 2024 19:39:03 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F1B21452; Thu, 8 Aug 2024 19:38:56 -0400 (EDT) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3B3871452 for ; Thu, 8 Aug 2024 19:38:36 -0400 (EDT) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2ef2cce8be8so15719411fa.1 for ; Thu, 08 Aug 2024 16:38:36 -0700 (PDT) Received: from localhost ([69.51.98.127]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c8d6a28fb4sm3668929173.89.2024.08.08.16.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 16:38:34 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1723160315; x=1723765115; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j7V+++zVavcA6V2+JOuX3BoNhg30qB9vmQUT1jAh9aw=; b=CAXjzptGGQ6dC++MQ5qusYYuS2LTOiNdgOXrAWj07/R4R3WXN/FR40VHfI8stWY7TA 6RByQu1blx/b93f5fvGeM7X2IgjDfiCQEWbdyhl8alKBjyuewbZTsix30cHusXfFi08N 6Oeb8n5T2+IqiNJrTv2DCvI4tvM6eZxecjaB9KaNk2EoDlM2xjoJ028Pj81nEqwnNjQP cuBxxQJMt+bst7oqeYcepdF9sggjkEAbrxn+XXGQS/KspALddMQDHlSMTLW2iFSaSQxr eZ8kZH6KFwSgT20mRrAplfyLi8DUxE4xfOdUNn3Ky/gIKoG0ARogWLUucq8/rZxeQw7x 5OHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723160315; x=1723765115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j7V+++zVavcA6V2+JOuX3BoNhg30qB9vmQUT1jAh9aw=; b=C+YWEUb0oYujZMu6MGFZ+pTD5vtNEG2c8CgjKwqLlfbFJW7SMthHYDEK/wicYzV96U Dd+BCkKsFyA6ED36D5Mti6BXi8CVmrtINKE38IDpqi/GJEv7Yo0sMMr0YAGSYd8+5J8O WWar/WtcuO047NjhA5OIDUDNaJpmm7BcVQLgI+INlhC+NVxF/Nyh/hj39pgrIXoSmYOA F83z+GUKshlngvDeTNSuS6PgKJUZvJ+VjQ2jjDUOYJgxB4FYMCpi1hOQWz4tzf7Qh0jA dQt68NqenPR36OspIzuvpdcinEBZf6qTkXP35BzjUEDG+D558KeH0e/u5ye0Exlqdjyt uf2w== X-Gm-Message-State: AOJu0YwnpuJc7scA7reKjVotLj2ywculbFNnlsgCHq7/hIn/vCUcnI69 7CRC0HQ1mEZQr6lUMeek62munis1wIuSfw6ND3vdvCpQK4/Dmi7zqGXjdUNgBIUktkQUabWPGTj 0 X-Google-Smtp-Source: AGHT+IH2MzsIKid98KzOjji1c0sltnErK6v/ku7J/IezqJ2eu379kSD5nQlaStIiF9u491rRduVxQw== X-Received: by 2002:a2e:be1f:0:b0:2ef:1d8d:21fd with SMTP id 38308e7fff4ca-2f19de1f94dmr28573181fa.2.1723160314760; Thu, 08 Aug 2024 16:38:34 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 09/20] qemu: Add helper function for creating save image fd Date: Thu, 8 Aug 2024 17:38:02 -0600 Message-Id: <20240808233813.22905-10-jfehlig@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240808233813.22905-1-jfehlig@suse.com> References: <20240808233813.22905-1-jfehlig@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MEQSK2YLCXKKGYPPVSPV2WX45CKE7TXI X-Message-ID-Hash: MEQSK2YLCXKKGYPPVSPV2WX45CKE7TXI X-MailFrom: jfehlig@suse.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: farosas@suse.de X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jim Fehlig via Devel Reply-To: Jim Fehlig X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723160577249116600 Content-Type: text/plain; charset="utf-8" Move the code in qemuSaveImageCreate that opens, labels, and wraps the save image fd to a helper function, providing more flexibility for upcoming mapped-ram support. Signed-off-by: Jim Fehlig --- src/qemu/qemu_saveimage.c | 65 +++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index bffa0a3397..6f2ce40124 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -361,6 +361,50 @@ qemuSaveImageDecompressionStop(virCommand *cmd, } =20 =20 +static int +qemuSaveImageCreateFd(virQEMUDriver *driver, + virDomainObj *vm, + const char *path, + virFileWrapperFd *wrapperFd, + bool *needUnlink, + unsigned int flags) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + int ret =3D -1; + VIR_AUTOCLOSE fd =3D -1; + int directFlag =3D 0; + unsigned int wrapperFlags =3D VIR_FILE_WRAPPER_NON_BLOCKING; + + if (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) { + wrapperFlags |=3D VIR_FILE_WRAPPER_BYPASS_CACHE; + directFlag =3D virFileDirectFdFlag(); + if (directFlag < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("bypass cache unsupported by this system")); + return -1; + } + } + + fd =3D virQEMUFileOpenAs(cfg->user, cfg->group, false, path, + O_WRONLY | O_TRUNC | O_CREAT | directFlag, + needUnlink); + + if (fd < 0) + return -1; + + if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) = < 0) + return -1; + + if (!(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapperFlags))) + return -1; + + ret =3D fd; + fd =3D -1; + + return ret; +} + + /* Helper function to execute a migration to file with a correct save head= er * the caller needs to make sure that the processors are stopped and do al= l other * actions besides saving memory */ @@ -377,33 +421,14 @@ qemuSaveImageCreate(virQEMUDriver *driver, bool needUnlink =3D false; int ret =3D -1; int fd =3D -1; - int directFlag =3D 0; virFileWrapperFd *wrapperFd =3D NULL; - unsigned int wrapperFlags =3D VIR_FILE_WRAPPER_NON_BLOCKING; =20 /* Obtain the file handle. */ - if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) { - wrapperFlags |=3D VIR_FILE_WRAPPER_BYPASS_CACHE; - directFlag =3D virFileDirectFdFlag(); - if (directFlag < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("bypass cache unsupported by this system")); - goto cleanup; - } - } + fd =3D qemuSaveImageCreateFd(driver, vm, path, wrapperFd, &needUnlink,= flags); =20 - fd =3D virQEMUFileOpenAs(cfg->user, cfg->group, false, path, - O_WRONLY | O_TRUNC | O_CREAT | directFlag, - &needUnlink); if (fd < 0) goto cleanup; =20 - if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) = < 0) - goto cleanup; - - if (!(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapperFlags))) - goto cleanup; - if (virQEMUSaveDataWrite(data, fd, path) < 0) goto cleanup; =20 --=20 2.35.3