Module Name:    src
Committed By:   jdolecek
Date:           Wed Apr  5 18:34:56 UTC 2017

Modified Files:
        src/sys/dev: ccd.c
        src/sys/sys: dkio.h

Log Message:
introduce DKCACHE_COMBINE() macro - it combines the flags in a way that
all common flags are retained, and flags regarding write cache are preserved
if either of the devices has it; callers can thus rely on write cache not
being possible to be used when both flags are missing

use the new macro for ccd(4)


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/dev/ccd.c
cvs rdiff -u -r1.22 -r1.23 src/sys/sys/dkio.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ccd.c
diff -u src/sys/dev/ccd.c:1.170 src/sys/dev/ccd.c:1.171
--- src/sys/dev/ccd.c:1.170	Thu Mar 30 16:50:32 2017
+++ src/sys/dev/ccd.c	Wed Apr  5 18:34:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ccd.c,v 1.170 2017/03/30 16:50:32 jdolecek Exp $	*/
+/*	$NetBSD: ccd.c,v 1.171 2017/04/05 18:34:56 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.170 2017/03/30 16:50:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.171 2017/04/05 18:34:56 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -1432,7 +1432,7 @@ ccdioctl(dev_t dev, u_long cmd, void *da
 			if (i == 0)
 				dkcache = j;
 			else
-				dkcache &= j;
+				dkcache = DKCACHE_COMBINE(dkcache, j);
 		}
 
 		*((int *)data) = dkcache;

Index: src/sys/sys/dkio.h
diff -u src/sys/sys/dkio.h:1.22 src/sys/sys/dkio.h:1.23
--- src/sys/sys/dkio.h:1.22	Tue Dec  8 20:36:15 2015
+++ src/sys/sys/dkio.h	Wed Apr  5 18:34:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: dkio.h,v 1.22 2015/12/08 20:36:15 christos Exp $	*/
+/*	$NetBSD: dkio.h,v 1.23 2017/04/05 18:34:56 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1987, 1988, 1993
@@ -86,6 +86,15 @@
 #define	DKCACHE_WCHANGE	0x000200 /* write enable is changeable */
 #define	DKCACHE_SAVE	0x010000 /* cache parameters are savable/save them */
 
+/*
+ * Combine disk cache flags of two drives to get common cache capabilities.
+ * All common flags are retained. Besides this, if one of the disks
+ * has a write cache enabled or changeable, propagate those flags into result,
+ * even if it's not shared, to indicate that write cache is present.
+ */
+#define DKCACHE_COMBINE(a, b) \
+	(((a) & (b)) | (((a) | (b)) & (DKCACHE_WRITE|DKCACHE_WCHANGE)))
+
 		/* sync disk cache */
 #define	DIOCCACHESYNC	_IOW('d', 118, int)	/* sync cache (force?) */
 

Reply via email to