1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
Copyright (C) 2014- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#include "dag.h"
#include "dag_file.h"
#include "xxmalloc.h"
#include "list.h"
#include "macros.h"
#include <stdlib.h>
struct dag_file * dag_file_create( const char *filename )
{
struct dag_file *f = xxcalloc(1, sizeof(*f));
f->filename = xxstrdup(filename);
f->needed_by = list_create();
f->created_by = 0;
f->actual_size = 0;
f->estimated_size = GIGABYTE;
f->reference_count = 0;
f->state = DAG_FILE_STATE_UNKNOWN;
f->type = DAG_FILE_TYPE_INTERMEDIATE;
f->source = NULL;
f->cache_name = NULL;
f->source_type = DAG_FILE_SOURCE_LOCAL;
return f;
}
/* Return JX object containing name, remote name, and size. */
struct jx * dag_file_to_jx( struct dag_file *f, struct dag_node *n)
{
struct jx *file = jx_object(0);
jx_insert(file, jx_string("dag_name"), jx_string(f->filename));
const char *remote_name = dag_node_get_remote_name(n, f->filename);
if(remote_name){
jx_insert(file, jx_string("task_name"), jx_string(remote_name));
}
jx_insert(file, jx_string("size"), jx_integer(dag_file_size(f)));
return file;
}
/* Converts enum to string value for decoding file state */
const char *dag_file_state_name(dag_file_state_t state)
{
switch (state) {
case DAG_FILE_STATE_UNKNOWN:
return "waiting";
case DAG_FILE_STATE_EXPECT:
return "running";
case DAG_FILE_STATE_EXISTS:
return "receive";
case DAG_FILE_STATE_COMPLETE:
return "complete";
case DAG_FILE_STATE_DELETE:
return "delete";
case DAG_FILE_STATE_DOWN:
return "download";
case DAG_FILE_STATE_UP:
return "upload";
default:
return "unknown";
}
}
/* Returns whether the file is created in the DAG or not */
int dag_file_is_source( const struct dag_file *f )
{
if(f->created_by)
return 0;
else
return 1;
}
/* Returns whether the file is used in any rule */
int dag_file_is_sink( const struct dag_file *f )
{
if(list_size(f->needed_by) > 0)
return 0;
else
return 1;
}
/* Reports if a file is expeced to exist, does not guarantee existence
* if files are altered outside of Makeflow */
int dag_file_should_exist( const struct dag_file *f )
{
if(f->state == DAG_FILE_STATE_EXISTS
|| f->state == DAG_FILE_STATE_COMPLETE
|| dag_file_is_source(f))
return 1;
else
return 0;
}
/* Reports if a file is in the process of being created, downloaded,
* or uploaded. As in file in transition */
int dag_file_in_trans( const struct dag_file *f )
{
if(f->state == DAG_FILE_STATE_EXPECT
|| f->state == DAG_FILE_STATE_DOWN
|| f->state == DAG_FILE_STATE_UP)
return 1;
else
return 0;
}
/* If the file exists, return actual size, else return estimated
* size. In the default case that size is 1GB */
uint64_t dag_file_size( const struct dag_file *f )
{
if(dag_file_should_exist(f))
return f->actual_size;
return f->estimated_size;
}
/* Returns the sum of results for dag_file_size for each file
* in list. */
uint64_t dag_file_list_size(struct list *s)
{
struct dag_file *f;
uint64_t size = 0;
list_first_item(s);
while((f = list_next_item(s)))
size += dag_file_size(f);
return size;
}
/* Returns the sum of results for dag_file_size for each file
* in set. */
uint64_t dag_file_set_size(struct set *s)
{
struct dag_file *f;
uint64_t size = 0;
set_first_element(s);
while((f = set_next_element(s)))
size += dag_file_size(f);
return size;
}
int dag_file_coexist_files(struct set *s, struct dag_file *f)
{
struct dag_node *n;
list_first_item(f->needed_by);
while((n = list_next_item(f->needed_by))){
if(set_lookup(s, n))
return 1;
}
return 0;
}
void dag_file_mount_clean(struct dag_file *df) {
if(!df) return;
if(df->source) {
free(df->source);
df->source = NULL;
}
if(df->cache_name) {
free(df->cache_name);
df->cache_name = NULL;
}
}
/* vim: set noexpandtab tabstop=4: */
|