Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128353
b: refs/heads/master
c: 70b2bef
h: refs/heads/master
i:
  128351: bc9fd9c
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed Apr 17, 2007
1 parent b5a0581 commit 74c7cee
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 169 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b18c6685810af8e6763760711aece31ccc7a8ea8
refs/heads/master: 70b2befd0c8a4064715d8b340270650cc9d15af8
9 changes: 4 additions & 5 deletions trunk/fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ static int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
return 1;
if (k1.objectid < k2->objectid)
return -1;
if (k1.offset > k2->offset)
return 1;
if (k1.offset < k2->offset)
return -1;
if (k1.flags > k2->flags)
return 1;
if (k1.flags < k2->flags)
return -1;
if (k1.offset > k2->offset)
return 1;
if (k1.offset < k2->offset)
return -1;
return 0;
}

Expand Down Expand Up @@ -1292,7 +1292,6 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans,
ioff + size_diff);
}
/* shift the data */
printk("truncate item, new_size %u old_size %u, diff %u, bufp %p, dst, %p, num %u, old_data_start %u, data_end %u\n", new_size, old_size, size_diff, leaf, btrfs_leaf_data(leaf) + data_end + size_diff, old_data_start-data_end, old_data_start, data_end);
btrfs_memmove(root, leaf, btrfs_leaf_data(leaf) +
data_end + size_diff, btrfs_leaf_data(leaf) +
data_end, old_data_start + new_size - data_end);
Expand Down
17 changes: 2 additions & 15 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ extern struct kmem_cache *btrfs_path_cachep;
*/
struct btrfs_disk_key {
__le64 objectid;
__le64 offset;
__le32 flags;
__le64 offset;
} __attribute__ ((__packed__));

struct btrfs_key {
u64 objectid;
u64 offset;
u32 flags;
u64 offset;
} __attribute__ ((__packed__));

/*
Expand Down Expand Up @@ -227,7 +227,6 @@ struct btrfs_file_extent_item {
} __attribute__ ((__packed__));

struct btrfs_csum_item {
__le64 extent_offset;
u8 csum[BTRFS_CSUM_SIZE];
} __attribute__ ((__packed__));

Expand Down Expand Up @@ -925,17 +924,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct
e->num_blocks = cpu_to_le64(val);
}

static inline u64 btrfs_csum_extent_offset(struct btrfs_csum_item *c)
{
return le64_to_cpu(c->extent_offset);
}

static inline void btrfs_set_csum_extent_offset(struct btrfs_csum_item *c,
u64 val)
{
c->extent_offset = cpu_to_le64(val);
}

static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
{
return le16_to_cpu(d->pathlen);
Expand Down Expand Up @@ -1091,7 +1079,6 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 offset,
u64 extent_offset,
char *data, size_t len);
int btrfs_csum_verify_file_block(struct btrfs_root *root,
u64 objectid, u64 offset,
Expand Down
28 changes: 19 additions & 9 deletions trunk/fs/btrfs/dir-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
key.objectid = dir;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
btrfs_set_key_overflow(&key, BTRFS_KEY_OVERFLOW_MAX - 1);
// btrfs_set_key_overflow(&key, BTRFS_KEY_OVERFLOW_MAX - 1);
ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret);
while(1) {
Expand Down Expand Up @@ -146,19 +146,29 @@ int btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
int cow = mod != 0;
struct btrfs_disk_key *found_key;
struct btrfs_leaf *leaf;
int overflow = 0;

key.objectid = dir;
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY);
btrfs_set_key_overflow(&key, BTRFS_KEY_OVERFLOW_MAX - 1);
key.offset = objectid;
ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
if (ret < 0)
return ret;
if (ret > 0) {
if (path->slots[0] == 0)
return 1;
path->slots[0]--;

while(1) {
btrfs_set_key_overflow(&key, overflow);
ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
if (ret < 0)
return ret;
if (ret > 0) {
if (overflow >= BTRFS_KEY_OVERFLOW_MAX)
return 1;
overflow++;
btrfs_set_key_overflow(&key, overflow);
btrfs_release_path(root, path);
continue;
} else {
/* found */
break;
}
}
leaf = btrfs_buffer_leaf(path->nodes[0]);
found_key = &leaf->items[path->slots[0]].key;
Expand Down
2 changes: 0 additions & 2 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ int btrfs_insert_dev_radix(struct btrfs_root *root,
u64 num_blocks)
{
struct dev_lookup *lookup;
char b[BDEVNAME_SIZE];
int ret;

lookup = kmalloc(sizeof(*lookup), GFP_NOFS);
Expand All @@ -34,7 +33,6 @@ int btrfs_insert_dev_radix(struct btrfs_root *root,
lookup->num_blocks = num_blocks;
lookup->bdev = bdev;
lookup->device_id = device_id;
printk("inserting %s into dev radix %Lu %Lu\n", bdevname(bdev, b), block_start, num_blocks);

ret = radix_tree_insert(&root->fs_info->dev_radix, block_start +
num_blocks - 1, lookup);
Expand Down
26 changes: 2 additions & 24 deletions trunk/fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,26 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
file_key.offset = offset;
file_key.flags = 0;
btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
printk("__lookup for %Lu\n", offset);
ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow);
if (ret < 0)
goto fail;
leaf = btrfs_buffer_leaf(path->nodes[0]);
if (ret > 0) {
ret = 1;
if (path->slots[0] == 0) {
printk("fail1\n");
if (path->slots[0] == 0)
goto fail;
}
path->slots[0]--;
btrfs_disk_key_to_cpu(&found_key,
&leaf->items[path->slots[0]].key);
if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY ||
found_key.objectid != objectid) {
printk("fail2 type %u %Lu %Lu\n", btrfs_key_type(&found_key), found_key.objectid, objectid);
goto fail;
}
csum_offset = (offset - found_key.offset) >>
root->fs_info->sb->s_blocksize_bits;
if (csum_offset >=
btrfs_item_size(leaf->items + path->slots[0]) /
sizeof(struct btrfs_csum_item)) {
printk("fail3, csum offset %lu size %u\n", csum_offset, btrfs_item_size(leaf->items + path->slots[0]) / sizeof(struct btrfs_csum_item));
goto fail;
}
}
Expand All @@ -109,26 +104,18 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_key file_key;
int ins_len = mod < 0 ? -1 : 0;
int cow = mod != 0;
struct btrfs_csum_item *csum_item;

