Skip to content

Commit d50f73f

Browse files
authored
Merge pull request #2869 from OSInside/consolidate_lock_method
Consolidate device lock into its own method
2 parents ad97062 + 588f888 commit d50f73f

File tree

7 files changed

+34
-21
lines changed

7 files changed

+34
-21
lines changed

dracut/modules.d/99kiwi-lib/kiwi-filesystem-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function resize_filesystem {
3737
local mpoint=/fs-resize
3838
local fstype
3939
fstype=$(probe_filesystem "${device}")
40-
lock="udevadm lock --device ${device}"
40+
lock="set_device_lock ${device}"
4141
case ${fstype} in
4242
ext2|ext3|ext4)
4343
resize_fs="${lock} resize2fs -f -p ${device}"
@@ -77,7 +77,7 @@ function check_filesystem {
7777
local check_fs_return_ok
7878
local fstype
7979
fstype=$(probe_filesystem "${device}")
80-
lock="udevadm lock --device ${device}"
80+
lock="set_device_lock ${device}"
8181
case ${fstype} in
8282
ext2|ext3|ext4)
8383
# The exit code by e2fsck is the sum of the following conditions:

dracut/modules.d/99kiwi-lib/kiwi-lib.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ function get_system_id {
1717
blkid -s PTUUID -o value "${disk_device}"
1818
}
1919

