示例#1
0
void* posix_init(const char* config_file, const char* log_file) {
	SetNamePgm("TC-POSIX");
	SetNameFunction("posix");
	SetNameHost("localhost");
	init_logging(log_file, NIV_EVENT);
	return (void*) log_file;
}
示例#2
0
/**
 * @brief This thread is in charge of signal management
 *
 * @param[in] UnusedArg Unused
 *
 * @return NULL.
 */
void *sigmgr_thread(void *UnusedArg)
{
	SetNameFunction("sigmgr");
	int signal_caught = 0;

	/* Loop until we catch SIGTERM */
	while (signal_caught != SIGTERM) {
		sigset_t signals_to_catch;
		sigemptyset(&signals_to_catch);
		sigaddset(&signals_to_catch, SIGTERM);
		sigaddset(&signals_to_catch, SIGHUP);
		if (sigwait(&signals_to_catch, &signal_caught) != 0) {
			LogFullDebug(COMPONENT_THREAD,
				     "sigwait exited with error");
			continue;
		}
		if (signal_caught == SIGHUP) {
			LogEvent(COMPONENT_MAIN,
				 "SIGHUP_HANDLER: Received SIGHUP.... initiating export list reload");
			admin_replace_exports();
			reread_log_config();
		}
	}
	LogDebug(COMPONENT_THREAD, "sigmgr thread exiting");

	admin_halt();

	/* Might as well exit - no need for this thread any more */
	return NULL;
}
示例#3
0
/**
 * @brief Initialize NFSd prerequisites
 *
 * @param[in] program_name Name of the program
 * @param[in] host_name    Server host name
 * @param[in] debug_level  Debug level
 * @param[in] log_path     Log path
 */
void nfs_prereq_init(char *program_name, char *host_name, int debug_level,
		     char *log_path)
{
	/* Initialize logging */
	SetNamePgm(program_name);
	SetNameFunction("main");
	SetNameHost(host_name);

	InitLogging();
	if (log_path)
		SetDefaultLogging(log_path);

	if (debug_level >= 0)
		SetLevelDebug(debug_level);

	ReadLogEnvironment();

	/* Register error families */
	AddFamilyError(ERR_POSIX, "POSIX Errors", tab_systeme_status);
	AddFamilyError(ERR_HASHTABLE, "HashTable related Errors",
		       tab_errctx_hash);
	AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL);
	AddFamilyError(ERR_CACHE_INODE, "Cache Inode related Errors",
		       tab_errstatus_cache_inode);
}
int dbus_heartbeat_cb(void *arg)
{
	SetNameFunction("dbus_heartbeat");
	int err = 0;
	int rc = BCAST_STATUS_OK;
	dbus_bool_t ishealthy = get_ganesha_health(&healthstats);

	if (ishealthy) {
		/* send the heartbeat pulse */
		err = gsh_dbus_broadcast(DBUS_PATH HEARTBEAT_NAME,
					 DBUS_ADMIN_IFACE,
					 HEARTBEAT_NAME,
					 DBUS_TYPE_BOOLEAN,
					 &ishealthy,
					 DBUS_TYPE_INVALID);
		if (err) {
			LogCrit(COMPONENT_DBUS,
				"heartbeat broadcast failed. err:%d",
				err);
			rc = BCAST_STATUS_WARN;
		}
	} else
		LogWarn(COMPONENT_DBUS,
			"Health status is unhealthy.  Not sending heartbeat");

	return rc;
}
void *long_processing_thread(void *addr)
{
    nfs_worker_data_t *workers_data = (nfs_worker_data_t *) addr;
    struct timeval timer_end;
    struct timeval timer_diff;
    int i;

    SetNameFunction("long_processing");

    while(1)
    {
        sleep(1);
        gettimeofday(&timer_end, NULL);

        for(i = 0; i < nfs_param.core_param.nb_worker; i++)
        {
            if(workers_data[i].timer_start.tv_sec == 0)
                continue;
            timer_diff = time_diff(workers_data[i].timer_start, timer_end);
            if(timer_diff.tv_sec == nfs_param.core_param.long_processing_threshold)
                LogEvent(COMPONENT_DISPATCH,
                         "Worker#%d: Function %s has been running for %llu.%.6llu seconds",
                         i, workers_data[i].pfuncdesc->funcname,
                         (unsigned long long)timer_diff.tv_sec,
                         (unsigned long long)timer_diff.tv_usec);
        }
    }

    return NULL;
}                               /* long_processing_thread */
示例#6
0
void run_Tests(int all, char *arg, char *str, char *file)
{
	SetNameFunction(arg);

	if (all)
		Test1(str, file);
}
示例#7
0
/**
 * @brief Initialize NFSd prerequisites
 *
 * @param[in] program_name Name of the program
 * @param[in] host_name    Server host name
 * @param[in] debug_level  Debug level
 * @param[in] log_path     Log path
 */
void nfs_prereq_init(char *program_name, char *host_name, int debug_level,
		     char *log_path)
{
	/* Initialize logging */
	SetNamePgm(program_name);
	SetNameFunction("main");
	SetNameHost(host_name);

	init_logging(log_path, debug_level);
}
void *ptfsal_closeHandle_listener_thread(void *args)
{
  int rc;
  struct msg_t msg;
  int msg_bytes;
  int close_rc;
  int i;
  struct CommonMsgHdr *msgHdr;
  int handleIdxFound;

  SetNameFunction("PT FSAL CloseOnOpen Handler");

  rc = ptfsal_closeHandle_attach_to_queues();
  if (rc == -1) {
    exit (1);
  }

  while (1) {
    msg_bytes = RCV_MSG_WAIT_BLOCK(g_closeHandle_req_msgq,
                                   &msg,
                                   sizeof(struct CommonMsgHdr),
                                   0);
    if (msg_bytes != -1) {
      close_rc = -1;
      FSI_TRACE(FSI_NOTICE, "Finding oldest handles");
      /* TBD: we need to address a design if we have more than one
              close thread or NFS4 support (that can issue close itself)
              in order to ensure proper locking to the handle table.
              Currently, one close thread model will work since we don't
              shuffle handle around and there is only one place to
              actually close the handle (which is here) in the code */

      handleIdxFound = CCL_FIND_OLDEST_HANDLE();
      if (handleIdxFound != -1) {
        close_rc = ptfsal_implicit_close_for_nfs(handleIdxFound,
                                                 CCL_CLOSE_STYLE_NORMAL);
      }
      /* Send the response back */
      msgHdr = (struct CommonMsgHdr *) &msg.mtext[0];
      msgHdr->transactionRc = close_rc;
      msg_bytes = SEND_MSG(g_closeHandle_rsp_msgq,
                           &msg,
                           sizeof(struct CommonMsgHdr));
    }
  }
}
void *ptfsal_polling_closeHandler_thread(void *args)
{
  SetNameFunction("PT FSAL Polling Close");
  
  g_poll_iterations   = 1;
  g_poll_for_timeouts = false;

  while (1) {
    FSI_TRACE(FSI_DEBUG, "Periodic check for opened handle to close");
    ptfsal_close_timedout_handle_bkg();
    sleep (PTFSAL_POLLING_THREAD_FREQUENCY_SEC);

    if ((g_poll_iterations * PTFSAL_POLLING_THREAD_FREQUENCY_SEC)
        % PTFSAL_POLLING_HANDLE_TIMEOUT_SEC == 0) {
      g_poll_for_timeouts = true;
      g_poll_iterations   = 1;
    } else {
      ++g_poll_iterations;
    }
  }
}
void *admin_thread(void *UnusedArg)
{
  SetNameFunction("Admin");

  pthread_mutex_lock(&admin_control_mtx);
  while (admin_command != admin_shutdown)
    {
      /* If we add more commands we can expand this into a
	 switch/case... */
      if (admin_command == admin_reload_exports)
	{
	  admin_command = admin_none_pending;
	  admin_status = admin_reloading;
	  pthread_cond_broadcast(&admin_control_cv);
	  pthread_mutex_unlock(&admin_control_mtx);
	  redo_exports();
	  pthread_mutex_lock(&admin_control_mtx);
	  admin_status = admin_stable;
	  pthread_cond_broadcast(&admin_control_cv);
	}
      if (admin_command != admin_none_pending) {
	continue;
      }
      pthread_cond_wait(&admin_control_cv, &admin_control_mtx);
    }

  admin_command = admin_none_pending;
  admin_status = admin_shutting_down;
  pthread_cond_broadcast(&admin_control_cv);
  pthread_mutex_unlock(&admin_control_mtx);
  do_shutdown();
  pthread_mutex_lock(&admin_control_mtx);
  admin_status = admin_halted;
  pthread_cond_broadcast(&admin_control_cv);
  pthread_mutex_unlock(&admin_control_mtx);

  return NULL;
}                               /* admin_thread */
示例#11
0
/**
 * _9p_dispatcher_thread: thread used for RPC dispatching.
 *
 * Thead used for RPC dispatching. It gets the requests and then spool it to
 * one of the worker's LRU.  The worker chosen is the one with the smaller load
 * (its LRU is the shorter one).
 *
 * @param Arg (unused)
 *
 * @return Pointer to the result (but this function will mostly loop forever).
 *
 */
void *_9p_dispatcher_thread(void *Arg)
{
	int _9p_socket = -1;

	SetNameFunction("_9p_disp");

	/* Calling dispatcher main loop */
	LogInfo(COMPONENT_9P_DISPATCH, "Entering nfs/rpc dispatcher");

	LogDebug(COMPONENT_9P_DISPATCH, "My pthread id is %p",
		 (caddr_t) pthread_self());

	/* Set up the _9p_socket */
	_9p_socket = _9p_create_socket();
	if (_9p_socket == -1) {
		LogCrit(COMPONENT_9P_DISPATCH,
			"Can't get socket for 9p dispatcher");
		exit(1);
	}

	_9p_dispatcher_svc_run(_9p_socket);

	return NULL;
}				/* _9p_dispatcher_thread */
示例#12
0
void *admin_thread(void *UnusedArg)
{
  SetNameFunction("admin_thr");

  while(1)
    {
      P(mutex_admin_condvar);
      while(reload_exports == FALSE)
            pthread_cond_wait(&(admin_condvar), &(mutex_admin_condvar));
      reload_exports = FALSE;
      V(mutex_admin_condvar);

      if (rebuild_export_list() <= 0)
        {
          LogCrit(COMPONENT_MAIN, "Could not reload the exports list.");
          continue;
        }

      if(pause_threads(PAUSE_RELOAD_EXPORTS) == PAUSE_EXIT)
        {
          LogDebug(COMPONENT_MAIN,
                   "Export reload interrupted by shutdown while pausing threads");
          /* Be helpfull and exit
           * (other termination will just blow us away, and that's ok...
           */
          break;
        }

      /* Clear the id mapping cache for gss principals to uid/gid.
       * The id mapping may have changed.
       */
#ifdef _HAVE_GSSAPI
#ifdef _USE_NFSIDMAP
      uidgidmap_clear();
      idmap_clear();
      namemap_clear();
#endif /* _USE_NFSIDMAP */
#endif /* _HAVE_GSSAPI */

      if (ChangeoverExports())
        {
          LogCrit(COMPONENT_MAIN, "ChangeoverExports failed.");
          continue;
        }

      LogEvent(COMPONENT_MAIN,
               "Exports reloaded and active");

      /* wake_workers could return PAUSE_PAUSE, but we don't have to do
       * anything special in that case.
       */
      if(wake_threads(AWAKEN_RELOAD_EXPORTS) == PAUSE_EXIT)
        {
          LogDebug(COMPONENT_MAIN,
                   "Export reload interrupted by shutdown while waking threads");
          /* Be helpfull and exit
           * (other termination will just blow us away, and that's ok...
           */
          break;
        }
    }

  return NULL;
}                               /* admin_thread */
示例#13
0
int main(int argc, char **argv)
{
  unsigned int i;
  struct timeval tv1, tv2, tv3, tvdiff;
  int count, rc;
  char *dir;
  handle_map_param_t param;
  time_t now;

  /* Init logging */
  SetNamePgm("test_handle_mapping");
  SetDefaultLogging("TEST");
  SetNameFunction("main");
  SetNameHost("localhost");
  InitLogging();

  if(argc != 3 || (count = atoi(argv[2])) == 0)
    {
      LogTest("usage: test_handle_mapping <db_dir> <db_count>");
      exit(1);
    }

#ifndef _NO_BUDDY_SYSTEM

  if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS)
    {
      /* Failed init */
      LogCrit(COMPONENT_FSAL, "ERROR: Could not initialize memory manager");
      exit(rc);
    }
