From 7f7e4ffb6259103c90bc82e3e823596854a3b4ac Mon Sep 17 00:00:00 2001
From: Drew Fisher <zarvox@google.com>
Date: Mon, 6 May 2019 20:56:26 +0000
Subject: [PATCH] [fshost] Revert log when encountering unknown disk format

This reverts commit 396d21629ae626cd0d85ae979943bc9d39ca9e8b.

Reason for revert: we've gotten enough information on the bug that we were trying to investigate with this (DNO-492) that we no longer need this logging, and the excessive logging is causing people grief.

Original change's description:
> [fshost] log when encountering unknown disk format
>
> DNO-492 #comment
> Tests: paved an Astro, saw this log reasonable content
> for the empty volumes before formatted, did not log after paved.
>
> Change-Id: I07a80dc2a826e80ba5c12ca5901d460a65266153

TBR=smklein@google.com,abarth@google.com,zarvox@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Ifc296d88a00a9898cebd49980ffcfa409d45b0d0
---
 .../core/devmgr/fshost/block-device.cpp       |  8 ++---
 .../core/devmgr/fshost/block-watcher.cpp      |  9 +-----
 zircon/system/ulib/fs-management/BUILD.gn     |  1 -
 .../include/fs-management/mount.h             |  1 -
 zircon/system/ulib/fs-management/mount.cpp    | 29 +------------------
 5 files changed, 6 insertions(+), 42 deletions(-)

