Пример #1
0
int do_close(long fd)
{
	if(do_chirp) {
		return chirp_reli_close((struct chirp_file *) fd, stoptime);
	} else {
		return close(fd);
	}
}
Пример #2
0
void chirp_matrix_close(struct chirp_matrix *a, time_t stoptime)
{
	int i;
	for(i = 0; i < a->nfiles; i++)
		chirp_reli_close(a->rfiles[i], stoptime);
	free(a->bulkio);
	free(a->rfiles);
	free(a);
}
Пример #3
0
struct chirp_matrix *chirp_matrix_open(const char *host, const char *path, time_t stoptime)
{

	int result, i;
	char *line;
	char *tmp;
	struct chirp_matrix *matrix;

	matrix = xxmalloc(sizeof(*matrix));

	result = chirp_reli_getfile_buffer(host, path, &line, stoptime);
	if(result < 0) {
		debug(D_CHIRP, "matrix: could not create metadata file /chirp/%s/%s: %s\n", host, path, strerror(errno));
		return 0;
	}
	tmp = strtok(line, SEPCHARS);
	matrix->width = atoi(tmp);
	tmp = strtok(NULL, SEPCHARS);
	matrix->height = atoi(tmp);
	tmp = strtok(NULL, SEPCHARS);
	matrix->element_size = atoi(tmp);
	tmp = strtok(NULL, SEPCHARS);
	matrix->nhosts = atoi(tmp);
	tmp = strtok(NULL, SEPCHARS);
	matrix->nfiles = atoi(tmp);

	matrix->n_row_per_file = matrix->height / matrix->nfiles;
	if(matrix->height % matrix->nfiles)
		matrix->n_row_per_file++;

	matrix->rfiles = malloc(sizeof(struct chirp_file *) * matrix->nfiles);
	matrix->bulkio = malloc(sizeof(struct chirp_bulkio) * matrix->nfiles);

	for(i = 0; i < matrix->nfiles; i++) {
		char *host = strtok(NULL, SEPCHARS);
		char *path = strtok(NULL, SEPCHARS);
		matrix->rfiles[i] = chirp_reli_open(host, path, O_RDWR | O_CREAT, 0755, stoptime);
		if(!matrix->rfiles[i]) {
			int j;
			for(j = 0; j < i; j++)
				chirp_reli_close(matrix->rfiles[i], stoptime);
			free(line);
			return 0;
		}
	}

	free(line);


