Github user animeshtrivedi commented on a diff in the pull request:

    https://github.com/apache/incubator-crail/pull/16#discussion_r180313817
  
    --- Diff: 
storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/NvmfStorageServer.java 
---
    @@ -31,51 +28,68 @@
     
     import java.io.IOException;
     import java.net.InetSocketAddress;
    -import java.net.URI;
    +import java.util.List;
     
     public class NvmfStorageServer implements StorageServer {
        private static final Logger LOG = CrailUtils.getLogger();
     
        private boolean isAlive;
        private long alignedSize;
    -   private long offset;
    +   private long address;
        private boolean initialized = false;
    -   private NvmeEndpoint endpoint;
    +   private Controller controller;
     
        public NvmfStorageServer() {}
    -   
    +
        public void init(CrailConfiguration crailConfiguration, String[] args) 
throws Exception {
                if (initialized) {
                        throw new IOException("NvmfStorageTier already 
initialized");
                }
                initialized = true;
                NvmfStorageConstants.parseCmdLine(crailConfiguration, args);
     
    -           NvmeEndpointGroup group = new NvmeEndpointGroup(new 
NvmeTransportType[]{NvmeTransportType.RDMA}, 
NvmfStorageConstants.SERVER_MEMPOOL);
    -           endpoint = group.createEndpoint();
    -
    -           URI uri = new URI("nvmef://" + 
NvmfStorageConstants.IP_ADDR.getHostAddress() + ":" + NvmfStorageConstants.PORT 
+
    -                                   "/0/" + NvmfStorageConstants.NAMESPACE 
+ "?subsystem=" + NvmfStorageConstants.NQN);
    -           endpoint.connect(uri);
    -
    -           long namespaceSize = endpoint.getNamespaceSize();
    +           Nvme nvme = new Nvme();
    +           NvmfTransportId transportId = new NvmfTransportId(
    +                           new 
InetSocketAddress(NvmfStorageConstants.IP_ADDR, NvmfStorageConstants.PORT),
    +                           NvmfStorageConstants.NQN);
    +           controller = nvme.connect(transportId);
    +           controller.getControllerConfiguration().setEnable(true);
    +           controller.syncConfiguration();
    +           controller.waitUntilReady();
    +
    +           List<Namespace> namespaces = controller.getActiveNamespaces();
    +           Namespace namespace = null;
    +           for (Namespace n : namespaces) {
    +                   if 
(n.getIdentifier().equals(NvmfStorageConstants.NAMESPACE)) {
    +                           namespace = n;
    +                           break;
    +                   }
    +           }
    +           if (namespace == null) {
    +                   throw new IllegalArgumentException("No namespace with 
id " + NvmfStorageConstants.NAMESPACE +
    +                                   " at controller " + 
transportId.toString());
    +           }
    +           IdentifyNamespaceData namespaceData = 
namespace.getIdentifyNamespaceData();
    +           LbaFormat lbaFormat = namespaceData.getFormattedLbaSize();
    +           int dataSize = lbaFormat.getLbaDataSize().toInt();
    +           long namespaceSize = dataSize * 
namespaceData.getNamespaceCapacity();
                alignedSize = namespaceSize - (namespaceSize % 
NvmfStorageConstants.ALLOCATION_SIZE);
    -           offset = 0;
    +           address = 0;
     
                isAlive = true;
    -   }       
    +   }
     
        @Override
        public void printConf(Logger log) {
    -           NvmfStorageConstants.printConf(log);            
    +           NvmfStorageConstants.printConf(log);
        }
     
        public void run() {
                LOG.info("NnvmfStorageServer started with NVMf target " + 
getAddress());
                while (isAlive) {
                        try {
                                Thread.sleep(1000 /* ms */);
    --- End diff --
    
    Magic 1000 milliseconds :)


---

Reply via email to