Skip to content

Commit

Permalink
Support for exporting Btrfs subvolumes
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 25, 2016
1 parent 862d087 commit 8f656d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
40 changes: 18 additions & 22 deletions src/modules/AutoinstPartPlan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,30 +530,13 @@ def ReadHelper
end
# Subvolumes
# Save possibly existing subvolumes
if !Builtins.isempty(Ops.get_list(pe, "subvol", []))
if !pe.fetch("subvol", []).empty?
defsub = ""
if !Builtins.isempty(FileSystems.default_subvol)
defsub = Ops.add(FileSystems.default_subvol, "/")
if !FileSystems.default_subvol.empty?
defsub = FileSystems.default_subvol + "/"
end
Ops.set(
new_pe,
"subvolumes",
Builtins.maplist(Ops.get_list(pe, "subvol", [])) do |p|
if Ops.greater_than(Builtins.size(defsub), 0) &&
Builtins.substring(
Ops.get_string(p, "name", ""),
0,
Builtins.size(defsub)
) == defsub
next Builtins.substring(
Ops.get_string(p, "name", ""),
Builtins.size(defsub)
)
else
next Ops.get_string(p, "name", "")
end
end
)
new_pe["subvolumes"] = pe.fetch("subvol", []).map { |s| export_subvolume(s, defsub) }

Ops.set(
new_pe,
"subvolumes",
Expand Down Expand Up @@ -1103,6 +1086,19 @@ def deletePartition(driveId, partitionIdx)
end
end

# Build a subvolume specification from the current definition
#
# @param subvolume [Hash] Subvolume definition (internal storage layer definition)
# @param prefix [String] Subvolume prefix (usually default subvolume + '/')
# @return [Hash] External representation of a subvolume (e.g. to be used by AutoYaST)
def export_subvolume(subvolume, prefix = "")
subvolume_spec = {
"name" => subvolume["name"].sub(/\A#{prefix}/, "")
}
subvolume_spec["options"] = "nocow" if subvolume["nocow"]
subvolume_spec
end

publish :function => :SetModified, :type => "void ()"
publish :function => :GetModified, :type => "boolean ()"
publish :function => :updateTree, :type => "void ()"
Expand Down
4 changes: 3 additions & 1 deletion src/modules/AutoinstPartition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ def parsePartition(part)
end
if !Builtins.isempty(Ops.get_list(part, "subvolumes", []))
#Filtering out all snapper subvolumes
newPart["subvolumes"] = part["subvolumes"].reject { |s| s.start_with?(".snapshots") }
newPart["subvolumes"] = part["subvolumes"].reject do |subvolume|
subvolume["name"].start_with?(".snapshots")
end
else
newPart = Builtins.remove(newPart, "subvolumes")
end
Expand Down
10 changes: 5 additions & 5 deletions test/AutoinstPartPlan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
exported = Yast::AutoinstPartPlan.Export
subvolumes = exported.first["partitions"].first["subvolumes"]
expect(subvolumes).to eq([
"@",
"home",
"var/log",
"var/lib/pgsql",
"myvol"
{ "name" => "@" },
{ "name" => "home" },
{ "name" => "var/log" },
{ "name" => "var/lib/pgsql" },
{ "name" => "myvol", "options" => "nocow" },
])
end

Expand Down

0 comments on commit 8f656d3

Please sign in to comment.