Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user.external_url extended attribute (replaces #2924) #3101

Merged
merged 3 commits into from Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions cvmfs/magic_xattr.cc
Expand Up @@ -64,6 +64,7 @@ MagicXattrManager::MagicXattrManager(MountPoint *mountpoint,
Register("xfsroot.rawlink", new RawlinkMagicXattr());

Register("user.authz", new AuthzMagicXattr());
Register("user.external_url", new ExternalURLMagicXattr());
}

std::string MagicXattrManager::GetListString(catalog::DirectoryEntry *dirent) {
Expand Down Expand Up @@ -547,3 +548,24 @@ std::string UsedDirPMagicXattr::GetValue() {
std::string VersionMagicXattr::GetValue() {
return std::string(VERSION) + "." + std::string(CVMFS_PATCH_LEVEL);
}

std::string ExternalURLMagicXattr::GetValue() {
std::vector<std::string> host_chain;
std::vector<int> rtt;
unsigned current_host;
if (mount_point_->external_download_mgr() != NULL) {
mount_point_->external_download_mgr()->GetHostInfo(
&host_chain, &rtt, &current_host);
if (host_chain.size()) {
return std::string(host_chain[current_host]) + std::string(path_.c_str());
}
} else {
return std::string("");
}
}

bool ExternalURLMagicXattr::PrepareValueFenced() {
return dirent_->IsRegular() && dirent_->IsExternalFile();
}


5 changes: 5 additions & 0 deletions cvmfs/magic_xattr.h
Expand Up @@ -363,4 +363,9 @@ class VersionMagicXattr : public BaseMagicXattr {
virtual std::string GetValue();
};

class ExternalURLMagicXattr : public BaseMagicXattr {
virtual bool PrepareValueFenced();
virtual std::string GetValue();
};

#endif // CVMFS_MAGIC_XATTR_H_
19 changes: 18 additions & 1 deletion test/src/615-externaldata/main
@@ -1,12 +1,24 @@

cvmfs_test_name="External data"
cvmfs_test_autofs_on_startup=false
cvmfs_test_suites="quick"

is_external_file() {
local full_file_path="$1"
[ x"$(attr -qg external_file "$full_file_path")" = x"1" ]
}

has_correct_external_url() {
cvmfs_mntpnt=${1}
external_base=${2}
filename=${3}

local cvmfs_fullpath=$cvmfs_mntpnt/$filename
local external_fullpath=$external_base/$filename

[ x"$(attr -qg external_url "$cvmfs_fullpath")" = x"$external_fullpath" ]
}

get_content_hash() {
local full_file_path="$1"
attr -qg hash "$full_file_path"
Expand Down Expand Up @@ -159,6 +171,10 @@ cvmfs_run_test() {
echo "Chunk count is $chunk_count"
return 28
fi
if ! has_correct_external_url ${cvmfs_mnt} $external_http_base chunked_file ; then
echo "External URL of chunked file points to the wrong place."
return 29
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Expand Down Expand Up @@ -221,7 +237,8 @@ cvmfs_run_test() {
##############################################################################

# This part has to be second last


echo "*** Cleanup: Remove files"
start_transaction $CVMFS_TEST_REPO || return $?
is_external_file ${cvmfs_mnt}/external/file || return 90
is_external_file ${cvmfs_mnt}/chunked_file || return 90
Expand Down