From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#23904: Btrfs clone support in copy operations Date: Wed, 6 Jul 2016 02:49:12 +0200 Message-ID: <577C5588.3060608@cs.ucla.edu> References: <1467745602.28158.17.camel@kcolford.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070407000101080704040409" X-Trace: ger.gmane.org 1467766228 17277 80.91.229.3 (6 Jul 2016 00:50:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 6 Jul 2016 00:50:28 +0000 (UTC) Cc: sbaugh@catern.com, Kieran Colford To: 23904@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 06 02:50:16 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bKb2d-0003Sr-E1 for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Jul 2016 02:50:15 +0200 Original-Received: from localhost ([::1]:58756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb2c-0000P3-7N for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Jul 2016 20:50:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb2U-0000MY-9a for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:50:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKb2Q-0000Xm-2K for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:50:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb2P-0000Xi-VU for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:50:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bKb2P-00053U-OL for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:50:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Jul 2016 00:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.146776617819393 (code B ref -1); Wed, 06 Jul 2016 00:50:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jul 2016 00:49:38 +0000 Original-Received: from localhost ([127.0.0.1]:38738 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKb21-00052j-Sn for submit@debbugs.gnu.org; Tue, 05 Jul 2016 20:49:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKb1y-00052T-72 for submit@debbugs.gnu.org; Tue, 05 Jul 2016 20:49:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKb1r-0000Rt-Eq for submit@debbugs.gnu.org; Tue, 05 Jul 2016 20:49:28 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:47234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb1r-0000Rm-BD for submit@debbugs.gnu.org; Tue, 05 Jul 2016 20:49:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb1o-0000Kr-Lm for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:49:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKb1l-0000Qi-DD for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:49:24 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKb1l-0000Q9-4R for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2016 20:49:21 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B59131614C4; Tue, 5 Jul 2016 17:49:19 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id SFeRXCk90mgA; Tue, 5 Jul 2016 17:49:17 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E03CE1614AD; Tue, 5 Jul 2016 17:49:17 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9qTC7WVSxn1m; Tue, 5 Jul 2016 17:49:17 -0700 (PDT) Original-Received: from [192.168.0.35] (89-159-79-138.rev.numericable.fr [89.159.79.138]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 1EDCB1613C2; Tue, 5 Jul 2016 17:49:16 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <1467745602.28158.17.camel@kcolford.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:120475 Archived-At: This is a multi-part message in MIME format. --------------070407000101080704040409 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Tags: patch The attached proposed patch to Emacs master builds on a suggestion by Kieran Colford. Kieran, can you please comment on its two FIXMEs? --------------070407000101080704040409 Content-Type: text/x-patch; name="0001-copy-file-now-uses-GNU-Linux-file-cloning.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-copy-file-now-uses-GNU-Linux-file-cloning.patch" >From 4b2a532a87ec2a21afc205b83db4a779664ccd20 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Jul 2016 02:42:58 +0200 Subject: [PATCH] copy-file now uses GNU/Linux file cloning >From a suggestion by Kieran Colford in: http://lists.gnu.org/archive/html/emacs-devel/2016-07/msg00191.html * configure.ac: Check for linux/fs.h. * src/fileio.c [HAVE_LINUX_FS_H]: Include sys/ioctl.h and linux/fs.h. (clone_file): New function. (Fcopy_file): Use it. --- configure.ac | 1 + src/fileio.c | 64 ++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index aaddfcd..1798fa3 100644 --- a/configure.ac +++ b/configure.ac @@ -1636,6 +1636,7 @@ AC_DEFUN dnl checks for header files AC_CHECK_HEADERS_ONCE( + linux/fs.h malloc.h sys/systeminfo.h sys/sysinfo.h diff --git a/src/fileio.c b/src/fileio.c index b1f9d3c..c2e3a18 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -52,6 +52,11 @@ along with GNU Emacs. If not, see . */ #include "region-cache.h" #include "frame.h" +#ifdef HAVE_LINUX_FS_H +# include +# include +#endif + #ifdef WINDOWSNT #define NOMINMAX 1 #include @@ -1828,6 +1833,24 @@ barf_or_query_if_file_exists (Lisp_Object absname, bool known_to_exist, } } +/* Copy all data to DEST from SOURCE if possible. Return true if OK. */ +static bool +clone_file (int dest, int source) +{ +#ifdef FICLONE + /* FIXME: Might this ioctl take a long time if the file is very + large? Is the ioctl interruptible? If so, what happens if the + ioctl is interrupted by a signal? Might it partially copy the + file? */ + /* FIXME: Does this ioctl truncate the output file to be the same + size as the input file, if the output file already exists and is + larger than the input file? */ + if (ioctl (dest, FICLONE, source) == 0) + return true; +#endif + return false; +} + DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6, "fCopy file: \nGCopy %s to file: \np\nP", doc: /* Copy FILE to NEWNAME. Both args must be strings. @@ -1988,28 +2011,31 @@ permissions. */) oldsize = out_st.st_size; } - immediate_quit = 1; - QUIT; - while (true) + if (! clone_file (ofd, ifd)) { - char buf[MAX_ALLOCA]; - ptrdiff_t n = emacs_read (ifd, buf, sizeof buf); - if (n < 0) - report_file_error ("Read error", file); - if (n == 0) - break; - if (emacs_write_sig (ofd, buf, n) != n) - report_file_error ("Write error", newname); - newsize += n; - } + immediate_quit = 1; + QUIT; + while (true) + { + char buf[MAX_ALLOCA]; + ptrdiff_t n = emacs_read (ifd, buf, sizeof buf); + if (n < 0) + report_file_error ("Read error", file); + if (n == 0) + break; + if (emacs_write_sig (ofd, buf, n) != n) + report_file_error ("Write error", newname); + newsize += n; + } - /* Truncate any existing output file after writing the data. This - is more likely to work than truncation before writing, if the - file system is out of space or the user is over disk quota. */ - if (newsize < oldsize && ftruncate (ofd, newsize) != 0) - report_file_error ("Truncating output file", newname); + /* Truncate any existing output file after writing the data. This + is more likely to work than truncation before writing, if the + file system is out of space or the user is over disk quota. */ + if (newsize < oldsize && ftruncate (ofd, newsize) != 0) + report_file_error ("Truncating output file", newname); - immediate_quit = 0; + immediate_quit = 0; + } #ifndef MSDOS /* Preserve the original file permissions, and if requested, also its -- 2.5.5 --------------070407000101080704040409--