Skip to content

Commit 82c4e8a

Browse files
committed
MGM: Improve the display information of fileinfo for symlink and hardlink files.
Fixes EOS-5430 Fixes EOS-6442
1 parent 2f7c987 commit 82c4e8a

7 files changed

Lines changed: 183 additions & 163 deletions

File tree

mgm/Constants.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace eos::mgm
3434
static const std::string EOS_ATOMIC = "eos.atomic";
3535
static const std::string EOS_INJECTION = "eos.injection";
3636

37+
static const std::string SYS_HARD_LINK = "sys.eos.mdino";
38+
static const std::string SYS_NUM_LINK = "sys.eos.nlink";
3739
static const std::string SYS_OWNER_AUTH = "sys.owner.auth";
3840
static const std::string SYS_VERSIONING = "sys.versioning";
3941
static const std::string SYS_FORCED_ATOMIC = "sys.forced.atomic";

mgm/FuseServer/Server.cc

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
************************************************************************/
2323

2424
#include "mgm/FuseServer/Server.hh"
25+
#include "mgm/Constants.hh"
2526
#include "mgm/Acl.hh"
2627
#include "mgm/Policy.hh"
2728
#include "mgm/Quota.hh"
@@ -52,8 +53,8 @@ USE_EOSMGMNAMESPACE
5253

5354
EOSFUSESERVERNAMESPACE_BEGIN
5455

55-
#define k_mdino XrdMgmOfsFile::k_mdino
56-
#define k_nlink XrdMgmOfsFile::k_nlink
56+
#define k_mdino eos::mgm::SYS_HARD_LINK
57+
#define k_nlink eos::mgm::SYS_NUM_LINK
5758

5859
USE_EOSFUSESERVERNAMESPACE
5960