#endif

  dir = argv[1];

  strcpy(param.databases_directory, dir);
  strcpy(param.temp_directory, "/tmp");
  param.database_count = count;
  param.hashtable_size = 27;
  param.nb_handles_prealloc = 1024;
  param.nb_db_op_prealloc = 1024;
  param.synchronous_insert = FALSE;

  rc = HandleMap_Init(&param);

  LogTest("HandleMap_Init() = %d", rc);
  if(rc)
    exit(rc);

  gettimeofday(&tv1, NULL);

  /* Now insert a set of handles */

  now = time(NULL);

  for(i = 0; i < 10000; i++)
    {
      nfs23_map_handle_t nfs23_digest;
      fsal_handle_t handle;

      memset(&handle, i, sizeof(fsal_handle_t));
      nfs23_digest.object_id = 12345 + i;
      nfs23_digest.handle_hash = (1999 * i + now) % 479001599;

      rc = HandleMap_SetFH(&nfs23_digest, &handle);
      if(rc && (rc != HANDLEMAP_EXISTS))
        exit(rc);
    }

  gettimeofday(&tv2, NULL);

  timersub(&tv2, &tv1, &tvdiff);

  LogTest("%u threads inserted 10000 handles in %d.%06ds",
          count, (int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

  /* Now get them ! */

  for(i = 0; i < 10000; i++)
    {
      nfs23_map_handle_t nfs23_digest;
      fsal_handle_t handle;

      nfs23_digest.object_id = 12345 + i;
      nfs23_digest.handle_hash = (1999 * i + now) % 479001599;

      rc = HandleMap_GetFH(&nfs23_digest, &handle);
      if(rc)
        {
          LogTest("Error %d retrieving handle !", rc);
          exit(rc);
        }

      rc = HandleMap_DelFH(&nfs23_digest);
      if(rc)
        {
          LogTest("Error %d deleting handle !", rc);
          exit(rc);
        }

    }

  gettimeofday(&tv3, NULL);

  timersub(&tv3, &tv2, &tvdiff);

  LogTest("Retrieved and deleted 10000 handles in %d.%06ds", (int)tvdiff.tv_sec,
          (int)tvdiff.tv_usec);

  rc = HandleMap_Flush();

  gettimeofday(&tv3, NULL);

  timersub(&tv3, &tv1, &tvdiff);
  LogTest("Total time with %u threads (including flush): %d.%06ds", count,
          (int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

  exit(0);

}
void *file_content_gc_thread(void *UnusedArg)
{
  char command[2 * MAXPATHLEN];
  exportlist_t *pexport = NULL;
  int is_hw_reached = FALSE;
  int some_flush_to_do = FALSE;
  unsigned long nb_blocks_to_manage;
  char cache_sub_dir[MAXPATHLEN];
  cache_content_status_t cache_content_status;
  FILE *command_stream = NULL;

  char logfile_arg[MAXPATHLEN];
  char *loglevel_arg;

  SetNameFunction("file_content_gc_thread");

  LogEvent(COMPONENT_MAIN,
           "NFS FILE CONTENT GARBAGE COLLECTION : Starting GC thread");

  if(mark_thread_existing(&gccb) == PAUSE_EXIT)
    {
      /* Oops, that didn't last long... exit. */
      mark_thread_done(&gccb);
      LogDebug(COMPONENT_DISPATCH,
               "NFS FILE CONTENT GARBAGE COLLECTION Thread exiting before initialization");
      return NULL;
    }

  LogDebug(COMPONENT_MAIN,
           "NFS FILE CONTENT GARBAGE COLLECTION : my pthread id is %p",
           (caddr_t) pthread_self());

  while(1)
    {
      /* Sleep until some work is to be done */
      sleep(nfs_param.cache_layers_param.dcgcpol.run_interval);

      if(gccb.tcb_state != STATE_AWAKE)
        {
          while(1)
            {
              P(gccb.tcb_mutex);
              if(gccb.tcb_state == STATE_AWAKE)
                {
                  V(gccb.tcb_mutex);
                  break;
                }
              switch(thread_sm_locked(&gccb))
                {
                  case THREAD_SM_RECHECK:
                    V(gccb.tcb_mutex);
                    continue;

                  case THREAD_SM_BREAK:
                    V(gccb.tcb_mutex);
                    break;

                  case THREAD_SM_EXIT:
                    V(gccb.tcb_mutex);
                    return NULL;
                }
            }
        }

      LogDebug(COMPONENT_MAIN,
               "NFS FILE CONTENT GARBAGE COLLECTION : processing...");
      for(pexport = nfs_param.pexportlist; pexport != NULL; pexport = pexport->next)
        {
          if(pexport->options & EXPORT_OPTION_USE_DATACACHE)
            {
              snprintf(cache_sub_dir, MAXPATHLEN, "%s/export_id=%d",
                       nfs_param.cache_layers_param.cache_content_client_param.cache_dir,
                       0);

              if((cache_content_status = cache_content_check_threshold(cache_sub_dir,
                                                                       nfs_param.
                                                                       cache_layers_param.
                                                                       dcgcpol.lwmark_df,
                                                                       nfs_param.
                                                                       cache_layers_param.
                                                                       dcgcpol.hwmark_df,
                                                                       &is_hw_reached,
                                                                       &nb_blocks_to_manage))
                 == CACHE_CONTENT_SUCCESS)
                {
                  if(is_hw_reached)
                    {
                      LogEvent(COMPONENT_MAIN,
                               "NFS FILE CONTENT GARBAGE COLLECTION : High Water Mark is  reached, %lu blocks to be removed",
                               nb_blocks_to_manage);
                      some_flush_to_do = TRUE;
                      break;
                    }
                  else {
                    LogDebug(COMPONENT_MAIN,
                             "NFS FILE CONTENT GARBAGE COLLECTION : High Water Mark is not reached");
		  }

                  /* Use signal management */
                  if(force_flush_by_signal == TRUE)
                    {
                      some_flush_to_do = TRUE;
                      break;
                    }
                }
            }
        }                       /* for */

      if (strncmp(fcc_log_path, "/dev/null", 9) == 0)
	switch(LogComponents[COMPONENT_CACHE_INODE_GC].comp_log_type)
	  {
	  case FILELOG:
	    strncpy(logfile_arg, LogComponents[COMPONENT_CACHE_INODE_GC].comp_log_file, MAXPATHLEN);
	    break;
	  case SYSLOG:
	    strncpy(logfile_arg, "SYSLOG", MAXPATHLEN);
	    break;
	  case STDERRLOG:
	    strncpy(logfile_arg, "STDERRLOG", MAXPATHLEN);
	    break;
	  case STDOUTLOG:
	    strncpy(logfile_arg, "STDOUTLOG", MAXPATHLEN);
	    break;
	  default:
	    LogCrit(COMPONENT_MAIN,
	            "Could not figure out the proper -L option for emergency cache flush thread.");
	  }
      else
	strncpy(logfile_arg, fcc_log_path, MAXPATHLEN); /* config variable */

      if(fcc_debug_level != -1) /* config variable */
	loglevel_arg = ReturnLevelInt(fcc_debug_level);
      else
	loglevel_arg = ReturnLevelInt(ReturnLevelComponent(COMPONENT_CACHE_INODE_GC));

      snprintf(command, 2 * MAXPATHLEN, "%s -f %s -N %s -L %s",
	       ganesha_exec_path, config_path, loglevel_arg, logfile_arg);
	       
      if(some_flush_to_do)
        strncat(command, " -P 3", 2 * MAXPATHLEN);      /* Sync and erase */
      else
        strncat(command, " -S 3", 2 * MAXPATHLEN);      /* Sync Only */

      if((command_stream = popen(command, "r")) == NULL)
        LogCrit(COMPONENT_MAIN,
                "NFS FILE CONTENT GARBAGE COLLECTION : /!\\ Cannot lauch command %s",
                command);
      else
        LogEvent(COMPONENT_MAIN,
                 "NFS FILE CONTENT GARBAGE COLLECTION : I launched command %s",
                 command);

      pclose(command_stream);
    }
  tcb_remove(&gccb);
}                               /* file_content_gc_thread */
示例#15
0
/* This thread processes FSAL UP events. */
void *fsal_up_process_thread(void *UnUsedArg)
{
  struct timeval             now;
  struct timespec            timeout;
  fsal_up_event_t          * fupevent;
  int                        rc;

  SetNameFunction("fsal_up_process_thread");

  if (mark_thread_existing(&fsal_up_process_tcb) == PAUSE_EXIT)
    {
      /* Oops, that didn't last long... exit. */
      mark_thread_done(&fsal_up_process_tcb);
      LogDebug(COMPONENT_INIT,
               "FSAL_UP Process Thread: Exiting before initialization");
      return NULL;
    }

  LogFullDebug(COMPONENT_INIT,
               "FSAL_UP Process Thread: my pthread id is %p",
               (caddr_t) pthread_self());

  while(1)
    {
      /* Check without tcb lock*/
      if ((fsal_up_process_tcb.tcb_state != STATE_AWAKE) ||
          glist_empty(&fsal_up_process_queue))
        {
          while(1)
            {
              P(fsal_up_process_tcb.tcb_mutex);
              if ((fsal_up_process_tcb.tcb_state == STATE_AWAKE) &&
                  !glist_empty(&fsal_up_process_queue))
                {
                  V(fsal_up_process_tcb.tcb_mutex);
                  break;
                }
              switch(thread_sm_locked(&fsal_up_process_tcb))
                {
                  case THREAD_SM_RECHECK:
                  V(fsal_up_process_tcb.tcb_mutex);
                  continue;

                  case THREAD_SM_BREAK:
                  if (glist_empty(&fsal_up_process_queue))
                    {
                      gettimeofday(&now, NULL);
                      timeout.tv_sec = 10 + now.tv_sec;
                      timeout.tv_nsec = 0;
                      rc = pthread_cond_timedwait(&fsal_up_process_tcb.tcb_condvar,
                                                  &fsal_up_process_tcb.tcb_mutex,
                                                  &timeout);
                    }
                  V(fsal_up_process_tcb.tcb_mutex);
                  continue;

                  case THREAD_SM_EXIT:
                  V(fsal_up_process_tcb.tcb_mutex);
                  return NULL;
                }
             }
          }
        P(fsal_up_process_tcb.tcb_mutex);
        fupevent = glist_first_entry(&fsal_up_process_queue,
                                     fsal_up_event_t,
                                     event_list);
        if(fupevent != NULL)
          {
            /* Pull the event off of the list */
            glist_del(&fupevent->event_list);

            /* Release the mutex */
            V(fsal_up_process_tcb.tcb_mutex);
            fupevent->event_process_func(&fupevent->event_data);
            gsh_free(fupevent->event_data.event_context.fsal_data.fh_desc.start);
            pool_free(fsal_up_event_pool, fupevent);

            continue;
          }
        V(fsal_up_process_tcb.tcb_mutex);
    }
  tcb_remove(&fsal_up_process_tcb);
}
int main(int argc, char **argv)
{
	unsigned int i;
	struct timeval tv1, tv2, tv3, tvdiff;
	int count, rc;
	char *dir;
	time_t now;

	if (argc != 3) {
		LogTest("usage: test_handle_mapping_db <db_dir> <db_count>");
		exit(1);
	}

	count = atoi(argv[2])
	if (count == 0) {
		LogTest("usage: test_handle_mapping_db <db_dir> <db_count>");
		exit(1);
	}

	dir = argv[1];

	/* Init logging */
	SetNamePgm("test_handle_mapping");
	SetNameFileLog("/dev/tty");
	SetNameFunction("main");
	SetNameHost("localhost");

	/* count databases */

	rc = handlemap_db_count(dir);

	LogTest("handlemap_db_count(%s)=%d", dir, rc);

	if (rc != 0 && count != rc) {
		LogTest(
			"Warning: incompatible thread count %d <> database count %d",
			count, rc);
	}

	rc = handlemap_db_init(dir, "/tmp", count, 1024, false);

	LogTest("handlemap_db_init() = %d", rc);
	if (rc)
		exit(rc);

	rc = handlemap_db_reaload_all(NULL);

	LogTest("handlemap_db_reaload_all() = %d", rc);
	if (rc)
		exit(rc);

	gettimeofday(&tv1, NULL);

	/* Now insert a set of handles */

	now = time(NULL);

	for (i = 0; i < 10000; i++) {
		nfs23_map_handle_t nfs23_digest;
		fsal_handle_t handle;

		memset(&handle, i, sizeof(fsal_handle_t));
		nfs23_digest.object_id = 12345 + i;
		nfs23_digest.handle_hash = (1999 * i + now) % 479001599;

		rc = handlemap_db_insert(&nfs23_digest, &handle);
		if (rc)
			exit(rc);
	}

	gettimeofday(&tv2, NULL);

	timersub(&tv2, &tv1, &tvdiff);

	LogTest("%u threads inserted 10000 handles in %d.%06ds", count,
		(int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

	rc = handlemap_db_flush();

	gettimeofday(&tv3, NULL);

	timersub(&tv3, &tv1, &tvdiff);
	LogTest("Total time with %u threads (including flush): %d.%06ds", count,
		(int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

	LogTest("Now, delete operations");

	for (i = 0; i < 10000; i++) {
		nfs23_map_handle_t nfs23_digest;

		nfs23_digest.object_id = 12345 + i;
		nfs23_digest.handle_hash = (1999 * i + now) % 479001599;

		rc = handlemap_db_delete(&nfs23_digest);
		if (rc)
			exit(rc);
	}

	gettimeofday(&tv2, NULL);
	timersub(&tv2, &tv3, &tvdiff);

	LogTest("%u threads deleted 10000 handles in %d.%06ds", count,
		(int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

	rc = handlemap_db_flush();

	gettimeofday(&tv1, NULL);
	timersub(&tv1, &tv3, &tvdiff);
	LogTest("Delete time with %u threads (including flush): %d.%06ds",
		count, (int)tvdiff.tv_sec, (int)tvdiff.tv_usec);

	exit(0);

}
示例#17
0
main(int argc, char *argv[])
{
  char localmachine[256];

  cache_inode_client_t client;
  LRU_parameter_t lru_param;
  LRU_status_t lru_status;
  cache_inode_fsal_data_t fsdata;

  fsal_status_t status;
  fsal_parameter_t init_param;
  fsal_name_t name;
  fsal_path_t path;
  fsal_attrib_mask_t mask;
  fsal_path_t pathroot;
  fsal_attrib_list_t attribs;
  fsal_handle_t root_handle;

  cache_inode_endofdir_t eod_met;
  cache_inode_dir_entry_t dirent_array[100];
  cache_inode_dir_entry_t dirent_array_loop[5];
  unsigned int nbfound;

  unsigned int begin_cookie = 0;
  hash_buffer_t key, value;

  uid_t uid;
  fsal_cred_t cred;

  cache_inode_status_t cache_status;
  cache_inode_parameter_t cache_param;
  cache_inode_client_parameter_t cache_client_param;

  hash_table_t *ht = NULL;
  fsal_attrib_list_t attrlookup;
  cache_entry_t *cache_entry_root = NULL;
  cache_entry_t *cache_entry_lookup = NULL;
  cache_entry_t *cache_entry_lookup2 = NULL;
  cache_entry_t *cache_entry_lookup3 = NULL;
  cache_entry_t *cache_entry_lookup4 = NULL;
  cache_entry_t *cache_entry_lookup5 = NULL;
  cache_entry_t *cache_entry_lookup6 = NULL;
  cache_entry_t *cache_entry_dircont = NULL;

  cache_inode_gc_policy_t gcpol;

  char *configfile = argv[1];
  int i = 0;
  int rc = 0;

  /* Init the Buddy System allocation */
  if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS)
    {
      LogTest("Error while initializing Buddy system allocator");
      exit(1);
    }

  /* init debug */

  SetNamePgm("test_cache_inode");
  SetDefaultLogging("TEST");
  SetNameFunction("main");
  InitLogging();

#if defined( _USE_GHOSTFS )
  if(argc != 2)
    {
      LogTest("Please set the configuration file as parameter");
      exit(1);
    }
#endif

  /* Obtention du nom de la machine */
  if(gethostname(localmachine, sizeof(localmachine)) != 0)
    {
      LogError(COMPONENT_STDOUT, ERR_SYS, ERR_GETHOSTNAME, errno);
      exit(1);
    }
  else
    SetNameHost(localmachine);

  AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL);
  AddFamilyError(ERR_CACHE_INODE, "FSAL related Errors", tab_errstatus_cache_inode);

  LogTest( "Starting the test");
  LogTest( "-----------------");

#if defined( _USE_GHOSTFS )
  if(FSAL_IS_ERROR(status = FSAL_str2path(configfile,
                                          strlen(configfile) + 1,
                                          &(init_param.fs_specific_info.
                                            definition_file))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
    }
#elif defined( _USE_HPSS )

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, Flags);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugValue);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TransferType);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, NumRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, GKTotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, LimitedRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, MaxConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ReuseDataConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, UsePortRange);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RetryStageInp);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DMAPWriteUpdates);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ServerName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DescName);

  init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.PrincipalName,
          HPSS_SSM, HPSS_MAX_PRINCIPAL_NAME);

  init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.KeytabPath,
          HPSS_KEYTAB, HPSS_MAX_PATH_NAME);

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugPath);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, HostName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RegistrySiteName);

