svn commit: r362830 - stable/12/bin/dd

Richard Scheffenegger rscheff at FreeBSD.org
Wed Jul 1 09:28:01 UTC 2020


Author: rscheff
Date: Wed Jul  1 09:28:00 2020
New Revision: 362830
URL: https://svnweb.freebsd.org/changeset/base/362830

Log:
  MFC r361806: Add O_DIRECT flag to DD for cache bypass
  
  FreeBSD DD utility has not had support for the O_DIRECT flag, which
  is useful to bypass local caching, e.g. for unconditionally issuing
  NFS IO requests during testing.
  
  Reviewed by:	rgrimes (mentor)
  Approved by:	rgrimes (blanket)
  MFC after:	3 weeks
  Sponsored by:	NetApp, Inc.
  Differential Revision:	https://reviews.freebsd.org/D25066

Modified:
  stable/12/bin/dd/args.c
  stable/12/bin/dd/dd.1
  stable/12/bin/dd/dd.c
  stable/12/bin/dd/dd.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/dd/args.c
==============================================================================
--- stable/12/bin/dd/args.c	Wed Jul  1 08:23:57 2020	(r362829)
+++ stable/12/bin/dd/args.c	Wed Jul  1 09:28:00 2020	(r362830)
@@ -266,6 +266,7 @@ static const struct iflag {
 	const char *name;
 	uint64_t set, noset;
 } ilist[] = {
+	{ "direct",	C_IDIRECT,	0 },
 	{ "fullblock",	C_IFULLBLOCK,	C_SYNC },
 };
 
@@ -410,6 +411,7 @@ static const struct oflag {
 	const char *name;
 	uint64_t set;
 } olist[] = {
+	{ "direct",	C_ODIRECT },
 	{ "fsync",	C_OFSYNC },
 	{ "sync",	C_OFSYNC },
 };

Modified: stable/12/bin/dd/dd.1
==============================================================================
--- stable/12/bin/dd/dd.1	Wed Jul  1 08:23:57 2020	(r362829)
+++ stable/12/bin/dd/dd.1	Wed Jul  1 09:28:00 2020	(r362830)
@@ -32,7 +32,7 @@
 .\"     @(#)dd.1	8.2 (Berkeley) 1/13/94
 .\" $FreeBSD$
 .\"
-.Dd March 26, 2019
+.Dd June 4, 2020
 .Dt DD 1
 .Os
 .Sh NAME
@@ -117,6 +117,8 @@ limits the number of times
 is called on the input rather than the number of blocks copied in full.
 May not be combined with
 .Cm conv=sync .
+.It Cm direct
+Set the O_DIRECT flag on the input file to make reads bypass any local caching.
 .El
 .It Cm iseek Ns = Ns Ar n
 Seek on the input file
@@ -143,7 +145,7 @@ the output file is truncated at that point.
 Where
 .Cm value
 is one of the symbols from the following list.
-.Bl -tag -width "fsync"
+.Bl -tag -width "direct"
 .It Cm fsync
 Set the O_FSYNC flag on the output file to make writes synchronous.
 .It Cm sync
@@ -151,6 +153,8 @@ Set the O_SYNC flag on the output file to make writes 
 This is synonymous with the
 .Cm fsync
 value.
+.It Cm direct
+Set the O_DIRECT flag on the output file to make writes bypass any local caching.
 .El
 .It Cm oseek Ns = Ns Ar n
 Seek on the output file

Modified: stable/12/bin/dd/dd.c
==============================================================================
--- stable/12/bin/dd/dd.c	Wed Jul  1 08:23:57 2020	(r362829)
+++ stable/12/bin/dd/dd.c	Wed Jul  1 09:28:00 2020	(r362830)
@@ -143,7 +143,7 @@ static void
 setup(void)
 {
 	u_int cnt;
-	int oflags;
+	int iflags, oflags;
 	cap_rights_t rights;
 	unsigned long cmds[] = { FIODTYPE, MTIOCTOP };
 
@@ -151,7 +151,10 @@ setup(void)
 		in.name = "stdin";
 		in.fd = STDIN_FILENO;
 	} else {
-		in.fd = open(in.name, O_RDONLY, 0);
+		iflags = 0;
+		if (ddflags & C_IDIRECT)
+			iflags |= O_DIRECT;
+		in.fd = open(in.name, O_RDONLY | iflags, 0);
 		if (in.fd == -1)
 			err(1, "%s", in.name);
 	}
@@ -186,6 +189,8 @@ setup(void)
 			oflags |= O_TRUNC;
 		if (ddflags & C_OFSYNC)
 			oflags |= O_FSYNC;
+		if (ddflags & C_ODIRECT)
+			oflags |= O_DIRECT;
 		out.fd = open(out.name, O_RDWR | oflags, DEFFILEMODE);
 		/*
 		 * May not have read access, so try again with write only.

Modified: stable/12/bin/dd/dd.h
==============================================================================
--- stable/12/bin/dd/dd.h	Wed Jul  1 08:23:57 2020	(r362829)
+++ stable/12/bin/dd/dd.h	Wed Jul  1 09:28:00 2020	(r362830)
@@ -105,6 +105,8 @@ typedef struct {
 #define	C_FDATASYNC	0x0000000100000000ULL
 #define	C_OFSYNC	0x0000000200000000ULL
 #define	C_IFULLBLOCK	0x0000000400000000ULL
+#define	C_IDIRECT	0x0000000800000000ULL
+#define	C_ODIRECT	0x0000001000000000ULL
 
 #define	C_PARITY	(C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
 


More information about the svn-src-all mailing list