[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] linux-user: add name_to_handle_at/open_by_handl
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH] linux-user: add name_to_handle_at/open_by_handle_at |
Date: |
Tue, 1 Sep 2015 12:07:06 +0100 |
On 27 August 2015 at 23:27, Laurent Vivier <address@hidden> wrote:
> This patch allows to run example given by open_by_handle_at(2):
>
> The following shell session demonstrates the use of these two programs:
>
> $ echo 'Can you please think about it?' > cecilia.txt
> $ ./t_name_to_handle_at cecilia.txt > fh
> $ ./t_open_by_handle_at < fh
> open_by_handle_at: Operation not permitted
> $ sudo ./t_open_by_handle_at < fh # Need CAP_SYS_ADMIN
> Read 31 bytes
> $ rm cecilia.txt
>
> Now we delete and (quickly) re-create the file so that it has the same
> content and (by chance) the same inode.[...]
>
> $ stat --printf="%i\n" cecilia.txt # Display inode number
> 4072121
> $ rm cecilia.txt
> $ echo 'Can you please think about it?' > cecilia.txt
> $ stat --printf="%i\n" cecilia.txt # Check inode number
> 4072121
> $ sudo ./t_open_by_handle_at < fh
> open_by_handle_at: Stale NFS file handle
>
> See the man page for source code.
>
> Signed-off-by: Laurent Vivier <address@hidden>
> ---
> linux-user/syscall.c | 97
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 97 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index f62c698..725ed66 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5246,6 +5246,93 @@ static int do_futex(target_ulong uaddr, int op, int
> val, target_ulong timeout,
> return -TARGET_ENOSYS;
> }
> }
> +#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
> +static abi_long do_name_to_handle_at(abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4,
> + abi_long arg5)
Since this is in its own function you have the opportunity to
give the input parameters more meaningful names than arg1..arg5.
> +{
> + struct file_handle *target_fh;
> + struct file_handle *fh;
> + int mount_id = 0;
> + abi_long ret;
> + char *name;
> + unsigned int size;
> +
> + if (get_user_s32(size, arg3)) {
> + return -TARGET_EFAULT;
> + }
> +
> + name = lock_user_string(arg2);
> + if (!name) {
> + return -TARGET_EFAULT;
> + }
> +
> + target_fh = lock_user(VERIFY_WRITE, arg3,
> + sizeof(struct file_handle) + size, 0);
> + if (!target_fh) {
> + unlock_user(name, arg2, 0);
> + return -TARGET_EFAULT;
> + }
> +
> + fh = g_malloc0(sizeof(struct file_handle) + size);
> + fh->handle_bytes = size;
I was going to suggest just using target_fh, since we know
the host and guest have the same sized struct here. But I
guess they might have different alignment restrictions.
> +
> + ret = get_errno(name_to_handle_at(arg1, path(name), fh, &mount_id,
> arg5));
> + unlock_user(name, arg2, 0);
> +
> + /* man name_to_handle_at(2):
> + * Other than the use of the handle_bytes field, the caller should treat
> + * the file_handle structure as an opaque data type
> + */
> +
> + memcpy(target_fh, fh, fh->handle_bytes);
> + target_fh->handle_bytes = tswap32(fh->handle_bytes);
You need to swap the handle_type field too (to match the
swap you do in do_open_by_handle_at()).
(I think swapping in both places is better than doing so in
neither.)
Otherwise looks good.
thanks
-- PMM
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Qemu-devel] [PATCH] linux-user: add name_to_handle_at/open_by_handle_at,
Peter Maydell <=