-
Notifications
You must be signed in to change notification settings - Fork 0
/
hammer.subr
102 lines (85 loc) · 2.44 KB
/
hammer.subr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
if [ ! "$_CBSD_HAMMER_SUBR" ]; then
_CBSD_HAMMER_SUBR=1
###
#v10.0.0
# return 0 if $1 is not valid Hammer mountpoint
# return 1 if $1 is valid Hammer mountpoint and mounted
# return 2 if $1 is valid Hammer mountpoint and not mounted
# if hammermnt /mnt; then
# echo " not hammer (mounted or not) mountpoint"
# fi
# export ZPOOL for name Hammer for $1 mountpoint
hammermnt() {
local _A
ZPOOL=$(/sbin/hammer list -Ho name,mountpoint | while read _name _mnt; do
[ "${_mnt}" = "${1}" ] && echo ${_name} && exit 2
done)
if [ $? -eq 2 ]; then
# Check for mounted
_A=$( /sbin/hammer get -Ho value mounted ${ZPOOL} )
[ "${_A}" = "yes" ] && return 1
return 2
else
return 0
fi
}
# return 0 if $1 is not valid Hammer filesystem
# return 1 if $1 is valid Hammer mountpoint and mounted
# return 2 if $1 is valid Hammer mountpoint and not mounted
# if hammerfs /mnt; then
# echo " not hammer (mounted or not) mounted"
# fi
hammerfs() {
local _A
_A=$( /sbin/hammer list -Ho name | while read _name; do
[ "${_name}" = "${1}" ] && exit 2
done)
if [ $? -eq 2 ]; then
# Check for mounted
_A=$( /sbin/hammer get -Ho value mounted ${1} )
[ "${_A}" = "yes" ] && return 1
return 2
else
return 0
fi
}
# export zmnt if $zroot exist, return 1
getmnt() {
local _res
[ -z "$1" ] && return 1
zmnt=$( /sbin/hammer get -Ho value mountpoint ${1} )
return $?
}
# return 0 if ${ZPOOL}/$1 hammer source exist
# if hammerroot jail1; then
# echo "zroot/$jail1 exist
# fi
hammerroot() {
[ -z "$1" ] && return 0
/sbin/hammer list -H -o name | while read _mnt; do
[ "$_mnt" = "${ZPOOL}/${1}" ] && exit 0
done
return $?
}
# $1 - oldjname
# $2 - newjname
hammer_snapshot_rename()
{
local _fs _jname _mod _snapname _oldjname _newjname
_oldjname="$1"
_newjname="$2"
[ -z "${_oldjname}" -o -z "${_newjname}" ] && return 0
# [ -n "${_oldjname}" ] && _mod="${ZPOOL}/${_oldjname}"
_mod="${ZPOOL}"
for _fs in $( /sbin/hammer list -H -r -t snapshot -o name ${_mod} 2>/dev/null ); do
_jname=$( /sbin/hammer get -H -o value -s local cbsdsnap:jname "${_fs}" 2>/dev/null )
[ -z "${_jname}" ] && continue
[ -n "${_oldjname}" -a "${_oldjname}" != "${_jname}" ] && continue
_snapname=$( /sbin/hammer get -H -o value -s local cbsdsnap:snapname "${_fs}" 2>/dev/null )
[ -z "${_snapname}" ] && continue
/sbin/hammer set cbsdsnap:jname=${_newjname} ${ZPOOL}@${_snapname}
# ${ECHO} "${MAGENTA}Hammer snapshot renamed: ${GREEN}${_snapname}${NORMAL}"
done
}
###
fi