42 const int MAX_ACCESSES = 20;
43 const long long ONE_MB = 1024ll * 1024;
44 const long long ONE_GB = 1024ll * 1024 * 1024;
53 static const char *top_epfx =
"ExecuteCommandUrl ";
59 if (token !=
"xrdpfc_command")
61 TRACE(
Error, top_epfx <<
"First token is NOT xrdpfc_command.");
69 char *t = sp.get_token();
71 return (t[0] ==
'-' && t[1] != 0) ? t[1] : 0;
80 if (token ==
"create_file")
82 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/create_file: ";
83 static const char*
usage =
84 "Usage: create_file/ [-h] [-s filesize] [-b blocksize] [-t access_time] [-d access_duration]/<path>\n"
85 " Creates a cache file with given parameters. Data in file is random.\n"
86 " Useful for cache purge testing.\n"
88 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n"
89 " . Default filesize=1G, blocksize=<as configured>, access_time=-10, access_duration=10.\n"
90 " . -t and -d can be given multiple times to record several accesses.\n"
91 " . Negative arguments given to -t are interpreted as relative to now.\n";
96 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
98 TRACE(
Error, err_prefix <<
"Options section must not be empty, a single space character is OK.");
103 TRACE(
Error, err_prefix <<
"Path section must not be empty.");
107 long long file_size = ONE_GB;
109 int access_time [MAX_ACCESSES];
110 int access_duration[MAX_ACCESSES];
111 int at_count = 0, ad_count = 0;
113 time_t time_now = time(0);
118 while ((theOpt = get_opt(ap)) != (
char) -1)
123 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
128 &file_size, 0ll, 32 * ONE_GB))
134 &block_size, 0ll, 64 * ONE_MB))
140 &access_time[at_count++], INT_MIN, INT_MAX))
146 &access_duration[ad_count++], 0, 24 * 3600))
151 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
157 if (at_count < 1) access_time [at_count++] = time_now - 10;
158 if (ad_count < 1) access_duration[ad_count++] = 10;
160 if (at_count != ad_count)
162 TRACE(
Error, err_prefix <<
"Options -t and -d must be given the same number of times.");
169 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully. Proceeding to create file " << file_path);
173 struct stat infoStat;
176 TRACE(
Error, err_prefix <<
"cinfo file already exists for '" << file_path <<
"'. Refusing to overwrite.");
181 TRACE(
Debug, err_prefix <<
"Command arguments parsed successfully, proceeding to execution.");
189 char size_str[32]; sprintf(size_str,
"%lld", file_size);
190 myEnv.
Put(
"oss.asize", size_str);
200 if ((cret = myFile->
Open(file_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
209 myEnv.
Put(
"oss.asize",
"64k");
214 myFile->
Close();
delete myFile;
219 if ((cret = myInfoFile->
Open(cinfo_path.c_str(), O_RDWR, 0600, myEnv)) !=
XrdOssOK)
223 myFile->
Close();
delete myFile;
229 if ((cret = posix_fallocate(myFile->
getFD(), 0, file_size)))
236 Info myInfo(m_trace,
false);
240 for (
int i = 0; i < at_count; ++i)
242 time_t att_time = access_time[i] >= 0 ? access_time[i] : time_now + access_time[i];
247 myInfo.
Write(myInfoFile, cinfo_path.c_str());
253 struct timespec acc_mod_time[2] = { {last_detach, UTIME_OMIT}, {last_detach, 0} };
255 futimens(myInfoFile->
getFD(), acc_mod_time);
258 myInfoFile->
Close();
delete myInfoFile;
259 myFile->
Close();
delete myFile;
263 TRACE(
Info, err_prefix <<
"Created file '" << file_path <<
"', size=" << (file_size>>20) <<
"MB, "
264 <<
"st_blocks=" << dstat.st_blocks);
269 m_writeQ.writes_between_purges += file_size;
286 else if (token ==
"remove_file")
288 static const char* err_prefix =
"ExecuteCommandUrl: /xrdpfc_command/remove_file: ";
289 static const char*
usage =
290 "Usage: remove_file/ [-h] /<path>\n"
291 " Removes given file from the cache unless it is currently open.\n"
292 " Useful for removal of stale files or duplicate files in a caching cluster.\n"
294 " . If no options are needed one should still leave a space between / separators, ie., '/ /'\n";
297 TRACE(
Debug, err_prefix <<
"Entered with argument string '" << token <<
"'.");
299 TRACE(
Error, err_prefix <<
"Options section must not be empty, a single space character is OK.");
304 TRACE(
Error, err_prefix <<
"Path section must not be empty.");
311 while ((theOpt = get_opt(ap)) != (
char) -1)
316 m_log.
Say(err_prefix,
" -- printing help, no action will be taken\n",
usage);
320 TRACE(
Error, err_prefix <<
"Unhandled command argument.");
328 TRACE(
Debug, err_prefix <<
"file argument '" << f_name <<
"'.");
332 TRACE(
Info, err_prefix <<
"returned with status " << ret);
341 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
virtual int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *envP=0)=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
std::string get_token_as_string()
char * get_reminder_with_delim()