From ead425f42619fde0422647c48bf945c747928023 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 8 Mar 2017 22:03:46 -0800 Subject: [PATCH 1/7] Add rootfs service Add rootfs service to allow creation of rootfs from layer array Signed-off-by: Derek McGowan (github: dmcgowan) --- api/services/rootfs/rootfs.pb.go | 577 ++++++++++++++++++++++++++ api/services/rootfs/rootfs.proto | 38 ++ api/types/descriptor/descriptor.pb.go | 417 +++++++++++++++++++ api/types/descriptor/descriptor.proto | 11 + cmd/containerd/builtins.go | 1 + rootfs/apply.go | 19 +- services/rootfs/preparer.go | 39 ++ services/rootfs/service.go | 86 ++++ 8 files changed, 1182 insertions(+), 6 deletions(-) create mode 100644 api/services/rootfs/rootfs.pb.go create mode 100644 api/services/rootfs/rootfs.proto create mode 100644 api/types/descriptor/descriptor.pb.go create mode 100644 api/types/descriptor/descriptor.proto create mode 100644 services/rootfs/preparer.go create mode 100644 services/rootfs/service.go diff --git a/api/services/rootfs/rootfs.pb.go b/api/services/rootfs/rootfs.pb.go new file mode 100644 index 0000000..6362050 --- /dev/null +++ b/api/services/rootfs/rootfs.pb.go @@ -0,0 +1,577 @@ +// Code generated by protoc-gen-gogo. +// source: github.com/docker/containerd/api/services/rootfs/rootfs.proto +// DO NOT EDIT! + +/* + Package rootfs is a generated protocol buffer package. + + It is generated from these files: + github.com/docker/containerd/api/services/rootfs/rootfs.proto + + It has these top-level messages: + PrepareRequest + PrepareResponse +*/ +package rootfs + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/golang/protobuf/ptypes/empty" +import _ "github.com/docker/containerd/api/types/mount" +import containerd_v1_types1 "github.com/docker/containerd/api/types/descriptor" + +import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +import strings "strings" +import reflect "reflect" + +import io "io" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type PrepareRequest struct { + Layers []*containerd_v1_types1.Descriptor `protobuf:"bytes,1,rep,name=layers" json:"layers,omitempty"` +} + +func (m *PrepareRequest) Reset() { *m = PrepareRequest{} } +func (*PrepareRequest) ProtoMessage() {} +func (*PrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{0} } + +type PrepareResponse struct { + ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,1,opt,name=chainid,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chainid"` +} + +func (m *PrepareResponse) Reset() { *m = PrepareResponse{} } +func (*PrepareResponse) ProtoMessage() {} +func (*PrepareResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{1} } + +func init() { + proto.RegisterType((*PrepareRequest)(nil), "containerd.v1.PrepareRequest") + proto.RegisterType((*PrepareResponse)(nil), "containerd.v1.PrepareResponse") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for RootFS service + +type RootFSClient interface { + Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*PrepareResponse, error) +} + +type rootFSClient struct { + cc *grpc.ClientConn +} + +func NewRootFSClient(cc *grpc.ClientConn) RootFSClient { + return &rootFSClient{cc} +} + +func (c *rootFSClient) Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*PrepareResponse, error) { + out := new(PrepareResponse) + err := grpc.Invoke(ctx, "/containerd.v1.RootFS/Prepare", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for RootFS service + +type RootFSServer interface { + Prepare(context.Context, *PrepareRequest) (*PrepareResponse, error) +} + +func RegisterRootFSServer(s *grpc.Server, srv RootFSServer) { + s.RegisterService(&_RootFS_serviceDesc, srv) +} + +func _RootFS_Prepare_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PrepareRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RootFSServer).Prepare(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/containerd.v1.RootFS/Prepare", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RootFSServer).Prepare(ctx, req.(*PrepareRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _RootFS_serviceDesc = grpc.ServiceDesc{ + ServiceName: "containerd.v1.RootFS", + HandlerType: (*RootFSServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Prepare", + Handler: _RootFS_Prepare_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "github.com/docker/containerd/api/services/rootfs/rootfs.proto", +} + +func (m *PrepareRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrepareRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Layers) > 0 { + for _, msg := range m.Layers { + dAtA[i] = 0xa + i++ + i = encodeVarintRootfs(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + return i, nil +} + +func (m *PrepareResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrepareResponse) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ChainID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintRootfs(dAtA, i, uint64(len(m.ChainID))) + i += copy(dAtA[i:], m.ChainID) + } + return i, nil +} + +func encodeFixed64Rootfs(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Rootfs(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintRootfs(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *PrepareRequest) Size() (n int) { + var l int + _ = l + if len(m.Layers) > 0 { + for _, e := range m.Layers { + l = e.Size() + n += 1 + l + sovRootfs(uint64(l)) + } + } + return n +} + +func (m *PrepareResponse) Size() (n int) { + var l int + _ = l + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovRootfs(uint64(l)) + } + return n +} + +func sovRootfs(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozRootfs(x uint64) (n int) { + return sovRootfs(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *PrepareRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PrepareRequest{`, + `Layers:` + strings.Replace(fmt.Sprintf("%v", this.Layers), "Descriptor", "containerd_v1_types1.Descriptor", 1) + `,`, + `}`, + }, "") + return s +} +func (this *PrepareResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PrepareResponse{`, + `ChainID:` + fmt.Sprintf("%v", this.ChainID) + `,`, + `}`, + }, "") + return s +} +func valueToStringRootfs(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *PrepareRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrepareRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrepareRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Layers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Layers = append(m.Layers, &containerd_v1_types1.Descriptor{}) + if err := m.Layers[len(m.Layers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRootfs(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthRootfs + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrepareResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrepareResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrepareResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = github_com_opencontainers_go_digest.Digest(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRootfs(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthRootfs + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipRootfs(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRootfs + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRootfs + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRootfs + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthRootfs + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowRootfs + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipRootfs(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthRootfs = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRootfs = fmt.Errorf("proto: integer overflow") +) + +func init() { + proto.RegisterFile("github.com/docker/containerd/api/services/rootfs/rootfs.proto", fileDescriptorRootfs) +} + +var fileDescriptorRootfs = []byte{ + // 335 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0x4f, 0xea, 0x40, + 0x10, 0xc6, 0xd9, 0xbc, 0x04, 0xf2, 0xf6, 0xe5, 0xbd, 0x97, 0x34, 0x1e, 0x08, 0xc6, 0x2d, 0xe1, + 0x44, 0x4c, 0xdc, 0x8d, 0x78, 0xd0, 0x0b, 0x17, 0x24, 0x46, 0x6e, 0xa6, 0x1e, 0x3c, 0x97, 0x76, + 0x58, 0x56, 0xa1, 0xb3, 0xee, 0x6e, 0x49, 0xb8, 0xf9, 0xe7, 0x71, 0xf4, 0x68, 0x3c, 0x10, 0xe9, + 0x5f, 0x62, 0x68, 0x0b, 0x82, 0x89, 0xd1, 0x4b, 0x67, 0x9a, 0xef, 0x9b, 0xdf, 0x7c, 0xb3, 0xb4, + 0x2b, 0x95, 0x1b, 0xa7, 0x43, 0x1e, 0xe1, 0x54, 0xc4, 0x18, 0x3d, 0x80, 0x11, 0x11, 0x26, 0x2e, + 0x54, 0x09, 0x98, 0x58, 0x84, 0x5a, 0x09, 0x0b, 0x66, 0xa6, 0x22, 0xb0, 0xc2, 0x20, 0xba, 0xd1, + 0xa6, 0x70, 0x6d, 0xd0, 0xa1, 0xf7, 0xf7, 0xc3, 0xcc, 0x67, 0xa7, 0x8d, 0x03, 0x89, 0x12, 0x73, + 0x45, 0xac, 0xbb, 0xc2, 0xd4, 0x38, 0x94, 0x88, 0x72, 0x02, 0x22, 0xff, 0x1b, 0xa6, 0x23, 0x01, + 0x53, 0xed, 0xe6, 0xa5, 0x78, 0xf1, 0x6d, 0x00, 0x37, 0xd7, 0x60, 0xc5, 0x14, 0xd3, 0xc4, 0x15, + 0xdf, 0x72, 0xb2, 0xf7, 0xc3, 0xc9, 0x18, 0x6c, 0x64, 0x94, 0x76, 0x68, 0x76, 0xda, 0x82, 0xd1, + 0x1a, 0xd0, 0x7f, 0x37, 0x06, 0x74, 0x68, 0x20, 0x80, 0xc7, 0x14, 0xac, 0xf3, 0xce, 0x69, 0x75, + 0x12, 0xce, 0xc1, 0xd8, 0x3a, 0x69, 0xfe, 0x6a, 0xff, 0xe9, 0xf8, 0x7c, 0xef, 0x44, 0x9e, 0x33, + 0x79, 0x7f, 0x0b, 0x0a, 0x4a, 0x7b, 0xeb, 0x9e, 0xfe, 0xdf, 0xa2, 0xac, 0xc6, 0xc4, 0x82, 0x77, + 0x47, 0x6b, 0xd1, 0x38, 0x54, 0x89, 0x8a, 0xeb, 0xa4, 0x49, 0xda, 0xbf, 0x7b, 0xdd, 0xc5, 0xd2, + 0xaf, 0xbc, 0x2e, 0xfd, 0xe3, 0x9d, 0xe8, 0xa8, 0x21, 0xd9, 0xae, 0xb0, 0x42, 0xe2, 0x49, 0xac, + 0x24, 0x58, 0xc7, 0xfb, 0x79, 0xc9, 0x96, 0x7e, 0xed, 0x72, 0x0d, 0x19, 0xf4, 0x83, 0x0d, 0xad, + 0x13, 0xd0, 0x6a, 0x80, 0xe8, 0xae, 0x6e, 0xbd, 0x6b, 0x5a, 0x2b, 0xb7, 0x7a, 0x47, 0x9f, 0x92, + 0xee, 0x1f, 0xd6, 0x60, 0x5f, 0xc9, 0x45, 0xd8, 0x5e, 0x7d, 0xb1, 0x62, 0x95, 0x97, 0x15, 0xab, + 0x3c, 0x65, 0x8c, 0x2c, 0x32, 0x46, 0x9e, 0x33, 0x46, 0xde, 0x32, 0x46, 0x86, 0xd5, 0xfc, 0xad, + 0xce, 0xde, 0x03, 0x00, 0x00, 0xff, 0xff, 0x4c, 0xa2, 0x59, 0x7e, 0x2c, 0x02, 0x00, 0x00, +} diff --git a/api/services/rootfs/rootfs.proto b/api/services/rootfs/rootfs.proto new file mode 100644 index 0000000..866f78a --- /dev/null +++ b/api/services/rootfs/rootfs.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; + +package containerd.v1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/empty.proto"; +import "github.com/docker/containerd/api/types/mount/mount.proto"; +import "github.com/docker/containerd/api/types/descriptor/descriptor.proto"; + +service RootFS { + rpc Prepare(PrepareRequest) returns (PrepareResponse); + + // TODO: Add method for initializing and retrieving mounts + //rpc InitMounts(InitRequest) returns (MountResponse); + //rpc Mounts(MountRequest) returns (MountResponse); +} + +message PrepareRequest { + repeated containerd.v1.types.Descriptor layers = 1; +} + +message PrepareResponse { + string chainid = 1 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; +} + +//message InitRequest { +// string name = 1; +// string chainID = 2; +// bool Readonly = 3; +//} +// +//message MountRequest { +// string name = 1; +//} +// +//message MountResponse { +// repeated containerd.v1.types.Mount mounts = 1; +//} diff --git a/api/types/descriptor/descriptor.pb.go b/api/types/descriptor/descriptor.pb.go new file mode 100644 index 0000000..6c1b662 --- /dev/null +++ b/api/types/descriptor/descriptor.pb.go @@ -0,0 +1,417 @@ +// Code generated by protoc-gen-gogo. +// source: github.com/docker/containerd/api/types/descriptor/descriptor.proto +// DO NOT EDIT! + +/* + Package descriptor is a generated protocol buffer package. + + It is generated from these files: + github.com/docker/containerd/api/types/descriptor/descriptor.proto + + It has these top-level messages: + Descriptor +*/ +package descriptor + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest" + +import strings "strings" +import reflect "reflect" + +import io "io" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type Descriptor struct { + MediaType string `protobuf:"bytes,1,opt,name=mediaType,proto3" json:"mediaType,omitempty"` + Digest github_com_opencontainers_go_digest.Digest `protobuf:"bytes,2,opt,name=digest,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"digest"` + MediaSize int64 `protobuf:"varint,3,opt,name=mediaSize,proto3" json:"mediaSize,omitempty"` +} + +func (m *Descriptor) Reset() { *m = Descriptor{} } +func (*Descriptor) ProtoMessage() {} +func (*Descriptor) Descriptor() ([]byte, []int) { return fileDescriptorDescriptor, []int{0} } + +func init() { + proto.RegisterType((*Descriptor)(nil), "containerd.v1.types.Descriptor") +} +func (m *Descriptor) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Descriptor) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.MediaType) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintDescriptor(dAtA, i, uint64(len(m.MediaType))) + i += copy(dAtA[i:], m.MediaType) + } + if len(m.Digest) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintDescriptor(dAtA, i, uint64(len(m.Digest))) + i += copy(dAtA[i:], m.Digest) + } + if m.MediaSize != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintDescriptor(dAtA, i, uint64(m.MediaSize)) + } + return i, nil +} + +func encodeFixed64Descriptor(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Descriptor(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintDescriptor(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *Descriptor) Size() (n int) { + var l int + _ = l + l = len(m.MediaType) + if l > 0 { + n += 1 + l + sovDescriptor(uint64(l)) + } + l = len(m.Digest) + if l > 0 { + n += 1 + l + sovDescriptor(uint64(l)) + } + if m.MediaSize != 0 { + n += 1 + sovDescriptor(uint64(m.MediaSize)) + } + return n +} + +func sovDescriptor(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozDescriptor(x uint64) (n int) { + return sovDescriptor(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Descriptor) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Descriptor{`, + `MediaType:` + fmt.Sprintf("%v", this.MediaType) + `,`, + `Digest:` + fmt.Sprintf("%v", this.Digest) + `,`, + `MediaSize:` + fmt.Sprintf("%v", this.MediaSize) + `,`, + `}`, + }, "") + return s +} +func valueToStringDescriptor(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Descriptor) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDescriptor + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Descriptor: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Descriptor: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MediaType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDescriptor + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDescriptor + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MediaType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Digest", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDescriptor + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDescriptor + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Digest = github_com_opencontainers_go_digest.Digest(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MediaSize", wireType) + } + m.MediaSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDescriptor + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MediaSize |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDescriptor(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDescriptor + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDescriptor(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDescriptor + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDescriptor + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDescriptor + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthDescriptor + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDescriptor + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipDescriptor(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthDescriptor = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDescriptor = fmt.Errorf("proto: integer overflow") +) + +func init() { + proto.RegisterFile("github.com/docker/containerd/api/types/descriptor/descriptor.proto", fileDescriptorDescriptor) +} + +var fileDescriptorDescriptor = []byte{ + // 230 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00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 0xa1, 0x1c, 0xc3, 0x8d, 0x87, + 0x72, 0x0c, 0x0d, 0x8f, 0xe4, 0x18, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, + 0x23, 0x39, 0xc6, 0x24, 0x36, 0xb0, 0xbb, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x3c, + 0x86, 0x2d, 0x28, 0x01, 0x00, 0x00, +} diff --git a/api/types/descriptor/descriptor.proto b/api/types/descriptor/descriptor.proto new file mode 100644 index 0000000..7a82bd8 --- /dev/null +++ b/api/types/descriptor/descriptor.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package containerd.v1.types; + +import "gogoproto/gogo.proto"; + +message Descriptor { + string mediaType = 1; + string digest = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false]; + int64 mediaSize = 3; +} diff --git a/cmd/containerd/builtins.go b/cmd/containerd/builtins.go index 9620297..b5dd214 100644 --- a/cmd/containerd/builtins.go +++ b/cmd/containerd/builtins.go @@ -7,6 +7,7 @@ import ( _ "github.com/docker/containerd/services/execution" _ "github.com/docker/containerd/services/healthcheck" _ "github.com/docker/containerd/services/metrics" + _ "github.com/docker/containerd/services/rootfs" _ "github.com/docker/containerd/snapshot/btrfs" _ "github.com/docker/containerd/snapshot/overlay" ) diff --git a/rootfs/apply.go b/rootfs/apply.go index e713a2c..acbb77c 100644 --- a/rootfs/apply.go +++ b/rootfs/apply.go @@ -16,9 +16,13 @@ import ( "github.com/pkg/errors" ) +type Preparer interface { + Prepare(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) +} + type Mounter interface { - Mount(mounts ...containerd.Mount) error - Unmount(mounts ...containerd.Mount) error + Mount(target string, mounts ...containerd.Mount) error + Unmount(target string) error } // ApplyLayer applies the layer to the provided parent. The resulting snapshot @@ -51,13 +55,13 @@ func ApplyLayer(snapshots snapshot.Snapshotter, mounter Mounter, rd io.Reader, p return "", err } - if err := mounter.Mount(mounts...); err != nil { + if err := mounter.Mount(dir, mounts...); err != nil { if err := snapshots.Remove(ctx, key); err != nil { log.L.WithError(err).Error("snapshot rollback failed") } return "", err } - defer mounter.Unmount(mounts...) + defer mounter.Unmount(dir) rd, err = dockerarchive.DecompressStream(rd) if err != nil { @@ -74,6 +78,9 @@ func ApplyLayer(snapshots snapshot.Snapshotter, mounter Mounter, rd io.Reader, p if parent != "" { chainID = identity.ChainID([]digest.Digest{parent, chainID}) } + if _, err := snapshots.Stat(ctx, chainID.String()); err == nil { + return diffID, nil //TODO: call snapshots.Remove(ctx, key) once implemented + } return diffID, snapshots.Commit(ctx, chainID.String(), key) } @@ -90,7 +97,7 @@ func Prepare(ctx context.Context, snapshots snapshot.Snapshotter, mounter Mounte // rootfs Controller. // // Just pass them in for now. - openBlob func(digest.Digest) (io.ReadCloser, error), + openBlob func(context.Context, digest.Digest) (io.ReadCloser, error), resolveDiffID func(digest.Digest) digest.Digest, registerDiffID func(diffID, dgst digest.Digest) error) (digest.Digest, error) { var ( @@ -116,7 +123,7 @@ func Prepare(ctx context.Context, snapshots snapshot.Snapshotter, mounter Mounte } } - rc, err := openBlob(layerDigest) + rc, err := openBlob(ctx, layerDigest) if err != nil { return "", err } diff --git a/services/rootfs/preparer.go b/services/rootfs/preparer.go new file mode 100644 index 0000000..40d3c7d --- /dev/null +++ b/services/rootfs/preparer.go @@ -0,0 +1,39 @@ +package rootfs + +import ( + "context" + + rootfsapi "github.com/docker/containerd/api/services/rootfs" + containerd_v1_types "github.com/docker/containerd/api/types/descriptor" + "github.com/docker/containerd/rootfs" + digest "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" +) + +func NewPreparerFromClient(client rootfsapi.RootFSClient) rootfs.Preparer { + return remotePreparer{ + client: client, + } +} + +type remotePreparer struct { + client rootfsapi.RootFSClient +} + +func (rp remotePreparer) Prepare(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) { + pr := rootfsapi.PrepareRequest{ + Layers: make([]*containerd_v1_types.Descriptor, len(layers)), + } + for i, l := range layers { + pr.Layers[i] = &containerd_v1_types.Descriptor{ + MediaType: l.MediaType, + Digest: l.Digest, + MediaSize: l.Size, + } + } + resp, err := rp.client.Prepare(ctx, &pr) + if err != nil { + return "", nil + } + return resp.ChainID, nil +} diff --git a/services/rootfs/service.go b/services/rootfs/service.go new file mode 100644 index 0000000..817cbf1 --- /dev/null +++ b/services/rootfs/service.go @@ -0,0 +1,86 @@ +package rootfs + +import ( + "syscall" + + "github.com/docker/containerd" + rootfsapi "github.com/docker/containerd/api/services/rootfs" + "github.com/docker/containerd/content" + "github.com/docker/containerd/log" + "github.com/docker/containerd/plugin" + "github.com/docker/containerd/rootfs" + "github.com/docker/containerd/snapshot" + digest "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "golang.org/x/net/context" + "google.golang.org/grpc" +) + +func init() { + plugin.Register("rootfs-grpc", &plugin.Registration{ + Type: plugin.GRPCPlugin, + Init: func(ic *plugin.InitContext) (interface{}, error) { + return NewService(ic.Store, ic.Snapshotter) + }, + }) +} + +type Service struct { + store *content.Store + snapshotter snapshot.Snapshotter +} + +func NewService(store *content.Store, snapshotter snapshot.Snapshotter) (*Service, error) { + return &Service{ + store: store, + snapshotter: snapshotter, + }, nil +} + +func (s *Service) Register(gs *grpc.Server) error { + rootfsapi.RegisterRootFSServer(gs, s) + return nil +} + +func (s *Service) Prepare(ctx context.Context, pr *rootfsapi.PrepareRequest) (*rootfsapi.PrepareResponse, error) { + layers := make([]ocispec.Descriptor, len(pr.Layers)) + for i, l := range pr.Layers { + layers[i] = ocispec.Descriptor{ + MediaType: l.MediaType, + Digest: l.Digest, + Size: l.MediaSize, + } + } + log.G(ctx).Infof("Preparing %#v", layers) + chainID, err := rootfs.Prepare(ctx, s.snapshotter, mounter{}, layers, s.store.Reader, emptyResolver, noopRegister) + if err != nil { + log.G(ctx).Errorf("Rootfs Prepare failed!: %v", err) + return nil, err + } + log.G(ctx).Infof("ChainID %#v", chainID) + return &rootfsapi.PrepareResponse{ + ChainID: chainID, + }, nil +} + +type mounter struct{} + +func (mounter) Mount(dir string, mounts ...containerd.Mount) error { + return containerd.MountAll(mounts, dir) +} + +func (mounter) Unmount(dir string) error { + return syscall.Unmount(dir, 0) +} + +func emptyResolver(digest.Digest) digest.Digest { + return digest.Digest("") +} + +func noopRegister(digest.Digest, digest.Digest) error { + return nil +} + +//func (s *Service) Mounts(ctx context.Context, mr *rootfsapi.MountRequest) (*rootfsapi.MountResponse, error) { +// +//} From 38a6f90f2b3d4d87a6c5bbc0bea15d9cbe19da21 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 8 Mar 2017 22:04:44 -0800 Subject: [PATCH 2/7] Add rootfs command to dist Commands allows preparing a rootfs from a manifest hash Signed-off-by: Derek McGowan (github: dmcgowan) --- cmd/containerd/main.go | 3 ++ cmd/dist/main.go | 1 + cmd/dist/rootfs.go | 91 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 cmd/dist/rootfs.go diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index 5b69c6a..bd2d27a 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -19,6 +19,7 @@ import ( "github.com/docker/containerd" contentapi "github.com/docker/containerd/api/services/content" api "github.com/docker/containerd/api/services/execution" + rootfsapi "github.com/docker/containerd/api/services/rootfs" "github.com/docker/containerd/content" "github.com/docker/containerd/log" "github.com/docker/containerd/plugin" @@ -366,6 +367,8 @@ func interceptor(ctx gocontext.Context, ctx = log.WithModule(ctx, "execution") case contentapi.ContentServer: ctx = log.WithModule(ctx, "content") + case rootfsapi.RootFSServer: + ctx = log.WithModule(ctx, "rootfs") default: fmt.Printf("unknown GRPC server type: %#v\n", info.Server) } diff --git a/cmd/dist/main.go b/cmd/dist/main.go index cf96ad5..f29af17 100644 --- a/cmd/dist/main.go +++ b/cmd/dist/main.go @@ -69,6 +69,7 @@ distribution tool deleteCommand, listCommand, applyCommand, + rootfsCommand, } app.Before = func(context *cli.Context) error { var ( diff --git a/cmd/dist/rootfs.go b/cmd/dist/rootfs.go new file mode 100644 index 0000000..e9075c8 --- /dev/null +++ b/cmd/dist/rootfs.go @@ -0,0 +1,91 @@ +package main + +import ( + "context" + "encoding/json" + "io/ioutil" + + contentapi "github.com/docker/containerd/api/services/content" + rootfsapi "github.com/docker/containerd/api/services/rootfs" + "github.com/docker/containerd/content" + "github.com/docker/containerd/log" + contentservice "github.com/docker/containerd/services/content" + rootfsservice "github.com/docker/containerd/services/rootfs" + digest "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/urfave/cli" +) + +var rootfsCommand = cli.Command{ + Name: "rootfs", + Usage: "rootfs setups a rootfs", + Subcommands: []cli.Command{ + rootfsPrepareCommand, + }, +} + +var rootfsPrepareCommand = cli.Command{ + Name: "prepare", + Usage: "prepare applies layers from a manifest to a snapshot", + ArgsUsage: "[flags] ", + Flags: []cli.Flag{}, + Action: func(clicontext *cli.Context) error { + var ( + ctx = background + ) + + dgst, err := digest.Parse(clicontext.Args().First()) + if err != nil { + return err + } + + log.G(ctx).Infof("preparing manifest %s", dgst.String()) + + conn, err := connectGRPC(clicontext) + if err != nil { + return err + } + + provider := contentservice.NewProviderFromClient(contentapi.NewContentClient(conn)) + m, err := resolveManifest(ctx, provider, dgst) + if err != nil { + return err + } + + preparer := rootfsservice.NewPreparerFromClient(rootfsapi.NewRootFSClient(conn)) + chainID, err := preparer.Prepare(ctx, m.Layers) + if err != nil { + return err + } + + log.G(ctx).Infof("chain ID: %s", chainID.String()) + + return nil + }, +} + +func resolveManifest(ctx context.Context, provider content.Provider, dgst digest.Digest) (ocispec.Manifest, error) { + p, err := readAll(ctx, provider, dgst) + if err != nil { + return ocispec.Manifest{}, err + } + + // TODO(stevvooe): This assumption that we get a manifest is unfortunate. + // Need to provide way to resolve what the type of the target is. + var manifest ocispec.Manifest + if err := json.Unmarshal(p, &manifest); err != nil { + return ocispec.Manifest{}, err + } + + return manifest, nil +} + +func readAll(ctx context.Context, provider content.Provider, dgst digest.Digest) ([]byte, error) { + rc, err := provider.Reader(ctx, dgst) + if err != nil { + return nil, err + } + defer rc.Close() + + return ioutil.ReadAll(rc) +} From 5d4577534a2cf04e3527e874351ff3b777329e80 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 9 Mar 2017 18:11:26 -0800 Subject: [PATCH 3/7] Add init and get mounts to rootfs service Update rootfs package to add mount initializer function. Signed-off-by: Derek McGowan (github: dmcgowan) --- api/services/rootfs/rootfs.pb.go | 604 +++++++++++++++++++++++++++++-- api/services/rootfs/rootfs.proto | 33 +- rootfs/init.go | 98 +++++ rootfs/init_linux.go | 114 ++++++ rootfs/init_other.go | 7 + services/rootfs/service.go | 37 +- 6 files changed, 847 insertions(+), 46 deletions(-) create mode 100644 rootfs/init.go create mode 100644 rootfs/init_linux.go create mode 100644 rootfs/init_other.go diff --git a/api/services/rootfs/rootfs.pb.go b/api/services/rootfs/rootfs.pb.go index 6362050..2a04ade 100644 --- a/api/services/rootfs/rootfs.pb.go +++ b/api/services/rootfs/rootfs.pb.go @@ -11,6 +11,9 @@ It has these top-level messages: PrepareRequest PrepareResponse + InitMountsRequest + MountsRequest + MountResponse */ package rootfs @@ -18,8 +21,7 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" import _ "github.com/gogo/protobuf/gogoproto" -import _ "github.com/golang/protobuf/ptypes/empty" -import _ "github.com/docker/containerd/api/types/mount" +import containerd_v1_types "github.com/docker/containerd/api/types/mount" import containerd_v1_types1 "github.com/docker/containerd/api/types/descriptor" import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest" @@ -61,9 +63,38 @@ func (m *PrepareResponse) Reset() { *m = PrepareResponse{} } func (*PrepareResponse) ProtoMessage() {} func (*PrepareResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{1} } +type InitMountsRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,2,opt,name=chainID,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chainID"` + Readonly bool `protobuf:"varint,3,opt,name=Readonly,proto3" json:"Readonly,omitempty"` +} + +func (m *InitMountsRequest) Reset() { *m = InitMountsRequest{} } +func (*InitMountsRequest) ProtoMessage() {} +func (*InitMountsRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{2} } + +type MountsRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *MountsRequest) Reset() { *m = MountsRequest{} } +func (*MountsRequest) ProtoMessage() {} +func (*MountsRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{3} } + +type MountResponse struct { + Mounts []*containerd_v1_types.Mount `protobuf:"bytes,1,rep,name=mounts" json:"mounts,omitempty"` +} + +func (m *MountResponse) Reset() { *m = MountResponse{} } +func (*MountResponse) ProtoMessage() {} +func (*MountResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{4} } + func init() { proto.RegisterType((*PrepareRequest)(nil), "containerd.v1.PrepareRequest") proto.RegisterType((*PrepareResponse)(nil), "containerd.v1.PrepareResponse") + proto.RegisterType((*InitMountsRequest)(nil), "containerd.v1.InitMountsRequest") + proto.RegisterType((*MountsRequest)(nil), "containerd.v1.MountsRequest") + proto.RegisterType((*MountResponse)(nil), "containerd.v1.MountResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -78,6 +109,8 @@ const _ = grpc.SupportPackageIsVersion4 type RootFSClient interface { Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*PrepareResponse, error) + InitMounts(ctx context.Context, in *InitMountsRequest, opts ...grpc.CallOption) (*MountResponse, error) + Mounts(ctx context.Context, in *MountsRequest, opts ...grpc.CallOption) (*MountResponse, error) } type rootFSClient struct { @@ -97,10 +130,30 @@ func (c *rootFSClient) Prepare(ctx context.Context, in *PrepareRequest, opts ... return out, nil } +func (c *rootFSClient) InitMounts(ctx context.Context, in *InitMountsRequest, opts ...grpc.CallOption) (*MountResponse, error) { + out := new(MountResponse) + err := grpc.Invoke(ctx, "/containerd.v1.RootFS/InitMounts", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rootFSClient) Mounts(ctx context.Context, in *MountsRequest, opts ...grpc.CallOption) (*MountResponse, error) { + out := new(MountResponse) + err := grpc.Invoke(ctx, "/containerd.v1.RootFS/Mounts", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for RootFS service type RootFSServer interface { Prepare(context.Context, *PrepareRequest) (*PrepareResponse, error) + InitMounts(context.Context, *InitMountsRequest) (*MountResponse, error) + Mounts(context.Context, *MountsRequest) (*MountResponse, error) } func RegisterRootFSServer(s *grpc.Server, srv RootFSServer) { @@ -125,6 +178,42 @@ func _RootFS_Prepare_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _RootFS_InitMounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InitMountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RootFSServer).InitMounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/containerd.v1.RootFS/InitMounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RootFSServer).InitMounts(ctx, req.(*InitMountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _RootFS_Mounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RootFSServer).Mounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/containerd.v1.RootFS/Mounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RootFSServer).Mounts(ctx, req.(*MountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _RootFS_serviceDesc = grpc.ServiceDesc{ ServiceName: "containerd.v1.RootFS", HandlerType: (*RootFSServer)(nil), @@ -133,6 +222,14 @@ var _RootFS_serviceDesc = grpc.ServiceDesc{ MethodName: "Prepare", Handler: _RootFS_Prepare_Handler, }, + { + MethodName: "InitMounts", + Handler: _RootFS_InitMounts_Handler, + }, + { + MethodName: "Mounts", + Handler: _RootFS_Mounts_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "github.com/docker/containerd/api/services/rootfs/rootfs.proto", @@ -192,6 +289,100 @@ func (m *PrepareResponse) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *InitMountsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *InitMountsRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Name) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintRootfs(dAtA, i, uint64(len(m.Name))) + i += copy(dAtA[i:], m.Name) + } + if len(m.ChainID) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintRootfs(dAtA, i, uint64(len(m.ChainID))) + i += copy(dAtA[i:], m.ChainID) + } + if m.Readonly { + dAtA[i] = 0x18 + i++ + if m.Readonly { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } + return i, nil +} + +func (m *MountsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MountsRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Name) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintRootfs(dAtA, i, uint64(len(m.Name))) + i += copy(dAtA[i:], m.Name) + } + return i, nil +} + +func (m *MountResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MountResponse) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Mounts) > 0 { + for _, msg := range m.Mounts { + dAtA[i] = 0xa + i++ + i = encodeVarintRootfs(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + return i, nil +} + func encodeFixed64Rootfs(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) dAtA[offset+1] = uint8(v >> 8) @@ -241,6 +432,45 @@ func (m *PrepareResponse) Size() (n int) { return n } +func (m *InitMountsRequest) Size() (n int) { + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovRootfs(uint64(l)) + } + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovRootfs(uint64(l)) + } + if m.Readonly { + n += 2 + } + return n +} + +func (m *MountsRequest) Size() (n int) { + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovRootfs(uint64(l)) + } + return n +} + +func (m *MountResponse) Size() (n int) { + var l int + _ = l + if len(m.Mounts) > 0 { + for _, e := range m.Mounts { + l = e.Size() + n += 1 + l + sovRootfs(uint64(l)) + } + } + return n +} + func sovRootfs(x uint64) (n int) { for { n++ @@ -274,6 +504,38 @@ func (this *PrepareResponse) String() string { }, "") return s } +func (this *InitMountsRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&InitMountsRequest{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `ChainID:` + fmt.Sprintf("%v", this.ChainID) + `,`, + `Readonly:` + fmt.Sprintf("%v", this.Readonly) + `,`, + `}`, + }, "") + return s +} +func (this *MountsRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&MountsRequest{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `}`, + }, "") + return s +} +func (this *MountResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&MountResponse{`, + `Mounts:` + strings.Replace(fmt.Sprintf("%v", this.Mounts), "Mount", "containerd_v1_types.Mount", 1) + `,`, + `}`, + }, "") + return s +} func valueToStringRootfs(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -442,6 +704,294 @@ func (m *PrepareResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *InitMountsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: InitMountsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: InitMountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = github_com_opencontainers_go_digest.Digest(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Readonly", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Readonly = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipRootfs(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthRootfs + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MountsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MountsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRootfs(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthRootfs + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MountResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Mounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRootfs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRootfs + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Mounts = append(m.Mounts, &containerd_v1_types.Mount{}) + if err := m.Mounts[len(m.Mounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRootfs(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthRootfs + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipRootfs(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 @@ -552,26 +1102,32 @@ func init() { } var fileDescriptorRootfs = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0x4f, 0xea, 0x40, - 0x10, 0xc6, 0xd9, 0xbc, 0x04, 0xf2, 0xf6, 0xe5, 0xbd, 0x97, 0x34, 0x1e, 0x08, 0xc6, 0x2d, 0xe1, - 0x44, 0x4c, 0xdc, 0x8d, 0x78, 0xd0, 0x0b, 0x17, 0x24, 0x46, 0x6e, 0xa6, 0x1e, 0x3c, 0x97, 0x76, - 0x58, 0x56, 0xa1, 0xb3, 0xee, 0x6e, 0x49, 0xb8, 0xf9, 0xe7, 0x71, 0xf4, 0x68, 0x3c, 0x10, 0xe9, - 0x5f, 0x62, 0x68, 0x0b, 0x82, 0x89, 0xd1, 0x4b, 0x67, 0x9a, 0xef, 0x9b, 0xdf, 0x7c, 0xb3, 0xb4, - 0x2b, 0x95, 0x1b, 0xa7, 0x43, 0x1e, 0xe1, 0x54, 0xc4, 0x18, 0x3d, 0x80, 0x11, 0x11, 0x26, 0x2e, - 0x54, 0x09, 0x98, 0x58, 0x84, 0x5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7a, 0x47, 0x9f, 0x92, - 0xee, 0x1f, 0xd6, 0x60, 0x5f, 0xc9, 0x45, 0xd8, 0x5e, 0x7d, 0xb1, 0x62, 0x95, 0x97, 0x15, 0xab, - 0x3c, 0x65, 0x8c, 0x2c, 0x32, 0x46, 0x9e, 0x33, 0x46, 0xde, 0x32, 0x46, 0x86, 0xd5, 0xfc, 0xad, - 0xce, 0xde, 0x03, 0x00, 0x00, 0xff, 0xff, 0x4c, 0xa2, 0x59, 0x7e, 0x2c, 0x02, 0x00, 0x00, + // 428 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x3f, 0x8f, 0xd3, 0x30, + 0x18, 0xc6, 0x6b, 0x0e, 0xa5, 0x87, 0xd1, 0x81, 0xb0, 0x18, 0xa2, 0x08, 0x92, 0x28, 0x2c, 0x15, + 0x12, 0xb1, 0x28, 0x03, 0x2c, 0xb7, 0xf4, 0x22, 0x44, 0x24, 0x90, 0x50, 0x18, 0x98, 0x73, 0xc9, + 0x4b, 0xce, 0x70, 0xf5, 0x1b, 0x6c, 0xf7, 0xa4, 0x6e, 0x7c, 0x10, 0x3e, 0x50, 0x47, 0x46, 0xc4, + 0x50, 0x71, 0x19, 0xf8, 0x1c, 0xa8, 0xf9, 0x77, 0xd7, 0x52, 0xd4, 0x0e, 0xb7, 0xc4, 0x6f, 0xe4, + 0xe7, 0xfd, 0xbd, 0x8f, 0x1f, 0x9b, 0x1e, 0x17, 0xc2, 0x9c, 0xcd, 0x4e, 0xc3, 0x0c, 0xa7, 0x3c, + 0xc7, 0xec, 0x0b, 0x28, 0x9e, 0xa1, 0x34, 0xa9, 0x90, 0xa0, 0x72, 0x9e, 0x96, 0x82, 0x6b, 0x50, + 0x17, 0x22, 0x03, 0xcd, 0x15, 0xa2, 0xf9, 0xd4, 0x2d, 0x61, 0xa9, 0xd0, 0x20, 0x3b, 0xba, 0x12, + 0x87, 0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0xff, 0xc1, 0x13, 0x7a, 0xb4, 0xd3, 0x59, 0x70, + 0xd2, 0x8a, 0xfa, 0xb4, 0xc6, 0xd4, 0xaa, 0xaf, 0xb7, 0x4b, 0xde, 0xd9, 0x9a, 0x7c, 0xd3, 0xd3, + 0x2a, 0xc7, 0x7f, 0x08, 0xb5, 0x12, 0x44, 0xf3, 0xfa, 0x03, 0x7b, 0x43, 0x87, 0x6d, 0xfe, 0xec, + 0xf1, 0x46, 0xe7, 0xfa, 0x15, 0x3b, 0xee, 0xff, 0xb6, 0x5b, 0x23, 0x6f, 0x29, 0xbd, 0x0a, 0x97, + 0xf9, 0x1b, 0xea, 0x7f, 0x72, 0x77, 0x1e, 0x6d, 0x28, 0xd6, 0x8f, 0x15, 0x51, 0xab, 0x25, 0x6d, + 0xd5, 0xed, 0x47, 0x99, 0xd8, 0x8b, 0x4b, 0x77, 0xf0, 0xf3, 0xd2, 0x1d, 0x7c, 0xab, 0x5c, 0xb2, + 0xa8, 0x5c, 0xf2, 0xa3, 0x72, 0xc9, 0xef, 0xca, 0x25, 0xa7, 0x56, 0xfd, 0x92, 0x5f, 0xfc, 0x0d, + 0x00, 0x00, 0xff, 0xff, 0xca, 0x73, 0x7a, 0x14, 0xad, 0x03, 0x00, 0x00, } diff --git a/api/services/rootfs/rootfs.proto b/api/services/rootfs/rootfs.proto index 866f78a..190e88d 100644 --- a/api/services/rootfs/rootfs.proto +++ b/api/services/rootfs/rootfs.proto @@ -3,16 +3,13 @@ syntax = "proto3"; package containerd.v1; import "gogoproto/gogo.proto"; -import "google/protobuf/empty.proto"; import "github.com/docker/containerd/api/types/mount/mount.proto"; import "github.com/docker/containerd/api/types/descriptor/descriptor.proto"; service RootFS { rpc Prepare(PrepareRequest) returns (PrepareResponse); - - // TODO: Add method for initializing and retrieving mounts - //rpc InitMounts(InitRequest) returns (MountResponse); - //rpc Mounts(MountRequest) returns (MountResponse); + rpc InitMounts(InitMountsRequest) returns (MountResponse); + rpc Mounts(MountsRequest) returns (MountResponse); } message PrepareRequest { @@ -23,16 +20,16 @@ message PrepareResponse { string chainid = 1 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; } -//message InitRequest { -// string name = 1; -// string chainID = 2; -// bool Readonly = 3; -//} -// -//message MountRequest { -// string name = 1; -//} -// -//message MountResponse { -// repeated containerd.v1.types.Mount mounts = 1; -//} +message InitMountsRequest { + string name = 1; + string chainID = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; + bool Readonly = 3; +} + +message MountsRequest { + string name = 1; +} + +message MountResponse { + repeated containerd.v1.types.Mount mounts = 1; +} diff --git a/rootfs/init.go b/rootfs/init.go new file mode 100644 index 0000000..e2fe777 --- /dev/null +++ b/rootfs/init.go @@ -0,0 +1,98 @@ +package rootfs + +import ( + "context" + "fmt" + "io/ioutil" + "os" + + "github.com/docker/containerd" + "github.com/docker/containerd/log" + "github.com/docker/containerd/snapshot" + digest "github.com/opencontainers/go-digest" + "github.com/pkg/errors" +) + +var ( + initializers = map[string]initializerFunc{} +) + +type initializerFunc func(string) error + +func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]containerd.Mount, error) { + _, err := snapshotter.Stat(ctx, name) + if err == nil { + return nil, errors.Errorf("rootfs already exists") + } + // TODO: check if should return error + + parentS := parent.String() + + initName := defaultInitializer + initFn := initializers[initName] + if initFn != nil { + parentS, err = createInitLayer(ctx, parentS, initName, initFn, snapshotter, mounter) + if err != nil { + return nil, err + } + } + + if readonly { + return snapshotter.View(ctx, name, parentS) + } + + return snapshotter.Prepare(ctx, name, parentS) +} + +func GetRootFS(ctx context.Context, name string, snapshotter snapshot.Snapshotter) ([]containerd.Mount, error) { + return snapshotter.Mounts(ctx, name) +} + +func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshot.Snapshotter, mounter Mounter) (string, error) { + initS := fmt.Sprintf("%s %s", parent, initName) + if _, err := snapshotter.Stat(ctx, initS); err == nil { + return initS, nil + } + // TODO: check if should return error + + // Create tempdir + td, err := ioutil.TempDir("", "create-init-") + if err != nil { + return "", err + } + defer os.RemoveAll(td) + + mounts, err := snapshotter.Prepare(ctx, td, parent) + if err != nil { + return "", err + } + defer func() { + if err != nil { + // TODO: once implemented uncomment + //if rerr := snapshotter.Remove(ctx, td); rerr != nil { + // log.G(ctx).Errorf("Failed to remove snapshot %s: %v", td, merr) + //} + } + }() + + if err = mounter.Mount(td, mounts...); err != nil { + return "", err + } + + if err = initFn(td); err != nil { + if merr := mounter.Unmount(td); merr != nil { + log.G(ctx).Errorf("Failed to unmount %s: %v", td, merr) + } + return "", err + } + + if err = mounter.Unmount(td); err != nil { + return "", err + } + + if err := snapshotter.Commit(ctx, initS, td); err != nil { + return "", err + } + + return initS, nil +} diff --git a/rootfs/init_linux.go b/rootfs/init_linux.go new file mode 100644 index 0000000..cabc457 --- /dev/null +++ b/rootfs/init_linux.go @@ -0,0 +1,114 @@ +package rootfs + +import ( + "os" + "path/filepath" + "syscall" +) + +const ( + defaultInitializer = "linux-init" +) + +func init() { + initializers[defaultInitializer] = initFS +} + +func createDirectory(name string, uid, gid int) initializerFunc { + return func(root string) error { + dname := filepath.Join(root, name) + st, err := os.Stat(dname) + if err != nil && !os.IsNotExist(err) { + return err + } else if err == nil { + if st.IsDir() { + stat := st.Sys().(*syscall.Stat_t) + if int(stat.Gid) == gid && int(stat.Uid) == uid { + return nil + } + } else { + if err := os.Remove(dname); err != nil { + return err + } + if err := os.Mkdir(dname, 0755); err != nil { + return err + } + } + } else { + if err := os.Mkdir(dname, 0755); err != nil { + return err + } + } + + return os.Chown(dname, uid, gid) + } +} + +func touchFile(name string, uid, gid int) initializerFunc { + return func(root string) error { + fname := filepath.Join(root, name) + + st, err := os.Stat(fname) + if err != nil && !os.IsNotExist(err) { + return err + } else if err == nil { + stat := st.Sys().(*syscall.Stat_t) + if int(stat.Gid) == gid && int(stat.Uid) == uid { + return nil + } + return os.Chown(fname, uid, gid) + } + + f, err := os.OpenFile(fname, os.O_CREATE, 0644) + if err != nil { + return err + } + defer f.Close() + + return f.Chown(uid, gid) + } +} + +func symlink(oldname, newname string) initializerFunc { + return func(root string) error { + linkName := filepath.Join(root, newname) + if _, err := os.Stat(linkName); err != nil && !os.IsNotExist(err) { + return err + } else if err == nil { + return nil + } + return os.Symlink(oldname, linkName) + } +} + +func initFS(root string) error { + st, err := os.Stat(root) + if err != nil { + return err + } + stat := st.Sys().(*syscall.Stat_t) + uid := int(stat.Uid) + gid := int(stat.Gid) + + initFuncs := []initializerFunc{ + createDirectory("/dev", uid, gid), + createDirectory("/dev/pts", uid, gid), + createDirectory("/dev/shm", uid, gid), + touchFile("/dev/console", uid, gid), + createDirectory("/proc", uid, gid), + createDirectory("/sys", uid, gid), + createDirectory("/etc", uid, gid), + touchFile("/etc/resolv.conf", uid, gid), + touchFile("/etc/hosts", uid, gid), + touchFile("/etc/hostname", uid, gid), + symlink("/proc/mounts", "/etc/mtab"), + } + + for _, fn := range initFuncs { + if err := fn(root); err != nil { + return err + } + } + + return nil +} diff --git a/rootfs/init_other.go b/rootfs/init_other.go new file mode 100644 index 0000000..b5e04e2 --- /dev/null +++ b/rootfs/init_other.go @@ -0,0 +1,7 @@ +// +build !linux + +package rootfs + +const ( + defaultInitializer = "" +) diff --git a/services/rootfs/service.go b/services/rootfs/service.go index 817cbf1..ab6cb72 100644 --- a/services/rootfs/service.go +++ b/services/rootfs/service.go @@ -5,6 +5,7 @@ import ( "github.com/docker/containerd" rootfsapi "github.com/docker/containerd/api/services/rootfs" + containerd_v1_types "github.com/docker/containerd/api/types/mount" "github.com/docker/containerd/content" "github.com/docker/containerd/log" "github.com/docker/containerd/plugin" @@ -63,6 +64,38 @@ func (s *Service) Prepare(ctx context.Context, pr *rootfsapi.PrepareRequest) (*r }, nil } +func (s *Service) InitMounts(ctx context.Context, ir *rootfsapi.InitMountsRequest) (*rootfsapi.MountResponse, error) { + mounts, err := rootfs.InitRootFS(ctx, ir.Name, ir.ChainID, ir.Readonly, s.snapshotter, mounter{}) + if err != nil { + return nil, err + } + return &rootfsapi.MountResponse{ + Mounts: apiMounts(mounts), + }, nil +} + +func (s *Service) Mounts(ctx context.Context, mr *rootfsapi.MountsRequest) (*rootfsapi.MountResponse, error) { + mounts, err := rootfs.GetRootFS(ctx, mr.Name, s.snapshotter) + if err != nil { + return nil, err + } + return &rootfsapi.MountResponse{ + Mounts: apiMounts(mounts), + }, nil +} + +func apiMounts(mounts []containerd.Mount) []*containerd_v1_types.Mount { + am := make([]*containerd_v1_types.Mount, len(mounts)) + for i, m := range mounts { + am[i] = &containerd_v1_types.Mount{ + Type: m.Type, + Source: m.Source, + Options: m.Options, + } + } + return am +} + type mounter struct{} func (mounter) Mount(dir string, mounts ...containerd.Mount) error { @@ -80,7 +113,3 @@ func emptyResolver(digest.Digest) digest.Digest { func noopRegister(digest.Digest, digest.Digest) error { return nil } - -//func (s *Service) Mounts(ctx context.Context, mr *rootfsapi.MountRequest) (*rootfsapi.MountResponse, error) { -// -//} From 3a20dd41d50038da4fd05f3a38aa916c88309627 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 9 Mar 2017 19:50:23 -0800 Subject: [PATCH 4/7] Add init subcommand to rootfs Init command gets the mounts for a given chain id and outputs a mount command. Signed-off-by: Derek McGowan (github: dmcgowan) --- cmd/dist/rootfs.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/cmd/dist/rootfs.go b/cmd/dist/rootfs.go index e9075c8..b77d677 100644 --- a/cmd/dist/rootfs.go +++ b/cmd/dist/rootfs.go @@ -3,7 +3,10 @@ package main import ( "context" "encoding/json" + "fmt" "io/ioutil" + "os" + "strings" contentapi "github.com/docker/containerd/api/services/content" rootfsapi "github.com/docker/containerd/api/services/rootfs" @@ -21,6 +24,7 @@ var rootfsCommand = cli.Command{ Usage: "rootfs setups a rootfs", Subcommands: []cli.Command{ rootfsPrepareCommand, + rootfsInitCommand, }, } @@ -64,6 +68,54 @@ var rootfsPrepareCommand = cli.Command{ }, } +var rootfsInitCommand = cli.Command{ + Name: "init", + Usage: "init gets mount commands for digest", + ArgsUsage: "[flags] ", + Flags: []cli.Flag{}, + Action: func(clicontext *cli.Context) error { + var ( + ctx = background + ) + + if clicontext.NArg() != 2 { + return cli.ShowSubcommandHelp(clicontext) + } + + dgst, err := digest.Parse(clicontext.Args().Get(0)) + if err != nil { + return err + } + target := clicontext.Args().Get(1) + + log.G(ctx).Infof("initializing mounts %s", dgst.String()) + + conn, err := connectGRPC(clicontext) + if err != nil { + return err + } + + rclient := rootfsapi.NewRootFSClient(conn) + + ir := &rootfsapi.InitMountsRequest{ + Name: target, + ChainID: dgst, + } + + resp, err := rclient.InitMounts(ctx, ir) + if err != nil { + return err + } + + for _, m := range resp.Mounts { + fmt.Fprintf(os.Stdout, "mount -t %s %s %s -o %s\n", m.Type, m.Source, target, strings.Join(m.Options, ",")) + } + log.G(ctx).Infof("Mount response: %#v", resp) + + return nil + }, +} + func resolveManifest(ctx context.Context, provider content.Provider, dgst digest.Digest) (ocispec.Manifest, error) { p, err := readAll(ctx, provider, dgst) if err != nil { From 340e56ecd020e6c22616421a07ee2e9db7bd03d7 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 10 Mar 2017 22:05:27 -0800 Subject: [PATCH 5/7] Update comments in rootfs and for desciptor Signed-off-by: Derek McGowan (github: dmcgowan) --- api/types/descriptor/descriptor.proto | 5 +++++ rootfs/init.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/types/descriptor/descriptor.proto b/api/types/descriptor/descriptor.proto index 7a82bd8..99c8ada 100644 --- a/api/types/descriptor/descriptor.proto +++ b/api/types/descriptor/descriptor.proto @@ -4,6 +4,11 @@ package containerd.v1.types; import "gogoproto/gogo.proto"; +// Descriptor describes a blob in a content store. +// +// This descriptor can be used to reference content from an +// oci descriptor found in a manifest. +// See https://godoc.org/github.com/opencontainers/image-spec/specs-go/v1#Descriptor message Descriptor { string mediaType = 1; string digest = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false]; diff --git a/rootfs/init.go b/rootfs/init.go index e2fe777..ebcae81 100644 --- a/rootfs/init.go +++ b/rootfs/init.go @@ -24,7 +24,7 @@ func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly if err == nil { return nil, errors.Errorf("rootfs already exists") } - // TODO: check if should return error + // TODO: ensure not exist error once added to snapshot package parentS := parent.String() @@ -53,7 +53,7 @@ func createInitLayer(ctx context.Context, parent, initName string, initFn func(s if _, err := snapshotter.Stat(ctx, initS); err == nil { return initS, nil } - // TODO: check if should return error + // TODO: ensure not exist error once added to snapshot package // Create tempdir td, err := ioutil.TempDir("", "create-init-") From b1bc82726fac357e226e168210bd6be96d0c7a03 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 14 Mar 2017 23:34:32 -0700 Subject: [PATCH 6/7] Rename prepare to unpack and init to prepare Unpack and prepare better map to the actions done by rootfs. Signed-off-by: Derek McGowan (github: dmcgowan) --- api/services/rootfs/rootfs.pb.go | 215 +++++++++++++------------- api/services/rootfs/rootfs.proto | 14 +- api/types/descriptor/descriptor.pb.go | 45 +++--- api/types/descriptor/descriptor.proto | 2 +- cmd/dist/rootfs.go | 20 +-- rootfs/apply.go | 4 +- services/rootfs/preparer.go | 14 +- services/rootfs/service.go | 8 +- 8 files changed, 164 insertions(+), 158 deletions(-) diff --git a/api/services/rootfs/rootfs.pb.go b/api/services/rootfs/rootfs.pb.go index 2a04ade..50a4893 100644 --- a/api/services/rootfs/rootfs.pb.go +++ b/api/services/rootfs/rootfs.pb.go @@ -9,9 +9,9 @@ github.com/docker/containerd/api/services/rootfs/rootfs.proto It has these top-level messages: + UnpackRequest + UnpackResponse PrepareRequest - PrepareResponse - InitMountsRequest MountsRequest MountResponse */ @@ -47,31 +47,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package -type PrepareRequest struct { +type UnpackRequest struct { Layers []*containerd_v1_types1.Descriptor `protobuf:"bytes,1,rep,name=layers" json:"layers,omitempty"` } +func (m *UnpackRequest) Reset() { *m = UnpackRequest{} } +func (*UnpackRequest) ProtoMessage() {} +func (*UnpackRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{0} } + +type UnpackResponse struct { + ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,1,opt,name=chainid,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chainid"` +} + +func (m *UnpackResponse) Reset() { *m = UnpackResponse{} } +func (*UnpackResponse) ProtoMessage() {} +func (*UnpackResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{1} } + +type PrepareRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chain_id"` + Readonly bool `protobuf:"varint,3,opt,name=readonly,proto3" json:"readonly,omitempty"` +} + func (m *PrepareRequest) Reset() { *m = PrepareRequest{} } func (*PrepareRequest) ProtoMessage() {} -func (*PrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{0} } - -type PrepareResponse struct { - ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,1,opt,name=chainid,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chainid"` -} - -func (m *PrepareResponse) Reset() { *m = PrepareResponse{} } -func (*PrepareResponse) ProtoMessage() {} -func (*PrepareResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{1} } - -type InitMountsRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - ChainID github_com_opencontainers_go_digest.Digest `protobuf:"bytes,2,opt,name=chainID,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"chainID"` - Readonly bool `protobuf:"varint,3,opt,name=Readonly,proto3" json:"Readonly,omitempty"` -} - -func (m *InitMountsRequest) Reset() { *m = InitMountsRequest{} } -func (*InitMountsRequest) ProtoMessage() {} -func (*InitMountsRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{2} } +func (*PrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{2} } type MountsRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -90,9 +90,9 @@ func (*MountResponse) ProtoMessage() {} func (*MountResponse) Descriptor() ([]byte, []int) { return fileDescriptorRootfs, []int{4} } func init() { + proto.RegisterType((*UnpackRequest)(nil), "containerd.v1.UnpackRequest") + proto.RegisterType((*UnpackResponse)(nil), "containerd.v1.UnpackResponse") proto.RegisterType((*PrepareRequest)(nil), "containerd.v1.PrepareRequest") - proto.RegisterType((*PrepareResponse)(nil), "containerd.v1.PrepareResponse") - proto.RegisterType((*InitMountsRequest)(nil), "containerd.v1.InitMountsRequest") proto.RegisterType((*MountsRequest)(nil), "containerd.v1.MountsRequest") proto.RegisterType((*MountResponse)(nil), "containerd.v1.MountResponse") } @@ -108,8 +108,8 @@ const _ = grpc.SupportPackageIsVersion4 // Client API for RootFS service type RootFSClient interface { - Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*PrepareResponse, error) - InitMounts(ctx context.Context, in *InitMountsRequest, opts ...grpc.CallOption) (*MountResponse, error) + Unpack(ctx context.Context, in *UnpackRequest, opts ...grpc.CallOption) (*UnpackResponse, error) + Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*MountResponse, error) Mounts(ctx context.Context, in *MountsRequest, opts ...grpc.CallOption) (*MountResponse, error) } @@ -121,18 +121,18 @@ func NewRootFSClient(cc *grpc.ClientConn) RootFSClient { return &rootFSClient{cc} } -func (c *rootFSClient) Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*PrepareResponse, error) { - out := new(PrepareResponse) - err := grpc.Invoke(ctx, "/containerd.v1.RootFS/Prepare", in, out, c.cc, opts...) +func (c *rootFSClient) Unpack(ctx context.Context, in *UnpackRequest, opts ...grpc.CallOption) (*UnpackResponse, error) { + out := new(UnpackResponse) + err := grpc.Invoke(ctx, "/containerd.v1.RootFS/Unpack", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } -func (c *rootFSClient) InitMounts(ctx context.Context, in *InitMountsRequest, opts ...grpc.CallOption) (*MountResponse, error) { +func (c *rootFSClient) Prepare(ctx context.Context, in *PrepareRequest, opts ...grpc.CallOption) (*MountResponse, error) { out := new(MountResponse) - err := grpc.Invoke(ctx, "/containerd.v1.RootFS/InitMounts", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.v1.RootFS/Prepare", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -151,8 +151,8 @@ func (c *rootFSClient) Mounts(ctx context.Context, in *MountsRequest, opts ...gr // Server API for RootFS service type RootFSServer interface { - Prepare(context.Context, *PrepareRequest) (*PrepareResponse, error) - InitMounts(context.Context, *InitMountsRequest) (*MountResponse, error) + Unpack(context.Context, *UnpackRequest) (*UnpackResponse, error) + Prepare(context.Context, *PrepareRequest) (*MountResponse, error) Mounts(context.Context, *MountsRequest) (*MountResponse, error) } @@ -160,6 +160,24 @@ func RegisterRootFSServer(s *grpc.Server, srv RootFSServer) { s.RegisterService(&_RootFS_serviceDesc, srv) } +func _RootFS_Unpack_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UnpackRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RootFSServer).Unpack(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/containerd.v1.RootFS/Unpack", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RootFSServer).Unpack(ctx, req.(*UnpackRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _RootFS_Prepare_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(PrepareRequest) if err := dec(in); err != nil { @@ -178,24 +196,6 @@ func _RootFS_Prepare_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } -func _RootFS_InitMounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(InitMountsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RootFSServer).InitMounts(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/containerd.v1.RootFS/InitMounts", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RootFSServer).InitMounts(ctx, req.(*InitMountsRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _RootFS_Mounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MountsRequest) if err := dec(in); err != nil { @@ -219,12 +219,12 @@ var _RootFS_serviceDesc = grpc.ServiceDesc{ HandlerType: (*RootFSServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Prepare", - Handler: _RootFS_Prepare_Handler, + MethodName: "Unpack", + Handler: _RootFS_Unpack_Handler, }, { - MethodName: "InitMounts", - Handler: _RootFS_InitMounts_Handler, + MethodName: "Prepare", + Handler: _RootFS_Prepare_Handler, }, { MethodName: "Mounts", @@ -235,7 +235,7 @@ var _RootFS_serviceDesc = grpc.ServiceDesc{ Metadata: "github.com/docker/containerd/api/services/rootfs/rootfs.proto", } -func (m *PrepareRequest) Marshal() (dAtA []byte, err error) { +func (m *UnpackRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalTo(dAtA) @@ -245,7 +245,7 @@ func (m *PrepareRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PrepareRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *UnpackRequest) MarshalTo(dAtA []byte) (int, error) { var i int _ = i var l int @@ -265,7 +265,7 @@ func (m *PrepareRequest) MarshalTo(dAtA []byte) (int, error) { return i, nil } -func (m *PrepareResponse) Marshal() (dAtA []byte, err error) { +func (m *UnpackResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalTo(dAtA) @@ -275,7 +275,7 @@ func (m *PrepareResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PrepareResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *UnpackResponse) MarshalTo(dAtA []byte) (int, error) { var i int _ = i var l int @@ -289,7 +289,7 @@ func (m *PrepareResponse) MarshalTo(dAtA []byte) (int, error) { return i, nil } -func (m *InitMountsRequest) Marshal() (dAtA []byte, err error) { +func (m *PrepareRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalTo(dAtA) @@ -299,7 +299,7 @@ func (m *InitMountsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *InitMountsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *PrepareRequest) MarshalTo(dAtA []byte) (int, error) { var i int _ = i var l int @@ -410,7 +410,7 @@ func encodeVarintRootfs(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return offset + 1 } -func (m *PrepareRequest) Size() (n int) { +func (m *UnpackRequest) Size() (n int) { var l int _ = l if len(m.Layers) > 0 { @@ -422,7 +422,7 @@ func (m *PrepareRequest) Size() (n int) { return n } -func (m *PrepareResponse) Size() (n int) { +func (m *UnpackResponse) Size() (n int) { var l int _ = l l = len(m.ChainID) @@ -432,7 +432,7 @@ func (m *PrepareResponse) Size() (n int) { return n } -func (m *InitMountsRequest) Size() (n int) { +func (m *PrepareRequest) Size() (n int) { var l int _ = l l = len(m.Name) @@ -484,31 +484,31 @@ func sovRootfs(x uint64) (n int) { func sozRootfs(x uint64) (n int) { return sovRootfs(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *PrepareRequest) String() string { +func (this *UnpackRequest) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&PrepareRequest{`, + s := strings.Join([]string{`&UnpackRequest{`, `Layers:` + strings.Replace(fmt.Sprintf("%v", this.Layers), "Descriptor", "containerd_v1_types1.Descriptor", 1) + `,`, `}`, }, "") return s } -func (this *PrepareResponse) String() string { +func (this *UnpackResponse) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&PrepareResponse{`, + s := strings.Join([]string{`&UnpackResponse{`, `ChainID:` + fmt.Sprintf("%v", this.ChainID) + `,`, `}`, }, "") return s } -func (this *InitMountsRequest) String() string { +func (this *PrepareRequest) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&InitMountsRequest{`, + s := strings.Join([]string{`&PrepareRequest{`, `Name:` + fmt.Sprintf("%v", this.Name) + `,`, `ChainID:` + fmt.Sprintf("%v", this.ChainID) + `,`, `Readonly:` + fmt.Sprintf("%v", this.Readonly) + `,`, @@ -544,7 +544,7 @@ func valueToStringRootfs(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } -func (m *PrepareRequest) Unmarshal(dAtA []byte) error { +func (m *UnpackRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -567,10 +567,10 @@ func (m *PrepareRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PrepareRequest: wiretype end group for non-group") + return fmt.Errorf("proto: UnpackRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PrepareRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: UnpackRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -625,7 +625,7 @@ func (m *PrepareRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *PrepareResponse) Unmarshal(dAtA []byte) error { +func (m *UnpackResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -648,10 +648,10 @@ func (m *PrepareResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PrepareResponse: wiretype end group for non-group") + return fmt.Errorf("proto: UnpackResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PrepareResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: UnpackResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -704,7 +704,7 @@ func (m *PrepareResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *InitMountsRequest) Unmarshal(dAtA []byte) error { +func (m *PrepareRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -727,10 +727,10 @@ func (m *InitMountsRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: InitMountsRequest: wiretype end group for non-group") + return fmt.Errorf("proto: PrepareRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: InitMountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: PrepareRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1102,32 +1102,33 @@ func init() { } var fileDescriptorRootfs = []byte{ - // 428 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x3f, 0x8f, 0xd3, 0x30, - 0x18, 0xc6, 0x6b, 0x0e, 0xa5, 0x87, 0xd1, 0x81, 0xb0, 0x18, 0xa2, 0x08, 0x92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f0, 0xf3, 0xd2, 0x1d, 0x7c, 0xab, 0x5c, 0xb2, - 0xa8, 0x5c, 0xf2, 0xa3, 0x72, 0xc9, 0xef, 0xca, 0x25, 0xa7, 0x56, 0xfd, 0x92, 0x5f, 0xfc, 0x0d, - 0x00, 0x00, 0xff, 0xff, 0xca, 0x73, 0x7a, 0x14, 0xad, 0x03, 0x00, 0x00, + // 433 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x6f, 0x13, 0x31, + 0x10, 0x8d, 0x29, 0xda, 0x04, 0xa3, 0xf4, 0x60, 0x71, 0x58, 0xad, 0x60, 0x13, 0x2d, 0x97, 0x08, + 0x89, 0xb5, 0x08, 0x07, 0xb8, 0xf4, 0x92, 0x86, 0x8a, 0x1e, 0x90, 0xd0, 0x22, 0x04, 0x37, 0xe4, + 0xae, 0x87, 0xad, 0xd5, 0xc6, 0x63, 0x6c, 0xa7, 0x52, 0x6e, 0xfc, 0x0e, 0x7e, 0x51, 0x8e, 0x1c, + 0x11, 0x12, 0x11, 0xdd, 0x5f, 0x82, 0xb2, 0x1f, 0xa1, 0x89, 0x0a, 0xf4, 0xc0, 0x65, 0x3d, 0x2b, + 0xbf, 0xf7, 0xe6, 0xcd, 0x1b, 0xd3, 0x83, 0x42, 0xf9, 0xd3, 0xf9, 0x49, 0x9a, 0xe3, 0x8c, 0x4b, + 0xcc, 0xcf, 0xc0, 0xf2, 0x1c, 0xb5, 0x17, 0x4a, 0x83, 0x95, 0x5c, 0x18, 0xc5, 0x1d, 0xd8, 0x0b, + 0x95, 0x83, 0xe3, 0x16, 0xd1, 0x7f, 0x6c, 0x8f, 0xd4, 0x58, 0xf4, 0xc8, 0xfa, 0xbf, 0xc1, 0xe9, + 0xc5, 0x93, 0xe8, 0x5e, 0x81, 0x05, 0x56, 0x37, 0x7c, 0x5d, 0xd5, 0xa0, 0xe8, 0xf9, 0x3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, 0xe4, 0xb0, 0x01, 0x6d, 0xb2, 0x1a, 0xd3, 0xa0, 0x5a, 0x6d, 0x1b, 0x7b, + 0x74, 0x6d, 0xec, 0x35, 0xa7, 0x41, 0x8e, 0x7f, 0x10, 0x1a, 0x64, 0x88, 0xfe, 0xe8, 0x0d, 0x7b, + 0x41, 0x83, 0x3a, 0x7c, 0x76, 0x7f, 0x87, 0xb8, 0xb5, 0xdd, 0xe8, 0xc1, 0x1f, 0x6e, 0x1b, 0x17, + 0x47, 0xb4, 0xdb, 0xe4, 0xca, 0x76, 0x91, 0xdb, 0x79, 0x47, 0xbb, 0x6d, 0xb6, 0xa7, 0x99, 0xd2, + 0xa0, 0xce, 0x80, 0x5d, 0x8b, 0x73, 0x37, 0x52, 0x99, 0x84, 0xcb, 0xcb, 0xb8, 0xf3, 0xed, 0x32, + 0xee, 0x7c, 0x2e, 0x63, 0xb2, 0x2c, 0x63, 0xf2, 0xb5, 0x8c, 0xc9, 0xcf, 0x32, 0x26, 0x27, 0x41, + 0xf5, 0x78, 0x9f, 0xfe, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x52, 0xeb, 0x01, 0xe0, 0xa0, 0x03, 0x00, + 0x00, } diff --git a/api/services/rootfs/rootfs.proto b/api/services/rootfs/rootfs.proto index 190e88d..070f097 100644 --- a/api/services/rootfs/rootfs.proto +++ b/api/services/rootfs/rootfs.proto @@ -7,23 +7,23 @@ import "github.com/docker/containerd/api/types/mount/mount.proto"; import "github.com/docker/containerd/api/types/descriptor/descriptor.proto"; service RootFS { - rpc Prepare(PrepareRequest) returns (PrepareResponse); - rpc InitMounts(InitMountsRequest) returns (MountResponse); + rpc Unpack(UnpackRequest) returns (UnpackResponse); + rpc Prepare(PrepareRequest) returns (MountResponse); rpc Mounts(MountsRequest) returns (MountResponse); } -message PrepareRequest { +message UnpackRequest { repeated containerd.v1.types.Descriptor layers = 1; } -message PrepareResponse { +message UnpackResponse { string chainid = 1 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; } -message InitMountsRequest { +message PrepareRequest { string name = 1; - string chainID = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; - bool Readonly = 3; + string chain_id = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false, (gogoproto.customname) = "ChainID"]; + bool readonly = 3; } message MountsRequest { diff --git a/api/types/descriptor/descriptor.pb.go b/api/types/descriptor/descriptor.pb.go index 6c1b662..b924742 100644 --- a/api/types/descriptor/descriptor.pb.go +++ b/api/types/descriptor/descriptor.pb.go @@ -36,10 +36,15 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +// Descriptor describes a blob in a content store. +// +// This descriptor can be used to reference content from an +// oci descriptor found in a manifest. +// See https://godoc.org/github.com/opencontainers/image-spec/specs-go/v1#Descriptor type Descriptor struct { MediaType string `protobuf:"bytes,1,opt,name=mediaType,proto3" json:"mediaType,omitempty"` Digest github_com_opencontainers_go_digest.Digest `protobuf:"bytes,2,opt,name=digest,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"digest"` - MediaSize int64 `protobuf:"varint,3,opt,name=mediaSize,proto3" json:"mediaSize,omitempty"` + Size_ int64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` } func (m *Descriptor) Reset() { *m = Descriptor{} } @@ -76,10 +81,10 @@ func (m *Descriptor) MarshalTo(dAtA []byte) (int, error) { i = encodeVarintDescriptor(dAtA, i, uint64(len(m.Digest))) i += copy(dAtA[i:], m.Digest) } - if m.MediaSize != 0 { + if m.Size_ != 0 { dAtA[i] = 0x18 i++ - i = encodeVarintDescriptor(dAtA, i, uint64(m.MediaSize)) + i = encodeVarintDescriptor(dAtA, i, uint64(m.Size_)) } return i, nil } @@ -122,8 +127,8 @@ func (m *Descriptor) Size() (n int) { if l > 0 { n += 1 + l + sovDescriptor(uint64(l)) } - if m.MediaSize != 0 { - n += 1 + sovDescriptor(uint64(m.MediaSize)) + if m.Size_ != 0 { + n += 1 + sovDescriptor(uint64(m.Size_)) } return n } @@ -148,7 +153,7 @@ func (this *Descriptor) String() string { s := strings.Join([]string{`&Descriptor{`, `MediaType:` + fmt.Sprintf("%v", this.MediaType) + `,`, `Digest:` + fmt.Sprintf("%v", this.Digest) + `,`, - `MediaSize:` + fmt.Sprintf("%v", this.MediaSize) + `,`, + `Size_:` + fmt.Sprintf("%v", this.Size_) + `,`, `}`, }, "") return s @@ -250,9 +255,9 @@ func (m *Descriptor) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MediaSize", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Size_", wireType) } - m.MediaSize = 0 + m.Size_ = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDescriptor @@ -262,7 +267,7 @@ func (m *Descriptor) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.MediaSize |= (int64(b) & 0x7F) << shift + m.Size_ |= (int64(b) & 0x7F) << shift if b < 0x80 { break } @@ -398,20 +403,20 @@ func init() { } var fileDescriptorDescriptor = []byte{ - // 230 bytes of a gzipped FileDescriptorProto + // 231 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x72, 0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xc9, 0x4f, 0xce, 0x4e, 0x2d, 0xd2, 0x4f, 0xce, 0xcf, 0x2b, 0x49, 0xcc, 0xcc, 0x4b, 0x2d, 0x4a, 0xd1, 0x4f, 0x2c, 0xc8, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x4f, 0x49, 0x2d, 0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0x41, 0x2c, 0x88, 0x52, 0xa5, 0x2e, 0x46, 0x2e, + 0x2e, 0x17, 0xb8, 0x7e, 0x21, 0x19, 0x2e, 0xce, 0xdc, 0xd4, 0x94, 0xcc, 0xc4, 0x90, 0xca, 0x82, + 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x84, 0x80, 0x90, 0x17, 0x17, 0x5b, 0x4a, 0x66, + 0x7a, 0x6a, 0x71, 0x89, 0x04, 0x13, 0x48, 0xca, 0xc9, 0xe8, 0xc4, 0x3d, 0x79, 0x86, 0x5b, 0xf7, + 0xe4, 0xb5, 0x90, 0xdc, 0x9c, 0x5f, 0x90, 0x9a, 0x07, 0xb7, 0xbe, 0x58, 0x3f, 0x3d, 0x5f, 0x17, + 0xa2, 0x45, 0xcf, 0x05, 0x4c, 0x05, 0x41, 0x4d, 0x10, 0x12, 0xe2, 0x62, 0x29, 0xce, 0xac, 0x4a, + 0x95, 0x60, 0x56, 0x60, 0xd4, 0x60, 0x0e, 0x02, 0xb3, 0x9d, 0x24, 0x4e, 0x3c, 0x94, 0x63, 0xb8, + 0xf1, 0x50, 0x8e, 0xa1, 0xe1, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, + 0x3e, 0x78, 0x24, 0xc7, 0x98, 0xc4, 0x06, 0x76, 0xad, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x37, + 0xe8, 0x43, 0x79, 0x1e, 0x01, 0x00, 0x00, } diff --git a/api/types/descriptor/descriptor.proto b/api/types/descriptor/descriptor.proto index 99c8ada..e44244e 100644 --- a/api/types/descriptor/descriptor.proto +++ b/api/types/descriptor/descriptor.proto @@ -12,5 +12,5 @@ import "gogoproto/gogo.proto"; message Descriptor { string mediaType = 1; string digest = 2 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false]; - int64 mediaSize = 3; + int64 size = 3; } diff --git a/cmd/dist/rootfs.go b/cmd/dist/rootfs.go index b77d677..bff3271 100644 --- a/cmd/dist/rootfs.go +++ b/cmd/dist/rootfs.go @@ -29,8 +29,8 @@ var rootfsCommand = cli.Command{ } var rootfsPrepareCommand = cli.Command{ - Name: "prepare", - Usage: "prepare applies layers from a manifest to a snapshot", + Name: "unpack", + Usage: "unpack applies layers from a manifest to a snapshot", ArgsUsage: "[flags] ", Flags: []cli.Flag{}, Action: func(clicontext *cli.Context) error { @@ -43,7 +43,7 @@ var rootfsPrepareCommand = cli.Command{ return err } - log.G(ctx).Infof("preparing manifest %s", dgst.String()) + log.G(ctx).Infof("unpacking layers from manifest %s", dgst.String()) conn, err := connectGRPC(clicontext) if err != nil { @@ -56,8 +56,8 @@ var rootfsPrepareCommand = cli.Command{ return err } - preparer := rootfsservice.NewPreparerFromClient(rootfsapi.NewRootFSClient(conn)) - chainID, err := preparer.Prepare(ctx, m.Layers) + unpacker := rootfsservice.NewUnpackerFromClient(rootfsapi.NewRootFSClient(conn)) + chainID, err := unpacker.Unpack(ctx, m.Layers) if err != nil { return err } @@ -69,8 +69,8 @@ var rootfsPrepareCommand = cli.Command{ } var rootfsInitCommand = cli.Command{ - Name: "init", - Usage: "init gets mount commands for digest", + Name: "prepare", + Usage: "prepare gets mount commands for digest", ArgsUsage: "[flags] ", Flags: []cli.Flag{}, Action: func(clicontext *cli.Context) error { @@ -88,7 +88,7 @@ var rootfsInitCommand = cli.Command{ } target := clicontext.Args().Get(1) - log.G(ctx).Infof("initializing mounts %s", dgst.String()) + log.G(ctx).Infof("preparing mounts %s", dgst.String()) conn, err := connectGRPC(clicontext) if err != nil { @@ -97,12 +97,12 @@ var rootfsInitCommand = cli.Command{ rclient := rootfsapi.NewRootFSClient(conn) - ir := &rootfsapi.InitMountsRequest{ + ir := &rootfsapi.PrepareRequest{ Name: target, ChainID: dgst, } - resp, err := rclient.InitMounts(ctx, ir) + resp, err := rclient.Prepare(ctx, ir) if err != nil { return err } diff --git a/rootfs/apply.go b/rootfs/apply.go index acbb77c..f53e553 100644 --- a/rootfs/apply.go +++ b/rootfs/apply.go @@ -16,8 +16,8 @@ import ( "github.com/pkg/errors" ) -type Preparer interface { - Prepare(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) +type Unpacker interface { + Unpack(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) } type Mounter interface { diff --git a/services/rootfs/preparer.go b/services/rootfs/preparer.go index 40d3c7d..52ad489 100644 --- a/services/rootfs/preparer.go +++ b/services/rootfs/preparer.go @@ -10,28 +10,28 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) -func NewPreparerFromClient(client rootfsapi.RootFSClient) rootfs.Preparer { - return remotePreparer{ +func NewUnpackerFromClient(client rootfsapi.RootFSClient) rootfs.Unpacker { + return remoteUnpacker{ client: client, } } -type remotePreparer struct { +type remoteUnpacker struct { client rootfsapi.RootFSClient } -func (rp remotePreparer) Prepare(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) { - pr := rootfsapi.PrepareRequest{ +func (rp remoteUnpacker) Unpack(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) { + pr := rootfsapi.UnpackRequest{ Layers: make([]*containerd_v1_types.Descriptor, len(layers)), } for i, l := range layers { pr.Layers[i] = &containerd_v1_types.Descriptor{ MediaType: l.MediaType, Digest: l.Digest, - MediaSize: l.Size, + Size_: l.Size, } } - resp, err := rp.client.Prepare(ctx, &pr) + resp, err := rp.client.Unpack(ctx, &pr) if err != nil { return "", nil } diff --git a/services/rootfs/service.go b/services/rootfs/service.go index ab6cb72..362b526 100644 --- a/services/rootfs/service.go +++ b/services/rootfs/service.go @@ -43,13 +43,13 @@ func (s *Service) Register(gs *grpc.Server) error { return nil } -func (s *Service) Prepare(ctx context.Context, pr *rootfsapi.PrepareRequest) (*rootfsapi.PrepareResponse, error) { +func (s *Service) Unpack(ctx context.Context, pr *rootfsapi.UnpackRequest) (*rootfsapi.UnpackResponse, error) { layers := make([]ocispec.Descriptor, len(pr.Layers)) for i, l := range pr.Layers { layers[i] = ocispec.Descriptor{ MediaType: l.MediaType, Digest: l.Digest, - Size: l.MediaSize, + Size: l.Size_, } } log.G(ctx).Infof("Preparing %#v", layers) @@ -59,12 +59,12 @@ func (s *Service) Prepare(ctx context.Context, pr *rootfsapi.PrepareRequest) (*r return nil, err } log.G(ctx).Infof("ChainID %#v", chainID) - return &rootfsapi.PrepareResponse{ + return &rootfsapi.UnpackResponse{ ChainID: chainID, }, nil } -func (s *Service) InitMounts(ctx context.Context, ir *rootfsapi.InitMountsRequest) (*rootfsapi.MountResponse, error) { +func (s *Service) Prepare(ctx context.Context, ir *rootfsapi.PrepareRequest) (*rootfsapi.MountResponse, error) { mounts, err := rootfs.InitRootFS(ctx, ir.Name, ir.ChainID, ir.Readonly, s.snapshotter, mounter{}) if err != nil { return nil, err From 212efa578a2bdd0e3686acb4a1cfd5ae27360fef Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 15 Mar 2017 16:13:15 -0700 Subject: [PATCH 7/7] Remove get function from rootfs The service can use the snapshotter directly to get the rootfs. Removed debug line for mount response. Signed-off-by: Derek McGowan (github: dmcgowan) --- cmd/dist/rootfs.go | 1 - rootfs/init.go | 4 ---- services/rootfs/service.go | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/dist/rootfs.go b/cmd/dist/rootfs.go index bff3271..ca4e40e 100644 --- a/cmd/dist/rootfs.go +++ b/cmd/dist/rootfs.go @@ -110,7 +110,6 @@ var rootfsInitCommand = cli.Command{ for _, m := range resp.Mounts { fmt.Fprintf(os.Stdout, "mount -t %s %s %s -o %s\n", m.Type, m.Source, target, strings.Join(m.Options, ",")) } - log.G(ctx).Infof("Mount response: %#v", resp) return nil }, diff --git a/rootfs/init.go b/rootfs/init.go index ebcae81..4acbf7e 100644 --- a/rootfs/init.go +++ b/rootfs/init.go @@ -44,10 +44,6 @@ func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly return snapshotter.Prepare(ctx, name, parentS) } -func GetRootFS(ctx context.Context, name string, snapshotter snapshot.Snapshotter) ([]containerd.Mount, error) { - return snapshotter.Mounts(ctx, name) -} - func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshot.Snapshotter, mounter Mounter) (string, error) { initS := fmt.Sprintf("%s %s", parent, initName) if _, err := snapshotter.Stat(ctx, initS); err == nil { diff --git a/services/rootfs/service.go b/services/rootfs/service.go index 362b526..21c98ca 100644 --- a/services/rootfs/service.go +++ b/services/rootfs/service.go @@ -75,7 +75,7 @@ func (s *Service) Prepare(ctx context.Context, ir *rootfsapi.PrepareRequest) (*r } func (s *Service) Mounts(ctx context.Context, mr *rootfsapi.MountsRequest) (*rootfsapi.MountResponse, error) { - mounts, err := rootfs.GetRootFS(ctx, mr.Name, s.snapshotter) + mounts, err := s.snapshotter.Mounts(ctx, mr.Name) if err != nil { return nil, err }