45const long long ONE_MB = 1024ll * 1024;
46const long long ONE_GB = 1024ll * 1024 * 1024;
50 static const char *top_epfx =
"ExecuteCommandUrl ";
56 if (token !=
"xrdpfc_command")
58 TRACE(
Error, top_epfx <<
"First token is NOT xrdpfc_command.");
70 if (token ==
"create_file")
72 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/create_file: ";
73 static const char*
usage =
74 "Usage: create_file/ [-h] [-s filesize] [-b blocksize] [-t access_time] [-d access_duration]/<path>\n"
75 " Creates a cache file with given parameters. Data in file is random.\n"
76 " Useful for cache purge testing.\n"
78 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n"
79 " . Default filesize=1G, blocksize=<as configured>, access_time=-10, access_duration=10.\n"
80 " . -t and -d can be given multiple times to record several accesses.\n"
81 " . Negative arguments given to -t are interpreted as relative to now.\n";
87 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
89 std::vector<char*> argv;
93 long long file_size =
ONE_GB;
97 int at_count = 0, ad_count = 0;
98 XrdOucArgs Spec(&m_log, err_prefix,
"hvs:b:t:d:",
107 time_t time_now = time(0);
109 Spec.
Set(argc, &argv[0]);
112 while ((theOpt = Spec.
getopt()) != (
char) -1)
117 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
122 &file_size, 0ll, 32 *
ONE_GB))
128 &block_size, 0ll, 64 *
ONE_MB))
134 &access_time[at_count++], INT_MIN, INT_MAX))
140 &access_duration[ad_count++], 0, 24 * 3600))
145 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
152 TRACE(
Error, err_prefix <<
"Options must take up all the arguments.");
156 if (at_count < 1) access_time [at_count++] = time_now - 10;
157 if (ad_count < 1) access_duration[ad_count++] = 10;
159 if (at_count != ad_count)
161 TRACE(
Error, err_prefix <<
"Options -t and -d must be given the same number of times.");
168 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully. Proceeding to create file " << file_path);
172 struct stat infoStat;
175 TRACE(
Error, err_prefix <<
"cinfo file already exists for '" << file_path <<
"'. Refusing to overwrite.");
180 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully, proceeding to execution.");
188 char size_str[32]; sprintf(size_str,
"%lld", file_size);
189 myEnv.
Put(
"oss.asize", size_str);
199 if ((cret = myFile->
Open(file_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
208 myEnv.
Put(
"oss.asize",
"64k");
213 myFile->
Close();
delete myFile;
218 if ((cret = myInfoFile->
Open(cinfo_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
222 myFile->
Close();
delete myFile;
228 if ((cret = posix_fallocate(myFile->
getFD(), 0, file_size)))
235 Info myInfo(m_trace,
false);
239 for (
int i = 0; i < at_count; ++i)
241 time_t att_time = access_time[i] >= 0 ? access_time[i] : time_now + access_time[i];
246 myInfo.
Write(myInfoFile, cinfo_path.c_str());
248 myInfoFile->
Close();
delete myInfoFile;
249 myFile->
Close();
delete myFile;
251 TRACE(
Info, err_prefix <<
"Created file '" << file_path <<
"', size=" << (file_size>>20) <<
"MB.");
256 m_writeQ.writes_between_purges += file_size;
265 else if (token ==
"remove_file")
267 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/remove_file: ";
268 static const char*
usage =
269 "Usage: remove_file/ [-h] /<path>\n"
270 " Removes given file from the cache unless it is currently open.\n"
271 " Useful for removal of stale files or duplicate files in a caching cluster.\n"
273 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n";
277 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
279 std::vector<char*> argv;
283 XrdOucArgs Spec(&m_log, err_prefix,
"hvs:b:t:d:",
287 Spec.
Set(argc, &argv[0]);
290 while ((theOpt = Spec.
getopt()) != (
char) -1)
295 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
299 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
306 TRACE(
Error, err_prefix <<
"Options must take up all the arguments.");
312 TRACE(
Debug, err_prefix <<
"file argument '" << f_name <<
"'.");
316 TRACE(
Info, err_prefix <<
"returned with status " << ret);
325 TRACE(
Error, top_epfx <<
"Unknown or empty command '" << token <<
"'");
#define ERRNO_AND_ERRSTR(err_code)
virtual int Close(long long *retsz=0)=0
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
virtual XrdOssDF * newFile(const char *tident)=0
void Put(const char *varname, const char *value)
static int a2i(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
void ExecuteCommandUrl(const std::string &command_url)
int UnlinkFile(const std::string &f_name, bool fail_if_open)
Remove cinfo and data files from cache.
Status of cached file. Can be read from and written into a binary file.
static const char * s_infoExtension
void WriteIOStatSingle(long long bytes_disk)
Write single open/close time for given bytes read from disk.
bool Write(XrdOssDF *fp, const char *dname, const char *fname=0)
void SetAllBitsSynced()
Mark all blocks as synced to disk.
void SetBufferSizeFileSizeAndCreationTime(long long bs, long long fs)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
Contains parameters configurable from the xrootd config file.
std::string m_data_space
oss space for data files
long long m_bufferSize
prefetch buffer size, default 1MB
std::string m_meta_space
oss space for metadata files (cinfo)
std::string m_username
username passed to oss plugin
char * get_reminder_with_delim()
int fill_argv(std::vector< char * > &argv)