zfs-0.6.5-fix-openrc-scripts.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. commit 3cb750b249717b43cbfcde78b44b0e38a2a61dc2
  2. Author: James Lee <jlee@thestaticvoid.com>
  3. Date: Sat Sep 19 22:00:36 2015 -0400
  4. zfs-import: Perform verbatim import using cache file
  5. This change modifies the import service to use the default cache file
  6. to perform a verbatim import of pools at boot. This fixes code that
  7. searches all devices and imported all visible pools.
  8. Using the cache file is in keeping with the way ZFS has always worked,
  9. how Solaris, Illumos, FreeBSD, and systemd performs imports, and is how
  10. it is written in the man page (zpool(1M,8)):
  11. All pools in this cache are automatically imported when the
  12. system boots.
  13. Importantly, the cache contains important information for importing
  14. multipath devices, and helps control which pools get imported in more
  15. dynamic environments like SANs, which may have thousands of visible
  16. and constantly changing pools, which the ZFS_POOL_EXCEPTIONS variable
  17. is not equipped to handle. Verbatim imports prevent rogue pools from
  18. being automatically imported and mounted where they shouldn't be.
  19. The change also stops the service from exporting pools at shutdown.
  20. Exporting pools is only meant to be performed explicitly by the
  21. administrator of the system.
  22. The old behavior of searching and importing all visible pools is
  23. preserved and can be switched on by heeding the warning and toggling
  24. the ZPOOL_IMPORT_ALL_VISIBLE variable in /etc/default/zfs.
  25. Closes #3777
  26. Closes #3526
  27. diff --git a/etc/init.d/zfs-import.in b/etc/init.d/zfs-import.in
  28. index 5e21929..2258638 100755
  29. --- a/etc/init.d/zfs-import.in
  30. +++ b/etc/init.d/zfs-import.in
  31. @@ -1,11 +1,10 @@
  32. #!@SHELL@
  33. #
  34. -# zfs-import This script will import/export zfs pools.
  35. +# zfs-import This script will import ZFS pools
  36. #
  37. # chkconfig: 2345 01 99
  38. -# description: This script will import/export zfs pools during system
  39. -# boot/shutdown.
  40. -# It is also responsible for all userspace zfs services.
  41. +# description: This script will perform a verbatim import of ZFS pools
  42. +# during system boot.
  43. # probe: true
  44. #
  45. ### BEGIN INIT INFO
  46. @@ -17,7 +16,7 @@
  47. # X-Start-Before: checkfs
  48. # X-Stop-After: zfs-mount
  49. # Short-Description: Import ZFS pools
  50. -# Description: Run the `zpool import` or `zpool export` commands.
  51. +# Description: Run the `zpool import` command.
  52. ### END INIT INFO
  53. #
  54. # NOTE: Not having '$local_fs' on Required-Start but only on Required-Stop
  55. @@ -43,6 +42,16 @@ do_depend()
  56. keyword -lxc -openvz -prefix -vserver
  57. }
  58. +# Use the zpool cache file to import pools
  59. +do_verbatim_import()
  60. +{
  61. + if [ -f "$ZPOOL_CACHE" ]
  62. + then
  63. + zfs_action "Importing ZFS pool(s)" \
  64. + "$ZPOOL" import -c "$ZPOOL_CACHE" -N -a
  65. + fi
  66. +}
  67. +
  68. # Support function to get a list of all pools, separated with ';'
  69. find_pools()
  70. {
  71. @@ -60,8 +69,8 @@ find_pools()
  72. echo "${pools%%;}" # Return without the last ';'.
  73. }
  74. -# Import all pools
  75. -do_import()
  76. +# Find and import all visible pools, even exported ones
  77. +do_import_all_visible()
  78. {
  79. local already_imported available_pools pool npools
  80. local exception dir ZPOOL_IMPORT_PATH RET=0 r=1
  81. @@ -109,7 +118,7 @@ do_import()
  82. fi
  83. fi
  84. - # Filter out any exceptions...
  85. + # Filter out any exceptions...
  86. if [ -n "$ZFS_POOL_EXCEPTIONS" ]
  87. then
  88. local found=""
  89. @@ -249,41 +258,15 @@ do_import()
  90. return "$RET"
  91. }
  92. -# Export all pools
  93. -do_export()
  94. +do_import()
  95. {
  96. - local already_imported pool root_pool RET r
  97. - RET=0
  98. -
  99. - root_pool=$(get_root_pool)
  100. -
  101. - [ -n "$init" ] && zfs_log_begin_msg "Exporting ZFS pool(s)"
  102. -
  103. - # Find list of already imported pools.
  104. - already_imported=$(find_pools "$ZPOOL" list -H -oname)
  105. -
  106. - OLD_IFS="$IFS" ; IFS=";"
  107. - for pool in $already_imported; do
  108. - [ "$pool" = "$root_pool" ] && continue
  109. -
  110. - if [ -z "$init" ]
  111. - then
  112. - # Interactive - one 'Importing ...' line per pool
  113. - zfs_log_begin_msg "Exporting ZFS pool $pool"
  114. - else
  115. - # Not interactive - a dot for each pool.
  116. - zfs_log_progress_msg "."
  117. - fi
  118. -
  119. - "$ZPOOL" export "$pool"
  120. - r="$?" ; RET=$((RET + r))
  121. - [ -z "$init" ] && zfs_log_end_msg "$r"
  122. - done
  123. - IFS="$OLD_IFS"
  124. -
  125. - [ -n "$init" ] && zfs_log_end_msg "$RET"
  126. -
  127. - return "$RET"
  128. + if check_boolean "$ZPOOL_IMPORT_ALL_VISIBLE"
  129. + then
  130. + do_import_all_visible
  131. + else
  132. + # This is the default option
  133. + do_verbatim_import
  134. + fi
  135. }
  136. # Output the status and list of pools
  137. @@ -323,14 +306,6 @@ do_start()
  138. fi
  139. }
  140. -do_stop()
  141. -{
  142. - # Check to see if the module is even loaded.
  143. - check_module_loaded "zfs" || exit 0
  144. -
  145. - do_export
  146. -}
  147. -
  148. # ----------------------------------------------------
  149. if [ ! -e /etc/gentoo-release ]
  150. @@ -340,7 +315,7 @@ then
  151. do_start
  152. ;;
  153. stop)
  154. - do_stop
  155. + # no-op
  156. ;;
  157. status)
  158. do_status
  159. @@ -350,7 +325,7 @@ then
  160. ;;
  161. *)
  162. [ -n "$1" ] && echo "Error: Unknown command $1."
  163. - echo "Usage: $0 {start|stop|status}"
  164. + echo "Usage: $0 {start|status}"
  165. exit 3
  166. ;;
  167. esac
  168. @@ -360,6 +335,5 @@ else
  169. # Create wrapper functions since Gentoo don't use the case part.
  170. depend() { do_depend; }
  171. start() { do_start; }
  172. - stop() { do_stop; }
  173. status() { do_status; }
  174. fi
  175. diff --git a/etc/init.d/zfs.in b/etc/init.d/zfs.in
  176. index eabb7e4..d81ef22 100644
  177. --- a/etc/init.d/zfs.in
  178. +++ b/etc/init.d/zfs.in
  179. @@ -16,6 +16,24 @@ ZFS_SHARE='yes'
  180. # Run `zfs unshare -a` during system stop?
  181. ZFS_UNSHARE='yes'
  182. +# By default, a verbatim import of all pools is performed at boot based on the
  183. +# contents of the default zpool cache file. The contents of the cache are
  184. +# managed automatically by the 'zpool import' and 'zpool export' commands.
  185. +#
  186. +# By setting this to 'yes', the system will instead search all devices for
  187. +# pools and attempt to import them all at boot, even those that have been
  188. +# exported. Under this mode, the search path can be controlled by the
  189. +# ZPOOL_IMPORT_PATH variable and a list of pools that should not be imported
  190. +# can be listed in the ZFS_POOL_EXCEPTIONS variable.
  191. +#
  192. +# Note that importing all visible pools may include pools that you don't
  193. +# expect, such as those on removable devices and SANs, and those pools may
  194. +# proceed to mount themselves in places you do not want them to. The results
  195. +# can be unpredictable and possibly dangerous. Only enable this option if you
  196. +# understand this risk and have complete physical control over your system and
  197. +# SAN to prevent the insertion of malicious pools.
  198. +ZPOOL_IMPORT_ALL_VISIBLE='no'
  199. +
  200. # Specify specific path(s) to look for device nodes and/or links for the
  201. # pool import(s). See zpool(8) for more information about this variable.
  202. # It supersedes the old USE_DISK_BY_ID which indicated that it would only
  203. @@ -23,6 +41,18 @@ ZFS_UNSHARE='yes'
  204. # The old variable will still work in the code, but is deprecated.
  205. #ZPOOL_IMPORT_PATH="/dev/disk/by-vdev:/dev/disk/by-id"
  206. +# List of pools that should NOT be imported at boot
  207. +# when ZPOOL_IMPORT_ALL_VISIBLE is 'yes'.
  208. +# This is a space separated list.
  209. +#ZFS_POOL_EXCEPTIONS="test2"
  210. +
  211. +# List of pools that SHOULD be imported at boot by the initramfs
  212. +# instead of trying to import all available pools. If this is set
  213. +# then ZFS_POOL_EXCEPTIONS is ignored.
  214. +# Only applicable for Debian GNU/Linux {dkms,initramfs}.
  215. +# This is a semi-colon separated list.
  216. +#ZFS_POOL_IMPORT="pool1;pool2"
  217. +
  218. # Should the datasets be mounted verbosely?
  219. # A mount counter will be used when mounting if set to 'yes'.
  220. VERBOSE_MOUNT='no'
  221. @@ -97,17 +127,6 @@ ZFS_INITRD_POST_MODPROBE_SLEEP='0'
  222. # Example: If root FS is 'rpool/ROOT/rootfs', this would make sense.
  223. #ZFS_INITRD_ADDITIONAL_DATASETS="rpool/ROOT/usr rpool/ROOT/var"
  224. -# List of pools that should NOT be imported at boot?
  225. -# This is a space separated list.
  226. -#ZFS_POOL_EXCEPTIONS="test2"
  227. -
  228. -# List of pools to import?
  229. -# If this variable is set, there will be NO auto-import of ANY other
  230. -# pool. In essence, there will be no auto detection of availible pools.
  231. -# This is a semi-colon separated list.
  232. -# Makes the variable ZFS_POOL_EXCEPTIONS above redundant (won't be checked).
  233. -#ZFS_POOL_IMPORT="pool1;pool2"
  234. -
  235. # Optional arguments for the ZFS Event Daemon (ZED).
  236. # See zed(8) for more information on available options.
  237. #ZED_ARGS="-M"