Repository: google/gvisor
File: runsc/boot/gofer_conf.go (Go)

Code before:
}

// ShouldUseOverlayfs returns true if an overlayfs should be applied.
func (g GoferMountConf) ShouldUseOverlayfs() bool {
	return g.Lower != NoneLower && g.Upper != NoOverlay
}

// ShouldUseTmpfs returns true if a tmpfs should be applied.
func (g GoferMountConf) ShouldUseTmpfs() bool {
	// g.valid() implies that g.Upper != NoOverlay.
	return g.Lower == NoneLower
}

// ShouldUseLisafs returns true if a lisafs client/server should be set up.
func (g GoferMountConf) ShouldUseLisafs() bool {
	return g.Lower == Lisafs
}

// ShouldUseErofs returns true if an EROFS should be applied.
func (g GoferMountConf) ShouldUseErofs() bool {
	return g.Lower == Erofs
}

// valid returns true if this is a valid gofer mount config.
func (g GoferMountConf) valid() bool {
	return g.Lower < LowerMax && g.Upper < UpperMax && (g.Lower != NoneLower || g.Upper != NoOverlay) && (g.UpperSize == "" || g.ShouldUseOverlayfs())
}

// GoferMountConfFlags can be used with GoferMountConf flags that appear
// multiple times.
type GoferMountConfFlags []GoferMountConf

// String implements flag.Value.
func (g *GoferMountConfFlags) String() string {
	confs := make([]string, 0, len(*g))
	for _, confVal := range *g {
		confs = append(confs, confVal.String())
	}
	return strings.Join(confs, ",")
}

// Get implements flag.Value.
func (g *GoferMountConfFlags) Get() any {
	return g
}

// GetArray returns an array of mappings.
func (g *GoferMountConfFlags) GetArray() []GoferMountConf {
	return *g
}


Review comment (suggestion):
I don't understand this change. When ShouldUseOverlayfs() returns false, it can be that we want to apply a tmpfs-only. In that case, why do we want size==""?

I think size does not apply when upper == NoOverlay, since here is nothing to apply the size on. Upper can be NoOverlay when the rootfs is being mounted readonly (in the OCI spec, Spec.Root.Readonly controls this). In such situations, we don't want to error out. Instead we can just ignore the size when upper is not present.

Revert this line.

Code after:
func (g GoferMountConf) IsFilestorePresent() bool {
	return g.Upper == SelfOverlay || g.Upper == AnonOverlay
}

// IsSelfBacked returns true if this mount is backed by a filestore in itself.
func (g GoferMountConf) IsSelfBacked() bool {
	return g.Upper == SelfOverlay
}

// ShouldUseOverlayfs returns true if an overlayfs should be applied.
func (g GoferMountConf) ShouldUseOverlayfs() bool {
	return g.Lower != NoneLower && g.Upper != NoOverlay
}

// ShouldUseTmpfs returns true if a tmpfs should be applied.
func (g GoferMountConf) ShouldUseTmpfs() bool {
	// g.valid() implies that g.Upper != NoOverlay.
	return g.Lower == NoneLower
}

// ShouldUseLisafs returns true if a lisafs client/server should be set up.
func (g GoferMountConf) ShouldUseLisafs() bool {
	return g.Lower == Lisafs
}

// ShouldUseErofs returns true if an EROFS should be applied.
func (g GoferMountConf) ShouldUseErofs() bool {
	return g.Lower == Erofs
}

// valid returns true if this is a valid gofer mount config.
func (g GoferMountConf) valid() bool {
	return g.Lower < LowerMax && g.Upper < UpperMax && (g.Lower != NoneLower || g.Upper != NoOverlay)
}

// GoferMountConfFlags can be used with GoferMountConf flags that appear
// multiple times.
type GoferMountConfFlags []GoferMountConf

// String implements flag.Value.
func (g *GoferMountConfFlags) String() string {
	confs := make([]string, 0, len(*g))
	for _, confVal := range *g {
		confs = append(confs, confVal.String())
	}
	return strings.Join(confs, ",")
}

// Get implements flag.Value.
func (g *GoferMountConfFlags) Get() any {
	return g