代码:git@github.com:google/crfs.git

概念

TOC :Table of Contents

TOCEntry:每个文件都至少有一个TOCEntry,如果一个文件被分成多个chunk,则会有多个TOCEntry

In summary:

  • That traditional .tar.gz format is: *Gzip(TarF(file1) + TarF(file2) + TarF(file3) + TarFooter))
  • Stargz’s format is: Gzip(TarF(file1)) + Gzip(TarF(file2)) + Gzip(TarF(file3_chunk1)) + Gzip(F(file3_chunk2)) + Gzip(F(index of earlier files in magic file), TarFooter), where the trailing ZIP-like index contains offsets for each file/chunk’s GZIP header in the overall stargz file.

代码结构解析

crfs.go

layerHostOwner 对应镜像project /crfs/layers/gcr.io/foo-proj/

�layerHostOwnerImage 对应镜像名 /crfs/layers/gcr.io/foo-proj/ubuntu

layerHostOwnerImageReference 对应某个镜像 /crfs/layers/gcr.io/foo-proj/ubuntu/sha256-7de52a7970a2d0a7d355c76e4f0e02b0e6ebc2841f64040062a27313761cc978

  1. manifest 镜像的manifest,包含layers信息


  1. type node struct {
  2. fs *FS
  3. te *stargz.TOCEntry
  4. // 这个Reader是通过stargz.Open创建的,缓存了所有文件名和对应的TOCEntry
  5. sr *stargz.Reader
  6. f *os.File // non-nil if root & in debug mode
  7. opaque bool // true if this node is an overlayfs opaque directory
  8. mu sync.Mutex // guards child, below
  9. // child maps from previously-looked up base names (like "foo.txt") to the
  10. // fspkg.Node that was previously returned. This prevents FUSE inode numbers
  11. // from getting out of sync
  12. child map[string]fspkg.Node
  13. }

node 对应 a CRFS node in the FUSE filesystem. 事实上就是镜像的一个layer
—》node.Open 打开一个文件,返回一个 nodeHandle

�nodeHandle
�—》Read 读取文件
�——》 chunkData 通过httpRangeRead读取部分数据