[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 2/6] net: introduce lock to protect NetClient
From: |
liu ping fan |
Subject: |
Re: [Qemu-devel] [PATCH v2 2/6] net: introduce lock to protect NetClientState's peer's access |
Date: |
Thu, 20 Jun 2013 14:30:30 +0800 |
On Tue, Jun 18, 2013 at 8:25 PM, Stefan Hajnoczi <address@hidden> wrote:
> On Thu, Jun 13, 2013 at 05:03:02PM +0800, Liu Ping Fan wrote:
>> @@ -67,6 +67,10 @@ struct NetClientState {
>> NetClientInfo *info;
>> int link_down;
>> QTAILQ_ENTRY(NetClientState) next;
>> + /* protect the race access of peer only between reader and writer.
>> + * to resolve the writer's race condition, resort on biglock.
>> + */
>
> Indentation
>
Will fix.
>> @@ -301,6 +303,38 @@ static void qemu_free_net_client(NetClientState *nc)
>> }
>> }
>>
>> +/* elimate the reference and sync with exit of rx/tx action.
>
> s/elimate/Eliminate/
>
Will fix
>> + * And flush out peer's queue.
>> + */
>> +static void qemu_net_client_detach_flush(NetClientState *nc)
>> +{
>> + NetClientState *peer;
>> +
>> + /* reader of self's peer field , fixme? the deleters are not concurrent,
>> + * so this pair lock can save.
>> + */
>
> Indentation, also please resolve the fixme.
>
So, here can I take the assumption that the deleters are serialized by
biglock, and remove the lock following this comment?
>> @@ -394,6 +433,28 @@ int qemu_can_send_packet(NetClientState *sender)
>> return 1;
>> }
>>
>> +int qemu_can_send_packet(NetClientState *sender)
>> +{
>> + int ret = 1;
>> +
>> + qemu_mutex_lock(&sender->peer_lock);
>> + if (!sender->peer) {
>> + goto unlock;
>> + }
>> +
>> + if (sender->peer->receive_disabled) {
>> + ret = 0;
>> + goto unlock;
>> + } else if (sender->peer->info->can_receive &&
>> + !sender->peer->info->can_receive(sender->peer)) {
>> + ret = 0;
>> + goto unlock;
>> + }
>
> Just call qemu_can_send_packet_nolock() instead of duplicating code?
Yes.
Thx & regards,
pingfan
[Qemu-devel] [PATCH v2 3/6] net: make netclient re-entrant with refcnt, Liu Ping Fan, 2013/06/13
[Qemu-devel] [PATCH v2 4/6] net: force NetQue opaque to be NetClientState, Liu Ping Fan, 2013/06/13
[Qemu-devel] [PATCH v2 5/6] net: defer nested call to BH, Liu Ping Fan, 2013/06/13