Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnl merge #1653

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/actions/prepare/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
sudo apt-get update
sudo apt-get install -y --no-install-recommends git wget gnupg lsb-release curl xz-utils tzdata cmake \
python3-dev python3-pip ninja-build antlr3 m4 libidn11-dev libaio1 libaio-dev make clang-14 lld-14 llvm-14 file \
distcc strace qemu-kvm qemu-utils dpkg-dev atop pigz pbzip2 xz-utils pixz libnl-3-dev libnl-genl-3-dev
distcc strace qemu-kvm qemu-utils dpkg-dev atop pigz pbzip2 xz-utils pixz
sudo apt-get remove -y unattended-upgrades
sudo pip3 install conan==1.59 pytest==7.1.3 pytest-timeout pytest-xdist==3.3.1 setproctitle==1.3.2 grpcio grpcio-tools \
PyHamcrest tornado xmltodict pyarrow boto3 moto[server] psutil yandexcloud==0.258.0 PyGithub==2.2.0 pyinstaller==5.13.2 \
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/github-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sudo apt-get install -y --no-install-recommends \
dpkg-dev docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin jq \
aria2 jq tree tmux atop awscli iftop htop \
pixz pigz pbzip2 xz-utils libnl-3-dev libnl-genl-3-dev
pixz pigz pbzip2 xz-utils
cat << EOF > /tmp/requirements.txt
conan==1.59
pytest==7.1.3
Expand Down
8 changes: 0 additions & 8 deletions build/sysincl/unsorted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,7 @@
- netdnet/dnetdb.h
- sys/ethernet.h
- sys/stream.h
- netlink/genl/genl.h
- netlink/genl/family.h
- netlink/genl/ctrl.h
- netlink/msg.h
- netlink/attr.h
# end libpcap files
# libnl3 files
- netlink/netlink.h
# end libnl3 files

# These includes are not used in autocheck builds, but might be necessary for
# some external builds with exotic settings
Expand Down
4 changes: 0 additions & 4 deletions cloud/blockstore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,11 @@ void TBootstrapBase::Init()
NBD::IDeviceFactoryPtr nbdDeviceFactory;

if (Configs->ServerConfig->GetNbdNetlink()) {
#ifdef NETLINK
nbdDeviceFactory = NBD::CreateNetlinkDeviceFactory(
Logging,
Configs->ServerConfig->GetNbdRequestTimeout(),
Configs->ServerConfig->GetNbdConnectionTimeout(),
true); // reconfigure
#else
STORAGE_ERROR("built without netlink support, falling back to ioctl");
#endif
}

