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 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/sample-turbo-config.yaml b/turbonfs/sample-turbo-config.yaml index 7f05d85c4..9cd7ac0c7 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 diff --git a/turbonfs/src/connection.cpp b/turbonfs/src/connection.cpp index 014e13eb7..ec8304d3c 100644 --- a/turbonfs/src/connection.cpp +++ b/turbonfs/src/connection.cpp @@ -17,7 +17,6 @@ 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..8786c4a1d 100644 --- a/turbonfs/src/main.cpp +++ b/turbonfs/src/main.cpp @@ -603,6 +603,40 @@ 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))+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 %lu",server_cap_map); + return 0; + } + int main(int argc, char *argv[]) { // Initialize logger first thing. @@ -789,7 +823,10 @@ 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); } + set_azauth_res_callback(set_azauth_res_sc_cb); /* * Initialize nfs_client singleton.