From 9e76b7fdaaaa0d006acc185e4f76efc973fa1bba Mon Sep 17 00:00:00 2001 From: Travis Rhoden Date: Tue, 13 Jun 2017 11:47:46 -0700 Subject: [PATCH] Allow disabling of RBD modprobe When RBD driver is running in a container, using `modprobe` to check if the RBD module is already inserted is not apprpriate. Keep that behavior as the default, but add a config option to disable it that can be used for container deployments. --- .docs/user-guide/storage-providers.md | 5 +++++ drivers/storage/rbd/executor/rbd_executor.go | 12 ++++++++---- drivers/storage/rbd/rbd.go | 9 ++++++++- drivers/storage/rbd/storage/rbd_storage.go | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.docs/user-guide/storage-providers.md b/.docs/user-guide/storage-providers.md index 61f08017..eac82e0f 100644 --- a/.docs/user-guide/storage-providers.md +++ b/.docs/user-guide/storage-providers.md @@ -411,6 +411,7 @@ example see the [Examples](./storage-providers.md#ceph-rbd-examples) section. ```yaml rbd: defaultPool: rbd + testModule: true ``` ##### Configuration Notes @@ -418,6 +419,10 @@ rbd: * The `defaultPool` parameter is optional, and defaults to "rbd". When set, all volume requests that do not reference a specific pool will use the `defaultPool` value as the destination storage pool. +* The `testModule` parameter is optional, and defaults to "true". This setting + indicates whether the libStorage client should test if the `rbd` kernel module + is loaded, with the side-effect of loading it if is not already loaded. This + setting should be disabled when the driver is executing inside of a container. #### Runtime behavior diff --git a/drivers/storage/rbd/executor/rbd_executor.go b/drivers/storage/rbd/executor/rbd_executor.go index a3a8998c..2962b5fc 100644 --- a/drivers/storage/rbd/executor/rbd_executor.go +++ b/drivers/storage/rbd/executor/rbd_executor.go @@ -21,7 +21,8 @@ import ( ) type driver struct { - config gofig.Config + config gofig.Config + doModprobe bool } func init() { @@ -34,6 +35,7 @@ func newdriver() types.StorageExecutor { func (d *driver) Init(context types.Context, config gofig.Config) error { d.config = config + d.doModprobe = config.GetBool(rbd.ConfigTestModule) return nil } @@ -57,9 +59,11 @@ func (d *driver) Supported( return false, nil } - cmd := exec.Command("modprobe", "rbd") - if _, _, err := utils.RunCommand(ctx, cmd); err != nil { - return false, nil + if d.doModprobe { + cmd := exec.Command("modprobe", "rbd") + if _, _, err := utils.RunCommand(ctx, cmd); err != nil { + return false, nil + } } return true, nil diff --git a/drivers/storage/rbd/rbd.go b/drivers/storage/rbd/rbd.go index eb6621ec..1d0d37d2 100644 --- a/drivers/storage/rbd/rbd.go +++ b/drivers/storage/rbd/rbd.go @@ -10,6 +10,12 @@ import ( const ( // Name is the name of the storage driver Name = "rbd" + + // ConfigDefaultPool is the config key for default pool + ConfigDefaultPool = Name + ".defaultPool" + + // ConfigTestModule is the config key for testing kernel module presence + ConfigTestModule = Name + ".testModule" ) func init() { @@ -18,6 +24,7 @@ func init() { func registerConfig() { r := gofigCore.NewRegistration("RBD") - r.Key(gofig.String, "", "rbd", "", "rbd.defaultPool") + r.Key(gofig.String, "", "rbd", "", ConfigDefaultPool) + r.Key(gofig.Bool, "", true, "", ConfigTestModule) gofigCore.Register(r) } diff --git a/drivers/storage/rbd/storage/rbd_storage.go b/drivers/storage/rbd/storage/rbd_storage.go index e85dc34e..a4e4f15a 100644 --- a/drivers/storage/rbd/storage/rbd_storage.go +++ b/drivers/storage/rbd/storage/rbd_storage.go @@ -370,7 +370,7 @@ func (d *driver) SnapshotRemove( } func (d *driver) defaultPool() string { - return d.config.GetString("rbd.defaultPool") + return d.config.GetString(rbd.ConfigDefaultPool) } func (d *driver) toTypeVolumes(