diff --git a/internal/hcs/migration.go b/internal/hcs/migration.go index 5bb02effa2..5328ba5cca 100644 --- a/internal/hcs/migration.go +++ b/internal/hcs/migration.go @@ -198,7 +198,7 @@ func (computeSystem *System) StartWithMigrationOptions(ctx context.Context, conf return makeSystemError(computeSystem, operation, err, nil) } - return computeSystem.start(ctx, op, string(raw)) + return computeSystem.startV2(ctx, op, string(raw)) } // InitializeLiveMigrationOnSource initializes a live migration on the source side with the given options. diff --git a/internal/hcs/system.go b/internal/hcs/system.go index 3d9fcce1bd..869a5f3e7a 100644 --- a/internal/hcs/system.go +++ b/internal/hcs/system.go @@ -202,31 +202,44 @@ func GetComputeSystems(ctx context.Context, q schema1.ComputeSystemQuery) ([]sch return computeSystems, nil } -// Start synchronously starts the computeSystem. -func (computeSystem *System) Start(ctx context.Context) error { +// Start synchronously starts the computeSystem using HCS V1 API. +func (computeSystem *System) Start(ctx context.Context) (err error) { + operation := "hcs::System::Start" + + // hcsStartComputeSystemContext is an async operation. Start the outer span + // here to measure the full start time. + ctx, span := oc.StartSpan(ctx, operation) + defer span.End() + defer func() { oc.SetSpanStatus(span, err) }() + span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + computeSystem.handleLock.RLock() defer computeSystem.handleLock.RUnlock() + // prevent starting an exited system because waitblock we do not recreate waitBlock + // or rerun waitBackground, so we have no way to be notified of it closing again if computeSystem.handle == 0 { - return makeSystemError(computeSystem, "hcs::System::Start", ErrAlreadyClosed, nil) + return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil) } - op, err := computecore.HcsCreateOperation(ctx, 0, 0) + resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "") + events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, + hcsNotificationSystemStartCompleted, &timeout.SystemStart) if err != nil { - return makeSystemError(computeSystem, "hcs::System::Start", err, nil) + return makeSystemError(computeSystem, operation, err, events) } - defer computecore.HcsCloseOperation(ctx, op) - - return computeSystem.start(ctx, op, "") + computeSystem.startTime = time.Now() + return nil } -// start is the shared implementation used by Start and StartWithMigrationOptions. +// startV2 is the implementation used by StartWithMigrationOptions to start the compute system +// using HCS V2 APIs. // The caller provides a pre-created computecore operation (with any resources already // attached) and the JSON-encoded options string to pass to HcsStartComputeSystem. // // The caller MUST hold computeSystem.handleLock and verify the handle is valid // before calling this method. -func (computeSystem *System) start(ctx context.Context, op computecore.HcsOperation, opts string) (err error) { +func (computeSystem *System) startV2(ctx context.Context, op computecore.HcsOperation, opts string) (err error) { operation := "hcs::System::Start" // hcsStartComputeSystemContext is an async operation. Start the outer span