Skip to content

Commit

Permalink
Use Btrfs#btrfs_subvolume_mount_point when setting Btrfs 'ro'
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 13, 2018
1 parent a97cd09 commit d2bada8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib/installation/clients/umount_finish.rb
Expand Up @@ -411,6 +411,9 @@ def set_btrfs_defaults_as_ro
ro_btrfs_filesystems.each { |f| default_subvolume_as_ro(f) }
end

# [String] Name used by btrfs tools to name the filesystem tree.
BTRFS_FS_TREE = "(FS_TREE)".freeze

# Set the "read-only" property for the root subvolume.
# This has to be done as long as the target root filesystem is still
# mounted.
Expand All @@ -421,18 +424,13 @@ def default_subvolume_as_ro(fs)
"btrfs", "subvolume", "get-default", fs.mount_point.path, stdout: :capture
)
default_subvolume = output.strip.split.last

# no btrfs_default_subvolume and no snapshots
default_subvolume = "" if default_subvolume == "(FS_TREE)"

if !fs.subvolumes_prefix.empty?
default_subvolume = default_subvolume.sub(fs.subvolumes_prefix, "")
end
default_subvolume = "" if default_subvolume == BTRFS_FS_TREE

default_subvolume = Pathname.new(fs.mount_point.path).join(default_subvolume).to_s
subvolume_path = fs.btrfs_subvolume_mount_point(default_subvolume)

log.info("Setting root subvol read-only property on #{default_subvolume}")
Yast::Execute.on_target("btrfs", "property", "set", default_subvolume, "ro", "true")
log.info("Setting root subvol read-only property on #{subvolume_path}")
Yast::Execute.on_target("btrfs", "property", "set", subvolume_path, "ro", "true")
end
end
end
10 changes: 10 additions & 0 deletions test/lib/clients/umount_finish_test.rb
Expand Up @@ -43,6 +43,8 @@
let(:get_default) { "ID 276 gen 1172 top level 275 path .snapshots/1/snapshot\n" }

it "sets 'ro' property to true on the snapshot" do
expect(root_fs).to receive(:btrfs_subvolume_mount_point)
.with(".snapshots/1/snapshot").and_return("/.snapshots/1/snapshot")
expect(Yast::Execute).to receive(:on_target)
.with("btrfs", "property", "set", "/.snapshots/1/snapshot", "ro", "true")
client.set_btrfs_defaults_as_ro
Expand All @@ -53,6 +55,8 @@
let(:get_default) { "ID 5 (FS_TREE)\n" }

it "sets 'ro' property to true on the mount point" do
expect(root_fs).to receive(:btrfs_subvolume_mount_point)
.with("").and_return("/")
expect(Yast::Execute).to receive(:on_target)
.with("btrfs", "property", "set", "/", "ro", "true")
client.set_btrfs_defaults_as_ro
Expand All @@ -67,6 +71,8 @@
let(:get_default) { "ID 276 gen 1172 top level 275 path @/.snapshots/1/snapshot\n" }

it "sets 'ro' property to true on the snapshot" do
expect(root_fs).to receive(:btrfs_subvolume_mount_point)
.with("@/.snapshots/1/snapshot").and_return("/.snapshots/1/snapshot")
expect(Yast::Execute).to receive(:on_target)
.with("btrfs", "property", "set", "/.snapshots/1/snapshot", "ro", "true")
client.set_btrfs_defaults_as_ro
Expand All @@ -77,6 +83,8 @@
let(:get_default) { "ID 276 gen 1172 top level 275 path @\n" }

it "sets 'ro' property to true on the mount point" do
expect(root_fs).to receive(:btrfs_subvolume_mount_point)
.with("@").and_return("/")
expect(Yast::Execute).to receive(:on_target)
.with("btrfs", "property", "set", "/", "ro", "true")
client.set_btrfs_defaults_as_ro
Expand All @@ -95,6 +103,8 @@
end

it "sets 'ro' property to true on the mount point" do
expect(root_fs).to receive(:btrfs_subvolume_mount_point)
.with("").and_return("/home")
expect(Yast::Execute).to receive(:on_target)
.with("btrfs", "property", "set", "/home", "ro", "true")
client.set_btrfs_defaults_as_ro
Expand Down

0 comments on commit d2bada8

Please sign in to comment.