From patchwork Fri Nov 24 16:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtepa X-Patchwork-Id: 17065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1333950vqx; Fri, 24 Nov 2023 08:12:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUvO487ujGMbIwGSdjOtPsHVCkM4eSZpZxz8TpFicWlXd5Hlahp6BeK3+pbWD2OzvR/4Mr X-Received: by 2002:a05:6830:157:b0:6d7:f367:518f with SMTP id j23-20020a056830015700b006d7f367518fmr3952071otp.16.1700842377650; Fri, 24 Nov 2023 08:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700842377; cv=none; d=google.com; s=arc-20160816; b=r4FE0BKWZwmHDL7ChJ01xr3J1NHqgaXRec3BHlbiQWUaUw9dARl9fPQoQcj6++s+S8 D8ITHvbaeBaM/dj6Y+k4+hd+B6hOuRnNwwadW1JjVIAL7eR2fNes+nZrXcAzc9oE6rsl atZwJWRQr7FNJBQIwegYDPKhlnG8EC1hxBbLgvhr9+6mJIR/5tUFud3SYUC1lrRAedFy fp3MBZRUWfSa+6mfJXa7vFa/k4O/sdv+8IQuygz/u3VrG2ErVyAH4DGxPYO36tCH9epo UhpFicQ200lV/hKycq8uguYRoaTwNWbZva5CyBdhoEu/BBAI7KwNXHA6iwR2f+YRDcUQ W+BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9n3c1WXBz4lxlyB6dBEMGNuqryUbttK1iJefoc3GvV0=; fh=sGVGOFmMLAnX+07bQNWtBjXylIzixACIEFOcvK9wZzw=; b=eRhqDWa2FcuOeWnz++LBydyZHgugflAiCYZpeddta9TIg0hPdGT1PLpLIxlZdk86hM BYUUE7d2Ek6pERy7flVR7fBxjb33WsYQMBNiSJza3qK6nAFWdGu/oRLNswyFawBF8Gd1 7G8JnM5WTEk32Ecm2n6IJhmUmAhMj5fZv/RSormSC2dfluyfDHltaL24iR81kxxYy4Rq 1IlXZmdcKx0cQL9ntwVWrshh106ZHChSVF0lElxxV6e6zfE3n3TXkXwFDwnwcx8xhHGD 5bjBsE3jlsXPkaPABFOGu/6E0XywtwmwrnV+l/G9/vhiBolHMWlu6VOGCHLODDKevH6p bH9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ufUApXbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w9-20020a056830060900b006d65371f121si1481614oti.367.2023.11.24.08.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 08:12:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ufUApXbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 61E40804F61F; Fri, 24 Nov 2023 08:10:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbjKXQK3 (ORCPT + 99 others); Fri, 24 Nov 2023 11:10:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjKXQK2 (ORCPT ); Fri, 24 Nov 2023 11:10:28 -0500 X-Greylist: delayed 325 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 24 Nov 2023 08:10:32 PST Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A98C1998 for ; Fri, 24 Nov 2023 08:10:32 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700841904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9n3c1WXBz4lxlyB6dBEMGNuqryUbttK1iJefoc3GvV0=; b=ufUApXbkL4u8/4es/MN12fyBMDrWdeSuZO9T4Q4cExLIsNgxLNsikNO3pQoyjRxWphsZHt RPTGkMn6TAouyrZgF+bHYgVnl0El5K+X0TznhffRH0f3w6HUZCsG6AKZsm2DRoIiLuLgIw 53LePh6Cp2om5pkGkFD0Jc1WCwg/6cE= From: Sergei Shtepa To: axboe@kernel.dk, hch@infradead.org, corbet@lwn.net, snitzer@kernel.org Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viro@zeniv.linux.org.uk, brauner@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de, christian.koenig@amd.com, yi.l.liu@intel.com, jirislaby@kernel.org, stfrench@microsoft.com, jpanis@baylibre.com, jgg@ziepe.ca, contact@emersion.fr, dchinner@redhat.com, jack@suse.cz, linux@weissschuh.net, min15.li@samsung.com, dlemoal@kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Sergei Shtepa Subject: [PATCH v6 00/11] blksnap - block devices snapshots module Date: Fri, 24 Nov 2023 17:04:48 +0100 Message-Id: <20231124160459.26227-1-sergei.shtepa@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 24 Nov 2023 08:10:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783462496950857382 X-GMAIL-MSGID: 1783462496950857382 From: Sergei Shtepa Hi all. I am happy to offer an improved version of the Block Devices Snapshots Module. It allows creating non-persistent snapshots of any block devices. The main purpose of such snapshots is to provide backups of block devices. See more in Documentation/block/blksnap.rst. The Block Device Filtering Mechanism is added to the block layer. This allows attaching and detaching block device filters to the block layer. Filters allow extending the functionality of the block layer. See more in Documentation/block/blkfilter.rst. The tool, library and tests for working with blksnap can be found on github. Link: https://github.com/veeam/blksnap/tree/stable-v2.0 From the documentation, it is possible to learn how to manage the module using the library and console tool. In the new version, the method of saving snapshot difference has been changed. Why this should have been done, Dave Chinner described in detail in the comments to the previous version. Link: https://lore.kernel.org/lkml/20230612135228.10702-1-sergei.shtepa@veeam.com/T/#mfe9b8f46833011deea4b24714212230ac38db978 The module is incompatible with features hardware inline encryption and data integrity. Thanks to Eric Biggers . Link: https://lore.kernel.org/lkml/20230612135228.10702-1-sergei.shtepa@veeam.com/T/#m3f13e580876bff1d283eb2a79d1ecdef3b98cc42 Unfortunately, I didn't have a chance to check it, since I don't have such equipment. And it is impossible to determine the presence of a blk-crypto-fallback at the block layer filter level. The filter receives already encrypted data. The original device continues to work without problems, but the data in the snapshot is encrypted. Perhaps they can be decrypted if specify the correct key when mounting the file system for snapshot image. Tested on amd64 and ppc64le with a page size of 64KiB and a storage block size of 4KiB. Based on LK v6.7-rc2. Compatible with branch 'for-next'. link: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git v6 changes: - The difference storage has been changed. In the previous version, the file was created only to reserve sector ranges on a block device. The data was stored directly to the block device in these sector ranges. Now saving and reading data is done using 'VFS' using vfs_iter_write() and vfs_iter_read() functions. This allows not to depend on the filesystem and use, for example, tmpfs. Using an unnamed temporary file allows hiding it from other processes and automatically release it when the snapshot is closed. However, now the module does not allow adding a block device to the snapshot on which the difference storage is located. There is no way to ensure the immutability of file metadata when writing data to a file. This means that the metadata of the filesystem may change, which may cause damage to the snapshot. - _IOW and _IOR were mixed up - fixed. - Protection against the use of the snapshots for block devices with hardware inline encryption and data integrity was implemented. Compatibility with them was not planned and has not been tested at the moment. v5 changes: - Rebase for "kernel/git/axboe/linux-block.git" branch "for-6.5/block". Link: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/log/?h=for-6.5/block v4 changes: - Structures for describing the state of chunks are allocated dynamically. This reduces memory consumption, since the struct chunk is allocated only for those blocks for which the snapshot image state differs from the original block device. - The algorithm for calculating the chunk size depending on the size of the block device has been changed. For large block devices, it is now possible to allocate a larger number of chunks, and their size is smaller. - For block devices, a 'filter' file has been added to /sys/block/. It displays the name of the filter that is attached to the block device. - Fixed a problem with the lack of protection against re-adding a block device to a snapshot. - Fixed a bug in the algorithm of allocating the next bio for a chunk. This problem was occurred on large disks, for which a chunk consists of at least two bio. - The ownership mechanism of the diff_area structure has been changed. This fixed the error of prematurely releasing the diff_area structure when destroying the snapshot. - Documentation corrected. - The Sparse analyzer is passed. - Use __u64 type instead pointers in UAPI. v3 changes: - New block device I/O controls BLKFILTER_ATTACH and BLKFILTER_DETACH allow to attach and detach filters. - New block device I/O control BLKFILTER_CTL allow sending command to attached block device filter. - The copy-on-write algorithm for processing I/O units has been optimized and has become asynchronous. - The snapshot image reading algorithm has been optimized and has become asynchronous. - Optimized the finite state machine for processing chunks. - Fixed a tracking block size calculation bug. v2 changes: - Added documentation for Block Device Filtering Mechanism. - Added documentation for Block Devices Snapshots Module (blksnap). - The MAINTAINERS file has been updated. - Optimized queue code for snapshot images. - Fixed comments, log messages and code for better readability. v1 changes: - Forgotten "static" declarations have been added. - The text of the comments has been corrected. - It is possible to connect only one filter, since there are no others in upstream. - Do not have additional locks for attach/detach filter. - blksnap.h moved to include/uapi/. - #pragma once and commented code removed. - uuid_t removed from user API. - Removed default values for module parameters from the configuration file. - The debugging code for tracking memory leaks has been removed. - Simplified Makefile. - Optimized work with large memory buffers, CBT tables are now in virtual memory. - The allocation code of minor numbers has been optimized. - The implementation of the snapshot image block device has been simplified, now it is a bio-based block device. - Removed initialization of global variables with null values. - only one bio is used to copy one chunk. - Checked on ppc64le. Sergei Shtepa (11): documentation: Block Device Filtering Mechanism block: Block Device Filtering Mechanism documentation: Block Devices Snapshots Module blksnap: header file of the module interface blksnap: module management interface functions blksnap: handling and tracking I/O units blksnap: difference storage and chunk blksnap: event queue from the difference storage blksnap: snapshot and snapshot image block device blksnap: Kconfig and Makefile blksnap: prevents using devices with data integrity or inline encryption Documentation/block/blkfilter.rst | 66 ++ Documentation/block/blksnap.rst | 352 +++++++++ Documentation/block/index.rst | 2 + .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 17 + block/Makefile | 3 +- block/bdev.c | 2 + block/blk-core.c | 35 +- block/blk-filter.c | 238 +++++++ block/blk.h | 11 + block/genhd.c | 10 + block/ioctl.c | 7 + block/partitions/core.c | 9 + drivers/block/Kconfig | 2 + drivers/block/Makefile | 2 + drivers/block/blksnap/Kconfig | 31 + drivers/block/blksnap/Makefile | 15 + drivers/block/blksnap/cbt_map.c | 228 ++++++ drivers/block/blksnap/cbt_map.h | 90 +++ drivers/block/blksnap/chunk.c | 667 ++++++++++++++++++ drivers/block/blksnap/chunk.h | 142 ++++ drivers/block/blksnap/diff_area.c | 601 ++++++++++++++++ drivers/block/blksnap/diff_area.h | 175 +++++ drivers/block/blksnap/diff_buffer.c | 115 +++ drivers/block/blksnap/diff_buffer.h | 37 + drivers/block/blksnap/diff_storage.c | 291 ++++++++ drivers/block/blksnap/diff_storage.h | 104 +++ drivers/block/blksnap/event_queue.c | 81 +++ drivers/block/blksnap/event_queue.h | 64 ++ drivers/block/blksnap/main.c | 475 +++++++++++++ drivers/block/blksnap/params.h | 16 + drivers/block/blksnap/snapimage.c | 134 ++++ drivers/block/blksnap/snapimage.h | 10 + drivers/block/blksnap/snapshot.c | 457 ++++++++++++ drivers/block/blksnap/snapshot.h | 64 ++ drivers/block/blksnap/tracker.c | 358 ++++++++++ drivers/block/blksnap/tracker.h | 78 ++ include/linux/blk-filter.h | 51 ++ include/linux/blk_types.h | 1 + include/linux/blkdev.h | 1 + include/linux/sched.h | 1 + include/uapi/linux/blk-filter.h | 35 + include/uapi/linux/blksnap.h | 388 ++++++++++ include/uapi/linux/fs.h | 3 + 44 files changed, 5468 insertions(+), 2 deletions(-) create mode 100644 Documentation/block/blkfilter.rst create mode 100644 Documentation/block/blksnap.rst create mode 100644 block/blk-filter.c create mode 100644 drivers/block/blksnap/Kconfig create mode 100644 drivers/block/blksnap/Makefile create mode 100644 drivers/block/blksnap/cbt_map.c create mode 100644 drivers/block/blksnap/cbt_map.h create mode 100644 drivers/block/blksnap/chunk.c create mode 100644 drivers/block/blksnap/chunk.h create mode 100644 drivers/block/blksnap/diff_area.c create mode 100644 drivers/block/blksnap/diff_area.h create mode 100644 drivers/block/blksnap/diff_buffer.c create mode 100644 drivers/block/blksnap/diff_buffer.h create mode 100644 drivers/block/blksnap/diff_storage.c create mode 100644 drivers/block/blksnap/diff_storage.h create mode 100644 drivers/block/blksnap/event_queue.c create mode 100644 drivers/block/blksnap/event_queue.h create mode 100644 drivers/block/blksnap/main.c create mode 100644 drivers/block/blksnap/params.h create mode 100644 drivers/block/blksnap/snapimage.c create mode 100644 drivers/block/blksnap/snapimage.h create mode 100644 drivers/block/blksnap/snapshot.c create mode 100644 drivers/block/blksnap/snapshot.h create mode 100644 drivers/block/blksnap/tracker.c create mode 100644 drivers/block/blksnap/tracker.h create mode 100644 include/linux/blk-filter.h create mode 100644 include/uapi/linux/blk-filter.h create mode 100644 include/uapi/linux/blksnap.h