XRootD
XrdClS3Filesystem.hh
Go to the documentation of this file.
1 /******************************************************************************/
2 /* Copyright (C) 2025, Pelican Project, Morgridge Institute for Research */
3 /* */
4 /* This file is part of the XrdClS3 client plugin for XRootD. */
5 /* */
6 /* XRootD is free software: you can redistribute it and/or modify it under */
7 /* the terms of the GNU Lesser General Public License as published by the */
8 /* Free Software Foundation, either version 3 of the License, or (at your */
9 /* option) any later version. */
10 /* */
11 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
12 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
13 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
14 /* License for more details. */
15 /* */
16 /* The copyright holder's institutional names and contributor's names may not */
17 /* be used to endorse or promote products derived from this software without */
18 /* specific prior written permission of the institution or contributor. */
19 /******************************************************************************/
20 
21 #ifndef XRDCLS3_S3FILESYSTEM_HH
22 #define XRDCLS3_S3FILESYSTEM_HH
23 
24 #include "../XrdClHttp/XrdClHttpHeaderCallout.hh"
25 
27 
28 #include <mutex>
29 #include <shared_mutex>
30 #include <string>
31 #include <unordered_map>
32 
33 namespace XrdCl {
34 
35 class Log;
36 
37 }
38 
39 namespace XrdClS3 {
40 
41 class Filesystem final : public XrdCl::FileSystemPlugIn {
42 public:
43  Filesystem(const std::string &, XrdCl::Log *log);
44 
45  virtual ~Filesystem() noexcept;
46 
47  virtual XrdCl::XRootDStatus DirList(const std::string &path,
49  XrdCl::ResponseHandler *handler,
50  time_t timeout) override;
51 
52  virtual bool GetProperty(const std::string &name,
53  std::string &value) const override;
54 
55  virtual XrdCl::XRootDStatus Locate(const std::string &path,
57  XrdCl::ResponseHandler *handler,
58  time_t timeout) override;
59 
60  virtual XrdCl::XRootDStatus MkDir(const std::string &path,
63  XrdCl::ResponseHandler *handler,
64  time_t timeout) override;
65 
67  const XrdCl::Buffer &arg,
68  XrdCl::ResponseHandler *handler,
69  time_t timeout) override;
70 
71  virtual XrdCl::XRootDStatus Rm(const std::string &path,
72  XrdCl::ResponseHandler *handler,
73  time_t timeout) override;
74 
75  virtual XrdCl::XRootDStatus RmDir(const std::string &path,
76  XrdCl::ResponseHandler *handler,
77  time_t timeout) override;
78 
79  virtual bool SetProperty(const std::string &name,
80  const std::string &value) override;
81 
82  virtual XrdCl::XRootDStatus Stat(const std::string &path,
83  XrdCl::ResponseHandler *handler,
84  time_t timeout) override;
85 
86 private:
87  // State indicating whether the file is open.
88  bool m_is_opened{false};
89 
90  // Given a path, provide the corresponding HTTP filesystem handle.
91  std::pair<XrdCl::XRootDStatus, XrdCl::FileSystem*> GetFSHandle(const std::string &path);
92 
93  // Logger object for the filesystem
94  XrdCl::Log *m_logger{nullptr};
95 
96  // The pelican://-URL represented by this filesystem object.
97  XrdCl::URL m_url;
98 
99  // Properties set/get on this filesystem
100  std::unordered_map<std::string, std::string> m_properties;
101 
102  // Protects the m_properties data from concurrent access
103  mutable std::mutex m_properties_mutex;
104 
105  // Protects the m_handles data from concurrent access
106  std::shared_mutex m_handles_mutex;
107 
108  // HTTPS handles for the corresponding endpoints.
109  mutable std::unordered_map<std::string, XrdCl::FileSystem*> m_handles;
110 
111  // Class for setting up the required HTTP headers for S3 requests
112  class S3HeaderCallout : public XrdClHttp::HeaderCallout {
113  public:
114  S3HeaderCallout(Filesystem &fs) : m_parent(fs)
115  {}
116 
117  virtual ~S3HeaderCallout() noexcept = default;
118 
119  virtual std::shared_ptr<HeaderList> GetHeaders(const std::string &verb,
120  const std::string &url,
121  const HeaderList &headers) override;
122 
123  private:
124  Filesystem &m_parent;
125  };
126 
127  S3HeaderCallout m_header_callout{*this};
128 };
129 
130 }
131 
132 #endif // XRDCLS3_S3FILESYSTEM_HH
virtual XrdCl::XRootDStatus MkDir(const std::string &path, XrdCl::MkDirFlags::Flags flags, XrdCl::Access::Mode mode, XrdCl::ResponseHandler *handler, time_t timeout) override
Filesystem(const std::string &, XrdCl::Log *log)
virtual bool SetProperty(const std::string &name, const std::string &value) override
virtual XrdCl::XRootDStatus DirList(const std::string &path, XrdCl::DirListFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Rm(const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Stat(const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Locate(const std::string &path, XrdCl::OpenFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual ~Filesystem() noexcept
virtual XrdCl::XRootDStatus RmDir(const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual bool GetProperty(const std::string &name, std::string &value) const override
virtual XrdCl::XRootDStatus Query(XrdCl::QueryCode::Code queryCode, const XrdCl::Buffer &arg, XrdCl::ResponseHandler *handler, time_t timeout) override
Binary blob representation.
Definition: XrdClBuffer.hh:34
An interface for file plug-ins.
Handle diagnostics.
Definition: XrdClLog.hh:101
Handle an async response.
URL representation.
Definition: XrdClURL.hh:31
XrdSysError Log
Definition: XrdConfig.cc:113
Mode
Access mode.
Flags
Open flags, may be or'd when appropriate.
Code
XRootD query request codes.