From 5f30ee20425312d85bd30dd2f1615ea81e27115b Mon Sep 17 00:00:00 2001 From: Derek Su Date: Wed, 15 Nov 2023 14:43:15 +0800 Subject: [PATCH] rwx: remount and reexport volume if share manager is in running state Longhorn 7106 Signed-off-by: Derek Su (cherry picked from commit 83d343567f137987f00e04cbc6261c92a2f84a51) --- controller/share_manager_controller.go | 27 +++++++++++++++++++++++++- engineapi/share_manager.go | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/controller/share_manager_controller.go b/controller/share_manager_controller.go index 13d50913a0..c1927778bc 100644 --- a/controller/share_manager_controller.go +++ b/controller/share_manager_controller.go @@ -432,6 +432,31 @@ func (c *ShareManagerController) unmountShareManagerVolume(sm *longhorn.ShareMan } } +// mountShareManagerVolume checks, exports and mounts the volume in the share manager pod. +func (c *ShareManagerController) mountShareManagerVolume(sm *longhorn.ShareManager) error { + podName := types.GetShareManagerPodNameFromShareManagerName(sm.Name) + pod, err := c.ds.GetPod(podName) + if err != nil && !apierrors.IsNotFound(err) { + return errors.Wrapf(err, "failed to retrieve pod %v for share manager from datastore", podName) + } + + if pod == nil { + return fmt.Errorf("pod %v for share manager not found", podName) + } + + client, err := engineapi.NewShareManagerClient(sm, pod) + if err != nil { + return errors.Wrapf(err, "failed to create share manager client for pod %v", podName) + } + defer client.Close() + + if err := client.Mount(); err != nil { + return errors.Wrapf(err, "failed to mount share manager pod %v", podName) + } + + return nil +} + func hasActiveWorkload(vol *longhorn.Volume) bool { if vol == nil { return false @@ -500,7 +525,7 @@ func (c *ShareManagerController) syncShareManagerVolume(sm *longhorn.ShareManage } return nil } else if sm.Status.State == longhorn.ShareManagerStateRunning { - return nil + return c.mountShareManagerVolume(sm) } // in a single node cluster, there is no other manager that can claim ownership so we are prevented from creation diff --git a/engineapi/share_manager.go b/engineapi/share_manager.go index bc8644d4bf..4fbecb95ac 100644 --- a/engineapi/share_manager.go +++ b/engineapi/share_manager.go @@ -42,3 +42,7 @@ func (c *ShareManagerClient) FilesystemTrim(encryptedDevice bool) error { func (c *ShareManagerClient) Unmount() error { return c.grpcClient.Unmount() } + +func (c *ShareManagerClient) Mount() error { + return c.grpcClient.Mount() +}