From patchwork Sun May 19 20:36:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164524 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4796479ili; Sun, 19 May 2019 14:05:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaZWEPI5AefcHJQnZEEqK5lyDBrG5z+4BtVOnj+24Pg6NdJ6UFwXje46aw/gyCYW9puzhl X-Received: by 2002:a50:8877:: with SMTP id c52mr71176770edc.253.1558299955203; Sun, 19 May 2019 14:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558299955; cv=none; d=google.com; s=arc-20160816; b=b0gAOV2Kwf8oBQDpB3LwR5F4VpEvJo/oFwFOZu0Nn+Q4GldIrB4ztMle8RqSZtdxgf LkPTNSwMJ9VFJegQi37sO7OxBYfbFBj9wc6kbXzUZvHkG6UlE/d8vFmhj7tHAvXmA0CL HbDN38oEELDQBB1SMcgw7MtEMyVJRjT4FLxgeT7CpNWD32tI5VFLoUivs/IqH/NqC/ob NjAzv5i1Cgz6MPq0Kt+QLNvVTEz9k22KS73RN01UuVX6Ar2mYZTJUzQ9e2EjH4WUdlKH UAx/jbDniKGJcCb4NA4VPFs3ibPrBAGfqGsonqQmca7L/FvqsnY/3hYb6mg+qB9XmwnR jFsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=MZ4xTXHoRnqxjbKzyUEkFjQQbSbYuTgwnyU38LEY1MU=; b=ltIeQ8p7mEDrWbO/ICwtEu6pT2nNWd5fAvHPko4cm998ozSi3E0TibLOzpFgmBIJ+4 N4OvraCW+1m7hKJ9Wj7Zjxg1L1QPY++DklvG7wTcdyE5Mz9dd6dlujAlwsaFBtEhGDXZ A2Q3J7PIGfuAuJqph7WfaUG13Jur4srV9aYfDtirI6akEd03N4Z8u4m6JLh2Qri66cSu Ew3LfIgMTYrkUmzCHeE1ShdtHZK5VLiv+eYu+ozz+inAOjj34g2tLMNcZvr2urtHx/D4 3/S1NN0fDQhsDTUkrNTU2hqku70wIEWra9lQZhXSknkvxQ6LXDWOiBuc4OBRNjrxEivw v46w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jzueuHJi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p38si3860185edc.348.2019.05.19.14.05.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 14:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jzueuHJi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hST0E-0001ep-2j for patch@linaro.org; Sun, 19 May 2019 17:05:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZf-0003fD-Is for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZd-0004Pw-IC for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:27 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:39847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZd-0004Kj-7H for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:25 -0400 Received: by mail-pl1-x642.google.com with SMTP id g9so5709210plm.6 for ; Sun, 19 May 2019 13:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MZ4xTXHoRnqxjbKzyUEkFjQQbSbYuTgwnyU38LEY1MU=; b=jzueuHJih53MA65QrNMqcmuShPK8bfIscnDjn98SrMNKFRBaG66E6Wv8nseh/UiCH0 Rc4r985n1zXgVQN7RER0C+GI6nU74Ol7UFOXvqkGkEHXx8aylIljtPGYt1ecc2HgAV6I XnBHTnln+h9kPUsQbPtwxI3KknAAIF141R0mizaBlCwRSqQOqTjn/TZlhspqEQ+G7qCP p1LfBJfNIf67dk0kNz84mwpWUSxW4+CEK/6BugaRzBxozECjHDN6jRs3o7NBm1LoHfCK EsZp6KkusZBriWnFYo5vV8HR+H5+AMkGDT1BRSsPzVAdcaUytGM+jKKpY1lCrw11Btbq bfdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MZ4xTXHoRnqxjbKzyUEkFjQQbSbYuTgwnyU38LEY1MU=; b=i6PYpOI5AFVYm5BT7yTmr6V92O3uLhVyw8ufyDK4RwJipEjEFtc20eOOkP62PIRXYL 3rjy7QHKfSNhxqkBkYbrZ093qixasP3vyID2cuEWvoPIOOyLpFOTf7vL3lELeCXYxo/f hbHQ+xW9xj9TQqeu57cCwtur7Ne+jh0+vATjL7/ihGlsZbXMsMW4M1UW1LIEtUgsGY/9 6zMV1bFtnnje02xKk5RqRXVeqnEDA/Hm/VMak7JlGTuAqVpizyPlmoZO1k0Xw9zyjvAB Hmgy+PchgkS5nS+5fTDK2wKH7naVgRQM6rr1BVxTIvqwhq8l6ShA3OwDqNA9IMbfVyY0 iWuA== X-Gm-Message-State: APjAAAUZ1w3vNB5y4vTWvzUbm7uM+gZLI2Vq/wJ+mT8cR37l3W9eTIBF S+jTqTHXNK4nrHn08VmWDQ8mTkE+deM= X-Received: by 2002:a17:902:201:: with SMTP id 1mr26872192plc.263.1558298300365; Sun, 19 May 2019 13:38:20 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.38.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:38:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:52 -0700 Message-Id: <20190519203726.20729-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v7 40/74] linux-user: Split out rename, renameat, renameat2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Note that renameat2 is universally available for guests. Merge sys_renameat2 into the new do_renameat2 helper. Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 8 +++++ linux-user/syscall.h | 1 + linux-user/strace.c | 39 ++++++--------------- linux-user/syscall-file.inc.c | 45 ++++++++++++++++++++++++ linux-user/syscall.c | 64 ----------------------------------- linux-user/strace.list | 9 ----- 6 files changed, 65 insertions(+), 101 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index c672b5ad99..0ed01aa100 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -142,6 +142,14 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC); #ifdef TARGET_NR_readlinkat SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC); #endif +#ifdef TARGET_NR_rename +SYSCALL_DEF(rename, ARG_STR, ARG_STR); +#endif +#ifdef TARGET_NR_renameat +SYSCALL_DEF(renameat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR); +#endif +SYSCALL_DEF(renameat2, ARG_ATDIRFD, ARG_STR, + ARG_ATDIRFD, ARG_STR, ARG_RENAMEFLAG); SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC); #ifdef TARGET_NR_rmdir SYSCALL_DEF(rmdir, ARG_STR); diff --git a/linux-user/syscall.h b/linux-user/syscall.h index 642fb6dccb..7b197840f5 100644 --- a/linux-user/syscall.h +++ b/linux-user/syscall.h @@ -69,6 +69,7 @@ typedef enum { ARG_MODEFLAG, ARG_MOUNTFLAG, ARG_OPENFLAG, + ARG_RENAMEFLAG, ARG_UMOUNTFLAG, ARG_UNLINKATFLAG, diff --git a/linux-user/strace.c b/linux-user/strace.c index 01a5c210fa..8f871b30ae 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "qemu.h" #include "syscall.h" @@ -741,6 +742,13 @@ static struct flags const mount_flags[] = { FLAG_END, }; +static struct flags const renameat2_flags[] = { + FLAG_GENERIC(RENAME_EXCHANGE), + FLAG_GENERIC(RENAME_NOREPLACE), + FLAG_GENERIC(RENAME_WHITEOUT), + FLAG_END, +}; + static struct flags const umount2_flags[] = { #ifdef MNT_FORCE FLAG_GENERIC(MNT_FORCE), @@ -1899,34 +1907,6 @@ print_fstatat64(const struct syscallname *name, #define print_newfstatat print_fstatat64 #endif -#ifdef TARGET_NR_rename -static void -print_rename(const struct syscallname *name, - abi_long arg0, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5) -{ - print_syscall_prologue(name); - print_string(arg0, 0); - print_string(arg1, 1); - print_syscall_epilogue(name); -} -#endif - -#ifdef TARGET_NR_renameat -static void -print_renameat(const struct syscallname *name, - abi_long arg0, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5) -{ - print_syscall_prologue(name); - print_at_dirfd(arg0, 0); - print_string(arg1, 0); - print_at_dirfd(arg2, 0); - print_string(arg3, 1); - print_syscall_epilogue(name); -} -#endif - #ifdef TARGET_NR_statfs static void print_statfs(const struct syscallname *name, @@ -2212,6 +2192,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6]) case ARG_OPENFLAG: len = add_open_flags(b, rest, arg); break; + case ARG_RENAMEFLAG: + len = add_flags(b, rest, renameat2_flags, arg, false); + break; case ARG_UMOUNTFLAG: len = add_flags(b, rest, umount2_flags, arg, false); break; diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index 9f3cf7221a..18553f055e 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -873,6 +873,51 @@ SYSCALL_IMPL(readlinkat) } #endif +static abi_long do_renameat2(int oldfd, abi_ulong target_oldpath, + int newfd, abi_ulong target_newpath, + unsigned int flags) +{ + char *p_old = lock_user_string(target_oldpath); + char *p_new = lock_user_string(target_newpath); + abi_long ret = -TARGET_EFAULT; + + if (p_old && p_new) { + if (flags == 0) { + ret = renameat(oldfd, p_old, newfd, p_new); + } else { +#ifdef __NR_renameat2 + ret = syscall(__NR_renameat2, oldfd, p_old, newfd, p_new, flags); +#else + errno = ENOSYS; + ret = -1; +#endif + } + ret = get_errno(ret); + } + unlock_user(p_old, target_oldpath, 0); + unlock_user(p_new, target_newpath, 0); + return ret; +} + +#ifdef TARGET_NR_rename +SYSCALL_IMPL(rename) +{ + return do_renameat2(AT_FDCWD, arg1, AT_FDCWD, arg2, 0); +} +#endif + +#ifdef TARGET_NR_renameat +SYSCALL_IMPL(renameat) +{ + return do_renameat2(arg1, arg2, arg3, arg4, 0); +} +#endif + +SYSCALL_IMPL(renameat2) +{ + return do_renameat2(arg1, arg2, arg3, arg4, arg5); +} + SYSCALL_IMPL(sync) { sync(); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3fe770890c..d8f6da63cc 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -331,24 +331,6 @@ static int sys_utimensat(int dirfd, const char *pathname, #endif #endif /* TARGET_NR_utimensat */ -#ifdef TARGET_NR_renameat2 -#if defined(__NR_renameat2) -#define __NR_sys_renameat2 __NR_renameat2 -_syscall5(int, sys_renameat2, int, oldfd, const char *, old, int, newfd, - const char *, new, unsigned int, flags) -#else -static int sys_renameat2(int oldfd, const char *old, - int newfd, const char *new, int flags) -{ - if (flags == 0) { - return renameat(oldfd, old, newfd, new); - } - errno = ENOSYS; - return -1; -} -#endif -#endif /* TARGET_NR_renameat2 */ - #ifdef CONFIG_INOTIFY #include @@ -5391,52 +5373,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_rename - case TARGET_NR_rename: - { - void *p2; - p = lock_user_string(arg1); - p2 = lock_user_string(arg2); - if (!p || !p2) - ret = -TARGET_EFAULT; - else - ret = get_errno(rename(p, p2)); - unlock_user(p2, arg2, 0); - unlock_user(p, arg1, 0); - } - return ret; -#endif -#if defined(TARGET_NR_renameat) - case TARGET_NR_renameat: - { - void *p2; - p = lock_user_string(arg2); - p2 = lock_user_string(arg4); - if (!p || !p2) - ret = -TARGET_EFAULT; - else - ret = get_errno(renameat(arg1, p, arg3, p2)); - unlock_user(p2, arg4, 0); - unlock_user(p, arg2, 0); - } - return ret; -#endif -#if defined(TARGET_NR_renameat2) - case TARGET_NR_renameat2: - { - void *p2; - p = lock_user_string(arg2); - p2 = lock_user_string(arg4); - if (!p || !p2) { - ret = -TARGET_EFAULT; - } else { - ret = get_errno(sys_renameat2(arg1, p, arg3, p2, arg5)); - } - unlock_user(p2, arg4, 0); - unlock_user(p, arg2, 0); - } - return ret; -#endif #ifdef TARGET_NR_mkdir case TARGET_NR_mkdir: if (!(p = lock_user_string(arg1))) diff --git a/linux-user/strace.list b/linux-user/strace.list index 07e5f7c518..3b002a0500 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -944,15 +944,6 @@ #ifdef TARGET_NR_removexattr { TARGET_NR_removexattr, "removexattr" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_rename -{ TARGET_NR_rename, "rename" , NULL, print_rename, NULL }, -#endif -#ifdef TARGET_NR_renameat -{ TARGET_NR_renameat, "renameat" , NULL, print_renameat, NULL }, -#endif -#ifdef TARGET_NR_renameat2 -{ TARGET_NR_renameat2, "renameat2" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_request_key { TARGET_NR_request_key, "request_key" , NULL, NULL, NULL }, #endif