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

Set fuse.Attr.Blocks to number of 512-byte blocks #1387

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Conversation

Kern--
Copy link
Contributor

@Kern-- Kern-- commented Sep 16, 2023

Before this change, stargz-snapshotter set fuse.Attr.Blocks to the number of blockSize-byte blocks. go-fuse and linux expect this to be reported as 512-byte blocks.

Since blockSize > 512, the number of blocks was under-reported which made the files look sparse to programs that inspected them (e.g. cp).

fixes #1386.


I ran a ubuntu:23.04 container to see that this fixed the hanging issue:

Before:

# stat /bin/bash
  File: /bin/bash
  Size: 1437832   	Blocks: 352        IO Block: 4096   regular file
# cp /bin/bash /bin/bash2 # hangs forever

After:

# stat /bin/bash
  File: /bin/bash
  Size: 1437832     Blocks: 2816       IO Block: 4096   regular file
# cp /bin/bash /bin/bash2
# stat /bin/bash2
  File: /bin/bash2
  Size: 1437832     Blocks: 2816       IO Block: 4096   regular file

if out.Size%uint64(out.Blksize) > 0 {
out.Blocks++
}
out.Blocks = (out.Size + uint64(out.Blksize) - 1) / uint64(out.Blksize) * physicalBlockRatio
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted to try to keep the blocks reported aligned to blockSize. I'm not sure if anything would care if it were unaligned, but it seemed reasonable to do.

@ktock
Copy link
Member

ktock commented Sep 17, 2023

@Kern-- Thanks! The patch looks good to me. Could you run go fmt ./fs/layer/node.go to make the linter happy?

Before this change, stargz-snapshotter set fuse.Attr.Blocks to the
number of `blockSize`-byte blocks. go-fuse and linux expect this to be
reported as 512-byte blocks.

Since `blockSize` > 512, the number of blocks was under-reported which
made the files look sparse to programs that inspected them (e.g. `cp`).

Signed-off-by: Kern Walster <[email protected]>
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

Thanks!

@ktock ktock merged commit ea547ff into containerd:main Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stargz-snapshotter incorrectly reports number blocks for a file.
2 participants