Skip to content

Commit d719285

Browse files
bbockelmmatyasselmeci
authored andcommitted
[#32] Enable write-through mode for cache
Allow the PFC to proxy ("write-through") writes when configured to do so (default is current behavior of disabling writes). The implementation is simple -- when writing is enabled, don't attach the PFC to the cache object. Adds a new parameter: ``` pfc.writemode [writethrough | off] ``` where the default write mode is `off`.
1 parent 5f77452 commit d719285

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/XrdPfc/XrdPfc.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ XrdOucCacheIO *Cache::Attach(XrdOucCacheIO *io, int Options)
180180
{
181181
const char* tpfx = "Attach() ";
182182

183-
if (Cache::GetInstance().Decide(io))
183+
if (Options & XrdOucCache::optRW)
184+
{
185+
TRACE(Info, tpfx << "passing through write operation" << obfuscateAuth(io->Path()));
186+
}
187+
else if (Cache::GetInstance().Decide(io))
184188
{
185189
TRACE(Info, tpfx << obfuscateAuth(io->Path()));
186190

@@ -1071,6 +1075,10 @@ int Cache::Prepare(const char *curl, int oflags, mode_t mode)
10711075
// Do not allow write access.
10721076
if ((oflags & O_ACCMODE) != O_RDONLY)
10731077
{
1078+
if (Cache::GetInstance().RefConfiguration().m_write_through)
1079+
{
1080+
return 0;
1081+
}
10741082
TRACE(Warning, "Prepare write access requested on file " << f_name << ". Denying access.");
10751083
return -EROFS;
10761084
}

src/XrdPfc/XrdPfc.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct Configuration
8181

8282
bool should_uvkeep_purge(time_t delta) const { return m_cs_UVKeep >= 0 && delta > m_cs_UVKeep; }
8383

84+
bool m_write_through; //!< flag indicating write-through mode is enabled
8485
bool m_hdfsmode; //!< flag for enabling block-level operation
8586
bool m_allow_xrdpfc_command; //!< flag for enabling access to /xrdpfc-command/ functionality.
8687

@@ -133,6 +134,7 @@ struct TmpConfiguration
133134
std::string m_fileUsageNominal;
134135
std::string m_fileUsageMax;
135136
std::string m_flushRaw;
137+
std::string m_writemodeRaw;
136138

137139
TmpConfiguration() :
138140
m_diskUsageLWM("0.90"), m_diskUsageHWM("0.95"),

src/XrdPfc/XrdPfcConfiguration.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace XrdPfc;
3131
XrdVERSIONINFO(XrdOucGetCache, XrdPfc);
3232

3333
Configuration::Configuration() :
34+
m_write_through(false),
3435
m_hdfsmode(false),
3536
m_allow_xrdpfc_command(false),
3637
m_data_space("public"),
@@ -608,6 +609,21 @@ bool Cache::Config(const char *config_filename, const char *parameters)
608609
}
609610
}
610611

612+
// set the write mode
613+
if ( ! tmpc.m_writemodeRaw.empty())
614+
{
615+
if (tmpc.m_writemodeRaw == "writethrough")
616+
{
617+
m_configuration.m_write_through = true;
618+
}
619+
else if (tmpc.m_writemodeRaw != "off")
620+
{
621+
m_log.Emsg("ConfigParameters()", "Unknown value for pfc.writemode (valid values are `writethrough` or `off`): %s",
622+
tmpc.m_writemodeRaw.c_str());
623+
return false;
624+
}
625+
}
626+
611627
// get number of available RAM blocks after process configuration
612628
if (m_configuration.m_RamAbsAvailable == 0)
613629
{
@@ -690,6 +706,7 @@ bool Cache::Config(const char *config_filename, const char *parameters)
690706
{
691707
loff += snprintf(buff + loff, sizeof(buff) - loff, " pfc.hdfsmode hdfsbsize %lld\n", m_configuration.m_hdfsbsize);
692708
}
709+
loff += snprintf(buff + loff, sizeof(buff) - loff, " pfc.writemode %s\n", m_configuration.m_write_through ? "writethrough" : "off");
693710

694711
if (m_configuration.m_username.empty())
695712
{
@@ -1015,6 +1032,15 @@ bool Cache::ConfigParameters(std::string part, XrdOucStream& config, TmpConfigur
10151032
}
10161033
}
10171034
}
1035+
else if ( part == "writemode" )
1036+
{
1037+
tmpc.m_writemodeRaw = cwg.GetWord();
1038+
if ( ! cwg.HasLast())
1039+
{
1040+
m_log.Emsg("Config", "Error: pfc.writemode requires a parameter.");
1041+
return false;
1042+
}
1043+
}
10181044
else if ( part == "flush" )
10191045
{
10201046
tmpc.m_flushRaw = cwg.GetWord();

0 commit comments

Comments
 (0)