示例#1
0
void ADIOI_IME_Open(ADIO_File fd,
                   int *error_code)
{
    static char myname[] = "ADIOI_IME_OPEN";
    struct ADIOI_IME_fs_s *ime_fs;
    int perm;
    int amode = 0;
    int ret;
    int rank = 0;
    mode_t old_mask;

    /* validate input args */
    if (!fd)
    {
        *error_code = MPI_ERR_FILE;
        return;
    }
    if (!error_code)
    {
        *error_code = MPI_ERR_FILE;
        return;
    }

    /* setup file permissions */
    if (fd->perm == ADIO_PERM_NULL)
    {
        old_mask = umask(022);
        umask(old_mask);
        perm = old_mask ^ 0666;
    }
    else
        perm = fd->perm;

    /* setup the file access mode */
    if (fd->access_mode & ADIO_CREATE)
        amode = amode | O_CREAT;
    if (fd->access_mode & ADIO_RDONLY)
        amode = amode | O_RDONLY;
    if (fd->access_mode & ADIO_WRONLY)
        amode = amode | O_WRONLY;
    if (fd->access_mode & ADIO_RDWR)
        amode = amode | O_RDWR;
    if (fd->access_mode & ADIO_EXCL)
        amode = amode | O_EXCL;

    /* XXX no O_APPEND support */
    assert((fd->access_mode & ADIO_APPEND) == 0);

    /* init IME */
    MPI_Comm_rank(fd->comm, &rank);
    ADIOI_IME_Init(rank, error_code);
    if (*error_code != MPI_SUCCESS)
        return;

    ime_fs = (ADIOI_IME_fs *) ADIOI_Malloc(sizeof(ADIOI_IME_fs));

    /* --BEGIN ERROR HANDLING-- */
    if (ime_fs == NULL) {
        *error_code = MPIO_Err_create_code(MPI_SUCCESS,
                                           MPIR_ERR_RECOVERABLE,
                                           myname, __LINE__,
                                           MPI_ERR_UNKNOWN,
                                           "Error allocating memory", 0);
        return;
    }

    ime_fs->ime_filename = ADIOI_IME_Add_prefix(fd->filename);

    /* all processes open the file */
    ret = ime_native_open(ime_fs->ime_filename, amode, perm);
    if (ret < 0)
    {
        *error_code = MPI_ERR_FILE;
        ADIOI_Free(ime_fs->ime_filename);
        ADIOI_Free(ime_fs);
        return;
    }

    fd->fd_sys = ret;
    fd->fd_direct = -1;
    fd->fs_ptr = ime_fs;

    *error_code = MPI_SUCCESS;

    return;
}
示例#2
0
文件: ime.c 项目: arh/fio
/* This functions mimics the generic_file_open function, but issues
   IME native calls instead of POSIX calls. */
static int fio_ime_open_file(struct thread_data *td, struct fio_file *f)
{
	int flags = 0;
	int ret;
	uint64_t desired_fs;
	char *ime_filename;

	dprint(FD_FILE, "fd open %s\n", f->file_name);

	if (td_trim(td)) {
		td_verror(td, EINVAL, "IME does not support TRIM operation");
		return 1;
	}

	if (td->o.oatomic) {
		td_verror(td, EINVAL, "IME does not support atomic IO");
		return 1;
	}
	if (td->o.odirect)
		flags |= O_DIRECT;
	if (td->o.sync_io)
		flags |= O_SYNC;
	if (td->o.create_on_open && td->o.allow_create)
		flags |= O_CREAT;

	if (td_write(td)) {
		if (!read_only)
			flags |= O_RDWR;

		if (td->o.allow_create)
			flags |= O_CREAT;
	} else if (td_read(td)) {
		flags |= O_RDONLY;
	} else {
		/* We should never go here. */
		td_verror(td, EINVAL, "Unsopported open mode");
		return 1;
	}

	ime_filename = fio_set_ime_filename(f->file_name);
	if (ime_filename == NULL)
		return 1;
	f->fd = ime_native_open(ime_filename, flags, 0600);
	if (f->fd == -1) {
		char buf[FIO_VERROR_SIZE];
		int __e = errno;

		snprintf(buf, sizeof(buf), "open(%s)", f->file_name);
		td_verror(td, __e, buf);
		return 1;
	}

	/* Now we need to make sure the real file size is sufficient for FIO
	   to do its things. This is normally done before the file open function
	   is called, but because FIO would use POSIX calls, we need to do it
	   ourselves */
	ret = fio_ime_get_file_size(td, f);
	if (ret < 0) {
		ime_native_close(f->fd);
		td_verror(td, errno, "ime_get_file_size");
		return 1;
	}

	desired_fs = f->io_size + f->file_offset;
	if (td_write(td)) {
		dprint(FD_FILE, "Laying out file %s%s\n",
			DEFAULT_IME_FILE_PREFIX, f->file_name);
		if (!td->o.create_on_open &&
				f->real_file_size < desired_fs &&
				ime_native_ftruncate(f->fd, desired_fs) < 0) {
			ime_native_close(f->fd);
			td_verror(td, errno, "ime_native_ftruncate");
			return 1;
		}
		if (f->real_file_size < desired_fs)
			f->real_file_size = desired_fs;
	} else if (td_read(td) && f->real_file_size < desired_fs) {
		ime_native_close(f->fd);
		log_err("error: can't read %lu bytes from file with "
						"%lu bytes\n", desired_fs, f->real_file_size);
		return 1;
	}

	return 0;
}