csum_item = btrfs_lookup_csum(trans, root, path, objectid, offset, 0);
if (IS_ERR(csum_item))
return PTR_ERR(csum_item);
file_key.objectid = objectid;
file_key.offset = btrfs_csum_extent_offset(csum_item);
file_key.offset = offset;
file_key.flags = 0;
btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);
btrfs_release_path(root, path);
printk("lookup file extent searches for %Lu\n", file_key.offset);
ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow);
printk("ret is %d\n", ret);
return ret;
}

int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 offset,
u64 extent_offset,
char *data, size_t len)
{
int ret;
Expand All @@ -151,10 +138,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
file_key.offset = offset;
file_key.flags = 0;
btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
printk("searching for csum %Lu %Lu\n", objectid, offset);
ret = btrfs_search_slot(trans, root, &file_key, path,
sizeof(struct btrfs_csum_item), 1);
printk("ret %d\n", ret);
if (ret < 0)
goto fail;
if (ret == 0) {
Expand All @@ -167,29 +152,24 @@ printk("ret %d\n", ret);
path->slots[0]--;
leaf = btrfs_buffer_leaf(path->nodes[0]);
btrfs_disk_key_to_cpu(&found_key, &leaf->items[path->slots[0]].key);
printk("found key %Lu %Lu %u\n", found_key.objectid, found_key.offset, found_key.flags);
csum_offset = (offset - found_key.offset) >>
root->fs_info->sb->s_blocksize_bits;
printk("csum_offset %Lu\n", csum_offset);
if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY ||
found_key.objectid != objectid ||
csum_offset >= MAX_CSUM_ITEMS(root)) {
btrfs_release_path(root, path);
printk("insert1\n");
goto insert;
}
if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) /
sizeof(struct btrfs_csum_item)) {
ret = btrfs_extend_item(trans, root, path,
sizeof(struct btrfs_csum_item));
BUG_ON(ret);
printk("item extended\n");
goto csum;
}

insert:
csum_offset = 0;
printk("inserting item %Lu %Lu %u\n", file_key.objectid, file_key.offset, file_key.flags);
ret = btrfs_insert_empty_item(trans, root, path, &file_key,
sizeof(struct btrfs_csum_item));
if (ret != 0 && ret != -EEXIST)
Expand All @@ -201,12 +181,10 @@ printk("inserting item %Lu %Lu %u\n", file_key.objectid, file_key.offset, file_k
item += csum_offset;
found:
ret = btrfs_csum_data(root, data, len, item->csum);
btrfs_set_csum_extent_offset(item, extent_offset);
btrfs_mark_buffer_dirty(path->nodes[0]);
fail:
btrfs_release_path(root, path);
btrfs_free_path(path);
printk("return ret %d\n", ret);
return ret;
}

Expand Down
Loading

0 comments on commit 74c7cee

Please sign in to comment.