aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2012-06-21 16:03:58 -0400
committerChris Mason <chris.mason@fusionio.com>2012-07-23 16:27:42 -0400
commit02db0844beffc1c4e99d750be58ffb3ed95d6d62 (patch)
treeee82fa926f2900e24a1ca76eab6a85a32f453898
parent96c3f4331a8c1cd0a58307e4ac7e73e09d7dab23 (diff)
Btrfs: add DEVICE_READY ioctl
This will be used in conjunction with btrfs device ready <dev>. This is needed for initrd's to have a nice and lightweight way to tell if all of the devices needed for a file system are in the cache currently. This keeps them from having to do mount+sleep loops waiting for devices to show up. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
-rw-r--r--fs/btrfs/ioctl.h3
-rw-r--r--fs/btrfs/super.c7
-rw-r--r--fs/btrfs/volumes.c9
-rw-r--r--fs/btrfs/volumes.h1
4 files changed, 18 insertions, 2 deletions
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 021c55ed8aed..4e3e5d342a2b 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -363,7 +363,8 @@ struct btrfs_ioctl_get_dev_stats {
363 struct btrfs_ioctl_ino_path_args) 363 struct btrfs_ioctl_ino_path_args)
364#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ 364#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
365 struct btrfs_ioctl_ino_path_args) 365 struct btrfs_ioctl_ino_path_args)
366#define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
367 struct btrfs_ioctl_vol_args)
366#define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \ 368#define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
367 struct btrfs_ioctl_get_dev_stats) 369 struct btrfs_ioctl_get_dev_stats)
368
369#endif 370#endif
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 88a2d2bb2d75..26da344231ac 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1462,6 +1462,13 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
1462 ret = btrfs_scan_one_device(vol->name, FMODE_READ, 1462 ret = btrfs_scan_one_device(vol->name, FMODE_READ,
1463 &btrfs_fs_type, &fs_devices); 1463 &btrfs_fs_type, &fs_devices);
1464 break; 1464 break;
1465 case BTRFS_IOC_DEVICES_READY:
1466 ret = btrfs_scan_one_device(vol->name, FMODE_READ,
1467 &btrfs_fs_type, &fs_devices);
1468 if (ret)
1469 break;
1470 ret = !(fs_devices->num_devices == fs_devices->total_devices);
1471 break;
1465 } 1472 }
1466 1473
1467 kfree(vol); 1474 kfree(vol);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 957bf393ab46..39a0d04759f8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -429,6 +429,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
429 mutex_init(&fs_devices->device_list_mutex); 429 mutex_init(&fs_devices->device_list_mutex);
430 fs_devices->latest_devid = orig->latest_devid; 430 fs_devices->latest_devid = orig->latest_devid;
431 fs_devices->latest_trans = orig->latest_trans; 431 fs_devices->latest_trans = orig->latest_trans;
432 fs_devices->total_devices = orig->total_devices;
432 memcpy(fs_devices->fsid, orig->fsid, sizeof(fs_devices->fsid)); 433 memcpy(fs_devices->fsid, orig->fsid, sizeof(fs_devices->fsid));
433 434
434 /* We have held the volume lock, it is safe to get the devices. */ 435 /* We have held the volume lock, it is safe to get the devices. */
@@ -739,6 +740,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
739 int ret; 740 int ret;
740 u64 devid; 741 u64 devid;
741 u64 transid; 742 u64 transid;
743 u64 total_devices;
742 744
743 flags |= FMODE_EXCL; 745 flags |= FMODE_EXCL;
744 bdev = blkdev_get_by_path(path, flags, holder); 746 bdev = blkdev_get_by_path(path, flags, holder);
@@ -760,6 +762,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
760 disk_super = (struct btrfs_super_block *)bh->b_data; 762 disk_super = (struct btrfs_super_block *)bh->b_data;
761 devid = btrfs_stack_device_id(&disk_super->dev_item); 763 devid = btrfs_stack_device_id(&disk_super->dev_item);
762 transid = btrfs_super_generation(disk_super); 764 transid = btrfs_super_generation(disk_super);
765 total_devices = btrfs_super_num_devices(disk_super);
763 if (disk_super->label[0]) 766 if (disk_super->label[0])
764 printk(KERN_INFO "device label %s ", disk_super->label); 767 printk(KERN_INFO "device label %s ", disk_super->label);
765 else 768 else
@@ -767,7 +770,8 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
767 printk(KERN_CONT "devid %llu transid %llu %s\n", 770 printk(KERN_CONT "devid %llu transid %llu %s\n",
768 (unsigned long long)devid, (unsigned long long)transid, path); 771 (unsigned long long)devid, (unsigned long long)transid, path);
769 ret = device_list_add(path, disk_super, devid, fs_devices_ret); 772 ret = device_list_add(path, disk_super, devid, fs_devices_ret);
770 773 if (!ret && fs_devices_ret)
774 (*fs_devices_ret)->total_devices = total_devices;
771 brelse(bh); 775 brelse(bh);
772error_close: 776error_close:
773 mutex_unlock(&uuid_mutex); 777 mutex_unlock(&uuid_mutex);
@@ -1433,6 +1437,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1433 list_del_rcu(&device->dev_list); 1437 list_del_rcu(&device->dev_list);
1434 1438
1435 device->fs_devices->num_devices--; 1439 device->fs_devices->num_devices--;
1440 device->fs_devices->total_devices--;
1436 1441
1437 if (device->missing) 1442 if (device->missing)
1438 root->fs_info->fs_devices->missing_devices--; 1443 root->fs_info->fs_devices->missing_devices--;
@@ -1550,6 +1555,7 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
1550 fs_devices->seeding = 0; 1555 fs_devices->seeding = 0;
1551 fs_devices->num_devices = 0; 1556 fs_devices->num_devices = 0;
1552 fs_devices->open_devices = 0; 1557 fs_devices->open_devices = 0;
1558 fs_devices->total_devices = 0;
1553 fs_devices->seed = seed_devices; 1559 fs_devices->seed = seed_devices;
1554 1560
1555 generate_random_uuid(fs_devices->fsid); 1561 generate_random_uuid(fs_devices->fsid);
@@ -1749,6 +1755,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1749 root->fs_info->fs_devices->num_devices++; 1755 root->fs_info->fs_devices->num_devices++;
1750 root->fs_info->fs_devices->open_devices++; 1756 root->fs_info->fs_devices->open_devices++;
1751 root->fs_info->fs_devices->rw_devices++; 1757 root->fs_info->fs_devices->rw_devices++;
1758 root->fs_info->fs_devices->total_devices++;
1752 if (device->can_discard) 1759 if (device->can_discard)
1753 root->fs_info->fs_devices->num_can_discard++; 1760 root->fs_info->fs_devices->num_can_discard++;
1754 root->fs_info->fs_devices->total_rw_bytes += device->total_bytes; 1761 root->fs_info->fs_devices->total_rw_bytes += device->total_bytes;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index e404414a95a9..5479325987b3 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -126,6 +126,7 @@ struct btrfs_fs_devices {
126 u64 missing_devices; 126 u64 missing_devices;
127 u64 total_rw_bytes; 127 u64 total_rw_bytes;
128 u64 num_can_discard; 128 u64 num_can_discard;
129 u64 total_devices;
129 struct block_device *latest_bdev; 130 struct block_device *latest_bdev;
130 131
131 /* all of the devices in the FS, protected by a mutex 132 /* all of the devices in the FS, protected by a mutex