#endif
  /* 2-common info (default) */
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite);

  /* Init */
  if(FSAL_IS_ERROR(status = FSAL_Init(&init_param)))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
    }

  /* getting creds */
  uid = getuid();

  if(FSAL_IS_ERROR(status = FSAL_GetUserCred(uid, NULL, &cred)))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
    }

  /* Init of the cache inode module */
  cache_param.hparam.index_size = 31;
  cache_param.hparam.alphabet_length = 10;      /* Buffer seen as a decimal polynom */
  cache_param.hparam.nb_node_prealloc = 100;
  cache_param.hparam.hash_func_key = cache_inode_fsal_hash_func;
  cache_param.hparam.hash_func_rbt = cache_inode_fsal_rbt_func;
  cache_param.hparam.hash_func_both = NULL ; /* BUGAZOMEU */
  cache_param.hparam.compare_key = cache_inode_compare_key_fsal;
  cache_param.hparam.key_to_str = display_key;
  cache_param.hparam.val_to_str = display_value;

  if((ht = cache_inode_init(cache_param, &cache_status)) == NULL)
    {
      LogTest( "Error %d while init hash ", cache_status);
    }
  else
    LogTest( "Hash Table address = %p", ht);

  /* We need a cache_client to acces the cache */
  cache_client_param.attrmask =
      FSAL_ATTRS_MANDATORY | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_ATIME;
  cache_client_param.nb_prealloc_entry = 1000;
  cache_client_param.nb_pre_dir_data = 200;
  cache_client_param.nb_pre_parent = 1200;
  cache_client_param.nb_pre_state_v4 = 100;

  cache_client_param.lru_param.nb_entry_prealloc = 1000;
  cache_client_param.lru_param.entry_to_str = lru_entry_to_str;
  cache_client_param.lru_param.clean_entry = lru_clean_entry;

  cache_client_param.grace_period_attr   = 0;
  cache_client_param.grace_period_link   = 0;
  cache_client_param.grace_period_dirent = 0;
  cache_client_param.expire_type_attr    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_link    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_dirent  = CACHE_INODE_EXPIRE_NEVER;

  /* Init the cache_inode client */
  if(cache_inode_client_init(&client, cache_client_param, 0) != 0)
    exit(1);

  /* Getting the root of the FS */
  if((FSAL_IS_ERROR(status = FSAL_str2path("/", 2, &pathroot))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  attribs.asked_attributes = cache_client_param.attrmask;
  if((FSAL_IS_ERROR(status = FSAL_lookupPath(pathroot, &cred, &root_handle, &attribs))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }
  fsdata.cookie = 0;
  fsdata.handle = root_handle;

  /* Cache the root of the FS */
  if((cache_entry_root =
      cache_inode_make_root(&fsdata, 1, ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't init fs's root");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* Lookup a second time (entry should now be cached) */
  if((cache_entry_lookup2 = cache_inode_lookup(cache_entry_root,
                                               name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup2 != cache_entry_lookup)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup3 = cache_inode_lookup(cache_entry_root,
                                               name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if((cache_entry_lookup4 = cache_inode_lookup(cache_entry_root,
                                               name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup3 != cache_entry_lookup4)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  LogTest( "---------------------------------");

  /* The end of all the tests */
  LogTest( "All tests exited successfully");

  exit(0);
}                               /* main */
/**
 * _9p_rdma_dispatcher_thread: 9P/RDMA dispatcher
 *
 * @param Arg the socket number cast as a void * in pthread_create
 *
 * @return NULL
 *
 */
void * _9p_rdma_dispatcher_thread( void * Arg )
{
  msk_trans_t *trans;
  msk_trans_t *child_trans;

  msk_trans_attr_t trans_attr;
  pthread_attr_t attr_thr ;
  pthread_t thrid_handle_trans ;

  memset(&trans_attr, 0, sizeof(msk_trans_attr_t));

  trans_attr.server = nfs_param._9p_param._9p_rdma_backlog ;
  trans_attr.rq_depth = _9P_RDMA_OUT+1;
  trans_attr.addr.sa_in.sin_family = AF_INET;
  trans_attr.addr.sa_in.sin_port =  htons(nfs_param._9p_param._9p_rdma_port) ;
  trans_attr.disconnect_callback = _9p_rdma_callback_disconnect;
  inet_pton(AF_INET, "0.0.0.0", &trans_attr.addr.sa_in.sin_addr);
  trans_attr.worker_count = -1;
  trans_attr.debug = MSK_DEBUG_EVENT;
  trans_attr.worker_queue_size = 256;

  SetNameFunction("_9p_rdma_dispatch_thr" ) ;

  /* Calling dispatcher main loop */
  LogInfo(COMPONENT_9P_DISPATCH,
          "Entering 9P/RDMA dispatcher");

  LogDebug(COMPONENT_9P_DISPATCH,
           "My pthread id is %p", (caddr_t) pthread_self());

  /* Prepare attr_thr for dispatch */
  memset( (char *)&attr_thr, 0 , sizeof( attr_thr ) ) ;

  /* Set the pthread attributes */
  if( pthread_attr_init( &attr_thr ) )
   LogFatal( COMPONENT_9P, "9P/RDMA dispatcher could not init pthread_attr_t" ) ;

  if( pthread_attr_setscope(&attr_thr, PTHREAD_SCOPE_SYSTEM) )
   LogFatal( COMPONENT_9P, "9P/RDMA dispatcher could not set pthread_attr_t:scope_system" ) ;

  if( pthread_attr_setdetachstate(&attr_thr, PTHREAD_CREATE_JOINABLE ) )
   LogFatal( COMPONENT_9P, "9P/RDMA dispatcher could not set pthread_attr_t:create_joignable" ) ;

  /* Init RDMA via mooshika */
  if( msk_init( &trans, &trans_attr ) )
    LogFatal( COMPONENT_9P, "9P/RDMA dispatcher could not start mooshika engine" ) ;
  else
    LogEvent( COMPONENT_9P, "Mooshika engine is started" ) ;

  /* Bind Mooshika */
  if( msk_bind_server(trans ) )
    LogFatal( COMPONENT_9P, "9P/RDMA dispatcher could not bind mooshika engine" ) ;
  else
    LogEvent( COMPONENT_9P, "Mooshika engine is bound" ) ;


  /* Start infinite loop here */
  while( 1 )
    {
      if( ( child_trans = msk_accept_one( trans ) ) == NULL )
        LogMajor( COMPONENT_9P, "9P/RDMA : dispatcher failed to accept a new client" ) ;
      else
       {
         if( pthread_create( &thrid_handle_trans,
                             &attr_thr,
                             _9p_rdma_thread,
                             child_trans ) )
           LogMajor( COMPONENT_9P, "9P/RDMA : dispatcher accepted a new client but could not spawn a related thread" ) ;
         else
	   LogEvent( COMPONENT_9P, "9P/RDMA: thread #%x spawned to managed new child_trans [%p]",
		     (unsigned int)thrid_handle_trans, child_trans ) ;
       }
    } /* for( ;; ) */

   return NULL ;
} /* _9p_rdma_dispatcher_thread */
示例#19
0
void *_9p_socket_thread(void *Arg)
{
	long int tcp_sock = (long int)Arg;
	int rc = -1;
	struct pollfd fds[1];
	int fdcount = 1;
	static char my_name[MAXNAMLEN + 1];
	socklen_t addrpeerlen = 0;
	struct sockaddr_storage addrpeer;
	char strcaller[INET6_ADDRSTRLEN];
	request_data_t *req = NULL;
	int tag;
	unsigned long sequence = 0;
	unsigned int i = 0;
	char *_9pmsg = NULL;
	uint32_t msglen;

	struct _9p_conn _9p_conn;

	int readlen = 0;
	int total_readlen = 0;

	snprintf(my_name, MAXNAMLEN, "9p_sock_mgr#fd=%ld", tcp_sock);
	SetNameFunction(my_name);

	/* Init the struct _9p_conn structure */
	memset(&_9p_conn, 0, sizeof(_9p_conn));
	pthread_mutex_init(&_9p_conn.sock_lock, NULL);
	_9p_conn.trans_type = _9P_TCP;
	_9p_conn.trans_data.sockfd = tcp_sock;
	for (i = 0; i < FLUSH_BUCKETS; i++) {
		pthread_mutex_init(&_9p_conn.flush_buckets[i].lock, NULL);
		glist_init(&_9p_conn.flush_buckets[i].list);
	}
	atomic_store_uint32_t(&_9p_conn.refcount, 0);

	/* Init the fids pointers array */
	memset(&_9p_conn.fids, 0, _9P_FID_PER_CONN * sizeof(struct _9p_fid *));

	/* Set initial msize.
	 * Client may request a lower value during TVERSION */
	_9p_conn.msize = _9p_param._9p_tcp_msize;

	if (gettimeofday(&_9p_conn.birth, NULL) == -1)
		LogFatal(COMPONENT_9P, "Cannot get connection's time of birth");

	addrpeerlen = sizeof(addrpeer);
	rc = getpeername(tcp_sock, (struct sockaddr *)&addrpeer,
			 &addrpeerlen);
	if (rc == -1) {
		LogMajor(COMPONENT_9P,
			 "Cannot get peername to tcp socket for 9p, error %d (%s)",
			 errno, strerror(errno));
		/* XXX */
		strncpy(strcaller, "(unresolved)", INET6_ADDRSTRLEN);
		strcaller[12] = '\0';
	} else {
		switch (addrpeer.ss_family) {
		case AF_INET:
			inet_ntop(addrpeer.ss_family,
				  &((struct sockaddr_in *)&addrpeer)->
				  sin_addr, strcaller, INET6_ADDRSTRLEN);
			break;
		case AF_INET6:
			inet_ntop(addrpeer.ss_family,
				  &((struct sockaddr_in6 *)&addrpeer)->
				  sin6_addr, strcaller, INET6_ADDRSTRLEN);
			break;
		default:
			snprintf(strcaller, INET6_ADDRSTRLEN, "BAD ADDRESS");
			break;
		}

		LogEvent(COMPONENT_9P, "9p socket #%ld is connected to %s",
			 tcp_sock, strcaller);
		printf("9p socket #%ld is connected to %s\n", tcp_sock,
		       strcaller);
	}
	_9p_conn.client = get_gsh_client(&addrpeer, false);

	/* Set up the structure used by poll */
	memset((char *)fds, 0, sizeof(struct pollfd));
	fds[0].fd = tcp_sock;
	fds[0].events =
	    POLLIN | POLLPRI | POLLRDBAND | POLLRDNORM | POLLRDHUP | POLLHUP |
	    POLLERR | POLLNVAL;

	for (;;) {
		total_readlen = 0;  /* new message */
		rc = poll(fds, fdcount, -1);
		if (rc == -1) {
			/* timeout = -1 => Wait indefinitely for events */
			/* Interruption if not an issue */
			if (errno == EINTR)
				continue;

			LogCrit(COMPONENT_9P,
				"Got error %u (%s) on fd %ld connect to %s while polling on socket",
				errno, strerror(errno), tcp_sock, strcaller);
		}

		if (fds[0].revents & POLLNVAL) {
			LogEvent(COMPONENT_9P,
				 "Client %s on socket %lu produced POLLNVAL",
				 strcaller, tcp_sock);
			goto end;
		}

		if (fds[0].revents & (POLLERR | POLLHUP | POLLRDHUP)) {
			LogEvent(COMPONENT_9P,
				 "Client %s on socket %lu has shut down and closed",
				 strcaller, tcp_sock);
			goto end;
		}

		if (!(fds[0].revents & (POLLIN | POLLRDNORM)))
			continue;

		/* Prepare to read the message */
		_9pmsg = gsh_malloc(_9p_conn.msize);
		if (_9pmsg == NULL) {
			LogCrit(COMPONENT_9P,
				"Could not allocate 9pmsg buffer for client %s on socket %lu",
				strcaller, tcp_sock);
			goto end;
		}

		/* An incoming 9P request: the msg has a 4 bytes header
		   showing the size of the msg including the header */
		readlen = recv(fds[0].fd, _9pmsg,
			       _9P_HDR_SIZE, MSG_WAITALL);
		if (readlen != _9P_HDR_SIZE)
			goto badmsg;

		msglen = *(uint32_t *) _9pmsg;
		if (msglen > _9p_conn.msize) {
			LogCrit(COMPONENT_9P,
				"Message size too big! got %u, max = %u",
				msglen, _9p_conn.msize);
			goto end;
		}

		LogFullDebug(COMPONENT_9P,
			     "Received 9P/TCP message of size %u from client %s on socket %lu",
			     msglen, strcaller, tcp_sock);

		total_readlen += readlen;
		while (total_readlen < msglen) {
			readlen = recv(fds[0].fd,
				       _9pmsg + total_readlen,
				       msglen - total_readlen,
				       0);

			if (readlen > 0) {
				total_readlen += readlen;
				continue;
			}
			if (readlen == 0 ||
			    (readlen < 0 && errno != EINTR))
				goto badmsg;
		}	/* while */

		server_stats_transport_done(_9p_conn.client,
					    total_readlen, 1, 0,
					    0, 0, 0);

		/* Message is good. */
		req = pool_alloc(request_pool, NULL);

		req->rtype = _9P_REQUEST;
		req->r_u._9p._9pmsg = _9pmsg;
		req->r_u._9p.pconn = &_9p_conn;

		/* Add this request to the request list,
		 * should it be flushed later. */
		tag = *(u16 *) (_9pmsg + _9P_HDR_SIZE +
				_9P_TYPE_SIZE);
		_9p_AddFlushHook(&req->r_u._9p, tag,
				 sequence++);
		LogFullDebug(COMPONENT_9P,
			     "Request tag is %d\n", tag);

		/* Message was OK push it */
		DispatchWork9P(req);

		/* Not our buffer anymore */
		_9pmsg = NULL;
		continue;

badmsg:
		if (readlen == 0)
			LogEvent(COMPONENT_9P,
				 "Premature end for Client %s on socket %lu, total read = %u",
				 strcaller, tcp_sock, total_readlen);
		else if (readlen < 0) {
			LogEvent(COMPONENT_9P,
				 "Read error client %s on socket %lu errno=%d, total read = %u",
				 strcaller, tcp_sock,
				 errno, total_readlen);
		} else
			LogEvent(COMPONENT_9P,
				 "Header too small! for client %s on socket %lu: readlen=%u expected=%u",
				 strcaller, tcp_sock, readlen,
				 _9P_HDR_SIZE);

		/* Either way, we close the connection.
		 * It is not possible to survive
		 * once we get out of sync in the TCP stream
		 * with the client
		 */
		break; /* bail out */
	}			/* for( ;; ) */

end:
	LogEvent(COMPONENT_9P, "Closing connection on socket %lu", tcp_sock);
	close(tcp_sock);

	/* Free buffer if we encountered an error
	 * before we could give it to a worker */
	if (_9pmsg)
		gsh_free(_9pmsg);

	while (atomic_fetch_uint32_t(&_9p_conn.refcount)) {
		LogEvent(COMPONENT_9P, "Waiting for workers to release pconn");
		sleep(1);
	}

	_9p_cleanup_fids(&_9p_conn);

	if (_9p_conn.client != NULL)
		put_gsh_client(_9p_conn.client);

	pthread_exit(NULL);
}				/* _9p_socket_thread */
示例#20
0
void *stats_thread(void *addr)
{
  FILE *stats_file = NULL;
  struct stat statref;
  struct stat stattest;
  time_t current_time;
  struct tm current_time_struct;
  struct tm boot_time_struct;
  char strdate[1024];
  char strbootdate[1024];
  unsigned int i = 0;
  unsigned int j = 0;
  int reopen_stats = FALSE;
  nfs_worker_data_t *workers_data = addr;

  cache_inode_stat_t global_cache_inode_stat;
  nfs_worker_stat_t global_worker_stat;
  hash_stat_t hstat;
  hash_stat_t hstat_reverse;

  unsigned long long total_fsal_calls;
  fsal_statistics_t global_fsal_stat;

  unsigned int min_pending_request;
  unsigned int max_pending_request;
  unsigned int total_pending_request;
  unsigned int average_pending_request;
  unsigned int len_pending_request = 0;

  unsigned int avg_latency;

#ifndef _NO_BUDDY_SYSTEM
  int rc = 0;
  buddy_stats_t global_buddy_stat;
#endif

  SetNameFunction("stat_thr");

#ifndef _NO_BUDDY_SYSTEM
  if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS)
    {
      /* Failed init */
      LogFatal(COMPONENT_MAIN,
               "NFS STATS : Memory manager could not be initialized");
    }
  LogInfo(COMPONENT_MAIN,
          "NFS STATS : Memory manager successfully initialized");
#endif

  /* Open the stats file, in append mode */
  if((stats_file = fopen(nfs_param.core_param.stats_file_path, "a")) == NULL)
    {
      LogCrit(COMPONENT_MAIN,
              "NFS STATS : Could not open stats file %s, no stats will be made...",
              nfs_param.core_param.stats_file_path);
      return NULL;
    }

  if(stat(nfs_param.core_param.stats_file_path, &statref) != 0)
    {
      LogCrit(COMPONENT_MAIN,
              "NFS STATS : Could not get inode for %s, no stats will be made...",
              nfs_param.core_param.stats_file_path);
      fclose(stats_file);
      return NULL;
    }

#ifdef _SNMP_ADM_ACTIVE
  /* start snmp library */
  if(stats_snmp(workers_data) == 0)
    LogInfo(COMPONENT_MAIN,
            "NFS STATS: SNMP stats service was started successfully");
  else
    LogCrit(COMPONENT_MAIN,
            "NFS STATS: ERROR starting SNMP stats export thread");
#endif /*_SNMP_ADM_ACTIVE*/

  while(1)
    {
      /* Initial wait */
      sleep(nfs_param.core_param.stats_update_delay);

      /* Debug trace */
      LogInfo(COMPONENT_MAIN, "NFS STATS : now dumping stats");

      /* Stats main loop */
      if(stat(nfs_param.core_param.stats_file_path, &stattest) == 0)
        {
          if(stattest.st_ino != statref.st_ino)
            reopen_stats = TRUE;
        }
      else
        {
          if(errno == ENOENT)
            reopen_stats = TRUE;
        }

      /* Check is file has changed (the inode number will be different) */
      if(reopen_stats == TRUE)
        {
          /* Stats file has changed */
          LogEvent(COMPONENT_MAIN,
                   "NFS STATS : stats file has changed or was removed, I close and reopen it");
          fflush(stats_file);
          fclose(stats_file);
          if((stats_file = fopen(nfs_param.core_param.stats_file_path, "a")) == NULL)
            {
              LogCrit(COMPONENT_MAIN,
                      "NFS STATS : Could not open stats file %s, no further stats will be made...",
                      nfs_param.core_param.stats_file_path);
              return NULL;
            }
          statref = stattest;
          reopen_stats = FALSE;
        }

      /* Get the current epoch time */
      current_time = time(NULL);
      memcpy(&current_time_struct, localtime(&current_time), sizeof(current_time_struct));
      snprintf(strdate, 1024, "%u, %.2d/%.2d/%.4d %.2d:%.2d:%.2d ",
               (unsigned int)current_time,
               current_time_struct.tm_mday,
               current_time_struct.tm_mon + 1,
               1900 + current_time_struct.tm_year,
               current_time_struct.tm_hour,
               current_time_struct.tm_min, current_time_struct.tm_sec);

      /* Printing the general Stats */
      memcpy(&boot_time_struct, localtime(&ServerBootTime), sizeof(boot_time_struct));
      snprintf(strbootdate, 1024, "%u, %.2d/%.2d/%.4d %.2d:%.2d:%.2d ",
               (unsigned int)ServerBootTime,
               boot_time_struct.tm_mday,
               boot_time_struct.tm_mon + 1,
               1900 + boot_time_struct.tm_year,
               boot_time_struct.tm_hour,
               boot_time_struct.tm_min, boot_time_struct.tm_sec);

      fprintf(stats_file, "NFS_SERVER_GENERAL,%s;%s\n", strdate, strbootdate);

      /* Zeroing the cache_stats */
      global_cache_inode_stat.nb_gc_lru_active = 0;
      global_cache_inode_stat.nb_gc_lru_total = 0;
      global_cache_inode_stat.nb_call_total = 0;

      memset(global_cache_inode_stat.func_stats.nb_err_unrecover, 0,
             sizeof(unsigned int) * CACHE_INODE_NB_COMMAND);

      /* Merging the cache inode stats for every thread */
      for(i = 0; i < nfs_param.core_param.nb_worker; i++)
        {
          global_cache_inode_stat.nb_gc_lru_active +=
              workers_data[i].cache_inode_client.stat.nb_gc_lru_active;
          global_cache_inode_stat.nb_gc_lru_total +=
              workers_data[i].cache_inode_client.stat.nb_gc_lru_total;
          global_cache_inode_stat.nb_call_total +=
              workers_data[i].cache_inode_client.stat.nb_call_total;

          for(j = 0; j < CACHE_INODE_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_cache_inode_stat.func_stats.nb_success[j] =
                      workers_data[i].cache_inode_client.stat.func_stats.nb_success[j];
                  global_cache_inode_stat.func_stats.nb_call[j] =
                      workers_data[i].cache_inode_client.stat.func_stats.nb_call[j];
                  global_cache_inode_stat.func_stats.nb_err_retryable[j] =
                      workers_data[i].cache_inode_client.stat.func_stats.
                      nb_err_retryable[j];
                  global_cache_inode_stat.func_stats.nb_err_unrecover[j] =
                      workers_data[i].cache_inode_client.stat.func_stats.
                      nb_err_unrecover[j];
                }
              else
                {
                  global_cache_inode_stat.func_stats.nb_success[j] +=
                      workers_data[i].cache_inode_client.stat.func_stats.nb_success[j];
                  global_cache_inode_stat.func_stats.nb_call[j] +=
                      workers_data[i].cache_inode_client.stat.func_stats.nb_call[j];
                  global_cache_inode_stat.func_stats.nb_err_retryable[j] +=
                      workers_data[i].cache_inode_client.stat.func_stats.
                      nb_err_retryable[j];
                  global_cache_inode_stat.func_stats.nb_err_unrecover[j] +=
                      workers_data[i].cache_inode_client.stat.func_stats.
                      nb_err_unrecover[j];
                }

            }
        }

      /* Printing the cache_inode stat */
      fprintf(stats_file, "CACHE_INODE_CALLS,%s;%u,%u,%u",
              strdate,
              global_cache_inode_stat.nb_call_total,
              global_cache_inode_stat.nb_gc_lru_total,
              global_cache_inode_stat.nb_gc_lru_active);

      for(j = 0; j < CACHE_INODE_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u,%u",
                global_cache_inode_stat.func_stats.nb_call[j],
                global_cache_inode_stat.func_stats.nb_success[j],
                global_cache_inode_stat.func_stats.nb_err_retryable[j],
                global_cache_inode_stat.func_stats.nb_err_unrecover[j]);
      fprintf(stats_file, "\n");

      /* Pinting the cache inode hash stat */
      /* This is done only on worker[0]: the hashtable is shared and worker 0 always exists */
      HashTable_GetStats(workers_data[0].ht, &hstat);

      fprintf(stats_file,
              "CACHE_INODE_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n",
              strdate, hstat.dynamic.nb_entries, hstat.computed.min_rbt_num_node,
              hstat.computed.max_rbt_num_node, hstat.computed.average_rbt_num_node,
              hstat.dynamic.ok.nb_set, hstat.dynamic.notfound.nb_set,
              hstat.dynamic.err.nb_set, hstat.dynamic.ok.nb_test,
              hstat.dynamic.notfound.nb_test, hstat.dynamic.err.nb_test,
              hstat.dynamic.ok.nb_get, hstat.dynamic.notfound.nb_get,
              hstat.dynamic.err.nb_get, hstat.dynamic.ok.nb_del,
              hstat.dynamic.notfound.nb_del, hstat.dynamic.err.nb_del);

      /* Merging the NFS protocols stats together */
      global_worker_stat.nb_total_req = 0;
      global_worker_stat.nb_udp_req = 0;
      global_worker_stat.nb_tcp_req = 0;
      global_worker_stat.stat_req.nb_mnt1_req = 0;
      global_worker_stat.stat_req.nb_mnt3_req = 0;
      global_worker_stat.stat_req.nb_nfs2_req = 0;
      global_worker_stat.stat_req.nb_nfs3_req = 0;
      global_worker_stat.stat_req.nb_nfs4_req = 0;
      global_worker_stat.stat_req.nb_nlm4_req = 0;
      global_worker_stat.stat_req.nb_nfs40_op = 0;
      global_worker_stat.stat_req.nb_nfs41_op = 0;
      global_worker_stat.stat_req.nb_rquota1_req = 0;
      global_worker_stat.stat_req.nb_rquota2_req = 0;

      /* prepare for computing pending request stats */
      min_pending_request = 10000000;
      max_pending_request = 0;
      total_pending_request = 0;
      average_pending_request = 0;
      len_pending_request = 0;

      for(i = 0; i < nfs_param.core_param.nb_worker; i++)
        {
          global_worker_stat.nb_total_req += workers_data[i].stats.nb_total_req;
          global_worker_stat.nb_udp_req += workers_data[i].stats.nb_udp_req;
          global_worker_stat.nb_tcp_req += workers_data[i].stats.nb_tcp_req;
          global_worker_stat.stat_req.nb_mnt1_req +=
              workers_data[i].stats.stat_req.nb_mnt1_req;
          global_worker_stat.stat_req.nb_mnt3_req +=
              workers_data[i].stats.stat_req.nb_mnt3_req;
          global_worker_stat.stat_req.nb_nfs2_req +=
              workers_data[i].stats.stat_req.nb_nfs2_req;
          global_worker_stat.stat_req.nb_nfs3_req +=
              workers_data[i].stats.stat_req.nb_nfs3_req;
          global_worker_stat.stat_req.nb_nfs4_req +=
              workers_data[i].stats.stat_req.nb_nfs4_req;
          global_worker_stat.stat_req.nb_nfs40_op +=
              workers_data[i].stats.stat_req.nb_nfs40_op;
          global_worker_stat.stat_req.nb_nfs41_op +=
              workers_data[i].stats.stat_req.nb_nfs41_op;

          global_worker_stat.stat_req.nb_nlm4_req +=
              workers_data[i].stats.stat_req.nb_nlm4_req;

          global_worker_stat.stat_req.nb_rquota1_req +=
              workers_data[i].stats.stat_req.nb_nlm4_req;

          global_worker_stat.stat_req.nb_rquota2_req +=
              workers_data[i].stats.stat_req.nb_nlm4_req;

          for(j = 0; j < MNT_V1_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_mnt1[j].total =
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].total;
                  global_worker_stat.stat_req.stat_req_mnt1[j].success =
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].success;
                  global_worker_stat.stat_req.stat_req_mnt1[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].dropped;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_mnt1[j].total +=
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].total;
                  global_worker_stat.stat_req.stat_req_mnt1[j].success +=
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].success;
                  global_worker_stat.stat_req.stat_req_mnt1[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_mnt1[j].dropped;
                }
            }

          for(j = 0; j < MNT_V3_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_mnt3[j].total =
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].total;
                  global_worker_stat.stat_req.stat_req_mnt3[j].success =
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].success;
                  global_worker_stat.stat_req.stat_req_mnt3[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].dropped;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_mnt3[j].total +=
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].total;
                  global_worker_stat.stat_req.stat_req_mnt3[j].success +=
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].success;
                  global_worker_stat.stat_req.stat_req_mnt3[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_mnt3[j].dropped;
                }
            }

          for(j = 0; j < NFS_V2_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_nfs2[j].total =
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].total;
                  global_worker_stat.stat_req.stat_req_nfs2[j].success =
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].success;
                  global_worker_stat.stat_req.stat_req_nfs2[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].dropped;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_nfs2[j].total +=
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].total;
                  global_worker_stat.stat_req.stat_req_nfs2[j].success +=
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].success;
                  global_worker_stat.stat_req.stat_req_nfs2[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_nfs2[j].dropped;
                }
            }

          for(j = 0; j < NFS_V3_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_nfs3[j].total =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].total;
                  global_worker_stat.stat_req.stat_req_nfs3[j].success =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].success;
                  global_worker_stat.stat_req.stat_req_nfs3[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].dropped;
                  global_worker_stat.stat_req.stat_req_nfs3[j].tot_latency =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].tot_latency;
                  global_worker_stat.stat_req.stat_req_nfs3[j].min_latency =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].min_latency;
                  global_worker_stat.stat_req.stat_req_nfs3[j].max_latency =
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].max_latency;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_nfs3[j].total +=
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].total;
                  global_worker_stat.stat_req.stat_req_nfs3[j].success +=
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].success;
                  global_worker_stat.stat_req.stat_req_nfs3[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].dropped;
                  global_worker_stat.stat_req.stat_req_nfs3[j].tot_latency +=
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].tot_latency;
                  set_min_latency(&(global_worker_stat.stat_req.stat_req_nfs3[j]),
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].min_latency);
                  set_max_latency(&(global_worker_stat.stat_req.stat_req_nfs3[j]),
                      workers_data[i].stats.stat_req.stat_req_nfs3[j].max_latency);
                }
            }

          for(j = 0; j < NFS_V4_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_nfs4[j].total =
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].total;
                  global_worker_stat.stat_req.stat_req_nfs4[j].success =
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].success;
                  global_worker_stat.stat_req.stat_req_nfs4[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].dropped;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_nfs4[j].total +=
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].total;
                  global_worker_stat.stat_req.stat_req_nfs4[j].success +=
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].success;
                  global_worker_stat.stat_req.stat_req_nfs4[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_nfs4[j].dropped;
                }
            }

          for(j = 0; j < NFS_V40_NB_OPERATION; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_op_nfs40[j].total =
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].total;
                  global_worker_stat.stat_req.stat_op_nfs40[j].success =
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].success;
                  global_worker_stat.stat_req.stat_op_nfs40[j].failed =
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].failed;
                }
              else
                {
                  global_worker_stat.stat_req.stat_op_nfs40[j].total +=
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].total;
                  global_worker_stat.stat_req.stat_op_nfs40[j].success +=
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].success;
                  global_worker_stat.stat_req.stat_op_nfs40[j].failed +=
                      workers_data[i].stats.stat_req.stat_op_nfs40[j].failed;
                }
            }

          for(j = 0; j < NFS_V41_NB_OPERATION; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_op_nfs41[j].total =
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].total;
                  global_worker_stat.stat_req.stat_op_nfs41[j].success =
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].success;
                  global_worker_stat.stat_req.stat_op_nfs41[j].failed =
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].failed;
                }
              else
                {
                  global_worker_stat.stat_req.stat_op_nfs41[j].total +=
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].total;
                  global_worker_stat.stat_req.stat_op_nfs41[j].success +=
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].success;
                  global_worker_stat.stat_req.stat_op_nfs41[j].failed +=
                      workers_data[i].stats.stat_req.stat_op_nfs41[j].failed;
                }
            }

          for(j = 0; j < NLM_V4_NB_OPERATION; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_nlm4[j].total =
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].total;
                  global_worker_stat.stat_req.stat_req_nlm4[j].success =
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].success;
                  global_worker_stat.stat_req.stat_req_nlm4[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].dropped;
                }
              else
                {
                  global_worker_stat.stat_req.stat_req_nlm4[j].total +=
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].total;
                  global_worker_stat.stat_req.stat_req_nlm4[j].success +=
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].success;
                  global_worker_stat.stat_req.stat_req_nlm4[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_nlm4[j].dropped;
                }
            }

          for(j = 0; j < RQUOTA_NB_COMMAND; j++)
            {
              if(i == 0)
                {
                  global_worker_stat.stat_req.stat_req_rquota1[j].total =
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].total;
                  global_worker_stat.stat_req.stat_req_rquota1[j].success =
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].success;
                  global_worker_stat.stat_req.stat_req_rquota1[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].dropped;

                  global_worker_stat.stat_req.stat_req_rquota2[j].total =
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].total;
                  global_worker_stat.stat_req.stat_req_rquota2[j].success =
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].success;
                  global_worker_stat.stat_req.stat_req_rquota2[j].dropped =
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].dropped;

                }
              else
                {
                  global_worker_stat.stat_req.stat_req_rquota1[j].total +=
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].total;
                  global_worker_stat.stat_req.stat_req_rquota1[j].success +=
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].success;
                  global_worker_stat.stat_req.stat_req_rquota1[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_rquota1[j].dropped;

                  global_worker_stat.stat_req.stat_req_rquota2[j].total +=
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].total;
                  global_worker_stat.stat_req.stat_req_rquota2[j].success +=
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].success;
                  global_worker_stat.stat_req.stat_req_rquota2[j].dropped +=
                      workers_data[i].stats.stat_req.stat_req_rquota2[j].dropped;
                }
            }

          /* Computing the pending request stats */
          len_pending_request =
              workers_data[i].pending_request->nb_entry -
              workers_data[i].pending_request->nb_invalid;

          if(len_pending_request < min_pending_request)
            min_pending_request = len_pending_request;

          if(len_pending_request > max_pending_request)
            max_pending_request = len_pending_request;

          total_pending_request += len_pending_request;
        }                       /* for( i = 0 ; i < nfs_param.core_param.nb_worker ; i++ ) */

      /* Compute average pending request */
      average_pending_request = total_pending_request / nfs_param.core_param.nb_worker;

      fprintf(stats_file, "NFS/MOUNT STATISTICS,%s;%u,%u,%u|%u,%u,%u,%u,%u|%u,%u,%u,%u\n",
              strdate,
              global_worker_stat.nb_total_req,
              global_worker_stat.nb_udp_req,
              global_worker_stat.nb_tcp_req,
              global_worker_stat.stat_req.nb_mnt1_req,
              global_worker_stat.stat_req.nb_mnt3_req,
              global_worker_stat.stat_req.nb_nfs2_req,
              global_worker_stat.stat_req.nb_nfs3_req,
              global_worker_stat.stat_req.nb_nfs4_req,
              total_pending_request,
              min_pending_request, max_pending_request, average_pending_request);

      fprintf(stats_file, "MNT V1 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_mnt1_req);
      for(j = 0; j < MNT_V1_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_mnt1[j].total,
                global_worker_stat.stat_req.stat_req_mnt1[j].success,
                global_worker_stat.stat_req.stat_req_mnt1[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "MNT V3 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_mnt3_req);
      for(j = 0; j < MNT_V3_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_mnt3[j].total,
                global_worker_stat.stat_req.stat_req_mnt3[j].success,
                global_worker_stat.stat_req.stat_req_mnt3[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NFS V2 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nfs2_req);
      for(j = 0; j < NFS_V2_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_nfs2[j].total,
                global_worker_stat.stat_req.stat_req_nfs2[j].success,
                global_worker_stat.stat_req.stat_req_nfs2[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NFS V3 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nfs3_req);
      for(j = 0; j < NFS_V3_NB_COMMAND; j++)
	{
          if(global_worker_stat.stat_req.stat_req_nfs3[j].total > 0)
            {
              avg_latency = (global_worker_stat.stat_req.stat_req_nfs3[j].tot_latency /
              global_worker_stat.stat_req.stat_req_nfs3[j].total);
            }
          else
            {
              avg_latency = 0;
            }
          fprintf(stats_file, "|%u,%u,%u,%u,%u,%u,%u",
                  global_worker_stat.stat_req.stat_req_nfs3[j].total,
                  global_worker_stat.stat_req.stat_req_nfs3[j].success,
                  global_worker_stat.stat_req.stat_req_nfs3[j].dropped,
                  global_worker_stat.stat_req.stat_req_nfs3[j].tot_latency,
                  avg_latency,
                  global_worker_stat.stat_req.stat_req_nfs3[j].min_latency,
                  global_worker_stat.stat_req.stat_req_nfs3[j].max_latency);
        }
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NFS V4 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nfs4_req);
      for(j = 0; j < NFS_V4_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_nfs4[j].total,
                global_worker_stat.stat_req.stat_req_nfs4[j].success,
                global_worker_stat.stat_req.stat_req_nfs4[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NFS V4.0 OPERATIONS,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nfs40_op);
      for(j = 0; j < NFS_V40_NB_OPERATION; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_op_nfs40[j].total,
                global_worker_stat.stat_req.stat_op_nfs40[j].success,
                global_worker_stat.stat_req.stat_op_nfs40[j].failed);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NFS V4.1 OPERATIONS,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nfs41_op);
      for(j = 0; j < NFS_V41_NB_OPERATION; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_op_nfs41[j].total,
                global_worker_stat.stat_req.stat_op_nfs41[j].success,
                global_worker_stat.stat_req.stat_op_nfs41[j].failed);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "NLM V4 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_nlm4_req);
      for(j = 0; j < NLM_V4_NB_OPERATION; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_nlm4[j].total,
                global_worker_stat.stat_req.stat_req_nlm4[j].success,
                global_worker_stat.stat_req.stat_req_nlm4[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "RQUOTA V1 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_rquota1_req);
      for(j = 0; j < RQUOTA_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_rquota1[j].total,
                global_worker_stat.stat_req.stat_req_rquota1[j].success,
                global_worker_stat.stat_req.stat_req_rquota1[j].dropped);
      fprintf(stats_file, "\n");

      fprintf(stats_file, "RQUOTA V2 REQUEST,%s;%u", strdate,
              global_worker_stat.stat_req.nb_rquota2_req);
      for(j = 0; j < RQUOTA_NB_COMMAND; j++)
        fprintf(stats_file, "|%u,%u,%u",
                global_worker_stat.stat_req.stat_req_rquota2[j].total,
                global_worker_stat.stat_req.stat_req_rquota2[j].success,
                global_worker_stat.stat_req.stat_req_rquota2[j].dropped);
      fprintf(stats_file, "\n");

      /* Printing the cache inode hash stat */
      nfs_dupreq_get_stats(&hstat);

      fprintf(stats_file,
              "DUP_REQ_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n",
              strdate, hstat.dynamic.nb_entries, hstat.computed.min_rbt_num_node,
              hstat.computed.max_rbt_num_node, hstat.computed.average_rbt_num_node,
              hstat.dynamic.ok.nb_set, hstat.dynamic.notfound.nb_set,
              hstat.dynamic.err.nb_set, hstat.dynamic.ok.nb_test,
              hstat.dynamic.notfound.nb_test, hstat.dynamic.err.nb_test,
              hstat.dynamic.ok.nb_get, hstat.dynamic.notfound.nb_get,
              hstat.dynamic.err.nb_get, hstat.dynamic.ok.nb_del,
              hstat.dynamic.notfound.nb_del, hstat.dynamic.err.nb_del);

      /* Printing the UIDMAP_TYPE hash table stats */
      idmap_get_stats(UIDMAP_TYPE, &hstat, &hstat_reverse);
      fprintf(stats_file,
              "UIDMAP_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n", strdate,
              hstat.dynamic.nb_entries, hstat.computed.min_rbt_num_node,
              hstat.computed.max_rbt_num_node, hstat.computed.average_rbt_num_node,
              hstat.dynamic.ok.nb_set, hstat.dynamic.notfound.nb_set,
              hstat.dynamic.err.nb_set, hstat.dynamic.ok.nb_test,
              hstat.dynamic.notfound.nb_test, hstat.dynamic.err.nb_test,
              hstat.dynamic.ok.nb_get, hstat.dynamic.notfound.nb_get,
              hstat.dynamic.err.nb_get, hstat.dynamic.ok.nb_del,
              hstat.dynamic.notfound.nb_del, hstat.dynamic.err.nb_del);
      fprintf(stats_file,
              "UNAMEMAP_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n",
              strdate, hstat_reverse.dynamic.nb_entries,
              hstat_reverse.computed.min_rbt_num_node,
              hstat_reverse.computed.max_rbt_num_node,
              hstat_reverse.computed.average_rbt_num_node,
              hstat_reverse.dynamic.ok.nb_set, hstat_reverse.dynamic.notfound.nb_set,
              hstat_reverse.dynamic.err.nb_set, hstat_reverse.dynamic.ok.nb_test,
              hstat_reverse.dynamic.notfound.nb_test, hstat_reverse.dynamic.err.nb_test,
              hstat_reverse.dynamic.ok.nb_get, hstat_reverse.dynamic.notfound.nb_get,
              hstat_reverse.dynamic.err.nb_get, hstat_reverse.dynamic.ok.nb_del,
              hstat_reverse.dynamic.notfound.nb_del, hstat_reverse.dynamic.err.nb_del);

      /* Printing the GIDMAP_TYPE hash table stats */
      idmap_get_stats(GIDMAP_TYPE, &hstat, &hstat_reverse);
      fprintf(stats_file,
              "GIDMAP_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n", strdate,
              hstat.dynamic.nb_entries, hstat.computed.min_rbt_num_node,
              hstat.computed.max_rbt_num_node, hstat.computed.average_rbt_num_node,
              hstat.dynamic.ok.nb_set, hstat.dynamic.notfound.nb_set,
              hstat.dynamic.err.nb_set, hstat.dynamic.ok.nb_test,
              hstat.dynamic.notfound.nb_test, hstat.dynamic.err.nb_test,
              hstat.dynamic.ok.nb_get, hstat.dynamic.notfound.nb_get,
              hstat.dynamic.err.nb_get, hstat.dynamic.ok.nb_del,
              hstat.dynamic.notfound.nb_del, hstat.dynamic.err.nb_del);
      fprintf(stats_file,
              "GNAMEMAP_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n",
              strdate, hstat_reverse.dynamic.nb_entries,
              hstat_reverse.computed.min_rbt_num_node,
              hstat_reverse.computed.max_rbt_num_node,
              hstat_reverse.computed.average_rbt_num_node,
              hstat_reverse.dynamic.ok.nb_set, hstat_reverse.dynamic.notfound.nb_set,
              hstat_reverse.dynamic.err.nb_set, hstat_reverse.dynamic.ok.nb_test,
              hstat_reverse.dynamic.notfound.nb_test, hstat_reverse.dynamic.err.nb_test,
              hstat_reverse.dynamic.ok.nb_get, hstat_reverse.dynamic.notfound.nb_get,
              hstat_reverse.dynamic.err.nb_get, hstat_reverse.dynamic.ok.nb_del,
              hstat_reverse.dynamic.notfound.nb_del, hstat_reverse.dynamic.err.nb_del);

      /* Stats for the IP/Name hashtable */
      nfs_ip_name_get_stats(&hstat);
      fprintf(stats_file,
              "IP_NAME_HASH,%s;%u,%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u|%u,%u,%u\n",
              strdate, hstat_reverse.dynamic.nb_entries,
              hstat_reverse.computed.min_rbt_num_node,
              hstat_reverse.computed.max_rbt_num_node,
              hstat_reverse.computed.average_rbt_num_node,
              hstat_reverse.dynamic.ok.nb_set, hstat_reverse.dynamic.notfound.nb_set,
              hstat_reverse.dynamic.err.nb_set, hstat_reverse.dynamic.ok.nb_test,
              hstat_reverse.dynamic.notfound.nb_test, hstat_reverse.dynamic.err.nb_test,
              hstat_reverse.dynamic.ok.nb_get, hstat_reverse.dynamic.notfound.nb_get,
              hstat_reverse.dynamic.err.nb_get, hstat_reverse.dynamic.ok.nb_del,
              hstat_reverse.dynamic.notfound.nb_del, hstat_reverse.dynamic.err.nb_del);

      /* fsal statistics */
      memset(&global_fsal_stat, 0, sizeof(fsal_statistics_t));
      total_fsal_calls = 0;

      for(i = 0; i < nfs_param.core_param.nb_worker; i++)
        {

          for(j = 0; j < FSAL_NB_FUNC; j++)
            {
              total_fsal_calls += workers_data[i].stats.fsal_stats.func_stats.nb_call[j];

              global_fsal_stat.func_stats.nb_call[j] +=
                  workers_data[i].stats.fsal_stats.func_stats.nb_call[j];
              global_fsal_stat.func_stats.nb_success[j] +=
                  workers_data[i].stats.fsal_stats.func_stats.nb_success[j];
              global_fsal_stat.func_stats.nb_err_retryable[j] +=
                  workers_data[i].stats.fsal_stats.func_stats.nb_err_retryable[j];
              global_fsal_stat.func_stats.nb_err_unrecover[j] +=
                  workers_data[i].stats.fsal_stats.func_stats.nb_err_unrecover[j];
            }

        }

      fprintf(stats_file, "FSAL_CALLS,%s;%llu", strdate, total_fsal_calls);
      for(j = 0; j < FSAL_NB_FUNC; j++)
        fprintf(stats_file, "|%u,%u,%u,%u",
                global_fsal_stat.func_stats.nb_call[j],
                global_fsal_stat.func_stats.nb_success[j],
                global_fsal_stat.func_stats.nb_err_retryable[j],
                global_fsal_stat.func_stats.nb_err_unrecover[j]);
      fprintf(stats_file, "\n");

#ifndef _NO_BUDDY_SYSTEM

      /* buddy memory */

      memset(&global_buddy_stat, 0, sizeof(buddy_stats_t));

      for(i = 0; i < nfs_param.core_param.nb_worker; i++)
        {

          global_buddy_stat.TotalMemSpace +=
              workers_data[i].stats.buddy_stats.TotalMemSpace;
          global_buddy_stat.ExtraMemSpace +=
              workers_data[i].stats.buddy_stats.ExtraMemSpace;

          global_buddy_stat.StdMemSpace += workers_data[i].stats.buddy_stats.StdMemSpace;
          global_buddy_stat.StdUsedSpace +=
              workers_data[i].stats.buddy_stats.StdUsedSpace;

          if(workers_data[i].stats.buddy_stats.StdUsedSpace >
             global_buddy_stat.WM_StdUsedSpace)
            global_buddy_stat.WM_StdUsedSpace =
                workers_data[i].stats.buddy_stats.StdUsedSpace;

          global_buddy_stat.NbStdPages += workers_data[i].stats.buddy_stats.NbStdPages;
          global_buddy_stat.NbStdUsed += workers_data[i].stats.buddy_stats.NbStdUsed;

          if(workers_data[i].stats.buddy_stats.NbStdUsed > global_buddy_stat.WM_NbStdUsed)
            global_buddy_stat.WM_NbStdUsed = workers_data[i].stats.buddy_stats.NbStdUsed;

        }

      /* total memory space preallocated, total space preallocated for pages, total space that overflows pages */
      /* total memory, used memory, avg used memory/worker, max used memory/worker */
      /* total pages, used pages, avg used pages/worker, max used pages/worker */

      fprintf(stats_file, "BUDDY_MEMORY,%s;%lu,%lu,%lu|%lu,%lu,%lu|%u,%u,%u,%u\n",
              strdate,
              (unsigned long)global_buddy_stat.TotalMemSpace,
              (unsigned long)global_buddy_stat.StdMemSpace,
              (unsigned long)global_buddy_stat.ExtraMemSpace,
              (unsigned long)global_buddy_stat.StdUsedSpace,
              (unsigned long)(global_buddy_stat.StdUsedSpace /
                              nfs_param.core_param.nb_worker),
              (unsigned long)global_buddy_stat.WM_StdUsedSpace,
              global_buddy_stat.NbStdPages, global_buddy_stat.NbStdUsed,
              global_buddy_stat.NbStdUsed / nfs_param.core_param.nb_worker,
              global_buddy_stat.WM_NbStdUsed);

#endif

      /* Flush the data written */
      fprintf(stats_file, "END, ----- NO MORE STATS FOR THIS PASS ----\n");
      fflush(stats_file);

      /* Now managed IP stats dump */
      nfs_ip_stats_dump(ht_ip_stats,
                        nfs_param.core_param.nb_worker,
                        nfs_param.core_param.stats_per_client_directory);

    }                           /* while ( 1 ) */

  return NULL;
}                               /* stats_thread */
示例#21
0
void *reaper_thread(void *unused)
{
        hash_table_t *ht = ht_client_id;
        struct rbt_head *head_rbt;
        hash_data_t *pdata = NULL;
        int i, v4;
        struct rbt_node *pn;
        nfs_client_id_t *clientp;

#ifndef _NO_BUDDY_SYSTEM
        if((i = BuddyInit(&nfs_param.buddy_param_admin)) != BUDDY_SUCCESS) {
        /* Failed init */
                LogFatal(COMPONENT_MAIN,
                    "Memory manager could not be initialized");
        }
        LogInfo(COMPONENT_MAIN, "Memory manager successfully initialized");
#endif

        SetNameFunction("reaper_thr");

        while(1) {
                /* Initial wait */
                /* TODO: should this be configurable? */
                /* sleep(nfs_param.core_param.reaper_delay); */
                sleep(reaper_delay);
                LogFullDebug(COMPONENT_MAIN,
                    "NFS reaper : now checking clients");

                /* For each bucket of the hashtable */
                for(i = 0; i < ht->parameter.index_size; i++) {
                        head_rbt = &(ht->array_rbt[i]);

restart:
                        /* acquire mutex */
                        P_w(&(ht->array_lock[i]));

                        /* go through all entries in the red-black-tree*/
                        RBT_LOOP(head_rbt, pn) {
                                pdata = RBT_OPAQ(pn);

                                clientp =
                                    (nfs_client_id_t *)pdata->buffval.pdata;
                                /*
                                 * little hack: only want to reap v4 clients
                                 * 4.1 initializess this field to '1'
                                 */
                                v4 = (clientp->create_session_sequence == 0);
                                if (clientp->confirmed != EXPIRED_CLIENT_ID &&
                                    nfs4_is_lease_expired(clientp) && v4) {
                                        V_w(&(ht->array_lock[i]));
                                        LogDebug(COMPONENT_MAIN,
                                            "NFS reaper: expire client %s",
                                            clientp->client_name);
                                        nfs_client_id_expire(clientp);
                                        goto restart;
                                }

                                if (clientp->confirmed == EXPIRED_CLIENT_ID) {
                                        LogDebug(COMPONENT_MAIN,
                                            "reaper: client %s already expired",
                                            clientp->client_name);
                                }

                                RBT_INCREMENT(pn);
                        }
                        V_w(&(ht->array_lock[i]));
                }

        }                           /* while ( 1 ) */
示例#22
0
int main(int argc, char **argv)
{
  int rc, i;
  ns_testset_t *p_test;
  char path[FSAL_MAX_PATH_LEN];
  unsigned int gen = 0;
  unsigned int dev = DEV;

  /* Init logging */

  SetNamePgm("test_ns");
  SetDefaultLogging("TEST");
  SetNameFunction("main");
  InitLogging();

  /* namespace init */
  rc = NamespaceInit(ROOT_INODE, DEV, &gen);
  if(rc)
    {
      LogTest("NamespaceInit rc=%d\n", rc);
      exit(1);
    }

  for(i = 0; i < 2; i++)
    {

      /* creation des entrees */
      for(p_test = testset; p_test->name != NULL; p_test++)
        {
          rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name,
                            p_test->entry_inode, DEV, &gen);
          LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode, p_test->name,
                 p_test->entry_inode, rc);
          if(rc)
            exit(1);            /* This is an error */
        }

      /* tentative de recreation */
      for(p_test = testset; p_test->name != NULL; p_test++)
        {
          rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name,
                            p_test->entry_inode, DEV, &gen);
          LogTest("Redundant NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode,
                 p_test->name, p_test->entry_inode, rc);
          if(rc)
            exit(1);            /* This is an error */
        }

      /* recolte du chemin complet de root */

      rc = NamespacePath(ROOT_INODE, DEV, gen, path);
      if(rc)
        {
          LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE, rc);
          exit(1);
        }
      else
        LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE, path);

      /* recolte du chemin complet des entrees */

      for(p_test = testset; p_test->name != NULL; p_test++)
        {
          rc = NamespacePath(p_test->entry_inode, DEV, gen, path);
          if(rc)
            {
              LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc);
              exit(1);
            }
          else
            LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path);
        }

      /* on efface les entrees en ordre inverse */
      for(p_test--; p_test >= testset; p_test--)
        {
          rc = NamespaceRemove(p_test->parent_inode, DEV, gen, p_test->name);
          LogTest("NamespaceRemove(%lu,%s) = %d\n", p_test->parent_inode,
                 p_test->name, rc);
        }

      /* on essaye d'obtenir leur nom */
      for(p_test = testset; p_test->name != NULL; p_test++)
        {
          rc = NamespacePath(p_test->entry_inode, DEV, gen, path);
          if(rc == 0)
            {
              LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path);
              exit(1);
            }
          else if(rc != ENOENT)
            {
              LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc);
              exit(1);
            }
          else
            LogTest("NamespacePath(%lu) rc=%d (ENOENT)\n", p_test->entry_inode, rc);
        }
    }

  /* now create/remove a hardlink to a file N times */

  rc = NamespaceAdd(ROOT_INODE, DEV, gen, "dir", ROOT_INODE + 1, DEV, &gen);
  if(rc)
    {
      LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
      exit(1);
    }

  rc = NamespaceAdd(ROOT_INODE + 1, DEV, gen, "subdir", ROOT_INODE + 2, DEV, &gen);
  if(rc)
    {
      LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
      exit(1);
    }

  rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, "entry", ROOT_INODE + 3, DEV, &gen);
  if(rc)
    {
      LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
      exit(1);
    }

  /* create hardlinks and lookup */
  for(i = 0; i < 3; i++)
    {
      char name[FSAL_MAX_NAME_LEN];

      sprintf(name, "entry.hl%d", i);

      rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, name, ROOT_INODE + 3, DEV, &gen);
      LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", ROOT_INODE + 2, name, ROOT_INODE + 3,
             rc);
      if(rc)
        exit(1);

      rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path);
      if(rc)
        {
          LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc);
          exit(1);
        }
      else
        LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path);

    }

  /* delete hardlinks and lookup */
  for(i = 0; i < 3; i++)
    {
      char name[FSAL_MAX_NAME_LEN];

      sprintf(name, "entry.hl%d", i);

      rc = NamespaceRemove(ROOT_INODE + 2, DEV, gen, name);
      LogTest("NamespaceRemove(%lu,%s) = %d\n", ROOT_INODE + 2, name, rc);
      if(rc)
        exit(1);

      rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path);
      if(rc)
        {
          LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc);
          exit(1);
        }
      else
        LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path);

    }

  return 0;

}
示例#23
0
/**
 * Start snmp thread.
 * @return 0 on success.
 */
