Skip to content

Commit

Permalink
Merge pull request #289 from nalind/rlock2
Browse files Browse the repository at this point in the history
Clarify Locker.Locked(), and switch some locks to read-only
  • Loading branch information
rhatdan authored Feb 28, 2019
2 parents 5524afe + cf287af commit 3d34255
Show file tree
Hide file tree
Showing 24 changed files with 288 additions and 177 deletions.
28 changes: 14 additions & 14 deletions cmd/containers-storage/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
func container(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
images, err := m.Images()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
matches := []*storage.Container{}
Expand Down Expand Up @@ -45,7 +45,7 @@ func container(flags *mflag.FlagSet, action string, m storage.Store, args []stri
}
size, err := m.ContainerSize(container.ID)
if err != nil {
fmt.Printf("Size unknown: %v\n", err)
fmt.Printf("Size unknown: %+v\n", err)
} else {
fmt.Printf("Size: %d\n", size)
}
Expand All @@ -64,7 +64,7 @@ func container(flags *mflag.FlagSet, action string, m storage.Store, args []stri
func listContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
container, err := m.Container(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
d, err := m.ListContainerBigData(container.ID)
Expand All @@ -81,7 +81,7 @@ func listContainerBigData(flags *mflag.FlagSet, action string, m storage.Store,
func getContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
container, err := m.Container(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
output := os.Stdout
Expand All @@ -95,7 +95,7 @@ func getContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, a
}
b, err := m.ContainerBigData(container.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
output.Write(b)
Expand All @@ -106,12 +106,12 @@ func getContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, a
func getContainerBigDataSize(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
container, err := m.Container(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
size, err := m.ContainerBigDataSize(container.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
fmt.Fprintf(os.Stdout, "%d\n", size)
Expand All @@ -121,12 +121,12 @@ func getContainerBigDataSize(flags *mflag.FlagSet, action string, m storage.Stor
func getContainerBigDataDigest(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
container, err := m.Container(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
d, err := m.ContainerBigDataDigest(container.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if d.Validate() != nil {
Expand All @@ -140,7 +140,7 @@ func getContainerBigDataDigest(flags *mflag.FlagSet, action string, m storage.St
func setContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
container, err := m.Container(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
input := os.Stdin
Expand All @@ -159,7 +159,7 @@ func setContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, a
}
err = m.SetContainerBigData(container.ID, args[1], b)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
return 0
Expand All @@ -168,7 +168,7 @@ func setContainerBigData(flags *mflag.FlagSet, action string, m storage.Store, a
func getContainerDir(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
path, err := m.ContainerDirectory(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
fmt.Printf("%s\n", path)
Expand All @@ -178,7 +178,7 @@ func getContainerDir(flags *mflag.FlagSet, action string, m storage.Store, args
func getContainerRunDir(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
path, err := m.ContainerRunDirectory(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
fmt.Printf("%s\n", path)
Expand All @@ -195,7 +195,7 @@ func containerParentOwners(flags *mflag.FlagSet, action string, m storage.Store,
for _, container := range matched {
uids, gids, err := m.ContainerParentOwners(container.ID)
if err != nil {
fmt.Fprintf(os.Stderr, "ContainerParentOwner: %v\n", err)
fmt.Fprintf(os.Stderr, "ContainerParentOwner: %+v\n", err)
return 1
}
if jsonOutput {
Expand Down
2 changes: 1 addition & 1 deletion cmd/containers-storage/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func containers(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
containers, err := m.Containers()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down
10 changes: 5 additions & 5 deletions cmd/containers-storage/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func copyContent(flags *mflag.FlagSet, action string, m storage.Store, args []st
}
targetLayer, err := m.Layer(targetParts[0])
if err != nil {
fmt.Fprintf(os.Stderr, "error finding layer %q: %v\n", targetParts[0], err)
fmt.Fprintf(os.Stderr, "error finding layer %q: %+v\n", targetParts[0], err)
return 1
}
untarIDMappings = idtools.NewIDMappingsFromMaps(targetLayer.UIDMap, targetLayer.GIDMap)
targetMount, err := m.Mount(targetLayer.ID, targetLayer.MountLabel)
if err != nil {
fmt.Fprintf(os.Stderr, "error mounting layer %q: %v\n", targetLayer.ID, err)
fmt.Fprintf(os.Stderr, "error mounting layer %q: %+v\n", targetLayer.ID, err)
return 1
}
target = filepath.Join(targetMount, targetParts[1])
Expand All @@ -73,21 +73,21 @@ func copyContent(flags *mflag.FlagSet, action string, m storage.Store, args []st
}
sourceLayer, err := m.Layer(sourceParts[0])
if err != nil {
fmt.Fprintf(os.Stderr, "error finding layer %q: %v\n", sourceParts[0], err)
fmt.Fprintf(os.Stderr, "error finding layer %q: %+v\n", sourceParts[0], err)
return 1
}
tarIDMappings = idtools.NewIDMappingsFromMaps(sourceLayer.UIDMap, sourceLayer.GIDMap)
sourceMount, err := m.Mount(sourceLayer.ID, sourceLayer.MountLabel)
if err != nil {
fmt.Fprintf(os.Stderr, "error mounting layer %q: %v\n", sourceLayer.ID, err)
fmt.Fprintf(os.Stderr, "error mounting layer %q: %+v\n", sourceLayer.ID, err)
return 1
}
source = filepath.Join(sourceMount, sourceParts[1])
defer m.Unmount(sourceLayer.ID, false)
}
archiver := chrootarchive.NewArchiverWithChown(tarIDMappings, chownOpts, untarIDMappings)
if err := archiver.CopyWithTar(source, target); err != nil {
fmt.Fprintf(os.Stderr, "error copying %q to %q: %v\n", source, target, err)
fmt.Fprintf(os.Stderr, "error copying %q to %q: %+v\n", source, target, err)
return 1
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/containers-storage/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func createLayer(flags *mflag.FlagSet, action string, m storage.Store, args []st
options := &storage.LayerOptions{IDMappingOptions: *mappings}
layer, err := m.CreateLayer(paramID, parent, paramNames, paramMountLabel, !paramCreateRO, options)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down Expand Up @@ -120,7 +120,7 @@ func importLayer(flags *mflag.FlagSet, action string, m storage.Store, args []st
options := &storage.LayerOptions{IDMappingOptions: *mappings}
layer, _, err := m.PutLayer(paramID, parent, paramNames, paramMountLabel, !paramCreateRO, options, diffStream)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down Expand Up @@ -157,7 +157,7 @@ func createImage(flags *mflag.FlagSet, action string, m storage.Store, args []st
}
image, err := m.CreateImage(paramID, paramNames, layer, paramMetadata, imageOptions)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down Expand Up @@ -193,7 +193,7 @@ func createContainer(flags *mflag.FlagSet, action string, m storage.Store, args
options := &storage.ContainerOptions{IDMappingOptions: *mappings}
container, err := m.CreateContainer(paramID, paramNames, args[0], paramLayer, paramMetadata, options)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down
14 changes: 7 additions & 7 deletions cmd/containers-storage/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func changes(flags *mflag.FlagSet, action string, m storage.Store, args []string
}
changes, err := m.Changes(from, to)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down Expand Up @@ -66,7 +66,7 @@ func diff(flags *mflag.FlagSet, action string, m storage.Store, args []string) i
if diffFile != "" {
f, err := os.Create(diffFile)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
diffStream = f
Expand All @@ -90,13 +90,13 @@ func diff(flags *mflag.FlagSet, action string, m storage.Store, args []string) i

reader, err := m.Diff(from, to, &options)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
_, err = io.Copy(diffStream, reader)
reader.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
return 0
Expand All @@ -110,15 +110,15 @@ func applyDiff(flags *mflag.FlagSet, action string, m storage.Store, args []stri
if applyDiffFile != "" {
f, err := os.Open(applyDiffFile)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
diffStream = f
defer f.Close()
}
_, err := m.ApplyDiff(args[0], diffStream)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
return 0
Expand All @@ -135,7 +135,7 @@ func diffSize(flags *mflag.FlagSet, action string, m storage.Store, args []strin
}
n, err := m.DiffSize(from, to)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
fmt.Printf("%d\n", n)
Expand Down
16 changes: 8 additions & 8 deletions cmd/containers-storage/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func image(flags *mflag.FlagSet, action string, m storage.Store, args []string)
}
size, err := m.ImageSize(image.ID)
if err != nil {
fmt.Printf("Size unknown: %v\n", err)
fmt.Printf("Size unknown: %+v\n", err)
} else {
fmt.Printf("Size: %d\n", size)
}
Expand All @@ -56,7 +56,7 @@ func image(flags *mflag.FlagSet, action string, m storage.Store, args []string)
func listImageBigData(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
image, err := m.Image(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
d, err := m.ListImageBigData(image.ID)
Expand All @@ -73,7 +73,7 @@ func listImageBigData(flags *mflag.FlagSet, action string, m storage.Store, args
func getImageBigData(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
image, err := m.Image(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
output := os.Stdout
Expand All @@ -87,7 +87,7 @@ func getImageBigData(flags *mflag.FlagSet, action string, m storage.Store, args
}
b, err := m.ImageBigData(image.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
output.Write(b)
Expand All @@ -98,12 +98,12 @@ func getImageBigData(flags *mflag.FlagSet, action string, m storage.Store, args
func getImageBigDataSize(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
image, err := m.Image(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
size, err := m.ImageBigDataSize(image.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
fmt.Fprintf(os.Stdout, "%d\n", size)
Expand All @@ -113,12 +113,12 @@ func getImageBigDataSize(flags *mflag.FlagSet, action string, m storage.Store, a
func getImageBigDataDigest(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
image, err := m.Image(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
d, err := m.ImageBigDataDigest(image.ID, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if d.Validate() != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/containers-storage/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
func images(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
images, err := m.Images()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down Expand Up @@ -52,7 +52,7 @@ func imagesByDigest(flags *mflag.FlagSet, action string, m storage.Store, args [
}
matched, err := m.ImagesByDigest(d)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
for _, match := range matched {
Expand Down
2 changes: 1 addition & 1 deletion cmd/containers-storage/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func layerParentOwners(flags *mflag.FlagSet, action string, m storage.Store, arg
for _, layer := range matched {
uids, gids, err := m.LayerParentOwners(layer.ID)
if err != nil {
fmt.Fprintf(os.Stderr, "LayerParentOwner: %v\n", err)
fmt.Fprintf(os.Stderr, "LayerParentOwner: %+v\n", err)
return 1
}
if jsonOutput {
Expand Down
2 changes: 1 addition & 1 deletion cmd/containers-storage/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var listLayersTree = false
func layers(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
layers, err := m.Layers()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
if jsonOutput {
Expand Down
2 changes: 1 addition & 1 deletion cmd/containers-storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func main() {
}
store, err := storage.GetStore(options)
if err != nil {
fmt.Printf("error initializing: %v\n", err)
fmt.Printf("error initializing: %+v\n", err)
os.Exit(1)
}
os.Exit(command.action(flags, cmd, store, args))
Expand Down
2 changes: 1 addition & 1 deletion cmd/containers-storage/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func setMetadata(flags *mflag.FlagSet, action string, m storage.Store, args []st
paramMetadata = string(b)
}
if err := m.SetMetadata(args[0], paramMetadata); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1
}
return 0
Expand Down
Loading

0 comments on commit 3d34255

Please sign in to comment.