From a0ef9da39016ecf9849da57ad162f95726fad3a1 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 16 Jan 2020 14:35:21 +0100 Subject: [PATCH] rbd: only load nbd module if not available yet Signed-off-by: Niels de Vos --- pkg/rbd/rbd_attach.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/rbd/rbd_attach.go b/pkg/rbd/rbd_attach.go index c4d3759f0..84938312b 100644 --- a/pkg/rbd/rbd_attach.go +++ b/pkg/rbd/rbd_attach.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "os" "strconv" "strings" "time" @@ -153,10 +154,15 @@ func waitForPath(ctx context.Context, pool, image string, maxRetries int, useNbd // Check if rbd-nbd tools are installed. func checkRbdNbdTools() bool { - _, err := execCommand("modprobe", []string{moduleNbd}) - if err != nil { - klog.V(3).Infof("rbd-nbd: nbd modprobe failed with error %v", err) - return false + // check if the module is loaded or compiled in + _, err := os.Stat(fmt.Sprintf("/sys/module/%s", moduleNbd)) + if os.IsNotExist(err) { + // try to load the module + _, err = execCommand("modprobe", []string{moduleNbd}) + if err != nil { + klog.V(3).Infof("rbd-nbd: nbd modprobe failed with error %v", err) + return false + } } if _, err := execCommand(rbdTonbd, []string{"--version"}); err != nil { klog.V(3).Infof("rbd-nbd: running rbd-nbd --version failed with error %v", err)