Skip to content

Commit cb95e7b

Browse files
Mark FashehJosef Bacik
authored andcommitted
btrfs: add "no file data" flag to btrfs send ioctl
This patch adds the flag, BTRFS_SEND_FLAG_NO_FILE_DATA to the btrfs send ioctl code. When this flag is set, the btrfs send code will never write file data into the stream (thus also avoiding expensive reads of that data in the first place). BTRFS_SEND_C_UPDATE_EXTENT commands will be sent (instead of BTRFS_SEND_C_WRITE) with an offset, length pair indicating the extent in question. This patch does not affect the operation of BTRFS_SEND_C_CLONE commands - they will continue to be sent when a search finds an appropriate extent to clone from. Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
1 parent 2f697dc commit cb95e7b

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

‎fs/btrfs/send.c‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct send_ctx {
8585
u32 send_max_size;
8686
u64 total_send_size;
8787
u64 cmd_send_size[BTRFS_SEND_C_MAX + 1];
88+
u64 flags; /* 'flags' member of btrfs_ioctl_send_args is u64 */
8889

8990
struct vfsmount *mnt;
9091

@@ -3709,6 +3710,39 @@ verbose_printk("btrfs: send_clone offset=%llu, len=%d, clone_root=%llu, "
37093710
return ret;
37103711
}
37113712

3713+
/*
3714+
* Send an update extent command to user space.
3715+
*/
3716+
static int send_update_extent(struct send_ctx *sctx,
3717+
u64 offset, u32 len)
3718+
{
3719+
int ret = 0;
3720+
struct fs_path *p;
3721+
3722+
p = fs_path_alloc(sctx);
3723+
if (!p)
3724+
return -ENOMEM;
3725+
3726+
ret = begin_cmd(sctx, BTRFS_SEND_C_UPDATE_EXTENT);
3727+
if (ret < 0)
3728+
goto out;
3729+
3730+
ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p);
3731+
if (ret < 0)
3732+
goto out;
3733+
3734+
TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p);
3735+
TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset);
3736+
TLV_PUT_U64(sctx, BTRFS_SEND_A_SIZE, len);
3737+
3738+
ret = send_cmd(sctx);
3739+
3740+
tlv_put_failure:
3741+
out:
3742+
fs_path_free(sctx, p);
3743+
return ret;
3744+
}
3745+
37123746
static int send_write_or_clone(struct send_ctx *sctx,
37133747
struct btrfs_path *path,
37143748
struct btrfs_key *key,
@@ -3744,7 +3778,11 @@ static int send_write_or_clone(struct send_ctx *sctx,
37443778
goto out;
37453779
}
37463780

3747-
if (!clone_root) {
3781+
if (clone_root) {
3782+
ret = send_clone(sctx, offset, len, clone_root);
3783+
} else if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) {
3784+
ret = send_update_extent(sctx, offset, len);
3785+
} else {
37483786
while (pos < len) {
37493787
l = len - pos;
37503788
if (l > BTRFS_SEND_READ_SIZE)
@@ -3757,10 +3795,7 @@ static int send_write_or_clone(struct send_ctx *sctx,
37573795
pos += ret;
37583796
}
37593797
ret = 0;
3760-
} else {
3761-
ret = send_clone(sctx, offset, len, clone_root);
37623798
}
3763-
37643799
out:
37653800
return ret;
37663801
}
@@ -4560,6 +4595,11 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
45604595
goto out;
45614596
}
45624597

4598+
if (arg->flags & ~BTRFS_SEND_FLAG_NO_FILE_DATA) {
4599+
ret = -EINVAL;
4600+
goto out;
4601+
}
4602+
45634603
sctx = kzalloc(sizeof(struct send_ctx), GFP_NOFS);
45644604
if (!sctx) {
45654605
ret = -ENOMEM;
@@ -4571,6 +4611,8 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
45714611
INIT_RADIX_TREE(&sctx->name_cache, GFP_NOFS);
45724612
INIT_LIST_HEAD(&sctx->name_cache_list);
45734613

4614+
sctx->flags = arg->flags;
4615+
45744616
sctx->send_filp = fget(arg->send_fd);
45754617
if (IS_ERR(sctx->send_filp)) {
45764618
ret = PTR_ERR(sctx->send_filp);

‎fs/btrfs/send.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ enum btrfs_send_cmd {
8686
BTRFS_SEND_C_UTIMES,
8787

8888
BTRFS_SEND_C_END,
89+
BTRFS_SEND_C_UPDATE_EXTENT,
8990
__BTRFS_SEND_C_MAX,
9091
};
9192
#define BTRFS_SEND_C_MAX (__BTRFS_SEND_C_MAX - 1)

‎include/uapi/linux/btrfs.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ struct btrfs_ioctl_received_subvol_args {
407407
__u64 reserved[16]; /* in */
408408
};
409409

410+
/*
411+
* Caller doesn't want file data in the send stream, even if the
412+
* search of clone sources doesn't find an extent. UPDATE_EXTENT
413+
* commands will be sent instead of WRITE commands.
414+
*/
415+
#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
416+
410417
struct btrfs_ioctl_send_args {
411418
__s64 send_fd; /* in */
412419
__u64 clone_sources_count; /* in */

0 commit comments

Comments
 (0)