Skip to content

Commit

Permalink
disk: support different drivers
Browse files Browse the repository at this point in the history
Longhorn 7672

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Feb 20, 2024
1 parent 75a972a commit f51e9b5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
2 changes: 2 additions & 0 deletions pkg/api/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package api

type DiskInfo struct {
ID string
Name string
UUID string
Path string
Type string
Driver string
TotalSize int64
FreeSize int64
TotalBlocks int64
Expand Down
50 changes: 30 additions & 20 deletions pkg/client/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewDiskServiceClientWithTLS(ctx context.Context, ctxCancel context.CancelFu

// DiskCreate creates a disk with the given name and path.
// diskUUID is optional, if not provided, it indicates the disk is newly added.
func (c *DiskServiceClient) DiskCreate(diskType, diskName, diskUUID, diskPath string, blockSize int64) (*api.DiskInfo, error) {
func (c *DiskServiceClient) DiskCreate(diskType, diskName, diskUUID, diskPath, diskDriver string, blockSize int64) (*api.DiskInfo, error) {
if diskName == "" || diskPath == "" {
return nil, fmt.Errorf("failed to create disk: missing required parameters")
}
Expand All @@ -100,21 +100,24 @@ func (c *DiskServiceClient) DiskCreate(diskType, diskName, diskUUID, diskPath st
defer cancel()

resp, err := client.DiskCreate(ctx, &rpc.DiskCreateRequest{
DiskType: rpc.DiskType(t),
DiskName: diskName,
DiskUuid: diskUUID,
DiskPath: diskPath,
BlockSize: blockSize,
DiskType: rpc.DiskType(t),
DiskName: diskName,
DiskUuid: diskUUID,
DiskPath: diskPath,
BlockSize: blockSize,
DiskDriver: diskDriver,
})
if err != nil {
return nil, err
}

return &api.DiskInfo{
ID: resp.GetId(),
Name: resp.GetName(),
UUID: resp.GetUuid(),
Path: resp.GetPath(),
Type: resp.GetType(),
Driver: resp.GetDriver(),
TotalSize: resp.GetTotalSize(),
FreeSize: resp.GetFreeSize(),
TotalBlocks: resp.GetTotalBlocks(),
Expand All @@ -125,9 +128,9 @@ func (c *DiskServiceClient) DiskCreate(diskType, diskName, diskUUID, diskPath st
}

// DiskGet returns the disk info with the given name and path.
func (c *DiskServiceClient) DiskGet(diskType, diskName, diskPath string) (*api.DiskInfo, error) {
func (c *DiskServiceClient) DiskGet(diskType, diskName, diskPath, diskDriver string) (*api.DiskInfo, error) {
if diskName == "" {
return nil, fmt.Errorf("failed to get disk info: missing required parameter")
return nil, fmt.Errorf("failed to get disk info: missing required parameter diskName")
}

t, ok := rpc.DiskType_value[diskType]
Expand All @@ -140,19 +143,22 @@ func (c *DiskServiceClient) DiskGet(diskType, diskName, diskPath string) (*api.D
defer cancel()

resp, err := client.DiskGet(ctx, &rpc.DiskGetRequest{
DiskType: rpc.DiskType(t),
DiskName: diskName,
DiskPath: diskPath,
DiskType: rpc.DiskType(t),
DiskName: diskName,
DiskPath: diskPath,
DiskDriver: diskDriver,
})
if err != nil {
return nil, err
}

return &api.DiskInfo{
ID: resp.GetId(),
Name: resp.GetName(),
UUID: resp.GetUuid(),
Path: resp.GetPath(),
Type: resp.GetType(),
Driver: resp.GetDriver(),
TotalSize: resp.GetTotalSize(),
FreeSize: resp.GetFreeSize(),
TotalBlocks: resp.GetTotalBlocks(),
Expand All @@ -162,8 +168,8 @@ func (c *DiskServiceClient) DiskGet(diskType, diskName, diskPath string) (*api.D
}, nil
}

// DiskDelete deletes the disk with the given name and uuid.
func (c *DiskServiceClient) DiskDelete(diskType, diskName, diskUUID string) error {
// DiskDelete deletes the disk with the given name, uuid and path and driver.
func (c *DiskServiceClient) DiskDelete(diskType, diskName, diskUUID, diskPath, diskDriver string) error {
if diskName == "" || diskUUID == "" {
return fmt.Errorf("failed to delete disk: missing required parameters")
}
Expand All @@ -173,14 +179,16 @@ func (c *DiskServiceClient) DiskDelete(diskType, diskName, diskUUID string) erro
defer cancel()

_, err := client.DiskDelete(ctx, &rpc.DiskDeleteRequest{
DiskType: rpc.DiskType(rpc.DiskType_value[diskType]),
DiskName: diskName,
DiskUuid: diskUUID,
DiskType: rpc.DiskType(rpc.DiskType_value[diskType]),
DiskName: diskName,
DiskUuid: diskUUID,
DiskPath: diskPath,
DiskDriver: diskDriver,
})
return err
}

func (c *DiskServiceClient) DiskReplicaInstanceList(diskType, diskName string) (map[string]*api.ReplicaStorageInstance, error) {
func (c *DiskServiceClient) DiskReplicaInstanceList(diskType, diskName, diskDriver string) (map[string]*api.ReplicaStorageInstance, error) {
if diskName == "" {
return nil, fmt.Errorf("failed to list replica instances on disk: missing required parameter")
}
Expand All @@ -190,8 +198,9 @@ func (c *DiskServiceClient) DiskReplicaInstanceList(diskType, diskName string) (
defer cancel()

resp, err := client.DiskReplicaInstanceList(ctx, &rpc.DiskReplicaInstanceListRequest{
DiskType: rpc.DiskType(rpc.DiskType_value[diskType]),
DiskName: diskName,
DiskType: rpc.DiskType(rpc.DiskType_value[diskType]),
DiskName: diskName,
DiskDriver: diskDriver,
})
if err != nil {
return nil, err
Expand All @@ -213,7 +222,7 @@ func (c *DiskServiceClient) DiskReplicaInstanceList(diskType, diskName string) (
}

// DiskReplicaInstanceDelete deletes the replica instance with the given name on the disk.
func (c *DiskServiceClient) DiskReplicaInstanceDelete(diskType, diskName, diskUUID, replciaInstanceName string) error {
func (c *DiskServiceClient) DiskReplicaInstanceDelete(diskType, diskName, diskUUID, diskDriver, replciaInstanceName string) error {
if diskName == "" || diskUUID == "" || replciaInstanceName == "" {
return fmt.Errorf("failed to delete replica instance on disk: missing required parameters")
}
Expand All @@ -226,6 +235,7 @@ func (c *DiskServiceClient) DiskReplicaInstanceDelete(diskType, diskName, diskUU
DiskType: rpc.DiskType(rpc.DiskType_value[diskType]),
DiskName: diskName,
DiskUuid: diskUUID,
DiskDriver: diskDriver,
ReplciaInstanceName: replciaInstanceName,
})

Expand Down
24 changes: 15 additions & 9 deletions pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ func (s *Server) VersionGet(ctx context.Context, req *emptypb.Empty) (*rpc.DiskV

func (s *Server) DiskCreate(ctx context.Context, req *rpc.DiskCreateRequest) (*rpc.Disk, error) {
log := logrus.WithFields(logrus.Fields{
"diskType": req.DiskType,
"diskName": req.DiskName,
"diskPath": req.DiskPath,
"blockSize": req.BlockSize,
"diskType": req.DiskType,
"diskName": req.DiskName,
"diskPath": req.DiskPath,
"blockSize": req.BlockSize,
"diskDriver": req.DiskDriver,
})

log.Info("Disk Server: Creating disk")
Expand All @@ -135,7 +136,7 @@ func (ops FilesystemDiskOps) DiskCreate(ctx context.Context, req *rpc.DiskCreate
}

func (ops BlockDiskOps) DiskCreate(ctx context.Context, req *rpc.DiskCreateRequest) (*rpc.Disk, error) {
ret, err := ops.spdkClient.DiskCreate(req.DiskName, req.DiskUuid, req.DiskPath, req.BlockSize)
ret, err := ops.spdkClient.DiskCreate(req.DiskName, req.DiskUuid, req.DiskPath, req.DiskDriver, req.BlockSize)
if err != nil {
return nil, grpcstatus.Error(grpccodes.Internal, err.Error())
}
Expand All @@ -144,8 +145,11 @@ func (ops BlockDiskOps) DiskCreate(ctx context.Context, req *rpc.DiskCreateReque

func (s *Server) DiskDelete(ctx context.Context, req *rpc.DiskDeleteRequest) (*emptypb.Empty, error) {
log := logrus.WithFields(logrus.Fields{
"diskName": req.DiskName,
"diskUUID": req.DiskUuid,
"diskType": req.DiskType,
"diskName": req.DiskName,
"diskUUID": req.DiskUuid,
"diskPath": req.DiskPath,
"diskDriver": req.DiskDriver,
})

log.Info("Disk Server: Deleting disk")
Expand All @@ -166,7 +170,7 @@ func (ops FilesystemDiskOps) DiskDelete(req *rpc.DiskDeleteRequest) (*emptypb.Em
}

func (ops BlockDiskOps) DiskDelete(req *rpc.DiskDeleteRequest) (*emptypb.Empty, error) {
return &emptypb.Empty{}, ops.spdkClient.DiskDelete(req.DiskName, req.DiskUuid)
return &emptypb.Empty{}, ops.spdkClient.DiskDelete(req.DiskName, req.DiskUuid, req.DiskPath, req.DiskDriver)
}

func (s *Server) DiskGet(ctx context.Context, req *rpc.DiskGetRequest) (*rpc.Disk, error) {
Expand Down Expand Up @@ -194,7 +198,7 @@ func (ops FilesystemDiskOps) DiskGet(req *rpc.DiskGetRequest) (*rpc.Disk, error)
}

func (ops BlockDiskOps) DiskGet(req *rpc.DiskGetRequest) (*rpc.Disk, error) {
ret, err := ops.spdkClient.DiskGet(req.DiskName)
ret, err := ops.spdkClient.DiskGet(req.DiskName, req.DiskPath, req.DiskDriver)
if err != nil {
return nil, grpcstatus.Error(grpccodes.Internal, err.Error())
}
Expand Down Expand Up @@ -274,9 +278,11 @@ func (ops BlockDiskOps) DiskReplicaInstanceDelete(req *rpc.DiskReplicaInstanceDe
func spdkDiskToDisk(disk *spdkrpc.Disk) *rpc.Disk {
return &rpc.Disk{
Id: disk.Id,
Name: disk.Name,
Uuid: disk.Uuid,
Path: disk.Path,
Type: disk.Type,
Driver: disk.Driver,
TotalSize: disk.TotalSize,
FreeSize: disk.FreeSize,
TotalBlocks: disk.TotalBlocks,
Expand Down

0 comments on commit f51e9b5

Please sign in to comment.