From nobody Fri May 17 06:07:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=syrmia.com) ARC-Seal: i=2; a=rsa-sha256; t=1598212842; cv=pass; d=zohomail.com; s=zohoarc; b=f7flof5UJf5nxNgkBRZhBGIWhR0JUD339RnxjR11XksPXo0x8/EGtuB5haR3gwlFFNBckXHBkCu+Jm222PlAxZesLljiQ8LOX5Qt2TtT9yfLUWEkhd/MOJRlHH15lzAxrECg5NkiLoG5IkiBeTseUu7745L0VklbkO84vhxJRvc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598212842; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=TMFa0FiIBzRXQ4m0IiPCjLLT9ZoveybgJX5NxxhJMY0=; b=expKVPy5O6r56BQEyE8Op7abmxt4ADd26MNM5TbYcFeW4i9wwQE3+cFcOGxqV6wOU00mInCnLtZpEmOP3T0h4ssosv0vbg2d8v17Yl1n02vxD7YWhq3ccQJn408DlYitys7bKMWGvzuiRuM0G+8ABpFptTKBCDjyhU6yagjHlV0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=syrmia.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598212842021460.49268218555176; Sun, 23 Aug 2020 13:00:42 -0700 (PDT) Received: from localhost ([::1]:44150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9wAR-0004hx-ME for importer@patchew.org; Sun, 23 Aug 2020 16:00:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9w9d-0004AD-D3 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 15:59:49 -0400 Received: from mail-eopbgr80121.outbound.protection.outlook.com ([40.107.8.121]:30689 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9w9Z-0007BN-Sb for qemu-devel@nongnu.org; Sun, 23 Aug 2020 15:59:48 -0400 Received: from VE1PR03MB5246.eurprd03.prod.outlook.com (2603:10a6:802:a1::22) by VI1PR03MB6143.eurprd03.prod.outlook.com (2603:10a6:800:131::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Sun, 23 Aug 2020 19:59:38 +0000 Received: from VE1PR03MB5246.eurprd03.prod.outlook.com ([fe80::3568:5b4f:ab6b:e362]) by VE1PR03MB5246.eurprd03.prod.outlook.com ([fe80::3568:5b4f:ab6b:e362%6]) with mapi id 15.20.3261.026; Sun, 23 Aug 2020 19:59:38 +0000 Received: from localhost.localdomain (147.91.217.236) by AM3PR05CA0103.eurprd05.prod.outlook.com (2603:10a6:207:1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Sun, 23 Aug 2020 19:59:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k8H3XjPO3Z1Woc7TsbSSJYw5QeGBGDCU/trXJ/rgTaTaHsb4n3t7+hly5olo5ydC/NZIX1LKZ9wEuuMNz3v5F4bjOgYu8gDjoOALbMbiBT2ftUcajPTb0LZBwAKL3ifDPvkpUz8fqi8RRE9+xI6dGEpqGolb5kACHYMX8Nw+T1j65qvfeO32c8V5qmC54HrQY6POu3B8nCAhuySrebYySgNDxAeVj4LPSfDXD8GOzokJsRjyIYj4ywQOUfN6lwvqOqxvfShHWFJYKydTAZEE2ZyUrPxb47YHLWwj5vg3I9m4YORSI/pxItw0OHwKX7e9hWK7yUjRJ1AosWXyukROhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TMFa0FiIBzRXQ4m0IiPCjLLT9ZoveybgJX5NxxhJMY0=; b=SVsvmHHyCpD/yzd3eZ59CQ1eyvX+Cg6DAfR6CmgUgcg2aW+vRpPRfPFamULm7r+EMaL5LOjB8jV5Y1otGFhA8hu4L1CQB3hjdh+Gh4qxpncetoZcKHRV4FjRqHVqEAZevtYO6yP9sG4JLi4MI4Yy9H8CKSNxS1OtPTdWJgS/OOFCJtN7AAyn3ktflimQU5MRRBQQM8E1b3yj1BLEp3oj3Rli7H/WL2HB+OKb2Y1EAihuCX1BVNQtodSL/wUONWGBiqakkrW40cyVUN2Boh04/iUn+ZBdCXUApYPn1msY1pDmxD+86Nxf7arcF1rNQe0rF5wWxqnAIsM8Yq9Qc1mztA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TMFa0FiIBzRXQ4m0IiPCjLLT9ZoveybgJX5NxxhJMY0=; b=VOGCOobXcOvpR0pd3JL7GUpZ/SoQ01TXLlBGtJkONfkrJNrLAV2Fp7yH8F7Ms67/0MNlk3JaOEkQt6LgIX7vvlw3f/zYcHwk3pBADhn6Jyty0do0Q1jZzL0dZbWZeLF3vZcWkH+jr7MGoa6BBcTaRN2pCTmvJkyZ5gNy5HzobZo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=syrmia.com; From: Filip Bozuta To: qemu-devel@nongnu.org Subject: [PATCH] linux-user: Add support for a group of '_V2' btrfs ioctls Date: Sun, 23 Aug 2020 21:59:25 +0200 Message-Id: <20200823195925.117104-1-Filip.Bozuta@syrmia.com> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR05CA0103.eurprd05.prod.outlook.com (2603:10a6:207:1::29) To VE1PR03MB5246.eurprd03.prod.outlook.com (2603:10a6:802:a1::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [147.91.217.236] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9edb5f0a-8fbf-4cee-38a9-08d8479f10d3 X-MS-TrafficTypeDiagnostic: VI1PR03MB6143: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mm62ZV9COv88IcAegaRKLZMdeaGQ8cBWoq2QcTJiNYh9F1XT13NIDVk4SmFhrzsaPv4Qr+89ugMK45GrzlTYSx684QlRUBPapGxpCUBd/NbFFUTiZrjSzrYcAIOJ6++CQWSEIUI5QJDcEBHWGaZJr4NKZP6xNbKFZpaNXPx7x1V2nM0b+zUIeQiwc3gYrFyKhXckICixI8diBBHkBi5wLf8bbFD8NcUPSvnV94TEo3eLKGsdLCL5oUIMwheYIH8RMRt+ujPnYChu3p5uul/3Vx/eNOhA5RVDXp0gDPMSYGV+PdcaCe56PgBFYyy6Ayisx58mlLncomQYxCyfkvz+LOZNZJ2NpmmHai71r/05SRncT2Q/KRHU4g9cxXOByLQwN4VpiFzNzyGZgsK77AvT+/pL7Eb7J+Y+iEJKCe2hl+uZ6v+OGVuQEnRHJ8BaLQ1pPMuiQPWWSVoDQZyU3Gv2T3yR72R1AYsU4MoXWt54W0g= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR03MB5246.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(39830400003)(136003)(366004)(396003)(6916009)(30864003)(8676002)(8936002)(6486002)(4326008)(66556008)(2616005)(6666004)(66476007)(316002)(956004)(6512007)(66946007)(36756003)(5660300002)(186003)(26005)(52116002)(6506007)(478600001)(2906002)(86362001)(966005)(69590400007)(16526019)(1076003)(83380400001)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: bxv0GHK3hPAxoXfWXyeQTrQ0Ap1FWJS3CUDNlgZ0Pzl0Qae+pSmlQGHKqJRRyrXJjnLtJ1FeQN06FQaEIlz81bmocaQJy4w3HF5I96GoOTd9n40m5jJZy+czmx7UAkA0Dh5SBEUKVV7oz908cqhDZZMFNJrTWhe9kqMeOJLEmT1US1pxHgPradxF4YQlXZT1APONWfrNUuOepm6/pzZCeggb2HABc5wTl2cA7Ej0zwA1a05sJbIMknFFYaarjiZwb+O3tXgiujUX3jekEsMAGIQYYKiPpTE2TdWfFkq3G65rHE3R0XKdfneRKsrrZ9+zq9NKlcjaIgDO8wi2vwyOS9dnn+Y+doMB3xM0jsvELrnXeorOAK/81HrdaROfwqLfM8//405Px2hW+XWx+3iRuJqGS/NiQE1bU8W0TuyrdswlVb0sGYejoKbQ24/XG9BKgJbpI5bY1u/zr3O7WsV0Fb0xaAvboHdnKjnHdZuiaetE5pKJty83uzKrV+WXi2f7rKKToolzr0f9wPrJOWHoN/ZCQMKvh51ZidKvIl6baoe3w2KvW0ujYqbNy/qWpYgZt5CllyNbZl13nRoPFl1nhi436jdLEpf5MUzHiSqmow1n/dZ+kr2MsLeYTw3MWPtjk9VJzhNyhJJncEgVy/UpxQ== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9edb5f0a-8fbf-4cee-38a9-08d8479f10d3 X-MS-Exchange-CrossTenant-AuthSource: VE1PR03MB5246.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2020 19:59:38.3913 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GRFPgaUHwwF8vPyWGhcBhfSyt6Nkns0gno18zuix/aG7SrpqmuHOELDGuIpml+a7CDiYZCcROHtlY9xeXoDnRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB6143 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.8.121; envelope-from=Filip.Bozuta@syrmia.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 15:50:44 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @syrmia.com) Content-Type: text/plain; charset="utf-8" This patch introduces functionality for following btrfs ioctls: BTRFS_IOC_SUBVOL_CREATE_V2 - Adding a new btrfs subvolume Create a new btrfs subvolume (same as with BTRFS_IOC_SUBVOL_CREATE). The third ioctl's argument is a pointer to a following type: struct btrfs_ioctl_vol_args_v2 { __s64 fd; __u64 transid; __u64 flags; union { struct { __u64 size; struct btrfs_qgroup_inherit __user *qgroup_inherit; }; __u64 unused[4]; }; union { char name[BTRFS_SUBVOL_NAME_MAX + 1]; __u64 devid; __u64 subvolid; /* added in kernel version 5.8 */ }; }; When calling this ioctl, the 'name' field should be filled with the aproppriate value that contains the name of the subvolume that is to be created. The flags field can take values that are 'BTRFS_SUBVOL_RDONLY' or 'BTRFS_SUBVOL_QGROUP_INHERIT'. If the latter is specified, the field 'qgroup_inherit' should be filled with aproppriate values of the quota group in which the newly created subvolume is to be added. The definition of 'struct btrfs_qgroup_inherit' can be found at: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs= .h#L90 BTRFS_IOC_SNAP_CREATE_V2 - Adding a btrfs snapshot for a subvolume Create a new btrfs snapshot for a specified subvolume (same as with BTRFS_IOC_SNAP_CREATE). The ioctl's third argument is a pointer to the above mentioned 'struct btrfs_ioctl_vol_args_v2'. Before calling this ioctl, field 'fd' should be filled with the aproppriate file descriptor value for the btrfs subvolume for which the snapshot is to be created. Also, the 'name' field should be filled with the aproppriate value that represents the name of the snapshot that is to be created. The 'flags' field takes the same values as in case of 'BTRFS_IOC_SUBVOL_CREATE_V2' and represents the same functionality. BTRFS_IOC_RM_DEV_V2 - Removing a btrfs device Delete a btrfs device (same as with BTRFS_IOC_RM_DEV). The ioctl's third argument is a pointer to the above mentioned 'struct btrfs_ioctl_vol_ar= gs_v2'. Before calling this ioctl, either the 'name' or the 'devid' field should be filled with the name or id of the device that is to be removed. Also= , the flags field should be filled either with 0 or 'BTRFS_DEVICE_SPEC_BY_ID' depending on if the device is gonna be specified via name or id. BTRFS_IOC_SNAP_DESTROY_V2 - Removing a btrfs snapshot Remove a btrfs snapshot (same as with BTRFS_IOC_SNAP_DESTROY). The ioct= l's third argument is a pointer to the above mentioned 'struct btrfs_ioctl_= vol_args_v2'. Before calling this ioctl, either the 'name' or the 'subvolid' field sh= ould be filled with the name or id of the snapshot that is to be removed. Al= so, the flags field should be filled either with 0 or 'BTRFS_SUBVOL_SPEC_BY_ID' depending on if the snapshot is gonna be specified via name or id. Implementation notes: Since the third argument of the implemented ioctl's is a structure that contains unions, a special converting function 'target_to_host_btrfs_ioctl_vol_args_v2' was defined in 'syscall.c'. This function is called instead of 'thunk_convert()' to convert the values of the third argument from target to host. All of the ioctls in this patch are of type 'IOW' which is why a converting function from host to target is not required. Also, a separate printing function was defined in file 'strace.c' that is called instead of 'thunk_print()' to print the contents of the third argument. Signed-off-by: Filip Bozuta Based-on: <20200811164553.27713-2-Filip.Bozuta@syrmia.com> Based-on: <20200723210233.349690-4-Filip.Bozuta@syrmia.com> --- linux-user/ioctls.h | 16 +++++++ linux-user/qemu.h | 5 ++ linux-user/strace.c | 95 ++++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 77 ++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 28 +++++++++++ linux-user/syscall_types.h | 5 ++ thunk.c | 2 +- 7 files changed, 227 insertions(+), 1 deletion(-) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index e3bfe78774..a29ce6b69d 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -209,6 +209,14 @@ #ifdef BTRFS_IOC_DEFAULT_SUBVOL IOCTL(BTRFS_IOC_DEFAULT_SUBVOL, IOC_W, MK_PTR(TYPE_ULONGLONG)) #endif +#ifdef BTRFS_IOC_SNAP_CREATE_V2 + IOCTL(BTRFS_IOC_SNAP_CREATE_V2, IOC_W, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args_v2))) +#endif +#ifdef BTRFS_IOC_SUBVOL_CREATE_V2 + IOCTL(BTRFS_IOC_SUBVOL_CREATE_V2, IOC_W, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args_v2))) +#endif #ifdef BTRFS_IOC_SUBVOL_GETFLAGS IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG)) #endif @@ -281,6 +289,10 @@ IOCTL(BTRFS_IOC_GET_SUPPORTED_FEATURES, IOC_R, MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 3)= )) #endif +#ifdef BTRFS_IOC_RM_DEV_V2 + IOCTL(BTRFS_IOC_RM_DEV_V2, IOC_W, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args_v2))) +#endif #ifdef BTRFS_IOC_LOGICAL_INO_V2 IOCTL(BTRFS_IOC_LOGICAL_INO_V2, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_logical_ino_args))) @@ -297,6 +309,10 @@ IOCTL(BTRFS_IOC_INO_LOOKUP_USER, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_user_args))) #endif +#ifdef BTRFS_IOC_SNAP_DESTROY_V2 + IOCTL(BTRFS_IOC_SNAP_DESTROY_V2, IOC_W, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args_v2))) +#endif =20 #ifdef CONFIG_USBFS /* USB ioctls */ diff --git a/linux-user/qemu.h b/linux-user/qemu.h index a69a0bd347..4add164673 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -708,6 +708,11 @@ static inline uint64_t target_offset64(uint64_t word0,= uint64_t word1) =20 void print_termios(void *arg); =20 +#if defined(BTRFS_IOC_SUBVOL_CREATE_V2) || defined(BTRFS_IOC_SNAP_CREATE_V= 2) \ + || defined(BTRFS_IOC_SNAP_DESTROY_V2) || defined(BTRFS_IOC_RM_DEV_V2) +void print_btrfs_ioctl_vol_args_v2(void *arg); +#endif + /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers= */ #ifdef TARGET_ARM static inline int regpairs_aligned(void *cpu_env, int num) diff --git a/linux-user/strace.c b/linux-user/strace.c index b9ba39ce6e..04fe38a846 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -9,6 +9,9 @@ #include #include #include +#ifdef CONFIG_BTRFS +#include +#endif #include #include "qemu.h" =20 @@ -1434,6 +1437,22 @@ UNUSED static struct enums itimer_types[] =3D { ENUM_END, }; =20 +UNUSED static struct flags btrfs_args_vol_v2_flags[] =3D { +#ifdef BTRFS_SUBVOL_RDONLY + FLAG_GENERIC(BTRFS_SUBVOL_RDONLY), +#endif +#ifdef BTRFS_SUBVOL_QGROUP_INHERIT + FLAG_GENERIC(BTRFS_SUBVOL_QGROUP_INHERIT), +#endif +#ifdef BTRFS_DEVICE_SPEC_BY_ID + FLAG_GENERIC(BTRFS_DEVICE_SPEC_BY_ID), +#endif +#ifdef BTRFS_SUBVOL_SPEC_BY_ID + FLAG_GENERIC(BTRFS_SUBVOL_SPEC_BY_ID), +#endif + FLAG_END, +}; + /* * print_xxx utility functions. These are used to print syscall * parameters in certain format. All of these have parameter @@ -1774,6 +1793,82 @@ print_termios(void *arg) qemu_log("}"); } =20 +#if defined(BTRFS_IOC_SUBVOL_CREATE_V2) || defined(BTRFS_IOC_SNAP_CREATE_V= 2) \ + || defined(BTRFS_IOC_SNAP_DESTROY_V2) || defined(BTRFS_IOC_RM_DEV_V2) +void +print_btrfs_ioctl_vol_args_v2(void *arg) +{ + struct target_btrfs_ioctl_vol_args_v2 *target_args_v2 =3D arg; + uint64_t flags =3D tswap64(target_args_v2->flags); + int device_spec_by_id =3D 0; + int subvol_spec_by_id =3D 0; + + qemu_log("{fd =3D %" PRId64 ", flags =3D ", tswap64(target_args_v2->fd= )); + print_flags(btrfs_args_vol_v2_flags, flags, 0); + qemu_log(" transid =3D %" PRIu64 ",", tswap64(target_args_v2->transid)= ); + +#ifdef BTRFS_SUBVOL_QGROUP_INHERIT + if (flags & BTRFS_SUBVOL_QGROUP_INHERIT) { + + struct btrfs_qgroup_inherit *target_inherit; + abi_long inherit_addr =3D tswapal(target_args_v2->qgroup_inherit); + + target_inherit =3D lock_user(VERIFY_READ, inherit_addr, + sizeof(*target_inherit), 1); + + if (target_inherit) { + qemu_log(" size =3D %" PRIu64, + tswap64(target_args_v2->size)); + qemu_log(", qgroup_inherit =3D {"); + + qemu_log("flags =3D %" PRIu64, + tswap64(target_inherit->flags)); + qemu_log(", num_qgroups =3D %" PRIu64, + tswap64(target_inherit->num_qgroups)); + qemu_log(", num_ref_copies =3D %" PRIu64, + tswap64(target_inherit->num_ref_copies)); + qemu_log(", num_excl_copies =3D %" PRIu64, + tswap64(target_inherit->num_excl_copies)); + + qemu_log(", lim =3D {"); + qemu_log("lim.flags =3D %" PRIu64, + tswap64(target_inherit->lim.flags)); + qemu_log(", lim.max_rfer =3D %" PRIu64, + tswap64(target_inherit->lim.max_rfer)); + qemu_log(", lim.max_excl =3D %" PRIu64, + tswap64(target_inherit->lim.max_excl)); + qemu_log(", lim.rsv_rfer =3D %" PRIu64, + tswap64(target_inherit->lim.rsv_rfer)); + qemu_log(", lim.rsv_excl =3D %" PRIu64 "}", + tswap64(target_inherit->lim.rsv_excl)); + + qemu_log(", ...}, "); + } + + unlock_user(target_inherit, inherit_addr, 0); + } +#endif + +#ifdef BTRFS_DEVICE_SPEC_BY_ID + if (flags & BTRFS_DEVICE_SPEC_BY_ID) { + qemu_log(" devid =3D %" PRIu64, tswap64(target_args_v2->devid)); + device_spec_by_id =3D 1; + } +#endif +#ifdef BTRFS_SUBVOL_SPEC_BY_ID + if (flags & BTRFS_SUBVOL_SPEC_BY_ID) { + qemu_log(" subvolid =3D %" PRIu64, tswap64(target_args_v2->subvoli= d)); + subvol_spec_by_id =3D 1; + } +#endif + if (!device_spec_by_id && !subvol_spec_by_id) { + qemu_log(" name =3D \"%s\"", target_args_v2->name); + } + + qemu_log("}"); +} +#endif + #undef UNUSED =20 #ifdef TARGET_NR_accept diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b58098b5bb..78d7106b80 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5668,6 +5668,83 @@ static const StructEntry struct_termios_def =3D { .print =3D print_termios, }; =20 +#if defined(BTRFS_IOC_SUBVOL_CREATE_V2) || defined(BTRFS_IOC_SNAP_CREATE_V= 2) \ + || defined(BTRFS_SNAP_DESTROY_V2) || defined(BTRFS_RM_DEV_V2) +static void target_to_host_btrfs_ioctl_vol_args_v2(void *dst, const void *= src) +{ + struct btrfs_ioctl_vol_args_v2 *host_args_v2 =3D dst; + const struct target_btrfs_ioctl_vol_args_v2 *target_args_v2 =3D src; + int device_spec_by_id =3D 0; + int subvol_spec_by_id =3D 0; + + __get_user(host_args_v2->fd, &target_args_v2->fd); + __get_user(host_args_v2->flags, &target_args_v2->flags); + __get_user(host_args_v2->transid, &target_args_v2->transid); + + if (host_args_v2->flags & BTRFS_SUBVOL_QGROUP_INHERIT) { + struct btrfs_qgroup_inherit *target_inherit; + abi_long inherit_addr =3D tswapal(target_args_v2->qgroup_inherit); + + target_inherit =3D lock_user(VERIFY_READ, inherit_addr, + sizeof(*target_inherit), 1); + + host_args_v2->qgroup_inherit =3D g_new(struct btrfs_qgroup_inherit= , 1); + + if (!target_inherit) { + host_args_v2->qgroup_inherit =3D NULL; + } else { + __get_user(host_args_v2->qgroup_inherit->flags, + &target_inherit->flags); + __get_user(host_args_v2->qgroup_inherit->num_qgroups, + &target_inherit->num_qgroups); + __get_user(host_args_v2->qgroup_inherit->num_ref_copies, + &target_inherit->num_ref_copies); + __get_user(host_args_v2->qgroup_inherit->num_excl_copies, + &target_inherit->num_excl_copies); + __get_user(host_args_v2->qgroup_inherit->lim.flags, + &target_inherit->lim.flags); + __get_user(host_args_v2->qgroup_inherit->lim.max_rfer, + &target_inherit->lim.max_rfer); + __get_user(host_args_v2->qgroup_inherit->lim.max_excl, + &target_inherit->lim.max_excl); + __get_user(host_args_v2->qgroup_inherit->lim.rsv_rfer, + &target_inherit->lim.rsv_rfer); + __get_user(host_args_v2->qgroup_inherit->lim.rsv_excl, + &target_inherit->lim.rsv_excl); + } + + unlock_user(target_inherit, inherit_addr, 0); + } + +#ifdef BTRFS_DEVICE_SPEC_BY_ID + if (host_args_v2->flags & BTRFS_DEVICE_SPEC_BY_ID) { + __get_user(host_args_v2->devid, &target_args_v2->devid); + device_spec_by_id =3D 1; + } +#endif +#ifdef BTRFS_SUBVOL_SPEC_BY_ID + if (host_args_v2->flags & BTRFS_SUBVOL_SPEC_BY_ID) { + __get_user(host_args_v2->subvolid, &target_args_v2->subvolid); + subvol_spec_by_id =3D 1; + } +#endif + + if (!device_spec_by_id & !subvol_spec_by_id) { + memcpy(host_args_v2->name, target_args_v2->name, + BTRFS_SUBVOL_NAME_MAX + 1); + } +} + +static const StructEntry struct_btrfs_ioctl_vol_args_v2_def =3D { + .convert =3D { NULL, target_to_host_btrfs_ioctl_vol_args_v2}, + .print =3D print_btrfs_ioctl_vol_args_v2, + .align =3D { __alignof__(struct target_btrfs_ioctl_vol_args_v2), + __alignof__(struct btrfs_ioctl_vol_args_v2) }, + .size =3D { sizeof(struct target_btrfs_ioctl_vol_args_v2), + sizeof(struct btrfs_ioctl_vol_args_v2) }, +}; +#endif + static bitmask_transtbl mmap_flags_tbl[] =3D { { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 969377d622..d2d4d1e1cb 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -967,6 +967,26 @@ struct target_rtc_pll_info { #define TARGET_FS_IOC32_GETVERSION TARGET_IOR('v', 1, int) #define TARGET_FS_IOC32_SETVERSION TARGET_IOW('v', 2, int) =20 +#define TARGET_BTRFS_SUBVOL_NAME_MAX 4039 + +struct target_btrfs_ioctl_vol_args_v2 { + uint64_t fd; + uint64_t transid; + uint64_t flags; + union { + struct { + uint64_t size; + abi_long qgroup_inherit; + }; + uint64_t unused[4]; + }; + union { + char name[TARGET_BTRFS_SUBVOL_NAME_MAX + 1]; + uint64_t devid; + uint64_t subvolid; + }; +}; + /* btrfs ioctls */ #define TARGET_BTRFS_IOC_SNAP_CREATE TARGET_IOWU(BTRFS_IOCTL_MA= GIC, 1) #define TARGET_BTRFS_IOC_SCAN_DEV TARGET_IOWU(BTRFS_IOCTL_MA= GIC, 4) @@ -978,6 +998,10 @@ struct target_rtc_pll_info { #define TARGET_BTRFS_IOC_INO_LOOKUP TARGET_IOWRU(BTRFS_IOCTL_M= AGIC, 18) #define TARGET_BTRFS_IOC_DEFAULT_SUBVOL TARGET_IOW(BTRFS_IOCTL_MAG= IC, 19,\ abi_ullong) +#define TARGET_BTRFS_IOC_SNAP_CREATE_V2 TARGET_IOW(BTRFS_IOCTL_MAG= IC, 23,\ + struct target_btrfs_ioctl_vol_= args_v2) +#define TARGET_BTRFS_IOC_SUBVOL_CREATE_V2 TARGET_IOW(BTRFS_IOCTL_MAG= IC, 24,\ + struct target_btrfs_ioctl_vol_= args_v2) #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS TARGET_IOR(BTRFS_IOCTL_MAG= IC, 25,\ abi_ullong) #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS TARGET_IOW(BTRFS_IOCTL_MAG= IC, 26,\ @@ -999,10 +1023,14 @@ struct target_rtc_pll_info { #define TARGET_BTRFS_IOC_GET_FEATURES TARGET_IORU(BTRFS_IOCTL_MA= GIC, 57) #define TARGET_BTRFS_IOC_SET_FEATURES TARGET_IOWU(BTRFS_IOCTL_MA= GIC, 57) #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MA= GIC, 57) +#define TARGET_BTRFS_IOC_RM_DEV_V2 TARGET_IOW(BTRFS_IOCTL_MAG= IC, 58,\ + struct target_btrfs_ioctl_vol_= args_v2) #define TARGET_BTRFS_IOC_LOGICAL_INO_V2 TARGET_IOWRU(BTRFS_IOCTL_M= AGIC, 59) #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MA= GIC, 60) #define TARGET_BTRFS_IOC_GET_SUBVOL_ROOTREF TARGET_IOWRU(BTRFS_IOCTL_M= AGIC, 61) #define TARGET_BTRFS_IOC_INO_LOOKUP_USER TARGET_IOWRU(BTRFS_IOCTL_M= AGIC, 62) +#define TARGET_BTRFS_IOC_SNAP_DESTROY_V2 TARGET_IOW(BTRFS_IOCTL_MAG= IC, 63,\ + struct target_btrfs_ioctl_vol_= args_v2) =20 /* usb ioctls */ #define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0) diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 8d4b5b3e92..83aee1fcf9 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -358,6 +358,11 @@ STRUCT(btrfs_ioctl_vol_args, TYPE_LONGLONG, /* fd */ MK_ARRAY(TYPE_CHAR, BTRFS_PATH_NAME_MAX + 1)) /* name */ =20 +#if defined(BTRFS_IOC_SUBVOL_CREATE_V2) || defined(BTRFS_IOC_SNAP_CREATE_V= 2) \ + || defined(BTRFS_IOC_SNAP_DESTROY_V2) || defined(BTRFS_IOC_RM_DEV_V2) +STRUCT_SPECIAL(btrfs_ioctl_vol_args_v2) +#endif + STRUCT(btrfs_ioctl_timespec, TYPE_ULONGLONG, /* sec */ TYPE_INT) /* nsec */ diff --git a/thunk.c b/thunk.c index 0718325d86..0dfecb644b 100644 --- a/thunk.c +++ b/thunk.c @@ -246,7 +246,7 @@ const argtype *thunk_convert(void *dst, const void *src, =20 assert(*type_ptr < max_struct_entries); se =3D struct_entries + *type_ptr++; - if (se->convert[0] !=3D NULL) { + if (se->convert[to_host] !=3D NULL) { /* specific conversion is needed */ (*se->convert[to_host])(dst, src); } else { --=20 2.25.1