From 46378f3bfc6e60e6e4d6dc06b93ce7d4b4db8423 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 14 Feb 2022 16:48:31 +0530 Subject: [PATCH] rbd: log stderror when running modprobe logging the error is not user-friendly and it contains system error message. Log the stderr which is user-friendly error message for identifying the problem. Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_attach.go | 5 +++-- internal/rbd/rbd_util.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/rbd/rbd_attach.go b/internal/rbd/rbd_attach.go index d84dd071a..60fce5bbe 100644 --- a/internal/rbd/rbd_attach.go +++ b/internal/rbd/rbd_attach.go @@ -199,14 +199,15 @@ func waitForPath(ctx context.Context, pool, namespace, image string, maxRetries // set features available with rbd-nbd, and NBD module loaded status. func setRbdNbdToolFeatures() { + var stderr string // 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 = util.ExecCommand(context.TODO(), "modprobe", moduleNbd) + _, stderr, err = util.ExecCommand(context.TODO(), "modprobe", moduleNbd) if err != nil { hasNBD = false - log.WarningLogMsg("rbd-nbd: nbd modprobe failed with error %v", err) + log.WarningLogMsg("rbd-nbd: nbd modprobe failed (%v): %q", err, stderr) } } diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 7dcd39155..71eb98685 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -214,6 +214,7 @@ var supportedFeatures = map[string]imageFeature{ // GetKrbdSupportedFeatures load the module if needed and return supported // features attribute as a string. func GetKrbdSupportedFeatures() (string, error) { + var stderr string // check if the module is loaded or compiled in _, err := os.Stat(krbdSupportedFeaturesFile) if err != nil { @@ -223,9 +224,9 @@ func GetKrbdSupportedFeatures() (string, error) { return "", err } // try to load the module - _, _, err = util.ExecCommand(context.TODO(), "modprobe", rbdDefaultMounter) + _, stderr, err = util.ExecCommand(context.TODO(), "modprobe", rbdDefaultMounter) if err != nil { - log.ErrorLogMsg("modprobe failed: %v", err) + log.ErrorLogMsg("modprobe failed (%v): %q", err, stderr) return "", err }