Skip to content

Commit

Permalink
Revert "issue-2270: return error if nbd device name is missing (#2375)…
Browse files Browse the repository at this point in the history
…" (#2436)

This reverts commit b6734bc.
  • Loading branch information
antonmyagkov authored Nov 7, 2024
1 parent e391024 commit 58d4901
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cloud/blockstore/libs/endpoints/endpoint_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ TResultOrError<NBD::IDevicePtr> TEndpointManager::StartNbdDevice(
}

if (!request->HasNbdDeviceFile() || !request->GetNbdDeviceFile()) {
return MakeError(E_ARGUMENT, "NBD device file is missing");
return NBD::CreateDeviceStub();
}

if (!restoring) {
Expand Down
30 changes: 12 additions & 18 deletions cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,9 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)

Y_UNIT_TEST(ShouldHandleListEndpoints)
{
TString nbdDevPrefix = CreateGuidAsString() + "_nbd";
TString nbdDevice = nbdDevPrefix + "0";
TFsPath(nbdDevice).Touch();
Y_DEFER {
TFsPath(nbdDevice).DeleteIfExists();
};

TBootstrap bootstrap;
bootstrap.NbdDeviceFactory = std::make_shared<TTestDeviceFactory>();
TMap<TString, NProto::TMountVolumeRequest> mountedVolumes;
bootstrap.Service = CreateTestService(mountedVolumes);
bootstrap.Options.NbdDevicePrefix = nbdDevPrefix;

bootstrap.EndpointListeners = {
{ NProto::IPC_GRPC, std::make_shared<TTestEndpointListener>() },
Expand Down Expand Up @@ -688,8 +679,6 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)
request2.SetDiskId("testDiskId2");
request2.SetClientId(TestClientId);
request2.SetIpcType(NProto::IPC_NBD);
request2.SetNbdDeviceFile(nbdDevice);
request2.SetPersistent(true);

{
auto future = StartEndpoint(*manager, request1);
Expand All @@ -700,7 +689,7 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)
{
auto future = StartEndpoint(*manager, request2);
auto response = future.GetValue(TDuration::Seconds(5));
UNIT_ASSERT_C(!HasError(response), response.GetError());
UNIT_ASSERT(!HasError(response));
}

{
Expand Down Expand Up @@ -1504,19 +1493,24 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)
request.SetNbdDeviceFile("");
auto future = StartEndpoint(*manager, request);
auto response = future.GetValue(TDuration::Seconds(5));
UNIT_ASSERT_C(HasError(response), response.GetError());
UNIT_ASSERT_VALUES_EQUAL_C(
E_ARGUMENT,
response.GetError().GetCode(),
response.GetError());
UNIT_ASSERT_C(!HasError(response), response.GetError());
}

{
auto request = baseRequest;
request.SetNbdDeviceFile("");
auto future = StartEndpoint(*manager, request);
auto response = future.GetValue(TDuration::Seconds(5));
UNIT_ASSERT(response.GetError().GetCode() == S_ALREADY);
UNIT_ASSERT_VALUES_EQUAL("", response.GetNbdDeviceFile());
}

{
auto request = baseRequest;
request.SetUseFreeNbdDeviceFile(true);
auto future = StartEndpoint(*manager, request);
auto response = future.GetValue(TDuration::Seconds(5));
UNIT_ASSERT_C(!HasError(response), response.GetError());
UNIT_ASSERT(response.GetError().GetCode() == E_INVALID_STATE);
}

{
Expand Down
26 changes: 21 additions & 5 deletions cloud/blockstore/tools/csi_driver/internal/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,11 @@ func (s *nodeService) nodePublishDiskAsFilesystemDeprecated(
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

logVolume(diskId, "endpoint started with device: %q", resp.NbdDeviceFile)
if resp.NbdDeviceFile == "" {
return fmt.Errorf("NbdDeviceFile shouldn't be empty")
}

logVolume(req.VolumeId, "endpoint started with device: %q", resp.NbdDeviceFile)

mnt := req.VolumeCapability.GetMount()

Expand Down Expand Up @@ -750,7 +754,11 @@ func (s *nodeService) nodeStageDiskAsFilesystem(
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

logVolume(diskId, "endpoint started with device: %q", resp.NbdDeviceFile)
if resp.NbdDeviceFile == "" {
return fmt.Errorf("NbdDeviceFile shouldn't be empty")
}

logVolume(req.VolumeId, "endpoint started with device: %q", resp.NbdDeviceFile)

mnt := req.VolumeCapability.GetMount()

Expand Down Expand Up @@ -823,7 +831,11 @@ func (s *nodeService) nodeStageDiskAsBlockDevice(
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

logVolume(diskId, "endpoint started with device: %q", resp.NbdDeviceFile)
if resp.NbdDeviceFile == "" {
return fmt.Errorf("NbdDeviceFile shouldn't be empty")
}

logVolume(req.VolumeId, "endpoint started with device: %q", resp.NbdDeviceFile)

devicePath := filepath.Join(req.StagingTargetPath, diskId)
return s.mountBlockDevice(diskId, resp.NbdDeviceFile, devicePath, false)
Expand All @@ -839,8 +851,12 @@ func (s *nodeService) nodePublishDiskAsBlockDeviceDeprecated(
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

logVolume(diskId, "endpoint started with device: %q", resp.NbdDeviceFile)
return s.mountBlockDevice(diskId, resp.NbdDeviceFile, req.TargetPath, req.Readonly)
if resp.NbdDeviceFile == "" {
return fmt.Errorf("NbdDeviceFile shouldn't be empty")
}

logVolume(req.VolumeId, "endpoint started with device: %q", resp.NbdDeviceFile)
return s.mountBlockDevice(req.VolumeId, resp.NbdDeviceFile, req.TargetPath, req.Readonly)
}

func (s *nodeService) nodePublishDiskAsBlockDevice(
Expand Down

0 comments on commit 58d4901

Please sign in to comment.