mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	btrfs: sipmlify uuid parameters of alloc_fs_devices()
Among all the callers, only the device_list_add() function uses the second argument of alloc_fs_devices(). It passes metadata_uuid when available, otherwise, it passes NULL. And in turn, alloc_fs_devices() is designed to copy either metadata_uuid or fsid into fs_devices::metadata_uuid. So remove the second argument in alloc_fs_devices(), and always copy the fsid. In the caller device_list_add() function, we will overwrite it with metadata_uuid when it is available. Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
		
							parent
							
								
									01fc062bd0
								
							
						
					
					
						commit
						f7361d8c3f
					
				
					 2 changed files with 18 additions and 17 deletions
				
			
		| 
						 | 
					@ -318,9 +318,10 @@ static bool check_tree_block_fsid(struct extent_buffer *eb)
 | 
				
			||||||
			   BTRFS_FSID_SIZE);
 | 
								   BTRFS_FSID_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * alloc_fs_devices() copies the fsid into metadata_uuid if the
 | 
						 * alloc_fsid_devices() copies the fsid into fs_devices::metadata_uuid.
 | 
				
			||||||
	 * metadata_uuid is unset in the superblock, including for a seed device.
 | 
						 * This is then overwritten by metadata_uuid if it is present in the
 | 
				
			||||||
	 * So, we can use fs_devices->metadata_uuid.
 | 
						 * device_list_add(). The same true for a seed device as well. So use of
 | 
				
			||||||
 | 
						 * fs_devices::metadata_uuid is appropriate here.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (memcmp(fsid, fs_info->fs_devices->metadata_uuid, BTRFS_FSID_SIZE) == 0)
 | 
						if (memcmp(fsid, fs_info->fs_devices->metadata_uuid, BTRFS_FSID_SIZE) == 0)
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -357,21 +357,19 @@ struct list_head * __attribute_const__ btrfs_get_fs_uuids(void)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * alloc_fs_devices - allocate struct btrfs_fs_devices
 | 
					 * Allocate new btrfs_fs_devices structure identified by a fsid.
 | 
				
			||||||
 * @fsid:		if not NULL, copy the UUID to fs_devices::fsid
 | 
					 *
 | 
				
			||||||
 * @metadata_fsid:	if not NULL, copy the UUID to fs_devices::metadata_fsid
 | 
					 * @fsid:    if not NULL, copy the UUID to fs_devices::fsid and to
 | 
				
			||||||
 | 
					 *           fs_devices::metadata_fsid
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Return a pointer to a new struct btrfs_fs_devices on success, or ERR_PTR().
 | 
					 * Return a pointer to a new struct btrfs_fs_devices on success, or ERR_PTR().
 | 
				
			||||||
 * The returned struct is not linked onto any lists and can be destroyed with
 | 
					 * The returned struct is not linked onto any lists and can be destroyed with
 | 
				
			||||||
 * kfree() right away.
 | 
					 * kfree() right away.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 | 
					static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid)
 | 
				
			||||||
						 const u8 *metadata_fsid)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct btrfs_fs_devices *fs_devs;
 | 
						struct btrfs_fs_devices *fs_devs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ASSERT(fsid || !metadata_fsid);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL);
 | 
						fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL);
 | 
				
			||||||
	if (!fs_devs)
 | 
						if (!fs_devs)
 | 
				
			||||||
		return ERR_PTR(-ENOMEM);
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
| 
						 | 
					@ -385,8 +383,7 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (fsid) {
 | 
						if (fsid) {
 | 
				
			||||||
		memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
 | 
							memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
 | 
				
			||||||
		memcpy(fs_devs->metadata_uuid,
 | 
							memcpy(fs_devs->metadata_uuid, fsid, BTRFS_FSID_SIZE);
 | 
				
			||||||
		       metadata_fsid ?: fsid, BTRFS_FSID_SIZE);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return fs_devs;
 | 
						return fs_devs;
 | 
				
			||||||
| 
						 | 
					@ -812,8 +809,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!fs_devices) {
 | 
						if (!fs_devices) {
 | 
				
			||||||
		fs_devices = alloc_fs_devices(disk_super->fsid,
 | 
							fs_devices = alloc_fs_devices(disk_super->fsid);
 | 
				
			||||||
				has_metadata_uuid ? disk_super->metadata_uuid : NULL);
 | 
							if (has_metadata_uuid)
 | 
				
			||||||
 | 
								memcpy(fs_devices->metadata_uuid,
 | 
				
			||||||
 | 
								       disk_super->metadata_uuid, BTRFS_FSID_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (IS_ERR(fs_devices))
 | 
							if (IS_ERR(fs_devices))
 | 
				
			||||||
			return ERR_CAST(fs_devices);
 | 
								return ERR_CAST(fs_devices);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -997,7 +997,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lockdep_assert_held(&uuid_mutex);
 | 
						lockdep_assert_held(&uuid_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fs_devices = alloc_fs_devices(orig->fsid, NULL);
 | 
						fs_devices = alloc_fs_devices(orig->fsid);
 | 
				
			||||||
	if (IS_ERR(fs_devices))
 | 
						if (IS_ERR(fs_devices))
 | 
				
			||||||
		return fs_devices;
 | 
							return fs_devices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2451,7 +2451,7 @@ static struct btrfs_fs_devices *btrfs_init_sprout(struct btrfs_fs_info *fs_info)
 | 
				
			||||||
	 * Private copy of the seed devices, anchored at
 | 
						 * Private copy of the seed devices, anchored at
 | 
				
			||||||
	 * fs_info->fs_devices->seed_list
 | 
						 * fs_info->fs_devices->seed_list
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	seed_devices = alloc_fs_devices(NULL, NULL);
 | 
						seed_devices = alloc_fs_devices(NULL);
 | 
				
			||||||
	if (IS_ERR(seed_devices))
 | 
						if (IS_ERR(seed_devices))
 | 
				
			||||||
		return seed_devices;
 | 
							return seed_devices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6901,7 +6901,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
 | 
				
			||||||
		if (!btrfs_test_opt(fs_info, DEGRADED))
 | 
							if (!btrfs_test_opt(fs_info, DEGRADED))
 | 
				
			||||||
			return ERR_PTR(-ENOENT);
 | 
								return ERR_PTR(-ENOENT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fs_devices = alloc_fs_devices(fsid, NULL);
 | 
							fs_devices = alloc_fs_devices(fsid);
 | 
				
			||||||
		if (IS_ERR(fs_devices))
 | 
							if (IS_ERR(fs_devices))
 | 
				
			||||||
			return fs_devices;
 | 
								return fs_devices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue