• Home
  • Raw
  • Download

Lines Matching refs:device

46 				struct btrfs_device *device);
77 struct btrfs_device *device; in free_fs_devices() local
80 device = list_entry(fs_devices->devices.next, in free_fs_devices()
82 list_del(&device->dev_list); in free_fs_devices()
83 kfree(device->name); in free_fs_devices()
84 kfree(device); in free_fs_devices()
138 static noinline int run_scheduled_bios(struct btrfs_device *device) in run_scheduled_bios() argument
149 bdi = device->bdev->bd_inode->i_mapping->backing_dev_info; in run_scheduled_bios()
150 fs_info = device->dev_root->fs_info; in run_scheduled_bios()
155 spin_lock(&device->io_lock); in run_scheduled_bios()
163 pending = device->pending_bios; in run_scheduled_bios()
164 tail = device->pending_bio_tail; in run_scheduled_bios()
166 device->pending_bios = NULL; in run_scheduled_bios()
167 device->pending_bio_tail = NULL; in run_scheduled_bios()
179 device->running_pending = 1; in run_scheduled_bios()
182 device->running_pending = 0; in run_scheduled_bios()
184 spin_unlock(&device->io_lock); in run_scheduled_bios()
211 spin_lock(&device->io_lock); in run_scheduled_bios()
213 old_head = device->pending_bios; in run_scheduled_bios()
214 device->pending_bios = pending; in run_scheduled_bios()
215 if (device->pending_bio_tail) in run_scheduled_bios()
218 device->pending_bio_tail = tail; in run_scheduled_bios()
220 device->running_pending = 1; in run_scheduled_bios()
222 spin_unlock(&device->io_lock); in run_scheduled_bios()
223 btrfs_requeue_work(&device->work); in run_scheduled_bios()
230 spin_lock(&device->io_lock); in run_scheduled_bios()
231 if (device->pending_bios) in run_scheduled_bios()
233 spin_unlock(&device->io_lock); in run_scheduled_bios()
240 struct btrfs_device *device; in pending_bios_fn() local
242 device = container_of(work, struct btrfs_device, work); in pending_bios_fn()
243 run_scheduled_bios(device); in pending_bios_fn()
250 struct btrfs_device *device; in device_list_add() local
265 device = NULL; in device_list_add()
267 device = __find_device(&fs_devices->devices, devid, in device_list_add()
270 if (!device) { in device_list_add()
274 device = kzalloc(sizeof(*device), GFP_NOFS); in device_list_add()
275 if (!device) { in device_list_add()
279 device->devid = devid; in device_list_add()
280 device->work.func = pending_bios_fn; in device_list_add()
281 memcpy(device->uuid, disk_super->dev_item.uuid, in device_list_add()
283 device->barriers = 1; in device_list_add()
284 spin_lock_init(&device->io_lock); in device_list_add()
285 device->name = kstrdup(path, GFP_NOFS); in device_list_add()
286 if (!device->name) { in device_list_add()
287 kfree(device); in device_list_add()
290 INIT_LIST_HEAD(&device->dev_alloc_list); in device_list_add()
291 list_add(&device->dev_list, &fs_devices->devices); in device_list_add()
292 device->fs_devices = fs_devices; in device_list_add()
307 struct btrfs_device *device; in clone_fs_devices() local
322 device = kzalloc(sizeof(*device), GFP_NOFS); in clone_fs_devices()
323 if (!device) in clone_fs_devices()
326 device->name = kstrdup(orig_dev->name, GFP_NOFS); in clone_fs_devices()
327 if (!device->name) in clone_fs_devices()
330 device->devid = orig_dev->devid; in clone_fs_devices()
331 device->work.func = pending_bios_fn; in clone_fs_devices()
332 memcpy(device->uuid, orig_dev->uuid, sizeof(device->uuid)); in clone_fs_devices()
333 device->barriers = 1; in clone_fs_devices()
334 spin_lock_init(&device->io_lock); in clone_fs_devices()
335 INIT_LIST_HEAD(&device->dev_list); in clone_fs_devices()
336 INIT_LIST_HEAD(&device->dev_alloc_list); in clone_fs_devices()
338 list_add(&device->dev_list, &fs_devices->devices); in clone_fs_devices()
339 device->fs_devices = fs_devices; in clone_fs_devices()
350 struct btrfs_device *device, *next; in btrfs_close_extra_devices() local
354 list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) { in btrfs_close_extra_devices()
355 if (device->in_fs_metadata) in btrfs_close_extra_devices()
358 if (device->bdev) { in btrfs_close_extra_devices()
359 close_bdev_exclusive(device->bdev, device->mode); in btrfs_close_extra_devices()
360 device->bdev = NULL; in btrfs_close_extra_devices()
363 if (device->writeable) { in btrfs_close_extra_devices()
364 list_del_init(&device->dev_alloc_list); in btrfs_close_extra_devices()
365 device->writeable = 0; in btrfs_close_extra_devices()
368 list_del_init(&device->dev_list); in btrfs_close_extra_devices()
370 kfree(device->name); in btrfs_close_extra_devices()
371 kfree(device); in btrfs_close_extra_devices()
385 struct btrfs_device *device; in __btrfs_close_devices() local
390 list_for_each_entry(device, &fs_devices->devices, dev_list) { in __btrfs_close_devices()
391 if (device->bdev) { in __btrfs_close_devices()
392 close_bdev_exclusive(device->bdev, device->mode); in __btrfs_close_devices()
395 if (device->writeable) { in __btrfs_close_devices()
396 list_del_init(&device->dev_alloc_list); in __btrfs_close_devices()
400 device->bdev = NULL; in __btrfs_close_devices()
401 device->writeable = 0; in __btrfs_close_devices()
402 device->in_fs_metadata = 0; in __btrfs_close_devices()
439 struct btrfs_device *device; in __btrfs_open_devices() local
449 list_for_each_entry(device, head, dev_list) { in __btrfs_open_devices()
450 if (device->bdev) in __btrfs_open_devices()
452 if (!device->name) in __btrfs_open_devices()
455 bdev = open_bdev_exclusive(device->name, flags, holder); in __btrfs_open_devices()
457 printk(KERN_INFO "open %s failed\n", device->name); in __btrfs_open_devices()
468 if (devid != device->devid) in __btrfs_open_devices()
471 if (memcmp(device->uuid, disk_super->dev_item.uuid, in __btrfs_open_devices()
475 device->generation = btrfs_super_generation(disk_super); in __btrfs_open_devices()
476 if (!latest_transid || device->generation > latest_transid) { in __btrfs_open_devices()
478 latest_transid = device->generation; in __btrfs_open_devices()
483 device->writeable = 0; in __btrfs_open_devices()
485 device->writeable = !bdev_read_only(bdev); in __btrfs_open_devices()
489 device->bdev = bdev; in __btrfs_open_devices()
490 device->in_fs_metadata = 0; in __btrfs_open_devices()
491 device->mode = flags; in __btrfs_open_devices()
494 if (device->writeable) { in __btrfs_open_devices()
496 list_add(&device->dev_alloc_list, in __btrfs_open_devices()
594 struct btrfs_device *device, in find_free_dev_extent() argument
598 struct btrfs_root *root = device->dev_root; in find_free_dev_extent()
604 u64 search_end = device->total_bytes; in find_free_dev_extent()
623 if (root->fs_info->alloc_start + num_bytes <= device->total_bytes) in find_free_dev_extent()
626 key.objectid = device->devid; in find_free_dev_extent()
666 if (key.objectid < device->devid) in find_free_dev_extent()
669 if (key.objectid > device->devid) in find_free_dev_extent()
712 struct btrfs_device *device, in btrfs_free_dev_extent() argument
717 struct btrfs_root *root = device->dev_root; in btrfs_free_dev_extent()
727 key.objectid = device->devid; in btrfs_free_dev_extent()
750 if (device->bytes_used > 0) in btrfs_free_dev_extent()
751 device->bytes_used -= btrfs_dev_extent_length(leaf, extent); in btrfs_free_dev_extent()
760 struct btrfs_device *device, in btrfs_alloc_dev_extent() argument
766 struct btrfs_root *root = device->dev_root; in btrfs_alloc_dev_extent()
771 WARN_ON(!device->in_fs_metadata); in btrfs_alloc_dev_extent()
776 key.objectid = device->devid; in btrfs_alloc_dev_extent()
887 struct btrfs_device *device) in btrfs_add_device() argument
904 key.offset = device->devid; in btrfs_add_device()
914 btrfs_set_device_id(leaf, dev_item, device->devid); in btrfs_add_device()
916 btrfs_set_device_type(leaf, dev_item, device->type); in btrfs_add_device()
917 btrfs_set_device_io_align(leaf, dev_item, device->io_align); in btrfs_add_device()
918 btrfs_set_device_io_width(leaf, dev_item, device->io_width); in btrfs_add_device()
919 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); in btrfs_add_device()
920 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes); in btrfs_add_device()
921 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); in btrfs_add_device()
928 write_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE); in btrfs_add_device()
940 struct btrfs_device *device) in btrfs_rm_dev_item() argument
956 key.offset = device->devid; in btrfs_rm_dev_item()
980 struct btrfs_device *device; in btrfs_rm_device() local
1018 device = NULL; in btrfs_rm_device()
1022 device = tmp; in btrfs_rm_device()
1029 if (!device) { in btrfs_rm_device()
1051 device = btrfs_find_device(root, devid, dev_uuid, in btrfs_rm_device()
1053 if (!device) { in btrfs_rm_device()
1059 if (device->writeable && root->fs_info->fs_devices->rw_devices == 1) { in btrfs_rm_device()
1066 if (device->writeable) { in btrfs_rm_device()
1067 list_del_init(&device->dev_alloc_list); in btrfs_rm_device()
1071 ret = btrfs_shrink_device(device, 0); in btrfs_rm_device()
1075 ret = btrfs_rm_dev_item(root->fs_info->chunk_root, device); in btrfs_rm_device()
1079 device->in_fs_metadata = 0; in btrfs_rm_device()
1080 list_del_init(&device->dev_list); in btrfs_rm_device()
1081 device->fs_devices->num_devices--; in btrfs_rm_device()
1085 if (device->bdev == root->fs_info->sb->s_bdev) in btrfs_rm_device()
1087 if (device->bdev == root->fs_info->fs_devices->latest_bdev) in btrfs_rm_device()
1090 if (device->bdev) { in btrfs_rm_device()
1091 close_bdev_exclusive(device->bdev, device->mode); in btrfs_rm_device()
1092 device->bdev = NULL; in btrfs_rm_device()
1093 device->fs_devices->open_devices--; in btrfs_rm_device()
1099 if (device->fs_devices->open_devices == 0) { in btrfs_rm_device()
1103 if (fs_devices->seed == device->fs_devices) in btrfs_rm_device()
1107 fs_devices->seed = device->fs_devices->seed; in btrfs_rm_device()
1108 device->fs_devices->seed = NULL; in btrfs_rm_device()
1109 __btrfs_close_devices(device->fs_devices); in btrfs_rm_device()
1110 free_fs_devices(device->fs_devices); in btrfs_rm_device()
1117 if (device->writeable) { in btrfs_rm_device()
1126 kfree(device->name); in btrfs_rm_device()
1127 kfree(device); in btrfs_rm_device()
1151 struct btrfs_device *device; in btrfs_prepare_sprout() local
1176 list_for_each_entry(device, &seed_devices->devices, dev_list) { in btrfs_prepare_sprout()
1177 device->fs_devices = seed_devices; in btrfs_prepare_sprout()
1204 struct btrfs_device *device; in btrfs_finish_sprout() local
1253 device = btrfs_find_device(root, devid, dev_uuid, fs_uuid); in btrfs_finish_sprout()
1254 BUG_ON(!device); in btrfs_finish_sprout()
1256 if (device->fs_devices->seeding) { in btrfs_finish_sprout()
1258 device->generation); in btrfs_finish_sprout()
1274 struct btrfs_device *device; in btrfs_init_new_device() local
1299 list_for_each_entry(device, devices, dev_list) { in btrfs_init_new_device()
1300 if (device->bdev == bdev) { in btrfs_init_new_device()
1306 device = kzalloc(sizeof(*device), GFP_NOFS); in btrfs_init_new_device()
1307 if (!device) { in btrfs_init_new_device()
1313 device->name = kstrdup(device_path, GFP_NOFS); in btrfs_init_new_device()
1314 if (!device->name) { in btrfs_init_new_device()
1315 kfree(device); in btrfs_init_new_device()
1320 ret = find_next_devid(root, &device->devid); in btrfs_init_new_device()
1322 kfree(device); in btrfs_init_new_device()
1329 device->barriers = 1; in btrfs_init_new_device()
1330 device->writeable = 1; in btrfs_init_new_device()
1331 device->work.func = pending_bios_fn; in btrfs_init_new_device()
1332 generate_random_uuid(device->uuid); in btrfs_init_new_device()
1333 spin_lock_init(&device->io_lock); in btrfs_init_new_device()
1334 device->generation = trans->transid; in btrfs_init_new_device()
1335 device->io_width = root->sectorsize; in btrfs_init_new_device()
1336 device->io_align = root->sectorsize; in btrfs_init_new_device()
1337 device->sector_size = root->sectorsize; in btrfs_init_new_device()
1338 device->total_bytes = i_size_read(bdev->bd_inode); in btrfs_init_new_device()
1339 device->dev_root = root->fs_info->dev_root; in btrfs_init_new_device()
1340 device->bdev = bdev; in btrfs_init_new_device()
1341 device->in_fs_metadata = 1; in btrfs_init_new_device()
1342 device->mode = 0; in btrfs_init_new_device()
1343 set_blocksize(device->bdev, 4096); in btrfs_init_new_device()
1351 device->fs_devices = root->fs_info->fs_devices; in btrfs_init_new_device()
1352 list_add(&device->dev_list, &root->fs_info->fs_devices->devices); in btrfs_init_new_device()
1353 list_add(&device->dev_alloc_list, in btrfs_init_new_device()
1358 root->fs_info->fs_devices->total_rw_bytes += device->total_bytes; in btrfs_init_new_device()
1362 total_bytes + device->total_bytes); in btrfs_init_new_device()
1369 ret = init_first_rw_device(trans, root, device); in btrfs_init_new_device()
1374 ret = btrfs_add_device(trans, root, device); in btrfs_init_new_device()
1406 struct btrfs_device *device) in btrfs_update_device() argument
1415 root = device->dev_root->fs_info->chunk_root; in btrfs_update_device()
1423 key.offset = device->devid; in btrfs_update_device()
1437 btrfs_set_device_id(leaf, dev_item, device->devid); in btrfs_update_device()
1438 btrfs_set_device_type(leaf, dev_item, device->type); in btrfs_update_device()
1439 btrfs_set_device_io_align(leaf, dev_item, device->io_align); in btrfs_update_device()
1440 btrfs_set_device_io_width(leaf, dev_item, device->io_width); in btrfs_update_device()
1441 btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); in btrfs_update_device()
1442 btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes); in btrfs_update_device()
1443 btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); in btrfs_update_device()
1452 struct btrfs_device *device, u64 new_size) in __btrfs_grow_device() argument
1455 &device->dev_root->fs_info->super_copy; in __btrfs_grow_device()
1457 u64 diff = new_size - device->total_bytes; in __btrfs_grow_device()
1459 if (!device->writeable) in __btrfs_grow_device()
1461 if (new_size <= device->total_bytes) in __btrfs_grow_device()
1465 device->fs_devices->total_rw_bytes += diff; in __btrfs_grow_device()
1467 device->total_bytes = new_size; in __btrfs_grow_device()
1468 btrfs_clear_space_info_full(device->dev_root->fs_info); in __btrfs_grow_device()
1470 return btrfs_update_device(trans, device); in __btrfs_grow_device()
1474 struct btrfs_device *device, u64 new_size) in btrfs_grow_device() argument
1477 lock_chunks(device->dev_root); in btrfs_grow_device()
1478 ret = __btrfs_grow_device(trans, device, new_size); in btrfs_grow_device()
1479 unlock_chunks(device->dev_root); in btrfs_grow_device()
1707 struct btrfs_device *device; in btrfs_balance() local
1724 list_for_each_entry(device, devices, dev_list) { in btrfs_balance()
1725 old_size = device->total_bytes; in btrfs_balance()
1728 if (!device->writeable || in btrfs_balance()
1729 device->total_bytes - device->bytes_used > size_to_free) in btrfs_balance()
1732 ret = btrfs_shrink_device(device, old_size - size_to_free); in btrfs_balance()
1738 ret = btrfs_grow_device(trans, device, old_size); in btrfs_balance()
1801 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) in btrfs_shrink_device() argument
1804 struct btrfs_root *root = device->dev_root; in btrfs_shrink_device()
1817 u64 diff = device->total_bytes - new_size; in btrfs_shrink_device()
1819 if (new_size >= device->total_bytes) in btrfs_shrink_device()
1836 device->total_bytes = new_size; in btrfs_shrink_device()
1837 if (device->writeable) in btrfs_shrink_device()
1838 device->fs_devices->total_rw_bytes -= diff; in btrfs_shrink_device()
1839 ret = btrfs_update_device(trans, device); in btrfs_shrink_device()
1850 key.objectid = device->devid; in btrfs_shrink_device()
1871 if (key.objectid != device->devid) in btrfs_shrink_device()
1938 struct btrfs_device *device = NULL; in __btrfs_alloc_chunk() local
2046 device = list_entry(cur, struct btrfs_device, dev_alloc_list); in __btrfs_alloc_chunk()
2047 BUG_ON(!device->writeable); in __btrfs_alloc_chunk()
2048 if (device->total_bytes > device->bytes_used) in __btrfs_alloc_chunk()
2049 avail = device->total_bytes - device->bytes_used; in __btrfs_alloc_chunk()
2054 if (device->in_fs_metadata && avail >= min_free) { in __btrfs_alloc_chunk()
2055 ret = find_free_dev_extent(trans, device, in __btrfs_alloc_chunk()
2058 list_move_tail(&device->dev_alloc_list, in __btrfs_alloc_chunk()
2060 map->stripes[index].dev = device; in __btrfs_alloc_chunk()
2064 map->stripes[index].dev = device; in __btrfs_alloc_chunk()
2070 } else if (device->in_fs_metadata && avail > max_avail) in __btrfs_alloc_chunk()
2132 device = map->stripes[index].dev; in __btrfs_alloc_chunk()
2135 ret = btrfs_alloc_dev_extent(trans, device, in __btrfs_alloc_chunk()
2154 struct btrfs_device *device; in __finish_chunk_alloc() local
2167 device = map->stripes[index].dev; in __finish_chunk_alloc()
2168 device->bytes_used += stripe_size; in __finish_chunk_alloc()
2169 ret = btrfs_update_device(trans, device); in __finish_chunk_alloc()
2177 device = map->stripes[index].dev; in __finish_chunk_alloc()
2180 btrfs_set_stack_stripe_devid(stripe, device->devid); in __finish_chunk_alloc()
2182 memcpy(stripe->dev_uuid, device->uuid, BTRFS_UUID_SIZE); in __finish_chunk_alloc()
2248 struct btrfs_device *device) in init_first_rw_device() argument
2288 ret = btrfs_add_device(trans, fs_info->chunk_root, device); in init_first_rw_device()
2540 struct btrfs_device *device; in __btrfs_map_block() local
2543 device = map->stripes[stripe_index].dev; in __btrfs_map_block()
2544 if (device->bdev) { in __btrfs_map_block()
2545 bdi = blk_get_backing_dev_info(device->bdev); in __btrfs_map_block()
2722 struct btrfs_device *device, in schedule_bio() argument
2746 spin_lock(&device->io_lock); in schedule_bio()
2748 if (device->pending_bio_tail) in schedule_bio()
2749 device->pending_bio_tail->bi_next = bio; in schedule_bio()
2751 device->pending_bio_tail = bio; in schedule_bio()
2752 if (!device->pending_bios) in schedule_bio()
2753 device->pending_bios = bio; in schedule_bio()
2754 if (device->running_pending) in schedule_bio()
2757 spin_unlock(&device->io_lock); in schedule_bio()
2761 &device->work); in schedule_bio()
2835 struct btrfs_device *device; in btrfs_find_device() local
2842 device = __find_device(&cur_devices->devices, in btrfs_find_device()
2844 if (device) in btrfs_find_device()
2845 return device; in btrfs_find_device()
2855 struct btrfs_device *device; in add_missing_dev() local
2858 device = kzalloc(sizeof(*device), GFP_NOFS); in add_missing_dev()
2859 if (!device) in add_missing_dev()
2861 list_add(&device->dev_list, in add_missing_dev()
2863 device->barriers = 1; in add_missing_dev()
2864 device->dev_root = root->fs_info->dev_root; in add_missing_dev()
2865 device->devid = devid; in add_missing_dev()
2866 device->work.func = pending_bios_fn; in add_missing_dev()
2867 device->fs_devices = fs_devices; in add_missing_dev()
2869 spin_lock_init(&device->io_lock); in add_missing_dev()
2870 INIT_LIST_HEAD(&device->dev_alloc_list); in add_missing_dev()
2871 memcpy(device->uuid, dev_uuid, BTRFS_UUID_SIZE); in add_missing_dev()
2872 return device; in add_missing_dev()
2965 struct btrfs_device *device) in fill_device_from_item() argument
2969 device->devid = btrfs_device_id(leaf, dev_item); in fill_device_from_item()
2970 device->total_bytes = btrfs_device_total_bytes(leaf, dev_item); in fill_device_from_item()
2971 device->bytes_used = btrfs_device_bytes_used(leaf, dev_item); in fill_device_from_item()
2972 device->type = btrfs_device_type(leaf, dev_item); in fill_device_from_item()
2973 device->io_align = btrfs_device_io_align(leaf, dev_item); in fill_device_from_item()
2974 device->io_width = btrfs_device_io_width(leaf, dev_item); in fill_device_from_item()
2975 device->sector_size = btrfs_device_sector_size(leaf, dev_item); in fill_device_from_item()
2978 read_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE); in fill_device_from_item()
3034 struct btrfs_device *device; in read_one_dev() local
3054 device = btrfs_find_device(root, devid, dev_uuid, fs_uuid); in read_one_dev()
3055 if (!device || !device->bdev) { in read_one_dev()
3059 if (!device) { in read_one_dev()
3062 device = add_missing_dev(root, devid, dev_uuid); in read_one_dev()
3063 if (!device) in read_one_dev()
3068 if (device->fs_devices != root->fs_info->fs_devices) { in read_one_dev()
3069 BUG_ON(device->writeable); in read_one_dev()
3070 if (device->generation != in read_one_dev()
3075 fill_device_from_item(leaf, dev_item, device); in read_one_dev()
3076 device->dev_root = root->fs_info->dev_root; in read_one_dev()
3077 device->in_fs_metadata = 1; in read_one_dev()
3078 if (device->writeable) in read_one_dev()
3079 device->fs_devices->total_rw_bytes += device->total_bytes; in read_one_dev()