From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDBBh-0003zW-JH for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:39:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDBBb-0002hl-De for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:39:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDBBb-0002hb-5q for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:39:47 -0400 Date: Fri, 1 Aug 2014 12:39:40 +0100 From: Stefan Hajnoczi Message-ID: <20140801113940.GC7258@stefanha-thinkpad.redhat.com> References: <1404830964-10733-1-git-send-email-fromani@redhat.com> <1404830964-10733-2-git-send-email-fromani@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DIOMP1UsTsWJauNi" Content-Disposition: inline In-Reply-To: <1404830964-10733-2-git-send-email-fromani@redhat.com> Subject: Re: [Qemu-devel] [PATCH] block: add watermark event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Francesco Romani Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, lcapitulino@redhat.com --DIOMP1UsTsWJauNi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 08, 2014 at 04:49:24PM +0200, Francesco Romani wrote: > @@ -5813,3 +5815,57 @@ void bdrv_flush_io_queue(BlockDriverState *bs) > bdrv_flush_io_queue(bs->file); > } > } > + > +static bool watermark_exceeded(BlockDriverState *bs, > + int64_t sector_num, > + int nb_sectors) > +{ > + > + if (bs->wr_watermark_perc > 0) { > + int64_t watermark = (bs->total_sectors) / 100 * bs->wr_watermark_perc; bs->total_sectors should not be used directly. Have you considered making the watermark parameter take sector units instead of a percentage? I'm not sure whether a precentage makes sense because 25% of a 10GB image is 2.5 GB so a 75% watermark might be reasonable. 25% of a 1 TB image is 250 GB and that's probably not a reasonable watermark. So let the block-set-watermark caller pass an absolute sector number instead. It keeps things simple for both QEMU and thin provisioning manager. > + if (sector_num >= watermark) { > + return true; > + } > + } > + return false; > +} > + > +static int coroutine_fn watermark_before_write_notify(NotifierWithReturn *notifier, > + void *opaque) > +{ > + BdrvTrackedRequest *req = opaque; > + int64_t sector_num = req->offset >> BDRV_SECTOR_BITS; > + int nb_sectors = req->bytes >> BDRV_SECTOR_BITS; > + > +/* FIXME: needed? */ > + assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0); > + assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0); Not really needed here. Emulated storage controllers either get requests in block units (i.e. they are automatically aligned) or check them (like virtio-blk). I guess there's no harm in checking, but I would drop it. > + > + if (watermark_exceeded(req->bs, sector_num, nb_sectors)) { > + BlockDriverState *bs = req->bs; > + qapi_event_send_block_watermark( > + bdrv_get_device_name(bs), > + sector_num, > + bs->wr_highest_sector, > + &error_abort); How do you prevent flooding events if every write request exceeds the watermark? Perhaps the watermark should be disabled until block-set-watermark is called again. > + } > + > + return 0; /* should always let other notifiers run */ > +} > + > +void bdrv_set_watermark_perc(BlockDriverState *bs, > + int watermark_perc) > +{ > + NotifierWithReturn before_write = { > + .notify = watermark_before_write_notify, > + }; > + > + if (watermark_perc <= 0) { > + return; > + } > + > + if (bs->wr_watermark_perc == 0) { > + bdrv_add_before_write_notifier(bs, &before_write); before_write must be a BlockDriverState field so it has the correct lifetime. In this patch before_write is allocated on the stack and will cause invalid memory accesses once we leave this function. --DIOMP1UsTsWJauNi Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJT23x8AAoJEJykq7OBq3PImFgH/0DeJfa8VCBsDNWpT8RYqN8b uqUgGnPsAUdSKuhnfkDpOO0C+1Hec68O0ly+Y6LAbmcSJ2mg/BWdPJJeNBur84JT x6+izgKIF0jAfRjL4d0If6AyOwQG7vva+eZJsjW4QroX5fklE9De8pPd801mj8e9 0VWjwUXnqkX4OkIce+KRz8b64e2oYaPmGcWnYpMC6qp/PNwvpaYrOgdc43K1P5IJ BoGkk8elW1GkL4m2MgOT/G6gszb/CZXTKJt9Qg+cGL2VVAFA8TU3llJC3MSd6oYN Q8UjmDu7LcLFLq1eUctY1hDMGXpCDWHLH28dsbzvcygJYu7BU29QKYr+YalCwyc= =nSBH -----END PGP SIGNATURE----- --DIOMP1UsTsWJauNi--