static int parseAccessParam_for_statexporter(char *var_name, char *var_value,
        exportlist_client_t *clients)
{
    int rc, err_flag = FALSE;
    char *expended_node_list;

    /* temp array of clients */
    char *client_list[EXPORT_MAX_CLIENTS];
    int idx;
    int count;

    /* expends host[n-m] notations */
    count =
        nodelist_common_condensed2extended_nodelist(var_value, &expended_node_list);

    if(count <= 0)
    {
        err_flag = TRUE;
        LogCrit(COMPONENT_CONFIG,
                "STAT_EXPORT_ACCESS: ERROR: Invalid format for client list in EXPORT::%s definition",
                var_name);

        return -1;
    }
    else if(count > EXPORT_MAX_CLIENTS)
    {
        err_flag = TRUE;
        LogCrit(COMPONENT_CONFIG,
                "STAT_EXPORT_ACCESS: ERROR: Client list too long (%d>%d)",
                count, EXPORT_MAX_CLIENTS);
        return -1;
    }

    /* allocate clients strings  */
    for(idx = 0; idx < count; idx++)
    {
        client_list[idx] = (char *)Mem_Alloc(EXPORT_MAX_CLIENTLEN);
        client_list[idx][0] = '\0';
    }

    /*
     * Search for coma-separated list of hosts, networks and netgroups
     */
    rc = nfs_ParseConfLine(client_list, count,
                           expended_node_list, find_comma, find_endLine);

    /* free the buffer the nodelist module has allocated */
    free(expended_node_list);

    if(rc < 0)
    {
        err_flag = TRUE;
        LogCrit(COMPONENT_CONFIG,
                "STAT_EXPORT_ACCESS: ERROR: Client list too long (>%d)", count);

        /* free client strings */
        for(idx = 0; idx < count; idx++)
            Mem_Free((caddr_t) client_list[idx]);

        return rc;
    }

    rc = nfs_AddClientsToClientArray( clients, rc,
                                      (char **)client_list, EXPORT_OPTION_READ_ACCESS | EXPORT_OPTION_WRITE_ACCESS);
    if(rc != 0)
    {
        err_flag = TRUE;
        LogCrit(COMPONENT_CONFIG,
                "STAT_EXPORT_ACCESS: ERROR: Invalid client found in \"%s\"",
                var_value);

        /* free client strings */
        for(idx = 0; idx < count; idx++)
            Mem_Free((caddr_t) client_list[idx]);

        return rc;
    }

    /* everything is OK */

    /* free client strings */
    for(idx = 0; idx < count; idx++)
        Mem_Free((caddr_t) client_list[idx]);

    return rc;
}
/**
 *
 * nfs_read_core_conf: read the configuration ite; for the worker theads.
 *
 * Reads the configuration ite; for the worker theads.
 *
 * @param in_config [IN] configuration file handle
 * @param pparam [OUT] read parameters
 *
 * @return 0 if ok, -1 if failed, 1 is stanza is not there.
 *
 */
