fsal_status_t MFSL_open(mfsl_object_t * filehandle,     /* IN */
                        fsal_op_context_t * p_context,  /* IN */
                        mfsl_context_t * p_mfsl_context,        /* IN */
                        fsal_openflags_t openflags,     /* IN */
                        fsal_file_t * file_descriptor,  /* OUT */
                        fsal_attrib_list_t * file_attributes    /* [ IN/OUT ] */
    )
{
  return FSAL_open(&filehandle->handle,
                   p_context, openflags, file_descriptor, file_attributes);
}                               /* MFSL_open */
示例#2
0
fsal_status_t GPFSFSAL_open_by_name(fsal_handle_t * dirhandle,      /* IN */
                                fsal_name_t * filename, /* IN */
                                fsal_op_context_t * p_context,  /* IN */
                                fsal_openflags_t openflags,     /* IN */
                                fsal_file_t * file_descriptor,  /* OUT */
                                fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ )
{
  fsal_status_t fsal_status;
  fsal_handle_t filehandle;

  if(!dirhandle || !filename || !p_context || !file_descriptor)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open_by_name);

  fsal_status = FSAL_lookup(dirhandle, filename, p_context, &filehandle, file_attributes);
  if(FSAL_IS_ERROR(fsal_status))
    return fsal_status;

  return FSAL_open(&filehandle, p_context, openflags, file_descriptor, file_attributes);
}
示例#3
0
fsal_status_t MFSL_open(mfsl_object_t * filehandle,     /* IN */
                        fsal_op_context_t * p_context,  /* IN */
                        mfsl_context_t * p_mfsl_context,        /* IN */
                        fsal_openflags_t openflags,     /* IN */
                        mfsl_file_t * file_descriptor,  /* OUT */
                        fsal_attrib_list_t * file_attributes,    /* [ IN/OUT ] */
			void * pextra
    )
{
  struct timeval start, stop, delta ;
  fsal_status_t fsal_status = { ERR_FSAL_NO_ERROR, 0 } ;
  
  gettimeofday( &start, 0 ) ; 
  fsal_status = FSAL_open(&filehandle->handle,
                   p_context, openflags, &file_descriptor->fsal_file, file_attributes);
  gettimeofday( &stop, 0 ) ; 
  delta = mfsl_timer_diff( &stop, &start ) ;
  LogFullDebug( COMPONENT_MFSL, "%s: duration=%ld.%06ld", __FUNCTION__, delta.tv_sec, delta.tv_usec ) ;
  return fsal_status ;
}                               /* MFSL_open */
cache_inode_status_t cache_inode_open(cache_entry_t * pentry,
                                      cache_inode_client_t * pclient,
                                      fsal_openflags_t openflags,
                                      fsal_op_context_t * pcontext,
                                      cache_inode_status_t * pstatus)
{
  fsal_status_t fsal_status;

  if((pentry == NULL) || (pclient == NULL) || (pcontext == NULL) || (pstatus == NULL))
    return CACHE_INODE_INVALID_ARGUMENT;

  if(pentry->internal_md.type != REGULAR_FILE)
    {
      *pstatus = CACHE_INODE_BAD_TYPE;
      return *pstatus;
    }

  /* Open file need to be closed, unless it is already open as read/write */
  if((pentry->object.file.open_fd.openflags != FSAL_O_RDWR) &&
     (pentry->object.file.open_fd.openflags != 0) &&
     (pentry->object.file.open_fd.fileno != 0) &&
     (pentry->object.file.open_fd.openflags != openflags))
    {
#ifdef _USE_MFSL
      fsal_status = MFSL_close(&(pentry->object.file.open_fd.mfsl_fd), &pclient->mfsl_context, NULL);
#else
      fsal_status = FSAL_close(&(pentry->object.file.open_fd.fd));
#endif
      if(FSAL_IS_ERROR(fsal_status) && (fsal_status.major != ERR_FSAL_NOT_OPENED))
        {
          *pstatus = cache_inode_error_convert(fsal_status);

          LogDebug(COMPONENT_CACHE_INODE,
                   "cache_inode_open: returning %d(%s) from FSAL_close",
                   *pstatus, cache_inode_err_str(*pstatus));

          return *pstatus;
        }

      /* force re-openning */
      pentry->object.file.open_fd.last_op = 0;
      pentry->object.file.open_fd.fileno = 0;

    }

  if((pentry->object.file.open_fd.last_op == 0)
     || (pentry->object.file.open_fd.fileno == 0))
    {
      /* opened file is not preserved yet */
#ifdef _USE_MFSL
      fsal_status = MFSL_open(&(pentry->mobject),
                              pcontext,
                              &pclient->mfsl_context,
                              openflags,
                              &pentry->object.file.open_fd.mfsl_fd,
                              &(pentry->object.file.attributes),
                              NULL );
#else
      fsal_status = FSAL_open(&(pentry->object.file.handle),
                              pcontext,
                              openflags,
                              &pentry->object.file.open_fd.fd,
                              &(pentry->object.file.attributes));
#endif

      if(FSAL_IS_ERROR(fsal_status))
        {
          *pstatus = cache_inode_error_convert(fsal_status);

          LogDebug(COMPONENT_CACHE_INODE,
                   "cache_inode_open: returning %d(%s) from FSAL_open",
                   *pstatus, cache_inode_err_str(*pstatus));

          return *pstatus;
        }

#ifdef _USE_MFSL
      pentry->object.file.open_fd.fileno = FSAL_FILENO(&(pentry->object.file.open_fd.mfsl_fd.fsal_file));
#else
      pentry->object.file.open_fd.fileno = FSAL_FILENO(&(pentry->object.file.open_fd.fd));
#endif
      pentry->object.file.open_fd.openflags = openflags;

      LogDebug(COMPONENT_CACHE_INODE,
               "cache_inode_open: pentry %p: lastop=0, fileno = %d, openflags = %d",
               pentry, pentry->object.file.open_fd.fileno, (int) openflags);
    }

  /* regular exit */
  pentry->object.file.open_fd.last_op = time(NULL);

  /* if file descriptor is too high, garbage collect FDs */
  if(pclient->use_fd_cache
     && (pentry->object.file.open_fd.fileno > pclient->max_fd))
    {
      if(cache_inode_gc_fd(pclient, pstatus) != CACHE_INODE_SUCCESS)
        {
          LogCrit(COMPONENT_CACHE_INODE_GC,
                  "FAILURE performing FD garbage collection");
          return *pstatus;
        }
    }

  *pstatus = CACHE_INODE_SUCCESS;
  return *pstatus;

}                               /* cache_inode_open */
示例#5
0
/**
 * FSAL_rcp_by_name:
 * Copy an HPSS file to/from a local filesystem.
 *
 * \param filehandle (input):
 *        Handle of the file to be copied.
 * \param p_context (input):
 *        Authentication context for the operation (user,...).
 * \param p_local_path (input):
 *        Path of the file in the local filesystem.
 * \param transfer_opt (input)
 *
 * \return always ERR_FSAL_NOTSUPP for FSAL_PROXY
 */
