From 38a8f8cb98803572367639eb3bf0c460585acecb Mon Sep 17 00:00:00 2001
From: Ed Coyne <edcoyne@google.com>
Date: Mon, 29 Apr 2019 17:17:37 +0000
Subject: [PATCH] [dmctl] Remove virtcon channel from devcoordinator.

We have already switched to using a more direct path to create virtcons,
this removes the old path through /dev/misc/dmctl to the devcoordinator.

Issue: ZX-3403
Test: Booted frank, virtcon still works, this change is in essence a
no-op as nothing is using this code.

Change-Id: Icb0b77984a818a56f98d5099d111878e9f88ea57
---
 .../devcoordinator/coordinator-test.cpp       | 27 -------------------
 .../devmgr/devcoordinator/coordinator.cpp     | 10 -------
 .../core/devmgr/devcoordinator/coordinator.h  |  7 -----
 .../core/devmgr/devcoordinator/device.cpp     |  1 -
 zircon/system/core/devmgr/dmctl/dmctl.cpp     |  9 -------
 .../fuchsia-device-manager/coordinator.fidl   |  3 ---
 .../fidl/fuchsia-device-manager/dmctl.fidl    |  3 ---
 7 files changed, 60 deletions(-)

diff --git a/zircon/system/core/devmgr/devcoordinator/coordinator-test.cpp b/zircon/system/core/devmgr/devcoordinator/coordinator-test.cpp
index 2a29e6ea3c0..6ae84e01e91 100644
--- a/zircon/system/core/devmgr/devcoordinator/coordinator-test.cpp
+++ b/zircon/system/core/devmgr/devcoordinator/coordinator-test.cpp
@@ -45,33 +45,6 @@ TEST(CoordinatorTestCase, InitializeCoreDevices) {
     ASSERT_EQ(ZX_OK, status);
 }
 
-TEST(CoordinatorTestCase, OpenVirtcon) {
-    devmgr::Coordinator coordinator(DefaultConfig(nullptr));
-
-    zx::channel client, server;
-    zx_status_t status = zx::channel::create(0, &client, &server);
-    ASSERT_EQ(ZX_OK, status);
-    coordinator.set_virtcon_channel(std::move(client));
-
-    zx::channel sender, receiver;
-    status = zx::channel::create(0, &sender, &receiver);
-    ASSERT_EQ(ZX_OK, status);
-    status = coordinator.DmOpenVirtcon(std::move(sender));
-    ASSERT_EQ(ZX_OK, status);
-
-    zx_signals_t signals;
-    status = server.wait_one(ZX_CHANNEL_READABLE, zx::time::infinite(), &signals);
-    ASSERT_EQ(ZX_OK, status);
-    ASSERT_TRUE(signals & ZX_CHANNEL_READABLE);
-
-    zx::channel sender_channel;
-    uint32_t actual_handles;
-    status = server.read(0, nullptr, sender_channel.reset_and_get_address(), 0, 1, nullptr, &actual_handles);
-    ASSERT_EQ(ZX_OK, status);
-    ASSERT_EQ(1, actual_handles);
-    ASSERT_TRUE(sender_channel.is_valid());
-}
-
 TEST(CoordinatorTestCase, DumpState) {
     devmgr::Coordinator coordinator(DefaultConfig(nullptr));
 
diff --git a/zircon/system/core/devmgr/devcoordinator/coordinator.cpp b/zircon/system/core/devmgr/devcoordinator/coordinator.cpp
index ef4b167b659..180f3937429 100644
--- a/zircon/system/core/devmgr/devcoordinator/coordinator.cpp
+++ b/zircon/system/core/devmgr/devcoordinator/coordinator.cpp
@@ -132,11 +132,6 @@ zx_status_t Coordinator::InitializeCoreDevices(const char* sys_device_driver) {
     return ZX_OK;
 }
 
-zx_status_t Coordinator::DmOpenVirtcon(zx::channel virtcon_receiver) const {
-    zx_handle_t raw_virtcon_receiver = virtcon_receiver.release();
-    return virtcon_channel_.write(0, nullptr, 0, &raw_virtcon_receiver, 1);
-}
-
 zx_status_t Coordinator::DmCommand(size_t len, const char* cmd) {
     if (InSuspend()) {
         log(ERROR, "devcoordinator: rpc: dm-command \"%.*s\" forbidden in suspend\n",
@@ -990,11 +985,6 @@ zx_status_t fidl_DmCommand(void* ctx, zx_handle_t raw_log_socket, const char* co
     return fuchsia_device_manager_CoordinatorDmCommand_reply(txn, status);
 }
 
-zx_status_t fidl_DmOpenVirtcon(void* ctx, zx_handle_t raw_vc_receiver) {
-    auto dev = fbl::WrapRefPtr(static_cast<Device*>(ctx));
-    return dev->coordinator->DmOpenVirtcon(zx::channel(raw_vc_receiver));
-}
-
 zx_status_t fidl_DmMexec(void* ctx, zx_handle_t raw_kernel, zx_handle_t raw_bootdata) {
     zx_status_t st;
     constexpr size_t kBootdataExtraSz = PAGE_SIZE * 4;
diff --git a/zircon/system/core/devmgr/devcoordinator/coordinator.h b/zircon/system/core/devmgr/devcoordinator/coordinator.h
index 680fa2b5aa5..12158756f8e 100644
--- a/zircon/system/core/devmgr/devcoordinator/coordinator.h
+++ b/zircon/system/core/devmgr/devcoordinator/coordinator.h
@@ -185,7 +185,6 @@ public:
                                    size_t components_count, uint32_t coresident_device_index);
 
     zx_status_t DmCommand(size_t len, const char* cmd);
-    zx_status_t DmOpenVirtcon(zx::channel virtcon_receiver) const;
     void DmMexec(zx::vmo kernel, zx::vmo bootdata);
 
     void HandleNewDevice(const fbl::RefPtr<Device>& dev);
@@ -209,9 +208,6 @@ public:
     void set_loader_service(DevhostLoaderService* loader_service) {
         loader_service_ = loader_service;
     }
-    void set_virtcon_channel(zx::channel virtcon_channel) {
-        virtcon_channel_ = std::move(virtcon_channel);
-    }
     void set_dmctl_socket(zx::socket dmctl_socket) { dmctl_socket_ = std::move(dmctl_socket); }
 
     fbl::DoublyLinkedList<Driver*, Driver::Node>& drivers() { return drivers_; }
@@ -252,8 +248,6 @@ private:
     bool system_loaded_ = false;
     DevhostLoaderService* loader_service_ = nullptr;
 
-    // Channel for creating new virtual consoles.
-    zx::channel virtcon_channel_;
     // This socket is used by DmPrintf for output, and DmPrintf can be called in
     // the context of a const member function, therefore it is also const. Given
     // that, we must make dmctl_socket_ mutable.
@@ -326,7 +320,6 @@ extern const char* kComponentDriverPath;
 
 zx_status_t fidl_DmCommand(void* ctx, zx_handle_t raw_log_socket, const char* command_data,
                            size_t command_size, fidl_txn_t* txn);
-zx_status_t fidl_DmOpenVirtcon(void* ctx, zx_handle_t raw_vc_receiver);
 zx_status_t fidl_DmMexec(void* ctx, zx_handle_t raw_kernel, zx_handle_t raw_bootdata);
 zx_status_t fidl_DirectoryWatch(void* ctx, uint32_t mask, uint32_t options,
                                 zx_handle_t raw_watcher, fidl_txn_t* txn);
diff --git a/zircon/system/core/devmgr/devcoordinator/device.cpp b/zircon/system/core/devmgr/devcoordinator/device.cpp
index 093409ded04..abac8991e19 100644
--- a/zircon/system/core/devmgr/devcoordinator/device.cpp
+++ b/zircon/system/core/devmgr/devcoordinator/device.cpp
@@ -322,7 +322,6 @@ static const fuchsia_device_manager_Coordinator_ops_t fidl_ops = {
     .AddCompositeDevice = fidl_AddCompositeDevice,
 
     .DmCommand = fidl_DmCommand,
-    .DmOpenVirtcon = fidl_DmOpenVirtcon,
     .DmMexec = fidl_DmMexec,
     .DirectoryWatch = fidl_DirectoryWatch,
 };
diff --git a/zircon/system/core/devmgr/dmctl/dmctl.cpp b/zircon/system/core/devmgr/dmctl/dmctl.cpp
index 3172c53d6ef..97263d83a5d 100644
--- a/zircon/system/core/devmgr/dmctl/dmctl.cpp
+++ b/zircon/system/core/devmgr/dmctl/dmctl.cpp
@@ -78,14 +78,6 @@ static zx_status_t fidl_ExecuteCommand(void* ctx, zx_handle_t raw_log_socket,
     return fuchsia_device_manager_ExternalControllerExecuteCommand_reply(txn, status);
 }
 
-static zx_status_t fidl_OpenVirtcon(void* ctx, zx_handle_t raw_vc_receiver) {
-    zx::channel vc_receiver(raw_vc_receiver);
-    auto zxdev = static_cast<zx_device_t*>(ctx);
-    const zx::channel& rpc = *zxdev->rpc;
-
-    return fuchsia_device_manager_CoordinatorDmOpenVirtcon(rpc.get(), vc_receiver.release());
-}
-
 static zx_status_t fidl_PerformMexec(void* ctx, zx_handle_t raw_kernel, zx_handle_t raw_bootdata) {
     zx::vmo kernel(raw_kernel);
     zx::vmo bootdata(raw_bootdata);
@@ -98,7 +90,6 @@ static zx_status_t fidl_PerformMexec(void* ctx, zx_handle_t raw_kernel, zx_handl
 
 static fuchsia_device_manager_ExternalController_ops_t fidl_ops = {
     .ExecuteCommand = fidl_ExecuteCommand,
-    .OpenVirtcon = fidl_OpenVirtcon,
     .PerformMexec = fidl_PerformMexec,
 };
 
diff --git a/zircon/system/fidl/fuchsia-device-manager/coordinator.fidl b/zircon/system/fidl/fuchsia-device-manager/coordinator.fidl
index dd7b9dc6dad..9944d8ff3d9 100644
--- a/zircon/system/fidl/fuchsia-device-manager/coordinator.fidl
+++ b/zircon/system/fidl/fuchsia-device-manager/coordinator.fidl
@@ -215,9 +215,6 @@ protocol Coordinator {
     DmCommand(handle<socket>? log_socket, string:COMMAND_MAX? command)
         -> (zx.status status);
 
-    /// Opens a new virtual console and transfers a handle to it over |vc_receiver|.
-    DmOpenVirtcon(handle<channel> vc_receiver);
-
     /// Perform an mexec with the given kernel and bootdata.
     /// See ZX-2069 for the thoughts on deprecating mexec.
     DmMexec(handle<vmo> kernel, handle<vmo> bootdata);
diff --git a/zircon/system/fidl/fuchsia-device-manager/dmctl.fidl b/zircon/system/fidl/fuchsia-device-manager/dmctl.fidl
index f81c5260717..9d4df1ee2ef 100644
--- a/zircon/system/fidl/fuchsia-device-manager/dmctl.fidl
+++ b/zircon/system/fidl/fuchsia-device-manager/dmctl.fidl
@@ -16,9 +16,6 @@ protocol ExternalController {
     ExecuteCommand(handle<socket>? log_socket, string:COMMAND_MAX? command)
         -> (zx.status status);
 
-    /// Opens a new virtual console and transfers a handle to it over |vc_receiver|.
-    OpenVirtcon(handle<channel> vc_receiver);
-
     /// Perform an mexec with the given kernel and bootdata.
     /// See ZX-2069 for the thoughts on deprecating mexec.
     PerformMexec(handle<vmo> kernel, handle<vmo> bootdata);
-- 
GitLab