@@ -640,63 +641,63 @@ Server::FillContainerCAP(uint64_t id,
640641
} else {
641642
if (!vid.token) {
642643
if (vid.sudoer) {
643-
mode |= C_OK | M_OK | U_OK | W_OK | D_OK | SA_OK | SU_OK
644-
; // chown + chmod permission + all the rest
644+
mode |= C_OK | M_OK | U_OK | W_OK | D_OK | SA_OK | SU_OK
645+
; // chown + chmod permission + all the rest
645646
}
646647

647648
if (vid.uid == (uid_t) dir.uid()) {
648-
// we don't apply a mask if we are the owner
649-
if (dir.mode() & S_IRUSR) {
650-
mode |= R_OK | M_OK | SU_OK;
651-
}
649+
// we don't apply a mask if we are the owner
650+
if (dir.mode() & S_IRUSR) {
651+
mode |= R_OK | M_OK | SU_OK;
652+
}
652653

653-
if (dir.mode() & S_IWUSR) {
654-
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
655-
}
654+
if (dir.mode() & S_IWUSR) {
655+
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
656+
}
656657

657-
if (dir.mode() & mask & S_IXUSR) {
658-
mode |= X_OK;
659-
}
658+
if (dir.mode() & mask & S_IXUSR) {
659+
mode |= X_OK;
660+
}
660661
}
661662

662663
bool same_group = false;
663664

664665
if (vid.gid == (gid_t) dir.gid()) {
665-
same_group = true;
666+
same_group = true;
666667
} else {
667-
if (eos::common::Mapping::gSecondaryGroups) {
668-
if (vid.allowed_gids.count(dir.gid())) {
669-
same_group = true;
670-
}
671-
}
668+
if (eos::common::Mapping::gSecondaryGroups) {
669+
if (vid.allowed_gids.count(dir.gid())) {
670+
same_group = true;
671+
}
672+
}
672673
}
673674

674675
if (same_group) {
675-
// we apply a mask if we are in the same group
676-
if (dir.mode() & mask & S_IRGRP) {
677-
mode |= R_OK;
678-
}
676+
// we apply a mask if we are in the same group
677+
if (dir.mode() & mask & S_IRGRP) {
678+
mode |= R_OK;
679+
}
679680

680-
if (dir.mode() & mask & S_IWGRP) {
681-
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
682-
}
681+
if (dir.mode() & mask & S_IWGRP) {
682+
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
683+
}
683684

684-
if (dir.mode() & mask & S_IXGRP) {
685-
mode |= X_OK;
686-
}
685+
if (dir.mode() & mask & S_IXGRP) {
686+
mode |= X_OK;
687+
}
687688
}
688689

689690
// we apply a mask if we are matching other permissions
690691
if (dir.mode() & mask & S_IROTH) {
691-
mode |= R_OK;
692+
mode |= R_OK;
692693
}
693694

694695
if (dir.mode() & mask & S_IWOTH) {
695-
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
696+
mode |= U_OK | W_OK | D_OK | SA_OK | M_OK | SU_OK;
696697
}
697698

698699
if (dir.mode() & mask & S_IXOTH) {
699-
mode |= X_OK;
700+
mode |= X_OK;
700701
}
701702
}
702703

@@ -1035,18 +1036,18 @@ Server::ValidatePERM(const eos::fusex::md& md, const std::string& mode,
10351036

10361037
if (!vid.token) {
10371038
for (auto g : gids) {
1038-
if (cmd->access(vid.uid, g, R_OK)) {
1039-
r_ok = true;
1040-
}
1039+
if (cmd->access(vid.uid, g, R_OK)) {
1040+
r_ok = true;
1041+
}
10411042

1042-
if (cmd->access(vid.uid, g, W_OK)) {
1043-
w_ok = true;
1044-
d_ok = true;
1045-
}
1043+
if (cmd->access(vid.uid, g, W_OK)) {
1044+
w_ok = true;
1045+
d_ok = true;
1046+
}
10461047

1047-
if (cmd->access(vid.uid, g, X_OK)) {
1048-
x_ok = true;
1049-
}
1048+
if (cmd->access(vid.uid, g, X_OK)) {
1049+
x_ok = true;
1050+
}
10501051
}
10511052
}
10521053

@@ -1248,7 +1249,8 @@ Server::OpGetLs(const std::string& id,
12481249
auto map = (*parent)[md.md_ino()].children();
12491250
auto it = map.begin();
12501251
size_t n_caps = 0;
1251-
gOFS->MgmStats.Add("Eosxd::ext::LS-Entry", vid.uid, vid.gid, map.size(), vid.app);
1252+
gOFS->MgmStats.Add("Eosxd::ext::LS-Entry", vid.uid, vid.gid, map.size(),
1253+
vid.app);
12521254

12531255
for (; it != map.end(); ++it) {
12541256
// this is a map by inode
@@ -1581,7 +1583,7 @@ Server::OpSetDirectory(const std::string& id,
15811583
vid.scope = gOFS->eosView->getUri(cmd.get());
15821584
/* chown is under control of container sys.acl only, if a vanilla user chowns to other than themselves */
15831585
Acl acl;
1584-
gOFS->listAttributes(gOFS->eosView, &(*cmd), attrmap, false);
1586+
gOFS->listAttributes(gOFS->eosView, &(*cmd), attrmap, false);
15851587

15861588
if (EOS_LOGS_DEBUG) {
15871589
eos_debug("sysacl '%s' useracl '%s' evaluseracl %d (ignored)",
@@ -2506,7 +2508,7 @@ Server::OpSetFile(const std::string& id,
25062508
break;
25072509

25082510
case CREATE:
2509-
gOFS->MgmStats.Add("Eosxd::ext::CREATE", vid.uid, vid.gid, 1 , vid.app);
2511+
gOFS->MgmStats.Add("Eosxd::ext::CREATE", vid.uid, vid.gid, 1, vid.app);
25102512
break;
25112513

25122514
case RENAME:

mgm/XrdMgmOfs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "grpc/GrpcServer.hh"
5151
#include "grpc/GrpcWncServer.hh"
5252
#include "grpc/GrpcRestGwServer.hh"
53+
#include "mgm/Constants.hh"
5354
#include "mgm/AdminSocket.hh"
5455
#include "mgm/Stat.hh"
5556
#include "mgm/Access.hh"
@@ -141,7 +142,6 @@ XrdSysError gMgmOfsEroute(0);
141142
XrdOucTrace gMgmOfsTrace(&gMgmOfsEroute);
142143
XrdMgmOfs* gOFS = 0;
143144

144-
const char* k_mdino = "sys.eos.mdino";
145145
const char* k_nlink = "sys.eos.nlink";
146146

147147
// Set the version information

mgm/XrdMgmOfs/Find.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ _cloneResp(XrdOucErrInfo& out_error, XrdOucString& stdErr,
174174
continue;
175175
}
176176

177-
if (!gmd->hasAttribute(XrdMgmOfsFile::k_mdino)) {
177+
if (!gmd->hasAttribute(SYS_HARD_LINK)) {
178178
fmd = gmd;
179179

180-
if (fmd->hasAttribute(XrdMgmOfsFile::k_nlink)) {
180+
if (fmd->hasAttribute(SYS_HARD_LINK)) {
181181
/* a (no-zombie) target for hard link(s), goes into the log */
182182
hardlinkTgt = eos::common::FileId::FidToInode(fmd->getId());
183183
}
@@ -190,7 +190,7 @@ _cloneResp(XrdOucErrInfo& out_error, XrdOucString& stdErr,
190190
* on restore they could be fiddled back together over the clone_path;
191191
* from above: we do not report the zombie targets themselves
192192
*/
193-
mdino = std::stoll(gmd->getAttribute(XrdMgmOfsFile::k_mdino));
193+
mdino = std::stoll(gmd->getAttribute(SYS_HARD_LINK));
194194
fmd = gOFS->eosFileService->getFileMD(eos::common::FileId::InodeToFid(mdino));
195195
eos_static_debug("hlnk switched from %s to file %s (%#llx)",
196196
gmd->getName().c_str(), fmd->getName().c_str(), mdino);
@@ -259,8 +259,9 @@ _cloneResp(XrdOucErrInfo& out_error, XrdOucString& stdErr,
259259
Json::Value attr;
260260

261261
for (auto it = attrmap.begin(); it != attrmap.end(); it++) {
262-
if (it->first == "sys.vtrace" ||
263-
it->first == XrdMgmOfsFile::k_mdino || it->first == XrdMgmOfsFile::k_nlink) {
262+
if ((it->first == "sys.vtrace") ||
263+
(it->first == SYS_HARD_LINK) ||
264+
(it->first == SYS_NUM_LINK)) {
264265
continue;
265266
}
266267

@@ -452,7 +453,7 @@ _clone(std::shared_ptr<eos::IContainerMD>& cmd,
452453
continue;
453454
}
454455

455-
/* fallthrough */
456+
/* fallthrough */
456457

457458
case '+':
458459
if ((uint64_t) stime.tv_sec < cloneId) {
@@ -707,7 +708,8 @@ XrdMgmOfs::_find(const char* path, XrdOucErrInfo& out_error,
707708
bool limited = false;
708709
bool fail_if_limited = (out_error.getErrInfo() == E2BIG);
709710

710-
if ((vid.uid != 0) && (!vid.hasUid(eos::common::ADM_UID)) && (!vid.hasGid(eos::common::ADM_GID)) && (!vid.sudoer)) {
711+
if ((vid.uid != 0) && (!vid.hasUid(eos::common::ADM_UID)) &&
712+
(!vid.hasGid(eos::common::ADM_GID)) && (!vid.sudoer)) {
711713
limitresult = true;
712714
}
713715

@@ -777,7 +779,7 @@ XrdMgmOfs::_find(const char* path, XrdOucErrInfo& out_error,
777779
try {
778780
cmd = gOFS->eosView->getContainer(Path.c_str(), false);
779781
eos::MDLocking::ContainerReadLock cmd_lock(cmd.get());
780-
permok = (!vid.token)?cmd->access(vid.uid, vid.gid, R_OK | X_OK): false;
782+
permok = (!vid.token) ? cmd->access(vid.uid, vid.gid, R_OK | X_OK) : false;
781783
cmd->getCTime(ctime);
782784
} catch (eos::MDException& e) {
783785
cmd.reset();
@@ -902,6 +904,7 @@ XrdMgmOfs::_find(const char* path, XrdOucErrInfo& out_error,
902904
if (fmd) {
903905
eos::IContainerMD::ctime_t ctime;
904906
fmd->getCTime(ctime);
907+
905908
// Skip file entries which are newer than max ctime
906909
if (max_ctime_file && (ctime.tv_sec > max_ctime_file)) {
907910
continue;
@@ -983,7 +986,8 @@ XrdMgmOfs::_find(const char* path, XrdOucErrInfo& out_error,
983986
// accessible since it can evt. be missing if it is empty
984987
XrdSfsFileExistence dir_exists;
985988

986-
if (((_exists(found_dirs[0][0].c_str(), dir_exists, out_error, vid, 0)) == SFS_OK) &&
989+
if (((_exists(found_dirs[0][0].c_str(), dir_exists, out_error, vid,
990+
0)) == SFS_OK) &&
987991
(dir_exists == XrdSfsFileExistIsDirectory)) {
988992
eos::common::Path cPath(found_dirs[0][0].c_str());
989993
(void) found[found_dirs[0][0].c_str()].size();

mgm/XrdMgmOfsFile.cc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "common/Strerror_r_wrapper.hh"
3333
#include "common/BehaviourConfig.hh"
3434
#include "common/Utils.hh"
35+
#include "mgm/Constants.hh"
3536
#include "mgm/Access.hh"
3637
#include "mgm/convert/ConversionTag.hh"
3738
#include "mgm/FileSystem.hh"
@@ -254,12 +255,12 @@ XrdMgmOfsFile::create_cow(int cowType,
254255
gmd->addLocation(fmd->getLocation(i));
255256
}
256257
} else if (cowType == cowUnlink) {
257-
int nlink = (fmd->hasAttribute(XrdMgmOfsFile::k_nlink)) ?
258-
std::stoi(fmd->getAttribute(XrdMgmOfsFile::k_nlink)) + 1 : 1;
259-
fmd->setAttribute(k_nlink, std::to_string(nlink));
258+
int nlink = (fmd->hasAttribute(SYS_NUM_LINK)) ?
259+
std::stoi(fmd->getAttribute(SYS_NUM_LINK)) + 1 : 1;
260+
fmd->setAttribute(SYS_NUM_LINK, std::to_string(nlink));
260261
gOFS->eosFileService->updateStore(fmd.get());
261262
uint64_t hlTarget = eos::common::FileId::FidToInode(fmd->getId());
262-
gmd->setAttribute(XrdMgmOfsFile::k_mdino, std::to_string(hlTarget));
263+
gmd->setAttribute(SYS_HARD_LINK, std::to_string(hlTarget));
263264
eos_static_debug("create_cow Unlink %s (%ld) -> %s (%ld)",
264265
gmd->getName().c_str(), gmd->getSize(),
265266
fmd->getName().c_str(), fmd->getSize());
@@ -296,19 +297,19 @@ XrdMgmOfsFile::handleHardlinkDelete(std::shared_ptr<eos::IContainerMD> cmd,
296297
long nlink =
297298
-2; /* assume this has nothing to do with hard links */
298299

299-
if (fmd->hasAttribute(XrdMgmOfsFile::k_mdino)) {
300+
if (fmd->hasAttribute(SYS_HARD_LINK)) {
300301
/* this is a hard link, decrease reference count on underlying file */
301-
uint64_t hlTgt = std::stoull(fmd->getAttribute(XrdMgmOfsFile::k_mdino));
302+
uint64_t hlTgt = std::stoull(fmd->getAttribute(SYS_HARD_LINK));
302303
uint64_t clock;
303304
/* gmd = the hard link target */
304305
std::shared_ptr<eos::IFileMD> gmd = gOFS->eosFileService->getFileMD(
305306
eos::common::FileId::InodeToFid(hlTgt), &clock);
306-
nlink = std::stol(gmd->getAttribute(XrdMgmOfsFile::k_nlink)) - 1;
307+
nlink = std::stol(gmd->getAttribute(SYS_NUM_LINK)) - 1;
307308

308309
if (nlink > 0) {
309-
gmd->setAttribute(XrdMgmOfsFile::k_nlink, std::to_string(nlink));
310+
gmd->setAttribute(SYS_NUM_LINK, std::to_string(nlink));
310311
} else {
311-
gmd->removeAttribute(XrdMgmOfsFile::k_nlink);
312+
gmd->removeAttribute(SYS_NUM_LINK);
312313
}
313314

314315
gOFS->eosFileService->updateStore(gmd.get());
@@ -342,9 +343,9 @@ XrdMgmOfsFile::handleHardlinkDelete(std::shared_ptr<eos::IContainerMD> cmd,
342343
gOFS->eosFileService->updateStore(gmd.get());
343344
}
344345
}
345-
} else if (fmd->hasAttribute(
346-
XrdMgmOfsFile::k_nlink)) { /* a hard link target */
347-
nlink = std::stol(fmd->getAttribute(XrdMgmOfsFile::k_nlink));
346+
} else if (fmd->hasAttribute(SYS_NUM_LINK)) {
347+
// a hard link target
348+
nlink = std::stol(fmd->getAttribute(SYS_NUM_LINK));
348349
eos_static_info("hlnk rm target nlink %ld", nlink);
349350

350351
if (nlink > 0) {
@@ -353,7 +354,7 @@ XrdMgmOfsFile::handleHardlinkDelete(std::shared_ptr<eos::IContainerMD> cmd,
353354
uint64_t ino = eos::common::FileId::FidToInode(fmd->getId());
354355
snprintf(nameBuf, sizeof(nameBuf), "...eos.ino...%lx", ino);
355356
std::string nameBufs(nameBuf);
356-
fmd->setAttribute(XrdMgmOfsFile::k_nlink, std::to_string(nlink));
357+
fmd->setAttribute(SYS_NUM_LINK, std::to_string(nlink));
357358
eos_static_info("hlnk unlink rename %s=>%s new nlink %d",
358359
fmd->getName().c_str(), nameBufs.c_str(), nlink);
359360
cmd->removeFile(nameBufs); // if the target exists, remove it!
@@ -503,7 +504,6 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
503504
Access_Operation acc_op = GetXrdAccessOperation(open_flags);
504505
{
505506
EXEC_TIMING_BEGIN("IdMap");
506-
507507
std::string validation_path = spath.c_str();
508508

509509
if (spath.beginswith("/zteos64:")) {
@@ -1025,11 +1025,11 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
10251025
if ((fmd = dmd->findFile(fileName))) {
10261026
/* in case of a hard link, may need to switch to target */
10271027
/* A hard link to another file */
1028-
if (fmd->hasAttribute(XrdMgmOfsFile::k_mdino)) {
1028+
if (fmd->hasAttribute(SYS_HARD_LINK)) {
10291029
std::shared_ptr<eos::IFileMD> gmd;
10301030
uint64_t mdino;
10311031

1032-
if (eos::common::StringToNumeric(fmd->getAttribute(XrdMgmOfsFile::k_mdino),
1032+
if (eos::common::StringToNumeric(fmd->getAttribute(SYS_HARD_LINK),
10331033
mdino)) {
10341034
gmd = gOFS->eosFileService->getFileMD(
10351035
eos::common::FileId::InodeToFid(mdino));
@@ -1255,17 +1255,17 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
12551255
}
12561256

12571257
if (!(taccess = dmd->access(vid.uid, vid.gid,
1258-
(isRW) ? W_OK | X_OK : R_OK | X_OK))) {
1259-
eos_debug("fCUid %d dCUid %d uid %d isSharedFile %d isRW %d stdpermcheck %d access %d",
1260-
fmd ? fmd->getCUid() : 0, dmd->getCUid(), vid.uid, isSharedFile, isRW,
1261-
stdpermcheck, taccess);
1262-
1263-
if (!((vid.uid == DAEMONUID) && (isPioReconstruct))) {
1264-
// we don't apply this permission check for reconstruction jobs issued via the daemon account
1265-
errno = EPERM;
1266-
gOFS->MgmStats.Add("OpenFailedPermission", vid.uid, vid.gid, 1);
1267-
return Emsg(epname, error, errno, "open file", path);
1268-
}
1258+
(isRW) ? W_OK | X_OK : R_OK | X_OK))) {
1259+
eos_debug("fCUid %d dCUid %d uid %d isSharedFile %d isRW %d stdpermcheck %d access %d",
1260+
fmd ? fmd->getCUid() : 0, dmd->getCUid(), vid.uid, isSharedFile, isRW,
1261+
stdpermcheck, taccess);
1262+
1263+
if (!((vid.uid == DAEMONUID) && (isPioReconstruct))) {
1264+
// we don't apply this permission check for reconstruction jobs issued via the daemon account
1265+
errno = EPERM;
1266+
gOFS->MgmStats.Add("OpenFailedPermission", vid.uid, vid.gid, 1);
1267+
return Emsg(epname, error, errno, "open file", path);
1268+
}
12691269
}
12701270
}
12711271

0 commit comments

Comments
 (0)