From patchwork Tue Jun 19 19:38:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 10475289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79C6E6029B for ; Tue, 19 Jun 2018 19:42:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D7F28BCA for ; Tue, 19 Jun 2018 19:42:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CF6D28BDA; Tue, 19 Jun 2018 19:42:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D5AF428BCA for ; Tue, 19 Jun 2018 19:42:30 +0000 (UTC) Received: from localhost ([::1]:44656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVMWL-0004jy-NV for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jun 2018 15:42:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVMSX-0001i1-VX for qemu-devel@nongnu.org; Tue, 19 Jun 2018 15:38:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVMSW-0002v9-Np for qemu-devel@nongnu.org; Tue, 19 Jun 2018 15:38:33 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:33086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVMSW-0002un-Ge for qemu-devel@nongnu.org; Tue, 19 Jun 2018 15:38:32 -0400 Received: by mail-qt0-x241.google.com with SMTP id l10-v6so894120qtj.0 for ; Tue, 19 Jun 2018 12:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zx+yLPVnrnotPHzfYdyA9IuCS6O3rQZhHm+pbPNCWqc=; b=MTZWzVu6EhJbdk1daxv8n8ytIAdkODulfgP/0t7VPLODg9My/5JKuX+glN0/p/9vuI Vsz/rQjuGyPy+tPEHy4K1Ey0BBeBOu23iLw8Nd/x3Ml1KS4N96xDzX5cJ+6BJVZfbxtL vdkwEBLGOudbwCvOBOtxVcPBPYkXuH9HhIt0kfSaEC/QMt00CKV3+M9sRNM4gX/URZ/x R7ndhwyRqjnEpe/PEcGQGNCtZUyT8ZrkEu1Q+Y/Ta0rYJN1X5AdXLTr1tQ58zNN/0NZL lLjEdlaBfLB+q+zlo3pmyjG8U/G3JF1bAkc2xRxDljL8n28MXo+5+Ka9hGF6OBPt3zHT oBQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zx+yLPVnrnotPHzfYdyA9IuCS6O3rQZhHm+pbPNCWqc=; b=LT+yq0aa7YY1PJUdlirHXJGbzwVjAxodHpf5U/illAI/uwmpr/EnxMBmyrV6IDFP8w W68xmZ+H7wB+JMqhV1YSkl7dSDRZY/zwnolqM/SGWACeNXXfMmQu8i58Rfq/yCP+ohg5 KTlrjaMGMwAXBFCnc+qbkmJWBfzLs9h+6+X90VAZtvuimnzWY54ZS3rWXnIPqjwt1L2v zSSUlOMz8e134OIUp7M7r3RO3Ut54gL73jrve7iFABDYLyALdxAVDu9xxO53bWGeUeoq BVoCTXIHXSZoVvbdEkvbciO7IOOD1UkD/vy8IT+LBTREbYE3rLaWwdAFSB9oVYvxlYxY vTAQ== X-Gm-Message-State: APt69E0azwfEEVnff/+IjnxhAYJDtgRkcIo8VHrHjmieetIO/kITguWI kVG88+pmzSH5ceGLL/a86JCHD94QUHI= X-Google-Smtp-Source: ADUXVKIMejBXVqUVVENT9/kz87HQT+SxOI9XT4axN8Xd1DqlWctPNDTmmy1gcFhdoHmAIUZuLfnbew== X-Received: by 2002:a0c:b916:: with SMTP id u22-v6mr15341710qvf.224.1529437111841; Tue, 19 Jun 2018 12:38:31 -0700 (PDT) Received: from localhost.localdomain ([2804:431:f701:9a90:70ce:7c7a:343e:57]) by smtp.gmail.com with ESMTPSA id a62-v6sm419686qka.11.2018.06.19.12.38.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jun 2018 12:38:31 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 19 Jun 2018 16:38:01 -0300 Message-Id: <20180619193806.17419-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619193806.17419-1-danielhb413@gmail.com> References: <20180619193806.17419-1-danielhb413@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v1 1/6] qga: refactoring qmp_guest_suspend_* functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , armbru@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP To be able to add new suspend mechanisms we need to detach the existing QMP functions from the current implementation specifics. At this moment we have functions such as qmp_guest_suspend_ram calling bios_suspend_mode and guest_suspend passing the pmutils command and arguments as parameters. This patch removes this logic from the QMP functions, moving them to the respective functions that will have to deal with which binary to use. Signed-off-by: Daniel Henrique Barboza --- qga/commands-posix.c | 87 ++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eae817191b..63c49791a4 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1438,15 +1438,38 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) #define LINUX_SYS_STATE_FILE "/sys/power/state" #define SUSPEND_SUPPORTED 0 #define SUSPEND_NOT_SUPPORTED 1 +#define SUSPEND_MODE_DISK 1 +#define SUSPEND_MODE_RAM 2 +#define SUSPEND_MODE_HYBRID 3 -static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg, - const char *sysfile_str, Error **errp) +static void bios_supports_mode(int suspend_mode, Error **errp) { Error *local_err = NULL; + const char *pmutils_arg, *sysfile_str; + const char *pmutils_bin = "pm-is-supported"; char *pmutils_path; pid_t pid; int status; + switch (suspend_mode) { + + case SUSPEND_MODE_DISK: + pmutils_arg = "--hibernate"; + sysfile_str = "disk"; + break; + case SUSPEND_MODE_RAM: + pmutils_arg = "--suspend"; + sysfile_str = "mem"; + break; + case SUSPEND_MODE_HYBRID: + pmutils_arg = "--suspend-hybrid"; + sysfile_str = NULL; + break; + default: + error_setg(errp, "guest suspend mode not supported"); + return; + } + pmutils_path = g_find_program_in_path(pmutils_bin); pid = fork(); @@ -1523,14 +1546,39 @@ out: g_free(pmutils_path); } -static void guest_suspend(const char *pmutils_bin, const char *sysfile_str, - Error **errp) +static void guest_suspend(int suspend_mode, Error **errp) { Error *local_err = NULL; + const char *pmutils_bin, *sysfile_str; char *pmutils_path; pid_t pid; int status; + bios_supports_mode(suspend_mode, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + switch (suspend_mode) { + + case SUSPEND_MODE_DISK: + pmutils_bin = "pm-hibernate"; + sysfile_str = "disk"; + break; + case SUSPEND_MODE_RAM: + pmutils_bin = "pm-suspend"; + sysfile_str = "mem"; + break; + case SUSPEND_MODE_HYBRID: + pmutils_bin = "pm-suspend-hybrid"; + sysfile_str = NULL; + break; + default: + error_setg(errp, "unknown guest suspend mode"); + return; + } + pmutils_path = g_find_program_in_path(pmutils_bin); pid = fork(); @@ -1593,42 +1641,17 @@ out: void qmp_guest_suspend_disk(Error **errp) { - Error *local_err = NULL; - - bios_supports_mode("pm-is-supported", "--hibernate", "disk", &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - guest_suspend("pm-hibernate", "disk", errp); + guest_suspend(SUSPEND_MODE_DISK, errp); } void qmp_guest_suspend_ram(Error **errp) { - Error *local_err = NULL; - - bios_supports_mode("pm-is-supported", "--suspend", "mem", &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - guest_suspend("pm-suspend", "mem", errp); + guest_suspend(SUSPEND_MODE_RAM, errp); } void qmp_guest_suspend_hybrid(Error **errp) { - Error *local_err = NULL; - - bios_supports_mode("pm-is-supported", "--suspend-hybrid", NULL, - &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - guest_suspend("pm-suspend-hybrid", NULL, errp); + guest_suspend(SUSPEND_MODE_HYBRID, errp); } static GuestNetworkInterfaceList *