Skip to content

Commit

Permalink
feat(proxy): support snapshot max count and size
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 authored and David Ko committed Jan 3, 2024
1 parent 3114405 commit e09a1a8
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
78 changes: 78 additions & 0 deletions pkg/client/proxy_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (c *ProxyClient) VolumeGet(dataEngine, engineName, volumeName, serviceAddre
LastExpansionError: resp.Volume.LastExpansionError,
LastExpansionFailedAt: resp.Volume.LastExpansionFailedAt,
UnmapMarkSnapChainRemoved: resp.Volume.UnmapMarkSnapChainRemoved,
SnapshotMaxCount: int(resp.Volume.SnapshotMaxCount),
SnapshotMaxSize: resp.Volume.SnapshotMaxSize,
}
return info, nil
}
Expand Down Expand Up @@ -214,3 +216,79 @@ func (c *ProxyClient) VolumeUnmapMarkSnapChainRemovedSet(dataEngine, engineName,

return nil
}

func (c *ProxyClient) VolumeSnapshotMaxCountSet(backendStoreDriver, engineName, volumeName,
serviceAddress string, count int) (err error) {
input := map[string]string{
"engineName": engineName,
"volumeName": volumeName,
"serviceAddress": serviceAddress,
"count": strconv.Itoa(count),
}
if err := validateProxyMethodParameters(input); err != nil {
return errors.Wrap(err, "failed to set volume flag SnapshotMaxCount")
}

driver, ok := rpc.BackendStoreDriver_value[backendStoreDriver]
if !ok {
return fmt.Errorf("failed to set volume flag SnapshotMaxCount: invalid backend store driver %v", backendStoreDriver)
}

defer func() {
err = errors.Wrapf(err, "%v failed to set SnapshotMaxCount", c.getProxyErrorPrefix(serviceAddress))
}()

req := &rpc.EngineVolumeSnapshotMaxCountSetRequest{
ProxyEngineRequest: &rpc.ProxyEngineRequest{
Address: serviceAddress,
EngineName: engineName,
BackendStoreDriver: rpc.BackendStoreDriver(driver),
VolumeName: volumeName,
},
Count: &eptypes.VolumeSnapshotMaxCountSetRequest{Count: int32(count)},
}
_, err = c.service.VolumeSnapshotMaxCountSet(getContextWithGRPCTimeout(c.ctx), req)
if err != nil {
return err
}

return nil
}

func (c *ProxyClient) VolumeSnapshotMaxSizeSet(backendStoreDriver, engineName, volumeName,
serviceAddress string, size int64) (err error) {
input := map[string]string{
"engineName": engineName,
"volumeName": volumeName,
"serviceAddress": serviceAddress,
"size": strconv.FormatInt(size, 10),
}
if err := validateProxyMethodParameters(input); err != nil {
return errors.Wrap(err, "failed to set volume flag SnapshotMaxSize")
}

driver, ok := rpc.BackendStoreDriver_value[backendStoreDriver]
if !ok {
return fmt.Errorf("failed to set volume flag SnapshotMaxSize: invalid backend store driver %v", backendStoreDriver)
}

defer func() {
err = errors.Wrapf(err, "%v failed to set SnapshotMaxSize", c.getProxyErrorPrefix(serviceAddress))
}()

req := &rpc.EngineVolumeSnapshotMaxSizeSetRequest{
ProxyEngineRequest: &rpc.ProxyEngineRequest{
Address: serviceAddress,
EngineName: engineName,
BackendStoreDriver: rpc.BackendStoreDriver(driver),
VolumeName: volumeName,
},
Size: &eptypes.VolumeSnapshotMaxSizeSetRequest{Size: size},
}
_, err = c.service.VolumeSnapshotMaxSizeSet(getContextWithGRPCTimeout(c.ctx), req)
if err != nil {
return err
}

return nil
}
82 changes: 82 additions & 0 deletions pkg/proxy/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (p *Proxy) volumeGet(ctx context.Context, req *rpc.ProxyEngineRequest) (res
LastExpansionError: recv.LastExpansionError,
LastExpansionFailedAt: recv.LastExpansionFailedAt,
UnmapMarkSnapChainRemoved: recv.UnmapMarkSnapChainRemoved,
SnapshotMaxCount: int32(recv.SnapshotMaxCount),
SnapshotMaxSize: recv.SnapshotMaxSize,
},
}, nil
}
Expand Down Expand Up @@ -247,3 +249,83 @@ func (p *Proxy) spdkVolumeUnmapMarkSnapChainRemovedSet(ctx context.Context, req
/* Not implemented */
return &emptypb.Empty{}, nil
}

