Skip to content

Commit

Permalink
Add 1 minute timeout for the luks commands
Browse files Browse the repository at this point in the history
Generally an operation should only take a 1 second, but just in case we
add a 1 minute timeout to each cryptsetup invocation, if the timeout is
reached the share-manager will end up failing early instead of sticking
around. This allows for rescheduling and teardown / tear up.

Longhorn #2867

Signed-off-by: Joshua Moody <joshua.moody@suse.com>
  • Loading branch information
joshimoo authored and innobead committed Aug 20, 2021
1 parent 0c5e4e8 commit 3dc851c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/crypto/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package crypto

import (
"bytes"
"context"
"fmt"
"os/exec"
"path/filepath"
"strings"
"time"

iscsi_util "github.com/longhorn/go-iscsi-helper/util"
)

const HostProcPath = "/host/proc"
const hostProcPath = "/host/proc"
const luksTimeout = time.Minute

func luksOpen(volume, devicePath, passphrase string) (stdout string, err error) {
return cryptSetupWithPassphrase(passphrase,
Expand Down Expand Up @@ -43,10 +46,12 @@ func cryptSetup(args ...string) (stdout string, err error) {
func cryptSetupWithPassphrase(passphrase string, args ...string) (stdout string, err error) {
// NOTE: cryptsetup needs to be run in the host IPC/MNT
// if you only use MNT the binary will not return but still do the appropriate action.
ns := iscsi_util.GetHostNamespacePath(HostProcPath)
// ns := fmt.Sprintf("%s/%d/ns/", HostProcPath, 1)
ns := iscsi_util.GetHostNamespacePath(hostProcPath)
// ns := fmt.Sprintf("%s/%d/ns/", hostProcPath, 1)
nsArgs := prepareCommandArgs(ns, "cryptsetup", args)
cmd := exec.Command("nsenter", nsArgs...)
ctx, cancel := context.WithTimeout(context.TODO(), luksTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, "nsenter", nsArgs...)

var stdoutBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
Expand Down

0 comments on commit 3dc851c

Please sign in to comment.