From 8ea5fa5a2e912b3622b25935c4a0ccf014001fbc Mon Sep 17 00:00:00 2001 From: root Date: Wed, 16 Apr 2025 07:36:16 +0000 Subject: [PATCH 1/3] Added azuthnone changes --- turbonfs/inc/nfs_internal.h | 4 +- turbonfs/src/connection.cpp | 81 ++++++++++++++++++++----------------- turbonfs/src/main.cpp | 23 +++++++++++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/turbonfs/inc/nfs_internal.h b/turbonfs/inc/nfs_internal.h index 2c2aabccc..4d36a0f73 100644 --- a/turbonfs/inc/nfs_internal.h +++ b/turbonfs/inc/nfs_internal.h @@ -79,8 +79,8 @@ struct mount_options // Whether auth is required. const bool auth; - // AuthType: Currently we only support AzAuthAAD. - const std::string authtype = "AzAuthAAD"; + // AuthType: Currently we only support AzAuthAAD and AzAuthNone. + std::string authtype = "AzAuthNone"; // Add any other options as needed. diff --git a/turbonfs/src/connection.cpp b/turbonfs/src/connection.cpp index 014e13eb7..bc0b12d60 100644 --- a/turbonfs/src/connection.cpp +++ b/turbonfs/src/connection.cpp @@ -13,11 +13,10 @@ * As of now we use the interface IPv4 address string, * but it can be changed to anything else in future. */ -std::string get_clientid() { + std::string get_clientid() { struct ifaddrs *ifaddr = nullptr; struct ifaddrs *ifa = nullptr; char ip[INET_ADDRSTRLEN] = {0}; - static std::string client_id = std::to_string(get_current_usecs()) + "-"; /* * Whatever is encoded here should not exceed the maximum possible that can be @@ -60,19 +59,28 @@ std::string get_clientid() { goto failed_get_clientip; } - client_id += std::string(ip); -failed_get_clientip: + // Build and cache the client ID only once + static std::string client_id = std::to_string(get_current_usecs()) + "-" + std::string(ip); + // We cannot send clientid of size more than MAX_IP_LENGTH. assert(client_id.length() <= MAX_IP_LENGTH); AZLogDebug("Using clientid {}", client_id); return client_id; + +failed_get_clientip: + static std::string fallback_client_id = std::to_string(get_current_usecs()) + "-unknown"; + AZLogDebug("Using fallback clientid {}", fallback_client_id); + return fallback_client_id; } bool nfs_connection::open() { const int nodelay = 1; + std::string client_id; + int ret = -1; + uint64_t n; // open() must be called only for a closed connection. assert(nfs_context == nullptr); @@ -100,38 +108,39 @@ bool nfs_connection::open() nfs_destroy_url(url); if (mo.auth) { - // 16 should be sufficient to hold the version string. - char client_version[16]; - - [[maybe_unused]] - const uint64_t n = snprintf(client_version, sizeof(client_version), - "%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR, - AZNFSCLIENT_VERSION_MINOR, - AZNFSCLIENT_VERSION_PATCH); - assert(n < sizeof(client_version)); - - std::string client_id = get_clientid(); - - assert(!mo.export_path.empty()); - assert(!mo.authtype.empty()); - assert(strlen(client_version) > 0); - assert(!client_id.empty()); - - const int ret = nfs_set_auth_context(nfs_context, - mo.export_path.c_str(), - mo.authtype.c_str(), - client_version, - client_id.c_str()); - if (ret != 0) { - AZLogError("Failed to set auth values in nfs context, " - "exportpath={} authtype={} " - "clientversion={} clientid={}", - mo.export_path.c_str(), - mo.authtype.c_str(), - client_version, - client_id.c_str()); - goto destroy_context; - } + mo.authtype = "AzAuthAAD"; + } + + // 16 should be sufficient to hold the version string. + char client_version[16]; + + n = snprintf(client_version, sizeof(client_version), + "%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR, + AZNFSCLIENT_VERSION_MINOR, + AZNFSCLIENT_VERSION_PATCH); + assert(n < sizeof(client_version)); + + client_id = get_clientid(); + + assert(!mo.export_path.empty()); + assert(!mo.authtype.empty()); + assert(strlen(client_version) > 0); + assert(!client_id.empty()); + + ret = nfs_set_auth_context(nfs_context, + mo.export_path.c_str(), + mo.authtype.c_str(), + client_version, + client_id.c_str()); + if (ret != 0) { + AZLogError("Failed to set auth values in nfs context, " + "exportpath={} authtype={} " + "clientversion={} clientid={}", + mo.export_path.c_str(), + mo.authtype.c_str(), + client_version, + client_id.c_str()); + goto destroy_context; } /* diff --git a/turbonfs/src/main.cpp b/turbonfs/src/main.cpp index 10e63a42b..42725facb 100644 --- a/turbonfs/src/main.cpp +++ b/turbonfs/src/main.cpp @@ -603,6 +603,27 @@ auth_token_cb_res *get_auth_token_and_setargs_cb(struct auth_context *auth) return cb_res; } +auth_token_cb_res *get_auth_token_and_setargs_cb_none(struct auth_context *auth) +{ + if (!auth) { + AZLogError("Null auth_context received"); + assert(0); + return nullptr; + } + + // Allocate response structure + auth_token_cb_res *cb_res = (auth_token_cb_res *) malloc(sizeof(auth_token_cb_res)); + if (!cb_res) { + AZLogError("Failed to allocate memory for auth_token_cb_res"); + return nullptr; + } + + cb_res->azauth_data = strdup("None"); + cb_res->expiry_time = static_cast(time(NULL)); + + return cb_res; +} + int main(int argc, char *argv[]) { // Initialize logger first thing. @@ -789,6 +810,8 @@ int main(int argc, char *argv[]) if (aznfsc_cfg.auth) { // Set the auth token callback for this connection if auth is enabled. set_auth_token_callback(get_auth_token_and_setargs_cb); + } else { + set_auth_token_callback(get_auth_token_and_setargs_cb_none); } /* From 8d424fe9b612bc527fceb8846c19e28ee972878f Mon Sep 17 00:00:00 2001 From: Pragya Gandhi Date: Thu, 8 May 2025 05:08:11 +0000 Subject: [PATCH 2/3] Minor changes --- turbonfs/CMakeLists.txt | 17 ----------------- turbonfs/extern/libnfs | 2 +- turbonfs/inc/nfs_internal.h | 2 +- turbonfs/sample-turbo-config.yaml | 6 +++--- turbonfs/src/connection.cpp | 8 ++++---- turbonfs/src/main.cpp | 16 +++++++++++++++- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/turbonfs/CMakeLists.txt b/turbonfs/CMakeLists.txt index 60edb0f7f..01b9a2241 100644 --- a/turbonfs/CMakeLists.txt +++ b/turbonfs/CMakeLists.txt @@ -76,23 +76,6 @@ set(LIBFUSE_BUILD_DIR "${CMAKE_BINARY_DIR}/extern/libfuse") # git submodule add https://github.com/microsoft/vcpkg.git extern/vcpkg # git submodule add https://github.com/nlohmann/json.git extern/json # -find_package(Git QUIET) -if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git") - option(GIT_SUBMODULE "Check submodules during build" ON) - if(GIT_SUBMODULE) - message(STATUS "Submodule update") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SUBMOD_RESULT) - if(NOT GIT_SUBMOD_RESULT EQUAL "0") - message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") - endif() - endif() -endif() - -if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/libnfs/CMakeLists.txt") - message(FATAL_ERROR "The libnfs submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") -endif() if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/yaml-cpp/CMakeLists.txt") message(FATAL_ERROR "The yaml-cpp submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") diff --git a/turbonfs/extern/libnfs b/turbonfs/extern/libnfs index f15c10b08..f7438c69d 160000 --- a/turbonfs/extern/libnfs +++ b/turbonfs/extern/libnfs @@ -1 +1 @@ -Subproject commit f15c10b0891f877f539d6e3377d4fe5ae690b6a0 +Subproject commit f7438c69dcc8b00453545c77b1ad5019eae766d2 diff --git a/turbonfs/inc/nfs_internal.h b/turbonfs/inc/nfs_internal.h index 4d36a0f73..40ac0313e 100644 --- a/turbonfs/inc/nfs_internal.h +++ b/turbonfs/inc/nfs_internal.h @@ -123,7 +123,7 @@ struct mount_options { std::string url(1024, '\0'); // TODO: Take it from aznfsc_cfg. - const int debug = 1; + const int debug = 2; /* * For Blob NFS force nfsport and mountport to avoid portmapper diff --git a/turbonfs/sample-turbo-config.yaml b/turbonfs/sample-turbo-config.yaml index 7f05d85c4..9bc83ec57 100644 --- a/turbonfs/sample-turbo-config.yaml +++ b/turbonfs/sample-turbo-config.yaml @@ -4,8 +4,8 @@ # "none" as source in the mount command. In that case account and container # are mandatory, cloud_suffix can be guessed and port is default 2048. # -account: sjc22prdste06hnfsv3acc1 -container: nfsv3test +account: amsprdsty01enfs25 +container: testcont #cloud_suffix: blob.core.windows.net #cloud_suffix: blob.preprod.core.windows.net @@ -23,7 +23,7 @@ auth: false # readdir_maxcount # lookupcache: all|none|pos|positive # -nconnect: 96 +nconnect: 1 timeo: 600 retrans: 2 acregmin: 3 diff --git a/turbonfs/src/connection.cpp b/turbonfs/src/connection.cpp index bc0b12d60..7072ec852 100644 --- a/turbonfs/src/connection.cpp +++ b/turbonfs/src/connection.cpp @@ -128,10 +128,10 @@ bool nfs_connection::open() assert(!client_id.empty()); ret = nfs_set_auth_context(nfs_context, - mo.export_path.c_str(), - mo.authtype.c_str(), - client_version, - client_id.c_str()); + mo.export_path.c_str(), + mo.authtype.c_str(), + client_version, + client_id.c_str()); if (ret != 0) { AZLogError("Failed to set auth values in nfs context, " "exportpath={} authtype={} " diff --git a/turbonfs/src/main.cpp b/turbonfs/src/main.cpp index 42725facb..d30a9631c 100644 --- a/turbonfs/src/main.cpp +++ b/turbonfs/src/main.cpp @@ -619,11 +619,24 @@ auth_token_cb_res *get_auth_token_and_setargs_cb_none(struct auth_context *auth) } cb_res->azauth_data = strdup("None"); - cb_res->expiry_time = static_cast(time(NULL)); + cb_res->expiry_time = static_cast(time(NULL))+300; return cb_res; } +uint64_t set_azauth_res_sc_cb(uint64_t server_cap_map) + { + if (server_cap_map == 1) { + if (!client_started) { + AZLogError("Client not started when get_azauth_res_cb is called"); + return -1; + } + } + + AZLogInfo("In get_azauth_Res_cb %llu",server_cap_map); + return 0; + } + int main(int argc, char *argv[]) { // Initialize logger first thing. @@ -813,6 +826,7 @@ int main(int argc, char *argv[]) } else { set_auth_token_callback(get_auth_token_and_setargs_cb_none); } + set_azauth_res_callback(set_azauth_res_sc_cb); /* * Initialize nfs_client singleton. From 92a588a13fde1be626f211ecf5824e46f65c231d Mon Sep 17 00:00:00 2001 From: Pragya Gandhi Date: Mon, 12 May 2025 05:30:28 +0000 Subject: [PATCH 3/3] Fixes --- turbonfs/CMakeLists.txt | 17 +++++++++++++++++ turbonfs/inc/nfs_internal.h | 2 +- turbonfs/sample-turbo-config.yaml | 2 +- turbonfs/src/connection.cpp | 2 +- turbonfs/src/main.cpp | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/turbonfs/CMakeLists.txt b/turbonfs/CMakeLists.txt index 01b9a2241..60edb0f7f 100644 --- a/turbonfs/CMakeLists.txt +++ b/turbonfs/CMakeLists.txt @@ -76,6 +76,23 @@ set(LIBFUSE_BUILD_DIR "${CMAKE_BINARY_DIR}/extern/libfuse") # git submodule add https://github.com/microsoft/vcpkg.git extern/vcpkg # git submodule add https://github.com/nlohmann/json.git extern/json # +find_package(Git QUIET) +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git") + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Submodule update") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() +endif() + +if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/libnfs/CMakeLists.txt") + message(FATAL_ERROR "The libnfs submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") +endif() if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/yaml-cpp/CMakeLists.txt") message(FATAL_ERROR "The yaml-cpp submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") diff --git a/turbonfs/inc/nfs_internal.h b/turbonfs/inc/nfs_internal.h index 40ac0313e..4d36a0f73 100644 --- a/turbonfs/inc/nfs_internal.h +++ b/turbonfs/inc/nfs_internal.h @@ -123,7 +123,7 @@ struct mount_options { std::string url(1024, '\0'); // TODO: Take it from aznfsc_cfg. - const int debug = 2; + const int debug = 1; /* * For Blob NFS force nfsport and mountport to avoid portmapper diff --git a/turbonfs/sample-turbo-config.yaml b/turbonfs/sample-turbo-config.yaml index 9bc83ec57..9cd7ac0c7 100644 --- a/turbonfs/sample-turbo-config.yaml +++ b/turbonfs/sample-turbo-config.yaml @@ -23,7 +23,7 @@ auth: false # readdir_maxcount # lookupcache: all|none|pos|positive # -nconnect: 1 +nconnect: 96 timeo: 600 retrans: 2 acregmin: 3 diff --git a/turbonfs/src/connection.cpp b/turbonfs/src/connection.cpp index 7072ec852..ec8304d3c 100644 --- a/turbonfs/src/connection.cpp +++ b/turbonfs/src/connection.cpp @@ -13,7 +13,7 @@ * As of now we use the interface IPv4 address string, * but it can be changed to anything else in future. */ - std::string get_clientid() { +std::string get_clientid() { struct ifaddrs *ifaddr = nullptr; struct ifaddrs *ifa = nullptr; char ip[INET_ADDRSTRLEN] = {0}; diff --git a/turbonfs/src/main.cpp b/turbonfs/src/main.cpp index d30a9631c..8786c4a1d 100644 --- a/turbonfs/src/main.cpp +++ b/turbonfs/src/main.cpp @@ -633,7 +633,7 @@ uint64_t set_azauth_res_sc_cb(uint64_t server_cap_map) } } - AZLogInfo("In get_azauth_Res_cb %llu",server_cap_map); + AZLogInfo("In get_azauth_res_cb %lu",server_cap_map); return 0; }