Simplify setupBaseImage() even further. Move some more code in a separate
function. Pure code reorganization. No functionality change.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
| ... | ... |
@@ -825,31 +825,48 @@ func (devices *DeviceSet) checkThinPool() error {
|
| 825 | 825 |
return nil |
| 826 | 826 |
} |
| 827 | 827 |
|
| 828 |
+// Base image is initialized properly. Either save UUID for first time (for |
|
| 829 |
+// upgrade case or verify UUID. |
|
| 830 |
+func (devices *DeviceSet) setupVerifyBaseImageUUID(baseInfo *devInfo) error {
|
|
| 831 |
+ // If BaseDeviceUUID is nil (upgrade case), save it and return success. |
|
| 832 |
+ if devices.BaseDeviceUUID == "" {
|
|
| 833 |
+ if err := devices.saveBaseDeviceUUID(baseInfo); err != nil {
|
|
| 834 |
+ return fmt.Errorf("Could not query and save base device UUID:%v", err)
|
|
| 835 |
+ } |
|
| 836 |
+ return nil |
|
| 837 |
+ } |
|
| 838 |
+ |
|
| 839 |
+ if err := devices.verifyBaseDeviceUUID(baseInfo); err != nil {
|
|
| 840 |
+ return fmt.Errorf("Base Device UUID verification failed. Possibly using a different thin pool than last invocation:%v", err)
|
|
| 841 |
+ } |
|
| 842 |
+ |
|
| 843 |
+ return nil |
|
| 844 |
+} |
|
| 845 |
+ |
|
| 828 | 846 |
func (devices *DeviceSet) setupBaseImage() error {
|
| 829 | 847 |
oldInfo, _ := devices.lookupDeviceWithLock("")
|
| 830 |
- if oldInfo != nil && oldInfo.Initialized {
|
|
| 831 |
- // If BaseDeviceUUID is nil (upgrade case), save it and |
|
| 832 |
- // return success. |
|
| 833 |
- if devices.BaseDeviceUUID == "" {
|
|
| 834 |
- if err := devices.saveBaseDeviceUUID(oldInfo); err != nil {
|
|
| 835 |
- return fmt.Errorf("Could not query and save base device UUID:%v", err)
|
|
| 848 |
+ |
|
| 849 |
+ // base image already exists. If it is initialized properly, do UUID |
|
| 850 |
+ // verification and return. Otherwise remove image and set it up |
|
| 851 |
+ // fresh. |
|
| 852 |
+ |
|
| 853 |
+ if oldInfo != nil {
|
|
| 854 |
+ if oldInfo.Initialized {
|
|
| 855 |
+ if err := devices.setupVerifyBaseImageUUID(oldInfo); err != nil {
|
|
| 856 |
+ return err |
|
| 836 | 857 |
} |
| 837 |
- return nil |
|
| 838 |
- } |
|
| 839 | 858 |
|
| 840 |
- if err := devices.verifyBaseDeviceUUID(oldInfo); err != nil {
|
|
| 841 |
- return fmt.Errorf("Base Device UUID verification failed. Possibly using a different thin pool than last invocation:%v", err)
|
|
| 859 |
+ return nil |
|
| 842 | 860 |
} |
| 843 |
- return nil |
|
| 844 |
- } |
|
| 845 | 861 |
|
| 846 |
- if oldInfo != nil && !oldInfo.Initialized {
|
|
| 847 | 862 |
logrus.Debugf("Removing uninitialized base image")
|
| 848 | 863 |
if err := devices.DeleteDevice(""); err != nil {
|
| 849 | 864 |
return err |
| 850 | 865 |
} |
| 851 | 866 |
} |
| 852 | 867 |
|
| 868 |
+ // If we are setting up base image for the first time, make sure |
|
| 869 |
+ // thin pool is empty. |
|
| 853 | 870 |
if devices.thinPoolDevice != "" && oldInfo == nil {
|
| 854 | 871 |
if err := devices.checkThinPool(); err != nil {
|
| 855 | 872 |
return err |