XRootD
Loading...
Searching...
No Matches
XrdOssMirageXAttr Class Reference

#include <XrdOssMirageXAttr.hh>

Inheritance diagram for XrdOssMirageXAttr:
Collaboration diagram for XrdOssMirageXAttr:

Public Member Functions

 XrdOssMirageXAttr ()=default
virtual ~XrdOssMirageXAttr ()=default
virtual int Del (const char *Aname, const char *Path, int fd=-1) override
virtual void Free (AList *aPL) override
virtual int Get (const char *Aname, void *Aval, int Avsz, const char *Path, int fd=-1) override
virtual int List (AList **aPL, const char *Path, int fd=-1, int getSz=0) override
virtual int Set (const char *Aname, const void *Aval, int Avsz, const char *Path, int fd=-1, int isNew=0) override
void setOss (XrdOssMirage &oss)
Public Member Functions inherited from XrdSysXAttr
 XrdSysXAttr ()
 Constructor and Destructor.
virtual ~XrdSysXAttr ()
virtual int Copy (const char *iPath, int iFD, const char *oPath, int oFD, const char *Aname=0)
virtual XrdSysError * SetMsgRoute (XrdSysError *errP)

Additional Inherited Members

Protected Attributes inherited from XrdSysXAttr
XrdSysError * Say

Detailed Description

Definition at line 10 of file XrdOssMirageXAttr.hh.

Constructor & Destructor Documentation

◆ XrdOssMirageXAttr()

XrdOssMirageXAttr::XrdOssMirageXAttr ( )
default

Referenced by XrdSysGetXAttrObject().

Here is the caller graph for this function:

◆ ~XrdOssMirageXAttr()

virtual XrdOssMirageXAttr::~XrdOssMirageXAttr ( )
virtualdefault

References Del(), Free(), Get(), List(), Path, Set(), and setOss().

Here is the call graph for this function:

Member Function Documentation

◆ Del()

int XrdOssMirageXAttr::Del ( const char * Aname,
const char * Path,
int fd = -1 )
overridevirtual

Remove an extended attribute.

Parameters
Aname-> The attribute name.
Path-> Path of the file whose attribute is to be removed.
fdIf >=0 is the file descriptor of the opened subject file.
Returns
=0 Attribute was successfully removed.
<0 Attribute was not removed or does not exist. The return value is -errno that describes the reason for the failure.

Implements XrdSysXAttr.

Definition at line 20 of file XrdOssMirageXAttr.cc.

21{
22 if (this->oss == nullptr)
23 return -ENOTSUP;
24
25 const auto opt = oss->get_entry_write(Path);
26 if (!opt.has_value())
27 return -EINVAL;
28
29 auto entry = opt.value();
30
31 const std::string_view name{Aname};
32
33 if (name == "U.open.return_code"sv)
34 entry->open.return_code = {};
35 else if (name == "U.close.return_code"sv)
36 entry->close.return_code = {};
37 else if (name == "U.read.return_code"sv)
38 entry->read.return_code = {};
39 else if (name == "U.read.return_position"sv)
40 entry->read.return_position = {};
41 else if (name == "U.write.return_code"sv)
42 entry->write.return_code = {};
43 else if (name == "U.write.return_position"sv)
44 entry->write.return_position = {};
45 else if (name == "U.pattern"sv)
46 entry->pattern = {};
47 else
48 return -EINVAL;
49
50 return 0;
51}
XrdOucString Path

References Path.

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

◆ Free()

void XrdOssMirageXAttr::Free ( AList * aPL)
overridevirtual

Release storage occupied by the Alist structure returned by List().

Parameters
aPL-> The first element of the AList structure.

Implements XrdSysXAttr.

Definition at line 53 of file XrdOssMirageXAttr.cc.

54{
55}

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

◆ Get()

int XrdOssMirageXAttr::Get ( const char * Aname,
void * Aval,
int Avsz,
const char * Path,
int fd = -1 )
overridevirtual

Get an attribute value and its size.

Parameters
Aname-> The attribute name.
Aval-> Buffer to receive the attribute value.
AvszLength of the buffer in bytes. Only up to this number of bytes should be returned. However, should Avsz be zero the the size of the attribute value should be returned and the Aval argument should be ignored.
Path-> Path of the file whose attribute is to be fetched.
fd-> If >=0 is the file descriptor of the opened subject file.
Returns
>0 The number of bytes placed in Aval. However, if avsz is zero then the value is the actual size of the attribute value.
=0 The attribute exists but has no associated value.
<0 The attribute value could not be returned. The returned value is -errno describing the reason.

Implements XrdSysXAttr.

Definition at line 57 of file XrdOssMirageXAttr.cc.

