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

Correctly export the root file-system changes #4643

Merged
merged 1 commit into from
Dec 17, 2019

Conversation

adrianreber
Copy link
Collaborator

When doing a checkpoint with --export the root file-system diff was not working as expected. Instead of getting the changes from the running container to the highest storage layer it got the changes from the highest layer to that parent's layer. For a one layer container this could mean that the complete root file-system is part of the checkpoint.

With this commit this changes to use the same functionality as podman diff. This actually enables to correctly diff the root file-system including tracking deleted files.

This also removes the non-working helper functions from libpod/diff.go.

Fixes: #4606

@baude
Copy link
Member

baude commented Dec 5, 2019

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 5, 2019
@rhatdan
Copy link
Member

rhatdan commented Dec 6, 2019

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I prefer one more pair of eyes to run over

@rst0git
Copy link
Contributor

rst0git commented Dec 6, 2019

@adrianreber when a folder inside the container is removed it looks like the complete root file-system becomes part of the checkpoint

podman run --name test -dit alpine
podman exec -l sh -c 'rm -rf srv'
podman container checkpoint -l -e podman.tar
tar tvf podman.tar
...
-rw-r--r-- root/root   5816320 2019-12-06 18:03 rootfs-diff.tar

@adrianreber
Copy link
Collaborator Author

adrianreber commented Dec 6, 2019

@adrianreber when a folder inside the container is removed it looks like the complete root file-system becomes part of the checkpoint

podman run --name test -dit alpine
podman exec -l sh -c 'rm -rf srv'
podman container checkpoint -l -e podman.tar
tar tvf podman.tar
...
-rw-r--r-- root/root   5816320 2019-12-06 18:03 rootfs-diff.tar

I cannot reproduce that:

#  podman diff -l ; podman container checkpoint -l -e podman.tar.gz -R
A /SOME_FILE
D /root
b564fe891c82fdc019ac167bb7b729128191057e84d546df90e7b7e14ec3012a
#  tar xf podman.tar
# ls -la
drwxr-xr-x.  4 root root   176 Dec  6 18:44 .
dr-xr-x---. 10 root root  4096 Dec  6 14:09 ..
drwxr-xr-x.  2 root root     6 Dec  6 18:34 artifacts
drw-r-xr-x.  2 root root  4096 Dec  6 18:44 checkpoint
-rw-r--r--.  1 root root 50215 Dec  6 18:44 config.dump
-rw-------.  1 root root     0 Dec  6 18:34 ctr.log
-rw-------.  1 root root    16 Dec  6 18:44 deleted.files
-rw-r--r--.  1 root root   791 Dec  6 18:44 network.status
-rw-------.  1 root root 48841 Dec  6 18:44 podman.tar
-rw-r--r--.  1 root root  4096 Dec  6 18:44 rootfs-diff.tar
-rw-r--r--.  1 root root 45766 Dec  6 18:44 spec.dump
#️  tar tf rootfs-diff.tar 
SOME_FILE

Looks like your Podman binary has not the changes from this pull request. Can you double check?

@rst0git
Copy link
Contributor

rst0git commented Dec 7, 2019

Looks like your Podman binary has not the changes from this pull request. Can you double check?

Yes, I updated the Podman binary with the changes from this pull request.
It occurs only when rootfsIncludeFiles = []. The following fix seems to work:

diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 25688db5..709e3655 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -622,26 +622,27 @@ func (c *Container) exportCheckpoint(dest string, ignoreRootfs bool) (err error)
 			}
 		}
 
-		rootfsTar, err := archive.TarWithOptions(c.state.Mountpoint, &archive.TarOptions{
-			Compression:      archive.Uncompressed,
-			IncludeSourceDir: true,
-			IncludeFiles:     rootfsIncludeFiles,
-		})
-		if err != nil {
-			return errors.Wrapf(err, "error exporting root file-system diff to %q", rootfsDiffPath)
-		}
-		rootfsDiffFile, err := os.Create(rootfsDiffPath)
-		if err != nil {
-			return errors.Wrapf(err, "error creating root file-system diff file %q", rootfsDiffPath)
-		}
-		defer rootfsDiffFile.Close()
-		_, err = io.Copy(rootfsDiffFile, rootfsTar)
-		if err != nil {
-			return err
+		if len(rootfsIncludeFiles) > 0 {
+			rootfsTar, err := archive.TarWithOptions(c.state.Mountpoint, &archive.TarOptions{
+				Compression:      archive.Uncompressed,
+				IncludeSourceDir: true,
+				IncludeFiles:     rootfsIncludeFiles,
+			})
+			if err != nil {
+				return errors.Wrapf(err, "error exporting root file-system diff to %q", rootfsDiffPath)
+			}
+			rootfsDiffFile, err := os.Create(rootfsDiffPath)
+			if err != nil {
+				return errors.Wrapf(err, "error creating root file-system diff file %q", rootfsDiffPath)
+			}
+			defer rootfsDiffFile.Close()
+			_, err = io.Copy(rootfsDiffFile, rootfsTar)
+			if err != nil {
+				return err
+			}
+			includeFiles = append(includeFiles, "rootfs-diff.tar")
 		}
 
-		includeFiles = append(includeFiles, "rootfs-diff.tar")
-
 		if len(deletedFiles) > 0 {
 			formatJSON, err := json.MarshalIndent(deletedFiles, "", "     ")
 			if err != nil {

@adrianreber
Copy link
Collaborator Author

@rst0git Right. Only deleting files is not working. Thanks. Will fix it.

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrianreber, baude, rst0git

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

When doing a checkpoint with --export the root file-system diff was not
working as expected. Instead of getting the changes from the running
container to the highest storage layer it got the changes from the
highest layer to that parent's layer. For a one layer container this
could mean that the complete root file-system is part of the checkpoint.

With this commit this changes to use the same functionality as 'podman
diff'. This actually enables to correctly diff the root file-system
including tracking deleted files.

This also removes the non-working helper functions from libpod/diff.go.

Signed-off-by: Adrian Reber <areber@redhat.com>
@adrianreber
Copy link
Collaborator Author

Can this be merged?

@rhatdan
Copy link
Member

rhatdan commented Dec 17, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2019
@stevekuznetsov
Copy link
Contributor

/hold

"PR is unmergable. Do the Tide merge requirements match the GitHub settings for the repo? At least 1 approving review is required by reviewers with write access."

I suggest you remove that requirement... it's duplicated from /approve

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 17, 2019
@rhatdan
Copy link
Member

rhatdan commented Dec 17, 2019

/lgtm

@mheon
Copy link
Member

mheon commented Dec 17, 2019

Github appears to have stopped complaining, I have a manual merge option now. I'm going to remove the hold and see if branch protection kicks in.

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 17, 2019
@openshift-merge-robot openshift-merge-robot merged commit e6b8433 into containers:master Dec 17, 2019
@mheon
Copy link
Member

mheon commented Dec 17, 2019

Still seems stuck.

I'm going to merge manually.

@mheon
Copy link
Member

mheon commented Dec 17, 2019

Oh, nevermind, it went.

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkpoint-restore-checkpoint-restore loses changes to rootfs
9 participants