Skip to content

Commit f6fb434

Browse files
committed
MGM: Move the enforce configuration of the Recycle bin from the space level
parameters to actually being attached to the RecyclePolicy. Update the corresponding help commands of the recycle and space commands and also make sure that the RecyclePolicy configuration is thread-safe as it can now be updated at any point in time.
1 parent d5fe8a1 commit f6fb434

File tree

17 files changed

+259
-124
lines changed

17 files changed

+259
-124
lines changed

common/grpc-proto

Submodule grpc-proto updated from d7a71d8 to 1ebc906

console/commands/com_proto_recycle.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void com_recycle_help()
108108
<< " [--add-bin|--remove-bin] <sub-tree>\n"
109109
<< " --add-bin : enable recycle bin for deletion in <sub-tree>\n"
110110
<< " --remove-bin : disable recycle bin for <sub-tree>\n"
111+
<< " --enable <on/off>\n"
112+
<< " enable or disable global recycle bin enforcement\n"
111113
<< " --lifetime <seconds>\n"
112114
<< " configure FIFO lifetime for the recycle bin\n"
113115
<< " --ratio <0..1.0>\n"

console/commands/com_proto_space.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ void com_space_help()
562562
<< " : configure default file layout creation settings as a space policy - a value='remove' deletes the space policy\n"
563563
<< std::endl
564564
<< "space config <space-name> space.altxs=on|off : enable/disable the alternative checksums computation when the file is uploaded\n"
565-
<< "space config <space-name> space.policy.recycle=on\n"
566-
<< " : globally enforce using always a recycle bin\n"
567565
<< std::endl
568566
<< "TAPE REST API specific parameters:\n"
569567
<< "space config default " << eos::mgm::rest::TAPE_REST_API_SWITCH_ON_OFF <<

console/commands/helpers/RecycleHelper.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ RecycleHelper::ParseCommand(const char* arg)
349349
return false;
350350
}
351351