int stats_snmp(void)
{
  int rc = 0;

  register_get_set *dyn_gs;
  int dyn_gs_count;

  SetNameFunction("stat_snmp");

  if(!config_ok)
    {
      LogCrit(COMPONENT_INIT,
              "Loading configuration has failed, SNMP_ADM is not activated");
      return 1;
    }

  /* set SNMP admin library's configuration  */
  if((rc = snmp_adm_config_daemon(nfs_param.extern_param.snmp_adm.snmp_agentx_socket,
                                  nfs_param.extern_param.snmp_adm.snmp_log_file,
                                  nfs_param.extern_param.snmp_adm.product_id)))
    {
      LogCrit(COMPONENT_INIT,
              "Error setting SNMP admin interface configuration");
      return 1;
    }

  /* always register general statistics */
  if((rc =
      snmp_adm_register_get_set_function(STAT_OID, snmp_export_stat_general,
                                         SNMPADM_STAT_GENERAL_COUNT)))
    {
      LogCrit(COMPONENT_INIT,
              "Error registering statistic variables to SNMP");
      return 2;
    }

  if(nfs_param.extern_param.snmp_adm.export_cache_stats)
    {
      if((rc =
          snmp_adm_register_get_set_function(STAT_OID, snmp_export_stat_cache,
                                             SNMPADM_STAT_CACHE_COUNT)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering statistic variables to SNMP");
          return 2;
        }
    }

  if(nfs_param.extern_param.snmp_adm.export_requests_stats)
    {
      if((rc =
          snmp_adm_register_get_set_function(STAT_OID, snmp_export_stat_req,
                                             SNMPADM_STAT_REQ_COUNT)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering statistic variables to SNMP");
          return 2;
        }
    }

  if(nfs_param.extern_param.snmp_adm.export_maps_stats)
    {
      if((rc =
          snmp_adm_register_get_set_function(STAT_OID, snmp_export_stat_maps,
                                             SNMPADM_STAT_MAPS_COUNT)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering statistic variables to SNMP");
          return 2;
        }
    }

  if(nfs_param.extern_param.snmp_adm.export_nfs_calls_detail)
    {
      create_dyn_mntv1_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering mntv1 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);

      create_dyn_mntv3_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering mntv3 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);

      create_dyn_nfsv2_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering nfsv2 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);

      create_dyn_nfsv3_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering nfsv3 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);

      create_dyn_nfsv4_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering nfsv4 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);
    }

  if(nfs_param.extern_param.snmp_adm.export_fsal_calls_detail)
    {
      create_dyn_fsal_stat(&dyn_gs, &dyn_gs_count);

      if((rc = snmp_adm_register_get_set_function(STAT_OID, dyn_gs, dyn_gs_count)))
        {
          LogCrit(COMPONENT_INIT,
                  "Error registering nfsv4 statistic variables to SNMP");
          return 2;
        }

      free_dyn(dyn_gs, dyn_gs_count);
    }

  /*
   * Set up logging snmp adm control
   */

  /* always register general logging variables */
  create_dyn_log_control(&dyn_gs, &dyn_gs_count);

  if((rc = snmp_adm_register_get_set_function(LOG_OID, dyn_gs, dyn_gs_count)))
    {
      LogCrit(COMPONENT_INIT,
              "Error registering logging component variables to SNMP");
      return 2;
    }

  free_dyn(dyn_gs, dyn_gs_count);