20+
function set_device_lock {
21+
# """
22+
# Set device lock, preferrable via udevadm or via
23+
# flock as fallback if systemd/udev does not provide
24+
# the command
25+
# """
26+
if udevadm lock --help &>/dev/null;then
27+
udevadm lock --device "$@"
28+
else
29+
flock -x "$@"
30+
fi
31+
}
32+
2033
function disk_matches_system_identifier {
2134
local disk_device=$1
2235
local system_identifier=/system_identifier

dracut/modules.d/99kiwi-lib/kiwi-luks-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function reencrypt_luks {
7474
setup_progress_fifo ${progress}
7575
(
7676
# reencrypt, this will overwrite all key slots
77-
udevadm lock --device "${device}" cryptsetup reencrypt \
77+
set_device_lock "${device}" cryptsetup reencrypt \
7878
--progress-frequency 1 \
7979
--key-file "${passphrase_file}" \
8080
--key-slot "${keyslot}" \
@@ -102,7 +102,7 @@ function activate_luks {
102102
# but this requires to manually call luksOpen since
103103
# with systemd-cryptsetup we saw it still asking for
104104
# a passphrase
105-
udevadm lock --device "${device}" cryptsetup \
105+
set_device_lock "${device}" cryptsetup \
106106
--key-file /dev/zero \
107107
--keyfile-size 32 \
108108
luksOpen "${device}" luks

dracut/modules.d/99kiwi-lib/kiwi-lvm-lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function get_volume_path_for_volume {
6363
function resize_pyhiscal_volumes {
6464
local device
6565
device=$(get_root_map)
66-
udevadm lock --device "${device}" pvresize "${device}"
66+
set_device_lock "${device}" pvresize "${device}"
6767
}
6868

6969
function resize_lvm_volumes_and_filesystems {

dracut/modules.d/99kiwi-lib/kiwi-mdraid-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ function deactivate_mdraid {
1919

2020
function activate_mdraid {
2121
declare kiwi_RaidDev=${kiwi_RaidDev}
22-
udevadm lock --device "${kiwi_RaidDev}" \
22+
set_device_lock "${kiwi_RaidDev}" \
2323
mdadm --assemble --scan "${kiwi_RaidDev}"
2424
wait_for_storage_device "${kiwi_RaidDev}"
2525
set_root_map "${kiwi_RaidDev}"
2626
}
2727

2828
function resize_mdraid {
2929
declare kiwi_RaidDev=${kiwi_RaidDev}
30-
udevadm lock --device "${kiwi_RaidDev}" \
30+
set_device_lock "${kiwi_RaidDev}" \
3131
mdadm --grow --size=max "${kiwi_RaidDev}"
3232
}

dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function create_partitions {
2323
;;
2424
esac
2525
if type partprobe &> /dev/null;then
26-
udevadm lock --device "${disk_device}" \
26+
set_device_lock "${disk_device}" \
2727
partprobe "${disk_device}"
2828
else
29-
udevadm lock --device "${disk_device}" \
29+
set_device_lock "${disk_device}" \
3030
partx -u "${disk_device}"
3131
fi
3232
}
@@ -61,22 +61,22 @@ function create_msdos_partitions {
6161
start_sector_from[$partid]=$(
6262
_get_msdos_partition_start_sector "${disk_device}" "${partid}"
6363
)
64-
udevadm lock --device "${disk_device}" \
64+
set_device_lock "${disk_device}" \
6565
sfdisk --force --delete "${disk_device}" "${partid}"
6666
;;
6767
"n")
6868
# create a partition...
6969
partid=${cmd_list[$index + 2]}
7070
part_size_end=${cmd_list[$index + 4]}
7171
echo "${start_sector_from[$partid]},${part_size_end}" > /tmp/sfdisk.in
72-
udevadm lock --device "${disk_device}" \
72+
set_device_lock "${disk_device}" \
7373
sfdisk --force -N "${partid}" "${disk_device}" < /tmp/sfdisk.in
7474
;;
7575
"t")
7676
# change a partition type...
7777
part_type=${cmd_list[$index + 2]}
7878
partid=${cmd_list[$index + 1]}
79-
udevadm lock --device "${disk_device}" \
79+
set_device_lock "${disk_device}" \
8080
sfdisk --force --change-id "${disk_device}" "${partid}" "${part_type}"
8181
;;
8282
esac
@@ -112,7 +112,7 @@ function create_gpt_partitions {
112112
"d")
113113
# delete a partition...
114114
partid=${cmd_list[$index + 1]}
115-
udevadm lock --device "${disk_device}" \
115+
set_device_lock "${disk_device}" \
116116
sgdisk --delete "${partid}" "${disk_device}"
117117
;;
118118
"n")
@@ -121,16 +121,16 @@ function create_gpt_partitions {
121121
partid=${cmd_list[$index + 2]}
122122
part_size_start=${cmd_list[$index + 3]}
123123
part_size_end=${cmd_list[$index + 4]}
124-
udevadm lock --device "${disk_device}" \
124+
set_device_lock "${disk_device}" \
125125
sgdisk --new "${partid}:${part_size_start}:${part_size_end}" "${disk_device}"
126-
udevadm lock --device "${disk_device}" \
126+
set_device_lock "${disk_device}" \
127127
sgdisk --change-name "${partid}:${part_name}" "${disk_device}"
128128
;;
129129
"t")
130130
# change a partition type...
131131
part_type=${cmd_list[$index + 2]}
132132
partid=${cmd_list[$index + 1]}
133-
udevadm lock --device "${disk_device}" \
133+
set_device_lock "${disk_device}" \
134134
sgdisk --typecode "${partid}:$(_to_guid "${part_type}")" "${disk_device}"
135135
;;
136136
esac
@@ -187,7 +187,7 @@ function create_dasd_partitions {
187187
done
188188
echo "w" >> ${partition_setup_file}
189189
echo "q" >> ${partition_setup_file}
190-
udevadm lock --device "${disk_device}" \
190+
set_device_lock "${disk_device}" \
191191
fdasd "${disk_device}" < ${partition_setup_file} 1>&2
192192
}
193193

@@ -342,7 +342,7 @@ function get_partition_uuid {
342342
}
343343

344344
function relocate_gpt_at_end_of_disk {
345-
if ! udevadm lock --device "$1" sfdisk --relocate gpt-bak-std "$1";then
345+
if ! set_device_lock "$1" sfdisk --relocate gpt-bak-std "$1";then
346346
die "Failed to write backup GPT at end of disk"
347347
fi
348348
}
@@ -384,7 +384,7 @@ function activate_boot_partition {
384384
pt_table_type=$(get_partition_table_type "${disk_device}")
385385
if [[ "$(uname -m)" =~ i.86|x86_64 ]];then
386386
if [ "${pt_table_type}" = "dos" ];then
387-
udevadm lock --device "${disk_device}" \
387+
set_device_lock "${disk_device}" \
388388
sfdisk --activate "${disk_device}" "${boot_partition_id}"
389389
fi
390390
fi
@@ -400,7 +400,7 @@ function create_hybrid_gpt {
400400
# see man sgdisk for details
401401
partition_count=3
402402
fi
403-
if ! udevadm lock --device "${disk_device}" \
403+
if ! set_device_lock "${disk_device}" \
404404
sgdisk -h "$(seq -s : 1 "${partition_count}")" "${disk_device}"
405405
then
406406
die "Failed to create hybrid GPT/MBR !"

dracut/modules.d/99kiwi-lib/module-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install() {
2323
vgs vgchange lvextend lvcreate lvresize pvresize \
2424
mdadm cryptsetup dialog \
2525
pv curl xz sha256sum sed \
26-
dmsetup touch chmod
26+
dmsetup touch chmod flock
2727
inst_multiple -o dolly
2828
if type partx &> /dev/null;then
2929
inst_multiple partx

0 commit comments

Comments
 (0)