Received: from eggs.gnu.org ([2001:4830:134:3::10]:50814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPriE-00010d-T8 for qemu-devel@nongnu.org; Tue, 27 Jun 2017 10:43:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPriC-0008Vl-8w for qemu-devel@nongnu.org; Tue, 27 Jun 2017 10:43:30 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:33469 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPriB-0008PO-U2 for qemu-devel@nongnu.org; Tue, 27 Jun 2017 10:43:28 -0400 References: <20170605123908.18777-1-pbonzini@redhat.com> <20170605123908.18777-17-pbonzini@redhat.com> <37960694-8f25-8201-5f17-e59c3ee67e90@redhat.com> <5ed4c5a0-11f3-14e7-77e6-47fa01a07d75@virtuozzo.com> <3a438db2-2c6d-e07b-94eb-b7c08073b9ae@virtuozzo.com> <13257113-2f2b-ccf5-93d1-66b2b963efce@virtuozzo.com> <5458c8fb-f73b-6651-b418-87bab8d3d143@redhat.com> From: Vladimir Sementsov-Ogievskiy Message-ID: <54703f2c-46ea-15b5-5c46-7520728bdd1c@virtuozzo.com> Date: Tue, 27 Jun 2017 17:43:25 +0300 MIME-Version: 1.0 In-Reply-To: <5458c8fb-f73b-6651-b418-87bab8d3d143@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [Qemu-devel] [PATCH 16/19] block: protect modification of dirty bitmaps with a mutex List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: famz@redhat.com 27.06.2017 17:26, Paolo Bonzini wrote: > > On 27/06/2017 16:20, Vladimir Sementsov-Ogievskiy wrote: >> I'm likely not right, but for me introducing this mutex looks like dirty >> bitmaps may be accessed from concurrent threads. So for me it looks >> strange that only accessors are protected by the mutex and not the whole >> transactions. > There must be something else protecting the whole transaction. But it doesn't? Before it (qmp_block_dirty_bitmap*) was protected by aio context acquire/release... > >> One example I've wrote above, other examples from code: are >> qmp_block_dirty_bitmap** functions: >> >> bdrv_create_dirty_bitmap() { >> >> bdrv_find_dirty_bitmap() >> >> .... >> >> bdrv_dirty_bitmaps_lock(bs); >> QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list); >> bdrv_dirty_bitmaps_unlock(bs); >> >> } >> >> - we protect inserting into list from other threads, but what prevent >> creating bitmap with the same name from other thread after >> bdrv_find_dirty_bitmap() and before bdrv_dirty_bitmaps_lock() ? > It's like a read-write lock. > > The write side is invoked under the 'big QEMU lock' so there cannot be > two concurrent writes. > > A bitmap can be written to after bdrv_find_dirty_bitmap returns, but > only if _you_ tell another thread about the bitmap you've just created. no, I'm not about touching just created bitmap. I'm about creating bitmap with the same name by other thread (unlikely case, but possible). > If that doesn't happen, the bitmap cannot change. And it can also > disappear because _your_ thread is the one with the big QEMU lock. So, if I under BQL, I don't need dirty_bitmap_lock? > > Paolo -- Best regards, Vladimir