* [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at
@ 2015-09-01 20:27 Laurent Vivier
2015-09-04 13:45 ` Peter Maydell
2015-09-28 13:48 ` Riku Voipio
0 siblings, 2 replies; 4+ messages in thread
From: Laurent Vivier @ 2015-09-01 20:27 UTC (permalink / raw)
To: riku.voipio, qemu-devel, peter.maydell; +Cc: Laurent Vivier
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 <laurent@vivier.eu>
---
v2: Rename function parameters, swap fh->handle_type in both functions,
When I have re-tested the patch I have found a bug in the size of
the data, so I fix this too (handle_bytes is the size of f_handle[]
only, not of the whole structure)
linux-user/syscall.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f62c698..8a17351 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5246,6 +5246,94 @@ 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 dirfd, abi_long pathname,
+ abi_long handle, abi_long mount_id,
+ abi_long flags)
+{
+ struct file_handle *target_fh;
+ struct file_handle *fh;
+ int mid = 0;
+ abi_long ret;
+ char *name;
+ unsigned int size, total_size;
+
+ if (get_user_s32(size, handle)) {
+ return -TARGET_EFAULT;
+ }
+
+ name = lock_user_string(pathname);
+ if (!name) {
+ return -TARGET_EFAULT;
+ }
+
+ total_size = sizeof(struct file_handle) + size;
+ target_fh = lock_user(VERIFY_WRITE, handle, total_size, 0);
+ if (!target_fh) {
+ unlock_user(name, pathname, 0);
+ return -TARGET_EFAULT;
+ }
+
+ fh = g_malloc0(total_size);
+ fh->handle_bytes = size;
+
+ ret = get_errno(name_to_handle_at(dirfd, path(name), fh, &mid, flags));
+ unlock_user(name, pathname, 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, total_size);
+ target_fh->handle_bytes = tswap32(fh->handle_bytes);
+ target_fh->handle_type = tswap32(fh->handle_type);
+ g_free(fh);
+ unlock_user(target_fh, handle, total_size);
+
+ if (put_user_s32(mid, mount_id)) {
+ return -TARGET_EFAULT;
+ }
+
+ return ret;
+
+}
+#endif
+
+#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
+static abi_long do_open_by_handle_at(abi_long mount_fd, abi_long handle,
+ abi_long flags)
+{
+ struct file_handle *target_fh;
+ struct file_handle *fh;
+ unsigned int size, total_size;
+ abi_long ret;
+
+ if (get_user_s32(size, handle)) {
+ return -TARGET_EFAULT;
+ }
+
+ total_size = sizeof(struct file_handle) + size;
+ target_fh = lock_user(VERIFY_READ, handle, total_size, 1);
+ if (!target_fh) {
+ return -TARGET_EFAULT;
+ }
+
+ fh = g_malloc0(total_size);
+ memcpy(fh, target_fh, total_size);
+ fh->handle_bytes = size;
+ fh->handle_type = tswap32(target_fh->handle_type);
+
+ ret = get_errno(open_by_handle_at(mount_fd, fh,
+ target_to_host_bitmask(flags, fcntl_flags_tbl)));
+
+ g_free(fh);
+
+ unlock_user(target_fh, handle, total_size);
+
+ return ret;
+}
+#endif
/* Map host to target signal numbers for the wait family of syscalls.
Assume all other status bits are the same. */
@@ -5655,6 +5743,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
arg4));
unlock_user(p, arg2, 0);
break;
+#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
+ case TARGET_NR_name_to_handle_at:
+ ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
+ break;
+#endif
+#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
+ case TARGET_NR_open_by_handle_at:
+ ret = do_open_by_handle_at(arg1, arg2, arg3);
+ break;
+#endif
case TARGET_NR_close:
ret = get_errno(close(arg1));
break;
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at
2015-09-01 20:27 [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at Laurent Vivier
@ 2015-09-04 13:45 ` Peter Maydell
2015-09-04 16:14 ` Laurent Vivier
2015-09-28 13:48 ` Riku Voipio
1 sibling, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2015-09-04 13:45 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 1 September 2015 at 21:27, Laurent Vivier <laurent@vivier.eu> 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 <laurent@vivier.eu>
> ---
> v2: Rename function parameters, swap fh->handle_type in both functions,
> When I have re-tested the patch I have found a bug in the size of
> the data, so I fix this too (handle_bytes is the size of f_handle[]
> only, not of the whole structure)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
(I guess the signalfd patch needs to be rebased on top of this,
since this adds another syscall that returns an fd...)
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at
2015-09-04 13:45 ` Peter Maydell
@ 2015-09-04 16:14 ` Laurent Vivier
0 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2015-09-04 16:14 UTC (permalink / raw)
To: Peter Maydell; +Cc: Riku Voipio, QEMU Developers
Le 04/09/2015 15:45, Peter Maydell a écrit :
> On 1 September 2015 at 21:27, Laurent Vivier <laurent@vivier.eu> 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 <laurent@vivier.eu>
>> ---
>> v2: Rename function parameters, swap fh->handle_type in both functions,
>> When I have re-tested the patch I have found a bug in the size of
>> the data, so I fix this too (handle_bytes is the size of f_handle[]
>> only, not of the whole structure)
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> (I guess the signalfd patch needs to be rebased on top of this,
> since this adds another syscall that returns an fd...)
Yes.
Thank you for the reviews. I'll rework the signalfd one.
Laurent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at
2015-09-01 20:27 [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at Laurent Vivier
2015-09-04 13:45 ` Peter Maydell
@ 2015-09-28 13:48 ` Riku Voipio
1 sibling, 0 replies; 4+ messages in thread
From: Riku Voipio @ 2015-09-28 13:48 UTC (permalink / raw)
To: Laurent Vivier; +Cc: peter.maydell, qemu-devel
On Tue, Sep 01, 2015 at 10:27:33PM +0200, Laurent Vivier 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.
Applied to linux-user,
Thanks
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> v2: Rename function parameters, swap fh->handle_type in both functions,
> When I have re-tested the patch I have found a bug in the size of
> the data, so I fix this too (handle_bytes is the size of f_handle[]
> only, not of the whole structure)
>
> linux-user/syscall.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 98 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index f62c698..8a17351 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5246,6 +5246,94 @@ 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 dirfd, abi_long pathname,
> + abi_long handle, abi_long mount_id,
> + abi_long flags)
> +{
> + struct file_handle *target_fh;
> + struct file_handle *fh;
> + int mid = 0;
> + abi_long ret;
> + char *name;
> + unsigned int size, total_size;
> +
> + if (get_user_s32(size, handle)) {
> + return -TARGET_EFAULT;
> + }
> +
> + name = lock_user_string(pathname);
> + if (!name) {
> + return -TARGET_EFAULT;
> + }
> +
> + total_size = sizeof(struct file_handle) + size;
> + target_fh = lock_user(VERIFY_WRITE, handle, total_size, 0);
> + if (!target_fh) {
> + unlock_user(name, pathname, 0);
> + return -TARGET_EFAULT;
> + }
> +
> + fh = g_malloc0(total_size);
> + fh->handle_bytes = size;
> +
> + ret = get_errno(name_to_handle_at(dirfd, path(name), fh, &mid, flags));
> + unlock_user(name, pathname, 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, total_size);
> + target_fh->handle_bytes = tswap32(fh->handle_bytes);
> + target_fh->handle_type = tswap32(fh->handle_type);
> + g_free(fh);
> + unlock_user(target_fh, handle, total_size);
> +
> + if (put_user_s32(mid, mount_id)) {
> + return -TARGET_EFAULT;
> + }
> +
> + return ret;
> +
> +}
> +#endif
> +
> +#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
> +static abi_long do_open_by_handle_at(abi_long mount_fd, abi_long handle,
> + abi_long flags)
> +{
> + struct file_handle *target_fh;
> + struct file_handle *fh;
> + unsigned int size, total_size;
> + abi_long ret;
> +
> + if (get_user_s32(size, handle)) {
> + return -TARGET_EFAULT;
> + }
> +
> + total_size = sizeof(struct file_handle) + size;
> + target_fh = lock_user(VERIFY_READ, handle, total_size, 1);
> + if (!target_fh) {
> + return -TARGET_EFAULT;
> + }
> +
> + fh = g_malloc0(total_size);
> + memcpy(fh, target_fh, total_size);
> + fh->handle_bytes = size;
> + fh->handle_type = tswap32(target_fh->handle_type);
> +
> + ret = get_errno(open_by_handle_at(mount_fd, fh,
> + target_to_host_bitmask(flags, fcntl_flags_tbl)));
> +
> + g_free(fh);
> +
> + unlock_user(target_fh, handle, total_size);
> +
> + return ret;
> +}
> +#endif
>
> /* Map host to target signal numbers for the wait family of syscalls.
> Assume all other status bits are the same. */
> @@ -5655,6 +5743,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> arg4));
> unlock_user(p, arg2, 0);
> break;
> +#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
> + case TARGET_NR_name_to_handle_at:
> + ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
> + break;
> +#endif
> +#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
> + case TARGET_NR_open_by_handle_at:
> + ret = do_open_by_handle_at(arg1, arg2, arg3);
> + break;
> +#endif
> case TARGET_NR_close:
> ret = get_errno(close(arg1));
> break;
> --
> 2.4.3
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-28 13:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-01 20:27 [Qemu-devel] [PATCH v2] linux-user: add name_to_handle_at/open_by_handle_at Laurent Vivier
2015-09-04 13:45 ` Peter Maydell
2015-09-04 16:14 ` Laurent Vivier
2015-09-28 13:48 ` Riku Voipio
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.