From patchwork Thu Aug 25 13:44: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: 9299387 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 5084A60459 for ; Thu, 25 Aug 2016 13:46:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 414DA29332 for ; Thu, 25 Aug 2016 13:46:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35B1B29334; Thu, 25 Aug 2016 13:46:31 +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 8E05C29338 for ; Thu, 25 Aug 2016 13:46:30 +0000 (UTC) Received: from localhost ([::1]:56351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuzF-0004NJ-LO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 09:46:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyS-0004EV-Qq for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyR-0002Bx-2y for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:40 -0400 Received: from mail-db5eur01on0133.outbound.protection.outlook.com ([104.47.2.133]:34146 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyJ-00026u-4N; Thu, 25 Aug 2016 09:45:31 -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=bcvOpMCETS3BSBuqomT6l5qIfnh88wQj5dCvxeQ0MeNpLJV3Y4uSB0iUUK1/Gqkeo6TYIyGPHqx+3nN7rctyE1PVbMp+vwvZhSwi4hH2fL59I55hRUQovyCuC0ulrX7staPYN/fAOGFcGHhon30PKaE/Q7Yg+0hfgjtzxip4QHY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 25 Aug 2016 13:45:27 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:00 +0300 Message-ID: <20160825134421.20231-2-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160825134421.20231-1-pbutsykin@virtuozzo.com> References: <20160825134421.20231-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR02CA0013.eurprd02.prod.outlook.com (10.242.225.141) To DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) X-MS-Office365-Filtering-Correlation-Id: 65af34f4-2047-4c72-6d3a-08d3ccee12c0 X-Microsoft-Exchange-Diagnostics: 1; DB6PR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r4gNYKf1b0VFi0C1EWoSN6LTSnIxd1OSqLGLMZGN4i+AyRob5icVLYYP6mrek+i94lQpntUhzno1KOFD0NTy79Rji5cUQws+M= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 31:VeW5C6O8j3h/HsVw3OspXuuKpJDYE1wElhBfpPpi7djKAbZnfUXWcebRnC6OiulXaOeJNqO3YuJHrh1etCwlDm8BpSlDPB11b10i7qgEyS9g8ULDv2QnACB1MUaTcKdBfgbxZcbS1RfsZEGUeXcZAMNYB1tShN9tErt4RJjPNCbDqzZijar1il10CbnD0v6PCQSkvV6mTenSdYWx5rOI4cfoGrViCf2GSjwmrlltfP0=; 4:KMA22JQDI6f8+uidE8U0d3zI4yHCXFQj5JSm/r9d1EUVAewsmefBUwQxWOGHqggpqfqdMrKx0N2GGH6QDEGefvXP5olytxA527eiXLCu8oSjZf+R5wNF4A3qrkdVhVOScRI261mGL/ktt+pko2Ax/ztVuObfpTn5y46Mn+3ztb2wAZJ4PMuNMKCluGgzx/cPtu0orFe6gP8YGPQmvpz94sfsgcSAIRqI4bn5ylGf4JEXcZ1LB7MxcbbeFM/zL8KYq2mvSeLgXyIbHpxzrF2lPwhuQ98ZTX9KDIDsREDZ4YdovQVicCa9LOBI/6MifkBx/ju9mpHl3oZUUbevqhMGaUjlf+wvsCSqV2fUf90X8T3WIALpp9PlUDP2cLJ92OIA6lr/M6czZq7yNJhFZsRy5vpL/79mA/QLbArxldYdzZY= 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)(6043046)(6042046); SRVR:DB6PR0802MB2549; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2549; X-Forefront-PRVS: 0045236D47 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(86362001)(33646002)(1076002)(69596002)(5003940100001)(42186005)(68736007)(189998001)(92566002)(66066001)(106356001)(47776003)(6116002)(3846002)(586003)(36756003)(5001770100001)(97736004)(2906002)(4326007)(2950100001)(5660300001)(76176999)(48376002)(53416004)(105586002)(50466002)(81156014)(8676002)(50226002)(77096005)(81166006)(19580405001)(50986999)(229853001)(101416001)(7846002)(7736002)(305945005)(19580395003)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DB6PR0802MB2549; 23:6YKv8tcnS5TYaqmPq46aJCMR4ihocOIWRQw9mlg?= =?us-ascii?Q?tC9rtv+VKl4Cf6eJdJYk3VoIRkH8l3I8J6HnhJPc9rJtLS5YzEULASRlxwxe?= =?us-ascii?Q?UvdCjWNej+By2gO5w5myBMfPJIcghPIDaWymV6L0HFTBNBSzhhufEd6Q1QpU?= =?us-ascii?Q?KbyZ7jQRG/SCQzd78MKkAE82VH3u3vgkqt+sO9p9BVcIUgBxXeM+me84/1S9?= =?us-ascii?Q?HCE7FMYpSd9W6m4yxasMJ6MkuOomCA9DtLl/l9G52x4hS21qsoOyhk3+u2bh?= =?us-ascii?Q?4LO46pEcguN4fbutjAIaJVQv38ysUkemzHavEJOXCTyH9xtPsnNsS1FWra8G?= =?us-ascii?Q?Waa+7A42crugf/AbqedBwHDx8Mapf7uQwrEjF8h4GBBNANJZxjvF82mI2zEK?= =?us-ascii?Q?CRE7NOX3bIhmjyzaek3nbpNzdM0hgqUcX6FGdqtR7zrV9I88yh2w/GsrnoG1?= =?us-ascii?Q?aejvEoBwDHEUTMHq/K3AMcEGwxwqUzAQcyZx+/IyN7aHvNv6n0/WvVxj/UOJ?= =?us-ascii?Q?GFQ4ehd+VI5YtiqWOs9TTM/mO6Jr0mFu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k3Drspv5IKJfJgi8ZJ3W0jjJDx9o2KLPAvettHt23mTy+0I85StY+62ulj; 5:iw9Xmeq2nRN/4QYS1ZIQ9zLDLEOw+OzPOmR/3gQIkDE6A6hSa02KLZJaU1gsDHWEeddzTNGE+07IrShtsO9qfXrVBTCXL0Plc9menKIYWlqIsQZExN4ET+tNI5OiNk7D9gZhqLSYRI3KDS7HZ7IJIg==; 24:ep1UsPFUvggh8mv65yeAhpCngrmH31JtQjkvw+RVWWTiuqvh1bIdVVTDM3cMy0jsmlHlt/d20UUlEGFyodvJkOMNMvPYsBKqLcMinK2NU4E=; 7:CutNZjHKZLjyza68plTACZQDFq4i40YSOJQjUSj5OmMSOd0nw3J6obQq7LZn5wnhnwSZcxh8dig3UT4riGM6u58bG36UhCX9u1QpANiBPed6fY4dEq0L1GJ3VJG2ZvMC+QtVlIKGjTKEvHET9QBdNdDZOPIgonYXpt0M87sl8nsPmcTviqJEAEzImpWM+lsXBJuHIlUX+q4dFm/kbGJLgLkzIbDZ8EQxi4yMhBK6YJDYkVHztWo0+x3vQxaLioBg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:ed2k6gHpm8Hzkvp4q2oRn+LRgKo5cZcA0SBg1TMu1QzVOwtjYpyrvXNGvIJi1oBX/6RPm1hOhZhBtVqwJbH4bwDBdq28vuCkcWjjRj+5V5Ex2mTSq381ePzzvvhzySdRE2ab5mhUusygl9aeEyQy9Xtt85hlVTqjGcy+YLowIUI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:27.1459 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2549 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.133 Subject: [Qemu-devel] [PATCH RFC 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, den@openvz.org, jsnow@redhat.com, stefanha@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);