Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp173354rdb; Thu, 30 Nov 2023 01:23:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEclJvCxpTcDPWmBb78IegZ7fQxCWT7i9WS+Rug3FQOWbTYCjhi6K5CAj9lJOEFZ33i/yDI X-Received: by 2002:a05:6808:191e:b0:3ae:a81:55a9 with SMTP id bf30-20020a056808191e00b003ae0a8155a9mr30786507oib.24.1701336219188; Thu, 30 Nov 2023 01:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701336219; cv=none; d=google.com; s=arc-20160816; b=JufoBk1z7HMqYzeJlvRPKZbM4/p6Iy5ivW2TtvEA92f2ZFV6IaKPAQcRgY2Xby7TGu 6H+x9CPRryZycJe5NTuaEhrqj2jfEFhZzReW1W9u3YHC/F3bkfvf2hIN54hBvnWZAbIe 4zQkc3gjoVzst4gbcwmFWQ+U1AWuDl+tY5AS8iwlXHhS4oWOnZlkNUJmp3KIriSVlSnX UABTR0Mf4cPThasps3zYRa65SckTx1aqZbNwLU6psmt8nM9iCxY2QuJHZGrKqrbM1eDA XkFT+BIErz32nm+/4HJ45WdEVG1eNm0ookmSO3UNRyU73r8Obh8awAhEoqVz70zfMeY4 Ytpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=Rlz4Una5lFEdcC2rxxNxFbJRLCbKuqXfn9V1CN1skN4=; fh=iehEewRXubtisj4ShmZfjRd9hhpUPlnu/+o8FDS+QQ8=; b=SkZ3dHhPkxgFXdWIseuKndKbDm6WnICCvBr/L69AgDD6CBzsYkczuB6I2ICfnrGrhu jhzOEMIo8t8ulZ8BuaHi3fyeTC8ZSdEse0ax2yj6EpDmJy2PLQRubaCbMjs4+ZElzJ73 lSN6SVNaAzWcvl9sR3lQnRVTuZ4qNWIllgNDXtjYmah+39e+ur90mZEKYwT2ykuNmyry x5E4T5VotU82Nkh0WNDTfY8Z7dSn8vJKz2QoSWNEECB9f0ridcwpyKRQJea0NTEQ2KuV aPfgWUUpaWGu+5UYn0mnHM0bTHMliP8+QBqXcm9W3nDtALvD/XvYdp6njrwSfJ7wFIzs 99bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IyX8nwYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 7-20020a630f47000000b005c2421cc394si899171pgp.532.2023.11.30.01.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 01:23:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IyX8nwYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BF9FF803A439; Thu, 30 Nov 2023 01:23:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235055AbjK3JXU (ORCPT + 99 others); Thu, 30 Nov 2023 04:23:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjK3JXU (ORCPT ); Thu, 30 Nov 2023 04:23:20 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B4158F for ; Thu, 30 Nov 2023 01:23:26 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5ca2e530041so12121457b3.3 for ; Thu, 30 Nov 2023 01:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701336205; x=1701941005; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=Rlz4Una5lFEdcC2rxxNxFbJRLCbKuqXfn9V1CN1skN4=; b=IyX8nwYATpgWd6Xf+K2Ych8TVib3UTc0bGcV+olAaK3B/RkH+s7eUv0fWpzZqRe55t oR0thQXPEVOVH9ohU7fZ9eEmPe+oujLZJTUM+U1wlFzJ74F7gvvDQQIQi79PpEdFR0Gj d+03DEqVex1LiYWS+kLcDS7DWWEMqWd631HliV4Bz58kQrEgD5MqobI9G+MP8EYm6fZr 0mfLpRyIl2xzO21PPBE2zq4NIc+5v7J1XUqn6LgVaDAx7p0QS9xVxxgVEs65vLX4R1fj 9g9hpngpdvcbG2XkTMEuZprJuTBAyCGNQG5Qy1auU/OBB1TEe/YauLDf/ZGVcik6qgze EH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701336205; x=1701941005; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Rlz4Una5lFEdcC2rxxNxFbJRLCbKuqXfn9V1CN1skN4=; b=oHIdp6ohnhEFKZhQGFzgMugdWmpooVNlFKA4g7H24waBPu2RYfDAahQvNGsdkKHqjr OTbtIcu0ywSi9sxczCt+PLhV3Kb/vimZ15tVbU995Bl98MhRwO9hYn1ppt7AXJZHo2Ym wHwbP7DU+N9uG+7YcphVmDCbf+Ogno/sNdMnMCnKyoBMRNqGvIzdKoqL4jEqqf0KIXQU 9ENqpu+3GDvZOIUJFTGQQtqbklFBKbfTkZWKmjyMqddmMD1IO/GjEp4ZRt9R8KEiIFyB yah8tzGXgqbGffYop8FSJrsvXIaA7nJ342erKW1utdihTg0S51qjg4xezXtZ/suDQLj9 Mcrw== X-Gm-Message-State: AOJu0Yya9RHGLZYfI3zsTRa3FGfhe6yVumFxsBhGIZeyfAdobeIrQ4m1 lUB5BZW7L5jD+ctBEPsrS9WWO7X538AfvtY= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a25:7082:0:b0:da0:59f7:3c97 with SMTP id l124-20020a257082000000b00da059f73c97mr671479ybc.12.1701336205366; Thu, 30 Nov 2023 01:23:25 -0800 (PST) Date: Thu, 30 Nov 2023 09:23:22 +0000 In-Reply-To: <20231130-neuwagen-balkon-aa1b34055fec@brauner> Mime-Version: 1.0 References: <20231130-neuwagen-balkon-aa1b34055fec@brauner> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231130092322.110837-1-aliceryhl@google.com> Subject: Re: [PATCH 4/7] rust: file: add `FileDescriptorReservation` From: Alice Ryhl To: brauner@kernel.org Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.com, arve@android.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, cmllamas@google.com, dan.j.williams@intel.com, dxu@dxuuu.xyz, gary@garyguo.net, gregkh@linuxfoundation.org, joel@joelfernandes.org, keescook@chromium.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, maco@android.com, ojeda@kernel.org, peterz@infradead.org, rust-for-linux@vger.kernel.org, surenb@google.com, tglx@linutronix.de, tkjos@android.com, viro@zeniv.linux.org.uk, wedsonaf@gmail.com, willy@infradead.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 01:23:37 -0800 (PST) Christian Brauner writes: > On Wed, Nov 29, 2023 at 06:14:24PM +0100, Alice Ryhl wrote: > > On Wed, Nov 29, 2023 at 5:55=E2=80=AFPM Alice Ryhl wrote: > >=20 > > > >> + pub fn commit(self, file: ARef) { > > > >> + // SAFETY: `self.fd` was previously returned by `get_unus= ed_fd_flags`, and `file.ptr` is > > > >> + // guaranteed to have an owned ref count by its type inva= riants. > > > >> + unsafe { bindings::fd_install(self.fd, file.0.get()) }; > > > > > > > > Why file.0.get()? Where did that come from? > > > > > > This gets a raw pointer to the C type. > > > > > > The `.0` part is a field access. `ARef` struct is a tuple struct, so = its > > > fields are unnamed. However, the fields can still be accessed by inde= x. > >=20 > > Oh, sorry, this is wrong. Let me try again: > >=20 > > This gets a raw pointer to the C type. The `.0` part accesses the > > field of type `Opaque` in the Rust wrapper. Recall > > that File is defined like this: > >=20 > > pub struct File(Opaque); > >=20 > > The above syntax defines a tuple struct, which means that the fields > > are unnamed. The `.0` syntax accesses the first field of a tuple > > struct [1]. > >=20 > > The `.get()` method is from the `Opaque` struct, which returns a raw > > pointer to the C type being wrapped. >=20 > It'd be nice if this could be written in a more obvious/elegant way. And > if not a comment would help. I know there'll be more text then code but > until this is second nature to read I personally won't mind... Because > searching for this specific syntax isn't really possible. Adding a comment to every instance of this is probably not realisitic. This kind of code will be very common in abstraction code. However, there are two other options that I think are reasonable: 1. I can change the definition of `File` so that the field has a name: struct File { inner: Opaque, } Then, it would say `file.inner.get()`. 2. Alternatively, I can add a method to file: impl File { #[inline] pub fn as_ptr(&self) -> *mut bindings::file { self.0.get() } } And then write `file.as_ptr()` whenever I want a pointer. Alice