Skip to content

Commit

Permalink
jexport: pass threads= args to xz
Browse files Browse the repository at this point in the history
when threads=0 (by defaults), cbsd jexport inherits CPU cores num

Suggested by: @Zlapsa (via Telegram)
  • Loading branch information
olevole committed Jan 17, 2024
1 parent 1f56c0d commit 939e764
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
5 changes: 5 additions & 0 deletions etc/defaults/jexport.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
# jexport_exclude="/usr/src /usr/ports /usr/obj"
#
jexport_exclude=

# threads:
# xz-specific: the number of worker threads to use, default - 0 (inherits CPU cores num);
# e.g., limit the compression process to two threads:
# threads="2"
32 changes: 19 additions & 13 deletions jailctl/jexport
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#v11.1.17
globalconf="${distdir}/cbsd.conf";
MYARG=""
MYOPTARG="compress dstdir genmd5 gensize header_extra imgname jexport_exclude jname ls"
MYOPTARG="compress dstdir genmd5 gensize header_extra imgname jexport_exclude jname ls threads"
MYDESC="Export jail into image"
CBSDMODULE="jail"
ADDHELP="
Expand Down Expand Up @@ -40,12 +40,13 @@ ${H3_COLOR}Options${N0_COLOR}:
${N2_COLOR}jexport_exclude${N0_COLOR} - skip/exclude path in jail when export;
${N2_COLOR}jname${N0_COLOR} - environment name;
${N2_COLOR}ls${N0_COLOR} - filter for list: bls or jls;
${N2_COLOR}threads${N0_COLOR} - xz-specific: the number of worker threads to use, default - 0 (inherits CPU cores num);

${H3_COLOR}Examples${N0_COLOR}:

cbsd jexport jname=test jexport_exclude=\"/tmp/* /usr/ports /var/run/*\" (exclude /tmp and /usr/ports in image)\n\
cbsd jexport jname=test jexport_exclude=\"/\" (export settings only, without data!)\n\
cbsd jexport jname=test compress=0 (tar only, without compression)\n\
cbsd jexport jname=test jexport_exclude=\"/tmp/* /usr/ports /var/run/*\" (exclude /tmp and /usr/ports in image)
cbsd jexport jname=test jexport_exclude=\"/\" (export settings only, without data!)
cbsd jexport jname=test compress=0 threads=1 (tar only, without compression)

${H3_COLOR}See also${N0_COLOR}:

Expand All @@ -69,8 +70,12 @@ gensize=0
header_extra=
jexport_exclude=
ojexport_exclude=
threads=
othreads=
. ${cbsdinit}
[ -n "${jexport_exclude}" ] && ojexport_exclude="${jexport_exclude}"
[ -n "${threads}" ] && othreads="${threads}"
[ -z "${threads}" ] && threads=0

