Browse code

Init default lvm volume group only if required

A recent patch [1] added support for lvm ephemeral storage for nova,
but at the cost of initializing a default lvm volume group even if it
was not required. This change ensures that init of the default volume
group is only performed when nova and/or cinder are configured to use
lvm.

1: https://review.openstack.org/#/c/132333

Change-Id: I7634ca0ed0ffe1b13464e4d66744918f85149f2e
Closes-Bug: #1414820

Maru Newby authored on 2015/01/28 02:44:44
Showing 4 changed files
... ...
@@ -399,6 +399,10 @@ function init_cinder {
399 399
             be_type=${be%%:*}
400 400
             be_name=${be##*:}
401 401
             if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
402
+                # Always init the default volume group for lvm.
403
+                if [[ "$be_type" == "lvm" ]]; then
404
+                    init_default_lvm_volume_group
405
+                fi
402 406
                 init_cinder_backend_${be_type} ${be_name}
403 407
             fi
404 408
         done
... ...
@@ -117,6 +117,25 @@ function init_lvm_volume_group {
117 117
     _clean_lvm_volume_group $vg
118 118
 }
119 119
 
120
+# Sentinal value to ensure that init of default lvm volume group is
121
+# only performed once across calls of init_default_lvm_volume_group.
122
+_DEFAULT_LVM_INIT=${_DEFAULT_LVM_INIT:-0}
123
+
124
+# init_default_lvm_volume_group() initializes a default volume group
125
+# intended to be shared between cinder and nova.  It is idempotent;
126
+# the init of the default volume group is guaranteed to be performed
127
+# only once so that either or both of the dependent services can
128
+# safely call this function.
129
+#
130
+# Usage: init_default_lvm_volume_group()
131
+function init_default_lvm_volume_group {
132
+    if [[ "$_DEFAULT_LVM_INIT" = "0" ]]; then
133
+        init_lvm_volume_group $DEFAULT_VOLUME_GROUP_NAME $VOLUME_BACKING_FILE_SIZE
134
+        _DEFAULT_LVM_INIT=1
135
+    fi
136
+}
137
+
138
+
120 139
 # Restore xtrace
121 140
 $MY_XTRACE
122 141
 
... ...
@@ -640,6 +640,10 @@ function init_nova {
640 640
 
641 641
     create_nova_cache_dir
642 642
     create_nova_keys_dir
643
+
644
+    if [[ "$NOVA_BACKEND" == "LVM" ]]; then
645
+        init_default_lvm_volume_group
646
+    fi
643 647
 }
644 648
 
645 649
 # install_novaclient() - Collect source and prepare
... ...
@@ -939,10 +939,6 @@ init_service_check
939 939
 # A better kind of sysstat, with the top process per time slice
940 940
 start_dstat
941 941
 
942
-# Initialize default LVM volume group
943
-# -----------------------------------
944
-init_lvm_volume_group $DEFAULT_VOLUME_GROUP_NAME $VOLUME_BACKING_FILE_SIZE
945
-
946 942
 # Start Services
947 943
 # ==============
948 944