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 <<
"'");
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 Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)