X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=volumes.c;h=2fde4762c93c5d2be6ae4e82bab1fe57d067b06b;hb=9896b43f70df300feb792487f92b1b1ed87a49ce;hp=2ae2d1bb9fc0b61c58cecdbf87103961c0f331c9;hpb=2030f497516e6e91f0884c12bbf0b91a6c6b83e4;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/volumes.c b/volumes.c index 2ae2d1b..2fde476 100644 --- a/volumes.c +++ b/volumes.c @@ -138,7 +138,21 @@ static int device_list_add(const char *path, list_add(&device->dev_list, &fs_devices->devices); device->fs_devices = fs_devices; } else if (!device->name || strcmp(device->name, path)) { - char *name = strdup(path); + char *name; + + /* + * The existing device has newer generation, so this one could + * be a stale one, don't add it. + */ + if (found_transid < device->generation) { + warning( + "adding device %s gen %llu but found an existing device %s gen %llu", + path, found_transid, device->name, + device->generation); + return -EEXIST; + } + + name = strdup(path); if (!name) return -ENOMEM; kfree(device->name); @@ -505,8 +519,9 @@ err: return ret; } -static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset) +static int find_next_chunk(struct btrfs_fs_info *fs_info, u64 *offset) { + struct btrfs_root *root = fs_info->chunk_root; struct btrfs_path *path; int ret; struct btrfs_key key; @@ -517,7 +532,7 @@ static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset) if (!path) return -ENOMEM; - key.objectid = objectid; + key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; key.offset = (u64)-1; key.type = BTRFS_CHUNK_ITEM_KEY; @@ -533,7 +548,7 @@ static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset) } else { btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); - if (found_key.objectid != objectid) + if (found_key.objectid != BTRFS_FIRST_CHUNK_TREE_OBJECTID) *offset = 0; else { chunk = btrfs_item_ptr(path->nodes[0], path->slots[0], @@ -995,8 +1010,7 @@ again: } return -ENOSPC; } - ret = find_next_chunk(chunk_root, BTRFS_FIRST_CHUNK_TREE_OBJECTID, - &offset); + ret = find_next_chunk(info, &offset); if (ret) return ret; key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; @@ -1129,9 +1143,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, } else { u64 tmp; - ret = find_next_chunk(chunk_root, - BTRFS_FIRST_CHUNK_TREE_OBJECTID, - &tmp); + ret = find_next_chunk(info, &tmp); key.offset = tmp; if (ret) return ret;