58{
59 if (this->oss == nullptr)
60 return -ENOTSUP;
61
62 const auto opt = oss->get_entry_read(Path);
63 if (!opt.has_value())
64 return -EINVAL;
65
66 const auto entry = opt.value();
67
68 const std::string_view name{Aname};
69 std::string value{};
70
71 if (name == "U.open.return_code"sv)
72 value = std::to_string(entry.open.return_code);
73 else if (name == "U.close.return_code"sv)
74 value = std::to_string(entry.close.return_code);
75 else if (name == "U.read.return_code"sv)
76 value = std::to_string(entry.read.return_code);
77 else if (name == "U.read.return_position"sv)
78 value = std::to_string(entry.read.return_position);
79 else if (name == "U.write.return_code"sv)
80 value = std::to_string(entry.write.return_code);
81 else if (name == "U.write.return_position"sv)
82 value = std::to_string(entry.write.return_position);
83 else if (name == "U.pattern"sv)
84 value = entry.pattern;
85 else
86 return -EINVAL;
87
88 const int num_bytes = std::min(static_cast<std::size_t>(Avsz), value.size());
89 std::copy_n(value.begin(), num_bytes, static_cast<char *>(Aval));
90
91 return num_bytes;
92}

References Path.

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

◆ List()

int XrdOssMirageXAttr::List ( AList ** aPL,
const char * Path,
int fd = -1,
int getSz = 0 )
overridevirtual

Get all of the attributes associated with a file.

Parameters
aPL-> the pointer to hold the first element of AList. The storage occupied by the returned AList must be released by calling Free().
Path-> Path of the file whose attributes are t be returned.
fd-> If >=0 is the file descriptor of the opened subject file.
getSzWhen != 0 then the size of the maximum attribute value should be returned. Otherwise, upon success 0 is returned.
Returns
>0 Attributes were returned and aPL points to the first attribute value. The returned value is the largest size of an attribute value encountered (getSz != 0).
=0 Attributes were returned and aPL points to the first attribute value (getSz == 0).
<0 The attribute values could not be returned. The returned value is -errno describing the reason.

Implements XrdSysXAttr.

Definition at line 94 of file XrdOssMirageXAttr.cc.

95{
96 return -ENOTSUP;
97}

References Path.

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

◆ Set()

int XrdOssMirageXAttr::Set ( const char * Aname,
const void * Aval,
int Avsz,
const char * Path,
int fd = -1,
int isNew = 0 )
overridevirtual

Set an attribute.

Parameters
Aname-> The attribute name.
Aval-> Buffer holding the attribute value.
AvszLength of the buffer in bytes. This is the length of the attribute value which may contain binary data.
Path-> Path of the file whose attribute is to be set.
fd-> If >=0 is the file descriptor of the opened subject file.
isNewWhen !0 then the attribute must not exist (i.e. new). Otherwise, if it does exist, the value is replaced. In either case, if it does not exist it should be created.
Returns
=0 The attribute was successfully set.
<0 The attribute values could not be set. The returned value is -errno describing the reason.

Implements XrdSysXAttr.

Definition at line 99 of file XrdOssMirageXAttr.cc.

100{
101 if (this->oss == nullptr)
102 return -ENOTSUP;
103
104 const auto opt = oss->get_entry_write(Path);
105 if (!opt.has_value())
106 return -EINVAL;
107
108 auto entry = opt.value();
109
110 const std::string_view name{Aname};
111 const std::string value(static_cast<const char *>(Aval), Avsz);
112
113 try
114 {
115 constexpr static auto parse_return_code = [](auto value) {
116
117 auto code = std::stoi(value);
118 if (code < 0)
119 throw std::invalid_argument("return code is negative");
120
121 return code;
122 };
123
124 constexpr static auto parse_return_position = [](auto value) {
125
126 auto position = std::stoll(value);
127 if (position < 0)
128 throw std::invalid_argument("return position is negative");
129 if (static_cast<std::uint64_t>(position) > XrdOssMirageEntry::max_file_size)
130 throw std::invalid_argument("return position is greater than the max file size");
131
132 return position;
133 };
134
135 if (name == "U.open.return_code"sv)
136 entry->open.return_code = parse_return_code(value);
137 else if (name == "U.close.return_code"sv)
138 entry->close.return_code = parse_return_code(value);
139 else if (name == "U.read.return_code"sv)
140 entry->read.return_code = parse_return_code(value);
141 else if (name == "U.read.return_position"sv)
142 entry->read.return_position = parse_return_position(value);
143 else if (name == "U.write.return_code"sv)
144 entry->write.return_code = parse_return_code(value);
145 else if (name == "U.write.return_position"sv)
146 entry->write.return_position = parse_return_position(value);
147 else if (name == "U.pattern"sv)
148 entry->pattern = value;
149 else
150 return -EINVAL;
151 }
152 catch(std::out_of_range &)
153 {
154 return -ERANGE;
155 }
156 catch(std::invalid_argument &)
157 {
158 return -EINVAL;
159 }
160
161 return 0;
162}
static constexpr std::uint64_t max_file_size

References XrdOssMirageEntry::max_file_size, and Path.

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

◆ setOss()

void XrdOssMirageXAttr::setOss ( XrdOssMirage & oss)

Definition at line 164 of file XrdOssMirageXAttr.cc.

165{
166 if (this->oss == nullptr)
167 this->oss = &oss;
168}

Referenced by ~XrdOssMirageXAttr().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: