Project

General

Profile

« Previous | Next » 

Revision b9097e4c

Added by Christian McDonald about 3 years ago

Fix RAM disk support for ZFS layout changes related to BEs. Fixes #13182

View differences:

src/etc/inc/pkg-utils.inc
114 114
		}
115 115
	}
116 116

  
117
	if (isset($config['system']['use_mfs_tmpvar']) &&
118
	    !file_exists("/conf/ram_disks_failed")) {
119
		$pkg_env_vars['PKG_DBDIR'] = '/root/var/db/pkg';
120
		$pkg_env_vars['PKG_CACHEDIR'] = '/root/var/cache/pkg';
121
	}
117
#	if (isset($config['system']['use_mfs_tmpvar']) &&
118
#	    !file_exists("/conf/ram_disks_failed")) {
119
#		$pkg_env_vars['PKG_DBDIR'] = '/root/var/db/pkg';
120
#		$pkg_env_vars['PKG_CACHEDIR'] = '/root/var/cache/pkg';
121
#	}
122 122

  
123 123
	foreach ($extra_env as $key => $value) {
124 124
		$pkg_env_vars[$key] = $value;
src/etc/pfSense-rc
144 144
	/sbin/reboot
145 145
fi
146 146

  
147
# Bring in RAM disk functions
148
. /etc/rc.ramdisk_functions.sh
149

  
147 150
# Handle ZFS read-only case
148 151
unset USE_ZFS
149 152
if /sbin/kldstat -qm zfs; then
......
162 165
		if [ -d /bootpool ]; then
163 166
			/sbin/zpool import -f bootpool
164 167
		fi
165
		# We need to handle ZFS boot environments here
166
		echo "Enabling ZFS boot environment..."
167
		/etc/rc.d/zfsbe onestart
168
		_be_mount_zfs # /etc/rc.d/zfsbe onestart
168 169
	fi
169 170
fi
170 171

  
......
181 182
# Sanity check the clock
182 183
/etc/rc.checkclock
183 184

  
184
. /etc/rc.ramdisk_functions.sh
185

  
186 185
# Check if RAM disks are enabled, store for repeated use
187 186
if ramdisk_check_enabled; then
188 187
	USE_RAMDISK=true
189 188
fi
190 189

  
191
# Relocate pkgdb based on desired RAM disk settings
192
ramdisk_relocate_pkgdb_all
190
# Relocate pkgdb on UFS based on desired RAM disk settings
191
if [ -z "${USE_ZFS}" ]; then
192
	ramdisk_relocate_pkgdb_all
193
fi
193 194

  
194 195
# Dismount /tmp and /var on ZFS if using RAM disks and they are separate volumes
195 196
if [ -n "${USE_ZFS}" -a -n "${USE_RAMDISK}" ]; then
196
	ramdisk_fixup_zfs umount
197
	ramdisk_fixup_zfs_unmount
197 198
fi
198 199

  
199 200
# Attempt to create and mount RAM disks
......
201 202
	/etc/rc.embedded
202 203
fi
203 204

  
204
# If RAM disks are active, make symlinks for pkg database
205
# If RAM disks are active, make symlinks for pkg database on UFS
205 206
if [ -n "${USE_RAMDISK}" -o -n "${MOVE_PKG_DATA}" ]; then
206
	ramdisk_link_pkgdb
207
	if [ -z "${USE_ZFS}" ]; then
208
		ramdisk_link_pkgdb
209
	fi
207 210
fi
208 211

  
209 212
# If activating RAM disks failed, then undo some of the above actions
210 213
if [ -n "${USE_RAMDISK}" ] && ramdisk_failed; then
211
	ramdisk_fixup_zfs mount
212
	ramdisk_relocate_pkgdb disk
214
	ramdisk_fixup_zfs_mount
215
	if [ -z "${USE_ZFS}" ]; then
216
		ramdisk_relocate_pkgdb disk
217
	fi
213 218
else
214 219
	ramdisk_reset_status
215 220
fi
src/etc/rc.ramdisk_functions.sh
26 26
RAMDISK_DEFAULT_SIZE_tmp=40
27 27
RAMDISK_DEFAULT_SIZE_var=60
28 28

  
29
_be_remount_ds() {
30
	local _dataset="${1}"
31

  
32
	/sbin/zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem "${_dataset}" | \
33
	while read _mp _name _canmount _mounted ; do
34
		# skip filesystems that must not be mounted
35
		[ "${_canmount}" = "off" -o "${_mp}" = "/" ] && continue
36
		# skip filesystems that are already mounted
37
		[ "$_mounted" = "yes" ] && \
38
			/sbin/umount -f "${_name}"
39
		# filesystems with mountpoint elsewhere
40
		/sbin/zfs mount "${_name}"
41
	done
42
}
43

  
44
_be_mount_zfs() {
45
	/sbin/mount -p | while read _dev _mp _type _rest; do
46
		[ "${_mp}"  = "/" ] || continue
47
		if [ "${_type}" = "zfs" ] ; then
48
			_be_remount_ds $_dev
49
		fi
50
		break
51
	done
52
}
53

  
29 54
# Check if RAM disks are enabled in config.xml
30 55
ramdisk_check_enabled () {
31 56
	[ "$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)" = "true" ]
......
103 128
	if [ ramdisk_check_size ]; then
104 129
		SIZE=$(eval echo \${${NAME}size})m
105 130
		/sbin/mount -o rw,size=${SIZE},mode=1777 -t tmpfs tmpfs /${NAME}
106
		return $?
131
		_rc=$?
132
		_be_mount_zfs
133
		return ${_rc}
107 134
	else
108 135
		return 1;
109 136
	fi
......
157 184
ramdisk_relocate_pkgdb_all () {
158 185
	unset MOVE_PKG_DATA
159 186
	unset USE_RAMDISK
187

  
160 188
	if ramdisk_check_enabled; then
161 189
		USE_RAMDISK=true
162 190
	fi
......
188 216
	fi
189 217
}
190 218

  
191
# Either unmount or mount /var and /tmp in ZFS as needed to avoid conflicts with
192
#   active RAM disk options.
193
ramdisk_fixup_zfs () {
194
	# Mount /var and /tmp on ZFS filesystems when necessary
195
	if [ ${1} = "mount" ]; then
196
		echo "Remounting ZFS volumes"
197
		zfs mount -a
198
	else
199
		zfs list -H -o name,mountpoint |
200
		    while read volume mountpoint; do
201
			[ "${mountpoint}" != "/var" -a "${mountpoint}" != "/tmp" ] \
202
				&& continue
203
			echo "Dismounting ZFS volume ${volume} for RAM disk"
204
			/sbin/zfs umount ${volume}
205
		done
206
	fi
219
ramdisk_zfs_deep_unmount() {
220
	local _path="${1}"
221

  
222
	/sbin/zfs list -rH -o name,mountpoint -S mountpoint -t filesystem "${_path}" | \
223
	while read _name _mp; do
224
		echo -n "Dismounting ZFS volume ${_name} at ${_mp} for RAM disk..."
225
		/sbin/zfs unmount -f "${_name}" 1>/dev/null 2>&1
226
		echo " done."
227
	done
228
}
229

  
230
ramdisk_fixup_zfs_mount() {
231
	echo -n "Remounting ZFS volumes..."
232
	/sbin/zfs mount -a 1>/dev/null 2>&1
233
	_be_mount_zfs
234
	echo " done."
235
}
236

  
237
ramdisk_fixup_zfs_unmount() {
238
	ramdisk_zfs_deep_unmount "/tmp"
239
	ramdisk_zfs_deep_unmount "/var"
240
	_be_mount_zfs
207 241
}
src/etc/skel/dot.shrc
35 35
fi
36 36

  
37 37
USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
38
if [ "${USE_MFS_TMPVAR}" = "true" ] && [ ! -f /conf/ram_disks_failed ]; then
39
	export PKG_DBDIR='/root/var/db/pkg'
40
	export PKG_CACHEDIR='/root/var/cache/pkg'
41
fi
38
# if [ "${USE_MFS_TMPVAR}" = "true" ] && [ ! -f /conf/ram_disks_failed ]; then
39
# 	export PKG_DBDIR='/root/var/db/pkg'
40
# 	export PKG_CACHEDIR='/root/var/cache/pkg'
41
# fi
42 42

  
43 43
# Detect interactive logins and display the shell
44 44
unset _interactive
src/etc/skel/dot.tcshrc
76 76
endif
77 77

  
78 78
set use_mfs_tmpvar=`/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar`
79
if ( $use_mfs_tmpvar == "true" && ! -f "/conf/ram_disks_failed" ) then
80
	setenv PKG_DBDIR '/root/var/db/pkg'
81
	setenv PKG_CACHEDIR '/root/var/cache/pkg'
82
endif
79
# if ( $use_mfs_tmpvar == "true" && ! -f "/conf/ram_disks_failed" ) then
80
# 	setenv PKG_DBDIR '/root/var/db/pkg'
81
# 	setenv PKG_CACHEDIR '/root/var/cache/pkg'
82
# endif

Also available in: Unified diff