Skip to content

Commit 7649f00

Browse files
authored
Merge pull request #283 from kzys/read-only
The rootfs of a microVM should be read-only
2 parents e30ccec + 96c7417 commit 7649f00

10 files changed

+137
-89
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/docker/go-events v0.0.0-20170721190031-9461782956ad // indirect
1919
github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 // indirect
2020
github.com/docker/go-units v0.3.3
21-
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20190920221449-6afccc1d121f
21+
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20191014182425-56995a05946a
2222
github.com/go-ole/go-ole v1.2.4 // indirect
2323
github.com/godbus/dbus v0.0.0-20181025153459-66d97aec3384 // indirect
2424
github.com/gofrs/uuid v3.2.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 h1:X0fj836zx99zF
5959
github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82/go.mod h1:/u0gXw0Gay3ceNrsHubL3BtdOL2fHf93USgMTe0W5dI=
6060
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
6161
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
62-
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20190920221449-6afccc1d121f h1:G81Ey0lQDWCqwdIRq6aLN5RyYbnSDx2O7FKFl433shc=
63-
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20190920221449-6afccc1d121f/go.mod h1:tVXziw7GjioCKVjI5/agymYxUaqJM6q7cp9e6kwjo8Q=
62+
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20191014182425-56995a05946a h1:WK1TpnYdiXA8Kb5UMMkybaZtlo+F1a2QeBmqCJHWeTE=
63+
github.com/firecracker-microvm/firecracker-go-sdk v0.17.1-0.20191014182425-56995a05946a/go.mod h1:tVXziw7GjioCKVjI5/agymYxUaqJM6q7cp9e6kwjo8Q=
6464
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvUbuvHW93esHg7F8N/OYeBBcJoTr0=
6565
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
6666
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=

proto/types.pb.go