#ifdef _ERROR_INJECTION
  rc = init_error_injector();
  if(rc != 0)
    return rc;
#endif

  /* finally, start the admin thread */
  if((rc = snmp_adm_start()))
    {
      LogCrit(COMPONENT_INIT,
              "Error starting SNMP administration service");
      return 3;
    }

  return 0;

}
示例#24
0
static void *database_worker_thread(void *arg)
{
	db_thread_info_t *p_info = (db_thread_info_t *) arg;
	int rc;
	db_op_item_t *to_be_done = NULL;
	char thread_name[256];

	/* initialize logging */
	snprintf(thread_name, 256, "DB thread #%u", p_info->thr_index);
	SetNameFunction(thread_name);

	/* initialize memory management */

	rc = init_database_access(p_info);

	if (rc != HANDLEMAP_SUCCESS) {
		/* Failed init */
		LogCrit(COMPONENT_FSAL,
			"ERROR: Database initialization error %d", rc);
		exit(rc);
	}

	/* main loop */
	while (1) {

		/* Is "work done" or "work available" condition verified ? */

		pthread_mutex_lock(&p_info->work_queue.queues_mutex);

		/* nothing to be done ? */
		while (p_info->work_queue.highprio_first == NULL
		       && p_info->work_queue.lowprio_first == NULL) {
			to_be_done = NULL;
			p_info->work_queue.status = IDLE;
			pthread_cond_signal(&p_info->work_queue.
					    work_done_condition);

			/* if termination is requested, exit */
			if (do_terminate) {
				p_info->work_queue.status = FINISHED;
				pthread_mutex_unlock(&p_info->work_queue.queues_mutex);
				return (void *)p_info;
			}

			/* else, wait for something to do */
			pthread_cond_wait(&p_info->work_queue.
					  work_avail_condition,
					  &p_info->work_queue.queues_mutex);

		}

		/* there is something to do:
		 * first check the highest priority list,
		 * then the lower priority.
		 */

		if (p_info->work_queue.highprio_first != NULL) {
			/* take the next item in the list */
			to_be_done = p_info->work_queue.highprio_first;
			p_info->work_queue.highprio_first = to_be_done->p_next;

			/* still any entries in the list ? */
			if (p_info->work_queue.highprio_first == NULL)
				p_info->work_queue.highprio_last = NULL;
			/* it it the last entry ? */
			else if (p_info->work_queue.highprio_first->p_next ==
				 NULL)
				p_info->work_queue.highprio_last =
				    p_info->work_queue.highprio_first;

			/* something to do */
			p_info->work_queue.status = WORKING;
		} else if (p_info->work_queue.lowprio_first != NULL) {
			/* take the next item in the list */
			to_be_done = p_info->work_queue.lowprio_first;
			p_info->work_queue.lowprio_first = to_be_done->p_next;

			/* still any entries in the list ? */
			if (p_info->work_queue.lowprio_first == NULL)
				p_info->work_queue.lowprio_last = NULL;
			/* it it the last entry ? */
			else if (p_info->work_queue.lowprio_first->p_next ==
				 NULL)
				p_info->work_queue.lowprio_last =
				    p_info->work_queue.lowprio_first;

			/* something to do */
			p_info->work_queue.status = WORKING;
		}

		p_info->work_queue.nb_waiting--;

		pthread_mutex_unlock(&p_info->work_queue.queues_mutex);

		/* PROCESS THE REQUEST */

		switch (to_be_done->op_type) {
		case LOAD:
			db_load_operation(p_info, to_be_done->op_arg.hash);
			break;

		case INSERT:
			db_insert_operation(p_info,
					    &to_be_done->op_arg.fh_info);
			break;

		case DELETE:
			db_delete_operation(p_info,
					    &to_be_done->op_arg.fh_info.
					    nfs23_digest);
			break;

		default:
			LogCrit(COMPONENT_FSAL,
				"ERROR: Invalid operation type %d",
				to_be_done->op_type);
		}

		/* free the db operation item */
		pthread_mutex_lock(&p_info->pool_mutex);
		pool_free(p_info->dbop_pool, to_be_done);
		pthread_mutex_unlock(&p_info->pool_mutex);

	}			/* loop forever */

	return (void *)p_info;
}
示例#25
0
int main(int argc, char **argv)
{

  char localmachine[256];
  char *test;
  fsal_parameter_t init_param;
  fsal_status_t st;
  uid_t uid;
  fsal_export_context_t export_ctx;
  fsal_op_context_t op_ctx;
  fsal_handle_t root_handle, handle;
  fsal_name_t name;
  fsal_path_t path;
  fsal_attrib_list_t attribs;
  fsal_attrib_mask_t mask;

  char tracebuff[256];

  if(argc < 2)
    {
      usage();
      exit(-1);
    }
  test = argv[1];
  /* retrieving params */

#ifndef _NO_BUDDY_SYSTEM
  BuddyInit(NULL);
#endif

  /* init debug */

  SetNamePgm("test_fsal");
  SetDefaultLogging("TEST");
  SetNameFunction("main");
  InitLogging();

  /* Obtention du nom de la machine */
  if(gethostname(localmachine, sizeof(localmachine)) != 0)
    {
      LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno);
      exit(1);
    }
  else
    SetNameHost(localmachine);

  AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL);

  /* prepare fsal_init */

  /* 1 - fs specific info */

#ifdef _USE_HPSS_51

  init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE;
  strcpy(init_param.fs_specific_info.hpss_config.PrincipalName, "hpss_nfs");

  init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE;
  strcpy(init_param.fs_specific_info.hpss_config.KeytabPath, "/krb5/hpssserver.keytab");