int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam)
{
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  config_item_t block;

  /* Is the config tree initialized ? */
  if(in_config == NULL || pparam == NULL)
    return CACHE_INODE_INVALID_ARGUMENT;

  /* Get the config BLOCK */
  if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL)
    {
      LogDebug(COMPONENT_CONFIG,
               "Cannot read item \"%s\" from configuration file",
               CONF_LABEL_NFS_CORE);
      return 1;
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      /* Expected to be a block */
      LogDebug(COMPONENT_CONFIG,
               "Item \"%s\" is expected to be a block",
               CONF_LABEL_NFS_CORE);
      return 1;
    }

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          LogCrit(COMPONENT_CONFIG,
                  "Error reading key[%d] from section \"%s\" of configuration file.",
                  var_index, CONF_LABEL_NFS_CORE);
          return CACHE_INODE_INVALID_ARGUMENT;
        }

      if(!strcasecmp(key_name, "Nb_Worker"))
        {
          pparam->nb_worker = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Nb_Call_Before_Queue_Avg"))
        {
          pparam->nb_call_before_queue_avg = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Nb_MaxConcurrentGC"))
        {
          pparam->nb_max_concurrent_gc = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DupReq_Expiration"))
        {
          pparam->expiration_dupreq = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_IO_Errors"))
        {
          pparam->drop_io_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_Inval_Errors"))
        {
          pparam->drop_inval_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_Delay_Errors"))
        {
          pparam->drop_delay_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "NFS_Port"))
        {
          pparam->port[P_NFS] = (unsigned short)atoi(key_value);
        }
      else if(!strcasecmp(key_name, "MNT_Port"))
        {
          pparam->port[P_MNT] = (unsigned short)atoi(key_value);
        }
      else if(!strcasecmp(key_name, "NLM_Port"))
        {
#ifdef _USE_NLM
          pparam->port[P_NLM] = (unsigned short)atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "Rquota_Port"))
        {
#ifdef _USE_QUOTA
          pparam->port[P_RQUOTA] = (unsigned short)atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "NFS_Program"))
        {
          pparam->program[P_NFS] = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "MNT_Program"))
        {
          pparam->program[P_MNT] = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "NLM_Program"))
        {
#ifdef _USE_NLM
          pparam->program[P_NLM] = atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "Rquota_Program"))
        {
#ifdef _USE_QUOTA
          pparam->program[P_RQUOTA] = atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "NFS_Protocols"))
        {

#     define MAX_NFSPROTO      10       /* large enough !!! */
#     define MAX_NFSPROTO_LEN  256      /* so is it !!! */

          char *nfsvers_list[MAX_NFSPROTO];
          int idx, count;

          /* reset nfs versions flags (clean defaults) */
          pparam->core_options &= ~(CORE_OPTION_ALL_VERS);

          /* allocate nfs vers strings */
          for(idx = 0; idx < MAX_NFSPROTO; idx++)
            nfsvers_list[idx] = (char *)Mem_Alloc(MAX_NFSPROTO_LEN);

          /*
           * Search for coma-separated list of nfsprotos
           */
          count = nfs_ParseConfLine(nfsvers_list, MAX_NFSPROTO,
                                    key_value, find_comma, find_endLine);

          if(count < 0)
            {
              LogCrit(COMPONENT_CONFIG,
                      "NFS_Protocols list too long (>%d)",
                      MAX_NFSPROTO);

              /* free sec strings */
              for(idx = 0; idx < MAX_NFSPROTO; idx++)
                Mem_Free((caddr_t) nfsvers_list[idx]);

              return -1;
            }

          /* add each Nfs protocol flag to the option field.  */

          for(idx = 0; idx < count; idx++)
            {
              if(!strcmp(nfsvers_list[idx], "4"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV4;
                }
/* only NFSv4 is supported for the FSAL_PROXY */
#if ! defined( _USE_PROXY ) || defined ( _HANDLE_MAPPING )
              else if(!strcmp(nfsvers_list[idx], "2"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV2;
                }
              else if(!strcmp(nfsvers_list[idx], "3"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV3;
                }
#endif                          /* _USE_PROXY */
              else
                {
                  LogCrit(COMPONENT_CONFIG,
                          "Invalid NFS Protocol \"%s\". Values can be: 2, 3, 4.",
                          nfsvers_list[idx]);
                  return -1;
                }
            }

          /* free sec strings */
          for(idx = 0; idx < MAX_NFSPROTO; idx++)
            Mem_Free((caddr_t) nfsvers_list[idx]);

          /* check that at least one nfs protocol has been specified */
          if((pparam->core_options & (CORE_OPTION_ALL_VERS)) == 0)
            {
              LogCrit(COMPONENT_CONFIG, "Empty NFS_Protocols list");
              return -1;
            }
        }
      else if(!strcasecmp(key_name, "Bind_Addr"))
        {
          int rc;
          memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr));
          rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr);
          if(rc <= 0)
            {
              /* Revert to INADDR_ANY in case of any error */
              pparam->bind_addr.sin_addr.s_addr = INADDR_ANY;   /* All the interfaces on the machine are used */
            }
        }
      else if(!strcasecmp(key_name, "Core_Dump_Size"))
        {
          pparam->core_dump_size = atol(key_value);
        }
      else if(!strcasecmp(key_name, "Nb_Max_Fd"))
        {
          pparam->nb_max_fd = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Stats_File_Path"))
        {
          strncpy(pparam->stats_file_path, key_value, MAXPATHLEN);
        }
      else if(!strcasecmp(key_name, "Stats_Update_Delay"))
        {
          pparam->stats_update_delay = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Long_Processing_Threshold"))
        {
          pparam->long_processing_threshold = atoi(key_value);
        }
      else if(!strcasecmp( key_name, "TCP_Fridge_Expiration_Delay" ) )
        {
          pparam->tcp_fridge_expiration_delay = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Dump_Stats_Per_Client"))
        {
          pparam->dump_stats_per_client = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Stats_Per_Client_Directory"))
        {
          strncpy(pparam->stats_per_client_directory, key_value, MAXPATHLEN);
        }
      else if(!strcasecmp(key_name, "FSAL_Shared_Library"))
        {
          strncpy(pparam->fsal_shared_library, key_value, MAXPATHLEN);
        }
      else
        {
          LogCrit(COMPONENT_CONFIG,
                  "Unknown or unsettable key: %s (item %s)",
                  key_name, CONF_LABEL_NFS_CORE);
          return -1;
        }

    }

  return 0;
}                               /* nfs_read_core_conf */
Beispiel #3
0
/**
 *
 * nfs_read_core_conf: read the configuration ite; for the worker theads.
 *
 * Reads the configuration ite; for the worker theads.
 *
 * @param in_config [IN] configuration file handle
 * @param pparam [OUT] read parameters
 *
 * @return 0 if ok, -1 if failed, 1 is stanza is not there.
 *
 */
int nfs_read_core_conf(config_file_t in_config, nfs_core_parameter_t * pparam)
{
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  config_item_t block;

  /* Is the config tree initialized ? */
  if(in_config == NULL || pparam == NULL)
    return CACHE_INODE_INVALID_ARGUMENT;

  /* Get the config BLOCK */
  if((block = config_FindItemByName(in_config, CONF_LABEL_NFS_CORE)) == NULL)
    {
      LogDebug(COMPONENT_CONFIG,
               "Cannot read item \"%s\" from configuration file",
               CONF_LABEL_NFS_CORE);
      return 1;
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      /* Expected to be a block */
      LogDebug(COMPONENT_CONFIG,
               "Item \"%s\" is expected to be a block",
               CONF_LABEL_NFS_CORE);
      return 1;
    }

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          LogCrit(COMPONENT_CONFIG,
                  "Error reading key[%d] from section \"%s\" of configuration file.",
                  var_index, CONF_LABEL_NFS_CORE);
          return CACHE_INODE_INVALID_ARGUMENT;
        }

      if(!strcasecmp(key_name, "Nb_Worker"))
        {
          pparam->nb_worker = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Nb_Call_Before_Queue_Avg"))
        {
          pparam->nb_call_before_queue_avg = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_Disabled"))
        {
            pparam->drc.disabled = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Npart"))
        {
          pparam->drc.tcp.npart = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Size"))
        {
          pparam->drc.tcp.size = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Cachesz"))
        {
          pparam->drc.tcp.cachesz = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Hiwat"))
        {
          pparam->drc.tcp.hiwat = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Recycle_Npart"))
        {
          pparam->drc.tcp.recycle_npart = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Recycle_Expire_S"))
        {
          pparam->drc.tcp.recycle_expire_s = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_TCP_Checksum"))
        {
          pparam->drc.tcp.checksum = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_UDP_Npart"))
        {
          pparam->drc.udp.npart = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_UDP_Size"))
        {
          pparam->drc.udp.size = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_UDP_Cachesz"))
        {
          pparam->drc.udp.cachesz = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_UDP_Hiwat"))
        {
          pparam->drc.udp.hiwat = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DRC_UDP_Checksum"))
        {
          pparam->drc.udp.checksum = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "DupReq_Expiration"))
        {
          pparam->expiration_dupreq = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Dispatch_Max_Reqs"))
        {
          pparam->dispatch_max_reqs = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Dispatch_Max_Reqs_Xprt"))
        {
          pparam->dispatch_max_reqs_xprt = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_IO_Errors"))
        {
          pparam->drop_io_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_Inval_Errors"))
        {
          pparam->drop_inval_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Drop_Delay_Errors"))
        {
          pparam->drop_delay_errors = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "NFS_Port"))
        {
          pparam->port[P_NFS] = (unsigned short)atoi(key_value);
        }
      else if(!strcasecmp(key_name, "MNT_Port"))
        {
          pparam->port[P_MNT] = (unsigned short)atoi(key_value);
        }
      else if(!strcasecmp(key_name, "NLM_Port"))
        {
#ifdef _USE_NLM
          pparam->port[P_NLM] = (unsigned short)atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "Rquota_Port"))
        {
#ifdef _USE_RQUOTA
          pparam->port[P_RQUOTA] = (unsigned short)atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "NFS_Program"))
        {
          pparam->program[P_NFS] = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "MNT_Program"))
        {
          pparam->program[P_MNT] = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "NLM_Program"))
        {
#ifdef _USE_NLM
          pparam->program[P_NLM] = atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "Rquota_Program"))
        {
#ifdef _USE_RQUOTA
          pparam->program[P_RQUOTA] = atoi(key_value);
#endif
        }
      else if(!strcasecmp(key_name, "NFS_Protocols"))
        {

#     define MAX_NFSPROTO      10       /* large enough !!! */

          char *nfsvers_list[MAX_NFSPROTO];
          int idx, count;

          /* reset nfs versions flags (clean defaults) */
          pparam->core_options &= ~(CORE_OPTION_ALL_VERS);

          /* fill nfs vers list with NULL pointers */
          memset(nfsvers_list, 0, sizeof(nfsvers_list));

          /*
           * Search for coma-separated list of nfsprotos
           */
          count = nfs_ParseConfLine(nfsvers_list,
                                    MAX_NFSPROTO,
                                    0,
                                    key_value,
                                    ',');

          if(count < 0)
            {
              LogCrit(COMPONENT_CONFIG,
                      "NFS_Protocols list too long (>%d)",
                      MAX_NFSPROTO);

              return -1;
            }

          /* add each Nfs protocol flag to the option field.  */

          for(idx = 0; idx < count; idx++)
            {
              if(!strcmp(nfsvers_list[idx], "4"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV4;
                }
              else if(!strcmp(nfsvers_list[idx], "2"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV2;
                }
              else if(!strcmp(nfsvers_list[idx], "3"))
                {
                  pparam->core_options |= CORE_OPTION_NFSV3;
                }
              else
                {
                  LogCrit(COMPONENT_CONFIG,
                          "Invalid NFS Protocol \"%s\". Values can be: 2, 3, 4.",
                          nfsvers_list[idx]);
                  return -1;
                }
            }

          /* check that at least one nfs protocol has been specified */
          if((pparam->core_options & (CORE_OPTION_ALL_VERS)) == 0)
            {
              LogCrit(COMPONENT_CONFIG, "Empty NFS_Protocols list");
              return -1;
            }
        }
      else if(!strcasecmp(key_name, "Bind_Addr"))
        {
          int rc;
          memset(&pparam->bind_addr.sin_addr, 0, sizeof(pparam->bind_addr.sin_addr));
          rc = inet_pton(AF_INET, key_value, &pparam->bind_addr.sin_addr);
          if(rc <= 0)
            {
              /* Revert to INADDR_ANY in case of any error */
              pparam->bind_addr.sin_addr.s_addr = INADDR_ANY;   /* All the interfaces on the machine are used */
            }
        }
      else if(!strcasecmp(key_name, "Core_Dump_Size"))
        {
          pparam->core_dump_size = atol(key_value);
        }
      else if(!strcasecmp(key_name, "Nb_Max_Fd"))
        {
          pparam->nb_max_fd = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Stats_File_Path"))
        {
          if(strmaxcpy(pparam->stats_file_path,
                       key_value,
                       sizeof(pparam->stats_file_path)) == -1)
            {
              LogCrit(COMPONENT_CONFIG,
                      "%s=\"%s\" too long",
                      key_name, key_value);
            }
        }
      else if(!strcasecmp(key_name, "Stats_Update_Delay"))
        {
          pparam->stats_update_delay = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Long_Processing_Threshold"))
        {
          pparam->long_processing_threshold = atoi(key_value);
          pparam->long_processing_threshold_msec = pparam->long_processing_threshold * MSEC_PER_SEC;
        }
      else if(!strcasecmp( key_name, "Decoder_Fridge_Expiration_Delay" ) )
        {
          pparam->decoder_fridge_expiration_delay = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Dump_Stats_Per_Client"))
        {
          pparam->dump_stats_per_client = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Stats_Per_Client_Directory"))
        {
          if(strmaxcpy(pparam->stats_per_client_directory,
                       key_value,
                       sizeof(pparam->stats_per_client_directory)) == -1)
            {
              LogCrit(COMPONENT_CONFIG,
                      "%s=\"%s\" too long",
                      key_name, key_value);
            }
        }
      else if(!strcasecmp( key_name, "MaxRPCSendBufferSize" ) )
        {
          pparam->max_send_buffer_size = atoi(key_value);
        }
      else if(!strcasecmp( key_name, "MaxRPCRecvBufferSize" ) )
        {
          pparam->max_recv_buffer_size = atoi(key_value);
        }
#ifdef _USE_NLM
      else if(!strcasecmp( key_name, "NSM_Use_Caller_Name" ) )
        {
          pparam->nsm_use_caller_name = StrToBoolean(key_value);
        }
#endif
      else if(!strcasecmp(key_name, "Clustered"))
        {
          pparam->clustered = StrToBoolean(key_value);
        }
      else
        {
          LogCrit(COMPONENT_CONFIG,
                  "Unknown or unsettable key: %s (item %s)",
                  key_name, CONF_LABEL_NFS_CORE);
          return -1;
        }

    }

  return 0;
}                               /* nfs_read_core_conf */