Received: from eggs.gnu.org ([2001:4830:134:3::10]:56671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtvBu-0004hl-SU for qemu-devel@nongnu.org; Thu, 27 Nov 2014 04:16:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XtvBo-00063z-Ky for qemu-devel@nongnu.org; Thu, 27 Nov 2014 04:16:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtvBo-00063v-DE for qemu-devel@nongnu.org; Thu, 27 Nov 2014 04:16:40 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAR9GdNF001571 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 27 Nov 2014 04:16:39 -0500 From: Markus Armbruster References: <1416944800-17919-1-git-send-email-jsnow@redhat.com> <1416944800-17919-3-git-send-email-jsnow@redhat.com> <5475C535.4010705@redhat.com> <5475F42A.5030900@redhat.com> Date: Thu, 27 Nov 2014 10:16:37 +0100 In-Reply-To: <5475F42A.5030900@redhat.com> (John Snow's message of "Wed, 26 Nov 2014 10:39:22 -0500") Message-ID: <877fyhknpm.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [2.3 PATCH v7 02/10] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: Fam Zheng , qemu-devel@nongnu.org, Max Reitz John Snow writes: > On 11/26/2014 07:19 AM, Max Reitz wrote: >> On 2014-11-25 at 20:46, John Snow wrote: >>> From: Fam Zheng >>> >>> The new command pair is added to manage user created dirty bitmap. The >>> dirty bitmap's name is mandatory and must be unique for the same device, >>> but different devices can have bitmaps with the same names. >>> >>> The types added to block-core.json will be re-used in future patches >>> in this series, see: >>> 'qapi: Add transaction support to block-dirty-bitmap-{add, enable, >>> disable}' [...] >>> diff --git a/blockdev.c b/blockdev.c >>> index 57910b8..e2fe687 100644 >>> --- a/blockdev.c >>> +++ b/blockdev.c >>> @@ -1810,6 +1810,69 @@ void qmp_block_set_io_throttle(const char >>> *device, int64_t bps, int64_t bps_rd, >>> aio_context_release(aio_context); >>> } >>> +void qmp_block_dirty_bitmap_add(const char *device, const char *name, >>> + bool has_granularity, int64_t >>> granularity, >>> + Error **errp) >>> +{ >>> + BlockDriverState *bs; >>> + Error *local_err = NULL; >>> + >>> + if (!device) { >>> + error_setg(errp, "Device to add dirty bitmap to must not be >>> null"); >>> + return; >>> + } >> >> I don't know if checking for that case makes sense, but of course it >> won't hurt. But...[1] >> >>> + >>> + bs = bdrv_lookup_bs(device, NULL, &local_err); >> >> Fair enough, I'd still like blk_by_name() and blk_bs() more >> (bdrv_lookup_bs() uses blk_bs(blk_by_name()) for the device name just as >> bdrv_find() did), but this is at least not a completely trivial wrapper. When a QMP command deals with a backend as a whole, then it should use the blk_ API. When it deals with individual (possibly interior) nodes, then it has to use the bdrv_ API. Since blk_ is new, most existing code doesn't use it, yet. Beginnings: 6007cdd blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend d829a21 block/qapi: Convert qmp_query_block() to BlockBackend >>> + if (!bs) { >>> + error_propagate(errp, local_err); >> >> Simply calling bdrv_lookup_bs(device, NULL, errp); suffices, no need for >> a local Error object and error_propagate(). But I'm fine with it either >> way. > > I found other cases where we do this in the code, I actually thought > it was a "style thing," which is why I did it so often. Cargo cult programming ;-P Back to serious: I believe a chief reason for bad or ugly error handling in new code is the many bad and ugly examples in existing code, from where they get copied into new code by sensible people. I've been chipping away at the bad examples. Don't hold your breath. > I'll happily cut it out. Yes, please. [...]