#elif defined _USE_HPSS_62
  init_param.fs_specific_info.behaviors.AuthnMech = FSAL_INIT_FORCE_VALUE;
  init_param.fs_specific_info.hpss_config.AuthnMech = hpss_authn_mech_krb5;

  init_param.fs_specific_info.behaviors.Principal = FSAL_INIT_FORCE_VALUE;
  strcpy(init_param.fs_specific_info.Principal, "hpssfs");

  init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE;
  strcpy(init_param.fs_specific_info.KeytabPath, "/var/hpss/etc/hpss.keytab");

#endif

  /* 2-common info (default) */
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, supported_attrs);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, umask);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, auth_exportpath_xdev);

  /* 3- fsal info */
  init_param.fsal_info.max_fs_calls = 0;

  /* Init */
  if(FSAL_IS_ERROR(st = FSAL_Init(&init_param)))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
    }

  /* getting creds */
  uid = getuid();
  LogTest("uid = %d", uid);

  st = FSAL_BuildExportContext(&export_ctx, NULL, NULL);
  if(FSAL_IS_ERROR(st))
    LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);

  st = FSAL_InitClientContext(&op_ctx);

  if(FSAL_IS_ERROR(st))
    LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);

  st = FSAL_GetClientContext(&op_ctx, &export_ctx, uid, -1, NULL, 0);

  if(FSAL_IS_ERROR(st))
    LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);

  /* getting root handle */

  if(FSAL_IS_ERROR(st = FSAL_lookup(NULL, NULL, &op_ctx, &root_handle, NULL)))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
    }

  snprintHandle(tracebuff, 256, &root_handle);
  LogTest("Root handle = %s", tracebuff);

  /* getting what are the supported attributes */

  attribs.asked_attributes = 0;
  FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR);
  LogTest("asked attributes :");
  printmask(attribs.asked_attributes);

  if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs)))
    {
      LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
    }

  LogTest("supported attributes :");
  printmask(attribs.supported_attributes);

  mask = attribs.supported_attributes;

/* TEST 1 */

  if(test[0] == '1')
    {

      attribs.asked_attributes = 0;
      FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR);
      LogTest("asked attributes :");
      printmask(attribs.asked_attributes);

      if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      LogTest("supported attributes :");

      /* getting all spported attributes of root */
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      printattributes(attribs);

    }
  else
/* TEST 2 */
  if(test[0] == '2')
    {

      /* getting handle and attributes for subdirectory "OSF1_V5" */
      if(FSAL_IS_ERROR(st = FSAL_str2name("cea", 4, &name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea handle = %s", tracebuff);

      /* displaying attributes */
      printattributes(attribs);

      /* getting handle and attributes for subdirectory "bin" */
      if(FSAL_IS_ERROR(st = FSAL_str2name("prot", 5, &name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      root_handle = handle;
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot handle = %s", tracebuff);

      /* displaying attributes */
      printattributes(attribs);

      /* getting handle and attributes for symlink "AglaePwrSW" */
      if(FSAL_IS_ERROR(st = FSAL_str2name("lama", 5, &name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      root_handle = handle;
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot/lama handle = %s", tracebuff);

      /* displaying attributes */
      printattributes(attribs);

    }
  else
/* TEST 3 */
  if(test[0] == '3')
    {

      /* lookup root */
      if(FSAL_IS_ERROR(st = FSAL_str2path("/", 30, &path)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/ handle = %s", tracebuff);

      /* displaying attributes */
      printattributes(attribs);

      /* lookup path */
      if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/lama", 15, &path)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot/lama handle = %s", tracebuff);

      /* displaying attributes */
      printattributes(attribs);

    }
  else
/* TEST 4 */
  if(test[0] == '4')
    {

      /* readdir on root */
      fsal_dir_t dir;
      fsal_cookie_t from, to;
      fsal_dirent_t entries[READDIR_SIZE];
      fsal_count_t number;
      fsal_boolean_t eod = FALSE;
      int error = FALSE;

      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      LogTest("'/' attributes :");

      /* displaying attributes */
      printattributes(attribs);

      from = FSAL_READDIR_FROM_BEGINNING;

      while(!error && !eod)
        {
          unsigned int i;
          char cookiebuff[256];

          snprintCookie(cookiebuff, 256, &from);
          LogTest("\nReaddir cookie = %s", cookiebuff);
          if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from,
                                             mask, READDIR_SIZE * sizeof(fsal_dirent_t),
                                             entries, &to, &number, &eod)))
            {
              LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
              error = TRUE;
            }

          for(i = 0; (!error) && (i < number); i++)
            {

              snprintHandle(tracebuff, 256, &entries[i].handle);

              snprintCookie(cookiebuff, 256, &entries[i].cookie);

              LogTest("\t%s : %s (cookie %s)", tracebuff,
                     entries[i].name.name, cookiebuff);
            }
          /* preparing next call */
          from = to;

        }
      LogTest("Fin de boucle : error=%d ; eod=%d", error, eod);

    }
  else
/* TEST 5 */
  if(test[0] == '5')
    {

      /* readdir on root */
      fsal_dir_t dir;
      fsal_cookie_t from, to;
      fsal_dirent_t entries[READDIR_SIZE];
      fsal_count_t number;
      fsal_boolean_t eod = FALSE;
      int error = FALSE;

      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      LogTest("'/' attributes :");

      /* displaying attributes */
      printattributes(attribs);

      from = FSAL_READDIR_FROM_BEGINNING;

      while(!error && !eod)
        {
          fsal_dirent_t *curr;

          char cookiebuff[256];

          snprintCookie(cookiebuff, 256, &from);

          LogTest("\nReaddir cookie = %s", cookiebuff);

          if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from,
                                             mask, READDIR_SIZE * sizeof(fsal_dirent_t),
                                             entries, &to, &number, &eod)))
            {
              LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
              error = TRUE;
            }

          if(number > 0)
            {
              curr = entries;
              do
                {

                  snprintHandle(tracebuff, 256, &curr->handle);
                  snprintCookie(cookiebuff, 256, &curr->cookie);

                  LogTest("\t%s : %s (cookie %s)", tracebuff,
                         curr->name.name, cookiebuff);
                }
              while(curr = curr->nextentry);
            }
          /* preparing next call */
          from = to;

        }
      LogTest("Fin de boucle : error=%d ; eod=%d", error, eod);

    }
  else
/* TEST 6 */
  if(test[0] == '6')
    {

      /* readdir on root */
      fsal_dir_t dir;
      fsal_cookie_t from, to;
      fsal_dirent_t entries[READDIR_SIZE];
      fsal_count_t number;
      fsal_boolean_t eod = FALSE;
      int error = FALSE;

      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      LogTest("'/' attributes :");

      /* displaying attributes */
      printattributes(attribs);

      from = FSAL_READDIR_FROM_BEGINNING;

      while(!error && !eod)
        {
          unsigned int i;

          snprintCookie(tracebuff, 256, &from);
          LogTest("\nReaddir cookie = %s", tracebuff);

          st = FSAL_readdir(&dir, from, mask,
                            READDIR_SIZE * sizeof(fsal_dirent_t),
                            entries, &to, &number, &eod);

          if(FSAL_IS_ERROR(st))
            {
              LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
              error = TRUE;
            }

          /* for each entry, we compare the result of FSAL_access
           * to FSAL_test_access. */
          for(i = 0; (!error) && (i < number); i++)
            {

              fsal_status_t st1, st2;
              char cookiebuff[256];

              snprintHandle(tracebuff, 256, &entries[i].handle);
              snprintCookie(cookiebuff, 256, &entries[i].cookie);

              LogTest("\t%s : %s (cookie %s)", tracebuff,
                     entries[i].name.name, cookiebuff);

              if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&entries[i].handle, &op_ctx, &attribs)))
                {
                  LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
                }

              /* 1 - test R access */

              st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_R_OK, NULL);

              st2 = FSAL_test_access(&op_ctx, FSAL_R_OK, &attribs);

              LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor);
              LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor);

              if(st1.major != st2.major)
                {
                  LogTest
                      ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d",
                       st1.major, st2.major);
                }

              /* 2 - test W access */

              st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_W_OK, NULL);

              st2 = FSAL_test_access(&op_ctx, FSAL_W_OK, &attribs);

              LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor);
              LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor);

              if(st1.major != st2.major)
                {
                  LogTest
                      ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d",
                       st1.major, st2.major);
                }

              /* 3 - test X access */

              st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_X_OK, NULL);

              st2 = FSAL_test_access(&op_ctx, FSAL_X_OK, &attribs);

              LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor);
              LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor);

              if(st1.major != st2.major)
                {
                  LogTest
                      ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d",
                       st1.major, st2.major);
                }

            }

          /* preparing next call */
          from = to;

        }
      LogTest("Fin de boucle : error=%d ; eod=%d", error, eod);

    }
  else
/* TEST 7 */
  if(test[0] == '7')
    {

      /* test snprintmem and sscanmem */
      char test_string[] =
          "Ceci est une chaine d'essai.\nLes chiffres : 0123456789\nLes lettres : ABCDEFGHIJKLMNOPQRSTUVWXYZ";

      char buffer[256];
      char string[200];         /* 200 suffit car test_string fait <100 */

      int size1, size2, size3, i;

      /* we put bad values in string, to see if it is correctly set. */
      for(i = 0; i < 200; i++)
        string[i] = (char)i;

      LogTest("Initial data (%d Bytes) = <<%s>>", strlen(test_string), test_string);

      /* Write test_string to a buffer. */
      /* We don't give the final '\0'.  */
      snprintmem(buffer, 256, test_string, strlen(test_string));

      LogTest("Dest_Buffer (%d Bytes) = <<%s>>", strlen(buffer), buffer);

      /* read the value from the buffer */
      sscanmem(string, strlen(test_string), buffer);

      /* sets the final 0 to print the content of the buffer */
      LogTest("Retrieved string : following byte = %d",
             (int)string[strlen(test_string)]);
      string[strlen(test_string)] = '\0';

      LogTest("Retrieved string (%d Bytes) = <<%s>>", strlen(string), string);

      /* Automatic tests : */
      size1 = strlen(test_string);
      size2 = strlen(buffer);
      size3 = strlen(string);

      LogTest("-------------------------------------");

      if(size1 <= 0)
        LogTest("***** ERROR: source size=0 !!!");

      if(size1 != size3)
        LogTest("***** ERROR: source size <> target size");
      else
        LogTest("OK: source size = target size");

      if((size1 * 2) != size2)
        LogTest("***** ERROR: hexa size <> 2 * source size");
      else
        LogTest("OK: hexa size = 2 * source size");

      if(strcmp(test_string, string))
        LogTest("***** ERROR: source string <> target string");
      else
        LogTest("OK: source string = target string");

    }
  else
/* TEST 8 */
  if(test[0] == '8')
    {

      fsal_handle_t dir_hdl, subdir_hdl;
      fsal_name_t subdir_name;

      /* lookup on /cea/prot/S/lama/s8/leibovic */

      if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff);

      sleep(1);

      /* creates a directory */
      LogTest("------- Create a directory -------");

      if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA", 30, &name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      attribs.asked_attributes = mask;

      if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx,
                                       FSAL_MODE_RUSR | FSAL_MODE_WUSR
                                       | FSAL_MODE_XUSR | FSAL_MODE_RGRP
                                       | FSAL_MODE_WGRP, &dir_hdl, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          snprintHandle(tracebuff, 256, &dir_hdl);
          LogTest("newly created dir handle = %s", tracebuff);

          printattributes(attribs);

        }

      sleep(1);

      /* Try to create it again */
      LogTest("------- Try to create it again -------");

      if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx,
                                       FSAL_MODE_RUSR | FSAL_MODE_WUSR
                                       | FSAL_MODE_XUSR | FSAL_MODE_RGRP
                                       | FSAL_MODE_WGRP, &dir_hdl, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          LogTest("**** Error: FSAL should have returned ERR_FSAL_EXIST");

        }

      sleep(1);

      /* creates a subdirectory */
      LogTest("------- Create a subdirectory -------");

      if(FSAL_IS_ERROR(st = FSAL_str2name("subdir_GANESHA", 30, &subdir_name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      if(FSAL_IS_ERROR(st = FSAL_mkdir(&dir_hdl, &subdir_name, &op_ctx,
                                       FSAL_MODE_RUSR | FSAL_MODE_WUSR
                                       | FSAL_MODE_XUSR | FSAL_MODE_RGRP
                                       | FSAL_MODE_WGRP, &subdir_hdl, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          snprintHandle(tracebuff, 256, &subdir_hdl);
          LogTest("newly created subdir handle = %s", tracebuff);

          printattributes(attribs);

        }

      /* try to removes the parent directory */
      LogTest("------- Try to removes the parent directory -------");

      if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          LogTest("FSAL should not have unlinked %s because it is not empty", name.name);

        }

      sleep(1);

      /* removes the subdirectory */
      LogTest("------- Removes the subdirectory -------");

      if(FSAL_IS_ERROR(st = FSAL_unlink(&dir_hdl, &subdir_name, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          LogTest("New attributes for parent directory:");
          printattributes(attribs);

        }

      /* removes the parent directory */
      LogTest("------- Removes the parent directory -------");

      if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          LogTest("Unlink %s OK", name.name);

        }

    }
/* TEST 9 */
  else if(test[0] == '9')
    {

      fsal_handle_t dir_hdl, subdir_hdl;
      fsal_name_t subdir_name;
      fsal_attrib_list_t attr_set;

      fsal_fsid_t set_fsid = { 1LL, 2LL };

#ifdef _LINUX
      struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0, 0, 0 };
#else
      struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0 };
#endif

      /* lookup on /cea/prot/S/lama/s8/leibovic */

      if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff);

      sleep(1);

      /* creates a file */
      LogTest("------- Create a file -------");

      if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA_setattrs", 30, &name)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      attribs.asked_attributes = mask;

      if(FSAL_IS_ERROR(st = FSAL_create(&handle, &name, &op_ctx,
                                        FSAL_MODE_RUSR | FSAL_MODE_WUSR
                                        | FSAL_MODE_XUSR | FSAL_MODE_RGRP
                                        | FSAL_MODE_WGRP, &dir_hdl, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          snprintHandle(tracebuff, 256, &dir_hdl);
          LogTest("newly created file handle = %s", tracebuff);

          printattributes(attribs);

        }

      sleep(1);

      LogTest("------- Try to change its attributes -------");

      /* Macro that try to change the value for an attribute */

#define CHANGE_ATTRS( str_nom, nom, flag, new_val ) do {\
  memset(&attr_set, 0, sizeof(fsal_attrib_list_t) );    \
  LogTest("\nTry to change '%s' :",str_nom);           \
  FSAL_SET_MASK( attr_set.asked_attributes , flag );    \
  attr_set.nom = new_val;                               \
  attribs.asked_attributes = attr_set.asked_attributes; \
/*  attribs.asked_attributes = mask;                      */\
  st = FSAL_setattrs( &dir_hdl, &op_ctx, &attr_set, &attribs );\
  if ( FSAL_IS_ERROR(st) )                              \
    LogError(COMPONENT_STDOUT,ERR_FSAL,st.major,st.minor);\
  else                                                  \
    printattributes( attribs );                         \
  } while(0)

      CHANGE_ATTRS("supported_attributes", supported_attributes,
                   FSAL_ATTR_SUPPATTR, FSAL_ATTRS_MANDATORY);

      CHANGE_ATTRS("type", type, FSAL_ATTR_TYPE, FSAL_TYPE_LNK);

      sleep(1);                 /* to see mtime modification by truncate */

      CHANGE_ATTRS("filesize", filesize, FSAL_ATTR_SIZE, (fsal_size_t) 12);

      sleep(1);                 /* to see mtime modification by truncate */

      CHANGE_ATTRS("fsid", fsid, FSAL_ATTR_FSID, set_fsid);

      /* @todo : ACLs */

      CHANGE_ATTRS("fileid", fileid, FSAL_ATTR_FILEID, (fsal_u64_t) 1234);

      CHANGE_ATTRS("mode", mode, FSAL_ATTR_MODE,
                   (FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_RGRP));

      CHANGE_ATTRS("numlinks", numlinks, FSAL_ATTR_NUMLINKS, 7);

      /* FSAL_ATTR_RAWDEV */

      CHANGE_ATTRS("atime", atime.seconds, FSAL_ATTR_ATIME, mktime(&jour_heure));

      jour_heure.tm_min++;

      CHANGE_ATTRS("creation", creation.seconds, FSAL_ATTR_CREATION, mktime(&jour_heure));

      jour_heure.tm_min++;

      CHANGE_ATTRS("mtime", mtime.seconds, FSAL_ATTR_MTIME, mktime(&jour_heure));

      jour_heure.tm_min++;

      CHANGE_ATTRS("ctime", ctime.seconds, FSAL_ATTR_CTIME, mktime(&jour_heure));

      CHANGE_ATTRS("spaceused", spaceused, FSAL_ATTR_SPACEUSED, (fsal_size_t) 12345);

      CHANGE_ATTRS("mounted_on_fileid", mounted_on_fileid,
                   FSAL_ATTR_MOUNTFILEID, (fsal_u64_t) 3210);

      CHANGE_ATTRS("owner", owner, FSAL_ATTR_OWNER, 3051);      /* deniel */

      CHANGE_ATTRS("group", group, FSAL_ATTR_GROUP, 5953);      /* sr */

      sleep(1);

      /* removes the parent directory */
      LogTest("------- Removes the directory -------");

      if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {

          LogTest("Unlink %s OK", name.name);

        }

    }
  else if(test[0] == 'A')
    {

      char digest_buff[FSAL_DIGEST_SIZE_HDLV3];

      /* lookup on /cea/prot/S/lama/s8/leibovic */

      if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      attribs.asked_attributes = mask;
      if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }

      snprintHandle(tracebuff, 256, &handle);
      LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff);

      /* building digest */

      st = FSAL_DigestHandle(&export_ctx, FSAL_DIGEST_NFSV3, &handle, digest_buff);

      if(FSAL_IS_ERROR(st))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {
          /* print digest */
          snprintmem(tracebuff, 256, digest_buff, FSAL_DIGEST_SIZE_HDLV3);
          LogTest("/cea/prot/S/lama/s8/leibovic: handle_digest = %s", tracebuff);
        }

      memset(&handle, 0, sizeof(fsal_handle_t));

      /* expend digest */

      st = FSAL_ExpandHandle(&export_ctx, FSAL_DIGEST_NFSV3, digest_buff, &handle);

      if(FSAL_IS_ERROR(st))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
        }
      else
        {
          /* print expended handle */
          snprintHandle(tracebuff, 256, &handle);
          LogTest("/cea/prot/S/lama/s8/leibovic: handle expended = %s", tracebuff);
        }

    }
  else if(test[0] == 'B')
    {

      fsal_dynamicfsinfo_t dyninfo;

      if(FSAL_IS_ERROR(st = FSAL_dynamic_fsinfo(&root_handle, &op_ctx, &dyninfo)))
        {
          LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor);
          exit(st.major);
        }

      LogTest("total_bytes = %llu", dyninfo.total_bytes);
      LogTest("free_bytes = %llu", dyninfo.free_bytes);
      LogTest("avail_bytes = %llu", dyninfo.avail_bytes);
      LogTest("total_files = %llu", dyninfo.total_files);
      LogTest("free_files = %llu", dyninfo.free_files);
      LogTest("avail_files = %llu", dyninfo.avail_files);
      LogTest("time_delta = %u.%u", dyninfo.time_delta.seconds,
             dyninfo.time_delta.nseconds);

    }
  else
    LogTest("%s : test inconnu", test);

  return 0;

}
void *stat_exporter_thread(void *addr)
{
    int sockfd, new_fd;
    struct addrinfo hints, *servinfo, *p;
    struct sockaddr_storage their_addr;
    socklen_t sin_size;
    int yes = 1;
    char s[INET6_ADDRSTRLEN];
    int rc;
    exportlist_client_entry_t pclient_found;

    SetNameFunction("statistics_exporter");

    memset(&hints, 0, sizeof hints);

#ifndef _USE_TIRPC_IPV6
    hints.ai_family = AF_INET;
#else
    hints.ai_family = AF_INET6;
#endif
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;

    if((rc = getaddrinfo(NULL, nfs_param.extern_param.stat_export.export_stat_port, &hints, &servinfo)) != 0)
    {
        LogCrit(COMPONENT_MAIN, "getaddrinfo: %s", gai_strerror(rc));
        return NULL;
    }
    for(p = servinfo; p != NULL; p = p->ai_next)
    {
        if((sockfd = socket(p->ai_family, p->ai_socktype,
                            p->ai_protocol)) == -1)
        {
            LogError(COMPONENT_MAIN, ERR_SYS, errno, sockfd);
            continue;
        }

        if((rc = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes,
                            sizeof(int))) == -1)
        {
            LogError(COMPONENT_MAIN, ERR_SYS, errno, rc);
            return NULL;
        }

        if((rc = bind(sockfd, p->ai_addr, p->ai_addrlen)) == -1)
        {
            close(sockfd);
            LogError(COMPONENT_MAIN, ERR_SYS, errno, rc);
            continue;
        }

        break;
    }

    if(p == NULL)
    {
        LogCrit(COMPONENT_MAIN, "server: failed to bind");
        return NULL;
    }

    freeaddrinfo(servinfo);
    if((rc = listen(sockfd, BACKLOG)) == -1)
    {
        LogError(COMPONENT_MAIN, ERR_SYS, errno, rc);
        return NULL;
    }
    LogInfo(COMPONENT_MAIN, "Stat export server: Waiting for connections...");

    while(1)
    {
        sin_size = sizeof their_addr;
        new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
        if(new_fd == -1)
        {
            LogError(COMPONENT_MAIN, ERR_SYS, errno, new_fd);
            continue;
        }

        sprint_sockip((sockaddr_t *)&their_addr, s, sizeof s);

        if (stat_export_check_access(&their_addr,
                                     &(nfs_param.extern_param.stat_export.allowed_clients),
                                     &pclient_found)) {
            LogDebug(COMPONENT_MAIN, "Stat export server: Access granted to %s", s);
            process_stat_request(addr, new_fd);
        } else {
            LogWarn(COMPONENT_MAIN, "Stat export server: Access denied to %s", s);
        }
    }                           /* while ( 1 ) */

    return NULL;
}                               /* stat_exporter_thread */
示例#27
0
/**
 * @brief Up Thread
 *
 * @param Arg reference to void
 *
 */
