Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4653204rdh; Wed, 29 Nov 2023 07:14:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0A8uD1++AvapJjLUvjXbrSXKIH7UI0h9RHJ3pvze4MfsHZomcbQ9wffNovN7x3eDWpOhn X-Received: by 2002:a17:90b:30cb:b0:281:3a4a:2e61 with SMTP id hi11-20020a17090b30cb00b002813a4a2e61mr16951483pjb.14.1701270849249; Wed, 29 Nov 2023 07:14:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701270849; cv=none; d=google.com; s=arc-20160816; b=HREe+n477kWTu/vXLRzrxohUZrYQpeRC5Mivf5qjdhtWKmNOjI9eQdrY8crV39l1wX TxNtjQ0ayJXKufONZFYy7DQGaFu3QF+9aZSNhxj0MJ2LcXYF6RmurwssjekqDI1tgEHW Sj2Q4P497HPRPE+RpMyicuLlVrVYIfXD2+KEe9GZfSHaVda21H/6FMKiigqth062DpRn 9Hl/dYAYxLZ7YdUdJbSRd+vuZmo4cfkSI8uU9pJUK1pKoh2ZbnRflGXg6rdEALJqOq3l 0RIn7vPiR2Rx9mMBOqLYAqGySAHIH+s+faGi6Uh0DqakmZBOxfD5hRXJy8VKPNnS/WS9 Crug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hXMxOlO+RptZuf7tC18898oF9lCqJDluY9IAnxRZEqY=; fh=uOTNrh3cM69Hs0mQ9j0HWtmS0InZy0ZlCMifR/I6rWU=; b=c3X//8La0hAzdXmxS0V7VtOpZNpiZ0NmGyaWI5H6IlNwnFRwvCtVJcARkMRrIsn3PX HORpGrtv40FSsxBBkFNov59QBrCzdloaNuRkRPiFwnG/khC5ZHgmgEdat18eOGoTj/pu spyrhBIYd2wsEGPfGQ6yiPhh2o+U3yg+qsLB9zae3BJBlGNV7Z5x+A5KZ4f29/RkEGU/ sNTZo9HrkNhDW5d8LdBRxLNpErCR851On7LD0kdniDhcHyey0MVwvaFaAaPEHwhJI6AM UNmBKX+IA0NHzXgrH1hpayH8rRF5jiyPcKszXZtlmdiA4IZ17kpny8ZDSdfsA1spholX kn1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iWaMT3ZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id y9-20020a17090aa40900b00274caaa057asi1405118pjp.42.2023.11.29.07.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 07:14:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iWaMT3ZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D8A5D804C210; Wed, 29 Nov 2023 07:14:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234284AbjK2PNj (ORCPT + 99 others); Wed, 29 Nov 2023 10:13:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbjK2PNi (ORCPT ); Wed, 29 Nov 2023 10:13:38 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC8BA3; Wed, 29 Nov 2023 07:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hXMxOlO+RptZuf7tC18898oF9lCqJDluY9IAnxRZEqY=; b=iWaMT3ZK3Iq5szkDIHQIo4Q6zd uVOQ9+a5l+Vl2Ij58r3TItf3naUI4KsjPqD/Yc9tIT1v9d8UXxCBejPzm/jUw/9gjgLmYbuoY9F1r MUb4Sh5qWs+PJu9UPSTfudrSH8n6wHs+c2gW3IgzbfmHoQ7oLbjgN8yJFZNcAnDjred3oD7mwlFjl XJZvuQY2lHbpIt2ppnWcz65kd3Vwpd3RkJsNAbkvd5yITdCnRdTt7oE/mYRynXKjMLo/uwbupqz/Y gzCx/Vu6K0B93J1DlxrhXeexkpBhqJpa5sAu8NBXKFusS99SXc+mK6eejToEXlz7FOn0nIXhjZM+I cnpBEd1g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r8MFe-00DVZy-3D; Wed, 29 Nov 2023 15:13:22 +0000 Date: Wed, 29 Nov 2023 15:13:22 +0000 From: Matthew Wilcox To: Alice Ryhl Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/7] rust: file: add Rust abstraction for `struct file` Message-ID: References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-1-f81afe8c7261@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231129-alice-file-v1-1-f81afe8c7261@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 07:14:03 -0800 (PST) On Wed, Nov 29, 2023 at 12:51:07PM +0000, Alice Ryhl wrote: > This introduces a struct for the EBADF error type, rather than just > using the Error type directly. This has two advantages: > * `File::from_fd` returns a `Result, BadFdError>`, which the > compiler will represent as a single pointer, with null being an error. > This is possible because the compiler understands that `BadFdError` > has only one possible value, and it also understands that the > `ARef` smart pointer is guaranteed non-null. > * Additionally, we promise to users of the method that the method can > only fail with EBADF, which means that they can rely on this promise > without having to inspect its implementation. > That said, there are also two disadvantages: > * Defining additional error types involves boilerplate. > * The question mark operator will only utilize the `From` trait once, > which prevents you from using the question mark operator on > `BadFdError` in methods that return some third error type that the > kernel `Error` is convertible into. (However, it works fine in methods > that return `Error`.) I haven't looked at how Rust-for-Linux handles errors yet, but it's disappointing to see that it doesn't do something like the PTR_ERR / ERR_PTR / IS_ERR C thing under the hood. > @@ -157,6 +158,12 @@ void rust_helper_init_work_with_key(struct work_struct *work, work_func_t func, > } > EXPORT_SYMBOL_GPL(rust_helper_init_work_with_key); > > +struct file *rust_helper_get_file(struct file *f) > +{ > + return get_file(f); > +} > +EXPORT_SYMBOL_GPL(rust_helper_get_file); This is ridiculous. A function call instead of doing the atomic_long_inc() in Rust?