Fix state persistence, create folder if it doesn't exist
This commit is contained in:
@@ -54,9 +54,23 @@ func newiscsiDriver(root string) (*iscsiDriver, error) {
|
|||||||
return nil, util.LogError("%v already exist and it's not a directory", root)
|
return nil, util.LogError("%v already exist and it's not a directory", root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stateFolder := filepath.Join(root, "plugins", "docker-iscsi")
|
||||||
|
fi, err = os.Lstat(stateFolder)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
if err := os.MkdirAll(stateFolder, 0755); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi != nil && !fi.IsDir() {
|
||||||
|
return nil, util.LogError("%v already exist and it's not a directory", stateFolder)
|
||||||
|
}
|
||||||
|
|
||||||
d := &iscsiDriver{
|
d := &iscsiDriver{
|
||||||
root: filepath.Join(root, "volumes"),
|
root: filepath.Join(root, "volumes"),
|
||||||
statePath: filepath.Join(root, "plugins", "docker-iscsi", "iscsi-state.json"),
|
statePath: filepath.Join(stateFolder, "iscsi-state.json"),
|
||||||
volumes: map[string]*iscsiVolume{},
|
volumes: map[string]*iscsiVolume{},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,8 +147,10 @@ func (d *iscsiDriver) Remove(r *volume.RemoveRequest) error {
|
|||||||
if err := os.RemoveAll(v.Mountpoint); err != nil {
|
if err := os.RemoveAll(v.Mountpoint); err != nil {
|
||||||
return util.LogError(err.Error())
|
return util.LogError(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(d.volumes, r.Name)
|
delete(d.volumes, r.Name)
|
||||||
d.saveState()
|
d.saveState()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user