@@ -71,7 +71,7 @@ func capabilities(hypervisorType hypervisor.Type) hypervisor.Capabilities {
7171// This sends a graceful shutdown signal to the guest.
7272func (q * QEMU ) DeleteVM (ctx context.Context ) error {
7373 if err := q .client .SystemPowerdown (); err != nil {
74- Remove (q .socketPath )
74+ removeIfCurrent (q .socketPath , q )
7575 return err
7676 }
7777 clearBalloonTargetCache (q .socketPath )
@@ -81,11 +81,11 @@ func (q *QEMU) DeleteVM(ctx context.Context) error {
8181// Shutdown stops the QEMU process.
8282func (q * QEMU ) Shutdown (ctx context.Context ) error {
8383 if err := q .client .Quit (); err != nil {
84- Remove (q .socketPath )
84+ removeIfCurrent (q .socketPath , q )
8585 return err
8686 }
8787 // Connection is gone after quit, remove from pool
88- Remove (q .socketPath )
88+ removeIfCurrent (q .socketPath , q )
8989 clearBalloonTargetCache (q .socketPath )
9090 return nil
9191}
@@ -94,7 +94,7 @@ func (q *QEMU) Shutdown(ctx context.Context) error {
9494func (q * QEMU ) GetVMInfo (ctx context.Context ) (* hypervisor.VMInfo , error ) {
9595 status , err := q .client .Status ()
9696 if err != nil {
97- Remove (q .socketPath )
97+ removeIfCurrent (q .socketPath , q )
9898 return nil , fmt .Errorf ("query status: %w" , err )
9999 }
100100
@@ -129,7 +129,7 @@ func (q *QEMU) GetVMInfo(ctx context.Context) (*hypervisor.VMInfo, error) {
129129// Pause suspends VM execution.
130130func (q * QEMU ) Pause (ctx context.Context ) error {
131131 if err := q .client .Stop (); err != nil {
132- Remove (q .socketPath )
132+ removeIfCurrent (q .socketPath , q )
133133 return err
134134 }
135135 return nil
@@ -138,7 +138,7 @@ func (q *QEMU) Pause(ctx context.Context) error {
138138// Resume continues VM execution.
139139func (q * QEMU ) Resume (ctx context.Context ) error {
140140 if err := q .client .Continue (); err != nil {
141- Remove (q .socketPath )
141+ removeIfCurrent (q .socketPath , q )
142142 return err
143143 }
144144 return nil
@@ -153,13 +153,13 @@ func (q *QEMU) Snapshot(ctx context.Context, destPath string) error {
153153 memoryFile := destPath + "/memory"
154154 uri := "exec:cat > " + memoryFile
155155 if err := q .client .Migrate (uri ); err != nil {
156- Remove (q .socketPath )
156+ removeIfCurrent (q .socketPath , q )
157157 return fmt .Errorf ("migrate: %w" , err )
158158 }
159159
160160 // Wait for migration to complete
161161 if err := q .client .WaitMigration (ctx , migrationTimeout ); err != nil {
162- Remove (q .socketPath )
162+ removeIfCurrent (q .socketPath , q )
163163 return fmt .Errorf ("wait migration: %w" , err )
164164 }
165165
@@ -197,7 +197,7 @@ func (q *QEMU) SetTargetGuestMemoryBytes(ctx context.Context, bytes int64) error
197197 return fmt .Errorf ("target guest memory %d must be non-negative" , bytes )
198198 }
199199 if err := q .client .Balloon (bytes ); err != nil {
200- Remove (q .socketPath )
200+ removeIfCurrent (q .socketPath , q )
201201 return fmt .Errorf ("set balloon target: %w" , err )
202202 }
203203 balloonTargetCache .Store (q .socketPath , bytes )
0 commit comments