Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fsFreeze field to VolumeSnapshot #477

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import (
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/reflection"
"k8s.io/mount-utils"

commonTypes "github.com/longhorn/go-common-libs/types"
helpernvme "github.com/longhorn/go-spdk-helper/pkg/nvme"
helpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
helperutil "github.com/longhorn/go-spdk-helper/pkg/util"
engineutil "github.com/longhorn/longhorn-engine/pkg/util"
spdk "github.com/longhorn/longhorn-spdk-engine/pkg/spdk"
spdkutil "github.com/longhorn/longhorn-spdk-engine/pkg/util"
rpc "github.com/longhorn/types/pkg/generated/imrpc"
Expand Down Expand Up @@ -159,6 +161,34 @@ func cleanupStaledNvmeAndDmDevices() error {
return nil
}

func unfreezeFilesystems() error {
// We do not need to switch to the host mount namespace to get mount points here. Usually, longhorn-engine runs in a
// container that has / bind mounted to /host with at least HostToContainer (rslave) propagation.
// - If it does not, we likely can't do a namespace swap anyway, since we don't have access to /host/proc.
// - If it does, we just need to know where in the container we can access the mount points to unfreeze the file
// system.
mounter := mount.New("")
mountPoints, err := mounter.List()
if err != nil {
return errors.Wrap(err, "failed to list mount points while starting up")
}

for _, mountPoint := range mountPoints {
if strings.Contains(mountPoint.Device, engineutil.DevicePathPrefix) {
// We do not actually expect any filesystems to be frozen. This is a best effort attempt to unfreeze them
// if somehow instance manager crashed at the wrong moment during a snapshot.
unfroze, err := engineutil.UnfreezeFilesystem(mountPoint.Path, nil)
if err != nil {
logrus.WithError(err).Warnf("Failed to unfreeze filesystem mounted at %v", mountPoint)
}
if unfroze {
logrus.Warnf("Unfroze filesystem mounted at %v", mountPoint)
}
}
}
return nil
}

func start(c *cli.Context) (err error) {
listen := c.String("listen")
logsDir := c.String("logs-dir")
Expand All @@ -183,6 +213,10 @@ func start(c *cli.Context) (err error) {
if err := cleanupStaledNvmeAndDmDevices(); err != nil {
return err
}
} else {
if err := unfreezeFilesystems(); err != nil {
return err
}
shuo-wu marked this conversation as resolved.
Show resolved Hide resolved
}

// setup tls config
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/longhorn/backupstore v0.0.0-20240509144945-3bce6e69af15
github.com/longhorn/go-common-libs v0.0.0-20240514074907-351459694cbf
github.com/longhorn/go-spdk-helper v0.0.0-20240514082311-4069f4804017
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240509154612-5fdc92a2d526
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240514224711-e39b7f0313b2
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240516014845-759dfa872eae
github.com/longhorn/types v0.0.0-20240510221052-ab949bbedea3
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -43,6 +43,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/longhorn/go-iscsi-helper v0.0.0-20240427164656-e9439c0018ce // indirect
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 // indirect
github.com/longhorn/sparse-tools v0.0.0-20240427164751-a7b9f1b2c8a8 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ github.com/longhorn/backupstore v0.0.0-20240509144945-3bce6e69af15 h1:D838/RWPKm
github.com/longhorn/backupstore v0.0.0-20240509144945-3bce6e69af15/go.mod h1:n210xpMUVrSn/W4Za/9BZhyXLCTVfAOq5lNdLrRSyz8=
github.com/longhorn/go-common-libs v0.0.0-20240514074907-351459694cbf h1:3mjybe5dP3uJF2daMVv/U/IGNcp1dsrzHl4b6w8icPU=
github.com/longhorn/go-common-libs v0.0.0-20240514074907-351459694cbf/go.mod h1:gFXUEciTv/03ncyA8CNrfVkbikvSWNqCYwwsTC3lFGg=
github.com/longhorn/go-iscsi-helper v0.0.0-20240427164656-e9439c0018ce h1:PxKniE9F6IZ2DMKfmxDsbqeAxQI1TZhnw7/HOBMs1Is=
github.com/longhorn/go-iscsi-helper v0.0.0-20240427164656-e9439c0018ce/go.mod h1:d9t3gtE+UPjescbCFluXd4xBc8OQT/JrC2cdkk2IXWQ=
github.com/longhorn/go-spdk-helper v0.0.0-20240514082311-4069f4804017 h1:Cl8mEO7uP2T9ZDbqV3BK2xhrBVyjelY0WV9LDGdqb/Y=
github.com/longhorn/go-spdk-helper v0.0.0-20240514082311-4069f4804017/go.mod h1:SgKStbsHMJqVjf/uDpS7KYQakOp2jHBRSbRnMk6iNqo=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240509154612-5fdc92a2d526 h1:JvSWv3PBV89p6TsM2DQhkm/FB4L95U9l2nrPomzT9KA=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240509154612-5fdc92a2d526/go.mod h1:SvLrPprzk/iXFG3G4wDbWXD1kePlxg12Oui96FLBHAg=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240514224711-e39b7f0313b2 h1:mG7wUWZrJ5arEZWaghm73ywH09LUZo77kGUaHN7nzyg=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240514224711-e39b7f0313b2/go.mod h1:G+iGNlJm1RKuKXqz4Igh0b5miiRblld2C9GL9hs4ROk=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240516014845-759dfa872eae h1:07uvZWinlp6Zwvuhacv9Lv3NzRM46UKPu0xIAXP7VEA=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240516014845-759dfa872eae/go.mod h1:i8arwLcEawuN9rdHmo3doVhg9fQFPh0q+GJaKR2FOxk=
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 h1:Jw9uANsGcHTxp6HcC++/vN17LfeuDmozHI2j6DoZf5E=
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/proxy_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (c *ProxyClient) VolumeSnapshot(dataEngine, engineName, volumeName, serviceAddress,
volumeSnapshotName string, labels map[string]string) (snapshotName string, err error) {
volumeSnapshotName string, labels map[string]string, freezeFilesystem bool) (snapshotName string, err error) {
input := map[string]string{
"engineName": engineName,
"volumeName": volumeName,
Expand Down Expand Up @@ -55,8 +55,9 @@ func (c *ProxyClient) VolumeSnapshot(dataEngine, engineName, volumeName, service
VolumeName: volumeName,
},
SnapshotVolume: &enginerpc.VolumeSnapshotRequest{
Name: volumeSnapshotName,
Labels: labels,
Name: volumeSnapshotName,
Labels: labels,
FreezeFilesystem: freezeFilesystem,
},
}
recv, err := c.service.VolumeSnapshot(getContextWithGRPCTimeout(c.ctx), req)
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (ops V1DataEngineProxyOps) VolumeSnapshot(ctx context.Context, req *rpc.Eng
}
defer c.Close()

recv, err := c.VolumeSnapshot(req.SnapshotVolume.Name, req.SnapshotVolume.Labels)
recv, err := c.VolumeSnapshot(req.SnapshotVolume.Name, req.SnapshotVolume.Labels, req.SnapshotVolume.FreezeFilesystem)
if err != nil {
return nil, err
}
Expand Down
201 changes: 201 additions & 0 deletions vendor/github.com/longhorn/go-iscsi-helper/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading