Skip to content

Commit caef5af

Browse files
authoredMar 12, 2025··
BackendEngine: Added bookkeeping of custom_params of each backend to the base class. (#16)
* The backend plugin should not modify the passed parameters by the user, so the base class bookkeeps them and gives setter and getter methods to the plugin to access it. * Now plugin can ask for value of a key, or add key/values for default parameters. * Also added an API on the base class to return all the key/values, to be used in the agent API. * Some rearragements in the base backend class to use protected when appropriate. Also the agent name is set only during construction and cannot be modified later. Signed-off-by: Moein Khazraee <[email protected]>
1 parent 8177104 commit caef5af

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed
 

‎include/backend/backend_engine.h

+42-16
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,51 @@
2525
// Base backend engine class for different backend implementations
2626
class nixlBackendEngine {
2727
private:
28-
nixl_backend_t backendType;
28+
// Members that cannot be modified by a child backend and parent bookkeep
29+
nixl_backend_t backendType;
30+
nixl_b_params_t* customParams;
31+
32+
protected:
33+
// Members that can be accessed by the child (localAgent cannot be modified)
34+
bool initErr;
35+
const std::string localAgent;
36+
37+
nixl_status_t setInitParam(const std::string &key, const std::string &value) {
38+
if (customParams->count(key)==0) {
39+
(*customParams)[key] = value;
40+
return NIXL_SUCCESS;
41+
} else {
42+
return NIXL_ERR_NOT_ALLOWED;
43+
}
44+
}
45+
46+
std::string getInitParam(const std::string &key) {
47+
if (customParams->count(key)==0)
48+
return "";
49+
else
50+
return (*customParams)[key];
51+
}
2952

3053
public:
54+
nixlBackendEngine (const nixlBackendInitParams* init_params)
55+
: localAgent(init_params->localAgent) {
56+
57+
this->backendType = init_params->type;
58+
this->initErr = false;
59+
this->customParams = new nixl_b_params_t(*(init_params->customParams));
60+
}
61+
62+
virtual ~nixlBackendEngine () {
63+
delete customParams;
64+
}
65+
66+
bool getInitErr() { return initErr; }
3167
nixl_backend_t getType () const { return backendType; }
68+
nixl_b_params_t getCustomParams () const { return *customParams; }
69+
70+
// The support function determine which methods are necessary by the child backend, and
71+
// if they're called by mistake, they will return error if not implemented by backend.
72+
3273
// Determines if a backend supports remote operations
3374
virtual bool supportsRemote () const = 0;
3475

@@ -42,21 +83,6 @@ class nixlBackendEngine {
4283
// Determines if a backend supports progress thread.
4384
virtual bool supportsProgTh () const = 0;
4485

45-
// The support function determine which methods are necessary by the child backend, and
46-
// if they're called by mistake, they will return error if not implemented by backend.
47-
48-
std::string localAgent;
49-
bool initErr;
50-
51-
nixlBackendEngine (const nixlBackendInitParams* init_params) {
52-
this->backendType = init_params->type;
53-
this->localAgent = init_params->localAgent;
54-
this->initErr = false;
55-
}
56-
57-
virtual ~nixlBackendEngine () = default;
58-
59-
bool getInitErr() { return initErr; }
6086

6187
// *** Pure virtual methods that need to be implemented by any backend *** //
6288

‎include/nixl_types.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ typedef enum {
4141
NIXL_ERR_NOT_FOUND = -3,
4242
NIXL_ERR_NYI = -4,
4343
NIXL_ERR_MISMATCH = -5,
44-
NIXL_ERR_BAD = -6
44+
NIXL_ERR_BAD = -6,
45+
NIXL_ERR_NOT_ALLOWED = -7
4546
} nixl_status_t;
4647

4748
class nixlSerDes;

‎src/nixl_agent.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ nixlBackendH* nixlAgent::createBackend(const nixl_backend_t &type,
9292
nixl_status_t ret;
9393
std::string str;
9494

95-
// Registring same type of backend is not supported, unlikey and prob error
95+
// Registering same type of backend is not supported, unlikely and prob error
9696
if (data->backendEngines.count(type)!=0)
9797
return nullptr;
9898

@@ -116,7 +116,7 @@ nixlBackendH* nixlAgent::createBackend(const nixl_backend_t &type,
116116
}
117117

118118
if (backend!=nullptr) {
119-
if (backend->initErr) {
119+
if (backend->getInitErr()) {
120120
delete backend;
121121
return nullptr;
122122
}
@@ -447,7 +447,7 @@ nixl_status_t nixlAgent::makeXferReq (const nixlXferSideH* local_side,
447447
// }
448448

449449
// Populate has been already done, no benefit in having sorted descriptors
450-
// which will be overwritten by [] assignement operator.
450+
// which will be overwritten by [] assignment operator.
451451
nixlXferReqH *handle = new nixlXferReqH;
452452
handle->initiatorDescs = new nixl_meta_dlist_t (
453453
local_side->descs->getType(),

0 commit comments

Comments
 (0)
Please sign in to comment.