-
Notifications
You must be signed in to change notification settings - Fork 913
cidata: fix virtiofs mounts with a space in the path #5145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ekalinin
wants to merge
1
commit into
lima-vm:master
Choose a base branch
from
ekalinin:fix/virtiofs-mount-path-with-spaces
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/bin/bash | ||
|
|
||
| # SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Read an /etc/fstab on stdin and write it to stdout with the mount-point field | ||
| # octal-escaped (per fstab(5)) for cloud-config virtiofs entries whose path | ||
| # contains a space or tab. cloud-init's cc_mounts writes the mount point verbatim, | ||
| # so a space/tab produces an unparsable line that mount(8) silently skips via the | ||
| # nofail option. Fields are tab-separated, so -F'\t' isolates the mount point; | ||
| # already-escaped paths have no literal space/tab, so the transformation is | ||
| # idempotent (and stays correct once cloud-init escapes the field itself). | ||
| # | ||
| # See: | ||
| # https://github.com/lima-vm/lima/issues/5136 | ||
| # https://github.com/abiosoft/colima/issues/1471 | ||
| # https://github.com/canonical/cloud-init/issues/3603 (cc_mounts does not escape) | ||
| # https://github.com/canonical/cloud-init/issues/6911 (the upstream cloud-init fix) | ||
|
|
||
| set -eu | ||
|
|
||
| : "${SELFTEST:=}" | ||
| if [ -n "${SELFTEST}" ]; then | ||
| unset SELFTEST | ||
| tab=$(printf '\t') | ||
| check() { | ||
| local desc=$1 input=$2 want=$3 got | ||
| got=$(printf '%s\n' "${input}" | "$0") | ||
| if [ "${got}" = "${want}" ]; then | ||
| echo "ok: ${desc}" | ||
| else | ||
| echo "FAIL: ${desc}" >&2 | ||
| printf ' want: %q\n got: %q\n' "${want}" "${got}" >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
| echo >&2 "=== Running tests ===" | ||
| check "space in the mount point is escaped" \ | ||
| "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \ | ||
| "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" | ||
| check "already-escaped path is unchanged (idempotent)" \ | ||
| "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \ | ||
| "tag${tab}/tmp/dir\\040with\\040spaces${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" | ||
| check "path without whitespace is unchanged" \ | ||
| "tag${tab}/mnt/nospace${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" \ | ||
| "tag${tab}/mnt/nospace${tab}virtiofs${tab}rw,nofail,comment=cloudconfig${tab}0${tab}0" | ||
| check "backslash is escaped before the space" \ | ||
| "tag${tab}/a b\\c${tab}virtiofs${tab}rw,comment=cloudconfig${tab}0${tab}0" \ | ||
| "tag${tab}/a\\040b\\134c${tab}virtiofs${tab}rw,comment=cloudconfig${tab}0${tab}0" | ||
| check "entry without comment=cloudconfig is unchanged" \ | ||
| "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw${tab}0${tab}0" \ | ||
| "tag${tab}/tmp/dir with spaces${tab}virtiofs${tab}rw${tab}0${tab}0" | ||
| check "non-virtiofs entry is unchanged" \ | ||
| "/dev/sda1${tab}/data dir${tab}ext4${tab}defaults,comment=cloudconfig${tab}0${tab}0" \ | ||
| "/dev/sda1${tab}/data dir${tab}ext4${tab}defaults,comment=cloudconfig${tab}0${tab}0" | ||
| echo >&2 "=== All tests passed ===" | ||
| exit 0 | ||
| fi | ||
|
|
||
| awk -F'\t' 'BEGIN { OFS = "\t" } | ||
| $3 == "virtiofs" && $4 ~ /comment=cloudconfig/ && $2 ~ /[ \t]/ { | ||
| p = $2 | ||
| gsub(/\\/, "\\134", p) # backslash first so introduced escapes are not re-escaped | ||
| gsub(/ /, "\\040", p) | ||
| gsub(/\t/, "\\011", p) | ||
| $2 = p | ||
| } | ||
| { print }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/bin/bash | ||
|
|
||
| # SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Read a string on stdin and write it to stdout with the octal escapes used in | ||
| # /etc/fstab and /proc/mounts decoded to their literal characters: | ||
| # "\040" -> space, "\011" -> tab, "\012" -> newline, "\134" -> backslash, | ||
| # "\043" -> "#". The inverse of util/escape_fstab.sh. | ||
| # https://github.com/torvalds/linux/blob/v6.6/fs/proc_namespace.c#L89 | ||
|
|
||
| set -eu | ||
|
|
||
| : "${SELFTEST:=}" | ||
| if [ -n "${SELFTEST}" ]; then | ||
| unset SELFTEST | ||
| tab=$(printf '\t') | ||
| check() { | ||
| local desc=$1 input=$2 want=$3 got | ||
| got=$(printf '%s\n' "${input}" | "$0") | ||
| if [ "${got}" = "${want}" ]; then | ||
| echo "ok: ${desc}" | ||
| else | ||
| echo "FAIL: ${desc}" >&2 | ||
| printf ' want: %q\n got: %q\n' "${want}" "${got}" >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
| echo >&2 "=== Running tests ===" | ||
| check "spaces are decoded" '/tmp/dir\040with\040spaces' "/tmp/dir with spaces" | ||
| check "tab is decoded" '/a\011b' "/a${tab}b" | ||
| check "newline is decoded" 'a\012b' "$(printf 'a\nb')" | ||
| check "backslash is decoded" '/a\134b' '/a\b' | ||
| check "hash is decoded" '/a\043b' "/a#b" | ||
| check "a string without escapes is unchanged" "/mnt/nospace" "/mnt/nospace" | ||
| check "mixed escapes are decoded" '/a\040b\134c' '/a b\c' | ||
| echo >&2 "=== All tests passed ===" | ||
| exit 0 | ||
| fi | ||
|
|
||
| sed -e 's/\\040/ /g; s/\\011/\t/g; s/\\012/\n/g; s/\\134/\\/g; s/\\043/#/g' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.