From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Newsgroups: gmane.lisp.guile.bugs Subject: bug#68504: [PATCH] Add copy-on-write support to scm_copy_file. Date: Wed, 24 Jan 2024 11:26:56 +0100 Message-ID: <87le8fuivj.fsf@gnu.org> References: <20240116124817.14680-1-~@wolfsden.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5036"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 68504@debbugs.gnu.org To: Tomas Volf <~@wolfsden.cz> Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed Jan 24 11:28:24 2024 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rSaUa-00015G-DY for guile-bugs@m.gmane-mx.org; Wed, 24 Jan 2024 11:28:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSaUE-0002zv-Gb; Wed, 24 Jan 2024 05:28:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSaUA-0002yC-8e for bug-guile@gnu.org; Wed, 24 Jan 2024 05:27:58 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSaU8-0005RY-Ms for bug-guile@gnu.org; Wed, 24 Jan 2024 05:27:57 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rSaUD-0004rC-RP for bug-guile@gnu.org; Wed, 24 Jan 2024 05:28:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 24 Jan 2024 10:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68504 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 68504-submit@debbugs.gnu.org id=B68504.170609204518619 (code B ref 68504); Wed, 24 Jan 2024 10:28:01 +0000 Original-Received: (at 68504) by debbugs.gnu.org; 24 Jan 2024 10:27:25 +0000 Original-Received: from localhost ([127.0.0.1]:44537 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSaTc-0004qF-Qw for submit@debbugs.gnu.org; Wed, 24 Jan 2024 05:27:25 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSaTa-0004q0-2G for 68504@debbugs.gnu.org; Wed, 24 Jan 2024 05:27:23 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSaTO-0005OY-Ii; Wed, 24 Jan 2024 05:27:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=XuXvZgmQdAJMWkeagTWDOMYEDtjPjp+h64MEsc4IqVc=; b=rnp3Jcr+1Jfz5ITciNDP TKKz4tKlbuyCKxLYNwKM3ueX+FTBmU8q8bA026fKUbRV2l9DaqtLK+3JPBjPGfkdVhj05faOa+CKv m+ROJCcLVtI/ZE+69J26yW7YXZEOFcqqntj5oF8ABPSmomakC15F+iicXPKLr5yWaj85Rk/iKlOa+ krEv2XreeQ6UgnFpiS/YZSYu9Pnd+W66NHCNwhZ1re8h8LxbVWkAWPYLsGQktettqywBfR6t681Nv jnmt4qIIvepGTybLDI+Je2GYf0zguEEoSTmcOs/LU4yURMvOKumIwQ3WtqROYDfhBFv1hdUjosH6B x88CIyRD/2CzNw==; In-Reply-To: <20240116124817.14680-1-~@wolfsden.cz> (Tomas Volf's message of "Tue, 16 Jan 2024 13:48:17 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10762 Archived-At: Hi, Tomas Volf <~@wolfsden.cz> skribis: > On modern file-systems (BTRFS, ZFS) it is possible to copy a file using > copy-on-write method. For large files it has the advantage of being > much faster and saving disk space (since identical extents are not > duplicated). This feature is stable and for example coreutils' `cp' > does use it automatically (see --reflink). > > This commit adds support for this feature into our > copy-file (scm_copy_file) procedure. Same as `cp', it defaults to > 'auto, meaning the copy-on-write is attempted, and in case of failure > the regular copy is performed. > > No tests are provided, because the behavior depends on the system, > underlying file-system and its configuration. That makes it challenging > to write a test for it. Manual testing was performed instead: > > $ btrfs filesystem du /tmp/cow* > Total Exclusive Set shared Filename > 36.00KiB 36.00KiB 0.00B /tmp/cow > > $ cat cow-test.scm > (copy-file "/tmp/cow" "/tmp/cow-unspecified") > (copy-file "/tmp/cow" "/tmp/cow-always" #:copy-on-write 'always) > (copy-file "/tmp/cow" "/tmp/cow-auto" #:copy-on-write 'auto) > (copy-file "/tmp/cow" "/tmp/cow-never" #:copy-on-write 'never) > (copy-file "/tmp/cow" "/dev/shm/cow-unspecified") > (copy-file "/tmp/cow" "/dev/shm/cow-auto" #:copy-on-write 'auto) > (copy-file "/tmp/cow" "/dev/shm/cow-never" #:copy-on-write 'never) > $ ./meta/guile -s cow-test.scm > > $ btrfs filesystem du /tmp/cow* > Total Exclusive Set shared Filename > 36.00KiB 0.00B 36.00KiB /tmp/cow > 36.00KiB 0.00B 36.00KiB /tmp/cow-always > 36.00KiB 0.00B 36.00KiB /tmp/cow-auto > 36.00KiB 36.00KiB 0.00B /tmp/cow-never > 36.00KiB 0.00B 36.00KiB /tmp/cow-unspecified > > $ sha1sum /tmp/cow* /dev/shm/cow* > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /tmp/cow > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /tmp/cow-always > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /tmp/cow-auto > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /tmp/cow-never > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /tmp/cow-unspecified > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /dev/shm/cow-auto > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /dev/shm/cow-never > 4c665f87b5dc2e7d26279c4b48968d085e1ace32 /dev/shm/cow-unspecified > > This commit also adds to new failure modes for (copy-file). > > Failure to copy-on-write when 'always was passed in: > > scheme@(guile-user)> (copy-file "/tmp/cow" "/dev/shm/cow" #:copy-on-w= rite 'always) > ice-9/boot-9.scm:1676:22: In procedure raise-exception: > In procedure copy-file: copy-on-write failed: Invalid cross-device li= nk > > Passing in invalid value for the #:copy-on-write keyword argument: > > scheme@(guile-user)> (copy-file "/tmp/cow" "/dev/shm/cow" #:copy-on-w= rite 'nevr) > ice-9/boot-9.scm:1676:22: In procedure raise-exception: > In procedure copy-file: invalid value for #:copy-on-write: nevr > > * NEWS: Add note for copy-file supporting copy-on-write. > * configure.ac: Check for linux/fs.h. > * doc/ref/posix.texi (File System)[copy-file]: Document the new > signature. > * libguile/filesys.c (clone_file): New function cloning a file using > FICLONE, if supported. > (k_copy_on_write): New keyword. > (sym_always, sym_auto, sym_never): New symbols. > (scm_copy_file): New #:copy-on-write keyword argument. Attempt > copy-on-write copy by default. > * libguile/filesys.h: Update signature for scm_copy_file. The patch looks great (and very useful) to me, modulo one issue: > -SCM_API SCM scm_copy_file (SCM oldfile, SCM newfile); > +SCM_API SCM scm_copy_file (SCM oldfile, SCM newfile, SCM rest); Since this is a public interface, we cannot change this function=E2=80=99s signature during the 3.0 stable series. Thus, I would suggest keeping the public =E2=80=98scm_copy_file=E2=80=99 un= changed and internally having a three-argument variant. The Scheme-level =E2=80=98copy-file=E2=80=99 would map to that three-argument variant. (See= how =E2=80=98scm_pipe=E2=80=99 and =E2=80=98scm=C2=A0accept=E2=80=99 as example= s.) Could you send an updated patch? BTW, copyright assignment to the FSF is now optional but encouraged. Please see . Thanks, Ludo=E2=80=99.