if (!nbdDeviceFactory && EndpointProxyClient) {
Expand Down
6 changes: 0 additions & 6 deletions cloud/blockstore/libs/daemon/common/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,4 @@ PEERDIR(
library/cpp/sighandler
)

IF(NETLINK)
CFLAGS(
-DNETLINK
)
ENDIF()

END()
96 changes: 42 additions & 54 deletions cloud/blockstore/libs/endpoint_proxy/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,63 +576,51 @@ struct TServer: IEndpointProxyServer

if (HasError(startResult)) {
*response.MutableError() = std::move(startResult);
} else {
STORAGE_INFO(request.ShortDebugString().Quote()
<< " - Started NBD server endpoint");

ep.NbdDevicePath = request.GetNbdDevice();
if (ep.NbdDevicePath) {
if (Config.Netlink) {
#ifdef NETLINK
try {
ep.NbdDevice = NBD::CreateNetlinkDevice(
Logging,
*ep.ListenAddress,
request.GetNbdDevice(),
Config.NbdRequestTimeout,
TDuration::Days(1), // connection timeout
true); // reconfigure existing device

} catch (const std::exception& e) {
STORAGE_ERROR(request.ShortDebugString().Quote()
<< " - Unable to create netlink device: " << e.what()
<< ", falling back to ioctl");
}
#else
STORAGE_ERROR(request.ShortDebugString().Quote()
<< " - Built without netlink support"
<< ", falling back to ioctl");
#endif
}
// request timeout is mainly useful as a tool to retry requests
// in kernel, but since devices configured via ioctl can't be
// reconnected to, there is little reason to configure it
if (ep.NbdDevice == nullptr) {
ep.NbdDevice = NBD::CreateDevice(
Logging,
*ep.ListenAddress,
request.GetNbdDevice(),
TDuration::Days(1)); // request timeout
}
return;
}
response.SetInternalUnixSocketPath(ep.InternalUnixSocketPath);

auto start = ep.NbdDevice->Start();
const auto& value = start.GetValue();
if (HasError(value)) {
STORAGE_ERROR(request.ShortDebugString().Quote()
<< " - Unable to start nbd device: "
<< value.GetMessage());
} else {
STORAGE_INFO(request.ShortDebugString().Quote()
<< " - Started NBD device connection");
}
} else {
STORAGE_WARN(request.ShortDebugString().Quote()
<< " - NbdDevice missing - no nbd connection with the"
<< " kernel will be established");
}
STORAGE_INFO(request.ShortDebugString().Quote()
<< " - Started NBD server endpoint");

ep.NbdDevicePath = request.GetNbdDevice();
if (!ep.NbdDevicePath) {
STORAGE_WARN(request.ShortDebugString().Quote()
<< " - NbdDevice missing - no nbd connection with the"
<< " kernel will be established");
return;
}

if (Config.Netlink) {
ep.NbdDevice = NBD::CreateNetlinkDevice(
Logging,
*ep.ListenAddress,
request.GetNbdDevice(),
Config.NbdRequestTimeout,
TDuration::Days(1), // connection timeout
true); // reconfigure device if exists
} else {
// For netlink devices we have to balance request timeout between
// time it takes to fail request for good and resend it if socket
// is dead due to proxy restart. We can't configure ioctl device
// to use a fresh socket, so there is no point configuring it
ep.NbdDevice = NBD::CreateDevice(
Logging,
*ep.ListenAddress,
request.GetNbdDevice(),
TDuration::Days(1)); // request timeout
}

response.SetInternalUnixSocketPath(ep.InternalUnixSocketPath);
auto status = ep.NbdDevice->Start().ExtractValue();
if (HasError(status)) {
STORAGE_ERROR(request.ShortDebugString().Quote()
<< " - Unable to start nbd device: "
<< status.GetMessage());
return;
}

STORAGE_INFO(request.ShortDebugString().Quote()
<< " - Started NBD device connection");
}

void ProcessRequest(TStartRequestContext* requestContext)
Expand Down
6 changes: 0 additions & 6 deletions cloud/blockstore/libs/endpoint_proxy/server/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ PEERDIR(
contrib/libs/grpc
)

IF(NETLINK)
CFLAGS(
-DNETLINK
)
ENDIF()

END()

RECURSE_FOR_TESTS(ut)
16 changes: 2 additions & 14 deletions cloud/blockstore/libs/nbd/CMakeLists.linux-aarch64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(blockstore-libs-nbd)
target_link_libraries(blockstore-libs-nbd PUBLIC
contrib-libs-linux-headers
contrib-libs-cxxsupp
contrib-restricted-libnl-lib-nl-genl-3
yutil
blockstore-libs-client
blockstore-libs-common
Expand All @@ -29,23 +30,10 @@ target_sources(blockstore-libs-nbd PRIVATE
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/client.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/client_handler.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/limiter.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/netlink_device.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/protocol.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/server.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/server_handler.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/utils.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/device.cpp
)
if(DEFINED ENV{NETLINK})
target_sources(blockstore-libs-nbd PRIVATE
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/netlink_device.cpp
)
target_compile_options(blockstore-libs-nbd PUBLIC
-DNETLINK
-I/usr/include/libnl3
)
target_link_options(blockstore-libs-nbd PUBLIC
-L/usr/lib/x86_64-linux-gnu
-l:libnl-3.a
-l:libnl-genl-3.a
)
endif()
16 changes: 2 additions & 14 deletions cloud/blockstore/libs/nbd/CMakeLists.linux-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(blockstore-libs-nbd)
target_link_libraries(blockstore-libs-nbd PUBLIC
contrib-libs-linux-headers
contrib-libs-cxxsupp
contrib-restricted-libnl-lib-nl-genl-3
yutil
blockstore-libs-client
blockstore-libs-common
Expand All @@ -29,23 +30,10 @@ target_sources(blockstore-libs-nbd PRIVATE
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/client.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/client_handler.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/limiter.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/netlink_device.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/protocol.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/server.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/server_handler.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/utils.cpp
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/device.cpp
)
if(DEFINED ENV{NETLINK})
target_sources(blockstore-libs-nbd PRIVATE
${CMAKE_SOURCE_DIR}/cloud/blockstore/libs/nbd/netlink_device.cpp
)
target_compile_options(blockstore-libs-nbd PUBLIC
-DNETLINK
-I/usr/include/libnl3
)
target_link_options(blockstore-libs-nbd PUBLIC
-L/usr/lib/x86_64-linux-gnu
-l:libnl-3.a
-l:libnl-genl-3.a
)
endif()
84 changes: 39 additions & 45 deletions cloud/blockstore/libs/nbd/netlink_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,6 @@ class TNetlinkDevice final
, Reconfigure(reconfigure)
{
Log = Logging->CreateLog("BLOCKSTORE_NBD");

// accept /dev/nbd devices with a prefix other than /
// (e.g. inside a container)
const size_t pos = DeviceName.rfind(NBD_DEVICE_SUFFIX);
if (pos == TString::npos) {
throw TServiceError(E_ARGUMENT)
<< "unable to parse " << DeviceName << " device index";
}

try {
TMemoryInput stream(
DeviceName.data() + pos + NBD_DEVICE_SUFFIX.size());
stream >> DeviceIndex;
} catch (...) {
throw TServiceError(E_ARGUMENT)
<< "unable to parse " << DeviceName << " device index";
}
}

~TNetlinkDevice()
Expand All @@ -232,8 +215,16 @@ class TNetlinkDevice final

TFuture<NProto::TError> Start() override
{
ConnectSocket();
ConnectDevice();
try {
ParseIndex();
ConnectSocket();
ConnectDevice();
} catch (const TServiceError& e) {
StartResult.SetValue(MakeError(
e.GetCode(),
TStringBuilder() << "unable to configure " << DeviceName
<< ": " << e.what()));
}

// will be set asynchronously in Connect > HandleStatus > DoConnect
return StartResult.GetFuture();
Expand All @@ -254,10 +245,9 @@ class TNetlinkDevice final
DisconnectDevice();
DisconnectSocket();
StopResult.SetValue(MakeError(S_OK));

} catch (const TServiceError& e) {
StopResult.SetValue(MakeError(
E_FAIL,
e.GetCode(),
TStringBuilder() << "unable to disconnect " << DeviceName
<< ": " << e.what()));
}
Expand All @@ -266,6 +256,8 @@ class TNetlinkDevice final
}

private:
void ParseIndex();

void ConnectSocket();
void DisconnectSocket();

Expand All @@ -278,6 +270,16 @@ class TNetlinkDevice final

////////////////////////////////////////////////////////////////////////////////

void TNetlinkDevice::ParseIndex()
{
// accept dev/nbd* devices with prefix other than /
TStringBuf l, r;
TStringBuf(DeviceName).RSplit(NBD_DEVICE_SUFFIX, l, r);
if (!TryFromString(r, DeviceIndex)) {
throw TServiceError(E_ARGUMENT) << "unable to parse device index";
}
}

void TNetlinkDevice::ConnectSocket()
{
STORAGE_DEBUG("connect socket");
Expand Down Expand Up @@ -369,31 +371,23 @@ void TNetlinkDevice::DisconnectDevice()
// or reconfigure (if Reconfigure == true) specified device
void TNetlinkDevice::ConnectDevice()
{
try {
TNetlinkSocket socket;
auto context = std::make_unique<THandlerContext>(shared_from_this());

if (int err = nl_socket_modify_cb(
socket,
NL_CB_VALID,
NL_CB_CUSTOM,
TNetlinkDevice::StatusHandler,
context.release())) // libnl doesn't throw
{
throw TServiceError(E_FAIL)
<< "unable to set socket callback: " << nl_geterror(err);
}

TNetlinkMessage message(socket.GetFamily(), NBD_CMD_STATUS);
message.Put(NBD_ATTR_INDEX, DeviceIndex);
message.Send(socket);

} catch (const TServiceError& e) {
StartResult.SetValue(MakeError(
e.GetCode(),
TStringBuilder()
<< "unable to configure " << DeviceName << ": " << e.what()));
TNetlinkSocket socket;
auto context = std::make_unique<THandlerContext>(shared_from_this());

if (int err = nl_socket_modify_cb(
socket,
NL_CB_VALID,
NL_CB_CUSTOM,
TNetlinkDevice::StatusHandler,
context.release())) // libnl doesn't throw
{
throw TServiceError(E_FAIL)
<< "unable to set socket callback: " << nl_geterror(err);
}

TNetlinkMessage message(socket.GetFamily(), NBD_CMD_STATUS);
message.Put(NBD_ATTR_INDEX, DeviceIndex);
message.Send(socket);
}

int TNetlinkDevice::StatusHandler(nl_msg* message, void* argument)
Expand Down
Loading
Loading