From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXA9G-0001QX-TG for qemu-devel@nongnu.org; Wed, 02 Sep 2015 11:40:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXA9F-00010V-P4 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 11:40:30 -0400 References: <1441183880-26993-1-git-send-email-wency@cn.fujitsu.com> <1441183880-26993-3-git-send-email-wency@cn.fujitsu.com> From: Eric Blake Message-ID: <55E71866.5050502@redhat.com> Date: Wed, 2 Sep 2015 09:40:22 -0600 MIME-Version: 1.0 In-Reply-To: <1441183880-26993-3-git-send-email-wency@cn.fujitsu.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ioPik2IaLVNwkLaeiQdRvJwUBPddrHJW6" Subject: Re: [Qemu-devel] [PATCH 02/16] introduce a new API to check if blk is attached List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wen Congyang , qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Yang Hongyang This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ioPik2IaLVNwkLaeiQdRvJwUBPddrHJW6 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/02/2015 02:51 AM, Wen Congyang wrote: > Signed-off-by: Wen Congyang > --- > block.c | 4 ++-- > block/block-backend.c | 9 +++++++++ > include/sysemu/block-backend.h | 1 + > 3 files changed, 12 insertions(+), 2 deletions(-) >=20 > /* > + * Return true if a device model is attached to @blk already, > + * otherwise, return false. > + */ > +bool blk_is_attached(BlockBackend *blk) > +{ > + return blk !=3D NULL && blk->dev !=3D NULL && blk->dev !=3D (void = *)-1; Again, I don't like the raw magic constant, even if we go with this patch. And it is shorter to write: return blk && blk->dev && blk->dev !=3D MAGIC; But I think it is better to just allow for a NULL BDS to represent an unattached media (in which case Max's patches may already cover what you are trying to do here), rather than trying to overload a special value different from NULL. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ioPik2IaLVNwkLaeiQdRvJwUBPddrHJW6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJV5xhmAAoJEKeha0olJ0Nq0K0H/3P3A4dVgJKkUEoviSHicEck OvDla/2LbDeBL7jsaKvcNuc48nho20FrNiX7JtHUzc90kUOdSgHfUxZDv9Zb1SIR rnWGrWU6hzYC3i2cThpb8O6j3lB/UVsFjOgLOFn19qf1UWad/g4ukYP8CtivYPFY hQmgDwk834wYocnwr6k65Qqz30o7iQj3bKg3Z71DfE8m24O/B45tCk0QkEp4K3fT f6uUOEOub3WT9+PtDlldQPK3MqZJIuBvHxhPO1gefJmntPdP97k88m2lqnTLTceg pnwa8SuvXk7FcnmOCmAvJYqTwedgp1Bd13zLiP1s6zEU4yZ/pjHramaYNaJKkcw= =ukYN -----END PGP SIGNATURE----- --ioPik2IaLVNwkLaeiQdRvJwUBPddrHJW6--