Browse code

devmapper autoconfig: add mkdir

I tried using dm.directlvm_device but it ended up with the following
error:

> Error starting daemon: error initializing graphdriver: error
> writing docker thinp autoextend profile: open
> /etc/lvm/profile/docker-thinpool.profile: no such file or directory

The reason is /etc/lvm/profile directory does not exist. I think it is
better to try creating it beforehand.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2017/08/12 00:00:00
Showing 1 changed files
... ...
@@ -172,6 +172,8 @@ func writeLVMConfig(root string, cfg directLVMConfig) error {
172 172
 }
173 173
 
174 174
 func setupDirectLVM(cfg directLVMConfig) error {
175
+	lvmProfileDir := "/etc/lvm/profile"
176
+
175 177
 	pvCreate, err := exec.LookPath("pvcreate")
176 178
 	if err != nil {
177 179
 		return errors.Wrap(err, "error looking up command `pvcreate` while setting up direct lvm")
... ...
@@ -197,6 +199,11 @@ func setupDirectLVM(cfg directLVMConfig) error {
197 197
 		return errors.Wrap(err, "error looking up command `lvchange` while setting up direct lvm")
198 198
 	}
199 199
 
200
+	err = os.MkdirAll(lvmProfileDir, 0755)
201
+	if err != nil {
202
+		return errors.Wrap(err, "error creating lvm profile directory")
203
+	}
204
+
200 205
 	if cfg.AutoExtendPercent == 0 {
201 206
 		cfg.AutoExtendPercent = 20
202 207
 	}
... ...
@@ -237,7 +244,7 @@ func setupDirectLVM(cfg directLVMConfig) error {
237 237
 	}
238 238
 
239 239
 	profile := fmt.Sprintf("activation{\nthin_pool_autoextend_threshold=%d\nthin_pool_autoextend_percent=%d\n}", cfg.AutoExtendThreshold, cfg.AutoExtendPercent)
240
-	err = ioutil.WriteFile("/etc/lvm/profile/docker-thinpool.profile", []byte(profile), 0600)
240
+	err = ioutil.WriteFile(lvmProfileDir+"/docker-thinpool.profile", []byte(profile), 0600)
241 241
 	if err != nil {
242 242
 		return errors.Wrap(err, "error writing docker thinp autoextend profile")
243 243
 	}