Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp443584rdb; Thu, 30 Nov 2023 08:41:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IExXIFXfCHT7cTbOGcAwPPeDDc9TJWBFp8XnXRSreO6lhttY8v4u4k9fDyKtrcIgGN6VCAq X-Received: by 2002:a17:90a:2f63:b0:286:5127:d9ba with SMTP id s90-20020a17090a2f6300b002865127d9bamr747798pjd.8.1701362486402; Thu, 30 Nov 2023 08:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701362486; cv=none; d=google.com; s=arc-20160816; b=P2wY6oK0MVOOBN95NNGvrCStvkgF5U2oXUe1hs5fdhVV8rPUff6iAQnQl4X0iI64HI H5yBlV24ld/6+YjISvemD+6etXUkgthJKPdrzWAv1uBnGS2j2rIgOH4W5uxViN4f5wq1 HK2Lrtx4+pOER4DJWeITRS1Ne+l1pW6QuXggoQXHFde/FtLc+uzFkxfVSUIghew1F2rD 9DozJ8e/r3qKAoqsI8unobc4SchrywXgsEgnlkCdun6Y2/9qG5oKGsYAlULeV6Mc39ja 1+2sRoA/vbicqcR62TJgVuDDv1BTJ5WB2ZCSGu+tym8p+XJ6pMJd+R3kduCBaCc9Ru2a ed2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=aUwMWJjNDKEwZmf6rHJqm0TKxpV/+zt7aI/cwBnNF/A=; fh=yGC6hLtEKxG/qAMK6tCmLY72Pr3WjPw6U6qgCoktHOQ=; b=CVb7s4C1HoLaUX9uYKaYBG4ZpfFIqGeZkPjTPOF3Z609pFLHA7hr+1hf7K0bVhPY7p 214GMEpMd8sY3WoJH+6ED03lA4wCYu22wTJxu2/sg5Q6Da/rrH/ne2XPL3pz7MY3yr4j gf50YRhgpQcFlDJvKBaO2Yo/SbsHshKF78i+Y64yI1k1KsGMCdA4dURXkn6+TKB44Ayu JY4wvS4Giuw+IaaICp/CsOio1S1y5IuxpfcGsjEzJEIF0d96ujvKtUJLSo5G5AtyRJQY JYg0faEypgc37247JAT7yezseaqgBvwqwySed1n67r6P21AskF/lzze2IY0ycOrnsZFx oLBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ehwizPfW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id kb8-20020a17090ae7c800b00280072b397csi4199282pjb.30.2023.11.30.08.41.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 08:41:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ehwizPfW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7A1888072A00; Thu, 30 Nov 2023 08:40:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345536AbjK3Qkd (ORCPT + 99 others); Thu, 30 Nov 2023 11:40:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232183AbjK3Qk3 (ORCPT ); Thu, 30 Nov 2023 11:40:29 -0500 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF8F1A3; Thu, 30 Nov 2023 08:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1701362431; x=1701621631; bh=aUwMWJjNDKEwZmf6rHJqm0TKxpV/+zt7aI/cwBnNF/A=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ehwizPfWAQhgd+7ta7CVxTTmFCLL9OZt2OTvHEdaMgrWXuHZyzNtxt32CUCB1M1PE 6Q+MytXCCWjdVY4dbSvh6ZJKpIPHcoYlRCO+llV1Xp7icXNkd0rCP0iJqnsIUNchCq vhjmms7N2eQ7KF8DgyqKB/J40WXRCW17Ire313/raamQ4GRVNVJo1nW5l2u+gwoSrD dGF7BTHj/ahSWnAkJBD+hsBw5ttmcbKOTao+Z8d3w4BlBlRvcdgDQAGODrIGsqu71+ rbRLbghNbiq+a+sjoiF4TvWS2W3VSuL2zQ0mH2WIU6Iv0P+QW5++cSqJPpi80t3Y51 C2KroYXNBsJbw== Date: Thu, 30 Nov 2023 16:40:08 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 4/7] rust: file: add `FileDescriptorReservation` Message-ID: <_xnOTacjwsOFSA4oog2DJs0VLa1w0EaSPM3rqDUjIZAmNgiq0V0-bJwfVZdDKaydes_rJb30Zz4TyacYImYZHK6i0-LR8AYbQa2T1l0h3K8=@proton.me> In-Reply-To: <20231129-alice-file-v1-4-f81afe8c7261@google.com> References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-4-f81afe8c7261@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 08:40:46 -0800 (PST) On 11/29/23 14:11, Alice Ryhl wrote: > +impl FileDescriptorReservation { > + /// Creates a new file descriptor reservation. > + pub fn new(flags: u32) -> Result { > + // SAFETY: FFI call, there are no safety requirements on `flags`= . > + let fd: i32 =3D unsafe { bindings::get_unused_fd_flags(flags) }; > + if fd < 0 { > + return Err(Error::from_errno(fd)); > + } I think here we could also use the modified `to_result` function that returns a `u32` if the value is non-negative. > + Ok(Self { > + fd: fd as _, > + _not_send_sync: PhantomData, > + }) > + } > + > + /// Returns the file descriptor number that was reserved. > + pub fn reserved_fd(&self) -> u32 { > + self.fd > + } > + > + /// Commits the reservation. > + /// > + /// The previously reserved file descriptor is bound to `file`. This= method consumes the > + /// [`FileDescriptorReservation`], so it will not be usable after th= is call. > + pub fn commit(self, file: ARef) { > + // SAFETY: `self.fd` was previously returned by `get_unused_fd_f= lags`, and `file.ptr` is > + // guaranteed to have an owned ref count by its type invariants. > + unsafe { bindings::fd_install(self.fd, file.0.get()) }; > + > + // `fd_install` consumes both the file descriptor and the file r= eference, so we cannot run > + // the destructors. > + core::mem::forget(self); > + core::mem::forget(file); Would be useful to have an `ARef::into_raw` function that would do the `forget` for us. --=20 Cheers, Benno