From patchwork Mon Jul 18 14:38:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 649590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3rtQm30BFZz9s9d; Tue, 19 Jul 2016 00:38:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b=qzwNWNvM; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1bP9h9-0007aA-SF; Mon, 18 Jul 2016 14:38:55 +0000 Received: from mail-it0-f42.google.com ([209.85.214.42]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1bP9gt-0007Vb-Bf for kernel-team@lists.ubuntu.com; Mon, 18 Jul 2016 14:38:39 +0000 Received: by mail-it0-f42.google.com with SMTP id u186so69652978ita.0 for ; Mon, 18 Jul 2016 07:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=pXrN4gJRviZppfYBCJpnAg2ZcjILDBRP5Sh+bMnSSKE=; b=qzwNWNvM6oT4m6YZDqqmc/k860kvPWfof3UuapZQ4zjeJCAfCHQJbPgo7BsFMxTH7x 72vs1YnH5Ul9lwNVHsBYLPUfU2uQTmhHoAfS564kbLN4CsLRCGryHE0nIRFc9uw9Q7Y/ 7N21EOCPyRnHLKCXbtBomBWufSFsqTyJJ0D1up8VTlORP4ZTSeMXQ3f17ugiOvG8tOrq mvPDa2qS5cbiQbYtlbcAL/YrXC5co6/lL/IrYhfxSc8qWtWHKoNmJm/I77YXsFU1zUsw 6esSFWzLk+pI4at1d8oNSoPCt4t4rDLqIBSpn74c4hx11QAAchakShpdqXRC4ED71JM8 9jRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=pXrN4gJRviZppfYBCJpnAg2ZcjILDBRP5Sh+bMnSSKE=; b=l/bqCAosZS+9c62iMqW9MxRbQ1RO3eZoF7bykWa82pvIHmvbRrb2NpEl2JAYGAoN4U 0FaB/tXBL4nZ92cHatPbYeR8KF8wurp7bUMovLxCe0BGDpvcpX6a/fEMrBXSm0wNSm0h RG1P4HtVOSeO6y3t41RH1sbdU382tNv+6Hi/921XeS3jUdmWn2iPO4/9pq378r4pqb1V N8uJvi8hqUx5qpX/xA/aoeXCSYrbsaFk2rFBzvlb6PeQgA/g0huCyob+ik9SydIpeVuP xUNYpnh3yz/SeDNGeJ+uBxFRI9It74Mtcr6lFnvJxNdNkZ6UI/ZBpGr588KLZqIL87zv vxuQ== X-Gm-Message-State: ALyK8tKgskjEeG1dLd7pAAonEsFP/HD4ZGpJMkcBk6fSVdGkmH8bV+zm5OOua+kUG0fWaklY X-Received: by 10.36.107.142 with SMTP id v136mr5947469itc.19.1468852718001; Mon, 18 Jul 2016 07:38:38 -0700 (PDT) Received: from localhost.localdomain (host-174-45-44-32.hln-mt.client.bresnan.net. [174.45.44.32]) by smtp.gmail.com with ESMTPSA id f129sm8902148ioe.35.2016.07.18.07.38.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jul 2016 07:38:37 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/3 Xenial SRU] ext4: factor out determining of hole size Date: Mon, 18 Jul 2016 08:38:27 -0600 Message-Id: <1468852709-12360-2-git-send-email-tim.gardner@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468852709-12360-1-git-send-email-tim.gardner@canonical.com> References: <1468852709-12360-1-git-send-email-tim.gardner@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Jan Kara BugLink: http://bugs.launchpad.net/bugs/1602524 upstream commit 140a52508a68387e22486659ff9eaa89a24f6e40 ext4_ext_put_gap_in_cache() determines hole size in the extent tree, then trims this with possible delayed allocated blocks, and inserts the result into the extent status tree. Factor out determination of the size of the hole in the extent tree as we will need this information in ext4_ext_map_blocks() as well. Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Tim Gardner --- fs/ext4/extents.c | 80 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3578b25..25d2d80 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2293,59 +2293,69 @@ static int ext4_fill_fiemap_extents(struct inode *inode, } /* - * ext4_ext_put_gap_in_cache: - * calculate boundaries of the gap that the requested block fits into - * and cache this gap + * ext4_ext_determine_hole - determine hole around given block + * @inode: inode we lookup in + * @path: path in extent tree to @lblk + * @lblk: pointer to logical block around which we want to determine hole + * + * Determine hole length (and start if easily possible) around given logical + * block. We don't try too hard to find the beginning of the hole but @path + * actually points to extent before @lblk, we provide it. + * + * The function returns the length of a hole starting at @lblk. We update @lblk + * to the beginning of the hole if we managed to find it. */ -static void -ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, - ext4_lblk_t block) +static ext4_lblk_t ext4_ext_determine_hole(struct inode *inode, + struct ext4_ext_path *path, + ext4_lblk_t *lblk) { int depth = ext_depth(inode); - ext4_lblk_t len; - ext4_lblk_t lblock; struct ext4_extent *ex; - struct extent_status es; + ext4_lblk_t len; ex = path[depth].p_ext; if (ex == NULL) { /* there is no extent yet, so gap is [0;-] */ - lblock = 0; + *lblk = 0; len = EXT_MAX_BLOCKS; - ext_debug("cache gap(whole file):"); - } else if (block < le32_to_cpu(ex->ee_block)) { - lblock = block; - len = le32_to_cpu(ex->ee_block) - block; - ext_debug("cache gap(before): %u [%u:%u]", - block, - le32_to_cpu(ex->ee_block), - ext4_ext_get_actual_len(ex)); - } else if (block >= le32_to_cpu(ex->ee_block) + } else if (*lblk < le32_to_cpu(ex->ee_block)) { + len = le32_to_cpu(ex->ee_block) - *lblk; + } else if (*lblk >= le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex)) { ext4_lblk_t next; - lblock = le32_to_cpu(ex->ee_block) - + ext4_ext_get_actual_len(ex); + *lblk = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); next = ext4_ext_next_allocated_block(path); - ext_debug("cache gap(after): [%u:%u] %u", - le32_to_cpu(ex->ee_block), - ext4_ext_get_actual_len(ex), - block); - BUG_ON(next == lblock); - len = next - lblock; + BUG_ON(next == *lblk); + len = next - *lblk; } else { BUG(); } + return len; +} - ext4_es_find_delayed_extent_range(inode, lblock, lblock + len - 1, &es); +/* + * ext4_ext_put_gap_in_cache: + * calculate boundaries of the gap that the requested block fits into + * and cache this gap + */ +static void +ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, + ext4_lblk_t hole_len) +{ + struct extent_status es; + + ext4_es_find_delayed_extent_range(inode, hole_start, + hole_start + hole_len - 1, &es); if (es.es_len) { /* There's delayed extent containing lblock? */ - if (es.es_lblk <= lblock) + if (es.es_lblk <= hole_start) return; - len = min(es.es_lblk - lblock, len); + hole_len = min(es.es_lblk - hole_start, hole_len); } - ext_debug(" -> %u:%u\n", lblock, len); - ext4_es_insert_extent(inode, lblock, len, ~0, EXTENT_STATUS_HOLE); + ext_debug(" -> %u:%u\n", hole_start, hole_len); + ext4_es_insert_extent(inode, hole_start, hole_len, ~0, + EXTENT_STATUS_HOLE); } /* @@ -4368,11 +4378,15 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, * we couldn't try to create block if create flag is zero */ if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) { + ext4_lblk_t hole_start, hole_len; + /* * put just found gap into cache to speed up * subsequent requests */ - ext4_ext_put_gap_in_cache(inode, path, map->m_lblk); + hole_start = map->m_lblk; + hole_len = ext4_ext_determine_hole(inode, path, &hole_start); + ext4_ext_put_gap_in_cache(inode, hole_start, hole_len); goto out2; }