From patchwork Thu Oct 1 18:36:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11812271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94A4D1668 for ; Thu, 1 Oct 2020 18:39:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79E68207DE for ; Thu, 1 Oct 2020 18:39:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mAf08R9T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733133AbgJASjK (ORCPT ); Thu, 1 Oct 2020 14:39:10 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24722 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733103AbgJASjH (ORCPT ); Thu, 1 Oct 2020 14:39:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1601577547; x=1633113547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q5i/I3gLwRLnWg5cl41eN7YTBx4uHlSfrYgPFVxy6iM=; b=mAf08R9TslT/9dkPgUbesT1T3v6CSs8E5x2gNXA5xuOkmHhY2FdezbQZ 4wsxwlTsPmMPoNfq8h6s1LM48kSPCVsrR2zw5N9G1xdbFUICb+HtRia1N XapOo0HTWEFxETneNXQExbj+hiu2wbchoXH2ZJBoSuJNBRc/cZL5X9rdh jMKOnBWmEAhIMOa8UQrUES80ouJhSivm0t0JlwmFr9xNmszNmDGAzpTgl CmR0xJOEGvjJuGQ0YFPbfdIr4zZibXTa7zLNTwNuwwmllAKq8x6ZeiVV0 WafPaXf2XAbbTmu89tNMAjracZA3JXh+Y2pvseqd8w/s4veKFG7XEtSBf g==; IronPort-SDR: ehF3AQeTioDudjVLILMlU8Z/oJCPcf6oEU6p6FPFWCsv/Gt+wOh7RHaJH7RH4GO4K2cvMsSvMe aC61N8n+st8gSRvRaby8o/rVm71MNpIvgxHJCnE5KiIHyQJky145UV6fG71lMVVQ1mFWs9AkT+ Ouon0qSzIR+k7VlqsYnybm2k+TLhsrZmltpsyz8D1fqLx+LW14aYFGRwSY68vQKSpkfr8OD9of CD8USv5hYlca4PY/POetwAZFIv9JBRF0j9907W1UYzAw8ObHyd1c350OFNBLq0lZk6xVucboNY 5/M= X-IronPort-AV: E=Sophos;i="5.77,324,1596470400"; d="scan'208";a="150036833" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 02 Oct 2020 02:38:42 +0800 IronPort-SDR: zEI/sW8fGcyZfUs4Cg42wmxrhwrRfPdG7GSIwRpfgGvjW1tVbtd//F984ja0oOLa5FaxU1EfPG 9ydqnGUyhgDg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 11:24:39 -0700 IronPort-SDR: mLJyzyrngVD96Zl4kdjiOE/N54Xjm4SOKuLetpDndMUnDP/FBZLiLJ31iBoQJjHuaLZVwyMSUF 1gmw0CGV93sw== WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Oct 2020 11:38:42 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, dsterba@suse.com Cc: hare@suse.com, linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v8 35/41] btrfs: enable relocation in ZONED mode Date: Fri, 2 Oct 2020 03:36:42 +0900 Message-Id: <0b38315d936c12a25e56118c429514541585aa23.1601574234.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org To serialize allocation and submit_bio, we introduced mutex around them. As a result, preallocation must be completely disabled to avoid a deadlock. Since current relocation process relies on preallocation to move file data extents, it must be handled in another way. In ZONED mode, we just truncate the inode to the size that we wanted to pre-allocate. Then, we flush dirty pages on the file before finishing relocation process. run_delalloc_zoned() will handle all the allocation and submit IOs to the underlying layers. Signed-off-by: Naohiro Aota --- fs/btrfs/relocation.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3602806d71bd..3fa60065b483 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2603,6 +2603,32 @@ static noinline_for_stack int prealloc_file_extent_cluster( if (ret) return ret; + /* + * In ZONED mode, we cannot preallocate the file region. Instead, we + * dirty and fiemap_write the region. + */ + + if (btrfs_fs_incompat(inode->root->fs_info, ZONED)) { + struct btrfs_root *root = inode->root; + struct btrfs_trans_handle *trans; + + end = cluster->end - offset + 1; + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + inode->vfs_inode.i_ctime = current_time(&inode->vfs_inode); + i_size_write(&inode->vfs_inode, end); + ret = btrfs_update_inode(trans, root, &inode->vfs_inode); + if (ret) { + btrfs_abort_transaction(trans, ret); + btrfs_end_transaction(trans); + return ret; + } + + return btrfs_end_transaction(trans); + } + inode_lock(&inode->vfs_inode); for (nr = 0; nr < cluster->nr; nr++) { start = cluster->boundary[nr] - offset; @@ -2799,6 +2825,8 @@ static int relocate_file_extent_cluster(struct inode *inode, } } WARN_ON(nr != cluster->nr); + if (btrfs_fs_incompat(fs_info, ZONED) && !ret) + ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); out: kfree(ra); return ret; @@ -3434,8 +3462,12 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, struct btrfs_path *path; struct btrfs_inode_item *item; struct extent_buffer *leaf; + u64 flags = BTRFS_INODE_NOCOMPRESS | BTRFS_INODE_PREALLOC; int ret; + if (btrfs_fs_incompat(trans->fs_info, ZONED)) + flags &= ~BTRFS_INODE_PREALLOC; + path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -3450,8 +3482,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, btrfs_set_inode_generation(leaf, item, 1); btrfs_set_inode_size(leaf, item, 0); btrfs_set_inode_mode(leaf, item, S_IFREG | 0600); - btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS | - BTRFS_INODE_PREALLOC); + btrfs_set_inode_flags(leaf, item, flags); btrfs_mark_buffer_dirty(leaf); out: btrfs_free_path(path);