NVMe-cli 설치 및 플러그인 추가

1. 클론/컴파일/설치

git clone https://github.com/linux-nvme/nvme-cli.git
cd nvme-cli
make
make install

# RUN
nvme --version

2. 커스텀 플러그인 추가

플러그인은 todd라는 명으로 추가한다.

mkdir -p plugins/todd
  • plugins/todd/todd-nvme.h

    #undef CMD_INC_FILE
    #define CMD_INC_FILE plugins/todd/todd-nvme
      
    #if !defined(TODD_NVME) || defined(CMD_HEADER_MULTI_READ)
    #define TODD_NVME
      
    #include "cmd.h"
    #include <stdio.h>
      
    PLUGIN(NAME("todd", "Todd plugin"),
            COMMAND_LIST(
                    ENTRY("list","List available FADU devices",todd_list)
            )
    );
      
    #endif
      
    #include "define_cmd.h"
    
  • plugins/todd/todd-nvme.c

    #include "nvme.h"
      
    #define CREATE_CMD
    #include "todd-nvme.h"
      
    static int todd_list(int argc, char **argv, struct command *cmd, struct plugin *plugin){
            printf("Hello world!");
            return 0;
    }
    
  • Makefile

    # 변경전
    PLUGIN_OBJS :=                                  \
            plugins/intel/intel-nvme.o              \
            plugins/lnvm/lnvm-nvme.o                \
            plugins/memblaze/memblaze-nvme.o        \
            plugins/wdc/wdc-nvme.o                  \
            plugins/wdc/wdc-utils.o                 \
            plugins/huawei/huawei-nvme.o            \
            plugins/netapp/netapp-nvme.o            \
            plugins/toshiba/toshiba-nvme.o          \
            plugins/micron/micron-nvme.o            \
            plugins/seagate/seagate-nvme.o          \
            plugins/virtium/virtium-nvme.o          \
            plugins/shannon/shannon-nvme.o          \
            plugins/dera/dera-nvme.o
              
    # 변경후
    PLUGIN_OBJS :=                                  \
            plugins/intel/intel-nvme.o              \
            plugins/lnvm/lnvm-nvme.o                \
            plugins/memblaze/memblaze-nvme.o        \
            plugins/wdc/wdc-nvme.o                  \
            plugins/wdc/wdc-utils.o                 \
            plugins/huawei/huawei-nvme.o            \
            plugins/netapp/netapp-nvme.o            \
            plugins/toshiba/toshiba-nvme.o          \
            plugins/micron/micron-nvme.o            \
            plugins/seagate/seagate-nvme.o          \
            plugins/virtium/virtium-nvme.o          \
            plugins/shannon/shannon-nvme.o          \
            plugins/dera/dera-nvme.o                \
            plugins/todd/todd-nvme.o
      
    
  • 컴파일/설치/실행

    pwd
    /root/nvme-cli
      
    # run on root permission state!
    make clean
    make
    make install
      
    # run 
    /usr/sbin/nvme
    nvme todd list
    

    image-20200423134713400