47 const long long ONE_MB = 1024ll * 1024;
48 const long long ONE_GB = 1024ll * 1024 * 1024;
52 static const char *top_epfx =
"ExecuteCommandUrl ";
58 if (token !=
"xrdpfc_command")
60 TRACE(
Error, top_epfx <<
"First token is NOT xrdpfc_command.");
72 if (token ==
"create_file")
74 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/create_file: ";
75 static const char*
usage =
76 "Usage: create_file/ [-h] [-s filesize] [-b blocksize] [-t access_time] [-d access_duration]/<path>\n"
77 " Creates a cache file with given parameters. Data in file is random.\n"
78 " Useful for cache purge testing.\n"
80 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n"
81 " . Default filesize=1G, blocksize=<as configured>, access_time=-10, access_duration=10.\n"
82 " . -t and -d can be given multiple times to record several accesses.\n"
83 " . Negative arguments given to -t are interpreted as relative to now.\n";
89 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
91 std::vector<char*> argv;
95 long long file_size =
ONE_GB;
99 int at_count = 0, ad_count = 0;
100 XrdOucArgs Spec(&m_log, err_prefix,
"hvs:b:t:d:",
109 time_t time_now = time(0);
111 Spec.
Set(argc, &argv[0]);
114 while ((theOpt = Spec.
getopt()) != (
char) -1)
119 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
124 &file_size, 0ll, 32 *
ONE_GB))
130 &block_size, 0ll, 64 *
ONE_MB))
136 &access_time[at_count++], INT_MIN, INT_MAX))
142 &access_duration[ad_count++], 0, 24 * 3600))
147 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
154 TRACE(
Error, err_prefix <<
"Options must take up all the arguments.");
158 if (at_count < 1) access_time [at_count++] = time_now - 10;
159 if (ad_count < 1) access_duration[ad_count++] = 10;
161 if (at_count != ad_count)
163 TRACE(
Error, err_prefix <<
"Options -t and -d must be given the same number of times.");
170 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully. Proceeding to create file " << file_path);
174 struct stat infoStat;
177 TRACE(
Error, err_prefix <<
"cinfo file already exists for '" << file_path <<
"'. Refusing to overwrite.");
182 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully, proceeding to execution.");
190 char size_str[32]; sprintf(size_str,
"%lld", file_size);
191 myEnv.
Put(
"oss.asize", size_str);
201 if ((cret = myFile->
Open(file_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
210 myEnv.
Put(
"oss.asize",
"64k");
215 myFile->
Close();
delete myFile;
220 if ((cret = myInfoFile->
Open(cinfo_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
224 myFile->
Close();
delete myFile;
230 if ((cret = posix_fallocate(myFile->
getFD(), 0, file_size)))
237 Info myInfo(m_trace,
false);
241 for (
int i = 0; i < at_count; ++i)
243 time_t att_time = access_time[i] >= 0 ? access_time[i] : time_now + access_time[i];
248 myInfo.
Write(myInfoFile, cinfo_path.c_str());
254 struct timespec acc_mod_time[2] = { {last_detach, UTIME_OMIT}, {last_detach, 0} };
256 futimens(myInfoFile->
getFD(), acc_mod_time);
259 myInfoFile->
Close();
delete myInfoFile;
260 myFile->
Close();
delete myFile;
262 TRACE(
Info, err_prefix <<
"Created file '" << file_path <<
"', size=" << (file_size>>20) <<
"MB.");
267 m_writeQ.writes_between_purges += file_size;
273 stats.
m_StBlocksAdded = (file_size & 0x1ff) ? (file_size >> 9) + 1 : file_size >> 9;
284 else if (token ==
"remove_file")
286 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/remove_file: ";
287 static const char*
usage =
288 "Usage: remove_file/ [-h] /<path>\n"
289 " Removes given file from the cache unless it is currently open.\n"
290 " Useful for removal of stale files or duplicate files in a caching cluster.\n"
292 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n";
296 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
298 std::vector<char*> argv;
306 Spec.
Set(argc, &argv[0]);
309 while ((theOpt = Spec.
getopt()) != (
char) -1)
314 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
318 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
325 TRACE(
Error, err_prefix <<
"Options must take up all the arguments.");
331 TRACE(
Debug, err_prefix <<
"file argument '" << f_name <<
"'.");
335 TRACE(
Info, err_prefix <<
"returned with status " << ret);
344 TRACE(
Error, top_epfx <<
"Unknown or empty command '" << token <<
"'");
#define ERRNO_AND_ERRSTR(err_code)
int stat(const char *path, struct stat *buf)
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)
virtual int Stat(const char *url, struct stat &sbuff)
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 GetLatestDetachTime(time_t &t) const
Get latest detach time.
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)
int register_file_open(const std::string &filename, time_t open_timestamp, bool existing_file)
void register_file_update_stats(int token_id, const Stats &stats)
void register_file_close(int token_id, time_t close_timestamp, const Stats &full_stats)
Statistics of cache utilisation by a File object.
long long m_StBlocksAdded
number of 512-byte blocks the file has grown by
long long m_BytesWritten
number of bytes written to disk
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
int fill_argv(std::vector< char * > &argv)
char * get_reminder_with_delim()