	return matrix;
}
Пример #4
0
static INT64_T do_put_one_fifo(const char *hostport, const char *source_file, const char *target_file, int mode, time_t stoptime)
{
	FILE *file;
	int save_errno;
	struct chirp_file *cf = 0;
	INT64_T result;
	INT64_T offset = 0;

	file = fopen64(source_file, "r");
	if(!file)
		return -1;

	cf = chirp_reli_open(hostport, target_file, O_WRONLY|O_CREAT|O_TRUNC, 0600, stoptime);
	if(cf) {
		size_t n;
		char buffer[65536];
		while((n = fread(buffer, sizeof(char), 65536, file))) {
			if(chirp_reli_pwrite(cf, buffer, n, offset, stoptime) < 0)
				goto fail;
			offset += n;
		}
		if (chirp_reli_close(cf, stoptime) < 0)
			goto fail;
	}

	result = offset;
	goto out;
fail:
	result = -1;
	goto out;
out:
	save_errno = errno;
	fclose(file);
	errno = save_errno;
	return result;
}
Пример #5
0
static INT64_T chirp_thirdput_recursive(const char *subject, const char *lpath, const char *hostname, const char *rpath, const char *hostsubject, time_t stoptime)
{
	struct chirp_stat info;
	INT64_T size = 0, result;
	char newlpath[CHIRP_PATH_MAX];
	char newrpath[CHIRP_PATH_MAX];
	int save_errno;
	int my_target_acl = 0;

	result = cfs->lstat(lpath, &info);
	if(result < 0)
		return result;

	if(S_ISDIR(info.cst_mode)) {
		CHIRP_FILE *aclfile;
		struct chirp_dir *dir;
		struct chirp_dirent *d;
		char aclsubject[CHIRP_PATH_MAX];
		int aclflags;

		if(!chirp_acl_check_dir(lpath, subject, CHIRP_ACL_LIST))
			return -1;

		// create the directory, but do not fail if it already exists
		result = chirp_reli_mkdir(hostname, rpath, 0700, stoptime);
		if(result < 0 && errno != EEXIST)
			return result;

		// set the access control to include the initiator
		result = chirp_reli_setacl(hostname, rpath, subject, "rwldax", stoptime);
		if(result < 0 && errno != EACCES)
			return result;

		// transfer each of the directory contents recurisvely
		dir = cfs->opendir(lpath);
		while((d = cfs->readdir(dir))) {
			if(!strcmp(d->name, "."))
				continue;
			if(!strcmp(d->name, ".."))
				continue;
			if(!strncmp(d->name, ".__", 3))
				continue;
			sprintf(newlpath, "%s/%s", lpath, d->name);
			sprintf(newrpath, "%s/%s", rpath, d->name);
			result = chirp_thirdput_recursive(subject, newlpath, hostname, newrpath, hostsubject, stoptime);
			if(result >= 0) {
				size += result;
			} else {
				result = -1;
				break;
			}
		}
		save_errno = errno;

		// finally, set the acl to duplicate the source directory,
		// but do not take away permissions from me or the initiator
		cfs->closedir(dir);

		aclfile = chirp_acl_open(lpath);
		if(!aclfile)
			return -1;

		while(chirp_acl_read(aclfile, aclsubject, &aclflags)) {

			// wait until the last minute to take away my permissions
			if(!strcmp(aclsubject, hostsubject)) {
				my_target_acl = aclflags;
			}
			// do not take permissions away from the initiator
			if(!strcmp(aclsubject, subject)) {
				continue;
			}

			chirp_reli_setacl(hostname, rpath, aclsubject, chirp_acl_flags_to_text(aclflags), stoptime);
		}

		chirp_acl_close(aclfile);

		// after setting everything else, then set my permissions from the ACL
		chirp_reli_setacl(hostname, rpath, hostsubject, chirp_acl_flags_to_text(my_target_acl), stoptime);

		errno = save_errno;

		if(result >= 0) {
			return size;
		} else {
			return -1;
		}

	} else if(S_ISLNK(info.cst_mode)) {
		if(!chirp_acl_check(lpath, subject, CHIRP_ACL_READ))
			return -1;
		result = cfs->readlink(lpath, newlpath, sizeof(newlpath));
		if(result < 0)
			return -1;
		return chirp_reli_symlink(hostname, newlpath, rpath, stoptime);
	} else if(S_ISREG(info.cst_mode)) {
		if(!chirp_acl_check(lpath, subject, CHIRP_ACL_READ))
			return -1;
		int fd = cfs->open(lpath, O_RDONLY, 0);
		if(fd >= 0) {
			struct chirp_file *F = chirp_reli_open(hostname, rpath, O_WRONLY|O_CREAT|O_TRUNC, info.cst_mode, stoptime);
			if(F) {
				char buffer[65536];
				INT64_T offset = 0;
				INT64_T nread;
				while ((nread = cfs->pread(fd, buffer, sizeof(buffer), offset)) > 0) {
					INT64_T nwritten = 0;
					while (nwritten < nread) {
						INT64_T nwrite = chirp_reli_pwrite(F, buffer+nwritten, nread-nwritten, offset, stoptime);
						if (nwrite == -1) {
							save_errno = errno;
							cfs->close(fd);
							chirp_reli_close(F, stoptime);
							errno = save_errno;
							return -1;
						}
						nwritten += nwrite;
						offset += nwrite;
					}
				}
				if(nread == -1) offset = -1;
				save_errno = errno;
				cfs->close(fd);
				chirp_reli_close(F, stoptime);
				errno = save_errno;
				return offset;
			} else {
				save_errno = errno;
				cfs->close(fd);
				errno = save_errno;
				return -1;
			}
		} else {
			return -1;
		}
	} else {
		return 0;
	}

	return -1;
}
Пример #6
0
static INT64_T chirp_fs_chirp_close(int fd)
{
	SETUP_FILE
	chirp_fs_file_table[fd] = 0;
	return chirp_reli_close(file, STOPTIME);
}
Пример #7
0
INT64_T chirp_global_close(struct chirp_file * file, time_t stoptime)
{
	return chirp_reli_close(file, stoptime);
}