Skip to content

Commit b53522a

Browse files
committed
fix logic and only set permissions on file or directory volumes
1 parent 8317cf7 commit b53522a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

files/virt_volume.sh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,20 @@ fi
9797
# Change the ownership of the volume to VOLUME_OWNER:VOLUME_GROUP if
9898
# these environmental variables are defined. Without doing this libvirt
9999
# cannot access the volume on RedHat based GNU/Linux distributions.
100-
if [[ -z "$VOLUME_OWNER" || -z "$VOLUME_GROUP" ]]; then
101-
# Avoid attempting to change permissions on volumes that are not file or
102-
# directory based
103-
if [[ -f "$output" || -d "$output" ]]; then
104-
existing_owner="$(stat --format '%U' "$output")"
105-
existing_group="$(stat --format '%G' "$output")"
106-
new_owner="${VOLUME_OWNER:-$existing_owner}"
107-
new_group="${VOLUME_GROUP:-$existing_group}"
108-
output=$(chown "$new_owner":"$new_group" "$output" 2>1)
109-
result=$?
110-
if [[ $result -ne 0 ]]; then
111-
echo "Failed to change ownership of the volume to $new_owner:$new_group"
112-
echo "$output"
113-
virsh vol-delete --pool "$POOL" --vol "$NAME"
114-
exit $result
115-
fi
116-
else
117-
echo "Setting ownership on volumes not backed by a file or directory is not supported"
118-
exit 1
100+
# Avoid attempting to change permissions on volumes that are not file or
101+
# directory based
102+
if [[ -f "$output" || -d "$output" ]]; then
103+
existing_owner="$(stat --format '%U' "$output")"
104+
existing_group="$(stat --format '%G' "$output")"
105+
new_owner="${VOLUME_OWNER:-$existing_owner}"
106+
new_group="${VOLUME_GROUP:-$existing_group}"
107+
output=$(chown "$new_owner":"$new_group" "$output" 2>1)
108+
result=$?
109+
if [[ $result -ne 0 ]]; then
110+
echo "Failed to change ownership of the volume to $new_owner:$new_group"
111+
echo "$output"
112+
virsh vol-delete --pool "$POOL" --vol "$NAME"
113+
exit $result
119114
fi
120115
fi
121116

0 commit comments

Comments
 (0)