Skip to content

Commit

Permalink
Fate317957 and 318555, support LVM configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-wang committed May 15, 2015
1 parent 6d1d8b0 commit 00cd23e
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ ynclude_DATA = \
include/drbd/resource_conf.rb \
include/drbd/helps.rb \
include/drbd/global_conf.rb \
include/drbd/lvm_conf.rb \
include/drbd/wizards.rb

scrconf_DATA = \
scrconf/drbd.scr
scrconf/drbd.scr \
scrconf/drbd_lvm.scr

desktop_DATA = \
desktop/drbd.desktop
Expand Down
3 changes: 2 additions & 1 deletion src/include/drbd/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def initialize_drbd_common(include_target)
Yast.import "Popup"
Yast.import "CWM"

@DIALOG = ["startup_conf", "global_conf", "resource_conf"]
@DIALOG = ["startup_conf", "global_conf", "resource_conf","lvm_conf"]

@PARENT = {}

@NAME = {
"startup_conf" => _("Start-up Configuration"),
"global_conf" => _("Global Configuration"),
"resource_conf" => _("Resource Configuration"),
"lvm_conf" => _("LVM Configuration"),
"basic_conf" => _("Resource Basic Configuration"),
"advance_conf" => _("Resource Advanced Configuration")
}
Expand Down
18 changes: 18 additions & 0 deletions src/include/drbd/helps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ def initialize_drbd_helps(include_target)
"\t\t<p><b>al-extents</b>: parameter you control how big the hot area (= active set) can get. The default number of extents is 127. (Minimum: 7, Maximum: 3843)</p>\n" +
"\t\t"
),
"lvm_conf" => _(
"<p><b><big>LVM Configuration</big></b></p>"
) +
_(
"\n" +
"\t\t<p><b>LVM configuration file /etc/lvm/lvm.conf</b></p>\n" +
"\t\t<p>To use LVM with DRBD, it is necessary to change some options in the LVM configuration file and to remove stale cache entries on the nodes.</p>" +
"\t\t<p>Refer to 'man lvm.conf' for further information including the file layout.</p>\n" +
"\t\t\t\t\t\t\t\t\t\t \n" +
"\t\t<p><b>Device Filter</b>: This masks the underlying block device from the list of devices LVM scans for Physical Volume signatures. This way, LVM is instructed to read Physical Volume signatures from DRBD devices, rather than from the underlying backing block devices.</p>" +
"\t\t<p><b>AutoFilter</b>: According to the configuration of drbd, LVM filter will always be changed automatically. To change it manually, disable the checkbox of AutoFilter.</p>\n" +
"\t\t<p>The filter consists of an array of regular expressions. These expressions can be delimited by a character of your choice, and prefixed with either an 'a' (for accept) or 'r' (for reject).</p>" +
"\t\t<p>For example, setting filter as [\"r|/dev/sda.*|\"]</p>\n" +
"\n" +
"\t\t<p><b>LVM cache</b>: Enable/turn on writing the LVM cache is default. Disable cache when for network storage, like nfs. </p>\n" +
"\n" +
"\t\t"
),
"global_conf" => _(
"<p><b><big>Global Configuration of DRBD</big></b></p>"
) +
Expand Down
175 changes: 175 additions & 0 deletions src/include/drbd/lvm_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# encoding: utf-8

module Yast
module DrbdLvmConfInclude
def initialize_drbd_lvm_conf(include_target)
textdomain "drbd"

Yast.import "Label"
Yast.import "Wizard"
Yast.import "Drbd"

Yast.include include_target, "drbd/helps.rb"
Yast.include include_target, "drbd/common.rb"

@filter = ""
@cache = true
# Default is always true (auto)
@auto_lvm_filter = true
end

def lvm_conf_Read
@filter = Ops.get_string( Drbd.lvm_config, "filter", "" )
cache_str = Ops.get_string( Drbd.lvm_config, "write_cache_state", "1" )

if cache_str == "0"
@cache = false
else
@cache = true
end

nil
end

def lvm_conf_GetDialog
_Tfilter = Frame(
_("LVM Filter Configuration of DRBD"),
Left(
VBox(
VBox(
Left(
CheckBox(
Id(:AutoFilter),
Opt(:notify),
_("Modify LVM Device filter Automatically"),
@auto_lvm_filter
)
)
),
VBox(
Left(
InputField(
Id(:Filter),
Opt(:hstretch),
_("Device Filter"),
@filter
)
)
),
)
)
)

_Tcache = Frame(
_("Writing the LVM cache"),
Left(
HSquash(
VBox(
VBox(
Left(
CheckBox(
Id(:LVMCache),
Opt(:notify),
_("Enable LVM Cache"),
@cache
)
)
),
)
)
)
)

VBox(
_Tfilter,
VSpacing(1),
_Tcache,
VStretch()
)
end

