Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Expose firecracker sockets #132

Merged
merged 3 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const (
IGNITE_TIMEOUT = 10

// In-container path for the firecracker socket
SOCKET_PATH = "/tmp/firecracker.sock"
FIRECRACKER_SOCKET_PATH = "firecracker"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please avoid creating an extra directory for now to keep the code a bit simpler?
Please attach these sockets at the /var/lib/firecracker/vm/$id/firecracker.sock etc. path directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing

FIRECRACKER_API_SOCKET = "firecracker.sock"

// In-container path for the firecracker log FIFO
LOG_FIFO = "/tmp/firecracker_log.fifo"
LOG_FIFO = "firecracker_log.fifo"

// In-container path for the firecracker metrics FIFO
METRICS_FIFO = "/tmp/firecracker_metrics.fifo"
METRICS_FIFO = "firecracker_metrics.fifo"

// Log level for the firecracker VM
VM_LOG_LEVEL = "Error"
Expand Down
15 changes: 9 additions & 6 deletions pkg/container/firecracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ func ExecuteFirecracker(md *vmmd.VM, dhcpIfaces []DHCPInterface) error {
cmdLine = constants.VM_DEFAULT_KERNEL_ARGS
}

firecrackerSocketPath := path.Join(md.ObjectPath(), constants.FIRECRACKER_SOCKET_PATH, FIRECRACKER_API_SOCKET)
logSocketPath := path.Join(md.ObjectPath(), constants.FIRECRACKER_SOCKET_PATH, LOG_FIFO)
metricsSocketPath := path.Join(md.ObjectPath(), constants.FIRECRACKER_SOCKET_PATH, METRICS_FIFO)
cfg := firecracker.Config{
SocketPath: constants.SOCKET_PATH,
SocketPath: firecrackerSocketPath,
KernelImagePath: path.Join(constants.KERNEL_DIR, md.GetKernelUID().String(), constants.KERNEL_FILE),
KernelArgs: cmdLine,
Drives: []models.Drive{{
Expand All @@ -62,20 +65,20 @@ func ExecuteFirecracker(md *vmmd.VM, dhcpIfaces []DHCPInterface) error {

// TODO: We could use /dev/null, but firecracker-go-sdk issues Mkfifo which collides with the existing device
LogLevel: constants.VM_LOG_LEVEL,
LogFifo: constants.LOG_FIFO,
MetricsFifo: constants.METRICS_FIFO,
LogFifo: logSocketPath,
MetricsFifo: metricsSocketPath,
}

// Remove these FIFOs for now
defer os.Remove(constants.LOG_FIFO)
defer os.Remove(constants.METRICS_FIFO)
defer os.Remove(logSocketPath)
defer os.Remove(metricsSocketPath)

ctx, vmmCancel := context.WithCancel(context.Background())
defer vmmCancel()

cmd := firecracker.VMCommandBuilder{}.
WithBin("firecracker").
WithSocketPath(constants.SOCKET_PATH).
WithSocketPath(firecrackerSocketPath).
WithStdin(os.Stdin).
WithStdout(os.Stdout).
WithStderr(os.Stderr).
Expand Down
4 changes: 4 additions & 0 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func processUID(obj meta.Object, c *client.Client) error {
if err := os.MkdirAll(dir, constants.DATA_DIR_PERM); err != nil {
return fmt.Errorf("failed to create directory for ID %q: %v", uid, err)
}

if err := os.MkdirAll(paths.Join(dir, FIRECRACKER_SOCKET_PATH), constants.DATA_DIR_PERM); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed with the above design

return fmt.Errorf("failed to create socket directory for ID %q: %v", uid, err)
}

return nil
}
Expand Down