fixed bug in fs_open(), now handles cache dataset creation properly

This commit is contained in:
Fufu Fang 2019-04-23 12:03:49 +01:00
parent 6536163f98
commit 36ddbe9ec5
2 changed files with 17 additions and 3 deletions

View File

@ -41,7 +41,7 @@ int CACHE_SYSTEM_INIT = 0;
/**
* \brief the receive buffer
*/
uint8_t RECV_BUF[DATA_BLK_SZ];
static uint8_t RECV_BUF[DATA_BLK_SZ];
/**
* \brief The metadata directory

View File

@ -4,9 +4,12 @@
#include "link.h"
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
static pthread_mutex_t open_lock;
static void *fs_init(struct fuse_conn_info *conn)
{
(void) conn;
@ -89,13 +92,24 @@ static int fs_open(const char *path, struct fuse_file_info *fi)
}
if (CACHE_SYSTEM_INIT) {
pthread_mutex_lock(&open_lock);
fi->fh = (uint64_t) Cache_open(path);
if (!fi->fh) {
/* The link clearly exists, the cache cannot be opened */
/*
* The link clearly exists, the cache cannot be opened, attempt
* cache creation
*/
Cache_delete(path);
Cache_create(link);
return -ENOENT;
fi->fh = (uint64_t) Cache_open(path);
/*
* The cache definitely cannot be opened for some reason.
*/
if (!fi->fh) {
return -ENOENT;
}
}
pthread_mutex_unlock(&open_lock);
}