From a39caacad341234e5d9e86ae2b7cf8c2ecbbc190 Mon Sep 17 00:00:00 2001
From: Mate Lakat <mate.lakat@citrix.com>
Date: Mon, 3 Sep 2012 15:45:53 +0100
Subject: [PATCH] Make sure tgt is using config.d approach

Fixes bug 1045358.

On ubuntu Oneiric, the tgt configuration was not using the config.d
approach. tgt was unable to find the config files, so no volumes could
be created. This fix makes sure, that the config.d directory is there,
and the configuration includes files from there.

Was Cinder only, added same fix for Nova volumes

Change-Id: I6752cb628dd22e91e640f0f584fafefa4cd6d0f1
---
 lib/cinder | 9 +++++++++
 lib/n-vol  | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/lib/cinder b/lib/cinder
index 5f0b25539c..ec491dda72 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -189,10 +189,19 @@ function install_cinder() {
     git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
 }
 
+# apply config.d approach (e.g. Oneiric does not have this)
+function _configure_tgt_for_config_d() {
+    if [[ ! -d /etc/tgt/conf.d/ ]]; then
+        sudo mkdir /etc/tgt/conf.d
+        echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
+    fi
+}
+
 # start_cinder() - Start running processes, including screen
 function start_cinder() {
     if is_service_enabled c-vol; then
         if [[ "$os_PACKAGE" = "deb" ]]; then
+            _configure_tgt_for_config_d
             if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
                echo "include $CINDER_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
             fi
diff --git a/lib/n-vol b/lib/n-vol
index 30be0cdd68..a9d1c7d12e 100644
--- a/lib/n-vol
+++ b/lib/n-vol
@@ -5,6 +5,7 @@
 # - functions
 # - KEYSTONE_AUTH_* must be defined
 # SERVICE_{TENANT_NAME|PASSWORD} must be defined
+# _configure_tgt_for_config_d() from lib/cinder
 
 # stack.sh
 # ---------
@@ -94,6 +95,7 @@ function install_nvol() {
 function start_nvol() {
     # Setup the tgt configuration file
     if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
+        _configure_tgt_for_config_d
        sudo mkdir -p /etc/tgt/conf.d
        echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
     fi