void *GPFSFSAL_UP_Thread(void *Arg)
{
	struct gpfs_filesystem *gpfs_fs = Arg;
	struct fsal_up_vector *event_func;
	char thr_name[16];
	int rc = 0;
	struct pnfs_deviceid devid;
	struct stat buf;
	struct glock fl;
	struct callback_arg callback;
	struct gpfs_file_handle handle;
	int reason = 0;
	int flags = 0;
	unsigned int *fhP;
	int retry = 0;
	struct gsh_buffdesc key;
	uint32_t expire_time_attr = 0;
	uint32_t upflags;
	int errsv = 0;
	fsal_status_t fsal_status = {0,};

#ifdef _VALGRIND_MEMCHECK
		memset(&handle, 0, sizeof(handle));
		memset(&buf, 0, sizeof(buf));
		memset(&fl, 0, sizeof(fl));
		memset(&devid, 0, sizeof(devid));
#endif

	snprintf(thr_name, sizeof(thr_name),
		 "fsal_up_%"PRIu64".%"PRIu64,
		 gpfs_fs->fs->dev.major, gpfs_fs->fs->dev.minor);
	SetNameFunction(thr_name);

	LogFullDebug(COMPONENT_FSAL_UP,
		     "Initializing FSAL Callback context for %d.",
		     gpfs_fs->root_fd);

	/* wait for nfs init completion to get general_fridge
	 * initialized which is needed for processing some upcall events
	 */
	nfs_init_wait();

	/* Start querying for events and processing. */
	while (1) {
		LogFullDebug(COMPONENT_FSAL_UP,
			     "Requesting event from FSAL Callback interface for %d.",
			     gpfs_fs->root_fd);

		handle.handle_size = GPFS_MAX_FH_SIZE;
		handle.handle_key_size = OPENHANDLE_KEY_LEN;
		handle.handle_version = OPENHANDLE_VERSION;

		callback.interface_version =
		    GPFS_INTERFACE_VERSION + GPFS_INTERFACE_SUB_VER;

		callback.mountdirfd = gpfs_fs->root_fd;
		callback.handle = &handle;
		callback.reason = &reason;
		callback.flags = &flags;
		callback.buf = &buf;
		callback.fl = &fl;
		callback.dev_id = &devid;
		callback.expire_attr = &expire_time_attr;

		rc = gpfs_ganesha(OPENHANDLE_INODE_UPDATE, &callback);
		errsv = errno;

		if (rc != 0) {
			rc = -(rc);
			if (rc > GPFS_INTERFACE_VERSION) {
				LogFatal(COMPONENT_FSAL_UP,
					 "Ganesha version %d mismatch GPFS version %d.",
					 callback.interface_version, rc);
				return NULL;
			}

			if (errsv == EINTR)
				continue;

			LogCrit(COMPONENT_FSAL_UP,
				"OPENHANDLE_INODE_UPDATE failed for %d. rc %d, errno %d (%s) reason %d",
				gpfs_fs->root_fd, rc, errsv,
				strerror(errsv), reason);

			/* @todo 1000 retry logic will go away once the
			 * OPENHANDLE_INODE_UPDATE ioctl separates EINTR
			 * and EUNATCH.
			 */
			if (errsv == EUNATCH && ++retry > 1000)
				LogFatal(COMPONENT_FSAL_UP,
					 "GPFS file system %d has gone away.",
					 gpfs_fs->root_fd);

			continue;
		}

		retry = 0;

		/* flags is int, but only the least significant 2 bytes
		 * are valid.  We are getting random bits into the upper
		 * 2 bytes! Workaround this until the kernel module
		 * gets fixed.
		 */
		flags = flags & 0xffff;

		LogDebug(COMPONENT_FSAL_UP,
			 "inode update: rc %d reason %d update ino %"
			 PRId64 " flags:%x",
			 rc, reason, callback.buf->st_ino, flags);

		LogFullDebug(COMPONENT_FSAL_UP,
			     "inode update: flags:%x callback.handle:%p handle size = %u handle_type:%d handle_version:%d key_size = %u handle_fsid=%X.%X f_handle:%p expire: %d",
			     *callback.flags, callback.handle,
			     callback.handle->handle_size,
			     callback.handle->handle_type,
			     callback.handle->handle_version,
			     callback.handle->handle_key_size,
			     callback.handle->handle_fsid[0],
			     callback.handle->handle_fsid[1],
			     callback.handle->f_handle, expire_time_attr);

		callback.handle->handle_version = OPENHANDLE_VERSION;

		fhP = (int *)&(callback.handle->f_handle[0]);
		LogFullDebug(COMPONENT_FSAL_UP,
			     " inode update: handle %08x %08x %08x %08x %08x %08x %08x",
			     fhP[0], fhP[1], fhP[2], fhP[3], fhP[4], fhP[5],
			     fhP[6]);

		/* Here is where we decide what type of event this is
		 * ... open,close,read,...,invalidate? */
		key.addr = &handle;
		key.len = handle.handle_key_size;

		LogDebug(COMPONENT_FSAL_UP, "Received event to process for %d",
			 gpfs_fs->root_fd);

		/* We need valid up_vector while processing some of the
		 * events below. Setup up vector and hold the mutex while
		 * processing the event for the entire duration.
		 */
		PTHREAD_MUTEX_lock(&gpfs_fs->upvector_mutex);
		if (!setup_up_vector(gpfs_fs)) {
			PTHREAD_MUTEX_unlock(&gpfs_fs->upvector_mutex);
			return NULL;
		}
		event_func = gpfs_fs->up_vector;

		switch (reason) {
		case INODE_LOCK_GRANTED:	/* Lock Event */
		case INODE_LOCK_AGAIN:	/* Lock Event */
			{
				LogMidDebug(COMPONENT_FSAL_UP,
					    "%s: owner %p pid %d type %d start %lld len %lld",
					    reason ==
					    INODE_LOCK_GRANTED ?
					    "inode lock granted" :
					    "inode lock again", fl.lock_owner,
					    fl.flock.l_pid, fl.flock.l_type,
					    (long long)fl.flock.l_start,
					    (long long)fl.flock.l_len);

				fsal_lock_param_t lockdesc = {
					.lock_sle_type = FSAL_POSIX_LOCK,
					.lock_type = fl.flock.l_type,
					.lock_start = fl.flock.l_start,
					.lock_length = fl.flock.l_len
				};
				if (reason == INODE_LOCK_AGAIN)
					fsal_status = up_async_lock_avail(
							 general_fridge,
							 event_func,
							 &key,
							 fl.lock_owner,
							 &lockdesc, NULL, NULL);
				else
					fsal_status = up_async_lock_grant(
							 general_fridge,
							 event_func,
							 &key,
							 fl.lock_owner,
							 &lockdesc, NULL, NULL);
			}
			break;

		case BREAK_DELEGATION:	/* Delegation Event */
			LogDebug(COMPONENT_FSAL_UP,
				 "delegation recall: flags:%x ino %" PRId64,
				 flags, callback.buf->st_ino);
			fsal_status = up_async_delegrecall(general_fridge,
						  event_func,
						  &key, NULL, NULL);
			break;

		case LAYOUT_FILE_RECALL:	/* Layout file recall Event */
			{
				struct pnfs_segment segment = {
					.offset = 0,
					.length = UINT64_MAX,
					.io_mode = LAYOUTIOMODE4_ANY
				};
				LogDebug(COMPONENT_FSAL_UP,
					 "layout file recall: flags:%x ino %"
					 PRId64, flags, callback.buf->st_ino);

				fsal_status = up_async_layoutrecall(
							general_fridge,
							event_func,
							&key,
							LAYOUT4_NFSV4_1_FILES,
							false, &segment,
							NULL, NULL, NULL,
							NULL);
			}
			break;

		case LAYOUT_RECALL_ANY:	/* Recall all layouts Event */
			LogDebug(COMPONENT_FSAL_UP,
				 "layout recall any: flags:%x ino %" PRId64,
				 flags, callback.buf->st_ino);

	    /**
	     * @todo This functionality needs to be implemented as a
	     * bulk FSID CB_LAYOUTRECALL.  RECALL_ANY isn't suitable
	     * since it can't be restricted to just one FSAL.  Also
	     * an FSID LAYOUTRECALL lets you have multiplke
	     * filesystems exported from one FSAL and not yank layouts
	     * on all of them when you only need to recall them for one.
	     */
			break;

		case LAYOUT_NOTIFY_DEVICEID:	/* Device update Event */
			LogDebug(COMPONENT_FSAL_UP,
				 "layout dev update: flags:%x ino %"
				 PRId64 " seq %d fd %d fsid 0x%" PRIx64,
				 flags,
				callback.buf->st_ino,
				devid.device_id2,
				devid.device_id4,
				devid.devid);

			memset(&devid, 0, sizeof(devid));
			devid.fsal_id = FSAL_ID_GPFS;

			fsal_status = up_async_notify_device(general_fridge,
						event_func,
						NOTIFY_DEVICEID4_DELETE_MASK,
						LAYOUT4_NFSV4_1_FILES,
						&devid,
						true, NULL,
						NULL);
			break;

		case INODE_UPDATE:	/* Update Event */
			{
				struct attrlist attr;

				LogMidDebug(COMPONENT_FSAL_UP,
					    "inode update: flags:%x update ino %"
					    PRId64 " n_link:%d",
					    flags, callback.buf->st_ino,
					    (int)callback.buf->st_nlink);

				/** @todo: This notification is completely
				 * asynchronous.  If we happen to change some
				 * of the attributes later, we end up over
				 * writing those with these possibly stale
				 * values as we don't know when we get to
				 * update with these up call values. We should
				 * probably use time stamp or let the up call
				 * always provide UP_TIMES flag in which case
				 * we can compare the current ctime vs up call
				 * provided ctime before updating the
				 * attributes.
				 *
				 * For now, we think size attribute is more
				 * important than others, so invalidate the
				 * attributes and let ganesha fetch attributes
				 * as needed if this update includes a size
				 * change. We are careless for other attribute
				 * changes, and we may end up with stale values
				 * until this gets fixed!
				 */
				if (flags & (UP_SIZE | UP_SIZE_BIG)) {
					fsal_status = event_func->invalidate(
						event_func, &key,
						FSAL_UP_INVALIDATE_CACHE);
					break;
				}

				/* Check for accepted flags, any other changes
				   just invalidate. */
				if (flags &
				    ~(UP_SIZE | UP_NLINK | UP_MODE | UP_OWN |
				     UP_TIMES | UP_ATIME | UP_SIZE_BIG)) {
					fsal_status = event_func->invalidate(
						event_func, &key,
						FSAL_UP_INVALIDATE_CACHE);
				} else {
					/* buf may not have all attributes set.
					 * Set the mask to what is changed
					 */
					attr.valid_mask = 0;
					attr.acl = NULL;
					upflags = 0;
					if (flags & UP_SIZE)
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_SIZE | ATTR_SPACEUSED;
					if (flags & UP_SIZE_BIG) {
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_SIZE | ATTR_SPACEUSED;
						upflags |=
						   fsal_up_update_filesize_inc |
						   fsal_up_update_spaceused_inc;
					}
					if (flags & UP_MODE)
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_MODE;
					if (flags & UP_OWN)
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_OWNER | ATTR_GROUP |
						   ATTR_MODE;
					if (flags & UP_TIMES)
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_ATIME | ATTR_CTIME |
						    ATTR_MTIME;
					if (flags & UP_ATIME)
						attr.valid_mask |=
						   ATTR_CHGTIME | ATTR_CHANGE |
						   ATTR_ATIME;
					if (flags & UP_NLINK)
						attr.valid_mask |=
							ATTR_NUMLINKS;
					attr.request_mask = attr.valid_mask;

					attr.expire_time_attr =
					    expire_time_attr;

					posix2fsal_attributes(&buf, &attr);
					fsal_status = event_func->update(
							event_func, &key,
							&attr, upflags);

					if ((flags & UP_NLINK)
					    && (attr.numlinks == 0)) {
						upflags = fsal_up_nlink;
						attr.valid_mask = 0;
						attr.request_mask = 0;
						fsal_status = up_async_update
						    (general_fridge,
						     event_func,
						     &key, &attr,
						     upflags, NULL, NULL);
					}
				}
			}
			break;

		case THREAD_STOP:  /* We wanted to terminate this thread */
			LogDebug(COMPONENT_FSAL_UP,
				"Terminating the GPFS up call thread for %d",
				gpfs_fs->root_fd);
			PTHREAD_MUTEX_unlock(&gpfs_fs->upvector_mutex);
			return NULL;

		case INODE_INVALIDATE:
			LogMidDebug(COMPONENT_FSAL_UP,
				    "inode invalidate: flags:%x update ino %"
				    PRId64, flags, callback.buf->st_ino);

			upflags = FSAL_UP_INVALIDATE_CACHE;
			fsal_status = event_func->invalidate_close(
						event_func,
						&key,
						upflags);
			break;

		case THREAD_PAUSE:
			/* File system image is probably going away, but
			 * we don't need to do anything here as we
			 * eventually get other errors that stop this
			 * thread.
			 */
			PTHREAD_MUTEX_unlock(&gpfs_fs->upvector_mutex);
			continue; /* get next event */

		default:
			PTHREAD_MUTEX_unlock(&gpfs_fs->upvector_mutex);
			LogWarn(COMPONENT_FSAL_UP, "Unknown event: %d", reason);
			continue;
		}

		PTHREAD_MUTEX_unlock(&gpfs_fs->upvector_mutex);

		if (FSAL_IS_ERROR(fsal_status) &&
		    fsal_status.major != ERR_FSAL_NOENT) {
			LogWarn(COMPONENT_FSAL_UP,
				"Event %d could not be processed for fd %d rc %s",
				reason, gpfs_fs->root_fd,
				fsal_err_txt(fsal_status));
		}
	}

	return NULL;
}				/* GPFSFSAL_UP_Thread */
示例#28
0
/**
 * _9p_dispatcher_thread: thread used for RPC dispatching.
 *
 * This function is the main loop for the 9p dispatcher.
 * It never returns because it is an infinite loop.
 *
 * @param Arg (unused)
 *
 * @return Pointer to the result (but this function will mostly loop forever).
 *
 */
