From patchwork Wed Feb 28 17:43:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Limonciello, Mario" X-Patchwork-Id: 10249067 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 CFF1960211 for ; Wed, 28 Feb 2018 17:45:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B020E28E28 for ; Wed, 28 Feb 2018 17:45:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C6A28E2B; Wed, 28 Feb 2018 17:45:16 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 486CF28E28 for ; Wed, 28 Feb 2018 17:45:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933140AbeB1RpB (ORCPT ); Wed, 28 Feb 2018 12:45:01 -0500 Received: from esa4.dell-outbound.iphmx.com ([68.232.149.214]:32190 "EHLO esa4.dell-outbound.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932466AbeB1Ro7 (ORCPT ); Wed, 28 Feb 2018 12:44:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dell.com; i=@dell.com; q=dns/txt; s=smtpout; t=1519839899; x=1551375899; h=from:to:cc:subject:date:message-id; bh=Eook6NyAVaKFYzAvoCtR6uroxeMihQJS+BS3hfX+6k4=; b=yzU8+TpLsNiCHvj90+jKm/Gw1e88HcY73M1oICXE9GyUYbPVbRe3uDUU t3C4Pi1l7BSUrCcz32R+GjF7DA+GMWuW8y7s+TciOTM45SvWi+7VxVlGC HUACRJ79/DoLGJMfZ0Geceo5JGwkAVUxflQhl2nhy+wpkWRI5yPZF0Jp6 0=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2HnAADY6ZZah2Oa6ERbGgEBAQEBAgEBA?= =?us-ascii?q?QEIAQEBAYMfggcom2WDGJZACoUwglhXFQECAQEBAQEBAgECEAEBAQoLCQgoL4I?= =?us-ascii?q?4IoNKT28ThRyuBohughYyhSOCJ4FXgWaIMoJwgxsFiByFVnSLbAmCC45pAoFkh?= =?us-ascii?q?1GFPQGRU4EuNIF1cIMSgXMBTxAMghpYjDwBAQE?= X-IPAS-Result: =?us-ascii?q?A2HnAADY6ZZah2Oa6ERbGgEBAQEBAgEBAQEIAQEBAYMfggc?= =?us-ascii?q?om2WDGJZACoUwglhXFQECAQEBAQEBAgECEAEBAQoLCQgoL4I4IoNKT28ThRyuB?= =?us-ascii?q?ohughYyhSOCJ4FXgWaIMoJwgxsFiByFVnSLbAmCC45pAoFkh1GFPQGRU4EuNIF?= =?us-ascii?q?1cIMSgXMBTxAMghpYjDwBAQE?= Received: from esa6.dell-outbound2.iphmx.com ([68.232.154.99]) by esa4.dell-outbound.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2018 11:44:57 -0600 Received: from ausc60pc101.us.dell.com ([143.166.85.206]) by esa6.dell-outbound2.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2018 23:44:57 +0600 X-LoopCount0: from 10.208.86.39 X-IronPort-AV: E=Sophos;i="5.47,406,1515477600"; d="scan'208";a="1222142815" X-DLP: DLP_GlobalPCIDSS From: Mario Limonciello To: "Rafael J . Wysocki" Cc: linux-acpi@vger.kernel.org, LKML , Mario Limonciello Subject: [RFC] power/hibernate: Make passing hibernate offsets more friendly Date: Wed, 28 Feb 2018 11:43:49 -0600 Message-Id: <1519839829-2191-1-git-send-email-mario.limonciello@dell.com> X-Mailer: git-send-email 2.7.4 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the only way to specify a hibernate offset for a swap file is on the kernel command line. This makes some changes to improve: 1) Add a new /sys/power/disk_offset that lets userspace specify the offset and disk to use when initiating a hibernate cycle. 2) Adjust /sys/power/resume interpretation to also read in an offset. Actually klibc's /bin/resume has supported passing a hibernate offset in since 20695264e21dcbde309cd81f73cfe2cea42e779d. The kernel was just lobbing anything after the device specified off the string. Instead parse that and populate hibernate offset with it. Signed-off-by: Mario Limonciello --- An alternative to introducing a new sysfs parameter may be to document setting these values via /sys/power/resume. If the wrong signature is found on the swapfile/swap partition by the kernel it does show an error but it updates the values and they'll work when actually invoked later. In that case it may make sense to adjust that error and make it level info and explain the situation. kernel/power/hibernate.c | 59 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a5c36e9..f606ed6 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -1025,33 +1025,68 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, power_attr(disk); -static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device), - MINOR(swsusp_resume_device)); -} - -static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t n) +static int parse_device_input(const char *buf, size_t n) { + unsigned long long offset; dev_t res; int len = n; char *name; + char *last; if (len && buf[len-1] == '\n') len--; name = kstrndup(buf, len, GFP_KERNEL); if (!name) return -ENOMEM; - + last = strrchr(name, ':'); + printk("%lu %s %s %d", last-name, name, last, len); + if (last != NULL && + (last-name) != len-1 && + sscanf(last+1, "%llu", &offset) == 1) + swsusp_resume_block = offset; res = name_to_dev_t(name); kfree(name); if (!res) return -EINVAL; + swsusp_resume_device = res; + + return 1; +} + +static ssize_t disk_offset_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf,"%d:%d:%lu\n", MAJOR(swsusp_resume_device), + MINOR(swsusp_resume_device), swsusp_resume_block); +} + +static ssize_t disk_offset_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t n) +{ + ssize_t rc = parse_device_input(buf, n); + if (rc < 0) + return rc; + + return n; +} + +power_attr(disk_offset); + +static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device), + MINOR(swsusp_resume_device)); +} + +static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t n) +{ + ssize_t rc = parse_device_input(buf, n); + if (rc < 0) + return rc; lock_system_sleep(); - swsusp_resume_device = res; unlock_system_sleep(); pr_info("Starting manual resume from disk\n"); noresume = 0; @@ -1106,6 +1141,7 @@ power_attr(reserved_size); static struct attribute * g[] = { &disk_attr.attr, + &disk_offset_attr.attr, &resume_attr.attr, &image_size_attr.attr, &reserved_size_attr.attr, @@ -1125,7 +1161,6 @@ static int __init pm_disk_init(void) core_initcall(pm_disk_init); - static int __init resume_setup(char *str) { if (noresume)