Skip to content

Commit

Permalink
Merge pull request xbmc#21659 from lrusak/nfs-v4
Browse files Browse the repository at this point in the history
NFS: add preliminary nfs4 support
  • Loading branch information
fuzzard authored Sep 6, 2022
2 parents ba773dd + a892fab commit 9864e74
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
25 changes: 22 additions & 3 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -4196,7 +4196,10 @@ msgctxt "#1200"
msgid "SMB client"
msgstr ""

#empty string with id 1201
#: xbmc/filesystem/NFSFile.cpp
msgctxt "#1201"
msgid "NFS Client"
msgstr ""

#: system/settings/settings.xml
msgctxt "#1202"
Expand Down Expand Up @@ -20279,7 +20282,11 @@ msgctxt "#36355"
msgid "In a multi-screen configuration, the screens not displaying this application are blacked out."
msgstr ""

#empty string with id 36356
#. Description of settings category with label #1201 "NFS Client"
#: xbmc/filesystem/NFSFile.cpp
msgctxt "#36356"
msgid "This category contains the settings for how the NFS client is handled."
msgstr ""

#. Description of setting with label #214 "Video calibration..."
#: system/settings/settings.xml
Expand Down Expand Up @@ -21878,7 +21885,19 @@ msgctxt "#37050"
msgid "Verbose logging for the [B]WS-Discovery[/B] component"
msgstr ""

#empty strings from id 37051 to 38010
#. Setting #37051 NFS Protocol Version"
#: xbmc/filesystem/NFSFile.cpp
msgctxt "#37051"
msgid "NFS Protocol Version"
msgstr ""

#. Description of setting #37051 NFS Protocol Version"
#: xbmc/filesystem/NFSFile.cpp
msgctxt "#37052"
msgid "NFS protocol version to use when establishing NFS connections"
msgstr ""

#empty strings from id 37053 to 38010

#. Setting #38011 "Show All Items entry"
#: system/settings/settings.xml
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindNFS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if(NOT LIBNFS_FOUND)
else()
# Try pkgconfig based search. Linux may not have a version with cmake config installed
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_NFS libnfs QUIET)
pkg_check_modules(PC_NFS libnfs>=3.0.0 QUIET)
endif()

find_path(NFS_INCLUDE_DIR nfsc/libnfs.h
Expand Down
15 changes: 15 additions & 0 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,21 @@
</setting>
</group>
</category>
<category id="nfs" label="1201" help="36356">
<requirement>HAS_FILESYSTEM_NFS</requirement>
<group id="1" label="16000">
<setting id="nfs.version" type="integer" label="37051" help="37052">
<level>2</level>
<default>3</default>
<constraints>
<minimum>3</minimum>
<step>1</step>
<maximum>4</maximum>
</constraints>
<control type="spinner" format="integer" />
</setting>
</group>
</category>
<category id="weather" label="8" help="36316">
<group id="1" label="16000">
<setting id="weather.currentlocation" type="integer" label="0" help="36317">
Expand Down
46 changes: 43 additions & 3 deletions xbmc/filesystem/NFSFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ServiceBroker.h"
#include "network/DNSNameCache.h"
#include "settings/AdvancedSettings.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
Expand Down Expand Up @@ -51,6 +52,8 @@ constexpr auto KEEP_ALIVE_TIMEOUT = 3min;

constexpr auto IDLE_TIMEOUT = 3min;

constexpr auto SETTING_NFS_VERSION = "nfs.version";

} // namespace

CNfsConnection::CNfsConnection()
Expand Down Expand Up @@ -214,7 +217,20 @@ bool CNfsConnection::splitUrlIntoExportAndPath(const CURL& url, std::string &exp
//refresh exportlist if empty or hostname change
if(m_exportList.empty() || !StringUtils::EqualsNoCase(url.GetHostName(), m_hostName))
{
m_exportList = GetExportList(url);
const auto settingsComponent = CServiceBroker::GetSettingsComponent();
if (!settingsComponent)
return false;

const auto settings = settingsComponent->GetSettings();
if (!settings)
return false;

const int nfsVersion = settings->GetInt(SETTING_NFS_VERSION);

if (nfsVersion == 4)
m_exportList = {"/"};
else
m_exportList = GetExportList(url);
}

return splitUrlIntoExportAndPath(url, exportPath, relativePath, m_exportList);
Expand Down Expand Up @@ -484,12 +500,36 @@ void CNfsConnection::AddIdleConnection()

void CNfsConnection::setOptions(struct nfs_context* context)
{
const auto settingsComponent = CServiceBroker::GetSettingsComponent();
if (!settingsComponent)
return;

const auto advancedSettings = settingsComponent->GetAdvancedSettings();
if (!advancedSettings)
return;

#ifdef HAS_NFS_SET_TIMEOUT
uint32_t timeout = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_nfsTimeout;
uint32_t timeout = advancedSettings->m_nfsTimeout;
nfs_set_timeout(context, timeout > 0 ? timeout * 1000 : -1);
#endif
int retries = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_nfsRetries;
int retries = advancedSettings->m_nfsRetries;
nfs_set_autoreconnect(context, retries);

const auto settings = settingsComponent->GetSettings();
if (!settings)
return;

const int nfsVersion = settings->GetInt(SETTING_NFS_VERSION);

int ret = nfs_set_version(context, nfsVersion);
if (ret != 0)
{
CLog::Log(LOGERROR, "NFS: Failed to set nfs version: {} ({})", nfsVersion,
nfs_get_error(context));
return;
}

CLog::Log(LOGDEBUG, "NFS: version: {}", nfsVersion);
}

CNfsConnection gNfsConnection;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/settings/SettingConditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ void CSettingConditions::Initialize()
#ifdef HAS_FILESYSTEM_SMB
m_simpleConditions.emplace("has_filesystem_smb");
#endif
#ifdef HAS_FILESYSTEM_NFS
m_simpleConditions.insert("has_filesystem_nfs");
#endif
#ifdef HAS_ZEROCONF
m_simpleConditions.emplace("has_zeroconf");
#endif
Expand Down

0 comments on commit 9864e74

Please sign in to comment.