From owner-freebsd-current@freebsd.org Fri Jul 5 17:33:26 2019 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8D4A915D07CE for ; Fri, 5 Jul 2019 17:33:26 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from ecc05.stack.nl (ws0.zlo.nu [190.2.135.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "*.stack.nl", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 05CC9813D4; Fri, 5 Jul 2019 17:33:24 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mail04.stack.nl (blade.stack.nl [51.15.111.152]) by ecc05.stack.nl (Postfix) with ESMTPS id D61F210029C; Fri, 5 Jul 2019 17:33:14 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail04.stack.nl (Postfix) with ESMTP id 9CB9610C6; Fri, 5 Jul 2019 17:33:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail04.stack.nl Received: from mail04.stack.nl ([127.0.0.1]) by localhost (mail04.stack.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EDDsrCb6uQsp; Fri, 5 Jul 2019 17:30:55 +0000 (UTC) Received: from blade.stack.nl (blade.stack.nl [192.168.122.130]) by mail04.stack.nl (Postfix) with ESMTP id 064FC40F; Fri, 5 Jul 2019 17:30:55 +0000 (UTC) Received: by blade.stack.nl (Postfix, from userid 1677) id D956320FA7; Fri, 5 Jul 2019 19:30:54 +0200 (CEST) Date: Fri, 5 Jul 2019 19:30:54 +0200 From: Jilles Tjoelker To: Rick Macklem Cc: "freebsd-current@FreeBSD.org" , "kib@freebsd.org" , Alan Somers Subject: Re: should a copy_file_range(2) syscall be interrupted via a signal Message-ID: <20190705173054.GA30404@stack.nl> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Queue-Id: 05CC9813D4 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of jilles@stack.nl designates 190.2.135.243 as permitted sender) smtp.mailfrom=jilles@stack.nl X-Spamd-Result: default: False [-2.56 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; NEURAL_HAM_MEDIUM(-0.81)[-0.814,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip4:190.2.135.243]; NEURAL_HAM_LONG(-0.99)[-0.989,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[stack.nl]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[mail01.stack.nl]; NEURAL_HAM_SHORT(-0.44)[-0.444,0]; IP_SCORE(0.00)[asn: 49981(-0.01), country: NL(0.01)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:49981, ipnet:190.2.128.0/20, country:NL]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jul 2019 17:33:26 -0000 On Fri, Jul 05, 2019 at 12:28:51AM +0000, Rick Macklem wrote: > I have been working on a Linux compatible copy_file_range(2) syscall > (the current code can be found at https://reviews.freebsd.org/D20584). > One outstanding issue is how it should deal with signals. Right now, I > have vn_start_write() without PCATCH, so that it won't be interrupted > by a signal, but I notice that vn_write() {ie. write syscall } does > have PCATCH on vn_start_write() and so does vn_rdwr() when it is > called without IO_NODELOCKED. A regular write() is only interruptible when writing to a terminal, pseudo-terminal master, pipe, socket, or, under certain conditions, a file on an NFS intr mount. Therefore, applications may not have the code to resume interrupted writes to regular files gracefully. > I am thinking that copy_file_range(2) should do this also. > However, if it returns an error, it is impossible for the caller to > know how much of the data range got copied. A regular write() returns partial success if interrupted by a signal when it has already written something. Therefore, the application can resume the operation by adjusting pointers and counts. Something similar applies to "deterministic" errors like [EFBIG] where the first call will write as far as possible (if this is not nothing) successfully and the next attempt will return the error. > What do you think the copy_file_range(2) code should do? I'm not sure it should actually be done, but the need for adjusting pointers and counts could be avoided with a little extra kernel and libc code. The system call would receive an additional argument pointing to an off_t that indicates how many bytes previous calls have already written. A libc wrapper would initialize this to 0. With this, the system call can be restarted automatically after a signal. In any case, [EINTR] and the internal ERESTART must not be returned unless it is safe to repeat the call with the same (direct) arguments. -- Jilles Tjoelker