Skip to content

Add cmd to framework

thokala edited this page Nov 9, 2012 · 6 revisions

Commands are represented in tnvme as a C++ classes in tnvme/Cmds directory. For details of commands, refer to https://github.com/nvmecompliance/tnvme/wiki/Commands.

Details on how to add a cmd to framework.

Create a C++ class in tnvme/Cmds directory, use the new command name as the name of this class. For example if the cmd you are adding to the framework is Async Event Request Cmd, then the name of the class should be AsyncEventReq in tnvme/Cmds directory. The files which contain these classes are named as asyncEventReq.cpp and asyncEventReq.h.

All the commands are derived from the base Cmd class. The resource manager is used to track the objects that are created and destroyed. The new cmd that you are about to add is also a resource so the framework uses boost library and shared pointers in order to track their creation and destruction. Refer to https://github.com/nvmecompliance/tnvme/wiki/Resource-Manager for full details.

In general, use any already existing classes to clone. For example copy Cmds/asyncEventReq.h and Cmds/asyncEventReq.cpp to build your cmd Cmds/yourCmd.h and Cmds/yourCmd.cpp files. Rename the variables correctly to your cmd name. Replace the opcode in cpp file to your cmd's opcode. Determine if the command uses any data buffers and add prp mask support, data direction accordingly.

The trackable in the default method requires you to provide a name and you should follow already used object naming convention <OBJ_YOURCMD>. This object should be added in enum definition of the tnvme/trackable.h file for ObjType. Open the file tnvme/trackable.cpp file and in the method Trackable::GetObjName(ObjType obj) add new case statement for your object and description for this new object.

The last step in adding this object to the framework is to update Singletons/ObjRsrc.cpp file. Open tnvme/Singletons/ObjRsrc.cpp file and add YOURCMD with your class name in the AllocWorker() method using INSTANTIATE_OBJ macro. For the above asyncEvenReq cmd example the marco will be INSTANTIATE_OBJ(ASYNCEVENTREQ, AsyncEventReq). Don't forget to include the header file of your class in Singletons/ObjRsrc.cpp file.

Now you should be able to wire this new command in any of the tnvme test.

Clone this wiki locally