From 8f656d395dbb5527646f69da21bfa5cb24c15175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Mon, 24 Oct 2016 12:36:25 +0100 Subject: [PATCH] Support for exporting Btrfs subvolumes --- src/modules/AutoinstPartPlan.rb | 40 ++++++++++++++------------------ src/modules/AutoinstPartition.rb | 4 +++- test/AutoinstPartPlan_test.rb | 10 ++++---- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/modules/AutoinstPartPlan.rb b/src/modules/AutoinstPartPlan.rb index 8a8a6dc6a..d631634d9 100644 --- a/src/modules/AutoinstPartPlan.rb +++ b/src/modules/AutoinstPartPlan.rb @@ -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", @@ -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 ()" diff --git a/src/modules/AutoinstPartition.rb b/src/modules/AutoinstPartition.rb index d43e5d9fa..9cab1d533 100644 --- a/src/modules/AutoinstPartition.rb +++ b/src/modules/AutoinstPartition.rb @@ -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 diff --git a/test/AutoinstPartPlan_test.rb b/test/AutoinstPartPlan_test.rb index 30a7d5329..779e91b5e 100644 --- a/test/AutoinstPartPlan_test.rb +++ b/test/AutoinstPartPlan_test.rb @@ -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