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 15:43:41 -0500 [thread overview]
Message-ID: <20040407204341.GF2814@hexapodia.org> (raw)
In-Reply-To: <20040407130308.7c7ec8dc.akpm@osdl.org>
On Wed, Apr 07, 2004 at 01:03:08PM -0700, Andrew Morton wrote:
> Andy Isaacson <adi@hexapodia.org> wrote:
> > I claim that O_DIRECT on of= is important because you just plain *can
> > not* do the minimal-sized IDE block scrub without it. I don't yet see a
> > similar benefit to O_DIRECT on if= side.
>
> If you want a block scrubber then write a block scrubber.
They exist. They're a pain in the ass to find when you need one. dd is
almost there; a small patch that might have a chance of getting accepted
upstream seemed like a reasonable time investment.
> If you want to add O_DIRECT support to dd then it should be implemented
> properly, and that means implementing it for both read and write.
>
> In fact the user should be able to specify the read-O_DIRECT and the
> write-O_DIRECT independently - if for no other reason than that the source
> and dest filesytems may not both support O_DIRECT.
Of course if both directions are supported they must be independently
specifiable. I just don't see a compelling use case for the input side.
Nevertheless, here you go. Still needs some autoconfiscation.
2004-04-07 Andy Isaacson <adi@hexapodia.org>
* add conv=direct, conv=idirect, and conv=fsync options.
diff -u'rx*.1' 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 15:24:17.000000000 -0500
@@ -6373,6 +6373,20 @@
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.
+
+@item idirect
+@opindex idirect
+Open the input file with O_DIRECT, avoiding (on Linux) using the buffer
@end table
@end table
diff -u'rx*.1' 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 15:23:24.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,9 @@
#define C_NOERROR 0400
#define C_NOTRUNC 01000
#define C_SYNC 02000
+#define C_FSYNC 010000
+#define C_DIRECT 020000
+#define C_IDIRECT 040000
/* Use separate input and output buffers, and combine partial input blocks. */
#define C_TWOBUFS 04000
@@ -162,6 +168,11 @@
{"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 output with O_DIRECT */
+ {"idirect", C_IDIRECT | C_TWOBUFS}, /* open input with O_DIRECT */
+#endif
{NULL, 0}
};
@@ -1177,7 +1188,14 @@
if (input_file != NULL)
{
- if (open_fd (STDIN_FILENO, input_file, O_RDONLY, 0) < 0)
+ int opts = O_RDONLY;
+
+#if HAVE_O_DIRECT
+ if (conversions_mask & C_IDIRECT)
+ opts |= O_DIRECT;
+#endif
+
+ if (open_fd (STDIN_FILENO, input_file, opts, 0) < 0)
error (EXIT_FAILURE, errno, _("opening %s"), quote (input_file));
}
else
@@ -1190,6 +1208,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 +1263,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);
}
next prev parent reply other threads:[~2004-04-07 20:44 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
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 [this message]
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=20040407204341.GF2814@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).