保险丝回调永久挂在某些Azure API调用上

时间:2019-03-27 02:58:47

标签: c++ linux azure fuse azure-blob-storage

我正在尝试在Ubuntu服务器18.04上与azure-storage-cpp使用保险丝。

我遇到的问题是,对azure::storage::cloud_blob::download_attributes的调用使回调永远挂起。

我制作了最少的代码来重现它

#include <fuse.h>
#include <string>
#include <was/blob.h>
#include <was/storage_account.h>
#include <cpprest/filestream.h>
#include <cpprest/containerstream.h>

// Global context
static struct fuse_operations azure_fuse;
static std::shared_ptr<azure::storage::cloud_storage_account> azure_client;

// Initialize azure client
void* init_azf(struct fuse_conn_info *conn)
{
    const std::string connection_str(loadConnectionString());
    const utility::string_t storage_connection_string(connection_str);
    azure_client = std::make_shared<azure::storage::cloud_storage_account>(azure::storage::cloud_storage_account::parse(storage_connection_string));

    return nullptr;
}

// Example of callback 
int getattr_azf(const char *path, struct stat *stbuf)
{
    // root -> directory
    if (strlen(path) == 1)
    {
        // Stuff
        return 0;
    }

    std::string blobNameStr(&(path[1]));

    // Retrieve blob
    azure::storage::cloud_blob_client blob_client = azure_client->create_cloud_blob_client();
    azure::storage::cloud_blob_container container(blob_client.get_container_reference(container_name));
    azure::storage::cloud_blob blob(container.get_blob_reference(blobNameStr));

    // Get properties
    /* Stuck here */
    blob.download_attributes();

    // Stuff
}

void set_up_callbacks(struct fuse_operations* operations)
{
    operations->init = init_azf;
    operations->getattr = getattr_azf;
    operations->open = open_azf;
    operations->read = read_azf;
}

int main(int argc, char *argv[])
{
    set_up_callbacks(&azure_fuse);

    return fuse_main(argc, argv, &azure_fuse, NULL);
}

当我尝试打开现有文件时,它挂在blob.download_attributes()中对getattr_azf的调用上。

奇怪的是,如果我在main函数中做到这一点,它将起作用。是否是因为blob.download_attributes()使用了异步机制来融合保险丝?还是我只是错过了一些静态初始化信息?

谢谢

0 个答案:

没有答案