mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-21 13:08:00 +00:00
FC: Fix error of overlong firecracker API unix socket
When sandbox id is too long, it will incur error of overlong firecracker API unix socket. In Linux, sun_path could maximumly contains 108 bytes in size. http://man7.org/linux/man-pages/man7/unix.7.html So here we try to truncate FC id to only keep the size of UUID(128bit). Fixes: #2504 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
parent
c3bafd5793
commit
44e23493a2
@ -180,6 +180,19 @@ func (fc *firecracker) trace(name string) (opentracing.Span, context.Context) {
|
||||
return span, ctx
|
||||
}
|
||||
|
||||
//At some cases, when sandbox id is too long, it will incur error of overlong
|
||||
//firecracker API unix socket(fc.socketPath).
|
||||
//In Linux, sun_path could maximumly contains 108 bytes in size.
|
||||
//(http://man7.org/linux/man-pages/man7/unix.7.html)
|
||||
func (fc *firecracker) truncateID(id string) string {
|
||||
if len(id) > 32 {
|
||||
//truncate the id to only leave the size of UUID(128bit).
|
||||
return id[:32]
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
// For firecracker this call only sets the internal structure up.
|
||||
// The sandbox will be created and started through startSandbox().
|
||||
func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
|
||||
@ -190,7 +203,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N
|
||||
|
||||
//TODO: check validity of the hypervisor config provided
|
||||
//https://github.com/kata-containers/runtime/issues/1065
|
||||
fc.id = id
|
||||
fc.id = fc.truncateID(id)
|
||||
fc.state.set(notReady)
|
||||
fc.config = *hypervisorConfig
|
||||
fc.stateful = stateful
|
||||
|
@ -29,3 +29,19 @@ func TestFCGenerateSocket(t *testing.T) {
|
||||
assert.NotEmpty(hvsock.UdsPath)
|
||||
assert.NotZero(hvsock.Port)
|
||||
}
|
||||
|
||||
func TestFCTruncateID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
fc := firecracker{}
|
||||
|
||||
testLongID := "3ef98eb7c6416be11e0accfed2f4e6560e07f8e33fa8d31922fd4d61747d7ead"
|
||||
expectedID := "3ef98eb7c6416be11e0accfed2f4e656"
|
||||
id := fc.truncateID(testLongID)
|
||||
assert.Equal(expectedID, id)
|
||||
|
||||
testShortID := "3ef98eb7c6416be11"
|
||||
expectedID = "3ef98eb7c6416be11"
|
||||
id = fc.truncateID(testShortID)
|
||||
assert.Equal(expectedID, id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user