From patchwork Wed Jan 9 17:39:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Lyakas X-Patchwork-Id: 1953831 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 73048E007B for ; Wed, 9 Jan 2013 17:39:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758023Ab3AIRjo (ORCPT ); Wed, 9 Jan 2013 12:39:44 -0500 Received: from mail-ia0-f175.google.com ([209.85.210.175]:45754 "EHLO mail-ia0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754183Ab3AIRjn (ORCPT ); Wed, 9 Jan 2013 12:39:43 -0500 Received: by mail-ia0-f175.google.com with SMTP id 21so1561578iay.20 for ; Wed, 09 Jan 2013 09:39:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type:x-gm-message-state; bh=dcDMUmh14edsd8nUCnAB/mYXrFt94DNXwGrjdOLbVU8=; b=AhiegpfXJs/HYF38cyfhBdrSeJDGaW/CzQEO1vNsphc8+m5Uh/5+miPimoY13OH4GG qZbPcXJpwDC1bt1CM6XBlpWS14Rh4YExalYZwveO3J/wcvm6QtKYvW2PBGEwon/SNmt5 cejNHm+sYT3WtoddK1I8R9ioOXeYaqmxIYHoDVuwHkeuqe4ps4iep8vS8Eb9ijylzw2P jNHx7Q8uPX09Pvru3vJlOwlEsDoMwsGQ8PUzNSBMVMKdqkROblUjiADN06E2UOkwBq4T RAtyGC02uw4GlFUO8xtjsw+kp1mxI/SEuag6H9Q+fU5onx2yiIpJgG0OY1YObZs8WBOp OiQg== MIME-Version: 1.0 X-Received: by 10.50.207.70 with SMTP id lu6mr2459491igc.50.1357753183561; Wed, 09 Jan 2013 09:39:43 -0800 (PST) Received: by 10.64.138.165 with HTTP; Wed, 9 Jan 2013 09:39:43 -0800 (PST) Date: Wed, 9 Jan 2013 19:39:43 +0200 Message-ID: Subject: [PATCH 1/2] Avoid sending disknr==0 extents when possible From: Alex Lyakas To: Alexander Block , Jan Schmidt , linux-btrfs Cc: Arne Jansen , Chen Yang X-Gm-Message-State: ALoCoQmYUWXkeBgA5DIb4tNKDT8mXiEZEJKNQEAUyYA4/tkX/NqymFsm3LdT39tVtXq9qZMisHUP Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] Avoid sending disknr==0 extents in the following cases: 1) full send 2) new inode in a diff-send 3) when disknr==0 extents are added to the end of an inode Original-version-by: Chen Yang Signed-off-by: Alex Lyakas --- fs/btrfs/send.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 5445454..5ab584f 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -3844,7 +3844,8 @@ static int is_extent_unchanged(struct send_ctx *sctx, btrfs_item_key_to_cpu(eb, &found_key, slot); if (found_key.objectid != key.objectid || found_key.type != key.type) { - ret = 0; + /* No need to send a no-data extent it in this case */ + ret = (left_disknr == 0) ? 1 : 0; goto out; } @@ -3870,7 +3871,8 @@ static int is_extent_unchanged(struct send_ctx *sctx, * This may only happen on the first iteration. */ if (found_key.offset + right_len <= ekey->offset) { - ret = 0; + /* No need to send a no-data extent it in this case */ + ret = (left_disknr == 0) ? 1 : 0; goto out; } @@ -3951,6 +3953,28 @@ static int process_extent(struct send_ctx *sctx, ret = 0; goto out; } + } else { + struct extent_buffer *eb; + struct btrfs_file_extent_item *ei; + u8 extent_type; + u64 extent_disknr; + + eb = path->nodes[0]; + ei = btrfs_item_ptr(eb, path->slots[0], + struct btrfs_file_extent_item); + + extent_type = btrfs_file_extent_type(eb, ei); + extent_disknr = btrfs_file_extent_disk_bytenr(eb, ei); + if (extent_type == BTRFS_FILE_EXTENT_REG && extent_disknr == 0) { + /* + * This is disknr=0 extent in a full-send or a new inode + * in a diff-send. Since we will send truncate command + * in finish_inode_if_needed anyways, the inode size will be + * correct, and we don't have to send all-zero data. + */ + ret = 0; + goto out; + } } ret = find_extent_clone(sctx, path, key->objectid, key->offset,