Skip to content

Commit

Permalink
rwx: remount and reexport volume if share manager is in running state
Browse files Browse the repository at this point in the history
Longhorn 7106

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and David Ko committed Nov 15, 2023
1 parent bc3bf0e commit 83d3435
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,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 (c *ShareManagerController) detachShareManagerVolume(sm *longhorn.ShareManager, va *longhorn.VolumeAttachment) {
log := getLoggerForShareManager(c.logger, sm)

Expand Down Expand Up @@ -516,7 +541,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
Expand Down
4 changes: 4 additions & 0 deletions engineapi/share_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 83d3435

Please sign in to comment.