4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 #include <sys/types.h>
28 #include <sys/errno.h>
29 #include <sys/cpuvar.h>
31 #include <sys/vnode.h>
32 #include <sys/pathname.h>
33 #include <sys/callb.h>
34 #include <sys/fs/ufs_inode.h>
36 #include <sys/fs/swapnode.h> /* for swapfs_minfree */
40 #include <sys/machclock.h>
43 * CPR miscellaneous support routines
45 #define cpr_open(path, mode, vpp) (vn_open(path, UIO_SYSSPACE, \
46 mode, 0600, vpp, CRCREAT, 0))
47 #define cpr_rdwr(rw, vp, basep, cnt) (vn_rdwr(rw, vp, (caddr_t)(basep), \
48 cnt, 0LL, UIO_SYSSPACE, 0, (rlim64_t)MAXOFF_T, CRED(), \
51 extern void clkset(time_t);
52 extern cpu_t
*i_cpr_bootcpu(void);
53 extern caddr_t
i_cpr_map_setup(void);
54 extern void i_cpr_free_memory_resources(void);
56 extern kmutex_t cpr_slock
;
57 extern size_t cpr_buf_size
;
59 extern size_t cpr_pagedata_size
;
60 extern char *cpr_pagedata
;
61 extern int cpr_bufs_allocated
;
62 extern int cpr_bitmaps_allocated
;
65 int cpr_is_ufs(struct vfs
*);
66 int cpr_is_zfs(struct vfs
*);
68 char cpr_default_path
[] = CPR_DEFAULT
;
70 #define COMPRESS_PERCENT 40 /* approx compression ratio in percent */
71 #define SIZE_RATE 115 /* increase size by 15% */
72 #define INTEGRAL 100 /* for integer math */
76 * cmn_err() followed by a 1/4 second delay; this gives the
77 * logging service a chance to flush messages and helps avoid
78 * intermixing output from prom_printf().
82 cpr_err(int ce
, const char *fmt
, ...)
87 vcmn_err(ce
, fmt
, adx
);
89 drv_usecwait(MICROSEC
>> 2);
97 * Allow only one suspend/resume process.
99 if (mutex_tryenter(&cpr_slock
) == 0)
104 CPR
->c_cprboot_magic
= 0;
105 CPR
->c_alloc_cnt
= 0;
108 if (fcn
== AD_CPR_REUSABLE
)
109 CPR
->c_flags
|= C_REUSABLE
;
111 CPR
->c_flags
|= C_SUSPENDING
;
112 if (fcn
== AD_SUSPEND_TO_RAM
|| fcn
== DEV_SUSPEND_TO_RAM
) {
120 * This routine releases any resources used during the checkpoint.
126 i_cpr_bitmap_cleanup();
129 * Free pages used by cpr buffers.
132 kmem_free(cpr_buf
, cpr_buf_size
);
136 kmem_free(cpr_pagedata
, cpr_pagedata_size
);
140 i_cpr_free_memory_resources();
141 mutex_exit(&cpr_slock
);
142 cpr_err(CE_CONT
, "System has been resumed.\n");
148 * clock/time related routines
150 static time_t cpr_time_stamp
;
154 cpr_tod_get(cpr_time_t
*ctp
)
158 mutex_enter(&tod_lock
);
159 ts
= TODOP_GET(tod_ops
);
160 mutex_exit(&tod_lock
);
161 ctp
->tv_sec
= (time32_t
)ts
.tv_sec
;
162 ctp
->tv_nsec
= (int32_t)ts
.tv_nsec
;
166 cpr_tod_status_set(int tod_flag
)
168 mutex_enter(&tod_lock
);
169 tod_status_set(tod_flag
);
170 mutex_exit(&tod_lock
);
176 cpr_time_stamp
= gethrestime_sec();
180 * correct time based on saved time stamp or hardware clock
183 cpr_restore_time(void)
185 clkset(cpr_time_stamp
);