Browse Source

Disk operations have the control of the directory creation and suppression

Corentin Salingue 8 years ago
parent
commit
58165fa899
4 changed files with 54 additions and 27 deletions
  1. 0 5
      src/core/disk.c
  2. 26 11
      src/core/disk_ops/disk_stdio.c
  3. 26 10
      src/core/disk_ops/unistd/disk_unistd_global.c
  4. 2 1
      src/core/workers.c

+ 0 - 5
src/core/disk.c

@@ -451,23 +451,19 @@ void _starpu_swap_init(void)
 	backend = starpu_getenv("STARPU_DISK_SWAP_BACKEND");
 	if (!backend)
 	{
-		_starpu_mkpath(path, S_IRWXU);
 		ops = &starpu_disk_unistd_ops;
 	}
 	else if (!strcmp(backend, "stdio"))
 	{
-		_starpu_mkpath(path, S_IRWXU);
 		ops = &starpu_disk_stdio_ops;
 	}
 	else if (!strcmp(backend, "unistd"))
 	{
-		_starpu_mkpath(path, S_IRWXU);
 		ops = &starpu_disk_unistd_ops;
 	}
 	else if (!strcmp(backend, "unistd_o_direct"))
 	{
 #ifdef STARPU_LINUX_SYS
-		_starpu_mkpath(path, S_IRWXU);
 		ops = &starpu_disk_unistd_o_direct_ops;
 #else
 		_STARPU_DISP("Warning: o_direct support is not compiled in, could not enable disk swap");
@@ -487,7 +483,6 @@ void _starpu_swap_init(void)
         else if (!strcmp(backend, "hdf5"))
         {
 #ifdef STARPU_HAVE_HDF5
-                _starpu_mkpath(path, S_IRWXU);
                 ops = &starpu_disk_hdf5_ops;
 #else
 		_STARPU_DISP("Warning: hdf5 support is not compiled in, could not enable disk swap");

+ 26 - 11
src/core/disk_ops/disk_stdio.c

@@ -55,6 +55,12 @@ struct starpu_stdio_obj
 	starpu_pthread_mutex_t mutex;
 };
 
+struct starpu_stdio_base
+{
+	char * path;
+	int created;
+};
+
 static struct starpu_stdio_obj *_starpu_stdio_init(int descriptor, char *path, size_t size)
 {
 	struct starpu_stdio_obj *obj;
@@ -127,9 +133,10 @@ static void _starpu_stdio_fini(struct starpu_stdio_obj *obj)
 static void *starpu_stdio_alloc(void *base, size_t size)
 {
 	struct starpu_stdio_obj *obj;
+	struct starpu_stdio_base * fileBase = (struct starpu_stdio_base *) base;
 
 	int id;
-	char *baseCpy = _starpu_mktemp_many(base, TEMP_HIERARCHY_DEPTH, O_RDWR | O_BINARY, &id);
+	char *baseCpy = _starpu_mktemp_many(fileBase->path, TEMP_HIERARCHY_DEPTH, O_RDWR | O_BINARY, &id);
 
 	/* fail */
 	if (!baseCpy)
@@ -171,11 +178,12 @@ static void starpu_stdio_free(void *base STARPU_ATTRIBUTE_UNUSED, void *obj, siz
 /* open an existing memory on disk */
 static void *starpu_stdio_open(void *base, void *pos, size_t size)
 {
+	struct starpu_stdio_base * fileBase = (struct starpu_stdio_base *) base;
 	struct starpu_stdio_obj *obj;
 	/* create template */
 	char *baseCpy;
-	_STARPU_MALLOC(baseCpy, strlen(base)+1+strlen(pos)+1);
-	strcpy(baseCpy,(char *) base);
+	_STARPU_MALLOC(baseCpy, strlen(fileBase->path)+1+strlen(pos)+1);
+	strcpy(baseCpy,(char *) fileBase->path);
 	strcat(baseCpy,(char *) "/");
 	strcat(baseCpy,(char *) pos);
 
@@ -316,28 +324,35 @@ static int starpu_stdio_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *obj
 	return 0;
 }
 
-/* create a new copy of parameter == base */
 static void *starpu_stdio_plug(void *parameter, starpu_ssize_t size STARPU_ATTRIBUTE_UNUSED)
 {
-	char *tmp;
-	_STARPU_MALLOC(tmp, sizeof(char)*(strlen(parameter)+1));
-	strcpy(tmp,(char *) parameter);
+	struct starpu_stdio_base * base;
+	_STARPU_MALLOC(base, sizeof(*base));
+	base->created = 0;
+
+	_STARPU_MALLOC(base->path, sizeof(char)*(strlen(parameter)+1));
+	strcpy(base->path,(char *) parameter);
 
 	{
 		struct stat buf;
-		if (!(stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)))
+		if (!(stat(base->path, &buf) == 0 && S_ISDIR(buf.st_mode)))
 		{
-			_STARPU_ERROR("Directory '%s' does not exist\n", tmp);
+			_starpu_mkpath(base->path, S_IRWXU);
+			base->created = 1;
 		}
 	}
 
-	return (void *) tmp;
+	return (void *) base;
 }
 
 /* free memory allocated for the base */
 static void starpu_stdio_unplug(void *base)
 {
-	free(base);
+	struct starpu_stdio_base * fileBase = (struct starpu_stdio_base *) base;
+	if (fileBase->created)
+		unlink(fileBase->path);
+	free(fileBase->path);
+	free(fileBase);
 }
 
 static int get_stdio_bandwidth_between_disk_and_main_ram(unsigned node)

+ 26 - 10
src/core/disk_ops/unistd/disk_unistd_global.c

@@ -55,6 +55,12 @@
 
 static unsigned starpu_unistd_opened_files;
 
+struct starpu_unistd_base
+{
+	char * path;
+	int created;
+};
+
 #if defined(HAVE_LIBAIO_H)
 struct starpu_unistd_aiocb
 {
@@ -127,7 +133,8 @@ static void _starpu_unistd_fini(struct starpu_unistd_global_obj *obj)
 void *starpu_unistd_global_alloc(struct starpu_unistd_global_obj *obj, void *base, size_t size)
 {
 	int id;
-	char *baseCpy = _starpu_mktemp_many(base, TEMP_HIERARCHY_DEPTH, obj->flags, &id);
+	struct starpu_unistd_base * fileBase = (struct starpu_unistd_base *) base;
+	char *baseCpy = _starpu_mktemp_many(fileBase->path, TEMP_HIERARCHY_DEPTH, obj->flags, &id);
 
 	/* fail */
 	if (!baseCpy)
@@ -167,10 +174,11 @@ void starpu_unistd_global_free(void *base STARPU_ATTRIBUTE_UNUSED, void *obj, si
 /* open an existing memory on disk */
 void *starpu_unistd_global_open(struct starpu_unistd_global_obj *obj, void *base, void *pos, size_t size)
 {
+	struct starpu_unistd_base * fileBase = (struct starpu_unistd_base *) base;
 	/* create template */
 	char *baseCpy;
-	_STARPU_MALLOC(baseCpy, strlen(base)+1+strlen(pos)+1);
-	strcpy(baseCpy,(char *) base);
+	_STARPU_MALLOC(baseCpy, strlen(fileBase->path)+1+strlen(pos)+1);
+	strcpy(baseCpy,(char *) fileBase->path);
 	strcat(baseCpy,(char *) "/");
 	strcat(baseCpy,(char *) pos);
 
@@ -432,25 +440,33 @@ int starpu_unistd_global_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *ob
 /* create a new copy of parameter == base */
 void *starpu_unistd_global_plug(void *parameter, starpu_ssize_t size STARPU_ATTRIBUTE_UNUSED)
 {
-	char *tmp;
-	_STARPU_MALLOC(tmp, sizeof(char)*(strlen(parameter)+1));
-	strcpy(tmp,(char *) parameter);
+	struct starpu_unistd_base * base;
+	_STARPU_MALLOC(base, sizeof(*base));
+	base->created = 0;
+
+	_STARPU_MALLOC(base->path, sizeof(char)*(strlen(parameter)+1));
+	strcpy(base->path,(char *) parameter);
 
 	{
 		struct stat buf;
-		if (!(stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)))
+		if (!(stat(base->path, &buf) == 0 && S_ISDIR(buf.st_mode)))
 		{
-			_STARPU_ERROR("Directory '%s' does not exist\n", tmp);
+			_starpu_mkpath(base->path, S_IRWXU);
+			base->created = 1;
 		}
 	}
 
-	return (void *) tmp;
+	return (void *) base;
 }
 
 /* free memory allocated for the base */
 void starpu_unistd_global_unplug(void *base)
 {
-	free(base);
+	struct starpu_unistd_base * fileBase = (struct starpu_unistd_base *) base;
+	if (fileBase->created)
+		rmdir(fileBase->path);
+	free(fileBase->path);
+	free(fileBase);
 }
 
 int get_unistd_global_bandwidth_between_disk_and_main_ram(unsigned node)

+ 2 - 1
src/core/workers.c

@@ -1383,7 +1383,8 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 		_starpu_launch_drivers(&_starpu_config);
 
 	/* Allocate swap, if any */
-	_starpu_swap_init();
+	if (!is_a_sink)
+		_starpu_swap_init();
 
 	_starpu_watchdog_init();