Skip to content

Commit

Permalink
fix(host): bind mount regular file when backing up volume mount of pod (
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed Jun 1, 2024
1 parent f9fa7ba commit fdfd90d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pkg/hostman/guestman/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,12 +1520,26 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
if err != nil {
return nil, errors.Wrapf(err, "GetRuntimeMountHostPath containerId: %s, vol: %s", input.ContainerId, jsonutils.Marshal(vol))
}
// bind mount
// mkdir tmpBackRootDir/subdirectory
targetBindMntPath := filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
if out, err := procutils.NewRemoteCommandAsFarAsPossible("mkdir", "-p", targetBindMntPath).Output(); err != nil {
return nil, errors.Wrapf(err, "mkdir -p %s: %s", targetBindMntPath, out)
isMntPathFile := false
targetBindMntPath := tmpBackRootDir
if vol.Disk.SubDirectory != "" {
// mkdir tmpBackRootDir/subdirectory
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
}
if vol.Disk.StorageSizeFile != "" {
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.StorageSizeFile)
isMntPathFile = true
}
if isMntPathFile {
if out, err := procutils.NewRemoteCommandAsFarAsPossible("touch", targetBindMntPath).Output(); err != nil {
return nil, errors.Wrapf(err, "touch %s: %s", targetBindMntPath, out)
}
} else {
if out, err := procutils.NewRemoteCommandAsFarAsPossible("mkdir", "-p", targetBindMntPath).Output(); err != nil {
return nil, errors.Wrapf(err, "mkdir -p %s: %s", targetBindMntPath, out)
}
}
// do bind mount
out, err := procutils.NewRemoteCommandAsFarAsPossible("mount", "--bind", mntPath, targetBindMntPath).Output()
if err != nil {
return nil, errors.Wrapf(err, "bind mount %s to %s: %s", mntPath, targetBindMntPath, out)
Expand All @@ -1539,6 +1553,9 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
// unbind mount
// umount
targetBindMntPath := filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
if vol.Disk.StorageSizeFile != "" {
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.StorageSizeFile)
}
out, err := procutils.NewRemoteCommandAsFarAsPossible("umount", targetBindMntPath).Output()
if err != nil {
return nil, errors.Wrapf(err, "umount bind point %s: %s", targetBindMntPath, out)
Expand Down

0 comments on commit fdfd90d

Please sign in to comment.