@@ -463,6 +463,75 @@ XrdMgmOfsFile::GetXrdAccessOperation(int open_flags)
463463 return op;
464464}
465465
466+
467+
468+ XrdMgmOfsFile::targetParams
469+ XrdMgmOfsFile::setProxyFwEntrypoint (const std::vector<std::string>& firewalleps,
470+ const std::vector<std::string>& proxys,
471+ size_t fsIndex,
472+ std::string_view fs_hostport,
473+ std::string_view fs_prefix)
474+ {
475+
476+ bool hasFirewall = fsIndex < firewalleps.size () &&
477+ !firewalleps[fsIndex].empty ();
478+ bool hasProxy = fsIndex < proxys.size () && !proxys[fsIndex].empty ();
479+ if (!hasFirewall && !hasProxy) {
480+ return {};
481+ }
482+
483+ targetParams out;
484+ // Set the FST gateway for clients who are geo-tagged with default
485+ // Do this with forwarding proxy syntax only if the firewall entrypoint is
486+ // different from the endpoint
487+ if (hasFirewall &&
488+ ((hasProxy && firewalleps[fsIndex] != proxys[fsIndex]) ||
489+ (firewalleps[fsIndex] != fs_hostport))) {
490+ // Build the URL for the forwarding proxy and must have the following
491+ // redirection proxy:port?eos.fstfrw=endpoint:port/abspath
492+ if (auto idx = firewalleps[fsIndex].rfind (' :' );
493+ idx != std::string::npos) {
494+ out.targethost = firewalleps[fsIndex].substr (0 , idx);
495+ out.targetport = atoi (firewalleps[fsIndex].substr (idx + 1 ,
496+ std::string::npos).c_str ());
497+ out.targethttpport = 8001 ;
498+ } else {
499+ out.targethost = firewalleps[fsIndex].c_str ();
500+ out.targetport = 0 ;
501+ out.targethttpport = 8001 ;
502+ }
503+
504+ out.redirectionhost = out.targethost + " :" +
505+ std::to_string (out.targetport ) + " ?eos.fstfrw=" ;
506+ if (hasProxy) {
507+ out.redirectionhost += proxys[fsIndex];
508+ } else {
509+ out.redirectionhost += fs_hostport;
510+ }
511+ } else if (hasProxy) {
512+ if (auto idx = proxys[fsIndex].rfind (' :' );
513+ idx != std::string::npos) {
514+ out.targethost = proxys[fsIndex].substr (0 , idx);
515+ out.targetport = atoi (proxys[fsIndex].substr (idx + 1 , std::string::npos).c_str ());
516+ out.targethttpport = 8001 ;
517+ } else {
518+ out.targethost = proxys[fsIndex];
519+ out.targetport = 0 ;
520+ out.targethttpport = 0 ;
521+ }
522+ out.redirectionhost = out.targethost ;
523+ }
524+
525+ if (hasProxy && !fs_prefix.empty ()) {
526+ std::string _s = " mgm.fsprefix=" ;
527+ _s.append (fs_prefix);
528+ eos::common::replace_all (_s, " :" , " #COL#" );
529+ out.redirectionhost += _s;
530+ out.redirectionsuffix = std::move (_s);
531+ }
532+ return out;
533+ }
534+
466535/* ----------------------------------------------------------------------------*/
467536/*
468537 * @brief open a given file with the indicated mode
@@ -843,7 +912,7 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
843912
844913 int rcode = SFS_ERROR;
845914 XrdOucString redirectionhost = " invalid?" ;
846- XrdOucString targethost = " " ;
915+ std::string targethost;
847916 int targetport = atoi (gOFS ->MgmOfsTargetPort .c_str ());
848917 int targethttpport = gOFS ->mHttpdPort ;
849918 int ecode = 0 ;
@@ -2303,6 +2372,7 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
23032372
23042373 {
23052374 COMMONTIMING (" Scheduler::FileAccess" , &tm);
2375+ // TODO future: this doesn't really require a FsView readlock!
23062376 eos::common::RWMutexReadLock fs_rd_lock (FsView::gFsView .ViewMutex );
23072377 retc = Scheduler::FileAccess (&acsargs);
23082378 COMMONTIMING (" Scheduler::FileAccessed" , &tm);
@@ -2767,90 +2837,21 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
27672837 fs_id = filesystem->GetId ();
27682838 } // fs_rd_lock scope
27692839
2770- // Set the FST gateway for clients who are geo-tagged with default
2771- if ((firewalleps.size () > fsIndex) && (proxys.size () > fsIndex)) {
2772- // Do this with forwarding proxy syntax only if the firewall entrypoint is
2773- // different from the endpoint
2774- if (!(firewalleps[fsIndex].empty ()) &&
2775- ((!proxys[fsIndex].empty () && firewalleps[fsIndex] != proxys[fsIndex]) ||
2776- (firewalleps[fsIndex] != fs_hostport))) {
2777- // Build the URL for the forwarding proxy and must have the following
2778- // redirection proxy:port?eos.fstfrw=endpoint:port/abspath
2779- auto idx = firewalleps[fsIndex].rfind (' :' );
2780-
2781- if (idx != std::string::npos) {
2782- targethost = firewalleps[fsIndex].substr (0 , idx).c_str ();
2783- targetport = atoi (firewalleps[fsIndex].substr (idx + 1 ,
2784- std::string::npos).c_str ());
2785- targethttpport = 8001 ;
2786- } else {
2787- targethost = firewalleps[fsIndex].c_str ();
2788- targetport = 0 ;
2789- targethttpport = 8001 ;
2790- }
2791-
2792- std::ostringstream oss;
2793- oss << targethost << " ?" << " eos.fstfrw=" ;
2794-
2795- // Check if we have to redirect to the fs host or to a proxy
2796- if (proxys[fsIndex].empty ()) {
2797- oss << fs_host << " :" << fs_port;
2798- } else {
2799- oss << proxys[fsIndex];
2800- }
2801-
2802- redirectionhost = oss.str ().c_str ();
2803- redirectionhost += " &" ;
2804- } else {
2805- if (proxys[fsIndex].empty ()) { // there is no proxy to use
2806- targethost = fs_host.c_str ();
2807- targetport = atoi (fs_port.c_str ());
2808- targethttpport = atoi (fs_http_port.c_str ());
2809-
2810- // default xrootd & http port
2811- if (!targetport) {
2812- targetport = 1095 ;
2813- }
2814-
2815- if (!targethttpport) {
2816- targethttpport = 8001 ;
2817- }
2818- } else { // we have a proxy to use
2819- auto idx = proxys[fsIndex].rfind (' :' );
2820-
2821- if (idx != std::string::npos) {
2822- targethost = proxys[fsIndex].substr (0 , idx).c_str ();
2823- targetport = atoi (proxys[fsIndex].substr (idx + 1 , std::string::npos).c_str ());
2824- targethttpport = 8001 ;
2825- } else {
2826- targethost = proxys[fsIndex].c_str ();
2827- targetport = 0 ;
2828- targethttpport = 0 ;
2829- }
2830- }
2831-
2832- redirectionhost = targethost;
2833- redirectionhost += " ?" ;
2834- }
2835-
2836- if (!proxys[fsIndex].empty ()) {
2837- if (!(fs_prefix.empty ())) {
2838- XrdOucString s = " mgm.fsprefix" ;
2839- s += " =" ;
2840- s += fs_prefix.c_str ();
2841- s.replace (" :" , " #COL#" );
2842- redirectionhost += s;
2843- }
2844- }
2840+ if (auto result = setProxyFwEntrypoint (firewalleps, proxys, fsIndex,
2841+ fs_hostport, fs_prefix);
2842+ result.valid ()) {
2843+ targetport = result.targetport ;
2844+ targethttpport = result.targethttpport ;
2845+ targethost = std::move (result.targethost );
2846+ redirectionhost = result.redirectionhost .c_str ();
28452847 } else {
28462848 // There is no proxy or firewall entry point to use
28472849 targethost = fs_host.c_str ();
28482850 targetport = atoi (fs_port.c_str ());
28492851 targethttpport = atoi (fs_http_port.c_str ());
2850- redirectionhost = targethost;
2852+ redirectionhost = targethost. c_str () ;
28512853 redirectionhost += " ?" ;
28522854 }
2853-
28542855 // ---------------------------------------------------------------------------
28552856 // Rebuild the layout ID (for read it should indicate only the number of
28562857 // available stripes for reading);
@@ -3114,78 +3115,41 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
31143115 " path=\" %s\" fsid=%d" , path, selectedfs[i]);
31153116 continue ;
31163117 }
3117-
3118+ std::string replicahost;
3119+ std::string redirectionsuffix;
3120+ int replicaport{0 };
3121+ bool hasreplaceProxy {false };
31183122 if (replace) {
31193123 fsIndex = i;
31203124
3121- // Set the FST gateway if this is available otherwise the actual FST
3122- if ((firewalleps.size () > fsIndex) && (proxys.size () > fsIndex) &&
3123- !(firewalleps[fsIndex].empty ()) &&
3124- ((!proxys[fsIndex].empty () && firewalleps[fsIndex] != proxys[fsIndex]) ||
3125- (firewalleps[fsIndex] != repfilesystem->GetString (" hostport" )))) {
3126- // Build the URL for the forwarding proxy and must have the following
3127- // redirection proxy:port?eos.fstfrw=endpoint:port/abspath
3128- auto idx = firewalleps[fsIndex].rfind (' :' );
3129-
3130- if (idx != std::string::npos) {
3131- targethost = firewalleps[fsIndex].substr (0 , idx).c_str ();
3132- targetport = atoi (firewalleps[fsIndex].substr (idx + 1 ,
3133- std::string::npos).c_str ());
3134- targethttpport = 8001 ;
3135- } else {
3136- targethost = firewalleps[fsIndex].c_str ();
3137- targetport = 0 ;
3138- targethttpport = 0 ;
3139- }
3140-
3141- std::ostringstream oss;
3142- oss << targethost << " ?"
3143- << " eos.fstfrw=" ;
3144-
3145- // check if we have to redirect to the fs host or to a proxy
3146- if (proxys[fsIndex].empty ()) {
3147- oss << repfilesystem->GetString (" host" ).c_str () << " :"
3148- << repfilesystem->GetString (" port" ).c_str ();
3149- } else {
3150- oss << proxys[fsIndex];
3151- }
3152-
3153- redirectionhost = oss.str ().c_str ();
3125+ if (auto result = setProxyFwEntrypoint (firewalleps, proxys,
3126+ fsIndex,
3127+ repfilesystem->GetString (" hostport" ),
3128+ repfilesystem->GetPath ());
3129+ result.valid ()) {
3130+ targetport = result.targetport ;
3131+ targethttpport = result.targethttpport ;
3132+ targethost = std::move (result.targethost );
3133+ redirectionhost = result.redirectionhost .c_str ();
3134+ redirectionsuffix = std::move (result.redirectionsuffix );
3135+ hasreplaceProxy = true ;
31543136 } else {
3155- if ((proxys.size () > fsIndex) && !proxys[fsIndex].empty ()) {
3156- // We have a proxy to use
3157- (void ) proxys[fsIndex].c_str ();
3158- auto idx = proxys[fsIndex].rfind (' :' );
3159-
3160- if (idx != std::string::npos) {
3161- targethost = proxys[fsIndex].substr (0 , idx).c_str ();
3162- targetport = atoi (proxys[fsIndex].substr (idx + 1 , std::string::npos).c_str ());
3163- targethttpport = 8001 ;
3164- } else {
3165- targethost = proxys[fsIndex].c_str ();
3166- targetport = 0 ;
3167- targethttpport = 0 ;
3168- }
3169- } else {
31703137 // There is no proxy to use
3171- targethost = repfilesystem->GetString (" host" ).c_str ();
3172- targetport = atoi (repfilesystem->GetString (" port" ).c_str ());
3173- targethttpport = atoi (repfilesystem->GetString (" stat.http.port" ).c_str ());
3174- }
3175-
3176- redirectionhost = targethost;
3138+ targethost = repfilesystem->GetString (" host" ).c_str ();
3139+ targetport = atoi (repfilesystem->GetString (" port" ).c_str ());
3140+ targethttpport = atoi (repfilesystem->GetString (" stat.http.port" ).c_str ());
3141+ redirectionhost = targethost.c_str ();
31773142 redirectionhost += " ?" ;
3143+ replicahost += repfilesystem->GetString (" host" ).c_str ();
3144+ replicaport = atoi (repfilesystem->GetString (" port" ).c_str ());
31783145 }
3179-
31803146 // point at the right vector entry
31813147 fsIndex = i;
31823148 }
31833149
31843150 capability += " &mgm.url" ;
31853151 capability += (int ) i;
31863152 capability += " =root://" ;
3187- XrdOucString replicahost = " " ;
3188- int replicaport = 0 ;
31893153
31903154 // -----------------------------------------------------------------------
31913155 // Logic to mask 'offline' filesystems
@@ -3197,25 +3161,24 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
31973161 }
31983162 }
31993163
3200- if ((proxys.size () > i) && !proxys[i].empty ()) {
3201- // We have a proxy to use
3202- auto idx = proxys[i].rfind (' :' );
3203-
3204- if (idx != std::string::npos) {
3205- replicahost = proxys[i].substr (0 , idx).c_str ();
3206- replicaport =
3207- atoi (proxys[i].substr (idx + 1 , std::string::npos).c_str ());
3208- } else {
3209- replicahost = proxys[i].c_str ();
3210- replicaport = 0 ;
3211- }
3212- } else {
3213- // There is no proxy to use
3214- replicahost += repfilesystem->GetString (" host" ).c_str ();
3215- replicaport = atoi (repfilesystem->GetString (" port" ).c_str ());
3164+ replicahost = repfilesystem->GetString (" host" );
3165+ replicaport = atoi (repfilesystem->GetString (" port" ).c_str ());
3166+ // if there was a replacement and proxy, copy replica
3167+ // details from target
3168+ if (hasreplaceProxy) {
3169+ replicahost = targethost;
3170+ replicaport = targetport;
3171+ } else if (auto result = setProxyFwEntrypoint (firewalleps, proxys,
3172+ i,
3173+ repfilesystem->GetString (" hostport" ),
3174+ repfilesystem->GetPath ());
3175+ result.valid ()) {
3176+ replicahost = std::move (result.targethost );
3177+ replicaport = result.targetport ;
3178+ redirectionsuffix = std::move (result.redirectionsuffix );
32163179 }
32173180
3218- capability += replicahost;
3181+ capability += replicahost. c_str () ;
32193182 capability += " :" ;
32203183 capability += replicaport;
32213184 capability += " //" ;
@@ -3225,17 +3188,9 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
32253188 capability += " =" ;
32263189 capability += (int )repfilesystem->GetId ();
32273190
3228- if ((proxys.size () > i) && !proxys[i].empty ()) {
3229- std::string fsprefix = repfilesystem->GetPath ();
3230-
3231- if (!fsprefix.empty ()) {
3232- XrdOucString s = " mgm.fsprefix" ;
3233- s += (int )i;
3234- s += " =" ;
3235- s += fsprefix.c_str ();
3236- s.replace (" :" , " #COL#" );
3237- capability += s;
3238- }
3191+ // If there was a proxy redirection add this to the cap
3192+ if (!redirectionsuffix.empty ()) {
3193+ capability += redirectionsuffix.c_str ();
32393194 }
32403195
32413196 if (isPio) {
@@ -3250,7 +3205,7 @@ XrdMgmOfsFile::open(eos::common::VirtualIdentity* invid,
32503205 piolist += " pio." ;
32513206 piolist += (int )i;
32523207 piolist += " =" ;
3253- piolist += replicahost;
3208+ piolist += replicahost. c_str () ;
32543209 piolist += " :" ;
32553210 piolist += replicaport;
32563211 piolist += " &" ;
0 commit comments