Beispiel #1
0
int syslog_dev_flush(void)
{
#if defined(CONFIG_SYSLOG_FILE) && !defined(CONFIG_DISABLE_MOUNTPOINT)
  /* Ignore return value, always return success.  file_fsync() could fail
   * because the file is not open, the inode is not a mountpoint, or the
   * mountpoint does not support the sync() method.
   */

  (void)file_fsync(&g_syslog_dev.sl_file);
#endif

  return OK;
}
Beispiel #2
0
static void aio_fsync_worker(FAR void *arg)
{
  FAR struct aio_container_s *aioc = (FAR struct aio_container_s *)arg;
  FAR struct aiocb *aiocbp;
  pid_t pid;
#ifdef CONFIG_PRIORITY_INHERITANCE
  uint8_t prio;
#endif
  int ret;

  /* Get the information from the container, decant the AIO control block,
   * and free the container before starting any I/O.  That will minimize
   * the delays by any other threads waiting for a pre-allocated container.
   */

  DEBUGASSERT(aioc && aioc->aioc_aiocbp);
  pid    = aioc->aioc_pid;
#ifdef CONFIG_PRIORITY_INHERITANCE
  prio   = aioc->aioc_prio;
#endif
  aiocbp = aioc_decant(aioc);

  /* Perform the fsync using u.aioc_filep */

  ret = file_fsync(aioc->u.aioc_filep);
  if (ret < 0)
    {
      int errcode = get_errno();
      ferr("ERROR: fsync failed: %d\n", errcode);
      DEBUGASSERT(errcode > 0);
      aiocbp->aio_result = -errcode;
    }
  else
    {
      aiocbp->aio_result = OK;
    }

  /* Signal the client */

  (void)aio_signal(pid, aiocbp);

#ifdef CONFIG_PRIORITY_INHERITANCE
  /* Restore the low priority worker thread default priority */

  lpwork_restorepriority(prio);
#endif
}
Beispiel #3
0
int coda_fsync(struct file *coda_file, struct dentry *coda_dentry)
{
        struct coda_inode_info *cnp;
	struct inode *coda_inode = coda_dentry->d_inode;
        struct inode *cont_inode = NULL;
        struct file  cont_file;
	struct dentry cont_dentry;
        int result = 0;
        ENTRY;
	coda_vfs_stat.fsync++;

	if (!(S_ISREG(coda_inode->i_mode) || S_ISDIR(coda_inode->i_mode) ||
	      S_ISLNK(coda_inode->i_mode)))
		return -EINVAL;

        cnp = ITOC(coda_inode);

        cont_inode = cnp->c_ovp;
        if ( cont_inode == NULL ) {
                printk("coda_file_write: cached inode is 0!\n");
                return -1; 
        }

        coda_prepare_openfile(coda_inode, coda_file, cont_inode, 
			      &cont_file, &cont_dentry);

	down(&cont_inode->i_sem);

        result = file_fsync(&cont_file ,&cont_dentry);
	if ( result == 0 ) {
		result = venus_fsync(coda_inode->i_sb, &(cnp->c_fid));
	}

	up(&cont_inode->i_sem);

        coda_restore_codafile(coda_inode, coda_file, cont_inode, &cont_file);
        return result;
}
Beispiel #4
0
/* sysfile_fsync - sync file */
int
sysfile_fsync(int fd) {
    return file_fsync(fd);
}
Beispiel #5
0
int file_execute_request(sb_request_t *sb_req, int thread_id)
{
  FILE_DESCRIPTOR    fd;
  sb_file_request_t *file_req = &sb_req->u.file_request;
  log_msg_t          msg;
  log_msg_oper_t     op_msg;
  
  if (sb_globals.debug)
  {
    log_text(LOG_DEBUG,
             "Executing request, operation: %d, file_id: %d, pos: %d, "
             "size: %d",
             file_req->operation,
             file_req->file_id,
             (int)file_req->pos,
             (int)file_req->size);
  }
  
  /* Check request parameters */
  if (file_req->file_id > num_files)
  {
    log_text(LOG_FATAL, "Incorrect file discovered in request");
    return 1;
  }
  if (file_req->pos + file_req->size > file_size)
  {
    log_text(LOG_FATAL, "Too large position discovered in request!");
    return 1;
  }
  
  fd = files[file_req->file_id];

  /* Prepare log message */
  msg.type = LOG_MSG_TYPE_OPER;
  msg.data = &op_msg;

  switch (file_req->operation) {
    case FILE_OP_TYPE_NULL:
      log_text(LOG_FATAL, "Execute of NULL request called !, aborting");
      return 1;
    case FILE_OP_TYPE_WRITE:

      /* Store checksum and offset in a buffer when in validation mode */
      if (sb_globals.validate)
        file_fill_buffer(buffer, file_req->size, file_req->pos);
                         
      LOG_EVENT_START(msg, thread_id);
      if(file_pwrite(file_req->file_id, buffer, file_req->size, file_req->pos,
                     thread_id)
         != (ssize_t)file_req->size)
      {
        log_errno(LOG_FATAL, "Failed to write file! file: " FD_FMT " pos: %lld", 
                  fd, (long long)file_req->pos);
        return 1;
      }
      /* Check if we have to fsync each write operation */
      if (file_fsync_all)
      {
        if (file_fsync(file_req->file_id, thread_id))
        {
          log_errno(LOG_FATAL, "Failed to fsync file! file: " FD_FMT, fd);
          return 1;
        }
      }
      LOG_EVENT_STOP(msg, thread_id);

      SB_THREAD_MUTEX_LOCK();
      write_ops++;
      real_write_ops++;
      bytes_written += file_req->size;
      if (file_fsync_all)
        other_ops++;
      SB_THREAD_MUTEX_UNLOCK();

      break;
    case FILE_OP_TYPE_READ:
      LOG_EVENT_START(msg, thread_id);
      if(file_pread(file_req->file_id, buffer, file_req->size, file_req->pos,
                    thread_id)
         != (ssize_t)file_req->size)
      {
        log_errno(LOG_FATAL, "Failed to read file! file: " FD_FMT " pos: %lld",
                  fd, (long long)file_req->pos);
        return 1;
      }
      LOG_EVENT_STOP(msg, thread_id);

      /* Validate block if run with validation enabled */
      if (sb_globals.validate &&
          file_validate_buffer(buffer, file_req->size, file_req->pos))
      {
        log_text(LOG_FATAL,
          "Validation failed on file " FD_FMT ", block offset 0x%x, exiting...",
           file_req->file_id, file_req->pos);
        return 1;
      }
      
      SB_THREAD_MUTEX_LOCK();
      read_ops++;
      real_read_ops++;
      bytes_read += file_req->size;

      SB_THREAD_MUTEX_UNLOCK();

      break;
    case FILE_OP_TYPE_FSYNC:
      /* Ignore fsync requests if we are already fsync'ing each operation */
      if (file_fsync_all)
        break;
      if(file_fsync(file_req->file_id, thread_id))
      {
        log_errno(LOG_FATAL, "Failed to fsync file! file: " FD_FMT, fd);
        return 1;
      }
    
      SB_THREAD_MUTEX_LOCK();
      other_ops++;
      SB_THREAD_MUTEX_UNLOCK();
    
      break;         
    default:
      log_text(LOG_FATAL, "Execute of UNKNOWN file request type called (%d)!, "
               "aborting", file_req->operation);
      return 1;
  }
  return 0;

}