cpr_misc.c revision ae115bc77f6fcde83175c75b4206dc2e50747966
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/pathname.h>
/*
* CPR miscellaneous support routines
*/
extern cpu_t *i_cpr_bootcpu(void);
extern caddr_t i_cpr_map_setup(void);
extern void i_cpr_free_memory_resources(void);
extern size_t cpr_buf_size;
extern char *cpr_buf;
extern size_t cpr_pagedata_size;
extern char *cpr_pagedata;
extern int cpr_bufs_allocated;
extern int cpr_bitmaps_allocated;
static int cprconfig_loaded = 0;
static int cpr_statefile_ok(vnode_t *, int);
static int cpr_p_online(cpu_t *, int);
static void cpr_save_mp_state(void);
int cpr_is_ufs(struct vfs *);
char cpr_default_path[] = CPR_DEFAULT;
/*
* cmn_err() followed by a 1/4 second delay; this gives the
* logging service a chance to flush messages and helps avoid
* intermixing output from prom_printf().
*/
/*PRINTFLIKE2*/
void
{
}
int
{
/*
*/
if (mutex_tryenter(&cpr_slock) == 0)
return (EBUSY);
CPR->c_substate = 0;
CPR->c_cprboot_magic = 0;
CPR->c_alloc_cnt = 0;
if (fcn == AD_CPR_REUSABLE)
else
/*
* reserve CPR_MAXCONTIG virtual pages for cpr_dump()
*/
return (EAGAIN);
}
if (cpr_debug & CPR_DEBUG3)
return (0);
}
/*
* This routine releases any resources used during the checkpoint.
*/
void
cpr_done(void)
{
/*
* Free pages used by cpr buffers.
*/
if (cpr_buf) {
}
if (cpr_pagedata) {
cpr_pagedata = NULL;
}
}
/*
* reads config data into cprconfig
*/
static int
cpr_get_config(void)
{
static char config_path[] = CPR_CONFIG;
char *fmt;
int err;
if (cprconfig_loaded)
return (0);
fmt = "cannot %s config file \"%s\", error %d\n";
return (err);
}
if (err) {
return (err);
}
cprconfig_loaded = 1;
else {
"rerun pmconfig(1M)\n", config_path);
}
return (err);
}
/*
* concat fs and path fields of the cprconfig structure;
* returns pointer to the base of static data
*/
static char *
cpr_cprconfig_to_path(void)
{
static char full_path[MAXNAMELEN];
char *ptr;
/*
*/
if (*ptr == '/')
ptr++;
return (full_path);
}
/*
* Verify that the information in the configuration file regarding the
* location for the statefile is still valid, depending on cf_type.
* for CFT_UFS, cf_fs must still be a mounted filesystem, it must be
* mounted on the same device as when pmconfig was last run,
* and the translation of that device to a node in the prom's
* device tree must be the same as when pmconfig was last run.
* for CFT_SPEC, cf_path must be the path to a block special file,
* it must have no file system mounted on it,
* and the translation of that device to a node in the prom's
* device tree must be the same as when pmconfig was last run.
*/
static int
{
static const char long_name[] = "Statefile pathname is too long.\n";
static const char lookup_fmt[] = "Lookup failed for "
"cpr statefile device %s.\n";
static const char path_chg_fmt[] = "Device path for statefile "
"has changed from %s to %s.\t%s\n";
static const char rerun[] = "Please rerun pmconfig(1m).";
int error;
char *errstr;
int found = 0;
union {
char un_devpath[OBP_MAXPATHLEN];
char un_sfpath[MAXNAMELEN];
} un;
/*
* We need not worry about locking or the timing of releasing
* the vnode, since we are single-threaded now.
*/
case CFT_SPEC:
return (ENAMETOOLONG);
}
return (error);
}
errstr = "statefile must be a block device";
errstr = "statefile device must not "
"have a file system mounted on it";
errstr = "statefile device must not "
"be configured as swap file";
else
if (errstr) {
return (ENOTSUP);
}
}
return (error);
case CFT_UFS:
break; /* don't indent all the original code */
default:
}
/*
* The original code for UFS statefile
*/
return (ENAMETOOLONG);
}
if (*sfpath != '/') {
"must begin with a /\n", sfpath);
return (EINVAL);
}
/*
* Find the longest prefix of the statefile pathname which
* is the mountpoint of a filesystem. This string must
* match the cf_fs field we read from the config file. Other-
* wise the user has changed things without running pmconfig.
*/
*slash = '/';
"statefile path %s was not found.\n", sfpath);
return (error);
}
do {
found = 1;
break;
}
/*
* If we have found a filesystem mounted on the current
* path prefix, remember the end of the string in
* "longest". If it happens to be the the exact fs
* saved in the configuration file, save the current
* ufsvfsp so we can make additional checks further down.
*/
if (found) {
}
found = 0;
}
*slash = '/';
}
*longest = '\0';
"the statefile when pmconfig was run (%s) has "
return (EINVAL);
}
return (error);
}
"statefile no longer mounted on device %s. "
return (ENXIO);
}
return (error);
}
return (0);
}
/*
* Make sure that the statefile can be used as a block special statefile
* (meaning that is exists and has nothing mounted on it)
* Returns errno if not a valid statefile.
*/
int
cpr_check_spec_statefile(void)
{
int err;
if (err = cpr_get_config())
return (err);
return (ENXIO);
return (cpr_verify_statefile_path());
}
int
{
register int rc = 0;
char *str;
/*
* Statefile size validation. If checkpoint the first time, disk blocks
* allocation will be done; otherwise, just do file size check.
* if statefile allocation is being retried, C_VP will be inited
*/
if (alloc_retry) {
str = "\n-->Retrying statefile allocation...";
} else {
/*
* Open an exiting file for writing, the state file needs to be
* pre-allocated since we can't and don't want to do allocation
* during checkpoint (too much of the OS is disabled).
* - do a preliminary size checking here, if it is too small,
* allocate more space internally and retry.
* - check the vp to make sure it's the right type.
*/
char *path = cpr_build_statefile_path();
return (ENXIO);
else if (rc = cpr_verify_statefile_path())
return (rc);
return (rc);
}
}
/*
* Only ufs and block special statefiles supported
*/
"Statefile must be regular file or block special file.");
return (EACCES);
}
return (rc);
/*
* sync out the fs change due to the statefile reservation.
*/
/*
* Validate disk blocks allocation for the state file.
* Ask the file system prepare itself for the dump operation.
*/
"blocks for cpr statefile.");
return (rc);
}
}
return (0);
}
/*
* lookup device size in blocks,
* and return available space in bytes
*/
{
int nblocks;
if (bytes > CPR_SPEC_OFFSET)
bytes -= CPR_SPEC_OFFSET;
else
bytes = 0;
return (bytes);
}
/*
* increase statefile size
*/
static int
{
extern uchar_t cpr_pagecopy[];
if (increase == 0)
return (0);
/*
* write to each logical block to reserve disk space
*/
error = 0;
cpr_pagecopy[0] = '1';
"disk space for statefile %s\n"
"wanted %lld bytes, file is %lld short",
}
break;
}
}
return (error);
}
/*
* do a simple estimate of the space needed to hold the statefile
* taking compression into account, but be fairly conservative
* so we have a better chance of completing; when dump fails,
* the retry cost is fairly high.
*
* Do disk blocks allocation for the state file if no space has
* been allocated yet. Since the state file will not be removed,
* allocation should only be done once.
*/
static int
{
extern size_t cpr_bitmap_size;
int error;
/*
* number of pages short for swapping.
*/
if (STAT->cs_nosw_pages < 0)
STAT->cs_nosw_pages = 0;
str = "cpr_statefile_ok:";
/*
* try increasing filesize by 15%
*/
if (alloc_retry) {
/*
* block device doesn't get any bigger
*/
"Retry statefile on special file\n");
return (ENOMEM);
} else {
}
} else {
int ndvram;
ndvram = 0;
(void) callb_execute_class(CB_CL_CPR_FB,
/*
* estimate 1 cpd_t for every (CPR_MAXCONTIG / 2) pages
*/
est_fmt = "%s estimated size with "
"%scompression %lld, ksize %lld\n";
} else {
}
}
/*
* All this is much simpler for a block device
*/
/*
* Export the estimated filesize info, this value will be
* compared before dumping out the statefile in the case of
* no compression.
*/
prom_printf("%s Estimated statefile size %llu, "
return (ENOMEM);
}
return (0);
} else {
return (ENOMEM);
}
/*
* Estimate space needed for the state file.
*
* State file size in bytes:
* kernel size + non-cache pte seg +
* bitmap size + cpr state file headers size
* (round up to fs->fs_bsize)
*/
/*
* Export the estimated filesize info, this value will be
* compared before dumping out the statefile in the case of
* no compression.
*/
prom_printf("%s Estimated statefile size %lld, "
}
return (error);
}
}
void
cpr_statef_close(void)
{
if (C_VP) {
if (!cpr_reusable_mode)
C_VP = 0;
}
}
/*
* open cpr default file and display error
*/
int
{
int error;
return (error);
}
/*
* write cdef_t to disk. This contains the original values of prom
* properties that we modify. We fill in the magic number of the file
* here as a signal to the booter code that the state file is valid.
* Be sure the file gets synced, since we may be shutting down the OS.
*/
int
{
char *str;
int rc;
return (rc);
str = "write";
str = "fsync";
if (rc) {
}
return (rc);
}
/*
* Clear the magic number in the defaults file. This tells the booter
* program that the state file is not current and thus prevents
* any attempt to restore from an obsolete state file.
*/
void
cpr_clear_definfo(void)
{
return;
}
/*
* If the cpr default file is invalid, then we must not be in reusable mode
* if it is valid, it tells us our mode
*/
int
cpr_get_reusable_mode(void)
{
int rc;
return (0);
return (0);
}
/*
*/
static time_t cpr_time_stamp;
void
{
}
void
cpr_tod_fault_reset(void)
{
}
void
cpr_save_time(void)
{
}
/*
* correct time based on saved time stamp or hardware clock
*/
void
cpr_restore_time(void)
{
}
/*
*/
int
cpr_mp_offline(void)
{
int rc = 0;
int brought_up_boot = 0;
/*
* Do nothing for UP.
*/
if (ncpus == 1)
return (0);
bootcpu = i_cpr_bootcpu();
if (!CPU_ACTIVE(bootcpu)) {
return (rc);
}
brought_up_boot = 1;
}
do {
continue;
continue;
return (rc);
}
prom_printf("changed cpu %p to state %d\n",
return (rc);
}
int
cpr_mp_online(void)
{
int rc = 0;
/*
* Do nothing for UP.
*/
if (ncpus == 1)
return (0);
/*
* cpr_save_mp_state() sets CPU_CPR_ONLINE in cpu_cpr_flags
* to indicate a cpu was online at the time of cpr_suspend();
* now restart those cpus that were marked as CPU_CPR_ONLINE
* and actually are offline.
*/
/*
* Clear the CPU_FROZEN flag in all cases.
*/
if (CPU_CPR_IS_OFFLINE(cp))
continue;
if (CPU_ACTIVE(cp))
continue;
return (rc);
}
}
/*
* turn off the boot cpu if it was offlined
*/
if (CPU_CPR_IS_OFFLINE(bootcpu)) {
return (rc);
}
}
return (0);
}
static void
cpr_save_mp_state(void)
{
do {
if (CPU_ACTIVE(cp))
}
/*
*/
static int
{
int rc;
switch (state) {
case CPU_CPR_ONLINE:
break;
case CPU_CPR_OFFLINE:
break;
}
if (rc) {
}
return (rc);
}
/*
* Construct the pathname of the state file and return a pointer to
* caller. Read the config file to get the mount point of the
* filesystem and the pathname within fs.
*/
char *
cpr_build_statefile_path(void)
{
if (cpr_get_config())
return (NULL);
case CFT_UFS:
return (NULL);
}
return (cpr_cprconfig_to_path());
case CFT_SPEC:
default:
/*NOTREACHED*/
return (NULL);
}
}
int
cpr_statefile_is_spec(void)
{
if (cpr_get_config())
return (0);
}
char *
{
return (cf->cf_dev_prom);
}
/*
* XXX The following routines need to be in the vfs source code.
*/
int
{
char *fsname;
}
/*
* This is a list of file systems that are allowed to be writeable when a
* reusable statefile checkpoint is taken. They must not have any state that
* cannot be restored to consistency by simply rebooting using the checkpoint.
* (In contrast to ufs, cachefs and pcfs which have disk state that could get
* out of sync with the in-kernel data).
*/
int
cpr_reusable_mount_check(void)
{
char *fsname;
char **cpp;
static char *cpr_writeok_fss[] = {
"autofs", "devfs", "fd", "lofs", "mntfs", "namefs", "nfs",
};
do {
continue;
}
break;
}
/*
* if the inner loop reached the NULL terminator,
* the current fs-type does not match any OK-type
*/
"no writeable filesystem of this type be mounted\n",
fsname);
return (EINVAL);
}
return (0);
}
/*
* Force a fresh read of the cprinfo per uadmin 3 call
*/
void
cpr_forget_cprconfig(void)
{
cprconfig_loaded = 0;
}
/*
* return statefile offset in DEV_BSIZE units
*/
int
cpr_statefile_offset(void)
{
}