Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3464180ybf; Tue, 3 Mar 2020 06:31:27 -0800 (PST) X-Google-Smtp-Source: ADFU+vumsd54pov+piu5CWiygjf/yIOg8bwI824ceRat3Y8S++hI0zyiSia5A8lc8h2WLtFz92g5 X-Received: by 2002:a9d:6:: with SMTP id 6mr3587468ota.191.1583245887396; Tue, 03 Mar 2020 06:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583245887; cv=none; d=google.com; s=arc-20160816; b=Cga2ZKOKnk/Zrt/H5b4phugKCThRVzmjejts3Z5zOOdLP/zFrfA6eoe5ovgO+/kiy7 Ma3BhLbr4xaNRk38CT0jwoxsdfbYLRoTCqzVvhdzWm7LTrZKj9oRabKqkMjVuHivD8cW AIpUBLUBeg+WnjUBHNJkGhtK6McM4K2yaajCvjFO1iNTAUXZ0CpJnwOjiPfwVHMilcrg BUKvtHPXAQsmwKQ66lfd14B/ga+cLYlu+sKJpKlRQ+GfR+C4/UcGOMQVtE5DCVNjRWF2 IB2NcRMUOmclqNKzmbbNTquCOA6BeoZqlBkl31qswoAk45RCc4irbcDV9p/QMjwBvHXG 0viA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=wf58kZKI+mTgIynh61BG3i7TYwQxuzRgLyVkzTEVnhE=; b=zdBuZSusIsDvNNZ3UrvhULnhKCL+pUPPLWnlfPhFtQf9lLyWir0loQpHW8MWFpwwFI qt5XZm0ABREJxp76IpUDKKBziSpYAb6T5A7wGurqMdNIjwvrwYMPva/0sGVNrzPDTh7z el/ZXk6zg3ZrHlFwuSfWb4xW1HYOy+FR7ZxczbXwnKVJD/v5XBZcWYTJFG2o76vQrWtV +dZPu3gAaCB7glVgfEWQzZEdfAvL6A76mjwpkI8kI6bGJX0fv/pyW35s9O54r+Pkb64W dJzytEz8BWyWDmz5dUvKnpFubdjs9QoNqIkax3qtyGDEE6K5Vp5ul/6glBMY4ba6v5c2 oNFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=duZsmPCx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si8084170oth.267.2020.03.03.06.31.15; Tue, 03 Mar 2020 06:31:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=duZsmPCx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729148AbgCCOaB (ORCPT + 99 others); Tue, 3 Mar 2020 09:30:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:56912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728158AbgCCOaB (ORCPT ); Tue, 3 Mar 2020 09:30:01 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43EDD20838; Tue, 3 Mar 2020 14:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583245800; bh=TcPA+2mgGtrFwfhcuBqjUOhNVvQpXnWRqswktmXfAMM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=duZsmPCxeAc5VhRa0Yt6P9WfVSUnLBKf/3B/UANogYCOeSUPd8Uo99JWWas4fX3Ct bFsA4K6GVvXuLmrLjvy/eSQZxixIY1E4SvnF9XQPei/asikOPZlIcrsGdX84Zs3Sgq S5fk2IOfMPJ+86ehQE8QG+laU36tf2Ln3yx1WP54= Date: Tue, 3 Mar 2020 15:29:58 +0100 From: Greg Kroah-Hartman To: Miklos Szeredi Cc: Karel Zak , David Howells , Ian Kent , Christian Brauner , James Bottomley , Steven Whitehouse , Miklos Szeredi , viro , Christian Brauner , Jann Horn , "Darrick J. Wong" , Linux API , linux-fsdevel , lkml Subject: Re: [PATCH 00/17] VFS: Filesystem information and notifications [ver #17] Message-ID: <20200303142958.GB47158@kroah.com> References: <0403cda7345e34c800eec8e2870a1917a8c07e5c.camel@themaw.net> <1509948.1583226773@warthog.procyon.org.uk> <20200303113814.rsqhljkch6tgorpu@ws.net.home> <20200303130347.GA2302029@kroah.com> <20200303131434.GA2373427@kroah.com> <20200303134316.GA2509660@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 03:10:50PM +0100, Miklos Szeredi wrote: > On Tue, Mar 3, 2020 at 2:43 PM Greg Kroah-Hartman > wrote: > > > > On Tue, Mar 03, 2020 at 02:34:42PM +0100, Miklos Szeredi wrote: > > > > If buffer is too small to fit the whole file, return error. > > > > Why? What's wrong with just returning the bytes asked for? If someone > > only wants 5 bytes from the front of a file, it should be fine to give > > that to them, right? > > I think we need to signal in some way to the caller that the result > was truncated (see readlink(2), getxattr(2), getcwd(2)), otherwise the > caller might be surprised. But that's not the way a "normal" read works. Short reads are fine, if the file isn't big enough. That's how char device nodes work all the time as well, and this kind of is like that, or some kind of "stream" to read from. If you think the file is bigger, then you, as the caller, can just pass in a bigger buffer if you want to (i.e. you can stat the thing and determine the size beforehand.) Think of the "normal" use case here, a sysfs read with a PAGE_SIZE buffer. That way userspace "knows" it will always read all of the data it can from the file, we don't have to do any seeking or determining real file size, or anything else like that. We return the number of bytes read as well, so we "know" if we did a short read, and also, you could imply, if the number of bytes read are the exact same as the number of bytes of the buffer, maybe the file is either that exact size, or bigger. This should be "simple", let's not make it complex if we can help it :) > > > Verify that the number of bytes read matches the file size, otherwise > > > return error (may need to loop?). > > > > No, we can't "match file size" as sysfs files do not really have a sane > > "size". So I don't want to loop at all here, one-shot, that's all you > > get :) > > Hmm. I understand the no-size thing. But looping until EOF (i.e. > until read return zero) might be a good idea regardless, because short > reads are allowed. If you want to loop, then do a userspace open/read-loop/close cycle. That's not what this syscall should be for. Should we call it: readfile-only-one-try-i-hope-my-buffer-is-big-enough()? :) thanks, greg k-h