| ... | ... |
@@ -362,19 +362,45 @@ func (devices *DeviceSetDM) log(level int, file string, line int, dmError int, m |
| 362 | 362 |
func (devices *DeviceSetDM) initDevmapper() error {
|
| 363 | 363 |
logInit(devices) |
| 364 | 364 |
|
| 365 |
+begin: |
|
| 365 | 366 |
info, err := getInfo(devices.getPoolName()) |
| 366 | 367 |
if info == nil {
|
| 367 | 368 |
utils.Debugf("Error device getInfo: %s", err)
|
| 368 | 369 |
return err |
| 369 | 370 |
} |
| 370 |
- utils.Debugf("initDevmapper(). Pool exists: %v", info.Exists)
|
|
| 371 |
+ |
|
| 372 |
+ loopbackExists := false |
|
| 373 |
+ if _, err := os.Stat(devices.loopbackDir()); err != nil {
|
|
| 374 |
+ if !os.IsNotExist(err) {
|
|
| 375 |
+ return err |
|
| 376 |
+ } |
|
| 377 |
+ // If it does not, then we use a different pool name |
|
| 378 |
+ parts := strings.Split(devices.devicePrefix, "-") |
|
| 379 |
+ i, err := strconv.Atoi(parts[len(parts)-1]) |
|
| 380 |
+ if err != nil {
|
|
| 381 |
+ i = 0 |
|
| 382 |
+ parts = append(parts, "0") |
|
| 383 |
+ } |
|
| 384 |
+ i++ |
|
| 385 |
+ parts[len(parts)-1] = strconv.Itoa(i) |
|
| 386 |
+ devices.devicePrefix = strings.Join(parts, "-") |
|
| 387 |
+ } else {
|
|
| 388 |
+ loopbackExists = true |
|
| 389 |
+ } |
|
| 390 |
+ |
|
| 391 |
+ // If the pool exists but the loopback does not, then we start again |
|
| 392 |
+ if info.Exists == 1 && !loopbackExists {
|
|
| 393 |
+ goto begin |
|
| 394 |
+ } |
|
| 395 |
+ |
|
| 396 |
+ utils.Debugf("initDevmapper(). Pool exists: %v, loopback Exists: %v", info.Exists, loopbackExists)
|
|
| 371 | 397 |
|
| 372 | 398 |
// It seems libdevmapper opens this without O_CLOEXEC, and go exec will not close files |
| 373 | 399 |
// that are not Close-on-exec, and lxc-start will die if it inherits any unexpected files, |
| 374 | 400 |
// so we add this badhack to make sure it closes itself |
| 375 | 401 |
setCloseOnExec("/dev/mapper/control")
|
| 376 | 402 |
|
| 377 |
- if info.Exists != 0 {
|
|
| 403 |
+ if info.Exists != 0 && loopbackExists {
|
|
| 378 | 404 |
/* Pool exists, assume everything is up */ |
| 379 | 405 |
if err := devices.loadMetaData(); err != nil {
|
| 380 | 406 |
utils.Debugf("Error device loadMetaData: %s\n", err)
|