aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/send.c
diff options
context:
space:
mode:
authorAlexander Block <ablock84@googlemail.com>2012-07-28 10:33:49 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-01 15:18:55 -0400
commite938c8ad543cd5ffe344371747484303ad51dfba (patch)
treee35ab6918023b66670b01cfc074f14526999a155 /fs/btrfs/send.c
parent766702ef49b8b5299d819f3a0ac42613c23424d1 (diff)
Btrfs: code cleanups for send/receive
Doing some code cleanups as suggested by Arne. Changes do not change any logic. Signed-off-by: Alexander Block <ablock84@googlemail.com>
Diffstat (limited to 'fs/btrfs/send.c')
-rw-r--r--fs/btrfs/send.c83
1 files changed, 35 insertions, 48 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 6926546939f6..3bc921aa5e21 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -1115,10 +1115,12 @@ static int __iterate_backrefs(u64 ino, u64 offset, u64 root, void *ctx_)
1115 */ 1115 */
1116 if (ino >= bctx->cur_objectid) 1116 if (ino >= bctx->cur_objectid)
1117 return 0; 1117 return 0;
1118 /*if (ino > ctx->cur_objectid) 1118#if 0
1119 if (ino > bctx->cur_objectid)
1120 return 0;
1121 if (offset + bctx->extent_len > bctx->cur_offset)
1119 return 0; 1122 return 0;
1120 if (offset + ctx->extent_len > ctx->cur_offset) 1123#endif
1121 return 0;*/
1122 } 1124 }
1123 1125
1124 bctx->found++; 1126 bctx->found++;
@@ -1327,8 +1329,6 @@ static int read_symlink(struct send_ctx *sctx,
1327 len = btrfs_file_extent_inline_len(path->nodes[0], ei); 1329 len = btrfs_file_extent_inline_len(path->nodes[0], ei);
1328 1330
1329 ret = fs_path_add_from_extent_buffer(dest, path->nodes[0], off, len); 1331 ret = fs_path_add_from_extent_buffer(dest, path->nodes[0], off, len);
1330 if (ret < 0)
1331 goto out;
1332 1332
1333out: 1333out:
1334 btrfs_free_path(path); 1334 btrfs_free_path(path);
@@ -1440,9 +1440,9 @@ static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen)
1440 } 1440 }
1441 1441
1442 if (!left_ret && !right_ret) { 1442 if (!left_ret && !right_ret) {
1443 if (left_gen == gen && right_gen == gen) 1443 if (left_gen == gen && right_gen == gen) {
1444 ret = inode_state_no_change; 1444 ret = inode_state_no_change;
1445 else if (left_gen == gen) { 1445 } else if (left_gen == gen) {
1446 if (ino < sctx->send_progress) 1446 if (ino < sctx->send_progress)
1447 ret = inode_state_did_create; 1447 ret = inode_state_did_create;
1448 else 1448 else
@@ -1615,11 +1615,7 @@ static int is_first_ref(struct send_ctx *sctx,
1615 goto out; 1615 goto out;
1616 } 1616 }
1617 1617
1618 ret = memcmp(tmp_name->start, name, name_len); 1618 ret = !memcmp(tmp_name->start, name, name_len);
1619 if (ret)
1620 ret = 0;
1621 else
1622 ret = 1;
1623 1619
1624out: 1620out:
1625 fs_path_free(sctx, tmp_name); 1621 fs_path_free(sctx, tmp_name);
@@ -1761,8 +1757,6 @@ static int did_overwrite_first_ref(struct send_ctx *sctx, u64 ino, u64 gen)
1761 1757
1762 ret = did_overwrite_ref(sctx, dir, dir_gen, ino, gen, 1758 ret = did_overwrite_ref(sctx, dir, dir_gen, ino, gen,
1763 name->start, fs_path_len(name)); 1759 name->start, fs_path_len(name));
1764 if (ret < 0)
1765 goto out;
1766 1760
1767out: 1761out:
1768 fs_path_free(sctx, name); 1762 fs_path_free(sctx, name);
@@ -1866,9 +1860,10 @@ static void name_cache_clean_unused(struct send_ctx *sctx)
1866static void name_cache_free(struct send_ctx *sctx) 1860static void name_cache_free(struct send_ctx *sctx)
1867{ 1861{
1868 struct name_cache_entry *nce; 1862 struct name_cache_entry *nce;
1869 struct name_cache_entry *tmp;
1870 1863
1871 list_for_each_entry_safe(nce, tmp, &sctx->name_cache_list, list) { 1864 while (!list_empty(&sctx->name_cache_list)) {
1865 nce = list_entry(sctx->name_cache_list.next,
1866 struct name_cache_entry, list);
1872 name_cache_delete(sctx, nce); 1867 name_cache_delete(sctx, nce);
1873 kfree(nce); 1868 kfree(nce);
1874 } 1869 }
@@ -2188,9 +2183,6 @@ static int send_subvol_begin(struct send_ctx *sctx)
2188 read_extent_buffer(leaf, name, (unsigned long)(ref + 1), namelen); 2183 read_extent_buffer(leaf, name, (unsigned long)(ref + 1), namelen);
2189 btrfs_release_path(path); 2184 btrfs_release_path(path);
2190 2185
2191 if (ret < 0)
2192 goto out;
2193
2194 if (parent_root) { 2186 if (parent_root) {
2195 ret = begin_cmd(sctx, BTRFS_SEND_C_SNAPSHOT); 2187 ret = begin_cmd(sctx, BTRFS_SEND_C_SNAPSHOT);
2196 if (ret < 0) 2188 if (ret < 0)
@@ -2393,19 +2385,19 @@ verbose_printk("btrfs: send_create_inode %llu\n", ino);
2393 if (ret < 0) 2385 if (ret < 0)
2394 goto out; 2386 goto out;
2395 2387
2396 if (S_ISREG(mode)) 2388 if (S_ISREG(mode)) {
2397 cmd = BTRFS_SEND_C_MKFILE; 2389 cmd = BTRFS_SEND_C_MKFILE;
2398 else if (S_ISDIR(mode)) 2390 } else if (S_ISDIR(mode)) {
2399 cmd = BTRFS_SEND_C_MKDIR; 2391 cmd = BTRFS_SEND_C_MKDIR;
2400 else if (S_ISLNK(mode)) 2392 } else if (S_ISLNK(mode)) {
2401 cmd = BTRFS_SEND_C_SYMLINK; 2393 cmd = BTRFS_SEND_C_SYMLINK;
2402 else if (S_ISCHR(mode) || S_ISBLK(mode)) 2394 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
2403 cmd = BTRFS_SEND_C_MKNOD; 2395 cmd = BTRFS_SEND_C_MKNOD;
2404 else if (S_ISFIFO(mode)) 2396 } else if (S_ISFIFO(mode)) {
2405 cmd = BTRFS_SEND_C_MKFIFO; 2397 cmd = BTRFS_SEND_C_MKFIFO;
2406 else if (S_ISSOCK(mode)) 2398 } else if (S_ISSOCK(mode)) {
2407 cmd = BTRFS_SEND_C_MKSOCK; 2399 cmd = BTRFS_SEND_C_MKSOCK;
2408 else { 2400 } else {
2409 printk(KERN_WARNING "btrfs: unexpected inode type %o", 2401 printk(KERN_WARNING "btrfs: unexpected inode type %o",
2410 (int)(mode & S_IFMT)); 2402 (int)(mode & S_IFMT));
2411 ret = -ENOTSUPP; 2403 ret = -ENOTSUPP;
@@ -2583,13 +2575,13 @@ static int record_ref(struct list_head *head, u64 dir,
2583static void __free_recorded_refs(struct send_ctx *sctx, struct list_head *head) 2575static void __free_recorded_refs(struct send_ctx *sctx, struct list_head *head)
2584{ 2576{
2585 struct recorded_ref *cur; 2577 struct recorded_ref *cur;
2586 struct recorded_ref *tmp;
2587 2578
2588 list_for_each_entry_safe(cur, tmp, head, list) { 2579 while (!list_empty(head)) {
2580 cur = list_entry(head->next, struct recorded_ref, list);
2589 fs_path_free(sctx, cur->full_path); 2581 fs_path_free(sctx, cur->full_path);
2582 list_del(&cur->list);
2590 kfree(cur); 2583 kfree(cur);
2591 } 2584 }
2592 INIT_LIST_HEAD(head);
2593} 2585}
2594 2586
2595static void free_recorded_refs(struct send_ctx *sctx) 2587static void free_recorded_refs(struct send_ctx *sctx)
@@ -3205,24 +3197,18 @@ static int process_all_refs(struct send_ctx *sctx,
3205 key.offset = 0; 3197 key.offset = 0;
3206 while (1) { 3198 while (1) {
3207 ret = btrfs_search_slot_for_read(root, &key, path, 1, 0); 3199 ret = btrfs_search_slot_for_read(root, &key, path, 1, 0);
3208 if (ret < 0) { 3200 if (ret < 0)
3209 btrfs_release_path(path);
3210 goto out; 3201 goto out;
3211 } 3202 if (ret)
3212 if (ret) {
3213 btrfs_release_path(path);
3214 break; 3203 break;
3215 }
3216 3204
3217 eb = path->nodes[0]; 3205 eb = path->nodes[0];
3218 slot = path->slots[0]; 3206 slot = path->slots[0];
3219 btrfs_item_key_to_cpu(eb, &found_key, slot); 3207 btrfs_item_key_to_cpu(eb, &found_key, slot);
3220 3208
3221 if (found_key.objectid != key.objectid || 3209 if (found_key.objectid != key.objectid ||
3222 found_key.type != key.type) { 3210 found_key.type != key.type)
3223 btrfs_release_path(path);
3224 break; 3211 break;
3225 }
3226 3212
3227 ret = iterate_inode_ref(sctx, sctx->parent_root, path, 3213 ret = iterate_inode_ref(sctx, sctx->parent_root, path,
3228 &found_key, 0, cb, sctx); 3214 &found_key, 0, cb, sctx);
@@ -3232,6 +3218,7 @@ static int process_all_refs(struct send_ctx *sctx,
3232 3218
3233 key.offset = found_key.offset + 1; 3219 key.offset = found_key.offset + 1;
3234 } 3220 }
3221 btrfs_release_path(path);
3235 3222
3236 ret = process_recorded_refs(sctx); 3223 ret = process_recorded_refs(sctx);
3237 3224
@@ -3554,7 +3541,7 @@ static int send_write(struct send_ctx *sctx, u64 offset, u32 len)
3554 int ret = 0; 3541 int ret = 0;
3555 struct fs_path *p; 3542 struct fs_path *p;
3556 loff_t pos = offset; 3543 loff_t pos = offset;
3557 int readed = 0; 3544 int num_read = 0;
3558 mm_segment_t old_fs; 3545 mm_segment_t old_fs;
3559 3546
3560 p = fs_path_alloc(sctx); 3547 p = fs_path_alloc(sctx);
@@ -3579,8 +3566,8 @@ verbose_printk("btrfs: send_write offset=%llu, len=%d\n", offset, len);
3579 ret = vfs_read(sctx->cur_inode_filp, sctx->read_buf, len, &pos); 3566 ret = vfs_read(sctx->cur_inode_filp, sctx->read_buf, len, &pos);
3580 if (ret < 0) 3567 if (ret < 0)
3581 goto out; 3568 goto out;
3582 readed = ret; 3569 num_read = ret;
3583 if (!readed) 3570 if (!num_read)
3584 goto out; 3571 goto out;
3585 3572
3586 ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE); 3573 ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE);
@@ -3593,7 +3580,7 @@ verbose_printk("btrfs: send_write offset=%llu, len=%d\n", offset, len);
3593 3580
3594 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); 3581 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p);
3595 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); 3582 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset);
3596 TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, readed); 3583 TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, num_read);
3597 3584
3598 ret = send_cmd(sctx); 3585 ret = send_cmd(sctx);
3599 3586
@@ -3603,7 +3590,7 @@ out:
3603 set_fs(old_fs); 3590 set_fs(old_fs);
3604 if (ret < 0) 3591 if (ret < 0)
3605 return ret; 3592 return ret;
3606 return readed; 3593 return num_read;
3607} 3594}
3608 3595
3609/* 3596/*
@@ -3614,7 +3601,6 @@ static int send_clone(struct send_ctx *sctx,
3614 struct clone_root *clone_root) 3601 struct clone_root *clone_root)
3615{ 3602{
3616 int ret = 0; 3603 int ret = 0;
3617 struct btrfs_root *clone_root2 = clone_root->root;
3618 struct fs_path *p; 3604 struct fs_path *p;
3619 u64 gen; 3605 u64 gen;
3620 3606
@@ -3639,22 +3625,23 @@ verbose_printk("btrfs: send_clone offset=%llu, len=%d, clone_root=%llu, "
3639 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_LEN, len); 3625 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_LEN, len);
3640 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); 3626 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p);
3641 3627
3642 if (clone_root2 == sctx->send_root) { 3628 if (clone_root->root == sctx->send_root) {
3643 ret = get_inode_info(sctx->send_root, clone_root->ino, NULL, 3629 ret = get_inode_info(sctx->send_root, clone_root->ino, NULL,
3644 &gen, NULL, NULL, NULL, NULL); 3630 &gen, NULL, NULL, NULL, NULL);
3645 if (ret < 0) 3631 if (ret < 0)
3646 goto out; 3632 goto out;
3647 ret = get_cur_path(sctx, clone_root->ino, gen, p); 3633 ret = get_cur_path(sctx, clone_root->ino, gen, p);
3648 } else { 3634 } else {
3649 ret = get_inode_path(sctx, clone_root2, clone_root->ino, p); 3635 ret = get_inode_path(sctx, clone_root->root,
3636 clone_root->ino, p);
3650 } 3637 }
3651 if (ret < 0) 3638 if (ret < 0)
3652 goto out; 3639 goto out;
3653 3640
3654 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID, 3641 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID,
3655 clone_root2->root_item.uuid); 3642 clone_root->root->root_item.uuid);
3656 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_CTRANSID, 3643 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_CTRANSID,
3657 clone_root2->root_item.ctransid); 3644 clone_root->root->root_item.ctransid);
3658 TLV_PUT_PATH(sctx, BTRFS_SEND_A_CLONE_PATH, p); 3645 TLV_PUT_PATH(sctx, BTRFS_SEND_A_CLONE_PATH, p);
3659 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_OFFSET, 3646 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_OFFSET,
3660 clone_root->offset); 3647 clone_root->offset);