Skip to content

Commit

Permalink
virtcontainers: handle persistent memory volumes
Browse files Browse the repository at this point in the history
A persistent memory volume MUST meet the following conditions:
* A loop device must be mounted in the directory passed as volume
* The loop device must have a backing file
* The backing file must have the PFN signature at offset 4k [1][2]

The backing file is used as backend file for a NVDIMM device in the guest

fixes kata-containers#2262

[1] - https://github.com/kata-containers/osbuilder/blob/master/image-builder
/nsdax.gpl.c
[2] - https://github.com/torvalds/linux/blob/master/drivers/nvdimm/pfn.h

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Mar 11, 2020
1 parent b7adaea commit d747f0c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
continue
}

if d.Pmem {
// block drive is a persistent memory device that
// was passed as volume (-v) not as device (--device).
// It shouldn't be visible in the container
continue
}

kataDevice := &grpc.Device{
ContainerPath: dev.ContainerPath,
}
Expand Down Expand Up @@ -1439,7 +1446,18 @@ func (k *kataAgent) handleBlockVolumes(c *Container) ([]*grpc.Storage, error) {
k.Logger().Error("malformed block drive")
continue
}

vol.MountPoint = m.Destination
vol.Fstype = "bind"
vol.Options = []string{"bind"}

switch {
// pmem volumes case
case blockDrive.Pmem:
vol.Driver = kataNvdimmDevType
vol.Source = fmt.Sprintf("/dev/pmem%s", blockDrive.NvdimmID)
vol.Fstype = blockDrive.Format
vol.Options = []string{"dax"}
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlockCCW:
vol.Driver = kataBlkCCWDevType
vol.Source = blockDrive.DevNo
Expand All @@ -1456,10 +1474,6 @@ func (k *kataAgent) handleBlockVolumes(c *Container) ([]*grpc.Storage, error) {
return nil, fmt.Errorf("Unknown block device driver: %s", c.sandbox.config.HypervisorConfig.BlockDeviceDriver)
}

vol.MountPoint = m.Destination
vol.Fstype = "bind"
vol.Options = []string{"bind"}

volumeStorages = append(volumeStorages, vol)
}

Expand Down

0 comments on commit d747f0c

Please sign in to comment.