diff --git a/zircon/system/core/devmgr/fshost/block-device.cpp b/zircon/system/core/devmgr/fshost/block-device.cpp
index 3881a0ac293..c5e64c85fc9 100644
--- a/zircon/system/core/devmgr/fshost/block-device.cpp
+++ b/zircon/system/core/devmgr/fshost/block-device.cpp
@@ -86,7 +86,7 @@ int UnsealZxcryptThread(void* arg) {
     zx_status_t rc;
     std::unique_ptr<zxcrypt::FdioVolume> zxcrypt_volume;
     if ((rc = zxcrypt::FdioVolume::Init(std::move(fd), &zxcrypt_volume)) != ZX_OK) {
-        printf("fshost: couldn't open zxcrypt fdio volume\n");
+        printf("fshost: couldn't open zxcrypt fdio volume");
         return ZX_OK;
     }
 
@@ -94,14 +94,14 @@ int UnsealZxcryptThread(void* arg) {
     if ((rc = zxcrypt_volume->OpenManager(zx::sec(2),
                                           zxcrypt_volume_manager_chan.reset_and_get_address())) !=
         ZX_OK) {
-        printf("fshost: couldn't open zxcrypt manager device\n");
+        printf("fshost: couldn't open zxcrypt manager device");
         return 0;
     }
 
     zxcrypt::FdioVolumeManager zxcrypt_volume_manager(std::move(zxcrypt_volume_manager_chan));
     uint8_t slot = 0;
     if ((rc = zxcrypt_volume_manager.UnsealWithDeviceKey(slot)) != ZX_OK) {
-        printf("fshost: couldn't unseal zxcrypt manager device\n");
+        printf("fshost: couldn't unseal zxcrypt manager device");
         return 0;
     }
 
@@ -112,7 +112,7 @@ int UnsealZxcryptThread(void* arg) {
 
 BlockDevice::BlockDevice(FilesystemMounter* mounter, fbl::unique_fd fd)
     : mounter_(mounter), fd_(std::move(fd)),
-      format_(detect_disk_format_log_unknown(fd_.get())) {}
+      format_(detect_disk_format(fd_.get())) {}
 
 disk_format_t BlockDevice::GetFormat() {
     return format_;
diff --git a/zircon/system/core/devmgr/fshost/block-watcher.cpp b/zircon/system/core/devmgr/fshost/block-watcher.cpp
index fab3a74d41f..ac5b37547bd 100644
--- a/zircon/system/core/devmgr/fshost/block-watcher.cpp
+++ b/zircon/system/core/devmgr/fshost/block-watcher.cpp
@@ -60,14 +60,7 @@ zx_status_t BlockDeviceCallback(int dirfd, int event, const char* name, void* co
 
     auto mounter = static_cast<FilesystemMounter*>(cookie);
     BlockDevice device(mounter, std::move(device_fd));
-    zx_status_t rc = device.Add();
-    if (rc != ZX_OK) {
-        // This callback has to return ZX_OK for resiliency reasons, or we'll
-        // stop getting subsequent callbacks, but we should log loudly that we
-        // tried to do something and that failed.
-        fprintf(stderr, "fshost: (%s/%s) failed: %s\n", kPathBlockDeviceRoot,
-                name, zx_status_get_string(rc));
-    }
+    device.Add();
     return ZX_OK;
 }
 
diff --git a/zircon/system/ulib/fs-management/BUILD.gn b/zircon/system/ulib/fs-management/BUILD.gn
index 788d03cc92c..c2b50087fcd 100644
--- a/zircon/system/ulib/fs-management/BUILD.gn
+++ b/zircon/system/ulib/fs-management/BUILD.gn
@@ -29,7 +29,6 @@ library("fs-management") {
     "$zx/system/ulib/fvm",
     "$zx/system/ulib/fzl",
     "$zx/system/ulib/gpt",
-    "$zx/system/ulib/pretty",
     "$zx/system/ulib/zx",
     "$zx/system/ulib/zxcpp",
     "$zx/third_party/ulib/uboringssl",
diff --git a/zircon/system/ulib/fs-management/include/fs-management/mount.h b/zircon/system/ulib/fs-management/include/fs-management/mount.h
index 081483610a0..79fecda40fa 100644
--- a/zircon/system/ulib/fs-management/include/fs-management/mount.h
+++ b/zircon/system/ulib/fs-management/include/fs-management/mount.h
@@ -73,7 +73,6 @@ static const uint8_t zxcrypt_magic[16] = {
 };
 
 disk_format_t detect_disk_format(int fd);
-disk_format_t detect_disk_format_log_unknown(int fd);
 
 typedef struct mount_options {
     bool readonly;
diff --git a/zircon/system/ulib/fs-management/mount.cpp b/zircon/system/ulib/fs-management/mount.cpp
index 2e24a44295f..7666424df98 100644
--- a/zircon/system/ulib/fs-management/mount.cpp
+++ b/zircon/system/ulib/fs-management/mount.cpp
@@ -25,7 +25,6 @@
 #include <lib/fdio/vfs.h>
 #include <lib/fzl/fdio.h>
 #include <lib/zx/channel.h>
-#include <pretty/hexdump.h>
 #include <zircon/compiler.h>
 #include <zircon/device/block.h>
 #include <zircon/device/vfs.h>
@@ -272,12 +271,7 @@ const fsck_options_t default_fsck_options = {
     .apply_journal = false,
 };
 
-enum DiskFormatLogVerbosity {
-    Silent,
-    Verbose,
-};
-
-disk_format_t detect_disk_format_impl(int fd, DiskFormatLogVerbosity verbosity) {
+disk_format_t detect_disk_format(int fd) {
     if (lseek(fd, 0, SEEK_SET) != 0) {
         fprintf(stderr, "detect_disk_format: Cannot seek to start of device.\n");
         return DISK_FORMAT_UNKNOWN;
@@ -333,30 +327,9 @@ disk_format_t detect_disk_format_impl(int fd, DiskFormatLogVerbosity verbosity)
         }
         return DISK_FORMAT_MBR;
     }
-
-    if (verbosity == DiskFormatLogVerbosity::Verbose) {
-        // Log a hexdump of the bytes we looked at and didn't find any magic in.
-        fprintf(stderr, "detect_disk_format: did not recognize format.  Looked at:\n");
-        // fvm, zxcrypt, minfs, and blobfs have their magic bytes at the start
-        // of the block.
-        hexdump_very_ex(data, 16, 0, hexdump_stdio_printf, stderr);
-        // MBR is two bytes at offset 0x1fe, but print 16 just for consistency
-        hexdump_very_ex(data + 0x1f0, 16, 0x1f0, hexdump_stdio_printf, stderr);
-        // GPT magic is stored 512 bytes in, so it can coexist with MBR.
-        hexdump_very_ex(data + 0x200, 16, 0x200, hexdump_stdio_printf, stderr);
-    }
-
     return DISK_FORMAT_UNKNOWN;
 }
 
-disk_format_t detect_disk_format(int fd) {
-    return detect_disk_format_impl(fd, DiskFormatLogVerbosity::Silent);
-}
-
-disk_format_t detect_disk_format_log_unknown(int fd) {
-    return detect_disk_format_impl(fd, DiskFormatLogVerbosity::Verbose);
-}
-
 zx_status_t fmount(int device_fd, int mount_fd, disk_format_t df, const mount_options_t* options,
                    LaunchCallback cb) {
     Mounter mounter(mount_fd);
-- 
GitLab