Commit 5bb73418 authored by Genaro Juan Sánchez Gallegos's avatar Genaro Juan Sánchez Gallegos Committed by Javier Garcia Blas
Browse files

Add improvements for 'unlink'.

No related merge requests found
Showing with 137 additions and 140 deletions
+137 -140
......@@ -16,8 +16,8 @@
// Pointer to the tree's root node.
extern GNode *tree_root;
extern pthread_mutex_t tree_mut;
extern int32_t __thread current_dataset; // Dataset whose policy has been set last.
extern dataset_info __thread curr_dataset; // Currently managed dataset.
// extern int32_t __thread current_dataset; // Dataset whose policy has been set last.
// extern dataset_info __thread curr_dataset; // Currently managed dataset.
extern imss __thread curr_imss;
// Initial buffer address.
......
......@@ -3,7 +3,7 @@
SCRIPT_NAME="ior_hercules_slurm.sh"
FILE_SIZE=$((1024*1024*10))
ATTACHED=1
ATTACHED=0
# 0 = Shared single file, 1 = File per process.
IOR_FILE_PER_PROCESS=1
......
......@@ -3,8 +3,8 @@
#SBATCH --time=01:00:00 # Time limit hrs:min:sec
#SBATCH --output=logs/hercules/%j.log # Standard output and error log
#SBATCH --mem=0
#SBATCH --exclude=broadwell-008,broadwell-010
#SBATCH --nodelist=broadwell-[012-027]
##SBATCH --exclude=broadwell-008,broadwell-010
##SBATCH --nodelist=broadwell-[012-027]
###SBATCH --exclusive=user
##SBATCH --overcommit
##SBATCH --oversubscribe
......@@ -73,7 +73,7 @@ if [ -z "$CONFIG_PATH" ]; then
source hercules start
else
echo "Configuration file pass $CONFIG_PATH"
export HERCULES_DEBUG_LEVEL=SLOG_TIME
export HERCULES_DEBUG_LEVEL=none
source /beegfs/home/javier.garciablas/hercules/scripts/hercules start \
-f "$CONFIG_PATH"
unset HERCULES_DEBUG_LEVEL
......
......@@ -297,121 +297,99 @@ int imss_getattr(char *path, struct stat *stbuf)
char *aux = NULL;
switch (type)
{
case '0':
// erase dataset from the local maps.
pthread_mutex_lock(&lock_file);
map_erase(map, imss_path);
pthread_mutex_unlock(&lock_file);
// map_release_prefetch(map_prefetch, path);
slog_debug("Calling release prefetch path = %s", imss_path);
map_release_prefetch(map_prefetch, imss_path);
slog_debug("Ending release prefetch path = %s", imss_path);
return -ENOENT;
case TYPE_HERCULES_INSTANCE:
{
slog_debug("n_ent=%d", n_ent);
stbuf->st_size = 4;
slog_debug("is a directy, setting st_nlink to 1");
stbuf->st_nlink = 1;
stbuf->st_mode = S_IFDIR | 0775;
free(refs);
return 0;
break;
}
case TYPE_DIRECTORY:
case TYPE_HERCULES_INSTANCE: // Directory case?
break;
case TYPE_REGULAR_FILE: // Case file
{
break;
// stbuf->st_blocks = ceil((double)stbuf->st_size / IMSS_BLKSIZE);
stbuf->st_blocks = ceil((double)stbuf->st_size / 512.0); // Number 512-byte blocks allocated.
// slog_debug("stats.st_nlink=%lu, stats.st_size=%lu", stats.st_nlink, stats.st_size);
slog_debug("[imss_getattr] path=%s, imss_path=%s, file descriptor=%d, file size=%lu, stbuf->st_blocks=%lu, stbuf->st_nlink=%lu stats.st_nlink=%lu", path, imss_path, fd, stbuf->st_size, stbuf->st_blocks, stbuf->st_nlink, stats.st_nlink);
// fprintf(stderr, "[imss_getattr] path=%s, imss_path=%s, file descriptor=%d, file size=%lu, stbuf->st_blocks=%lu\n", path, imss_path, fd, stbuf->st_size, stbuf->st_blocks);
print_file_type(*stbuf, path);
return 0;
}
default:
slog_error("Unkown type", type);
return -ENOENT; // to check!
}
fd_lookup(imss_path, &fd, &stats, &aux);
if (fd >= 0)
{
char *last = imss_path + strlen(imss_path) - 1;
size_t len = strlen(imss_path);
if (len > 0 && imss_path[len - 1] != '/')
ds = fd;
}
else
{
ds = open_dataset((char *)imss_path, 0);
slog_debug("[imss_getattr] ds=%d", ds);
if (ds >= (int32_t)0)
{
strcat(imss_path, "/");
int ret = 0;
// slog_debug("[imss_getattr] IMSS_BLKSIZE=%lu KBytes, IMSS_DATA_BSIZE=%lu Bytes", IMSS_BLKSIZE, IMSS_DATA_BSIZE);
void *data = (void *)malloc(IMSS_DATA_BSIZE * sizeof(char));
// void *data = NULL;
// data is allocated in "get data".
ret = get_ndata(ds, 0, data, 0, 0);
if (ret < 0)
{
slog_error("Error getting data: %s", imss_path);
return -ENOENT;
}
memcpy(&stats, data, sizeof(struct stat));
// pthread_mutex_lock(&lock_file);
slog_debug("file=%s, st_nlink=%lu", imss_path, stats.st_nlink);
map_put(map, imss_path, ds, stats, (char *)data);
}
if ((n_ent = get_dir((char *)imss_path, &buffer, &refs)) != -1)
else if (ds == -EEXIST)
{
slog_debug("[imss_getattr] n_ent=%d", n_ent);
stbuf->st_size = 4;
slog_debug("is a directy, setting st_nlink to 1");
stbuf->st_nlink = 1;
stbuf->st_mode = S_IFDIR | 0775;
// Free resources
// free(buffer);
free(refs);
// fprintf(stderr, "[imss_getattr] ds=%d, %s\n", ds, strerror(EEXIST));
return 0;
}
else
{
// fprintf(stderr,"imss_getattr get_dir ERROR\n");
// fprintf(stderr, "[IMSS-FUSE] Cannot get dataset metadata.");
return -ENOENT;
}
}
case TYPE_REGULAR_FILE: // Case file
{
slog_debug("type=%c, imss_path=%s", type, imss_path);
/*if(stat_dataset(imss_path, &metadata) == -1){
fprintf(stderr, "[IMSS-FUSE] Cannot get dataset metadata.");
return -ENOENT;
}*/
// Get header
// FIXME! Not always possible!!!!
fd_lookup(imss_path, &fd, &stats, &aux);
slog_debug("imss_path=%s, file descriptor=%d", imss_path, fd);
memcpy(stbuf, &stats, sizeof(struct stat));
if (fd >= 0)
{
ds = fd;
}
else
{
ds = open_dataset((char *)imss_path, 0);
slog_debug("[imss_getattr] ds=%d", ds);
if (ds >= (int32_t)0)
{
int ret = 0;
// slog_debug("[imss_getattr] IMSS_BLKSIZE=%lu KBytes, IMSS_DATA_BSIZE=%lu Bytes", IMSS_BLKSIZE, IMSS_DATA_BSIZE);
void *data = (void *)malloc(IMSS_DATA_BSIZE * sizeof(char));
// void *data = NULL;
// data is allocated in "get data".
ret = get_ndata(ds, 0, data, 0, 0);
if (ret < 0)
{
slog_error("Error getting data: %s", imss_path);
return -ENOENT;
}
memcpy(&stats, data, sizeof(struct stat));
pthread_mutex_lock(&lock_file);
slog_debug("file=%s, st_nlink=%lu", imss_path, stats.st_nlink);
map_put(map, imss_path, ds, stats, (char *)data);
pthread_mutex_unlock(&lock_file);
// free(aux);
}
else if (ds == -EEXIST)
{
// fprintf(stderr, "[imss_getattr] ds=%d, %s\n", ds, strerror(EEXIST));
return 0;
}
else
{
// fprintf(stderr, "[IMSS-FUSE] Cannot get dataset metadata.");
return -ENOENT;
}
}
// fprintf(stderr, "[imss_getattr] path=%s, ds=%d, stats.st_nlink=%lu, stats.st_size=%lu\n", path, ds, stats.st_nlink, stats.st_size);
// if (stats.st_nlink != 0)
switch (type)
{
case TYPE_DIRECTORY:
if ((n_ent = get_dir((char *)imss_path, &buffer, &refs)) != -1)
{
memcpy(stbuf, &stats, sizeof(struct stat));
stbuf->st_size = 4;
slog_debug("is a directy, setting st_nlink to 1");
stbuf->st_nlink = 1;
stbuf->st_mode = S_IFDIR | 0775;
free(refs);
}
// stbuf->st_size = stats.st_size;
// else
// {
// // fprintf(stderr, "[IMSS-FUSE] Cannot get dataset metadata.");
// slog_error("[imss_getattr] Cannot get dataset metadata");
// return -ENOENT;
// }
// stbuf->st_blocks = ceil((double)stbuf->st_size / IMSS_BLKSIZE);
stbuf->st_blocks = ceil((double)stbuf->st_size / 512.0); // Number 512-byte blocks allocated.
// slog_debug("stats.st_nlink=%lu, stats.st_size=%lu", stats.st_nlink, stats.st_size);
slog_debug("[imss_getattr] path=%s, imss_path=%s, file descriptor=%d, file size=%lu, stbuf->st_blocks=%lu, stbuf->st_nlink=%lu stats.st_nlink=%lu", path, imss_path, fd, stbuf->st_size, stbuf->st_blocks, stbuf->st_nlink, stats.st_nlink);
// fprintf(stderr, "[imss_getattr] path=%s, imss_path=%s, file descriptor=%d, file size=%lu, stbuf->st_blocks=%lu\n", path, imss_path, fd, stbuf->st_size, stbuf->st_blocks);
print_file_type(*stbuf, path);
return 0;
}
case TYPE_REGULAR_FILE:
stbuf->st_blocks = ceil((double)stbuf->st_size / 512.0);
break;
default:
slog_error("Unkown type", type);
return -ENOENT; // to check!
return -ENOENT; // to check!
}
// pthread_mutex_unlock(&lock_file);
// free(aux);
return 0;
}
/*
......@@ -593,7 +571,7 @@ int imss_open(char *path, uint64_t *fh)
slog_debug("[imss_open] ret=%d, file_desc=%d", ret, file_desc);
memcpy(&stats, data, sizeof(struct stat));
pthread_mutex_lock(&lock_file);
// pthread_mutex_lock(&lock_file);
// storing block 0 on the local map.
map_put(map, imss_path, file_desc, stats, (char *)data);
print_file_type(stats, imss_path);
......@@ -602,7 +580,7 @@ int imss_open(char *path, uint64_t *fh)
char *buff = (char *)malloc(PREFETCH * IMSS_DATA_BSIZE);
map_init_prefetch(map_prefetch, imss_path, buff);
}
pthread_mutex_unlock(&lock_file);
// pthread_mutex_unlock(&lock_file);
// free(aux);
}
......@@ -2745,7 +2723,7 @@ int imss_rename(char *old_path, char *new_path)
strncpy(name, old_rpath + pos + 1, strlen(old_rpath) - pos);
strcpy(full_path, new_path);
strcat(full_path, name);
//printf("%d, %s\n", pos, full_path);
// printf("%d, %s\n", pos, full_path);
slog_debug("%d, full_path=%s, old_rpath=%s\n", pos, full_path, old_rpath);
if (!strcmp(old_rpath, full_path))
......@@ -2804,7 +2782,7 @@ int imss_rename(char *old_path, char *new_path)
ret = imss_getattr(last_parent_dir, &ds_stat_n);
if (ret != 0)
{
slog_error("HERCULES_ERROR_RENAME_DEST_PARENT_DIR_DOES_NOT_EXIST");
slog_error("HERCULES_ERR_RENAME_DEST_PARENT_DIR_DOES_NOT_EXIST");
return ret;
}
}
......
......@@ -448,7 +448,7 @@ extern "C"
{
// slog_live("[HERCULES] after resolve path, pathname=%s, real_pathname=%s", pathname, real_pathname);
ret = ResolvePath(pathname, absolute_pathname);
//fprintf(stderr, "[IMSS] last option, pathname=%s, absolute_pathname=%s, absolute_pathname_len=%d, workdir=%s\n", pathname, absolute_pathname, ret, workdir);
// fprintf(stderr, "[IMSS] last option, pathname=%s, absolute_pathname=%s, absolute_pathname_len=%d, workdir=%s\n", pathname, absolute_pathname, ret, workdir);
if (ret > 0)
{ // absolute path.
// slog_live("[IMSS] absolute_pathname=%s", absolute_pathname);
......@@ -459,8 +459,8 @@ extern "C"
new_path = convert_path(pathname);
}
//slog_live("[HERCULES] pathname=%s, absolute_pathname=%s, new_path=%s", pathname, absolute_pathname,new_path);
// free(real_pathname);
// slog_live("[HERCULES] pathname=%s, absolute_pathname=%s, new_path=%s", pathname, absolute_pathname,new_path);
// free(real_pathname);
}
}
}
......@@ -519,7 +519,7 @@ extern "C"
char *new_path = (char *)calloc(PATH_MAX, sizeof(char));
strcpy(path, name);
//fprintf(stderr, "Received name=%s\n", name);
// fprintf(stderr, "Received name=%s\n", name);
size_t len = strlen(MOUNT_POINT);
// remove MOUNT_POINT prefix from the path.
if (len > 0)
......@@ -531,7 +531,7 @@ extern "C"
}
}
//fprintf(stderr, "name=%s, path=%s\n", name, path);
// fprintf(stderr, "name=%s, path=%s\n", name, path);
// seeks initial slashes "/" in the path.
len = strlen(path);
......@@ -3389,35 +3389,51 @@ extern "C"
if (new_path != NULL)
{
slog_live("[POSIX]. Calling Hercules 'unlink', name=%s, new_path=%s", name, new_path);
char type = get_type(new_path);
switch (type)
struct stat ds_stat_n;
ret = imss_getattr(new_path, &ds_stat_n);
if (ret != 0)
{
case TYPE_DIRECTORY:
case TYPE_HERCULES_INSTANCE: // Directory case?
slog_error("HERCULES_ERR_UNLINK_FILE_NOT_FOUND");
}
else
{
char *last = new_path + strlen(new_path) - 1;
size_t len = strlen(new_path);
if (len > 0 && new_path[len - 1] != '/')
if (S_ISDIR(ds_stat_n.st_mode))
{
strcat(new_path, "/");
ret = imss_rmdir(new_path);
} else {
ret = imss_unlink(new_path);
}
ret = imss_rmdir(new_path);
break;
}
case TYPE_REGULAR_FILE: // is regular file.
{
ret = imss_unlink(new_path);
break;
}
default:
{
slog_error("HERCULES_ERR_NOT_SUPPORTED_TYPE");
perror("HERCULES_ERR_NOT_SUPPORTED_TYPE");
ret = -1;
break;
}
}
// char type = get_type(new_path);
// switch (type)
// {
// case TYPE_DIRECTORY:
// case TYPE_HERCULES_INSTANCE: // Directory case?
// {
// char *last = new_path + strlen(new_path) - 1;
// size_t len = strlen(new_path);
// if (len > 0 && new_path[len - 1] != '/')
// {
// strcat(new_path, "/");
// }
// ret = imss_rmdir(new_path);
// break;
// }
// case TYPE_REGULAR_FILE: // is regular file.
// {
// ret = imss_unlink(new_path);
// break;
// }
// default:
// {
// slog_error("HERCULES_ERR_NOT_SUPPORTED_TYPE");
// perror("HERCULES_ERR_NOT_SUPPORTED_TYPE");
// ret = -1;
// break;
// }
// }
// if (ret == 3)
// {
// int ret_map = map_fd_erase_by_pathname(map_fd, new_path);
......@@ -3477,9 +3493,11 @@ extern "C"
{
if (map_fd_erase_by_pathname(map_fd, new_path) == -1)
{
slog_warn("[POSIX]. Hercules Warning, no file descriptor found for the pathname=%s", new_path);
ret = -1;
// slog_warn("[POSIX]. Hercules Warning, no file descriptor found for the pathname=%s", new_path);
// ret = -1;
// errno =
// file could be deleted but without be opened before.
ret = 0;
}
else
{
......@@ -3487,7 +3505,7 @@ extern "C"
}
}
slog_live("[POSIX]. Ending Hercules 'unlink', type=%d, new_path=%s, ret=%d\n", type, new_path, ret);
slog_live("[POSIX]. Ending Hercules 'unlink', new_path=%s, ret=%d\n", new_path, ret);
// fprintf(stderr, "[POSIX]. Ending Hercules 'unlink', type=%d, new_path=%s, ret=%d\n", type, new_path, ret);
free(new_path);
}
......@@ -3700,9 +3718,10 @@ extern "C"
{ // move from Hercules to Hercules.
slog_live("[POSIX]. Calling Hercules 'rename', old=%s, new_pathname=%s, old path=%s, new_pathname=%s", old, new_pathname, old_path, new_path);
ret = imss_rename(old_path, new_path);
if(ret < 0) {
if (ret < 0)
{
errno = -ret;
ret = - 1;
ret = -1;
}
slog_live("[POSIX]. End Hercules 'rename', old path=%s, new_pathname=%s, ret=%d\n", old_path, new_path, ret);
free(old_path);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment