Skip to content

Commit

Permalink
[NFS] Implement nfs timeout / advancedsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Mar 6, 2019
1 parent 26ba848 commit 03fb5fd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmake/modules/FindNFS.cmake
Expand Up @@ -34,7 +34,10 @@ find_package_handle_standard_args(NFS
if(NFS_FOUND)
set(NFS_LIBRARIES ${NFS_LIBRARY})
set(NFS_INCLUDE_DIRS ${NFS_INCLUDE_DIR})
set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1)

string(REPLACE "." ";" VERSION_LIST ${NFS_VERSION})
list(GET VERSION_LIST 0 NFS_VERSION_MAJOR)
set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1 -DNFS_VERSION=${NFS_VERSION_MAJOR})

if(NOT TARGET NFS::NFS)
add_library(NFS::NFS UNKNOWN IMPORTED)
Expand Down
15 changes: 15 additions & 0 deletions xbmc/filesystem/NFSFile.cpp
Expand Up @@ -11,6 +11,9 @@
//////////////////////////////////////////////////////////////////////

#include "NFSFile.h"
#include "ServiceBroker.h"
#include "settings/AdvancedSettings.h"
#include "settings/SettingsComponent.h"
#include "threads/SingleLock.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
Expand Down Expand Up @@ -178,6 +181,7 @@ int CNfsConnection::getContextForExport(const std::string &exportname)
{
struct contextTimeout tmp;
CSingleLock lock(openContextLock);
setTimeout(m_pNfsContext);
tmp.pContext = m_pNfsContext;
tmp.lastAccessedTime = XbmcThreads::SystemClockMillis();
m_openContextMap[exportname] = tmp; //add context to list of all contexts
Expand Down Expand Up @@ -424,6 +428,7 @@ int CNfsConnection::stat(const CURL &url, NFSSTAT *statbuff)

if(pTmpContext)
{
setTimeout(pTmpContext);
//we connect to the directory of the path. This will be the "root" path of this connection then.
//So all fileoperations are relative to this mountpoint...
nfsRet = nfs_mount(pTmpContext, m_resolvedHostName.c_str(), exportPath.c_str());
Expand Down Expand Up @@ -461,6 +466,16 @@ void CNfsConnection::AddIdleConnection()
m_IdleTimeout = 180;
}


void CNfsConnection::setTimeout(struct nfs_context *context)
{
#if NFS_VERSION >= 2
uint32_t timeout = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_nfsTimeout;
if (timeout > 0)
nfs_set_timeout(context, timeout * 1000);
#endif
}

CNfsConnection gNfsConnection;

CNFSFile::CNFSFile()
Expand Down
1 change: 1 addition & 0 deletions xbmc/filesystem/NFSFile.h
Expand Up @@ -94,6 +94,7 @@ class CNfsConnection : public CCriticalSection
void destroyContext(const std::string &exportName);
void resolveHost(const CURL &url);//resolve hostname by dnslookup
void keepAlive(std::string _exportPath, struct nfsfh *_pFileHandle);
static void setTimeout(struct nfs_context *context);
};

extern CNfsConnection gNfsConnection;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/settings/AdvancedSettings.cpp
Expand Up @@ -454,6 +454,8 @@ void CAdvancedSettings::Initialize()

m_userAgent = g_sysinfo.GetUserAgent();

m_nfsTimeout = 2;

m_initialized = true;
}

Expand Down Expand Up @@ -534,6 +536,7 @@ void CAdvancedSettings::ParseSettingsFile(const std::string &file)
passTag->LinkEndChild(new TiXmlText("*****"));
}
}
XMLUtils::GetUInt(network, "nfstimeout", m_nfsTimeout, 0, 3600);
}

// Dump contents of copied AS.xml to debug log
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/AdvancedSettings.h
Expand Up @@ -386,6 +386,7 @@ class CAdvancedSettings : public ISettingCallback, public ISettingsHandler
bool m_openGlDebugging;

std::string m_userAgent;
uint32_t m_nfsTimeout;

private:
void SetExtraLogLevel(const std::vector<CVariant> &components);
Expand Down

0 comments on commit 03fb5fd

Please sign in to comment.