diff --git a/src/nfs/nfs_proxy.cpp b/src/nfs/nfs_proxy.cpp index 3b86c640..386e39b7 100644 --- a/src/nfs/nfs_proxy.cpp +++ b/src/nfs/nfs_proxy.cpp @@ -70,8 +70,10 @@ static const char* help_text = " Start network NFS server. Options:\n" " --bind bind service to address (default 0.0.0.0)\n" " --port use port for NFS services (default is 2049)\n" + " specify \"auto\" to auto-select and print port\n" " --portmap 0 do not listen on port 111 (portmap/rpcbind, requires root)\n" " --nfs_rdma enable NFS-RDMA at RDMA-CM port (you can try 20049)\n" + " if RDMA is enabled and --port is set to 0, TCP will be disabled\n" " --nfs_rdma_credit 16 maximum operation credit for RDMA clients (max iodepth)\n" " --nfs_rdma_send 1024 maximum RDMA send operation count (should be larger than iodepth)\n" " --nfs_rdma_alloc 1M RDMA memory allocation rounding\n" @@ -205,8 +207,10 @@ void nfs_proxy_t::run(json11::Json cfg) nfs_port = cfg["port"].uint64_value() & 0xffff; nfs_rdma_port = cfg["nfs_rdma"].uint64_value() & 0xffff; // Allow RDMA-only mode if port is explicitly set to 0 + // Allow port auto-selection in server mode if explicitly set to --port auto + nfs_port_auto = cfg["port"] == "auto"; if (!nfs_port) - nfs_port = !cfg["port"].is_null() && nfs_rdma_port ? -1 : 2049; + nfs_port = nfs_port_auto ? 0 : (!cfg["port"].is_null() && nfs_rdma_port ? -1 : 2049); nfs_rdma_credit = cfg["nfs_rdma_credit"].uint64_value(); if (!nfs_rdma_credit) nfs_rdma_credit = 16; @@ -331,6 +335,10 @@ void nfs_proxy_t::run_server(json11::Json cfg) do_accept(nfs_socket); } }); + if (nfs_port_auto) + { + printf("Port: %d\n", listening_port); + } } else { diff --git a/src/nfs/nfs_proxy.h b/src/nfs/nfs_proxy.h index ad60c4a6..9a3f662d 100644 --- a/src/nfs/nfs_proxy.h +++ b/src/nfs/nfs_proxy.h @@ -34,6 +34,7 @@ public: std::string default_pool; std::string export_root; bool portmap_enabled; + bool nfs_port_auto = false; unsigned nfs_port = 0; unsigned nfs_rdma_port = 0; uint32_t nfs_rdma_credit = 16;