Lines changed: 52 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/types.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ message FirecrackerMachineConfiguration {
108108

109109
// Message to specify the block device config for a Firecracker VM
110110
message FirecrackerDrive {
111-
bool IsReadOnly = 1; // Specifies if the drive is read only
111+
bool IsWritable = 1; // Specifies if the drive is writable from a guest
112112
bool IsRootDevice = 2; // Specifies if the drive is the root device
113113
string Partuuid = 3; // Specifies the unique id of the boot partition on this device
114114
string PathOnHost = 4; // Specifies the host level path for the guest drive

runtime/cni_integ_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func TestCNISupport_Isolated(t *testing.T) {
9494
},
9595
RootDrive: &proto.FirecrackerDrive{
9696
PathOnHost: defaultVMRootfsPath,
97-
IsReadOnly: false,
9897
IsRootDevice: true,
9998
},
10099
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{{
@@ -269,7 +268,6 @@ func TestCNIPlugin_Performance(t *testing.T) {
269268
},
270269
RootDrive: &proto.FirecrackerDrive{
271270
PathOnHost: defaultVMRootfsPath,
272-
IsReadOnly: false,
273271
IsRootDevice: true,
274272
},
275273
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{{

runtime/helpers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func addDriveFromProto(builder firecracker.DrivesBuilder, drive *proto.Firecrack
122122
}
123123
}
124124

125-
return builder.AddDrive(drive.PathOnHost, drive.IsReadOnly, opt)
125+
return builder.AddDrive(drive.PathOnHost, !drive.IsWritable, opt)
126126
}
127127

128128
// rateLimiterFromProto creates a firecracker RateLimiter object from the
@@ -140,6 +140,15 @@ func rateLimiterFromProto(rl *proto.FirecrackerRateLimiter) *models.RateLimiter
140140
return &result
141141
}
142142

143+
func withRateLimiterFromProto(rl *proto.FirecrackerRateLimiter) firecracker.DriveOpt {
144+
if rl == nil {
145+
return func(d *models.Drive) {
146+
// no-op
147+
}
148+
}
149+
return firecracker.WithRateLimiter(*rateLimiterFromProto(rl))
150+
}
151+
143152
// tokenBucketFromProto creates a firecracker TokenBucket object from the
144153
// protobuf message.
145154
func tokenBucketFromProto(bucket *proto.FirecrackerTokenBucket) *models.TokenBucket {

runtime/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func TestTokenBucketFromProto(t *testing.T) {
210210

211211
func TestAddDriveFromProto(t *testing.T) {
212212
list := addDriveFromProto(firecracker.DrivesBuilder{}, &proto.FirecrackerDrive{
213-
IsReadOnly: true,
213+
IsWritable: false,
214214
PathOnHost: "/a",
215215
Partuuid: "xy",
216216
}).Build()

runtime/service.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/containerd/fifo"
4141
"github.com/containerd/ttrpc"
4242
"github.com/firecracker-microvm/firecracker-go-sdk"
43+
"github.com/firecracker-microvm/firecracker-go-sdk/client/models"
4344
"github.com/gofrs/uuid"
4445
ptypes "github.com/gogo/protobuf/types"
4546
"github.com/golang/protobuf/ptypes/empty"
@@ -638,27 +639,13 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
638639
containerCount = 1
639640
}
640641

641-
// Create stub drives first and let stub driver handler manage the drives
642-
handler, err := newStubDriveHandler(s.shimDir.RootPath(), s.logger, containerCount)
642+
stubDriveHandler, err := newStubDriveHandler(s.shimDir.RootPath(), s.logger, containerCount)
643643
if err != nil {
644644
return nil, errors.Wrap(err, "failed to create stub drives")
645645
}
646-
s.stubDriveHandler = handler
646+
s.stubDriveHandler = stubDriveHandler
647647

648-
var driveBuilder firecracker.DrivesBuilder
649-
// Create non-stub drives
650-
if root := req.RootDrive; root != nil {
651-
driveBuilder = firecracker.NewDrivesBuilder(root.PathOnHost)
652-
} else {
653-
driveBuilder = firecracker.NewDrivesBuilder(s.config.RootDrive)
654-
}
655-
656-
for _, drive := range req.AdditionalDrives {
657-
driveBuilder = addDriveFromProto(driveBuilder, drive)
658-
}
659-
660-
// a micro VM must know all drives
661-
cfg.Drives = append(handler.GetDrives(), driveBuilder.Build()...)
648+
cfg.Drives = append(stubDriveHandler.GetDrives(), s.buildNonStubDrives(req)...)
662649

663650
// If no value for NetworkInterfaces was specified (not even an empty but non-nil list) and
664651
// the runtime config specifies a default list, use those defaults
@@ -681,6 +668,25 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
681668
return &cfg, nil
682669
}
683670

671+
func (s *service) buildNonStubDrives(req *proto.CreateVMRequest) []models.Drive {
672+
var builder firecracker.DrivesBuilder
673+
674+
if input := req.RootDrive; input != nil {
675+
builder = builder.WithRootDrive(input.PathOnHost,
676+
firecracker.WithReadOnly(!input.IsWritable),
677+
firecracker.WithPartuuid(input.Partuuid),
678+
withRateLimiterFromProto(input.RateLimiter))
679+
} else {
680+
builder = builder.WithRootDrive(s.config.RootDrive, firecracker.WithReadOnly(true))
681+
}
682+
683+
for _, drive := range req.AdditionalDrives {
684+
builder = addDriveFromProto(builder, drive)
685+
}
686+
687+
return builder.Build()
688+
}
689+
684690
func (s *service) Create(requestCtx context.Context, request *taskAPI.CreateTaskRequest) (*taskAPI.CreateTaskResponse, error) {
685691
logger := s.logger.WithField("task_id", request.ID)
686692
defer logPanicAndDie(logger)

runtime/service_integ_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ func TestMultipleVMs_Isolated(t *testing.T) {
268268
},
269269
RootDrive: &proto.FirecrackerDrive{
270270
PathOnHost: rootfsPath,
271-
IsReadOnly: false,
272271
IsRootDevice: true,
273272
},
274273
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{
@@ -478,7 +477,6 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
478477
VMID: vmID,
479478
RootDrive: &proto.FirecrackerDrive{
480479
PathOnHost: defaultVMRootfsPath,
481-
IsReadOnly: false,
482480
IsRootDevice: true,
483481
},
484482
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{},
@@ -533,7 +531,6 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
533531
VMID: strconv.Itoa(vmID),
534532
RootDrive: &proto.FirecrackerDrive{
535533
PathOnHost: rootfsPath,
536-
IsReadOnly: false,
537534
IsRootDevice: true,
538535
},
539536
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{
@@ -670,7 +667,6 @@ func testCreateContainerWithSameName(t *testing.T, vmID string) {
670667
VMID: vmID,
671668
RootDrive: &proto.FirecrackerDrive{
672669
PathOnHost: defaultRootfsPath,
673-
IsReadOnly: true,
674670
IsRootDevice: true,
675671
},
676672
ContainerCount: 2,

0 commit comments

Comments
 (0)