Browse code

Fix issue reloading mount options on restart

On daemon restart the local volume driver will read options that it
persisted to disk, however it was reading an incorrect path, causing
volume options to be silently ignored after a daemon restart.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2016/08/02 12:02:51
Showing 2 changed files
... ...
@@ -88,7 +88,9 @@ func New(scope string, rootUID, rootGID int) (*Root, error) {
88 88
 			path:       r.DataPath(name),
89 89
 		}
90 90
 		r.volumes[name] = v
91
-		if b, err := ioutil.ReadFile(filepath.Join(name, "opts.json")); err == nil {
91
+		optsFilePath := filepath.Join(rootDirectory, name, "opts.json")
92
+		if b, err := ioutil.ReadFile(optsFilePath); err == nil {
93
+			v.opts = &optsConfig{}
92 94
 			if err := json.Unmarshal(b, v.opts); err != nil {
93 95
 				return nil, err
94 96
 			}
... ...
@@ -3,6 +3,7 @@ package local
3 3
 import (
4 4
 	"io/ioutil"
5 5
 	"os"
6
+	"reflect"
6 7
 	"runtime"
7 8
 	"strings"
8 9
 	"testing"
... ...
@@ -246,4 +247,18 @@ func TestCreateWithOpts(t *testing.T) {
246 246
 	if !mounted {
247 247
 		t.Fatal("expected mount to still be active")
248 248
 	}
249
+
250
+	r, err = New(rootDir, 0, 0)
251
+	if err != nil {
252
+		t.Fatal(err)
253
+	}
254
+
255
+	v2, exists := r.volumes["test"]
256
+	if !exists {
257
+		t.Fatal("missing volume on restart")
258
+	}
259
+
260
+	if !reflect.DeepEqual(v.opts, v2.opts) {
261
+		t.Fatal("missing volume options on restart")
262
+	}
249 263
 }