Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:39

0001 #ifndef __XRDPFC_DIRSTATEPURGESHOT_HH__
0002 #define __XRDPFC_DIRSTATEPURGESHOT_HH__
0003 
0004 #include "XrdPfc/XrdPfcDirStateBase.hh"
0005 #include "XrdPfc/XrdPfcPathParseTools.hh"
0006 
0007 namespace XrdPfc
0008 {
0009 struct DirPurgeElement : public DirStateBase
0010 {
0011    DirUsage m_usage;
0012 
0013    int m_parent = -1;
0014    int m_daughters_begin = -1, m_daughters_end = -1;
0015 
0016    DirPurgeElement() {}
0017    DirPurgeElement(const DirStateBase &b, const DirUsage &here_usage, const DirUsage &subdir_usage, int parent) :
0018      DirStateBase(b),
0019      m_usage(here_usage, subdir_usage),
0020      m_parent(parent)
0021    {}
0022 };
0023 
0024 struct DataFsPurgeshot : public DataFsStateBase
0025 {
0026    long long m_bytes_to_remove = 0;
0027    long long m_estimated_writes_from_writeq = 0;
0028 
0029    bool m_space_based_purge = false;
0030    bool m_age_based_purge = false;
0031 
0032    std::vector<DirPurgeElement> m_dir_vec;
0033    // could have parallel vector of DirState* ... or store them in the DirPurgeElement.
0034    // requires some interlock / ref-counting with the source tree.
0035    // or .... just block DirState removal for the duration of the purge :) Yay.
0036 
0037    DataFsPurgeshot() {}
0038    DataFsPurgeshot(const DataFsStateBase &b) :
0039      DataFsStateBase(b)
0040    {}
0041 
0042   int find_dir_entry_from_tok(int entry, PathTokenizer &pt, int pos, int *last_existing_entry) const;
0043 
0044   int find_dir_entry_for_dir_path(const std::string &dir_path) const;
0045 
0046   const DirUsage* find_dir_usage_for_dir_path(const std::string &dir_path) const;
0047 };
0048 
0049 
0050 inline int DataFsPurgeshot::find_dir_entry_from_tok(int entry, PathTokenizer &pt, int pos, int *last_existing_entry) const
0051 {
0052    if (pos == pt.get_n_dirs())
0053       return entry;
0054 
0055    const DirPurgeElement &dpe = m_dir_vec[entry];
0056    for (int i = dpe.m_daughters_begin; i != dpe.m_daughters_end; ++i)
0057    {
0058       if (m_dir_vec[i].m_dir_name == pt.get_dir(pos)) {
0059          return find_dir_entry_from_tok(i, pt, pos + 1, last_existing_entry);
0060       }
0061    }
0062    if (last_existing_entry)
0063       *last_existing_entry = entry;
0064    return -1;
0065 }
0066 
0067 inline int DataFsPurgeshot::find_dir_entry_for_dir_path(const std::string &dir_path) const
0068 {
0069    PathTokenizer pt(dir_path, -1, false);
0070    return find_dir_entry_from_tok(0, pt, 0, nullptr);
0071 }
0072 
0073 inline const DirUsage* DataFsPurgeshot::find_dir_usage_for_dir_path(const std::string &dir_path) const
0074 {
0075    int entry = find_dir_entry_for_dir_path(dir_path);
0076    return entry >= 0 ? &m_dir_vec[entry].m_usage : nullptr;
0077 }
0078 
0079 }
0080 
0081 #endif