Skip to content
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

Fixes subvol delete on a non-btrfs volume #42272

Merged
merged 2 commits into from Apr 22, 2021
Merged

Conversation

brettmilford
Copy link

Inode numbers are guaranteed to be unique only within a filesystem.
As such there is an edge case where these predicates are true on a
non-btrfs filesystem.

Closes #42271

Signed-off-by: Brett Milford brettmilford@gmail.com

- What I did
Added an additional check for filesystem type.

- How to verify it
Tested this code block on btrfs and non-btrfs (zfs) filesystems.

- Description for the changelog
Fixed issue where nuke-graph-directory.sh executes btrfs subvolume delete on a non-btrfs file.

Inode numbers are guaranteed to be unique only within a filesystem.
As such there is an edge case where these predicates are true on a
non-btrfs filesystem.

Closes moby#42271

Signed-off-by: Brett Milford <brettmilford@gmail.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a minor nit; but let me ask @tianon @AkihiroSuda to review

set -x
btrfs subvolume delete "$subvol"
)
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this script specified bash, but I know we try to stay close to POSIX where possible, to allow running scripts in non-bash environments; perhaps change this to;

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if [ "$(stat -f --format=%T $subvol)" = "btrfs" ]; then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full agreement from me 😇

I'd go one step further, too:

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if [ "$(stat -f --format=%T "$subvol")" = "btrfs" ]; then

Or even (to catch any possible failing exit code from stat):

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if subvolType="$(stat -f --format=%T "$subvol")" && [ "$subvolType" = "btrfs" ]; then

@@ -61,10 +61,12 @@ if command -v btrfs > /dev/null 2>&1; then
# Source: http://stackoverflow.com/a/32865333
for subvol in $(find "$dir" -type d -inum 256 | sort -r); do
if [ "$dir" != "$subvol" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's probably worth bringing that conditinoal all the way up to here, ala:

Suggested change
if [ "$dir" != "$subvol" ]; then
if [ "$dir" != "$subvol" ] && subvolType="$(stat -f --format=%T "$subvol")" && [ "$subvolType" = "btrfs" ]; then

(So we only have a single if)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's, nifty; and looks good to me.

Signed-off-by: Brett Milford <brettmilford@gmail.com>
Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😅

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 20bd03b into moby:master Apr 22, 2021
@thaJeztah thaJeztah added this to the 21.xx milestone May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nuke-graph-directory.sh error on btrfs subvolume delete
3 participants