]> granicus.if.org Git - zfs/commitdiff
Fixes for SNPRINTF_BLKPTR with encrypted BP's
authorMatthew Ahrens <mahrens@delphix.com>
Fri, 6 Apr 2018 20:30:26 +0000 (13:30 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 6 Apr 2018 20:30:26 +0000 (13:30 -0700)
mdb doesn't have dmu_ot[], so we need a different mechanism for its
SNPRINTF_BLKPTR() to determine if the BP is encrypted vs authenticated.

Additionally, since it already relies on BP_IS_ENCRYPTED (etc),
SNPRINTF_BLKPTR might as well figure out the "crypt_type" on its own,
rather than making the caller do so.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #7390

include/sys/dmu.h
include/sys/spa.h
module/zfs/spa_misc.c

index 4d805b6d77c892ee757e4de136e8cd3054f5e301..027d3d9fc02fb0e46754ed5ae382cbf627c98da4 100644 (file)
@@ -119,13 +119,22 @@ typedef enum dmu_object_byteswap {
        ((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \
        (ot) < DMU_OT_NUMTYPES)
 
+/*
+ * MDB doesn't have dmu_ot; it defines these macros itself.
+ */
+#ifndef ZFS_MDB
+#define        DMU_OT_IS_METADATA_IMPL(ot) (dmu_ot[ot].ot_metadata)
+#define        DMU_OT_IS_ENCRYPTED_IMPL(ot) (dmu_ot[ot].ot_encrypt)
+#define        DMU_OT_BYTESWAP_IMPL(ot) (dmu_ot[ot].ot_byteswap)
+#endif
+
 #define        DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \
        ((ot) & DMU_OT_METADATA) : \
-       dmu_ot[(int)(ot)].ot_metadata)
+       DMU_OT_IS_METADATA_IMPL(ot))
 
 #define        DMU_OT_IS_ENCRYPTED(ot) (((ot) & DMU_OT_NEWTYPE) ? \
        ((ot) & DMU_OT_ENCRYPTED) : \
-       dmu_ot[(int)(ot)].ot_encrypt)
+       DMU_OT_IS_ENCRYPTED_IMPL(ot))
 
 /*
  * These object types use bp_fill != 1 for their L0 bp's. Therefore they can't
@@ -137,7 +146,7 @@ typedef enum dmu_object_byteswap {
 
 #define        DMU_OT_BYTESWAP(ot) (((ot) & DMU_OT_NEWTYPE) ? \
        ((ot) & DMU_OT_BYTESWAP_MASK) : \
-       dmu_ot[(int)(ot)].ot_byteswap)
+       DMU_OT_BYTESWAP_IMPL(ot))
 
 typedef enum dmu_object_type {
        DMU_OT_NONE,
index 4a1b1410f7446439775fac829d9627eab67c40a9..f93354c7881a49e0f3e5af3862ee4c2c1c609158 100644 (file)
@@ -631,14 +631,25 @@ _NOTE(CONSTCOND) } while (0)
  * 'func' is either snprintf() or mdb_snprintf().
  * 'ws' (whitespace) can be ' ' for single-line format, '\n' for multi-line.
  */
-#define        SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, crypt_type, \
-       compress) \
+#define        SNPRINTF_BLKPTR(func, ws, buf, size, bp, type, checksum, compress) \
 {                                                                      \
        static const char *copyname[] =                                 \
            { "zero", "single", "double", "triple" };                   \
        int len = 0;                                                    \
        int copies = 0;                                                 \
-                                                                       \
+       const char *crypt_type;                                         \
+       if (bp != NULL) {                                               \
+               if (BP_IS_ENCRYPTED(bp)) {                              \
+                       crypt_type = "encrypted";                       \
+                       /* LINTED E_SUSPICIOUS_COMPARISON */            \
+               } else if (BP_IS_AUTHENTICATED(bp)) {                   \
+                       crypt_type = "authenticated";                   \
+               } else if (BP_HAS_INDIRECT_MAC_CKSUM(bp)) {             \
+                       crypt_type = "indirect-MAC";                    \
+               } else {                                                \
+                       crypt_type = "unencrypted";                     \
+               }                                                       \
+       }                                                               \
        if (bp == NULL) {                                               \
                len += func(buf + len, size - len, "<NULL>");           \
        } else if (BP_IS_HOLE(bp)) {                                    \
index 5e2af24e3b6d7240e5ba16c15373b6f9a4b6069f..17f8c16386192bdf7fc4c45bfd6aa5ce5cf73714 100644 (file)
@@ -1421,7 +1421,6 @@ snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp)
        char type[256];
        char *checksum = NULL;
        char *compress = NULL;
-       char *crypt_type = NULL;
 
        if (bp != NULL) {
                if (BP_GET_TYPE(bp) & DMU_OT_NEWTYPE) {
@@ -1435,15 +1434,6 @@ snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp)
                        (void) strlcpy(type, dmu_ot[BP_GET_TYPE(bp)].ot_name,
                            sizeof (type));
                }
-               if (BP_IS_ENCRYPTED(bp)) {
-                       crypt_type = "encrypted";
-               } else if (BP_IS_AUTHENTICATED(bp)) {
-                       crypt_type = "authenticated";
-               } else if (BP_HAS_INDIRECT_MAC_CKSUM(bp)) {
-                       crypt_type = "indirect-MAC";
-               } else {
-                       crypt_type = "unencrypted";
-               }
                if (!BP_IS_EMBEDDED(bp)) {
                        checksum =
                            zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name;
@@ -1452,7 +1442,7 @@ snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp)
        }
 
        SNPRINTF_BLKPTR(snprintf, ' ', buf, buflen, bp, type, checksum,
-           crypt_type, compress);
+           compress);
 }
 
 void