def lvm_conf_Write
@filter = UI.QueryWidget(Id(:Filter), :Value).to_s
@auto_lvm_filter = UI.QueryWidget(Id(:AutoFilter), :Value)

@cache = UI.QueryWidget(Id(:LVMCache), :Value)

if @cache
cache_str = "1"
else
cache_str = "0"
end

Drbd.auto_lvm_filter = @auto_lvm_filter
Ops.set(Drbd.lvm_config, "write_cache_state", cache_str)

if !@auto_lvm_filter
Ops.set(Drbd.lvm_config, "filter", @filter)
Builtins.y2debug("Change Device Filter manually.")
end

Drbd.modified = true

true
end

def status_switch
if UI.QueryWidget(Id(:AutoFilter), :Value)
UI.ChangeWidget(Id(:Filter), :Enabled, false)
else
UI.ChangeWidget(Id(:Filter), :Enabled, true)
end

nil
end

def ConfigureLVMDialog
lvm_conf_Read

my_SetContents("lvm_conf", lvm_conf_GetDialog)
status_switch

ret = nil
while true
Wizard.SelectTreeItem("lvm_conf")
status_switch

ret = UI.UserInput

if ret == :help
#myHelp("lvm_conf")
next
end

if ret == :wizardTree
ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem))
end

if ret == :Filter || ret == :LVMCache || ret == :AutoFilter
Drbd.modified = true
next
end

if ret == :abort || ret == :cancel
if ReallyAbort()
return deep_copy(ret)
else
next
end
end

if ret == :next || ret == :back ||
Builtins.contains(@DIALOG, Builtins.tostring(ret))
next if !lvm_conf_Write

if ret != :next && ret != :back
ret = Builtins.symbolof(Builtins.toterm(ret))
end

break
end
end
deep_copy(ret)
end
end
end
33 changes: 33 additions & 0 deletions src/include/drbd/resource_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,32 @@ def res_basic_config_get_dialog(res_config)
)
end

def update_add_disk_list
# Update new add disk used of drbd res for LVM filter
# Ignore the removed disk
local_hname = Drbd.local_hostname

node1 = UI.QueryWidget(Id(:n1_name), :Value).to_s.strip()
node2 = UI.QueryWidget(Id(:n2_name), :Value).to_s.strip()

if local_hname == node1
disk = UI.QueryWidget(Id(:n1_disk), :Value).to_s.strip()
elsif local_hname == node2
disk = UI.QueryWidget(Id(:n2_disk), :Value).to_s.strip()
else
disk = nil
Builtins.y2error("Disk is not belong to local. localhost is %1,
node1 is %2, node2 is %3.", local_hname, node1, node2)
end
Builtins.y2debug("Add %1 to add disk list.", disk)

if disk && !Drbd.local_disks_ori.include?(disk) &&
!Drbd.local_disks_added.include?(disk)
Drbd.local_disks_added.push(disk)
end

nil
end

def save_basic_config(res_config)
res_config = deep_copy(res_config)
Expand Down Expand Up @@ -593,6 +619,9 @@ def ResDialog(resname)
res_config = save_basic_config(res_config)
Builtins.y2debug("res_config = %1", res_config)

# For change LVM filter automatically
update_add_disk_list

my_SetContents(
"advance_conf",
res_advance_config_get_dialog(res_config)
Expand Down Expand Up @@ -635,6 +664,9 @@ def ResDialog(resname)

Builtins.y2debug("res_config=%1", res_config)

# For change LVM filter automatically
update_add_disk_list

if Ops.greater_than(Builtins.size(resname), 0)
Drbd.resource_config = Builtins.remove(
Drbd.resource_config,
Expand Down Expand Up @@ -701,6 +733,7 @@ def ResourceSequence
"list" => {
:startup_conf => :startup_conf,
:global_conf => :global_conf,
:lvm_conf => :lvm_conf,
:add => "add",
:edit => "edit",
:list => "list",
Expand Down
4 changes: 3 additions & 1 deletion src/include/drbd/wizards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def initialize_drbd_wizards(include_target)
Yast.include include_target, "drbd/dialogs.rb"
Yast.include include_target, "drbd/startup_conf.rb"
Yast.include include_target, "drbd/global_conf.rb"
Yast.include include_target, "drbd/lvm_conf.rb"
Yast.include include_target, "drbd/resource_conf.rb"
end

def TabSequence
_Aliases = {
"startup_conf" => lambda { ConfigureStartUpDialog() },
"global_conf" => lambda { ConfigureGlobalDialog() },
"resource_conf" => lambda { ResourceSequence() }
"resource_conf" => lambda { ResourceSequence() },
"lvm_conf" => lambda { ConfigureLVMDialog() }
}

anywhere = { :abort => :abort, :next => :next }
Expand Down
Loading

0 comments on commit 00cd23e

Please sign in to comment.