linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs: fix send to deal with sparse files properly
Date: Tue, 20 Aug 2013 15:57:08 -0400	[thread overview]
Message-ID: <1377028628-19544-1-git-send-email-jbacik@fusionio.com> (raw)

Send was just sending everything it found, even if the extent was a hole.  This
is unpleasant for users, so just skip holes when we are sending.  This will also
skip sending prealloc extents since the send spec doesn't have a prealloc
command.  Eventually we will add a prealloc command and rev the send version so
we can send down the prealloc info.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
 fs/btrfs/send.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index db7da68..3a1e75a 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -4011,8 +4011,10 @@ static int process_extent(struct send_ctx *sctx,
 			  struct btrfs_path *path,
 			  struct btrfs_key *key)
 {
-	int ret = 0;
 	struct clone_root *found_clone = NULL;
+	struct btrfs_file_extent_item *ei;
+	int ret = 0;
+	u8 type;
 
 	if (S_ISLNK(sctx->cur_inode_mode))
 		return 0;
@@ -4027,6 +4029,27 @@ static int process_extent(struct send_ctx *sctx,
 		}
 	}
 
+	ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
+			    struct btrfs_file_extent_item);
+	type = btrfs_file_extent_type(path->nodes[0], ei);
+	if (type == BTRFS_FILE_EXTENT_PREALLOC ||
+	    type == BTRFS_FILE_EXTENT_REG) {
+		/*
+		 * The send spec does not have a prealloc command yet, so just
+		 * leave a hole for prealloc'ed extents until we have enough
+		 * commands queued up to justify rev'ing the send spec.
+		 */
+		if (type == BTRFS_FILE_EXTENT_PREALLOC) {
+			ret = 0;
+			goto out;
+		}
+
+		/* Have a hole, just skip it. */
+		if (btrfs_file_extent_disk_bytenr(path->nodes[0], ei) == 0) {
+			ret = 0;
+			goto out;
+		}
+	}
 	ret = find_extent_clone(sctx, path, key->objectid, key->offset,
 			sctx->cur_inode_size, &found_clone);
 	if (ret != -ENOENT && ret < 0)
-- 
1.7.7.6


                 reply	other threads:[~2013-08-20 19:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377028628-19544-1-git-send-email-jbacik@fusionio.com \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).