From patchwork Mon Aug 29 17:10:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9304727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 764B360756 for ; Tue, 30 Aug 2016 02:45:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6291228A3F for ; Tue, 30 Aug 2016 02:45:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5577C28A7D; Tue, 30 Aug 2016 02:45:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D2A828A3F for ; Tue, 30 Aug 2016 02:45:28 +0000 (UTC) Received: from localhost ([::1]:46621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beZ3H-0002fb-Ma for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 22:45:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beZ2k-0002bC-DH for qemu-devel@nongnu.org; Mon, 29 Aug 2016 22:44:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beZ2i-0001RC-4X for qemu-devel@nongnu.org; Mon, 29 Aug 2016 22:44:53 -0400 Received: from mail-db5eur01on0108.outbound.protection.outlook.com ([104.47.2.108]:20543 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beZ2b-0001Mi-VS; Mon, 29 Aug 2016 22:44:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=j/Gm1pAe4bv2L/NODE75+EByNSrhSCFQNSOosIDStrA=; b=fVP4w/SePR7D3WxZbvoN2hHyD6aJ54HcQiZ5+Xo6ig6Eu6buvkg0SsANZ+JG1B141OKQtFXTHgr8ayfHyqK4fKOpO8Fb9GrYET05pdOtUR+3yvQBsBAKXtFECtgHXEZfMZpxRmClSHMmY15uzlGf5W1PfcvZVGTLIlWxPwuYLxw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 29 Aug 2016 17:11:15 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:00 +0300 Message-ID: <20160829171021.4902-2-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0901CA0011.eurprd09.prod.outlook.com (10.164.186.149) To AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) X-MS-Office365-Filtering-Correlation-Id: 7570ed05-7450-4357-714b-08d3d02f7c83 X-Microsoft-Exchange-Diagnostics: 1; AM5PR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vc1YMTWYajOcOSvAhs8QCBgjWqog=; 4:KEdDpcdVNp3V/XxGpnkVPz0r8pfUwJvnBicIUUYbXAyqf5Z+4DmSCcTWeQDu2III8x1N3AqOVjXn8RvjzMlN1jEyo2Tg0utlE6Nlk7IScjRQeFKaXBMett3bfbCSIobdtp84MoCK2APF76+ngFI+mW65tVK10e/A8GqKuwLvMz9ey+C9vY+gYJw02rN1gwYSxECbJXXhJNPiz6UTzXL2e5REg8UGYkipQxVVMVkhzzhDU2HFc/LDO4ZI/266s62kYghh1892HF1RKBZKUV1hWNT4wc9BmJnsOSDKDTG9a7x9bexvxLxLnrxuIJO2Ep8FuTWi+rODa2j/cso0Bmi8kR1FxNjsoskz60F5xTS1ko9UG9sLwgd7m0ULylDziMKP1fh7QBfzfs7xTeZ6L+ye8GO1SGPMLH3VvTIKZdm/WPs= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6042046)(6043046); SRVR:AM5PR0802MB2547; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2547; X-Forefront-PRVS: 0049B3F387 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(3846002)(305945005)(77096005)(86362001)(1076002)(53416004)(92566002)(68736007)(42186005)(97736004)(5001770100001)(47776003)(105586002)(2906002)(6116002)(189998001)(50986999)(4326007)(48376002)(586003)(2950100001)(5003940100001)(50466002)(66066001)(19580405001)(19580395003)(76176999)(69596002)(5660300001)(229853001)(101416001)(36756003)(7736002)(8676002)(106356001)(50226002)(7846002)(81156014)(33646002)(81166006)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0802MB2547; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0802MB2547; 23:zv+6P9/TtHyGQvuW4FfrX5A4oa+C0Y2OCkH2L+V?= =?us-ascii?Q?wnZcBKme1ySG7FtEbiO4c3GS+d8UQ5Fp/TUkQdfL9Usj7pOQui56BcV/dlu6?= =?us-ascii?Q?F38MF9RjkDEIyxHroZB4Z/RZBi05HoWlGc77rcm6KoJX1CgiqIfRngr11nKz?= =?us-ascii?Q?94ixRPhtUW0i1/yfhQGlYntF6nSssvhf15FFcAHhJrQHd/X7yAarLTQenkiJ?= =?us-ascii?Q?5av9YZCJclqtNT5JrTSyirbbYtRaxczb3PIocBtBnoECKuSphRt0bE98qbIw?= =?us-ascii?Q?n4F4qcxpkOfKB+NLAgVmeHQpIxhr3ptobcQZd4ghCB5V/Gc3BuSbD1P+3TVv?= =?us-ascii?Q?OzyOfOuEnzPougQ+uTSlmtpir/4WK4Qz6HxnrCNIJvsMmRa1nb4QqbDBrmwJ?= =?us-ascii?Q?VQDrxMtu076pYiCBLHMSDs2eokyX+VlYIh5454SVjTmJFu00g3c2e3+rzCB9?= =?us-ascii?Q?QULcnwq0aqaRqxuuKPsbx9FdJ9Ex248nUXptoPlqY9tw/NcnhWVuDJrh8nRj?= =?us-ascii?Q?T4I7g2uleY/hXvi2wv+LbnE2mtXpQfr4SFIqdoSNDIjUMAvJnOmcf+jk0ufS?= =?us-ascii?Q?IdgA864iPbESAgPV/opBr85D6QdvDzEJY+DJvRQx9rrnVDjrXMqgR/hXcoLJ?= =?us-ascii?Q?5v808k9hDPncG2drf/P61c0M32TI5GsqW6zJYqRNdbvlvO0wWNIDKacPinRa?= =?us-ascii?Q?h+hTtSZa2d8S3M4FHrJAnon+JLRTqGNe+udfz6RkKvODmREQVXjwcFUSJxss?= =?us-ascii?Q?AtcXthCGYCvDyWS7nvbNLUpKwvHDeL7RfnN1i1YLFhp2ULYruh1Zi8kSnMGO?= =?us-ascii?Q?dh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2K5vVaJDDqL6cy9GoPxPi1+SLEYSY6igBGRYbsOpxRjq2u+dOUJ6Vlz2A1dR2zF70LKpw381R+/4/gFnXQ5yDYJ90FXCsZ/kGPiCou20gU4wc+JAZhj6yPh9J7zBeyOTrRglw0Ra/MhsnH0UflhQI+JyIoIGE481sPmDCXZIt65iZ+wDITa1LYwCl1MJ7B2Qr/lgSgRxEdZLojR0leRej35WbAtgIFmx5lP2ndyzqzKBSO1Zpv3o SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:j6kQNtoZtjtCW00SeEbZWvJ1v1j5DbIwbDkGQx04OiQaJDUJS2zPkr8LfL0GS7P5WNNlgL0FQgsoKm5SIoWzfRxkyCeAEl/KWRgWGfeh5onty9R5zPmoHlY+DDTyvuK44D0iSfoC3wqQZkVtg62Nx7cVMYK1SbYBAsdIPBqtk2w= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:15.4976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2547 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.108 Subject: [Qemu-devel] [PATCH RFC v2 01/22] block/pcache: empty pcache driver filter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The basic version of pcache driver for easy preparation of a patch set. Signed-off-by: Pavel Butsykin --- block/Makefile.objs | 1 + block/pcache.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 block/pcache.c diff --git a/block/Makefile.objs b/block/Makefile.objs index 2593a2f..7c588ac 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -4,6 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o block-obj-y += quorum.o +block-obj-y += pcache.o block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o block-obj-y += block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o diff --git a/block/pcache.c b/block/pcache.c new file mode 100644 index 0000000..770bbc0 --- /dev/null +++ b/block/pcache.c @@ -0,0 +1,156 @@ +/* + * Prefetch cache driver filter + * + * Copyright (c) 2016 Pavel Butsykin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "qapi/error.h" +#include "qapi/qmp/qstring.h" + + +static const AIOCBInfo pcache_aiocb_info = { + .aiocb_size = sizeof(BlockAIOCB), +}; + +static QemuOptsList runtime_opts = { + .name = "pcache", + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), + .desc = { + { + .name = "x-image", + .type = QEMU_OPT_STRING, + .help = "[internal use only, will be removed]", + }, + { /* end of list */ } + }, +}; + +static void pcache_aio_cb(void *opaque, int ret) +{ + + BlockAIOCB *acb = opaque; + + acb->cb(acb->opaque, ret); + + qemu_aio_unref(acb); +} + +static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, + int64_t sector_num, + QEMUIOVector *qiov, + int nb_sectors, + BlockCompletionFunc *cb, + void *opaque) +{ + BlockAIOCB *acb = qemu_aio_get(&pcache_aiocb_info, bs, cb, opaque); + + bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, + pcache_aio_cb, acb); + return acb; +} + +static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, + int64_t sector_num, + QEMUIOVector *qiov, + int nb_sectors, + BlockCompletionFunc *cb, + void *opaque) +{ + BlockAIOCB *acb = qemu_aio_get(&pcache_aiocb_info, bs, cb, opaque); + + bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, + pcache_aio_cb, acb); + return acb; +} + +static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + QemuOpts *opts; + Error *local_err = NULL; + int ret = 0; + + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto fail; + } + + assert(bs->file == NULL); + bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, + "image", bs, &child_format, false, &local_err); + if (local_err) { + ret = -EINVAL; + error_propagate(errp, local_err); + } +fail: + qemu_opts_del(opts); + return ret; +} + +static void pcache_close(BlockDriverState *bs) +{ +} + +static void pcache_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + qdict_put(options, "x-image", qstring_from_str(filename)); +} + +static int64_t pcache_getlength(BlockDriverState *bs) +{ + return bdrv_getlength(bs->file->bs); +} + +static bool pcache_recurse_is_first_non_filter(BlockDriverState *bs, + BlockDriverState *candidate) +{ + return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); +} + +static BlockDriver bdrv_pcache = { + .format_name = "pcache", + .protocol_name = "pcache", + .instance_size = 0, + + .bdrv_parse_filename = pcache_parse_filename, + .bdrv_file_open = pcache_file_open, + .bdrv_close = pcache_close, + .bdrv_getlength = pcache_getlength, + + .bdrv_aio_readv = pcache_aio_readv, + .bdrv_aio_writev = pcache_aio_writev, + + .is_filter = true, + .bdrv_recurse_is_first_non_filter = pcache_recurse_is_first_non_filter, +}; + +static void bdrv_cache_init(void) +{ + bdrv_register(&bdrv_pcache); +} + +block_init(bdrv_cache_init);