fsal_status_t PROXYFSAL_rcp(proxyfsal_handle_t * filehandle,    /* IN */
                            proxyfsal_op_context_t * p_context, /* IN */
                            fsal_path_t * p_local_path, /* IN */
                            fsal_rcpflag_t transfer_opt /* IN */
    )
{

  int local_fd;
  int local_flags;

  proxyfsal_file_t fs_fd;
  fsal_openflags_t fs_flags;

  fsal_status_t st = FSAL_STATUS_NO_ERROR;

  caddr_t IObuffer;

  int to_local = FALSE;
  int to_fs = FALSE;

  int eof = FALSE;

  ssize_t local_size = 0;
  fsal_size_t fs_size;

  /* sanity checks. */

  if(!filehandle || !p_context || !p_local_path)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rcp);

  to_local = ((transfer_opt & FSAL_RCP_FS_TO_LOCAL) == FSAL_RCP_FS_TO_LOCAL);
  to_fs = ((transfer_opt & FSAL_RCP_LOCAL_TO_FS) == FSAL_RCP_LOCAL_TO_FS);

  if(to_local)
    LogFullDebug(COMPONENT_FSAL,
                 "FSAL_rcp: FSAL -> local file (%s)", p_local_path->path);

  if(to_fs)
    LogFullDebug(COMPONENT_FSAL,
                 "FSAL_rcp: local file -> FSAL (%s)", p_local_path->path);

  /* must give the sens of transfert (exactly one) */

  if((!to_local && !to_fs) || (to_local && to_fs))
    Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_rcp);

  /* first, open local file with the correct flags */

  if(to_fs)
    {
      local_flags = O_RDONLY;
    }
  else
    {
      local_flags = O_WRONLY | O_TRUNC;

      if((transfer_opt & FSAL_RCP_LOCAL_CREAT) == FSAL_RCP_LOCAL_CREAT)
        local_flags |= O_CREAT;

      if((transfer_opt & FSAL_RCP_LOCAL_EXCL) == FSAL_RCP_LOCAL_EXCL)
        local_flags |= O_EXCL;

    }

  if(isFullDebug(COMPONENT_FSAL))
    {
      char msg[1024];

      msg[0] = '\0';

      if((local_flags & O_RDONLY) == O_RDONLY)
        strcat(msg, "O_RDONLY ");

      if((local_flags & O_WRONLY) == O_WRONLY)
        strcat(msg, "O_WRONLY ");

      if((local_flags & O_TRUNC) == O_TRUNC)
        strcat(msg, "O_TRUNC ");

      if((local_flags & O_CREAT) == O_CREAT)
        strcat(msg, "O_CREAT ");

      if((local_flags & O_EXCL) == O_EXCL)
        strcat(msg, "O_EXCL ");

      LogFullDebug(COMPONENT_FSAL, "Openning local file %s with flags: %s",
                   p_local_path->path, msg);
    }

  local_fd = open(p_local_path->path, local_flags, 0644);

  if(local_fd == -1)
    {
    /** @todo : put a function in fsal_convert.c that convert your local
     * filesystem errors to an FSAL error code.
     * So you will have a call like :
     * Return( unix2fsal_error(errno) , errno , INDEX_FSAL_rcp );
     */

      Return(ERR_FSAL_SERVERFAULT, errno, INDEX_FSAL_rcp);
    }

  /* call FSAL_open with the correct flags */

  if(to_fs)
    {
      fs_flags = FSAL_O_WRONLY | FSAL_O_TRUNC;

      /* invalid flags for local to filesystem */

      if(((transfer_opt & FSAL_RCP_LOCAL_CREAT) == FSAL_RCP_LOCAL_CREAT)
         || ((transfer_opt & FSAL_RCP_LOCAL_EXCL) == FSAL_RCP_LOCAL_EXCL))
        {
          /* clean & return */
          close(local_fd);
          Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_rcp);
        }
    }
  else
    {
      fs_flags = FSAL_O_RDONLY;
    }

  if(isFullDebug(COMPONENT_FSAL))
  {
    char msg[1024];

    msg[0] = '\0';

    if((fs_flags & FSAL_O_RDONLY) == FSAL_O_RDONLY)
      strcat(msg, "FSAL_O_RDONLY ");

    if((fs_flags & FSAL_O_WRONLY) == FSAL_O_WRONLY)
      strcat(msg, "FSAL_O_WRONLY ");

    if((fs_flags & FSAL_O_TRUNC) == FSAL_O_TRUNC)
      strcat(msg, "FSAL_O_TRUNC ");

    LogFullDebug(COMPONENT_FSAL, "Openning FSAL file with flags: %s", msg);

  }

  st = FSAL_open(filehandle, p_context, fs_flags, &fs_fd, NULL);

  if(FSAL_IS_ERROR(st))
    {
      /* clean & return */
      close(local_fd);
      Return(st.major, st.minor, INDEX_FSAL_rcp);
    }
  LogFullDebug(COMPONENT_FSAL,
               "Allocating IO buffer of size %llu",
               (unsigned long long)RCP_BUFFER_SIZE);

  /* Allocates buffer */

  IObuffer = (caddr_t) Mem_Alloc(RCP_BUFFER_SIZE);

  if(IObuffer == NULL)
    {
      /* clean & return */
      close(local_fd);
      FSAL_close(&fs_fd);
      Return(ERR_FSAL_NOMEM, Mem_Errno, INDEX_FSAL_rcp);
    }

  /* read/write loop */

  while(!eof)
    {
      /* initialize error code */
      st = FSAL_STATUS_NO_ERROR;

      LogFullDebug(COMPONENT_FSAL, "Read a block from source");

      /* read */

      if(to_fs)                 /* from local filesystem */
        {
          local_size = read(local_fd, IObuffer, RCP_BUFFER_SIZE);

          if(local_size == -1)
            {
              st.major = ERR_FSAL_IO;
              st.minor = errno;
              break;            /* exit loop */
            }

          eof = (local_size == 0);

        }
      else                      /* from FSAL filesystem */
        {
          fs_size = 0;
          st = FSAL_read(&fs_fd, NULL, RCP_BUFFER_SIZE, IObuffer, &fs_size, &eof);

          if(FSAL_IS_ERROR(st))
            break;              /* exit loop */

        }

      /* write (if not eof) */

      if(!eof || ((!to_fs) && (fs_size > 0)))
        {

          LogFullDebug(COMPONENT_FSAL, "Write a block to destination");

          if(to_fs)             /* to FSAL filesystem */
            {

              st = FSAL_write(&fs_fd, NULL, local_size, IObuffer, &fs_size);

              if(FSAL_IS_ERROR(st))
                break;          /* exit loop */

            }
          else                  /* to local filesystem */
            {

              local_size = write(local_fd, IObuffer, fs_size);

              if(local_size == -1)
                {
                  st.major = ERR_FSAL_IO;
                  st.minor = errno;
                  break;        /* exit loop */
                }

            }                   /* if to_fs */

        }                       /* if eof */
      else
        LogFullDebug(COMPONENT_FSAL, "End of source file reached");

    }                           /* while !eof */

  /* Clean */

  Mem_Free(IObuffer);
  close(local_fd);
  FSAL_close(&fs_fd);

  /* return status. */
  Return(st.major, st.minor, INDEX_FSAL_rcp);
}                               /* FSAL_rcp */
示例#6
0
fsal_status_t GPFSFSAL_rcp(fsal_handle_t * filehandle,      /* IN */
                           fsal_op_context_t * p_context,   /* IN */
                           fsal_path_t * p_local_path,      /* IN */
                           fsal_rcpflag_t transfer_opt      /* IN */
                          )
{

    int local_fd;
    int local_flags;
    int errsv;

    fsal_file_t fs_fd;
    fsal_openflags_t fs_flags;

    fsal_status_t st = FSAL_STATUS_NO_ERROR;

    /* default buffer size for RCP: 10MB */
#define RCP_BUFFER_SIZE 10485760
    caddr_t IObuffer;

    int to_local = FALSE;
    int to_fs = FALSE;

    int eof = FALSE;

    ssize_t local_size;
    fsal_size_t fs_size;

    /* sanity checks. */

    if(!filehandle || !p_context || !p_local_path)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rcp);

    to_local = ((transfer_opt & FSAL_RCP_FS_TO_LOCAL) == FSAL_RCP_FS_TO_LOCAL);
    to_fs = ((transfer_opt & FSAL_RCP_LOCAL_TO_FS) == FSAL_RCP_LOCAL_TO_FS);

    if(to_local)
        LogFullDebug(COMPONENT_FSAL,
                     "FSAL_rcp: FSAL -> local file (%s)", p_local_path->path);

    if(to_fs)
        LogFullDebug(COMPONENT_FSAL,
                     "FSAL_rcp: local file -> FSAL (%s)", p_local_path->path);

    /* must give the sens of transfert (exactly one) */

    if((!to_local && !to_fs) || (to_local && to_fs))
        Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_rcp);

    /* first, open local file with the correct flags */

    if(to_fs)
    {
        local_flags = O_RDONLY;
    }
    else
    {
        local_flags = O_WRONLY | O_TRUNC;

        if((transfer_opt & FSAL_RCP_LOCAL_CREAT) == FSAL_RCP_LOCAL_CREAT)
            local_flags |= O_CREAT;

        if((transfer_opt & FSAL_RCP_LOCAL_EXCL) == FSAL_RCP_LOCAL_EXCL)
            local_flags |= O_EXCL;

    }

    if(isFullDebug(COMPONENT_FSAL))
    {
        char msg[1024];

        msg[0] = '\0';

        if((local_flags & O_RDONLY) == O_RDONLY)
            strcat(msg, "O_RDONLY ");

        if((local_flags & O_WRONLY) == O_WRONLY)
            strcat(msg, "O_WRONLY ");

        if((local_flags & O_TRUNC) == O_TRUNC)
            strcat(msg, "O_TRUNC ");

        if((local_flags & O_CREAT) == O_CREAT)
            strcat(msg, "O_CREAT ");

        if((local_flags & O_EXCL) == O_EXCL)
            strcat(msg, "O_EXCL ");

        LogFullDebug(COMPONENT_FSAL, "Openning local file %s with flags: %s",
                     p_local_path->path, msg);
    }

    local_fd = open(p_local_path->path, local_flags);
    errsv = errno;

    if(local_fd == -1)
    {
        Return(posix2fsal_error(errsv), errsv, INDEX_FSAL_rcp);
    }

    /* call FSAL_open with the correct flags */

    if(to_fs)
    {
        fs_flags = FSAL_O_WRONLY | FSAL_O_TRUNC;

        /* invalid flags for local to filesystem */

        if(((transfer_opt & FSAL_RCP_LOCAL_CREAT) == FSAL_RCP_LOCAL_CREAT)
                || ((transfer_opt & FSAL_RCP_LOCAL_EXCL) == FSAL_RCP_LOCAL_EXCL))
        {
            /* clean & return */
            close(local_fd);
            Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_rcp);
        }
    }
    else
    {
        fs_flags = FSAL_O_RDONLY;
    }

    if(isFullDebug(COMPONENT_FSAL))
    {
        char msg[1024];

        msg[0] = '\0';

        if((fs_flags & FSAL_O_RDONLY) == FSAL_O_RDONLY)
            strcat(msg, "FSAL_O_RDONLY ");

        if((fs_flags & FSAL_O_WRONLY) == FSAL_O_WRONLY)
            strcat(msg, "FSAL_O_WRONLY ");

        if((fs_flags & FSAL_O_TRUNC) == FSAL_O_TRUNC)
            strcat(msg, "FSAL_O_TRUNC ");

        LogFullDebug(COMPONENT_FSAL, "Openning FSAL file with flags: %s", msg);
    }


    st = FSAL_open(filehandle, p_context, fs_flags, &fs_fd, NULL);

    if(FSAL_IS_ERROR(st))
    {
        /* clean & return */
        close(local_fd);
        Return(st.major, st.minor, INDEX_FSAL_rcp);
    }
    LogFullDebug(COMPONENT_FSAL,
                 "Allocating IO buffer of size %llu",
                 (unsigned long long)RCP_BUFFER_SIZE);

    /* Allocates buffer */

    IObuffer = gsh_malloc(RCP_BUFFER_SIZE);

    if(IObuffer == NULL)
    {
        /* clean & return */
        close(local_fd);
        FSAL_close(&fs_fd, p_context);
        Return(ERR_FSAL_NOMEM, ENOMEM, INDEX_FSAL_rcp);
    }

    /* read/write loop */

    while(!eof)
    {
        /* initialize error code */
        st = FSAL_STATUS_NO_ERROR;

        LogFullDebug(COMPONENT_FSAL, "Read a block from source");

        /* read */

        if(to_fs)                 /* from local filesystem */
        {
            LogFullDebug(COMPONENT_FSAL,
                         "Read a block from local file system");
            local_size = read(local_fd, IObuffer, RCP_BUFFER_SIZE);

            if(local_size == -1)
            {
                st.major = ERR_FSAL_IO;
                st.minor = errno;
                break;            /* exit loop */
            }

            eof = (local_size == 0);
            if(!eof)
            {
                LogFullDebug(COMPONENT_FSAL,
                             "Write a block (%llu bytes) to FSAL",
                             (unsigned long long)local_size);

                st = FSAL_write(&fs_fd, p_context, NULL, local_size, IObuffer, &fs_size);
                if(FSAL_IS_ERROR(st))
                {
                    LogFullDebug(COMPONENT_FSAL,
                                 "Error writing to FSAL");
                    break;          /* exit loop */
                }
            }
            else
            {
                LogFullDebug(COMPONENT_FSAL,
                             "End of file on local file system");
            }
        }
        else                      /* from FSAL filesystem */
        {
            LogFullDebug(COMPONENT_FSAL,
                         "Read a block from FSAL");
            fs_size = 0;
            st = FSAL_read(&fs_fd, p_context, NULL, RCP_BUFFER_SIZE, IObuffer, &fs_size, &eof);

            if(FSAL_IS_ERROR(st))
                break;              /* exit loop */

            if(fs_size > 0)
            {
                LogFullDebug(COMPONENT_FSAL,
                             "Write a block (%llu bytes) to local file system",
                             (unsigned long long)fs_size);

                local_size = write(local_fd, IObuffer, fs_size);

                if(local_size == -1)
                {
                    st.major = ERR_FSAL_IO;
                    st.minor = errno;
                    break;        /* exit loop */
                }
            }
            else
            {
                LogFullDebug(COMPONENT_FSAL,
                             "End of file on FSAL");
                break;
            }

            LogFullDebug(COMPONENT_FSAL, "Size read from source: %llu",
                         (unsigned long long)fs_size);
        }
    }                           /* while !eof */

    /* Clean */

    gsh_free(IObuffer);
    close(local_fd);
    FSAL_close(&fs_fd, p_context);

    /* return status. */

    Return(st.major, st.minor, INDEX_FSAL_rcp);

}