Skip to content

Commit

Permalink
Added ublk frontend target
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampadais committed Nov 30, 2023
1 parent 81dc171 commit 22dd8cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
11 changes: 9 additions & 2 deletions app/cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func ControllerCmd() cli.Command {
Value: 5,
Usage: "HTTP client timeout for replica file sync server",
},
cli.IntFlag{
Name: "frontend-queues",
Required: false,
Value: 1,
Usage: "Number of frontend queues , only available in ublk frontend",
},
},
Action: func(c *cli.Context) {
if err := startController(c); err != nil {
Expand Down Expand Up @@ -114,6 +120,7 @@ func startController(c *cli.Context) error {
dataServerProtocol := c.String("data-server-protocol")
fileSyncHTTPClientTimeout := c.Int("file-sync-http-client-timeout")
engineInstanceName := c.GlobalString("engine-instance-name")
frontendQueues := c.Int("frontend-queues")

size := c.String("size")
if size == "" {
Expand Down Expand Up @@ -152,7 +159,7 @@ func startController(c *cli.Context) error {

var frontend types.Frontend
if frontendName != "" {
f, err := controller.NewFrontend(frontendName, iscsiTargetRequestTimeout)
f, err := controller.NewFrontend(frontendName, iscsiTargetRequestTimeout, frontendQueues)
if err != nil {
return errors.Wrapf(err, "failed to find frontend: %s", frontendName)
}
Expand All @@ -163,7 +170,7 @@ func startController(c *cli.Context) error {
volumeName, iscsiTargetRequestTimeout, engineReplicaTimeout)
control := controller.NewController(volumeName, dynamic.New(factories), frontend, isUpgrade, disableRevCounter, salvageRequested,
unmapMarkSnapChainRemoved, iscsiTargetRequestTimeout, engineReplicaTimeout, types.DataServerProtocol(dataServerProtocol),
fileSyncHTTPClientTimeout)
fileSyncHTTPClientTimeout, frontendQueues)

// need to wait for Shutdown() completion
control.ShutdownWG.Add(1)
Expand Down
21 changes: 5 additions & 16 deletions pkg/controller/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Controller struct {
lastExpansionError string

fileSyncHTTPClientTimeout int

frontendQueues int
}

const (
Expand All @@ -67,7 +69,7 @@ const (
)

func NewController(name string, factory types.BackendFactory, frontend types.Frontend, isUpgrade, disableRevCounter, salvageRequested, unmapMarkSnapChainRemoved bool,
iscsiTargetRequestTimeout, engineReplicaTimeout time.Duration, dataServerProtocol types.DataServerProtocol, fileSyncHTTPClientTimeout int) *Controller {
iscsiTargetRequestTimeout, engineReplicaTimeout time.Duration, dataServerProtocol types.DataServerProtocol, fileSyncHTTPClientTimeout int, frontendQueues int) *Controller {
c := &Controller{
factory: factory,
VolumeName: name,
Expand All @@ -85,6 +87,7 @@ func NewController(name string, factory types.BackendFactory, frontend types.Fro
DataServerProtocol: dataServerProtocol,

fileSyncHTTPClientTimeout: fileSyncHTTPClientTimeout,
frontendQueues: frontendQueues,
}
c.reset()
c.metricsStart()
Expand Down Expand Up @@ -484,7 +487,7 @@ func (c *Controller) StartFrontend(frontend string) error {
}
}

f, err := NewFrontend(frontend, c.iscsiTargetRequestTimeout)
f, err := NewFrontend(frontend, c.iscsiTargetRequestTimeout, c.frontendQueues)
if err != nil {
return errors.Wrapf(err, "failed to find frontend: %s", frontend)
}
Expand Down Expand Up @@ -737,20 +740,6 @@ func (c *Controller) Start(volumeSize, volumeCurrentSize int64, addresses ...str
continue
}

// If the instance manager crashes during the execution of [this code block](https://github.com/longhorn/longhorn-engine/blob/v1.5.1/pkg/sync/sync.go#L435-L446)
// the volume.meta file will be left with `Rebuilding` set to true. If Longhorn subsequently updates the replica
// as healthy, then the old replica will be removed. In scenarios involving multiple replicas, Longhorn will
// remove the replica with illegal values, thereby allowing rebuilding from other healthy replicas. However, in
// the case of single replicas, we cannot employ the same strategy.
// As a result, we will make a best-effort attempt to reset the `Rebuilding` flag for single replica cases.
// Ref: https://github.com/longhorn/longhorn/issues/6626
if len(addresses) == 1 {
err = newBackend.ResetRebuild()
if err != nil {
logrus.WithError(err).Warnf("Failed to reset invalid rebuild for backend with address %v", address)
}
}

newSize, err := newBackend.Size()
if err != nil {
if strings.Contains(err.Error(), "rpc error: code = Unavailable") {
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/init_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/longhorn/longhorn-engine/pkg/frontend/rest"
"github.com/longhorn/longhorn-engine/pkg/frontend/socket"
"github.com/longhorn/longhorn-engine/pkg/frontend/tgt"
"github.com/longhorn/longhorn-engine/pkg/frontend/ublk"
"github.com/longhorn/longhorn-engine/pkg/types"
"github.com/sirupsen/logrus"
)
Expand All @@ -21,7 +22,7 @@ const (
maxEngineReplicaTimeout = 30 * time.Second
)

func NewFrontend(frontendType string, iscsiTargetRequestTimeout time.Duration) (types.Frontend, error) {
func NewFrontend(frontendType string, iscsiTargetRequestTimeout time.Duration, frontendQueues int) (types.Frontend, error) {
switch frontendType {
case "rest":
return rest.New(), nil
Expand All @@ -31,6 +32,8 @@ func NewFrontend(frontendType string, iscsiTargetRequestTimeout time.Duration) (
return tgt.New(devtypes.FrontendTGTBlockDev, defaultScsiTimeout, defaultIscsiAbortTimeout, iscsiTargetRequestTimeout), nil
case devtypes.FrontendTGTISCSI:
return tgt.New(devtypes.FrontendTGTISCSI, defaultScsiTimeout, defaultIscsiAbortTimeout, iscsiTargetRequestTimeout), nil
case "ublk":
return ublk.New(frontendQueues), nil
default:
return nil, fmt.Errorf("unsupported frontend type: %v", frontendType)
}
Expand Down

0 comments on commit 22dd8cb

Please sign in to comment.