void *_9p_dispatcher_thread(void *Arg)
{
	int _9p_socket;
	int rc = 0;
	long int newsock = -1;
	pthread_attr_t attr_thr;
	pthread_t tcp_thrid;

	SetNameFunction("_9p_disp");

	/* Calling dispatcher main loop */
	LogInfo(COMPONENT_9P_DISPATCH, "Entering nfs/rpc dispatcher");

	LogDebug(COMPONENT_9P_DISPATCH, "My pthread id is %p",
		 (caddr_t) pthread_self());

	/* Set up the _9p_socket (trying V6 first, will fall back to V4
	 * if V6 fails).
	 */
	_9p_socket = _9p_create_socket_V6();

	if (_9p_socket == -1) {
		LogFatal(COMPONENT_9P_DISPATCH,
			 "Can't get socket for 9p dispatcher");
	}

	/* Init for thread parameter (mostly for scheduling) */
	if (pthread_attr_init(&attr_thr) != 0)
		LogDebug(COMPONENT_9P_DISPATCH,
			 "can't init pthread's attributes");

	if (pthread_attr_setscope(&attr_thr, PTHREAD_SCOPE_SYSTEM) != 0)
		LogDebug(COMPONENT_9P_DISPATCH, "can't set pthread's scope");

	if (pthread_attr_setdetachstate(&attr_thr,
					PTHREAD_CREATE_DETACHED) != 0)
		LogDebug(COMPONENT_9P_DISPATCH,
			 "can't set pthread's join state");

	LogEvent(COMPONENT_9P_DISPATCH, "9P dispatcher started");

	while (true) {
		newsock = accept(_9p_socket, NULL, NULL);

		if (newsock < 0) {
			LogCrit(COMPONENT_9P_DISPATCH, "accept failed: %d",
				errno);
			continue;
		}

		/* Starting the thread dedicated to signal handling */
		rc = pthread_create(&tcp_thrid, &attr_thr,
				    _9p_socket_thread, (void *)newsock);
		if (rc != 0) {
			LogFatal(COMPONENT_THREAD,
				 "Could not create 9p socket manager thread, error = %d (%s)",
				 errno, strerror(errno));
		}
	}			/* while */

	close(_9p_socket);

	return NULL;
}				/* _9p_dispatcher_thread */
示例#29
0
main(int argc, char *argv[])
{
  char localmachine[256];

  cache_inode_client_t client;
  LRU_parameter_t lru_param;
  LRU_status_t lru_status;
  cache_inode_fsal_data_t fsdata;

  fsal_status_t status;
  fsal_parameter_t init_param;
  fsal_name_t name;
  fsal_path_t path;
  fsal_attrib_mask_t mask;
  fsal_path_t pathroot;
  fsal_attrib_list_t attribs;
  fsal_handle_t root_handle;

  cache_inode_endofdir_t eod_met;
  cache_inode_dir_entry_t dirent_array[100];
  cache_inode_dir_entry_t dirent_array_loop[5];
  unsigned int nbfound;

  unsigned int begin_cookie = 0;
  hash_buffer_t key, value;

  uid_t uid;
  fsal_cred_t cred;

  cache_inode_status_t cache_status;
  cache_inode_parameter_t cache_param;
  cache_inode_client_parameter_t cache_client_param;

  hash_table_t *ht = NULL;
  fsal_attrib_list_t attrlookup;
  cache_entry_t *cache_entry_root = NULL;
  cache_entry_t *cache_entry_lookup = NULL;
  cache_entry_t *cache_entry_lookup2 = NULL;
  cache_entry_t *cache_entry_lookup3 = NULL;
  cache_entry_t *cache_entry_lookup4 = NULL;
  cache_entry_t *cache_entry_dircont = NULL;

  cache_inode_gc_policy_t gcpol;

  char *configfile = argv[1];
  int i = 0;
  int rc = 0;

  /* Init the Buddy System allocation */
  if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS)
    {
      LogTest("Error initializing memory allocator");
      exit(1);
    }


  /* init debug */
  SetDefaultLogging("TEST");
  SetNamePgm("test_cache_inode");
  SetNameFunction("main");
  InitLogging();

#if defined( _USE_GHOSTFS )
  if(argc != 2)
    {
      LogTest("Please set the configuration file as parameter");
      exit(1);
    }
#endif

  /* Obtention du nom de la machine */
  if(gethostname(localmachine, sizeof(localmachine)) != 0)
    {
      LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno);
      exit(1);
    }
  else
    SetNameHost(localmachine);

  AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL);
  AddFamilyError(ERR_CACHE_INODE, "FSAL related Errors", tab_errstatus_cache_inode);

  /* creating log */
  LogTest( "Starting the test");
  LogTest( "-----------------");

#if defined( _USE_GHOSTFS )
  if(FSAL_IS_ERROR(status = FSAL_str2path(configfile,
                                          strlen(configfile) + 1,
                                          &(init_param.fs_specific_info.
                                            definition_file))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }
#elif defined( _USE_HPSS )

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, Flags);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugValue);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TransferType);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, NumRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, GKTotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, LimitedRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, MaxConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ReuseDataConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, UsePortRange);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RetryStageInp);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DMAPWriteUpdates);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ServerName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DescName);

  init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.PrincipalName,
          HPSS_SSM, HPSS_MAX_PRINCIPAL_NAME);

  init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.KeytabPath,
          HPSS_KEYTAB, HPSS_MAX_PATH_NAME);

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugPath);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, HostName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RegistrySiteName);

#endif

  /* 2-common info (default) */
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite);

  /* Init */
  if(FSAL_IS_ERROR(status = FSAL_Init(&init_param)))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }

  /* getting creds */
  uid = getuid();

  if(FSAL_IS_ERROR(status = FSAL_GetUserCred(uid, NULL, &cred)))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }

  /* Init of the cache inode module */
  cache_param.hparam.index_size = 31;
  cache_param.hparam.alphabet_length = 10;      /* Buffer seen as a decimal polynom */
  cache_param.hparam.nb_node_prealloc = 100;
  cache_param.hparam.hash_func_key = cache_inode_fsal_hash_func;
  cache_param.hparam.hash_func_rbt = cache_inode_fsal_rbt_func;
  cache_param.hparam.hash_func_both = NULL ; /* BUGAZOMEU */
  cache_param.hparam.compare_key = cache_inode_compare_key_fsal;
  cache_param.hparam.key_to_str = display_key;
  cache_param.hparam.val_to_str = display_value;

  if((ht = cache_inode_init(cache_param, &cache_status)) == NULL)
    {
      LogTest( "Error %d while init hash ", cache_status);
    }
  else
    LogTest( "Hash Table address = %p", ht);

  /* We need a cache_client to acces the cache */
  cache_client_param.attrmask =
      FSAL_ATTRS_MANDATORY | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_ATIME;
  cache_client_param.nb_prealloc_entry = 1000;
  cache_client_param.nb_pre_dir_data = 200;
  cache_client_param.nb_pre_parent = 1200;
  cache_client_param.nb_pre_state_v4 = 100;

  cache_client_param.lru_param.nb_entry_prealloc = 1000;
  cache_client_param.lru_param.entry_to_str = lru_entry_to_str;
  cache_client_param.lru_param.clean_entry = lru_clean_entry;

  cache_client_param.grace_period_attr   = 0;
  cache_client_param.grace_period_link   = 0;
  cache_client_param.grace_period_dirent = 0;
  cache_client_param.expire_type_attr    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_link    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_dirent  = CACHE_INODE_EXPIRE_NEVER;

  /* Init the cache_inode client */
  if(cache_inode_client_init(&client, cache_client_param, 0, NULL) != 0)
    exit(1);

  /* Init the gc */
  gcpol.file_expiration_delay = 3;
  gcpol.directory_expiration_delay = 4;
  gcpol.hwmark_nb_entries = 6;
  gcpol.lwmark_nb_entries = 3;
  gcpol.run_interval = 4;

  cache_inode_set_gc_policy(gcpol);

  /* Getting the root of the FS */
  if((FSAL_IS_ERROR(status = FSAL_str2path("/", 2, &pathroot))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((FSAL_IS_ERROR(status = FSAL_lookupPath(&pathroot, &cred, &root_handle, &attribs))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }
  fsdata.cookie = 0;
  fsdata.handle = root_handle;

  /* Cache the root of the FS */
  if((cache_entry_root =
      cache_inode_make_root(&fsdata, 1, ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't init fs's root");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* Lookup a second time (entry should now be cached) */
  if((cache_entry_lookup2 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup2 != cache_entry_lookup)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup3 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if((cache_entry_lookup4 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup3 != cache_entry_lookup4)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("SunOS_5", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  cache_inode_print_dir(cache_entry_root);

  /* Test readdir */
  if(cache_inode_readdir(cache_entry_root,
                         0,
                         100,
                         &nbfound,
                         &eod_met,
                         dirent_array,
                         ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_readdir failed");
      exit(1);
    }

  LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met);
  for(i = 0; i < nbfound; i++)
    LogTest( "dirent_array[%d] ==> %s | %p", i,
                 dirent_array[i].name.name, dirent_array[i].pentry);

  cache_inode_print_dir(cache_entry_root);

  /* looping on readir */
  LogTest( "Loop directory in several pass");

  eod_met = TO_BE_CONTINUED;
  begin_cookie = 0;

  do
    {

      if(cache_inode_readdir(cache_entry_root,
                             begin_cookie,
                             2,
                             &nbfound,
                             &eod_met,
                             dirent_array_loop,
                             ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
        {
          LogTest("Error: cache_inode_readdir failed: %d", cache_status);
          exit(1);
        }

      for(i = 0; i < nbfound; i++)
        LogTest( " ==> %s | %p", dirent_array_loop[i].name.name,
                     dirent_array_loop[i].pentry);

      begin_cookie += nbfound;

    }
  while(eod_met == TO_BE_CONTINUED);

  LogTest( "---------------------------------");

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }
  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

#ifdef _ADDITIONAL_TEST
  /* Trying to lookup from a DIR_CONTINUE */
  fsdata.handle = cache_entry_root->object.dir_begin.handle;
  fsdata.cookie = 3 * CHILDREN_ARRAY_SIZE;

  LogTest("Input key: (Handle=%p, Cookie=%d)", fsdata.handle, fsdata.cookie);

  /* Turn the input to a hash key */
  if(cache_inode_fsaldata_2_key(&key, &fsdata, NULL))
    {
      LogTest( "Impossible to allocate a key to that value");
      exit(1);
    }

  if(HashTable_Get(ht, &key, &value) != HASHTABLE_SUCCESS)
    {
      LogTest( "Key could not be found");
      exit(1);
    }

  /* pentry for the dir cont */
  cache_entry_dircont = (cache_entry_t *) value.pdata;

  /* Test readdir */
  if(cache_inode_readdir(cache_entry_dircont,
                         fsdata.cookie,
                         100,
                         &nbfound,
                         &eod_met,
                         dirent_array,
                         ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_readdir failed");
      exit(1);
    }
#endif

  LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met);
  for(i = 0; i < nbfound; i++)
    LogTest( "dirent_array[%d] ==> %s | %p ", i,
                 dirent_array[i].name.name, dirent_array[i].pentry);

  /* Call the GC */
  LogTest( "Sleeping %d second before gc (for gc invalidation)",
               gcpol.file_expiration_delay + 2);
  sleep(gcpol.file_expiration_delay + 2);

  if(cache_inode_gc(ht, &client, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_gc failed");
      exit(1);
    }
  LogTest( "GC performed successfully");

  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

  /* Another readdir, after gc is made */
  eod_met = TO_BE_CONTINUED;
  begin_cookie = 0;

  LogTest( "ANOTHER READDIR AFTER GC");

  do
    {

      if(cache_inode_readdir(cache_entry_root,
                             begin_cookie,
                             2,
                             &nbfound,
                             &eod_met,
                             dirent_array_loop,
                             ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
        {
          LogTest("Error: cache_inode_readdir failed: %d", cache_status);
          exit(1);
        }

      for(i = 0; i < nbfound; i++)
        LogTest( " ==> %s | %p", dirent_array_loop[i].name.name,
                     dirent_array_loop[i].pentry);

      begin_cookie += nbfound;

    }
  while(eod_met == TO_BE_CONTINUED);

  LogTest( "---------------------------------");

  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

  LogTest( "---------------------------------");

  /* The end of all the tests */
  LogTest( "All tests exited successfully");

  exit(0);
}                               /* main */
示例#30
0
void *fsal_up_thread(void *Arg)
{
  fsal_status_t status;
  int rc;
  fsal_up_arg_t *fsal_up_args = (fsal_up_arg_t *)Arg;
  fsal_up_event_bus_context_t fsal_up_context;
  fsal_up_event_bus_parameter_t fsal_up_bus_param;
  fsal_up_event_bus_filter_t * pupebfilter = NULL;
  fsal_up_filter_list_t *filter = NULL;
  fsal_up_event_t *pevent_head, *event, *tmpevent;
  fsal_up_event_functions_t *event_func;
  fsal_count_t nb_events_found, event_nb;
  fsal_time_t timeout;
  char thr_name[40];

  memset(&fsal_up_bus_param, 0, sizeof(fsal_up_event_bus_parameter_t));
  memset(&fsal_up_context, 0, sizeof(fsal_up_event_bus_context_t));

  snprintf(thr_name, sizeof(thr_name), "FSAL UP Thread for filesystem %llu.%llu",
           fsal_up_args->export_entry->filesystem_id.major,
           fsal_up_args->export_entry->filesystem_id.minor);
  SetNameFunction(thr_name);

#ifndef _NO_BUDDY_SYSTEM
  if((rc = BuddyInit(&nfs_param.buddy_param_fsal_up)) != BUDDY_SUCCESS)
    {
      /* Failed init */
      LogFatal(COMPONENT_FSAL_UP,
               "FSAL_UP: Memory manager could not be initialized");
      Fatal();
    }
  LogInfo(COMPONENT_FSAL_UP,
          "FSAL_UP: Memory manager for filesystem %llu.%llu export id %d"
          " successfully initialized",
          fsal_up_args->export_entry->filesystem_id.major,
          fsal_up_args->export_entry->filesystem_id.minor,
          fsal_up_args->export_entry->id);
#endif

  /* Set the FSAL UP functions that will be used to process events. */
  event_func = get_fsal_up_functions(fsal_up_args->export_entry->fsal_up_type);
  if (event_func == NULL)
    {
      LogCrit(COMPONENT_FSAL_UP, "Error: FSAL UP TYPE: %s does not exist. "
              "Exiting FSAL UP thread.", fsal_up_args->export_entry->fsal_up_type);
      Mem_Free(Arg);
      return NULL;
    }

  /* Get fsal up context from FSAL */
  /* It is expected that the export entry and event_pool will be referenced
   * in the returned callback context structure. */
  memcpy(&fsal_up_context.FS_export_context,
         &fsal_up_args->export_entry->FS_export_context,
         sizeof(fsal_export_context_t));

  fsal_up_context.event_pool = &nfs_param.fsal_up_param.event_pool;

  LogDebug(COMPONENT_FSAL_UP, "Initializing FSAL Callback context.");
  status = FSAL_UP_Init(&fsal_up_bus_param, &fsal_up_context);
  if (FSAL_IS_ERROR(status))
    {
      LogCrit(COMPONENT_FSAL_UP, "Error: Could not initialize FSAL UP for"
              " filesystem %llu.%llu export %d. Exiting FSAL UP thread.",
              fsal_up_args->export_entry->filesystem_id.major,
              fsal_up_args->export_entry->filesystem_id.minor,
              fsal_up_args->export_entry->id);
    }

  /* Add filters ... later if needed we could add arguments to filters
   * configurable from configuration files. */
  for(filter = fsal_up_args->export_entry->fsal_up_filter_list;
      filter != NULL; filter = filter->next)
    {
      LogEvent(COMPONENT_FSAL_UP, "Applying filter \"%s\" to FSAL UP thread "
               "for filesystem id %llu.%llu export id %d.", filter->name,
              fsal_up_args->export_entry->filesystem_id.major,
              fsal_up_args->export_entry->filesystem_id.minor,
              fsal_up_args->export_entry->id);

      /* Find predefined filter */
      pupebfilter = find_filter(filter->name);
      if (pupebfilter == NULL)
        {
          LogCrit(COMPONENT_FSAL_UP, "Error: Could not find filter named \"%s\".",
                   filter->name);
        }

      /* Applying filter */
      FSAL_UP_AddFilter(pupebfilter, &fsal_up_context);
    }


  /* Set the timeout for getting events. */
  timeout = fsal_up_args->export_entry->fsal_up_timeout;

  /* Start querying for events and processing. */
  while(1)
    {
      /* pevent is passed in as a single empty node, it's expected the
       * FSAL will use the event_pool in the bus_context to populate
       * this array by adding to the pevent_head->next attribute. */
      event_nb = 0;
      nb_events_found = 0;
      pevent_head = NULL;
      LogDebug(COMPONENT_FSAL_UP, "Requesting event from FSAL Callback interface.");
      status = FSAL_UP_GetEvents(&pevent_head,     /* out */
                                 &event_nb,        /* in/out */
                                 timeout,          /* in */
                                 &nb_events_found, /* out */
                                 &fsal_up_context);/* in */
      if (FSAL_IS_ERROR(status))
        {
          if (status.major == ERR_FSAL_TIMEOUT)
            LogDebug(COMPONENT_FSAL_UP, "FSAL_UP_EB_GetEvents() hit the timeout"
                     " limit of %u.%u seconds for filesystem id %llu.%llu export id"
                     " %d.", timeout.seconds, timeout.nseconds,
                     fsal_up_args->export_entry->filesystem_id.major,
                     fsal_up_args->export_entry->filesystem_id.minor,
                     fsal_up_args->export_entry->id);
          else if (status.major == ERR_FSAL_NOTSUPP)
            {
              LogCrit(COMPONENT_FSAL_UP, "Exiting FSAL UP Thread for filesystem"
                      " id %llu.%llu export id %u because the FSAL Callback"
                      " Interface is not supported for this FSAL type.",
                      fsal_up_args->export_entry->filesystem_id.major,
                      fsal_up_args->export_entry->filesystem_id.minor,
                      fsal_up_args->export_entry->id);
              return NULL;
            }
          else
            LogDebug(COMPONENT_FSAL_UP, "Error: FSAL_UP_EB_GetEvents() "
                     "failed");
        }

      LogDebug(COMPONENT_FSAL_UP, "Received %lu events to process for filesystem"
                     " id %llu.%llu export id %u.",
               event_nb,
               fsal_up_args->export_entry->filesystem_id.major,
               fsal_up_args->export_entry->filesystem_id.minor,
               fsal_up_args->export_entry->id);

      /* process the list of events */
      for(event = pevent_head; event != NULL;)
        {
          status = process_event(event, event_func);
          if (FSAL_IS_ERROR(status))
            {
              LogDebug(COMPONENT_FSAL_UP, "Error: Event could not be processed "
                       "for filesystem %llu.%llu export id %u.",
                       fsal_up_args->export_entry->filesystem_id.major,
                       fsal_up_args->export_entry->filesystem_id.minor,
                       fsal_up_args->export_entry->id);
            }
          tmpevent = event;
          event = event->next_event;
          ReleaseToPool(tmpevent, &nfs_param.fsal_up_param.event_pool);
          event_nb--;
        }

      LogDebug(COMPONENT_FSAL_UP, "%lu events not found for filesystem"
               " %llu.%llu export id %u", event_nb,
               fsal_up_args->export_entry->filesystem_id.major,
               fsal_up_args->export_entry->filesystem_id.minor,
               fsal_up_args->export_entry->id);
    }

  Mem_Free(Arg);
  return NULL;
}                               /* fsal_up_thread */