diff mbox

[2/2] ide: ahci: call cleanup function in ahci unit

Message ID 1486623844-13140-3-git-send-email-liqiang6-s@360.cn
State New
Headers show

Commit Message

Li Qiang Feb. 9, 2017, 7:04 a.m. UTC
This can avoid memory leak when hotunplug the ahci device.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
 hw/ide/ahci.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

John Snow March 1, 2017, 12:35 a.m. UTC | #1
On 02/09/2017 02:04 AM, Li Qiang wrote:
> This can avoid memory leak when hotunplug the ahci device.
> 
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
>  hw/ide/ahci.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index 3c19bda..56f68a8 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -1485,6 +1485,14 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
>  
>  void ahci_uninit(AHCIState *s)
>  {
> +    int i;
> +
> +    for (i = 0; i < s->ports; i++) {
> +        AHCIDevice *ad = &s->dev[i];
> +
> +        ide_unregister_restart_cb(&ad->port);
> +        ide_exit(&ad->port);
> +    }
>      g_free(s->dev);
>  }
>  
> 

I couldn't actually prove to myself that ahci_uninit runs on an unplug
request. Did you observe improvements to the memory profile after
introducing this patch?

I don't think anyone has taken the care to plumb AHCI to behave well
when hotplugged.

--js
John Snow March 1, 2017, 12:42 a.m. UTC | #2
On 02/28/2017 07:35 PM, John Snow wrote:
> 
> 
> On 02/09/2017 02:04 AM, Li Qiang wrote:
>> This can avoid memory leak when hotunplug the ahci device.
>>
>> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
>> ---
>>  hw/ide/ahci.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
>> index 3c19bda..56f68a8 100644
>> --- a/hw/ide/ahci.c
>> +++ b/hw/ide/ahci.c
>> @@ -1485,6 +1485,14 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
>>  
>>  void ahci_uninit(AHCIState *s)
>>  {
>> +    int i;
>> +
>> +    for (i = 0; i < s->ports; i++) {
>> +        AHCIDevice *ad = &s->dev[i];
>> +
>> +        ide_unregister_restart_cb(&ad->port);
>> +        ide_exit(&ad->port);
>> +    }
>>      g_free(s->dev);
>>  }
>>  
>>
> 
> I couldn't actually prove to myself that ahci_uninit runs on an unplug
> request. Did you observe improvements to the memory profile after
> introducing this patch?
> 
> I don't think anyone has taken the care to plumb AHCI to behave well
> when hotplugged.
> 

Ah, my mistake actually! It's just that it requires guest cooperation.
It works perfectly well as long as Linux is ready to cooperate with the
request.

--js
diff mbox

Patch

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 3c19bda..56f68a8 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1485,6 +1485,14 @@  void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
 
 void ahci_uninit(AHCIState *s)
 {
+    int i;
+
+    for (i = 0; i < s->ports; i++) {
+        AHCIDevice *ad = &s->dev[i];
+
+        ide_unregister_restart_cb(&ad->port);
+        ide_exit(&ad->port);
+    }
     g_free(s->dev);
 }