forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbd_server.cpp
120 lines (98 loc) · 3.53 KB
/
nbd_server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "nbd_server.h"
#include <cloud/blockstore/libs/client/session.h>
#include <cloud/blockstore/libs/diagnostics/server_stats.h>
#include <cloud/blockstore/libs/endpoints/endpoint_listener.h>
#include <cloud/blockstore/libs/nbd/error_handler.h>
#include <cloud/blockstore/libs/nbd/server.h>
#include <cloud/blockstore/libs/nbd/server_handler.h>
#include <cloud/blockstore/libs/service/device_handler.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
namespace NCloud::NBlockStore::NServer {
using namespace NMonitoring;
using namespace NThreading;
namespace {
////////////////////////////////////////////////////////////////////////////////
class TNbdEndpointListener final
: public IEndpointListener
{
private:
const NBD::IServerPtr Server;
const ILoggingServicePtr Logging;
const IServerStatsPtr ServerStats;
public:
TNbdEndpointListener(
NBD::IServerPtr server,
ILoggingServicePtr logging,
IServerStatsPtr serverStats)
: Server(std::move(server))
, Logging(std::move(logging))
, ServerStats(std::move(serverStats))
{}
TFuture<NProto::TError> StartEndpoint(
const NProto::TStartEndpointRequest& request,
const NProto::TVolume& volume,
NClient::ISessionPtr session) override
{
NBD::TStorageOptions options;
options.DiskId = request.GetDiskId();
options.ClientId = request.GetClientId();
options.BlockSize = volume.GetBlockSize();
options.BlocksCount = volume.GetBlocksCount();
options.UnalignedRequestsDisabled = request.GetUnalignedRequestsDisabled();
options.SendMinBlockSize = request.GetSendNbdMinBlockSize();
auto requestFactory = CreateServerHandlerFactory(
CreateDefaultDeviceHandlerFactory(),
Logging,
std::move(session),
ServerStats,
NBD::CreateErrorHandlerStub(),
options);
auto address = TNetworkAddress(
TUnixSocketPath(request.GetUnixSocketPath()));
return Server->StartEndpoint(address, std::move(requestFactory));
}
TFuture<NProto::TError> AlterEndpoint(
const NProto::TStartEndpointRequest& request,
const NProto::TVolume& volume,
NClient::ISessionPtr session) override
{
Y_UNUSED(request, volume, session);
return MakeFuture<NProto::TError>();
}
TFuture<NProto::TError> StopEndpoint(const TString& socketPath) override
{
auto address = TNetworkAddress(TUnixSocketPath(socketPath));
return Server->StopEndpoint(address);
}
NProto::TError RefreshEndpoint(
const TString& socketPath,
const NProto::TVolume& volume) override
{
Y_UNUSED(socketPath);
Y_UNUSED(volume);
return {};
}
TFuture<NProto::TError> SwitchEndpoint(
const NProto::TStartEndpointRequest& request,
const NProto::TVolume& volume,
NClient::ISessionPtr session) override
{
Y_UNUSED(request);
Y_UNUSED(volume);
Y_UNUSED(session);
return MakeFuture(MakeError(E_NOT_IMPLEMENTED));
}
};
} // namespace
////////////////////////////////////////////////////////////////////////////////
IEndpointListenerPtr CreateNbdEndpointListener(
NBD::IServerPtr server,
ILoggingServicePtr logging,
IServerStatsPtr serverStats)
{
return std::make_shared<TNbdEndpointListener>(
std::move(server),
std::move(logging),
std::move(serverStats));
}
} // namespace NCloud::NBlockStore::NServer