From patchwork Fri Oct 2 13:01:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 54441 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id B716623009 for ; Fri, 2 Oct 2015 13:54:04 +0000 (UTC) Received: by wicuu12 with SMTP id uu12sf8331728wic.2 for ; Fri, 02 Oct 2015 06:54:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=oFa0ALq0Z/TaIKz5jkX1kcLOIiKAg+DEQBy8/oNS0PY=; b=WR4+Ix2Vy/pvtby/MujWUxaZdio0+2kMlKl8HUGDA4wVo4Zi0W9MWoTttvbArtzwtW awhEyfq4VINgbM2iEGlHwvEGld8zi/IcqreD50QdATJaeQpZDBswxU/Q9ouuIQjP66Gr rN2AfGqLiyyKN0ZHqgJyTiY3jDcXx3eFhbI8z68Kaa656bB9sVr2/+5sszU4TJvjYkbv 7EvszQkNU7AdpOQ1nU2oE2pkiwsTQ+xOof8sAPBrl0UlIKvI/0lpSFxkLB12HfczFsCv 8xjRIngZv69dFd+l2xj9h6lRcDFw35Qo47PjwqjtRRbo7FgHDnaPH9fK1TJGwbIaQapW lqJA== X-Gm-Message-State: ALoCoQnhitQ1E5BdCeK821JSXsKj8VdEtZXYFkqe20zTv1+9DEC4ykBRP3/YNhEQvDNjvu1E8/39 X-Received: by 10.112.190.65 with SMTP id go1mr2678106lbc.9.1443794044006; Fri, 02 Oct 2015 06:54:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.152.7 with SMTP id a7ls226848lfe.100.gmail; Fri, 02 Oct 2015 06:54:03 -0700 (PDT) X-Received: by 10.25.169.68 with SMTP id s65mr3776142lfe.78.1443794043839; Fri, 02 Oct 2015 06:54:03 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id d2si6295934lbc.149.2015.10.02.06.54.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 06:54:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbcao8 with SMTP id ao8so26871426lbc.3 for ; Fri, 02 Oct 2015 06:54:03 -0700 (PDT) X-Received: by 10.25.150.199 with SMTP id y190mr3824963lfd.35.1443794043674; Fri, 02 Oct 2015 06:54:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1260063lbq; Fri, 2 Oct 2015 06:54:01 -0700 (PDT) X-Received: by 10.140.131.70 with SMTP id 67mr21698087qhd.70.1443794041523; Fri, 02 Oct 2015 06:54:01 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g74si3072047qhc.67.2015.10.02.06.54.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 Oct 2015 06:54:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:60051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi0mf-0008LA-4s for patch@linaro.org; Fri, 02 Oct 2015 09:54:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzxl-0005Rq-FC for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhzxh-0000fO-5D for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:25 -0400 Received: from mail-la0-f49.google.com ([209.85.215.49]:34235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzxg-0000es-RX for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:21 -0400 Received: by labzv5 with SMTP id zv5so92419277lab.1 for ; Fri, 02 Oct 2015 06:01:20 -0700 (PDT) X-Received: by 10.112.157.99 with SMTP id wl3mr5305754lbb.98.1443790880134; Fri, 02 Oct 2015 06:01:20 -0700 (PDT) Received: from localhost.localdomain (91-157-196-38.elisa-laajakaista.fi. [91.157.196.38]) by smtp.gmail.com with ESMTPSA id w143sm1514751lfd.2.2015.10.02.06.01.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Oct 2015 06:01:19 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 16:01:02 +0300 Message-Id: <0f0426f343886fb5c9f137c2830f35cc2dae7327.1443790691.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.49 Cc: Laurent Vivier Subject: [Qemu-devel] [PULL 10/13] linux-user: add name_to_handle_at/open_by_handle_at X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: 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. Reviewed-by: Peter Maydell Signed-off-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c25ffd8..9528344 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5251,6 +5251,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. */ @@ -5663,6 +5751,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;