352+
config->set_value(option);
353+
} else if (soption == "--enable") {
354+
config->set_op(eos::console::RecycleProto::ConfigProto::ENABLE);
355+
356+
if (!(option = tokenizer.GetToken())) {
357+
return false;
358+
}
359+
352360
config->set_value(option);
353361
} else if ((soption == "--dump")) {
354362
config->set_op(eos::console::RecycleProto::ConfigProto::DUMP);

mgm/FsView.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,14 +3256,6 @@ FsView::ApplyGlobalConfig(const char* key, std::string& val)
32563256
if (tokens[1] == "token.generation") {
32573257
eos_static_info("token-generation := %s", val.c_str());
32583258
eos::common::EosTok::sTokenGeneration = strtoull(val.c_str(), 0, 10);
3259-
} else if (tokens[1] == "policy.recycle") {
3260-
eos_static_info("policy-recycle := %s", val.c_str());
3261-
3262-
if (val == "on") {
3263-
gOFS->enforceRecycleBin = true;
3264-
} else {
3265-
gOFS->enforceRecycleBin = false;
3266-
}
32673259
} else if (tokens[1] == "fusex.hbi") {
32683260
gOFS->zMQ->gFuseServer.Client().SetHeartbeatInterval(atoi(val.c_str()));
32693261
} else if (tokens[1] == "fusex.qti") {

mgm/XrdMgmOfs.cc

Lines changed: 139 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ XrdMgmOfs::XrdMgmOfs(XrdSysError* ep):
320320
{
321321
eDest = ep;
322322
ConfigFN = 0;
323-
enforceRecycleBin = false;
324323

325324
if (getenv("EOS_MGM_HTTP_PORT")) {
326325
mHttpdPort = strtol(getenv("EOS_MGM_HTTP_PORT"), 0, 10);
@@ -374,9 +373,14 @@ XrdMgmOfs::XrdMgmOfs(XrdSysError* ep):
374373
{
375374
const char* am = getenv("EOS_MGM_AUDIT");
376375
std::string mode = (am ? am : "");
376+
377377
// normalize to lowercase
378-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
379-
if (mode.empty() || mode == "none" || mode == "false" || mode == "no" || mode == "off") {
378+
for (auto& c : mode) {
379+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
380+
}
381+
382+
if (mode.empty() || mode == "none" || mode == "false" || mode == "no" ||
383+
mode == "off") {
380384
mEnvAuditDisableAll = true;
381385
mEnvAuditAttributeMode = false;
382386
mEnvAuditAttributeOnly = false;
@@ -415,27 +419,33 @@ XrdMgmOfs::XrdMgmOfs(XrdSysError* ep):
415419
}
416420

417421
const char* rs = getenv("EOS_MGM_AUDIT_READ_SUFFIX");
422+
418423
if (rs && *rs) {
419424
std::string s = rs;
420425
std::string token;
426+
421427
for (size_t i = 0; i <= s.size(); ++i) {
422428
if (i == s.size() || s[i] == ',' || s[i] == ';' || s[i] == ' ') {
423429
if (!token.empty()) {
424430
// normalize
425431
for (auto& c : token) c = static_cast<char>(
426-
std::tolower(static_cast<unsigned char>(c)));
427-
if (!token.empty() && token[0] == '.') token.erase(token.begin());
432+
std::tolower(static_cast<unsigned char>(c)));
433+
434+
if (!token.empty() && token[0] == '.') {
435+
token.erase(token.begin());
436+
}
437+
428438
mEnvAuditReadSuffixes.push_back(token);
429439
token.clear();
430440
}
431441
} else {
432442
token.push_back(s[i]);
433443
}
434444
}
445+
435446
mEnvAuditReadSuffixesSet = true;
436447
}
437448
}
438-
439449
EgroupRefresh.reset(new eos::mgm::Egroup());
440450
mRecycler.reset(new eos::mgm::Recycle());
441451
mDeviceTracker.reset(new eos::mgm::Devices());
@@ -1805,98 +1815,193 @@ XrdMgmOfs::IsMaster(const char* path,
18051815
bool
18061816
XrdMgmOfs::AllowAuditModification(const std::string& path)
18071817
{
1808-
if (!mAudit) return false;
1809-
if (!mEnvAuditAttributeOnly) return true;
1818+
if (!mAudit) {
1819+
return false;
1820+
}
1821+
1822+
if (!mEnvAuditAttributeOnly) {
1823+
return true;
1824+
}
1825+
18101826
// attribute-only: parent sys.audit must enable modifications
18111827
std::string pdir;
1812-
{ eos::common::Path cP(path.c_str()); pdir = cP.GetParentPath(); }
1828+
{
1829+
eos::common::Path cP(path.c_str());
1830+
pdir = cP.GetParentPath();
1831+
}
1832+
18131833
try {
18141834
auto pd = eosView->getContainer(pdir);
18151835
eos::MDLocking::ContainerReadLock cmd_lock(pd.get());
18161836
auto amap = pd->getAttributes();
18171837
auto it = amap.find("sys.audit");
1838+
18181839
if (it != amap.end()) {
18191840
std::string mode = it->second;
1820-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1821-
if (mode == "all" || mode == "detail" || mode == "default" || mode == "modifications") return true;
1841+
1842+
for (auto& c : mode) {
1843+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1844+
}
1845+
1846+
if (mode == "all" || mode == "detail" || mode == "default" ||
1847+
mode == "modifications") {
1848+
return true;
1849+
}
18221850
}
18231851
} catch (...) {}
1852+
18241853
return false;
18251854
}
18261855

18271856
bool
18281857
XrdMgmOfs::AllowAuditList(const std::string& dirPath)
18291858
{
1830-
if (!mAudit) return false;
1831-
if (!mEnvAuditAttributeOnly) return mAudit->isListAuditingEnabled();
1859+
if (!mAudit) {
1860+
return false;
1861+
}
1862+
1863+
if (!mEnvAuditAttributeOnly) {
1864+
return mAudit->isListAuditingEnabled();
1865+
}
1866+
18321867
// attribute-only: dir sys.audit must be 'all'
18331868
try {
18341869
auto dh = eosView->getContainer(dirPath);
18351870
eos::MDLocking::ContainerReadLock cmd_lock(dh.get());
18361871
auto amap = dh->getAttributes();
18371872
auto it = amap.find("sys.audit");
1873+
18381874
if (it != amap.end()) {
18391875
std::string mode = it->second;
1840-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1841-
if (mode == "all") return true;
1876+
1877+
for (auto& c : mode) {
1878+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1879+
}
1880+
1881+
if (mode == "all") {
1882+
return true;
1883+
}
18421884
}
18431885
} catch (...) {}
1886+
18441887
return false;
18451888
}
18461889

18471890
bool
18481891
XrdMgmOfs::AllowAuditRead(const std::string& path)
18491892
{
1850-
if (!mAudit) return false;
1851-
if (!mEnvAuditAttributeOnly) return (mAudit->isReadAuditingEnabled() && mAudit->shouldAuditReadPath(path));
1893+
if (!mAudit) {
1894+
return false;
1895+
}
1896+
1897+
if (!mEnvAuditAttributeOnly) {
1898+
return (mAudit->isReadAuditingEnabled() && mAudit->shouldAuditReadPath(path));
1899+
}
1900+
18521901
// attribute-only: parent sys.audit governs; default/detail/all enable; default uses suffix filter
18531902
std::string pdir;
1854-
{ eos::common::Path cP(path.c_str()); pdir = cP.GetParentPath(); }
1903+
{
1904+
eos::common::Path cP(path.c_str());
1905+
pdir = cP.GetParentPath();
1906+
}
1907+
18551908
try {
18561909
auto pd = eosView->getContainer(pdir);
18571910
eos::MDLocking::ContainerReadLock cmd_lock(pd.get());
18581911
auto amap = pd->getAttributes();
18591912
auto it = amap.find("sys.audit");
1913+
18601914
if (it != amap.end()) {
18611915
std::string mode = it->second;
1862-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1863-
if (mode == "detail" || mode == "all") return true;
1864-
if (mode == "default") return mAudit->shouldAuditReadPath(path);
1916+
1917+
for (auto& c : mode) {
1918+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1919+
}
1920+
1921+
if (mode == "detail" || mode == "all") {
1922+
return true;
1923+
}
1924+
1925+
if (mode == "default") {
1926+
return mAudit->shouldAuditReadPath(path);
1927+
}
18651928
}
18661929
} catch (...) {}
1930+
18671931
return false;
18681932
}
18691933

18701934
// Fast-path overloads that use an already available sys.audit attribute value
18711935
bool
18721936
XrdMgmOfs::AllowAuditModificationAttr(const std::string& auditMode)
18731937
{
1874-
if (!mAudit) return false;
1875-
if (!mEnvAuditAttributeOnly) return true;
1938+
if (!mAudit) {
1939+
return false;
1940+
}
1941+
1942+
if (!mEnvAuditAttributeOnly) {
1943+
return true;
1944+
}
1945+
18761946
std::string mode = auditMode;
1877-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1878-
if (mode == "all" || mode == "detail" || mode == "default" || mode == "modifications") return true;
1947+
1948+
for (auto& c : mode) {
1949+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1950+
}
1951+
1952+
if (mode == "all" || mode == "detail" || mode == "default" ||
1953+
mode == "modifications") {
1954+
return true;
1955+
}
1956+
18791957
return false;
18801958
}
18811959

18821960
bool
18831961
XrdMgmOfs::AllowAuditListAttr(const std::string& auditMode)
18841962
{
1885-
if (!mAudit) return false;
1886-
if (!mEnvAuditAttributeOnly) return mAudit->isListAuditingEnabled();
1963+
if (!mAudit) {
1964+
return false;
1965+
}
1966+
1967+
if (!mEnvAuditAttributeOnly) {
1968+
return mAudit->isListAuditingEnabled();
1969+
}
1970+
18871971
std::string mode = auditMode;
1888-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1972+
1973+
for (auto& c : mode) {
1974+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1975+
}
1976+
18891977
return (mode == "all");
18901978
}
18911979

18921980
bool
1893-
XrdMgmOfs::AllowAuditReadAttr(const std::string& auditMode, const std::string& path)
1981+
XrdMgmOfs::AllowAuditReadAttr(const std::string& auditMode,
1982+
const std::string& path)
18941983
{
1895-
if (!mAudit) return false;
1896-
if (!mEnvAuditAttributeOnly) return (mAudit->isReadAuditingEnabled() && mAudit->shouldAuditReadPath(path));
1984+
if (!mAudit) {
1985+
return false;
1986+
}
1987+
1988+
if (!mEnvAuditAttributeOnly) {
1989+
return (mAudit->isReadAuditingEnabled() && mAudit->shouldAuditReadPath(path));
1990+
}
1991+
18971992
std::string mode = auditMode;
1898-
for (auto& c : mode) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1899-
if (mode == "detail" || mode == "all") return true;
1900-
if (mode == "default") return mAudit->shouldAuditReadPath(path);
1993+
1994+
for (auto& c : mode) {
1995+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
1996+
}
1997+
1998+
if (mode == "detail" || mode == "all") {
1999+
return true;
2000+
}
2001+
2002+
if (mode == "default") {
2003+
return mAudit->shouldAuditReadPath(path);
2004+
}
2005+
19012006
return false;
19022007
}

mgm/XrdMgmOfs.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,6 @@ public:
21542154
std::unique_ptr<Devices> mDeviceTracker;
21552155

21562156
//! Variable enforcing a globally applied recycle bin policy
2157-
std::atomic<bool> enforceRecycleBin;
21582157
std::string mArchiveEndpoint; ///< archive ZMQ connection endpoint
21592158
std::string mFstGwHost; ///< FST gateway redirect fqdn host
21602159
int mFstGwPort; ///< FST gateway redirect port, default 1094

mgm/XrdMgmOfs/Rm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,12 @@ XrdMgmOfs::_rem(const char* path,
269269
XrdOucString sPath = path;
270270

271271
if (!(no_recycling) &&
272-
(gOFS->enforceRecycleBin || attrmap.count(Recycle::gRecyclingAttribute)) &&
272+
(gOFS->mRecycler->IsEnabled() || attrmap.count(Recycle::gRecyclingAttribute)) &&
273273
(!sPath.beginswith(Recycle::gRecyclingPrefix.c_str()))) {
274274
// ---------------------------------------------------------------------
275275
// this is two-step deletion via a recyle bin
276276
// ---------------------------------------------------------------------
277-
if (gOFS->enforceRecycleBin) {
277+
if (gOFS->mRecycler->IsEnabled()) {
278278
// add the recycle attribute to enable recycling funcionality
279279
attrmap[Recycle::gRecyclingAttribute] = Recycle::gRecyclingPrefix;
280280
}

mgm/proc/admin/SpaceCmd.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,6 @@ void SpaceCmd::ConfigSubcmd(const eos::console::SpaceProto_ConfigProto& config,
722722
if (value == "remove") {
723723
applied = true;
724724

725-
if ((key == "policy.recycle")) {
726-
gOFS->enforceRecycleBin = false;
727-
}
728-
729725
if (!space->DeleteConfigMember(key)) {
730726
ret_c = ENOENT;
731727
std_err.str("error: key has not been deleted");
@@ -744,14 +740,6 @@ void SpaceCmd::ConfigSubcmd(const eos::console::SpaceProto_ConfigProto& config,
744740
"' as " + key + "='" + value + "'\n");
745741
ret_c = 0;
746742
}
747-
748-
if ((key == "policy.recycle")) {
749-
if (value == "on") {
750-
gOFS->enforceRecycleBin = true;
751-
} else {
752-
gOFS->enforceRecycleBin = false;
753-
}
754-
}
755743
}
756744
} else if (key == eos::mgm::tgc::TGC_NAME_FREE_BYTES_SCRIPT) {
757745
applied = true;

mgm/proc/user/RecycleCmd.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ RecycleCmd::ProcessRequest() noexcept
149149
std::to_string(config.size()));
150150
} else if (config.op() == eos::console::RecycleProto_ConfigProto::DRY_RUN) {
151151
retc = Recycle::Config(std_out, std_err, mVid, config.op(), config.value());
152+
} else if (config.op() == eos::console::RecycleProto_ConfigProto::ENABLE) {
153+
retc = Recycle::Config(std_out, std_err, mVid, config.op(), config.value());
152154
} else if (config.op() == eos::console::RecycleProto_ConfigProto::DUMP) {
153155
retc = 0;
154156
std_out = gOFS->mRecycler->Dump();

0 commit comments

Comments
 (0)