if [ "${mod_cbsd_queue_enabled}" = "YES" -a -z "${MOD_CBSD_QUEUE_DISABLED}" ]; then
readconf cbsd_queue.conf
Expand Down Expand Up @@ -118,7 +123,7 @@ ___NCSTART_DATA=1 \
[ -r ${JAILRCCONF} ] && ${GREP_CMD} ^ci_ ${JAILRCCONF} > ${JAILRCCONF}.orig
jmkrcconf jname=${jname} > ${JAILRCCONF}
[ -n "${header_extra}" ] && _header_extra_opt="header_extra=\"${header_extra}\""
res=$( imgpart mode=pack jname=${jname} compress=${compress} part=header emulator=${emulator} out=${DEST} ${_header_extra_opt} )
res=$( imgpart mode=pack jname=${jname} compress=${compress} part=header emulator=${emulator} out=${DEST} threads=${threads} ${_header_extra_opt} )
_ret=$?
${RM_CMD} -f ${JAILRCCONF}
[ ${_ret} -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
Expand All @@ -134,21 +139,21 @@ ___NCSTART_DATA=1 \
${RM_CMD} -f ${JAILRCCONF}
err 1 "${N1_COLOR}Error in ${_part} replacewdir: ${res}${N0_COLOR}"
fi
res=$( imgpart mode=pack jname=${jname} part=rcconf out=${DEST} )
res=$( imgpart mode=pack jname=${jname} part=rcconf out=${DEST} threads=${threads} )
_ret=$?
${RM_CMD} -f ${JAILRCCONF}
[ ${_ret} -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_PKGINFO*)
res=$( imgpart mode=pack jname=${jname} part=pkginfo out=${DEST} )
res=$( imgpart mode=pack jname=${jname} part=pkginfo out=${DEST} threads=${threads} )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_DESCR*)
res=$( imgpart mode=pack jname=${jname} part=descr out=${DEST} )
res=$( imgpart mode=pack jname=${jname} part=descr out=${DEST} threads=${threads} )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_INFO*)
imgpart mode=pack jname=${jname} part=info out=${DEST}
imgpart mode=pack jname=${jname} part=info out=${DEST} threads=${threads}
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_FSTAB*)
Expand All @@ -158,7 +163,7 @@ ___NCSTART_DATA=1 \
${CP_CMD} ${mount_fstab} ${TMPFSTAB}
res=$( replacewdir file0="${mount_fstab}" old=${workdir} new="CBSDROOT" )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part} replacewdir: ${res}${N0_COLOR}"
res=$( imgpart mode=pack jname=${jname} part=fstab out=${DEST} )
res=$( imgpart mode=pack jname=${jname} part=fstab out=${DEST} threads=${threads} )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
${MV_CMD} ${TMPFSTAB} ${mount_fstab}
;;
Expand All @@ -168,11 +173,11 @@ ___NCSTART_DATA=1 \
res=$( replacewdir file0="${mount_fstab}.local" old=${workdir} new="CBSDROOT" )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part} replacewdir: ${res}${N0_COLOR}"
fi
res=$( imgpart mode=pack jname=${jname} part=localfstab out=${DEST} || true )
res=$( imgpart mode=pack jname=${jname} part=localfstab out=${DEST} threads=${threads} || true )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_SYSDATA*)
res=$( imgpart mode=pack jname=${jname} part=sysdata out=${DEST} )
res=$( imgpart mode=pack jname=${jname} part=sysdata out=${DEST} threads=${threads} )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
;;
___NCSTART_DATA*)
Expand All @@ -182,6 +187,7 @@ ___NCSTART_DATA=1 \
case "${emulator}" in
jail)
readconf jexport.conf
[ -n "${othreads}" ] && threads="${othreads}"
_sys_exclude=
[ -n "${ojexport_exclude}" ] && jexport_exclude="${ojexport_exclude}"
if [ -n "${jexport_exclude}" ]; then
Expand Down Expand Up @@ -228,7 +234,7 @@ ___NCSTART_DATA=1 \
esac
jmkrcconf jname=${jname} > ${JAILRCCONF}
printf "${H3_COLOR}"
res=$( imgpart mode=pack jname=${jname} compress=${compress} part=data out=${DEST} filestats=${_filestats} ebytes=${_ebytes} ${_jexport_exclude_args} )
res=$( imgpart mode=pack jname=${jname} compress=${compress} part=data out=${DEST} filestats=${_filestats} ebytes=${_ebytes} threads=${threads} ${_jexport_exclude_args} )
_ret=$?
printf "${N0_COLOR}"
[ ${_ret} -ne 0 ] && err 1 "${N1_COLOR}Error in ${_part}: ${res}${N0_COLOR}"
Expand Down
31 changes: 19 additions & 12 deletions tools/imgpart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/local/bin/cbsd
#v12.1.5
MYARG="jname mode part"
MYOPTARG="compress ebytes emulator filestats hdrver header_extra jexport_exclude out"
MYOPTARG="compress ebytes emulator filestats hdrver header_extra jexport_exclude out threads"
MYDESC="Pack or extract chunk from from image"
ADDHELP="
compress - XZ compress level ( 0 - 9 ). Default is: 6. 0 mean is compression disabled\n\
ebytes - expected bytes (for pass into cbsdtee) in extract mode\n\
filestats - save bytes stats for part=data into file in pack mode\n\
header_extra - can be as header_extra=\"test4=4,param=val\" or path to file. extra header data\n\
jexport_exclude - skip/exclude path in jail to export\n\
mode=pack,extract\n\
part variants: header,rcconf,fstab,pkginfo,descr,info,sysdata,data\n\
out=path_to_file for ascii-part or directory to extract for binary\n\
or for binary image from pack mode\n\
compress - XZ compress level ( 0 - 9 ). Default is: 6. 0 mean is compression disabled
ebytes - expected bytes (for pass into cbsdtee) in extract mode
filestats - save bytes stats for part=data into file in pack mode
header_extra - can be as header_extra=\"test4=4,param=val\" or path to file. extra header data
jexport_exclude - skip/exclude path in jail to export
mode - pack,extract
part - variants: header,rcconf,fstab,pkginfo,descr,info,sysdata,data
out - path_to_file for ascii-part or directory to extract for binary
or for binary image from pack mode
threads - xz-specific: the number of worker threads to use, default - 0 (inherits CPU cores num);
"

. ${subrdir}/nc.subr
Expand All @@ -21,6 +22,7 @@ filestats=
ebytes=
header_extra=
jexport_exclude=
threads=0
. ${cbsdinit}

extractchunk()
Expand Down Expand Up @@ -125,12 +127,17 @@ extractme()

packme()
{
local _hwnum=$( ${SYSCTL_CMD} -qn hw.ncpu )
local _hwnum=0
local _dsk_list _zvol_list _zvol_name _my_nodename
local real_jailsysdir real_datadir _i _header_extra _pos
local _arg_len= _pref= ARG= VAL=

[ -z "${_hwnum}" ] && _hwnum="0"
if [ "${threads}" = "0" ]; then
_hwnum=$( ${SYSCTL_CMD} -qn hw.ncpu )
else
_hwnum="${threads}"
fi
[ -z "${_hwnum}" ] && _hwnum="1"

case ${part} in
header)
Expand Down

0 comments on commit 939e764

Please sign in to comment.