Received: from eggs.gnu.org ([2001:4830:134:3::10]:60478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkuOn-0000jM-3U for qemu-devel@nongnu.org; Wed, 22 Apr 2015 09:09:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkuOg-0006J0-Vk for qemu-devel@nongnu.org; Wed, 22 Apr 2015 09:09:05 -0400 Received: from mail-wg0-x22b.google.com ([2a00:1450:400c:c00::22b]:35521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkuOg-0006IY-I0 for qemu-devel@nongnu.org; Wed, 22 Apr 2015 09:08:58 -0400 Received: by wgyo15 with SMTP id o15so246324114wgy.2 for ; Wed, 22 Apr 2015 06:08:58 -0700 (PDT) Date: Wed, 22 Apr 2015 14:08:55 +0100 From: Stefan Hajnoczi Message-ID: <20150422130855.GI27617@stefanha-thinkpad.redhat.com> References: <1426069701-1405-1-git-send-email-den@openvz.org> <1426069701-1405-9-git-send-email-den@openvz.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="nEsDIrWrg+hrB7l1" Content-Disposition: inline In-Reply-To: <1426069701-1405-9-git-send-email-den@openvz.org> Subject: Re: [Qemu-devel] [PATCH 08/27] block/parallels: _co_writev callback for Parallels format List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi --nEsDIrWrg+hrB7l1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 11, 2015 at 01:28:02PM +0300, Denis V. Lunev wrote: > +static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) > +{ > + BDRVParallelsState *s = bs->opaque; > + uint32_t idx, offset, tmp; > + int64_t pos; > + int ret; > + > + idx = sector_num / s->tracks; > + offset = sector_num % s->tracks; > + > + if (idx >= s->catalog_size) { > + return -EINVAL; > + } > + if (s->catalog_bitmap[idx] != 0) { > + return (uint64_t)s->catalog_bitmap[idx] * s->off_multiplier + offset; > + } > + > + pos = bdrv_getlength(bs->file) >> BDRV_SECTOR_BITS; > + bdrv_truncate(bs->file, (pos + s->tracks) << BDRV_SECTOR_BITS); > + s->catalog_bitmap[idx] = pos / s->off_multiplier; > + > + tmp = cpu_to_le32(s->catalog_bitmap[idx]); > + > + ret = bdrv_pwrite_sync(bs->file, > + sizeof(ParallelsHeader) + idx * sizeof(tmp), &tmp, sizeof(tmp)); What is the purpose of the sync? > + if (ret < 0) { > + return ret; > + } > + return (uint64_t)s->catalog_bitmap[idx] * s->off_multiplier + offset; > +} This function is missing error handling. If the catalog bitmap update cannot be written to file then our in-memory copy should also be reverted back to 0 (unallocated). --nEsDIrWrg+hrB7l1 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVN51nAAoJEJykq7OBq3PIPjoH/1kS54tytgCjPAOwtdSnoNlm HCqM/c83L/mLNL3FWd3/gQfV/Wzoza8IKpdvjslIhXgb35fbAQ6IkVv8XJxV79ld 44ehyEGoMb9e59i7F+mlgWf+krmFXmLDN9Wp67T83IzKq0tareFeMjDUdgWYLTMz BHbQaHURBUf8KclD/xrrC7+jH4Sfii+4vrQSJco2YRWIVDIW4llG537kLB+le+Ty bxLznJj8iX4/cNiFfJh36nvkb99JiyqPjhgAZORAb1HH7jE9sGoFQLcVvTrYyH1K LhpxIHdJoIqCySj/xInMw05KhhnWTxoyMd/lcjxrMInFrchp19J2ndMgf/p5Mno= =1CPw -----END PGP SIGNATURE----- --nEsDIrWrg+hrB7l1--