Exemple #1
0
static char *
remove_whole_file_or_dir(char *path, int is_recursive)
{
	char *e, *e2;
	struct gfs_stat gs;
	char cwdbuf[PATH_MAX * 2];

	e = gfs_stat(path, &gs);
	if (e == GFARM_ERR_NO_FRAGMENT_INFORMATION)
		e2 = gfs_unlink(path);	
	if (e != NULL)
		return (e);

	if (GFARM_S_ISREG(gs.st_mode)) {
		e = gfs_unlink(path);
	} else if (GFARM_S_ISDIR(gs.st_mode)) {
		if (!is_recursive)
	        	return (GFARM_ERR_IS_A_DIRECTORY);
		e = gfs_getcwd(cwdbuf, sizeof(cwdbuf));
		if (e != NULL)
			return (e);
		e = gfs_chdir(path);
		if (e != NULL)
			return (e);
		remove_cwd_entries();
		e = gfs_chdir_canonical(cwdbuf);
		if (e != NULL)
			return (e);
		e = gfs_rmdir(path);
	}
	gfs_stat_free(&gs);
	return (e);
}
int webgfarm_api_v1_delete_file(request_rec *r) {
    // get filepath from request
    char *filepath = webgfarm_api_v1_getfilepath(r);

    gfarm_error_t gerr;

    if (isdir(filepath)) { // dir
        gerr = gfs_rmdir(filepath);
    } else { // file
        gerr = gfs_unlink(filepath);
    }

    if (gerr != GFARM_ERR_NO_ERROR) {
        switch (gerr) {
            case GFARM_ERR_NO_SUCH_FILE_OR_DIRECTORY:
                return HTTP_NOT_FOUND;
                break;
            case GFARM_ERR_PERMISSION_DENIED:
                return HTTP_FORBIDDEN;
                break;
                //FIXEME: Support more error;
            default:
                return HTTP_INTERNAL_SERVER_ERROR;
        }
    } else {
        return OK;
    }
}
Exemple #3
0
gfarm_error_t
do_test()
{
	gfarm_error_t e;
	struct timeval start_time, end_time, exec_time;
	float f, t;

	e = gfperf_create_file_on_gfarm(testdir_filename,
					from_gfsd_name, file_size);
	if (e != GFARM_ERR_NO_ERROR)
		return (e);

	gettimeofday(&start_time, NULL);
	e = do_replica();
	gettimeofday(&end_time, NULL);
	if (e != GFARM_ERR_NO_ERROR) {
		gfs_unlink(testdir_filename);
		return (e);
	}

	e = gfs_unlink(testdir_filename);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "unlink %s: %s\n", testdir_filename,
			gfarm_error_string(e));
		return (e);
	}

	gfperf_sub_timeval(&end_time, &start_time, &exec_time);
	t = (float)exec_time.tv_sec + (float)exec_time.tv_usec/1000000;
	f = (float)file_size / t;
	if (parallel_flag)
		printf("parallel/%s/replica/libgfarm/%s/%s/%s = "
		       "%.02f bytes/sec %g sec\n",
		       group_name,
		       file_size_string, from_gfsd_name, to_gfsd_name, f, t);
	else
		printf("replica/libgfarm/%s/%s/%s = %.02f bytes/sec %g sec\n",
		       file_size_string, from_gfsd_name, to_gfsd_name, f, t);

	return (GFARM_ERR_NO_ERROR);
}
Exemple #4
0
int
__unlink(const char *path)
{
	const char *e;
	char *url;

	_gfs_hook_debug_v(fprintf(stderr, "Hooking __unlink(%s)\n", path));

	if (!gfs_hook_is_url(path, &url))
		return syscall(SYS_unlink, path);

	_gfs_hook_debug(fprintf(stderr, "GFS: Hooking __unlink(%s)\n", path));
	e = gfs_unlink(url);
	free(url);
	if (e == NULL)
		return (0);

	_gfs_hook_debug(fprintf(stderr, "GFS: __unlink: %s\n", e));
	errno = gfarm_error_to_errno(e);
	return (-1);
}
Exemple #5
0
static void
remove_cwd_entries()
{
	char *e;
	char cwdbf[PATH_MAX * 2];
	int i;
	GFS_Dir dir;
	struct gfs_dirent *entry;
	gfarm_stringlist entry_list;

	e = gfs_getcwd(cwdbf, sizeof(cwdbf));
	if (e != NULL) {
		fprintf(stderr, "%s\n", e);
		return;
	}
	e = gfs_opendir(".", &dir);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", cwdbf, e);
		return;
	}
	e = gfarm_stringlist_init(&entry_list);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", cwdbf, e);
		return;
	}
	while ((e = gfs_readdir(dir, &entry)) == NULL && entry != NULL) {
		char *p;

		if (entry->d_name[0] == '.' && (entry->d_name[1] == '\0' ||
		    (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
			continue; /* "." or ".." */
	 	p = strdup(entry->d_name);
		if (p == NULL) {
			fprintf(stderr, "%s\n", GFARM_ERR_NO_MEMORY);
			exit (1);
		}
		e = gfarm_stringlist_add(&entry_list, p);
		if (e != NULL) {
			fprintf(stderr, "%s/%s: %s\n",
					cwdbf, entry->d_name, e);
		}
	}
	if (e != NULL)
		fprintf(stderr, "%s: %s\n", cwdbf, e);
	gfs_closedir(dir);
	for (i = 0; i < gfarm_stringlist_length(&entry_list); i++) {
		struct gfs_stat gs;
		char *path = gfarm_stringlist_elem(&entry_list, i);

		e = gfs_stat(path, &gs);
		if (e != NULL) {
			fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
			continue;
		}
		if (GFARM_S_ISREG(gs.st_mode)) {
			char *url;

			url = gfarm_url_prefix_add(path);
			if (url == NULL) {
				fprintf(stderr, "%s\n", GFARM_ERR_NO_MEMORY);
				exit (1);
			}
			e = gfs_unlink(url);
			if (e != NULL)
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
			free(url);
		} else if (GFARM_S_ISDIR(gs.st_mode)) {
			e = gfs_chdir(path);
			if (e != NULL) {
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
				continue;
			}
			remove_cwd_entries();
			e = gfs_chdir("..");
			if (e != NULL) {
				fprintf(stderr, "%s: %s\n", cwdbf, e);
				exit (1);
			}
			e = gfs_rmdir(path);
			if (e != NULL)
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
		}
		gfs_stat_free(&gs);
	}
	gfarm_stringlist_free_deeply(&entry_list);
}
Exemple #6
0
static char *
unlink_file(char *path, void *closure)
{
	return (gfs_unlink(path));
}
Exemple #7
0
int
FUNC___OPEN(const char *path, int oflag, ...)
{
	GFS_File gf;
	const char *e;
	char *url;
	va_list ap;
	mode_t mode;
	int filedes;
	struct gfs_stat gs;
	int file_exist, file_size = 0, is_directory = 0;
	int nf = -1, np;

	va_start(ap, oflag);
	mode = va_arg(ap, mode_t);
	va_end(ap);

	_gfs_hook_debug_v(fprintf(stderr,
	    "Hooking " S(FUNC___OPEN) "(%s, 0x%x)\n", path, oflag));

	if (!gfs_hook_is_url(path, &url))
		return (SYSCALL_OPEN(path, oflag, mode));

	if (gfs_hook_get_current_view() == section_view)
		e = gfs_stat_section(url, gfs_hook_get_current_section(), &gs);
	else
		e = gfs_stat(url, &gs);
	if (e == GFARM_ERR_NO_SUCH_OBJECT)
		file_exist = 0;
	else if (e == NULL) {
		file_exist = 1;
		file_size = gs.st_size;
		is_directory = GFARM_S_ISDIR(gs.st_mode);
		gfs_stat_free(&gs);
	}
	else {
		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) ": gfs_stat: %s\n", e));
		/* XXX - metadata may be incomplete. anyway, continue. */
		file_exist = 1;
		file_size = 0;
		/* XXX - metadata of a directory should not be imcomplete */
		is_directory = 0; 
	}

	/*
	 * XXX - stopgap implementation of O_WRONLY/O_RDWR, O_CREAT,
	 * O_TRUNC flags
	 */
	if (!file_exist && (oflag & O_CREAT) != 0) {

		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) "(%s, 0x%x, 0%o)\n",
		    url, oflag, mode));

		e = gfs_pio_create(url, oflag, mode, &gf);
		if (e == NULL)
			gfs_hook_add_creating_file(gf);
	}
	else if ((oflag & O_ACCMODE) == O_WRONLY
		 || (oflag & O_ACCMODE) == O_RDWR) {

		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) "(%s, 0x%x, 0%o)\n",
		    url, oflag, mode));

		if (file_exist && (file_size == 0 || (oflag & O_TRUNC) != 0)) {
			/*
			 * XXX - O_TRUNC is basically supported in
			 * Gfarm v1 except in global file view.
			 * This case needs to be implemented in
			 * gfs_pio_set_view_global() in gfs_pio_global.c.
			 */
			if (gfs_hook_get_current_view() == global_view)
				gfs_unlink(url); /* XXX - FIXME */
			/*
			 * gfs_pio_create assumes GFARM_FILE_TRUNC.
			 * It is not necessary to set O_TRUNC explicitly.
			 */
			e = gfs_pio_create(url, oflag, mode, &gf);
			if (e == NULL)
				gfs_hook_add_creating_file(gf);
		}
		else if (file_exist) { /* read-write mode: not supported yet */
			_gfs_hook_debug(fprintf(stderr,
				"GFS: Hooking " S(FUNC___OPEN)
				": unsupported flags 0%o\n", oflag));
			free(url);
			errno = ENOSYS;
			return (-1);
		}
		else { /* no such file or directory */
			_gfs_hook_debug(fprintf(stderr,
				"GFS: Hooking " S(FUNC___OPEN)
				": no such file or directory\n"));
			free(url);
			errno = ENOENT;
			return (-1);
		}
	}
	/* XXX - end of stopgap implementation */
	else {
		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) "(%s, 0x%x)\n", url, oflag));

		if (file_exist && is_directory) {
			GFS_Dir dir;

			e = gfs_opendir(url, &dir);
                        if (e == NULL) {
                                filedes = gfs_hook_insert_gfs_dir(dir, url);
                                _gfs_hook_debug(
                                        if (filedes != -1) {
                                                fprintf(stderr,
                                                    "GFS: Hooking "
                                                    S(FUNC___OPEN)
                                                    " --> %d\n", filedes);
                                        }
                                );
                                free(url);
                                return (filedes);
			}
Exemple #8
0
int
FUNC___OPEN(const char *path, int oflag, ...)
{
	GFS_File gf;
	const char *e;
	char *url, *sec;
	va_list ap;
	mode_t mode;
	int filedes;

	va_start(ap, oflag);
	mode = va_arg(ap, mode_t);
	va_end(ap);

	_gfs_hook_debug_v(fprintf(stderr,
	    "Hooking " S(FUNC___OPEN) "(%s, 0x%x)\n", path, oflag));

	if (!gfs_hook_is_url(path, &url, &sec))
		return (SYSCALL_OPEN(path, oflag, mode));

	/* XXX - ROOT I/O creates a new file with O_CREAT|O_RDWR mode. */
	/* XXX - FIXME */
	if ((oflag & O_CREAT) != 0 || (oflag & O_TRUNC) != 0) {
		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) "(%s:%s, 0x%x, 0%o)\n",
		    url, sec != NULL ? sec : "(null)", oflag, mode));
		if (oflag & O_TRUNC) {
			/*
			 * Hooking open syscall does not mean to open
			 * an entire file but a file fragment in local and
			 * index file views.  gfs_unlink() should not be
			 * called in both views.
			 */
			if (_gfs_hook_default_view == global_view)
				gfs_unlink(url); /* XXX - FIXME */
			e = gfs_pio_create(url, oflag, mode, &gf);
		} else {
			e = gfs_pio_open(url, oflag, &gf);
			if (e == GFARM_ERR_NO_SUCH_OBJECT) /* XXX - FIXME */
				e = gfs_pio_create(url, oflag, mode, &gf);
		}
	} else {
		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) "(%s:%s, 0x%x)\n",
		    url, sec != NULL ? sec : "(null)", oflag));
		e = gfs_pio_open(url, oflag, &gf);
	}
	free(url);
	if (e != NULL) {
		_gfs_hook_debug(fprintf(stderr,
		    "GFS: Hooking " S(FUNC___OPEN) ": %s\n", e));
		errno = gfarm_error_to_errno(e);
		return (-1);
	}

	if (sec != NULL || _gfs_hook_default_view == index_view) {
		if (sec != NULL) {
			_gfs_hook_debug(fprintf(stderr,
				"GFS: set_view_section(%s, %s)\n", url, sec));
			e = gfs_pio_set_view_section(gf, sec, NULL, 0);
			free(sec);
		} else {
			_gfs_hook_debug(fprintf(stderr,
				"GFS: set_view_index(%s, %d, %d)\n", url,
				_gfs_hook_num_fragments, _gfs_hook_index));
			e = gfs_pio_set_view_index(gf, _gfs_hook_num_fragments,
				_gfs_hook_index, NULL, 0);
		}
		if (e != NULL) {
			_gfs_hook_debug(fprintf(stderr,
			    "GFS: set_view_section: %s\n", e));
			gfs_pio_close(gf);
			errno = gfarm_error_to_errno(e);
			return (-1);
		}
	} else if (_gfs_hook_default_view == local_view) {
		int nf = -1, np;
		/*
		 * If the number of fragments is not the same as the
		 * number of parallel processes, or the file is not
		 * fragmented, do not change to the local file view.
		 */
		if (gfs_pio_get_nfragment(gf, &nf) ==
			GFARM_ERR_FRAGMENT_INDEX_NOT_AVAILABLE ||
		    (gfs_pio_get_node_size(&np) == NULL && nf == np)) {
			_gfs_hook_debug(fprintf(stderr,
				"GFS: set_view_local(%s (%d, %d))\n",
					url, gfarm_node, gfarm_nnode));
			if ((e = gfs_pio_set_view_local(gf, 0)) != NULL) {
				_gfs_hook_debug(fprintf(stderr,
					"GFS: set_view_local: %s\n", e));
				gfs_pio_close(gf);
				errno = gfarm_error_to_errno(e);
				return (-1);
			}
		}
	}
	filedes = gfs_hook_insert_gfs_file(gf);
	_gfs_hook_debug(
		if (filedes != -1) {
			fprintf(stderr,
			    "GFS: Hooking " S(FUNC___OPEN) " --> %d(%d)\n",
			    filedes, gfs_pio_fileno(gf));
		}
	);