/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
* Copyright 2012 Milan Jurik. All rights reserved.
*/
/*
* System call to checkpoint and resume the currently running kernel
*/
#include <sys/autoconf.h>
#include <sys/machsystm.h>
extern int i_cpr_is_supported(int sleeptype);
extern int cpr_is_ufs(struct vfs *);
extern int cpr_is_zfs(struct vfs *);
extern int cpr_check_spec_statefile(void);
extern int cpr_reusable_mount_check(void);
extern int i_cpr_reusable_supported(void);
extern int i_cpr_reusefini(void);
extern struct mod_ops mod_miscops;
extern int cpr_init(int);
extern void cpr_done(void);
extern void i_cpr_stop_other_cpus(void);
extern int i_cpr_power_down(int);
#if defined(__sparc)
extern void cpr_forget_cprconfig(void);
#endif
&mod_miscops, "checkpoint resume"
};
};
int cpr_reusable_mode;
int cpr_debug;
/*
* All the loadable module related code follows
*/
int
_init(void)
{
register int e;
if ((e = mod_install(&modlinkage)) == 0) {
}
return (e);
}
int
_fini(void)
{
register int e;
if ((e = mod_remove(&modlinkage)) == 0) {
}
return (e);
}
int
{
}
static
int
atoi(char *p)
{
int i;
i = (*p++ - '0');
while (*p != '\0')
i = 10 * i + (*p++ - '0');
return (i);
}
int
{
#if defined(__sparc)
"that no swap area be configured.\n";
"a block device. See power.conf(4) and pmconfig(1M).\n";
"checkpoint/resume when in reusable statefile mode. "
"use uadmin A_FREEZE AD_REUSEFINI (uadmin %d %d) "
"to exit reusable statefile mode.\n";
#endif
register int rc = 0;
int cpr_sleeptype;
/*
* First, reject commands that we don't (yet) support on this arch.
* This is easier to understand broken out like this than grotting
* through the second switch below.
*/
switch (fcn) {
#if defined(__sparc)
case AD_CHECK_SUSPEND_TO_RAM:
case AD_SUSPEND_TO_RAM:
return (ENOTSUP);
case AD_CHECK_SUSPEND_TO_DISK:
case AD_SUSPEND_TO_DISK:
case AD_CPR_REUSEINIT:
case AD_CPR_NOCOMPRESS:
case AD_CPR_FORCE:
case AD_CPR_REUSABLE:
case AD_CPR_REUSEFINI:
case AD_CPR_TESTZ:
case AD_CPR_TESTNOZ:
case AD_CPR_TESTHALT:
case AD_CPR_SUSP_DEVICES:
break;
#endif
#if defined(__x86)
case AD_CHECK_SUSPEND_TO_DISK:
case AD_SUSPEND_TO_DISK:
case AD_CPR_REUSEINIT:
case AD_CPR_NOCOMPRESS:
case AD_CPR_FORCE:
case AD_CPR_REUSABLE:
case AD_CPR_REUSEFINI:
case AD_CPR_TESTZ:
case AD_CPR_TESTNOZ:
case AD_CPR_TESTHALT:
case AD_CPR_PRINT:
return (ENOTSUP);
/* The DEV_* values need to be removed after sys-syspend is fixed */
case DEV_CHECK_SUSPEND_TO_RAM:
case DEV_SUSPEND_TO_RAM:
case AD_CPR_SUSP_DEVICES:
case AD_CHECK_SUSPEND_TO_RAM:
case AD_SUSPEND_TO_RAM:
case AD_FORCE_SUSPEND_TO_RAM:
case AD_DEVICE_SUSPEND_TO_RAM:
break;
#endif
}
#if defined(__sparc)
/*
* Need to know if we're in reusable mode, but we will likely have
* rebooted since REUSEINIT, so we have to get the info from the
* file system
*/
if (!cpr_reusable_mode)
#endif
switch (fcn) {
#if defined(__sparc)
case AD_CPR_REUSEINIT:
if (!i_cpr_reusable_supported())
return (ENOTSUP);
if (!cpr_statefile_is_spec()) {
return (EINVAL);
}
if ((rc = cpr_check_spec_statefile()) != 0)
return (rc);
if (swapinfo) {
return (EINVAL);
}
cpr_test_mode = 0;
break;
case AD_CPR_NOCOMPRESS:
case AD_CPR_COMPRESS:
case AD_CPR_FORCE:
if (cpr_reusable_mode) {
return (ENOTSUP);
}
cpr_test_mode = 0;
break;
case AD_CPR_REUSABLE:
if (!i_cpr_reusable_supported())
return (ENOTSUP);
if (!cpr_statefile_is_spec()) {
return (EINVAL);
}
if ((rc = cpr_check_spec_statefile()) != 0)
return (rc);
if (swapinfo) {
return (EINVAL);
}
if ((rc = cpr_reusable_mount_check()) != 0)
return (rc);
cpr_test_mode = 0;
break;
case AD_CPR_REUSEFINI:
if (!i_cpr_reusable_supported())
return (ENOTSUP);
cpr_test_mode = 0;
break;
case AD_CPR_TESTZ:
case AD_CPR_TESTNOZ:
case AD_CPR_TESTHALT:
if (cpr_reusable_mode) {
return (ENOTSUP);
}
cpr_test_mode = 1;
break;
case AD_CPR_CHECK:
return (ENOTSUP);
return (0);
case AD_CPR_PRINT:
CPR_STAT_EVENT_END("POST CPR DELAY");
return (0);
#endif
case AD_CPR_DEBUG0:
cpr_debug = 0;
return (0);
case AD_CPR_DEBUG1:
case AD_CPR_DEBUG2:
case AD_CPR_DEBUG3:
case AD_CPR_DEBUG4:
case AD_CPR_DEBUG5:
case AD_CPR_DEBUG7:
case AD_CPR_DEBUG8:
return (0);
case AD_CPR_DEBUG9:
cpr_debug |= CPR_DEBUG6;
return (0);
/* The DEV_* values need to be removed after sys-syspend is fixed */
case DEV_CHECK_SUSPEND_TO_RAM:
case DEV_SUSPEND_TO_RAM:
case AD_CHECK_SUSPEND_TO_RAM:
case AD_SUSPEND_TO_RAM:
break;
break;
break;
case AD_FORCE_SUSPEND_TO_RAM:
break;
case AD_DEVICE_SUSPEND_TO_RAM:
/* Didn't pass enough arguments */
return (EINVAL);
}
break;
case AD_CPR_SUSP_DEVICES:
"Some devices did not suspend "
"and may be unusable");
(void) cpr_resume_devices(ddi_root_node(), 0);
return (0);
default:
return (ENOTSUP);
}
if (!i_cpr_is_supported(cpr_sleeptype))
return (ENOTSUP);
#if defined(__sparc)
if ((cpr_sleeptype == CPR_TODISK &&
return (ENOTSUP);
#endif
if (fcn == AD_CHECK_SUSPEND_TO_RAM ||
fcn == DEV_CHECK_SUSPEND_TO_RAM) {
return (0);
}
#if defined(__sparc)
if (fcn == AD_CPR_REUSEINIT) {
if (mutex_tryenter(&cpr_slock) == 0)
return (EBUSY);
if (cpr_reusable_mode) {
return (EBUSY);
}
rc = i_cpr_reuseinit();
return (rc);
}
if (fcn == AD_CPR_REUSEFINI) {
if (mutex_tryenter(&cpr_slock) == 0)
return (EBUSY);
if (!cpr_reusable_mode) {
return (EINVAL);
}
rc = i_cpr_reusefini();
return (rc);
}
#endif
/*
* acquire cpr serial lock and init cpr state structure.
*/
return (rc);
#if defined(__sparc)
if (fcn == AD_CPR_REUSABLE) {
if ((rc = i_cpr_check_cprinfo()) != 0) {
return (rc);
}
}
#endif
/*
* Call the main cpr routine. If we are successful, we will be coming
* down from the resume side, otherwise we are still in suspend.
*/
/*
* In the suspend to RAM case, by the time we get
* control back we're already resumed
*/
if (cpr_sleeptype == CPR_TORAM) {
cpr_done();
return (rc);
}
#if defined(__sparc)
/*
* Back from a successful checkpoint
*/
/* NOTREACHED */
}
/* make sure there are no more changes to the device tree */
/*
* stop other cpus and raise our priority. since there is only
* one active cpu after this, and our priority will be too high
* for us to be preempted, we're essentially single threaded
* from here on out.
*/
(void) spl6();
/*
* try and reset leaf devices. reset_leaves() should only
* be called when there are no other threads that could be
* accessing devices
*/
reset_leaves();
/*
* If i_cpr_power_down() succeeds, it'll not return
*
* Drives with write-cache enabled need to flush
* their cache.
*/
if (fcn != AD_CPR_TESTHALT) {
(void) i_cpr_power_down(cpr_sleeptype);
}
/* currently CPR_TODISK comes back via a boot path */
/* NOTREACHED */
#endif
}
cpr_done();
return (rc);
}