An lvm module that can set issue_discards and global_filter
authorPeter Palfrader <peter@palfrader.org>
Thu, 29 Aug 2019 15:08:40 +0000 (17:08 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 29 Aug 2019 15:53:41 +0000 (17:53 +0200)
modules/lvm/manifests/init.pp [new file with mode: 0644]
modules/lvm/templates/lvm.conf-buster.erb
modules/lvm/templates/lvm.conf-stretch.erb

diff --git a/modules/lvm/manifests/init.pp b/modules/lvm/manifests/init.pp
new file mode 100644 (file)
index 0000000..782827f
--- /dev/null
@@ -0,0 +1,24 @@
+# put a lvm.conf file on the host,
+#   optionally with the global_filter attribute set,
+#   with issue_discards set as configured.
+class lvm(
+  Optional[String] $global_filter = undef,
+  Boolean          $issue_discards = false,
+) {
+  if (versioncmp($::lsbmajdistrelease, '10') >= 0) {
+    $template = 'lvm/lvm.conf-buster.erb'
+  } else {
+    $template = 'lvm/lvm.conf-stretch.erb'
+  }
+
+  file { '/etc/lvm/lvm.conf':
+    ensure  => file,
+    content => template($template),
+    notify  => [ Exec['update-initramfs -u'], Exec['vgscan'] ];
+  }
+
+  exec { 'vgscan':
+      path        => '/etc/init.d:/usr/bin:/usr/sbin:/bin:/sbin',
+      refreshonly => true;
+  }
+}
index f2bcf02..fe17ea9 100644 (file)
@@ -148,6 +148,10 @@ devices {
        # global_filter are not opened by LVM.
        # This configuration option has an automatic default value.
        # global_filter = [ "a|.*/|" ]
+<% if @global_filter -%>
+       global_filter = <%= @global_filter -%>
+
+<% end -%>
 
        # Configuration option devices/types.
        # List of additional acceptable block device types.
@@ -282,8 +286,13 @@ devices {
        # benefit from discards, but SSDs and thinly provisioned LUNs
        # generally do. If enabled, discards will only be issued if both the
        # storage and kernel provide support.
+<% if @issue_discards -%>
+       issue_discards = 1
+
+<% else -%>
        issue_discards = 0
 
+<% end -%>
        # Configuration option devices/allow_changes_with_duplicate_pvs.
        # Allow VG modification while a PV appears on multiple devices.
        # When a PV appears on multiple devices, LVM attempts to choose the
index feb4917..7392a4d 100644 (file)
@@ -149,6 +149,10 @@ devices {
        # global_filter are not opened by LVM.
        # This configuration option has an automatic default value.
        # global_filter = [ "a|.*/|" ]
+<% if @global_filter -%>
+       global_filter = <%= @global_filter -%>
+
+<% end -%>
 
        # Configuration option devices/cache_dir.
        # Directory in which to store the device cache file.
@@ -298,8 +302,14 @@ devices {
        # benefit from discards, but SSDs and thinly provisioned LUNs
        # generally do. If enabled, discards will only be issued if both the
        # storage and kernel provide support.
+<% if @issue_discards -%>
+       issue_discards = 1
+
+<% else -%>
        issue_discards = 0
 
+<% end -%>
+
        # Configuration option devices/allow_changes_with_duplicate_pvs.
        # Allow VG modification while a PV appears on multiple devices.
        # When a PV appears on multiple devices, LVM attempts to choose the