From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O0Im9-00058y-0t for qemu-devel@nongnu.org; Fri, 09 Apr 2010 14:17:53 -0400 Received: from [140.186.70.92] (port=43159 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O0Im6-00055i-7o for qemu-devel@nongnu.org; Fri, 09 Apr 2010 14:17:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O0Im4-0000Sq-3s for qemu-devel@nongnu.org; Fri, 09 Apr 2010 14:17:50 -0400 Received: from mail-qy0-f188.google.com ([209.85.221.188]:50894) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O0Im3-0000ST-Up for qemu-devel@nongnu.org; Fri, 09 Apr 2010 14:17:48 -0400 Received: by qyk26 with SMTP id 26so3730787qyk.19 for ; Fri, 09 Apr 2010 11:17:46 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4BBF5A27.8090701@redhat.com> References: <1270822934-8623-1-git-send-email-stefanha@linux.vnet.ibm.com> <1270822934-8623-3-git-send-email-stefanha@linux.vnet.ibm.com> <4BBF5A27.8090701@redhat.com> Date: Fri, 9 Apr 2010 19:17:45 +0100 Message-ID: Subject: Re: [Qemu-devel] [PATCH 2/2] block: Convert bdrv_first to QTAILQ From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Stefan Hajnoczi , qemu-devel@nongnu.org On Fri, Apr 9, 2010 at 5:47 PM, Kevin Wolf wrote: >> @@ -545,13 +542,15 @@ void bdrv_close(BlockDriverState *bs) >> >> =A0void bdrv_delete(BlockDriverState *bs) >> =A0{ >> - =A0 =A0BlockDriverState **pbs; >> + =A0 =A0BlockDriverState *bs1; >> >> - =A0 =A0pbs =3D &bdrv_first; >> - =A0 =A0while (*pbs !=3D bs && *pbs !=3D NULL) >> - =A0 =A0 =A0 =A0pbs =3D &(*pbs)->next; >> - =A0 =A0if (*pbs =3D=3D bs) >> - =A0 =A0 =A0 =A0*pbs =3D bs->next; >> + =A0 =A0/* remove from list, if necessary */ >> + =A0 =A0QTAILQ_FOREACH(bs1, &bdrv_states, list) { >> + =A0 =A0 =A0 =A0if (bs1 =3D=3D bs) { >> + =A0 =A0 =A0 =A0 =A0 =A0QTAILQ_REMOVE(&bdrv_states, bs, list); >> + =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 =A0} >> + =A0 =A0} > > This loop looks strange, what is it used for? We had only a next pointer > previously, so we needed to search the element. A QTAILQ has both prev > and next pointers though, so you should be able to directly use > QTAILQ_REMOVE. Only named BlockDriverStates are added to the tail queue. Those with an empty string as their name will not be on the tail queue. The QTAILQ_REMOVE macro will not work if the element isn't on the tail queue. I didn't see a clean way to check if an element is on a tail queue using qemu-queue.h, so I kept the search behavior. The check I want is tge_prev !=3D NULL, I think. I see three options: 1. Leave the search. 2. Modify qemu-queue.h to add a QTAILQ_ON_LIST(elm) macro. 3. Break the QTAILQ abstraction and test tge_prev directly. What do you think? Stefan