Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit eea12a4

Browse files
committed
Add new option "cache" to container and volume
Signed-off-by: Hui Zhu <[email protected]>
1 parent af3acb5 commit eea12a4

File tree

6 files changed

+90
-70
lines changed

6 files changed

+90
-70
lines changed

api/descriptions.pb.go

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

api/descriptions.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ message VolumeDescription {
4848
string source = 2;
4949
string format = 3; //"raw" (or "qcow2" later) for volume, "vfs" for dir path
5050
string fstype = 4; //"xfs", "ext4" etc. for block dev, or "dir" for dir path
51+
string cache = 5;
5152
VolumeOption options = 8;
5253
bool dockerVolume = 9;
5354
bool readOnly = 10;

hypervisor/disk.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type DiskDescriptor struct {
1919
ScsiAddr string
2020
DockerVolume bool
2121
ReadOnly bool
22+
Cache string
2223
Options map[string]string
2324
}
2425

@@ -49,6 +50,7 @@ func NewDiskContext(ctx *VmContext, vol *api.VolumeDescription) *DiskContext {
4950
Fstype: vol.Fstype,
5051
DockerVolume: vol.DockerVolume,
5152
ReadOnly: vol.ReadOnly,
53+
Cache: vol.Cache,
5254
},
5355
sandbox: ctx,
5456
observers: make(map[string]*sync.WaitGroup),

hypervisor/persistence.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type PersistVolumeInfo struct {
2626
Filename string
2727
Format string
2828
Fstype string
29+
Cache string
2930
DeviceName string
3031
ScsiId int
3132
ContainerIds []string
@@ -178,6 +179,7 @@ func (blk *DiskDescriptor) dump() *PersistVolumeInfo {
178179
Filename: blk.Filename,
179180
Format: blk.Format,
180181
Fstype: blk.Fstype,
182+
Cache: blk.Cache,
181183
DeviceName: blk.DeviceName,
182184
ScsiId: blk.ScsiId,
183185
}
@@ -189,6 +191,7 @@ func (vol *PersistVolumeInfo) blockInfo() *DiskDescriptor {
189191
Filename: vol.Filename,
190192
Format: vol.Format,
191193
Fstype: vol.Fstype,
194+
Cache: vol.Cache,
192195
DeviceName: vol.DeviceName,
193196
ScsiId: vol.ScsiId,
194197
}
@@ -331,6 +334,7 @@ func (pinfo *PersistInfo) vmContext(hub chan VmEvent, client chan *types.VmRespo
331334
Source: bInfo.Filename,
332335
Format: bInfo.Format,
333336
Fstype: bInfo.Fstype,
337+
Cache: bInfo.Cache,
334338
DockerVolume: bInfo.DockerVolume,
335339
ReadOnly: bInfo.ReadOnly,
336340
},

hypervisor/qemu/qemu.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo
241241
format := blockInfo.Format
242242
id := blockInfo.ScsiId
243243
readonly := blockInfo.ReadOnly
244+
cache := blockInfo.Cache
244245

245246
if format == "rbd" {
246247
if blockInfo.Options != nil {
@@ -262,7 +263,7 @@ func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo
262263
}
263264
}
264265

265-
newDiskAddSession(ctx, qc, filename, format, id, readonly, result)
266+
newDiskAddSession(ctx, qc, filename, format, id, readonly, cache, result)
266267
}
267268

268269
func (qc *QemuContext) RemoveDisk(ctx *hypervisor.VmContext, blockInfo *hypervisor.DiskDescriptor, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) {

hypervisor/qemu/qmp_wrapper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ func defaultRespond(result chan<- hypervisor.VmEvent, callback hypervisor.VmEven
3535
}
3636
}
3737

38-
func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, filename, format string, id int, readonly bool, result chan<- hypervisor.VmEvent) {
39-
args := "drive_add dummy file=" + filename + ",if=none,id=" + "drive" + strconv.Itoa(id) + ",format=" + format + ",cache=writeback"
38+
func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, filename, format string, id int, readonly bool, cache string, result chan<- hypervisor.VmEvent) {
39+
if cache == "" {
40+
cache = "writeback"
41+
}
42+
args := "drive_add dummy file=" + filename + ",if=none,id=" + "drive" + strconv.Itoa(id) + ",format=" + format + ",cache=" + cache
4043
if readonly {
4144
args += ",readonly"
4245
}

0 commit comments

Comments
 (0)