From e09a1a821a26518c02833763d623e89936e7d9f5 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Wed, 3 Jan 2024 19:41:43 +0800 Subject: [PATCH] feat(proxy): support snapshot max count and size Signed-off-by: PoAn Yang --- pkg/client/proxy_volume.go | 78 ++++++++++++++++++++++++++++++++++++ pkg/proxy/volume.go | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/pkg/client/proxy_volume.go b/pkg/client/proxy_volume.go index 0f8a878b8..36b06e5f9 100644 --- a/pkg/client/proxy_volume.go +++ b/pkg/client/proxy_volume.go @@ -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 } @@ -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 +} diff --git a/pkg/proxy/volume.go b/pkg/proxy/volume.go index 8002d4611..b08ad0004 100644 --- a/pkg/proxy/volume.go +++ b/pkg/proxy/volume.go @@ -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 } @@ -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 +}