Skip to content

Add cmd to framework

thokala edited this page Nov 15, 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 and all the commands are derived from the base "Cmd" class. For example, if the cmd you are adding is Asynchronous event request cmd, then name your class as AsyncEventReq and super class for this cmd is Cmd, file names for this class are asyncEventReq.cpp and asyncEventReq.h. Place them in tnvme/Cmds directory. 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.

#Tracking new command objects: 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. The framework uses boost library and shared pointers in order to track their creation and destruction automatically. Refer to https://github.com/nvmecompliance/tnvme/wiki/Resource-Manager for full details.

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 as new enum definition in "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 add relevant description for this object.

#Update Singletons 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