All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Isaacson <adi@hexapodia.org>
To: Andrew Morton <akpm@osdl.org>
Cc: bug-coreutils@gnu.org, linux-kernel@vger.kernel.org
Subject: Re: dd PATCH: add conv=direct
Date: Wed, 7 Apr 2004 12:31:16 -0500	[thread overview]
Message-ID: <20040407173116.GB2814@hexapodia.org> (raw)
In-Reply-To: <20040406173326.0fbb9d7a.akpm@osdl.org>

On Tue, Apr 06, 2004 at 05:33:26PM -0700, Andrew Morton wrote:
> Andy Isaacson <adi@hexapodia.org> wrote:
> >          dd(1) is convenient for this purpose, but is lacking a method
> > to force O_DIRECT.  The enclosed patch adds a "conv=direct" flag to
> > enable this usage.
> 
> This would be rather nice to have.  You'll need to ensure that the data
> is page-aligned in memory.

So, some confusion on my part about O_DIRECT:  I can't get O_DIRECT to
work on ext3, at all, on 2.4.25 -- open(O_DIRECT) succeeds, but the write
returns EINVAL.  Same code works fine when writing to a block device.
If the problem is that ext3 can't support O_DIRECT, why does the open
succeed?

> While you're there, please add an fsync-before-closing option.

Easy enough.  How does this look?  Note that C_TWOBUFS ensures the
output buffer is getpagesize()-aligned.

The next feature to add would be OpenBSD-style "KB/s" reporting.  I'm
not going there.

-andy

2004-04-07  Andy Isaacson  <adi@hexapodia.org>

	* add conv=direct and conv=fsync options.

diff -ur coreutils-5.0.91/doc/coreutils.texi coreutils-5.0.91-adi/doc/coreutils.texi
--- coreutils-5.0.91/doc/coreutils.texi	2003-09-04 16:26:51.000000000 -0500
+++ coreutils-5.0.91-adi/doc/coreutils.texi	2004-04-07 11:26:36.000000000 -0500
@@ -6373,6 +6373,16 @@
 Pad every input block to size of @samp{ibs} with trailing zero bytes.
 When used with @samp{block} or @samp{unblock}, pad with spaces instead of
 zero bytes.
+
+@item fsync
+@opindex fsync
+Call @samp{fsync(2)} on the output file before exiting.  This ensures
+that the file data is written to permanent store.
+
+@item direct
+@opindex direct
+Open the output file with O_DIRECT, avoiding (on Linux) using the buffer
+cache.
 @end table
 
 @end table
diff -ur coreutils-5.0.91/src/dd.c coreutils-5.0.91-adi/src/dd.c
--- coreutils-5.0.91/src/dd.c	2003-07-25 02:43:09.000000000 -0500
+++ coreutils-5.0.91-adi/src/dd.c	2004-04-07 11:45:23.000000000 -0500
@@ -66,6 +66,9 @@
 /* Default input and output blocksize. */
 #define DEFAULT_BLOCKSIZE 512
 
+/* XXX hack */
+#define HAVE_O_DIRECT 1
+
 /* Conversions bit masks. */
 #define C_ASCII 01
 #define C_EBCDIC 02
@@ -78,6 +81,8 @@
 #define C_NOERROR 0400
 #define C_NOTRUNC 01000
 #define C_SYNC 02000
+#define C_FSYNC 010000
+#define C_DIRECT 020000
 /* Use separate input and output buffers, and combine partial input blocks. */
 #define C_TWOBUFS 04000
 
@@ -162,6 +167,10 @@
   {"noerror", C_NOERROR},	/* Ignore i/o errors. */
   {"notrunc", C_NOTRUNC},	/* Do not truncate output file. */
   {"sync", C_SYNC},		/* Pad input records to ibs with NULs. */
+  {"fsync", C_FSYNC},		/* call fsync(2) before closing output file */
+#ifdef HAVE_O_DIRECT
+  {"direct", C_DIRECT | C_TWOBUFS},	/* open files with O_DIRECT */
+#endif
   {NULL, 0}
 };
 
@@ -1190,6 +1199,11 @@
 	= (O_CREAT
 	   | (seek_records || (conversions_mask & C_NOTRUNC) ? 0 : O_TRUNC));
 
+#if HAVE_O_DIRECT
+      if (conversions_mask & C_DIRECT)
+	opts |= O_DIRECT;
+#endif
+
       /* Open the output file with *read* access only if we might
 	 need to read to satisfy a `seek=' request.  If we can't read
 	 the file, go ahead with write-only access; it might work.  */
@@ -1240,5 +1254,11 @@
 
   exit_status = dd_copy ();
 
+  if (conversions_mask & C_FSYNC)
+    {
+      if (fsync (STDOUT_FILENO) != 0)
+	error(0, errno, _("cannot fsync %s"), quote (output_file));
+    }
+
   quit (exit_status);
 }

  parent reply	other threads:[~2004-04-07 17:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-06 22:03 dd PATCH: add conv=direct Andy Isaacson
2004-04-07  0:33 ` Andrew Morton
2004-04-07 16:21   ` Bruce Allen
2004-04-07 16:42     ` Andrew Morton
2004-04-07 17:31   ` Andy Isaacson [this message]
2004-04-07 18:18     ` Andrew Morton
2004-04-07 19:24       ` Andy Isaacson
2004-04-07 19:34         ` Andrew Morton
2004-04-07 19:47           ` Andy Isaacson
2004-04-07 20:03             ` Andrew Morton
2004-04-07 20:43               ` Andy Isaacson
2004-04-07 21:00                 ` Valdis.Kletnieks
2004-04-07 21:35                 ` Bruce Allen
2004-04-08  6:56                   ` Paul Eggert
2004-04-08 11:07                     ` Jim Meyering
2004-04-08 19:32                       ` Paul Eggert
2004-04-08 19:51                         ` Paul Jarc
2004-04-08 21:34                         ` Jim Meyering
2004-04-08 16:23                     ` Philippe Troin
2004-04-08 20:20                       ` dd patch to remove noctty Paul Eggert
2004-04-08 21:40                         ` Jim Meyering
2004-04-09  0:37             ` dd PATCH: add conv=direct Anton Blanchard
2004-04-09  1:42               ` Wim Coekaerts
2004-04-10 21:28                 ` Jim Meyering
2004-04-07 20:46       ` Paul Eggert
2004-04-07 21:06         ` Andrew Morton
2004-04-07 21:09         ` Andy Isaacson
2004-04-07 19:12     ` Miquel van Smoorenburg
2004-04-07 20:14       ` Andy Isaacson
2004-04-07 22:02 ` Nathan Straz
2004-04-07 22:09   ` Andy Isaacson
2004-04-08 11:44     ` Miquel van Smoorenburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040407173116.GB2814@hexapodia.org \
    --to=adi@hexapodia.org \
    --cc=akpm@osdl.org \
    --cc=bug-coreutils@gnu.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.