Re: [PATCH v1 2/2] xfs: add FS_IOC_GETFSUUID ioctl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Nov 10, 2022, at 12:05 PM, Darrick J. Wong <djwong@xxxxxxxxxx> wrote:
> 
> On Wed, Nov 09, 2022 at 02:19:59PM -0800, Catherine Hoang wrote:
>> Add a new ioctl to retrieve the UUID of a mounted xfs filesystem.
> 
> I think it's worth mentioning that this is the precursor to trying to
> implement SETFSUUID... but that's something for a future series, since
> changing the uuid will upset the log, and we have to figure out how to
> deal with that gracefully.
> 
>> Signed-off-by: Catherine Hoang <catherine.hoang@xxxxxxxxxx>
>> ---
>> fs/xfs/xfs_ioctl.c | 32 ++++++++++++++++++++++++++++++++
>> 1 file changed, 32 insertions(+)
>> 
>> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
>> index 1f783e979629..657fe058dfba 100644
>> --- a/fs/xfs/xfs_ioctl.c
>> +++ b/fs/xfs/xfs_ioctl.c
>> @@ -1865,6 +1865,35 @@ xfs_fs_eofblocks_from_user(
>> 	return 0;
>> }
>> 
>> +static int xfs_ioctl_getuuid(
> 
> Nit: function names should start on a new line.
> 
Ok, will fix that
>> +	struct xfs_mount	*mp,
>> +	struct fsuuid __user	*ufsuuid)
>> +{
>> +	struct fsuuid		fsuuid;
>> +	__u8			uuid[UUID_SIZE];
>> +
>> +	if (copy_from_user(&fsuuid, ufsuuid, sizeof(fsuuid)))
>> +		return -EFAULT;
>> +
>> +	if (fsuuid.fsu_len == 0) {
>> +		fsuuid.fsu_len = UUID_SIZE;
>> +		if (copy_to_user(ufsuuid, &fsuuid, sizeof(fsuuid.fsu_len)))
>> +			return -EFAULT;
>> +		return -EINVAL;
> 
> Ted and I were looking through the ext4_ioctl_getuuid function on this
> morning's ext4 concall, and we decided that copying the desired uuid
> buffer length out to userspace shouldn't result in an EINVAL return
> here...
> 
>> +	}
>> +
>> +	if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0)
> 
> ...and that we shouldn't reject the case where fsu_len > UUID_SIZE.
> Instead, we should copy the uuid and update the caller's fsu_len to
> reflect however many bytes we copied out.  I'll send patches to do that
> shortly.

Ok, that makes sense. I’ll apply those changes over to xfs. Thanks!
> 
>> +		return -EINVAL;
>> +
>> +	spin_lock(&mp->m_sb_lock);
>> +	memcpy(uuid, &mp->m_sb.sb_uuid, UUID_SIZE);
>> +	spin_unlock(&mp->m_sb_lock);
>> +
>> +	if (copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE))
>> +		return -EFAULT;
> 
> The rest of this logic looks correct to me.  Thanks for getting this out
> there.
> 
> --D
> 
>> +	return 0;
>> +}
>> +
>> /*
>>  * These long-unused ioctls were removed from the official ioctl API in 5.17,
>>  * but retain these definitions so that we can log warnings about them.
>> @@ -2153,6 +2182,9 @@ xfs_file_ioctl(
>> 		return error;
>> 	}
>> 
>> +	case FS_IOC_GETFSUUID:
>> +		return xfs_ioctl_getuuid(mp, arg);
>> +
>> 	default:
>> 		return -ENOTTY;
>> 	}
>> -- 
>> 2.25.1





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux