From 34db8f5360992b1eb64640a92fb4dde3347a2b52 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 20 Mar 2023 09:13:19 +0100 Subject: [PATCH] Fix single-client handling in some block providers --- repos/os/src/drivers/nvme/main.cc | 5 ++++- repos/os/src/drivers/usb_block/main.cc | 2 -- repos/os/src/server/vfs_block/component.cc | 3 +++ repos/os/src/test/block_request_stream/main.cc | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/repos/os/src/drivers/nvme/main.cc b/repos/os/src/drivers/nvme/main.cc index 526aaaea7e..6f7416645b 100644 --- a/repos/os/src/drivers/nvme/main.cc +++ b/repos/os/src/drivers/nvme/main.cc @@ -2239,7 +2239,10 @@ struct Nvme::Main : Rpc_object> Capability session(Root::Session_args const &args, Affinity const &) override { - log("new block session: ", args.string()); + if (_block_session.constructed()) { + error("device is already in use"); + throw Service_denied(); + } Session_label const label { label_from_args(args.string()) }; Session_policy const policy { label, _config_rom.xml() }; diff --git a/repos/os/src/drivers/usb_block/main.cc b/repos/os/src/drivers/usb_block/main.cc index bf7f4c3423..1b7c5f8020 100644 --- a/repos/os/src/drivers/usb_block/main.cc +++ b/repos/os/src/drivers/usb_block/main.cc @@ -1034,8 +1034,6 @@ struct Usb::Main : Rpc_object> Genode::Session_capability session(Root::Session_args const &args, Affinity const &) override { - log("new block session: ", args.string()); - if (block_session.constructed()) { error("device is already in use"); throw Service_denied(); diff --git a/repos/os/src/server/vfs_block/component.cc b/repos/os/src/server/vfs_block/component.cc index 47e598c75a..0bf5508bed 100644 --- a/repos/os/src/server/vfs_block/component.cc +++ b/repos/os/src/server/vfs_block/component.cc @@ -383,6 +383,9 @@ struct Main : Rpc_object>, void close(Capability cap) override { + if (!_block_session.constructed()) + return; + if (cap == _block_session->cap()) { _block_session.destruct(); _block_file.destruct(); diff --git a/repos/os/src/test/block_request_stream/main.cc b/repos/os/src/test/block_request_stream/main.cc index fac20dc594..8233ae500b 100644 --- a/repos/os/src/test/block_request_stream/main.cc +++ b/repos/os/src/test/block_request_stream/main.cc @@ -212,7 +212,10 @@ struct Test::Main : Rpc_object > Capability session(Root::Session_args const &args, Affinity const &) override { - log("new block session: ", args.string()); + if (_block_session.constructed()) { + error("already in use"); + throw Service_denied(); + } size_t const ds_size = Arg_string::find_arg(args.string(), "tx_buf_size").ulong_value(0);