func (p *Proxy) VolumeSnapshotMaxCountSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxCountSetRequest) (resp *emptypb.Empty, err error) {
log := logrus.WithFields(logrus.Fields{
"serviceURL": req.ProxyEngineRequest.Address,
"engineName": req.ProxyEngineRequest.EngineName,
"volumeName": req.ProxyEngineRequest.VolumeName,
"dataEngine": req.ProxyEngineRequest.DataEngine,
})
log.Infof("Setting volume flag SnapshotMaxCount to %v", req.Count.Count)

switch req.ProxyEngineRequest.DataEngine {
case rpc.DataEngine_DATA_ENGINE_V1:
return p.volumeSnapshotMaxCountSet(ctx, req)
case rpc.DataEngine_DATA_ENGINE_V2:
return p.spdkVolumeSnapshotMaxCountSet(ctx, req)
default:
return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "unknown data engine %v", req.ProxyEngineRequest.DataEngine)
}
}

func (p *Proxy) volumeSnapshotMaxCountSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxCountSetRequest) (resp *emptypb.Empty, err error) {
c, err := eclient.NewControllerClient(req.ProxyEngineRequest.Address, req.ProxyEngineRequest.VolumeName,
req.ProxyEngineRequest.EngineName)
if err != nil {
return nil, err
}
defer c.Close()

err = c.VolumeSnapshotMaxCountSet(int(req.Count.Count))
if err != nil {
return nil, err
}

return &emptypb.Empty{}, nil
}

func (p *Proxy) spdkVolumeSnapshotMaxCountSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxCountSetRequest) (resp *emptypb.Empty, err error) {
/* Not implemented */
return &emptypb.Empty{}, nil
}

func (p *Proxy) VolumeSnapshotMaxSizeSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxSizeSetRequest) (resp *emptypb.Empty, err error) {
log := logrus.WithFields(logrus.Fields{
"serviceURL": req.ProxyEngineRequest.Address,
"engineName": req.ProxyEngineRequest.EngineName,
"volumeName": req.ProxyEngineRequest.VolumeName,
"dataEngine": req.ProxyEngineRequest.DataEngine,
})
log.Infof("Setting volume flag SnapshotMaxSize to %v", req.Size.Size)

switch req.ProxyEngineRequest.DataEngine {
case rpc.DataEngine_DATA_ENGINE_V1:
return p.volumeSnapshotMaxSizeSet(ctx, req)
case rpc.DataEngine_DATA_ENGINE_V2:
return p.spdkVolumeSnapshotMaxSizeSet(ctx, req)
default:
return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "unknown data engine %v", req.ProxyEngineRequest.DataEngine)
}
}

func (p *Proxy) volumeSnapshotMaxSizeSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxSizeSetRequest) (resp *emptypb.Empty, err error) {
c, err := eclient.NewControllerClient(req.ProxyEngineRequest.Address, req.ProxyEngineRequest.VolumeName,
req.ProxyEngineRequest.EngineName)
if err != nil {
return nil, err
}
defer c.Close()

err = c.VolumeSnapshotMaxSizeSet(req.Size.Size)
if err != nil {
return nil, err
}

return &emptypb.Empty{}, nil
}

func (p *Proxy) spdkVolumeSnapshotMaxSizeSet(ctx context.Context, req *rpc.EngineVolumeSnapshotMaxSizeSetRequest) (resp *emptypb.Empty, err error) {
/* Not implemented */
return &emptypb.Empty{}, nil
}

0 comments on commit e09a1a8

Please sign in to comment.