From patchwork Mon Feb 9 17:11:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 437985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0D75A140129 for ; Tue, 10 Feb 2015 04:12:34 +1100 (AEDT) Received: from localhost ([::1]:33988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKrsu-00047O-45 for incoming@patchwork.ozlabs.org; Mon, 09 Feb 2015 12:12:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKrsB-0002sV-Sp for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:11:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKrsA-00063x-QK for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:11:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56042) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKrsA-00063h-DH for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:11:46 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t19HBjwm022533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Feb 2015 12:11:46 -0500 Received: from localhost ([10.18.17.71]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t19HBjro024193 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 9 Feb 2015 12:11:45 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Mon, 9 Feb 2015 12:11:06 -0500 Message-Id: <1423501897-30410-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1423501897-30410-1-git-send-email-mreitz@redhat.com> References: <1423501897-30410-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Markus Armbruster , Max Reitz , Stefan Hajnoczi , John Snow Subject: [Qemu-devel] [PATCH v2 06/37] block: Make bdrv_is_inserted() return a bool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make bdrv_is_inserted(), blk_is_inserted(), and the callback BlockDriver.bdrv_is_inserted() return a bool. Suggested-by: Eric Blake Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 12 +++++++----- block/block-backend.c | 2 +- block/raw-posix.c | 10 ++++------ block/raw_bsd.c | 2 +- include/block/block.h | 2 +- include/block/block_int.h | 2 +- include/sysemu/block-backend.h | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index 9b707e3..ee7dfba 100644 --- a/block.c +++ b/block.c @@ -5230,14 +5230,16 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) /** * Return TRUE if the media is present */ -int bdrv_is_inserted(BlockDriverState *bs) +bool bdrv_is_inserted(BlockDriverState *bs) { BlockDriver *drv = bs->drv; - if (!drv) - return 0; - if (!drv->bdrv_is_inserted) - return 1; + if (!drv) { + return false; + } + if (!drv->bdrv_is_inserted) { + return true; + } return drv->bdrv_is_inserted(bs); } diff --git a/block/block-backend.c b/block/block-backend.c index ff21610..5cec6d9 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -741,7 +741,7 @@ void blk_invalidate_cache(BlockBackend *blk, Error **errp) bdrv_invalidate_cache(blk->bs, errp); } -int blk_is_inserted(BlockBackend *blk) +bool blk_is_inserted(BlockBackend *blk) { return bdrv_is_inserted(blk->bs); } diff --git a/block/raw-posix.c b/block/raw-posix.c index b5f077a..4034300 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -2274,7 +2274,7 @@ out: } -static int floppy_is_inserted(BlockDriverState *bs) +static bool floppy_is_inserted(BlockDriverState *bs) { return fd_open(bs) >= 0; } @@ -2408,15 +2408,13 @@ out: return prio; } -static int cdrom_is_inserted(BlockDriverState *bs) +static bool cdrom_is_inserted(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; int ret; ret = ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); - if (ret == CDS_DISC_OK) - return 1; - return 0; + return ret == CDS_DISC_OK; } static void cdrom_eject(BlockDriverState *bs, bool eject_flag) @@ -2542,7 +2540,7 @@ static int cdrom_reopen(BlockDriverState *bs) return 0; } -static int cdrom_is_inserted(BlockDriverState *bs) +static bool cdrom_is_inserted(BlockDriverState *bs) { return raw_getlength(bs) > 0; } diff --git a/block/raw_bsd.c b/block/raw_bsd.c index 05b02c7..0a76cbc 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -154,7 +154,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset) return bdrv_truncate(bs->file, offset); } -static int raw_is_inserted(BlockDriverState *bs) +static bool raw_is_inserted(BlockDriverState *bs) { return bdrv_is_inserted(bs->file); } diff --git a/include/block/block.h b/include/block/block.h index 471d11d..e0eec19 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -365,7 +365,7 @@ int bdrv_is_read_only(BlockDriverState *bs); int bdrv_is_sg(BlockDriverState *bs); int bdrv_enable_write_cache(BlockDriverState *bs); void bdrv_set_enable_write_cache(BlockDriverState *bs, bool wce); -int bdrv_is_inserted(BlockDriverState *bs); +bool bdrv_is_inserted(BlockDriverState *bs); int bdrv_media_changed(BlockDriverState *bs); void bdrv_lock_medium(BlockDriverState *bs, bool locked); void bdrv_eject(BlockDriverState *bs, bool eject_flag); diff --git a/include/block/block_int.h b/include/block/block_int.h index b340e7e..7dc0c91 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -213,7 +213,7 @@ struct BlockDriver { const char *backing_file, const char *backing_fmt); /* removable device specific */ - int (*bdrv_is_inserted)(BlockDriverState *bs); + bool (*bdrv_is_inserted)(BlockDriverState *bs); int (*bdrv_media_changed)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 2e8ebb2..f60949a 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -127,7 +127,7 @@ int blk_is_sg(BlockBackend *blk); int blk_enable_write_cache(BlockBackend *blk); void blk_set_enable_write_cache(BlockBackend *blk, bool wce); void blk_invalidate_cache(BlockBackend *blk, Error **errp); -int blk_is_inserted(BlockBackend *blk); +bool blk_is_inserted(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); int blk_get_flags(BlockBackend *blk);