From patchwork Wed May 7 14:58:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 29786 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2D31202E4 for ; Wed, 7 May 2014 14:59:59 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id i17sf3313209qcy.2 for ; Wed, 07 May 2014 07:59:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:in-reply-to:message-id :references:user-agent:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type; bh=TyMA+xDZ9Pa7fn/gJSHdlVkuCbr23apHw2/PSaiHw3A=; b=kv+2NERb6WEIjc15zHwRHMsxhM3EAXXx6aGJi0meJgHI2gH6wWh52mGOoHD197KjsK W64YxuZyZLPiajzm+WvStl9+nUN1/wPKPmlNC8wGBKpblhSzOPLDvvg/A7y8ZAMQaIQx ieYc/vrYLUVNQdmCsg8eT+ZOADXnBMYlQ5uD8UiL9UKKvc46h5ATjKLHX4eR9nVDyPjO D8bPkT9zliQucLJJhMSWgYiKZ41X2hK5jGcIfu4k2shLvWRZGXPwy/wAYFMylgk5anRb GzY5vEfl+AtZKGz5SUx2U8HpGVtrgQoPLJ9KFrEwKqyKAjfTkRrWfc+JD3Tnl1w17HqO ypxQ== X-Gm-Message-State: ALoCoQmyLBdC1gLBtLLyl0J+9l5K0ni+JsYVZOYluupYqrIF+HMs49eiBdamRTUjmqsayY10ir+g X-Received: by 10.236.93.38 with SMTP id k26mr4065555yhf.20.1399474799394; Wed, 07 May 2014 07:59:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.239 with SMTP id l102ls3476029qgd.81.gmail; Wed, 07 May 2014 07:59:59 -0700 (PDT) X-Received: by 10.52.93.201 with SMTP id cw9mr789829vdb.80.1399474799229; Wed, 07 May 2014 07:59:59 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id kp14si2960997vcb.2.2014.05.07.07.59.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 07:59:59 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id sa20so1467841veb.9 for ; Wed, 07 May 2014 07:59:59 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr20464563vdc.25.1399474799140; Wed, 07 May 2014 07:59:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp316612vcb; Wed, 7 May 2014 07:59:58 -0700 (PDT) X-Received: by 10.140.97.197 with SMTP id m63mr11893121qge.15.1399474798603; Wed, 07 May 2014 07:59:58 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w18si625648qgd.128.2014.05.07.07.59.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 07 May 2014 07:59:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:41813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wi3KA-0006yY-AE for patch@linaro.org; Wed, 07 May 2014 10:59:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wi3J3-0005pT-Rl for qemu-devel@nongnu.org; Wed, 07 May 2014 10:58:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wi3Iz-0004pE-9J for qemu-devel@nongnu.org; Wed, 07 May 2014 10:58:49 -0400 Received: from smtp.citrix.com ([66.165.176.89]:48954) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wi3Iz-0004oc-2V for qemu-devel@nongnu.org; Wed, 07 May 2014 10:58:45 -0400 X-IronPort-AV: E=Sophos; i="4.97,1004,1389744000"; d="scan'208"; a="128633135" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 07 May 2014 14:58:43 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Wed, 7 May 2014 10:58:43 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Wi3Iw-0003yO-OZ; Wed, 07 May 2014 15:58:42 +0100 Date: Wed, 7 May 2014 15:58:20 +0100 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Olaf Hering In-Reply-To: <1393259412-18554-1-git-send-email-olaf@aepfle.de> Message-ID: References: <1393259412-18554-1-git-send-email-olaf@aepfle.de> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-DLP: MIA1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, stefano.stabellini@eu.citrix.com Subject: Re: [Qemu-devel] [PATCH v3] xen_disk: add discard support 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 On Mon, 24 Feb 2014, Olaf Hering wrote: > Implement discard support for xen_disk. It makes use of the existing > discard code in qemu. > > The discard support is enabled unconditionally. The tool stack may > provide a property "discard-enable" in the backend node to optionally > disable discard support. This is helpful in case the backing file was > intentionally created non-sparse to avoid fragmentation. > > Signed-off-by: Olaf Hering > --- > v3: > define BLKIF_OP_DISCARD for xen-4.1 This change is not sufficient to get QEMU to compile against 4.1. I am going to go with the following: commit 6a16be0810eccd3aede1ef592c3c1b64430b3280 Author: Olaf Hering Date: Wed May 7 13:40:04 2014 +0000 xen_disk: add discard support Implement discard support for xen_disk. It makes use of the existing discard code in qemu. The discard support is enabled unconditionally. The tool stack may provide a property "discard-enable" in the backend node to optionally disable discard support. This is helpful in case the backing file was intentionally created non-sparse to avoid fragmentation. Signed-off-by: Olaf Hering Signed-off-by: Stefano Stabellini diff --git a/hw/block/xen_blkif.h b/hw/block/xen_blkif.h index c0f4136..711b692 100644 --- a/hw/block/xen_blkif.h +++ b/hw/block/xen_blkif.h @@ -79,6 +79,12 @@ static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_reque dst->handle = src->handle; dst->id = src->id; dst->sector_number = src->sector_number; + if (src->operation == BLKIF_OP_DISCARD) { + struct blkif_request_discard *s = (void *)src; + struct blkif_request_discard *d = (void *)dst; + d->nr_sectors = s->nr_sectors; + return; + } if (n > src->nr_segments) n = src->nr_segments; for (i = 0; i < n; i++) @@ -94,6 +100,12 @@ static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_reque dst->handle = src->handle; dst->id = src->id; dst->sector_number = src->sector_number; + if (src->operation == BLKIF_OP_DISCARD) { + struct blkif_request_discard *s = (void *)src; + struct blkif_request_discard *d = (void *)dst; + d->nr_sectors = s->nr_sectors; + return; + } if (n > src->nr_segments) n = src->nr_segments; for (i = 0; i < n; i++) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index a8fea72..aed5b5b 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -114,6 +114,7 @@ struct XenBlkDev { int requests_finished; /* Persistent grants extension */ + gboolean feature_discard; gboolean feature_persistent; GTree *persistent_gnts; unsigned int persistent_gnt_count; @@ -253,6 +254,8 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_WRITE: ioreq->prot = PROT_READ; /* from memory */ break; + case BLKIF_OP_DISCARD: + return 0; default: xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); @@ -492,6 +495,7 @@ static void qemu_aio_complete(void *opaque, int ret) case BLKIF_OP_READ: bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct); break; + case BLKIF_OP_DISCARD: default: break; } @@ -532,6 +536,15 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) &ioreq->v, ioreq->v.size / BLOCK_SIZE, qemu_aio_complete, ioreq); break; + case BLKIF_OP_DISCARD: + { + struct blkif_request_discard *discard_req = (void *)&ioreq->req; + ioreq->aio_inflight++; + bdrv_aio_discard(blkdev->bs, + discard_req->sector_number, discard_req->nr_sectors, + qemu_aio_complete, ioreq); + break; + } default: /* unknown operation (shouldn't happen -- parse catches this) */ goto err; @@ -710,6 +723,21 @@ static void blk_alloc(struct XenDevice *xendev) } } +static void blk_parse_discard(struct XenBlkDev *blkdev) +{ + int enable; + + blkdev->feature_discard = true; + + if (xenstore_read_be_int(&blkdev->xendev, "discard-enable", &enable) == 0) { + blkdev->feature_discard = !!enable; + } + + if (blkdev->feature_discard) { + xenstore_write_be_int(&blkdev->xendev, "feature-discard", 1); + } +} + static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); @@ -777,6 +805,8 @@ static int blk_init(struct XenDevice *xendev) xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1); xenstore_write_be_int(&blkdev->xendev, "info", info); + blk_parse_discard(blkdev); + g_free(directiosafe); return 0; @@ -812,6 +842,9 @@ static int blk_connect(struct XenDevice *xendev) qflags |= BDRV_O_RDWR; readonly = false; } + if (blkdev->feature_discard) { + qflags |= BDRV_O_UNMAP; + } /* init qemu block driver */ index = (blkdev->xendev.dev - 202 * 256) / 16; diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 2d5a25b..07731b9 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -144,6 +144,13 @@ static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom, { return -ENOSYS; } +/* The followings are only to compile op_discard related code on older + * Xen releases. */ +#define BLKIF_OP_DISCARD 5 +struct blkif_request_discard { + uint64_t nr_sectors; + uint64_t sector_number; +}; #else static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom, uint64_t addr, uint32_t data)