コード例 #1
0
ファイル: rmdir_config.c プロジェクト: seagate-ssg/robinhood
int Read_Rmdir_Config( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    bool           bval;
    rmdir_config_t *conf = ( rmdir_config_t * ) module_config;

    static const char * rmdir_allowed[] =
    {
        "runtime_interval", "nb_threads_rmdir", "rmdir_queue_size", NULL
    };

    /* get RMDIR_PARAM block */

    config_item_t  param_block = rh_config_FindItemByName( config, RMDIR_PARAM_BLOCK );
    if ( param_block == NULL )
      {
          /* no error, because no parameter is mandatory */
          return 0;
      }

    /* check this is a block... */
    if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK )
      {
          strcpy( msg_out, "A block is expected for '" RMDIR_PARAM_BLOCK "' item" );
          return EINVAL;
      }

    /* parse parameters */
    rc = GetDurationParam(param_block, RMDIR_PARAM_BLOCK, "runtime_interval",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                          &conf->runtime_interval, NULL, NULL, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;

    rc = GetIntParam( param_block, RMDIR_PARAM_BLOCK, "nb_threads_rmdir",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_rmdir,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( param_block, RMDIR_PARAM_BLOCK, "rmdir_queue_size",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->rmdir_queue_size,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam(param_block, RMDIR_PARAM_BLOCK, "simulation_mode",
                      0, &bval, NULL, NULL, msg_out);
    if (rc != ENOENT)
    {
        DisplayLog( LVL_EVENT, "RmdirConfig",
            "WARNING: deprecated parameter 'simulation_mode'. Use '--dry-run' option instead.");
    }

    CheckUnknownParameters( param_block, RMDIR_PARAM_BLOCK, rmdir_allowed );

    return 0;

}
コード例 #2
0
ファイル: listmgr_config.c プロジェクト: bringhurst/robinhood
int ReadLmgrConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    lmgr_config_t *conf = ( lmgr_config_t * ) module_config;
    char         **options = NULL;
    unsigned int   nb_options = 0;
    char           tmpstr[1024];

    config_item_t  db_block;

    static const char *lmgr_allowed[] = {
        "commit_behavior",
        "connect_retry_interval_min",
        "connect_retry_interval_max",
        "user_acct",
        "group_acct",
        MYSQL_CONFIG_BLOCK,
        SQLITE_CONFIG_BLOCK,
        NULL
    };


#ifdef _MYSQL
    static const char *db_allowed[] = {
        "server", "db", "user", "password", "password_file", "port", "socket",
        "innodb", NULL
    };
#elif defined (_SQLITE)
    static const char *db_allowed[] = {
        "db_file", "retry_delay_microsec",
        NULL
    };
#endif

    /* get ListManager block */

    config_item_t  lmgr_block = rh_config_FindItemByName( config, LMGR_CONFIG_BLOCK );

    if ( lmgr_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" LMGR_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( lmgr_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" LMGR_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */

    /* 1) commit_behavior */

    rc = GetStringParam( lmgr_block, LMGR_CONFIG_BLOCK, "commit_behavior",
                         STR_PARAM_NO_WILDCARDS, tmpstr, 1024, &options, &nb_options, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
    {
        if ( !strcasecmp( tmpstr, "autocommit" ) )
            conf->commit_behavior = 0;
        else if ( !strcasecmp( tmpstr, "transaction" ) )
            conf->commit_behavior = 1;
        else if ( !strcasecmp( tmpstr, "periodical" )  /* for backward compatibility */
                  || !strcasecmp( tmpstr, "periodic" ) )
        {
            if ( ( nb_options != 1 ) || !options || !options[0] )
            {
                strcpy( msg_out,
                        "A single argument is expected for periodic commit behavior. Eg: commit_behavior = periodic(1000)" );
                return EINVAL;
            }

            conf->commit_behavior = atoi( options[0] );
            if ( conf->commit_behavior == 0 )
            {
                strcpy( msg_out,
                        "The argument for \"" LMGR_CONFIG_BLOCK
                        "::commit_behavior = periodical\" must be a positive integer. Eg: commit_behavior = periodic(1000)" );
                return EINVAL;
            }
        }
        else
        {
            sprintf( msg_out, "Invalid commit behavior '%s' (expected: autocommit, "
                     "transaction, periodic(<count>))", tmpstr );
            return EINVAL;
        }

    }

    /* 2) connect_retry_interval_min  and connect_retry_interval_max */

    rc = GetDurationParam( lmgr_block, LMGR_CONFIG_BLOCK,
                           "connect_retry_interval_min",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->connect_retry_min, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( lmgr_block, LMGR_CONFIG_BLOCK,
                           "connect_retry_interval_max",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->connect_retry_max, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    /* 3) ACCT configuration*/

    rc = GetBoolParam( lmgr_block, LMGR_CONFIG_BLOCK,
                       "user_acct", 0, &conf->user_acct, NULL, NULL, msg_out);
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( lmgr_block, LMGR_CONFIG_BLOCK,
                       "group_acct", 0, &conf->group_acct, NULL, NULL, msg_out);
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;      

    CheckUnknownParameters( lmgr_block, LMGR_CONFIG_BLOCK, lmgr_allowed );

    /* Database specific parameters */
#ifdef _MYSQL

    /* get MySQL block */

    db_block = rh_config_GetItemByName( lmgr_block, MYSQL_CONFIG_BLOCK );

    if ( db_block == NULL )
    {
        strcpy( msg_out,
                "Missing configuration block '" LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( db_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out,
                 "A block is expected for '" LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK
                 "' item, line %d", rh_config_GetItemLine( db_block ) );
        return EINVAL;
    }

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "server",
                         STR_PARAM_NO_WILDCARDS, conf->db_config.server, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "db",
                         PARAM_MANDATORY | STR_PARAM_NO_WILDCARDS,
                         conf->db_config.db, 256, NULL, NULL, msg_out );
    if ( rc )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "user",
                         STR_PARAM_NO_WILDCARDS, conf->db_config.user, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "password",
                         0, conf->db_config.password, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
    {
        FILE          *passfile;
        char           errstr[1024];

        rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK,
                             "password_file",
                             STR_PARAM_ABSOLUTE_PATH |
                             STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc == ENOENT )
        {
            strcpy( msg_out,
                    MYSQL_CONFIG_BLOCK "::password or "
                    MYSQL_CONFIG_BLOCK "::password_file must be provided" );
            return ENOENT;
        }

        /* read password file and @TODO check its rights */
        passfile = fopen( tmpstr, "r" );
        if ( !passfile )
        {
            rc = errno;
            sprintf( msg_out, "Error openning password file %s : %s", tmpstr, strerror(errno) );
            return rc;
        }
        fscanf( passfile, "%1024s", tmpstr );
        if ( ferror( passfile ) )
        {
            rc = errno;
            strerror_r( rc, errstr, 1024 );
            sprintf( msg_out, "Error reading password file %s : %s", tmpstr, errstr );
            return rc;
        }
        fclose( passfile );
        strncpy( conf->db_config.password, tmpstr, 256 );
    }

    rc = GetIntParam( db_block, MYSQL_CONFIG_BLOCK, "port",
                         INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                         (int*)&conf->db_config.port, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "socket",
                         STR_PARAM_NO_WILDCARDS | STR_PARAM_ABSOLUTE_PATH,
                         conf->db_config.socket, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( db_block, MYSQL_CONFIG_BLOCK, "innodb", 0,
                       &conf->db_config.innodb, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( db_block, MYSQL_CONFIG_BLOCK, db_allowed );

#elif defined (_SQLITE)
    /* get SQLite block */

    db_block = rh_config_GetItemByName( lmgr_block, SQLITE_CONFIG_BLOCK );

    if ( db_block == NULL )
    {
        strcpy( msg_out,
                "Missing configuration block '" LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( db_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out,
                 "A block is expected for '" LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK
                 "' item, line %d", rh_config_GetItemLine( db_block ) );
        return EINVAL;
    }


    rc = GetStringParam( db_block, SQLITE_CONFIG_BLOCK, "db_file",
                         STR_PARAM_ABSOLUTE_PATH |
                         STR_PARAM_NO_WILDCARDS,
                         conf->db_config.filepath, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( db_block, SQLITE_CONFIG_BLOCK,
                      "retry_delay_microsec",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      (int*)&conf->db_config.retry_delay_microsec, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( db_block, SQLITE_CONFIG_BLOCK, db_allowed );
#endif


    return 0;
}
コード例 #3
0
ファイル: resmon_config.c プロジェクト: karig/robinhood
int Read_ResourceMon_Config( config_file_t config,
                             void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    int            intval;
    resource_monitor_config_t *conf = ( resource_monitor_config_t * ) module_config;

    unsigned int   blc_index;

    static const char *purge_allowed[] = {
        "nb_threads_purge", "post_purge_df_latency",
        "purge_queue_size", "db_result_size_max",
#ifdef ATTR_INDEX_status
        "check_purge_status_on_startup",
#endif
        "recheck_ignored_classes",
#ifdef _TMP_FS_MGR
        "purge_command",
#endif
        NULL
    };

    /* get PURGE_PARAM block */

    config_item_t  param_block = rh_config_FindItemByName( config, PURGE_PARAM_BLOCK );
    if ( param_block != NULL )
    {
        /* no error, because no parameter is mandatory */

        /* check this is a block... */
        if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK )
        {
            strcpy( msg_out, "A block is expected for '" PURGE_PARAM_BLOCK "' item" );
            return EINVAL;
        }

        /* parse parameters */
        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "nb_threads_purge",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_purge,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetDurationParam( param_block, PURGE_PARAM_BLOCK, "post_purge_df_latency", INT_PARAM_POSITIVE, /* 0 is authorized: no delay */
                               &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->post_purge_df_latency = intval;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "purge_queue_size",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->purge_queue_size,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "db_result_size_max",
                          INT_PARAM_POSITIVE, ( int * ) &conf->db_request_limit, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

#ifdef ATTR_INDEX_status
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "check_purge_status_on_startup",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->check_purge_status_on_startup = intval;
#endif
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "recheck_ignored_classes",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->recheck_ignored_classes = intval;

        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "simulation_mode",
                           0, &intval, NULL, NULL, msg_out );
        if ( rc == 0 )
        {
            DisplayLog( LVL_CRIT, RESMONCFG_TAG,
                "WARNING: 'simulation_mode' parameter is deprecated. Use '--dry-run' option instead.");
        }

#ifdef _TMP_FS_MGR
        rc = GetStringParam(param_block, PURGE_PARAM_BLOCK, "purge_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {path}, {fid}, {fsname} */
                         conf->purge_command, RBH_PATH_MAX, NULL, NULL, msg_out);
        if ((rc != 0) && (rc != ENOENT))
            return rc;
#endif

        CheckUnknownParameters( param_block, PURGE_PARAM_BLOCK, purge_allowed );

    } /* end of purge parameters */

    /* get PURGE_TRIGGER blocks */

    for ( blc_index = 0; blc_index < rh_config_GetNbBlocks( config ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetBlockByIndex( config, blc_index );
        critical_err_check( curr_item, "root" );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( block_name, "root" );

        if ( !strcasecmp( block_name, TRIGGER_BLOCK ) )
        {
            if ( conf->trigger_count == 0 )
                conf->trigger_list = ( trigger_item_t * ) malloc( sizeof( trigger_item_t ) );
            else
                conf->trigger_list =
                    ( trigger_item_t * ) realloc( conf->trigger_list,
                                                  ( conf->trigger_count +
                                                    1 ) * sizeof( trigger_item_t ) );

            conf->trigger_count++;

            /* analyze trigger block */
            rc = parse_trigger_block( curr_item, block_name,
                                      &conf->trigger_list[conf->trigger_count - 1], msg_out );

            if ( rc )
                return rc;
        }
    }

    return 0;
}
コード例 #4
0
ファイル: resmon_config.c プロジェクト: karig/robinhood
static int parse_trigger_block( config_item_t config_blk, const char *block_name,
                                trigger_item_t * p_trigger_item, char *msg_out )
{
    int            rc;
    int            rc_hp, rc_lp, rc_hv, rc_lv, rc_hc, rc_lc;
    unsigned int high_count = 0;
    unsigned int low_count = 0;
    double         h_pct, l_pct;
    unsigned long long h_vol, l_vol;
    uint64_t       h_cnt, l_cnt;
    int            tmpval;
    int            i;
    char           tmpstr[1024];
    char         **arg_tab;
    unsigned int   arg_count;

    static const char *trigger_expect[] =
    {
        "trigger_on", "check_interval",
        "high_threshold_pct", "low_threshold_pct",
        "high_threshold_vol", "low_threshold_vol",
        "high_threshold_cnt", "low_threshold_cnt",
        "alert_high", "alert_low",
        /* for backward compatibility */
        "high_watermark_pct", "low_watermark_pct",
        "high_watermark_vol", "low_watermark_vol",
        "high_watermark_cnt", "low_watermark_cnt",
        "notify", "notify_hw", "alert_lw",
        NULL
    };


    /* retrieve parameters */

    rc = GetStringParam( config_blk, block_name, "trigger_on",
                         PARAM_MANDATORY | STR_PARAM_NO_WILDCARDS, tmpstr, 1024, &arg_tab,
                         &arg_count, msg_out );

    if ( rc )                   /* even ENOENT retruns an error because trigger_on is mandatory */
        return rc;

    /* initialize list of optional args */
    p_trigger_item->list = NULL;
    p_trigger_item->list_size = 0;

    /* analyze trigger_on parameter */
    if ( !strcasecmp( tmpstr, "periodic" ) )
    {
        p_trigger_item->type = TRIGGER_ALWAYS;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = FALSE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "global_usage" ) )
    {
        p_trigger_item->type = TRIGGER_GLOBAL_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "OST_usage" ) )
    {
        p_trigger_item->type = TRIGGER_OST_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "user_usage" ) )
    {
        p_trigger_item->type = TRIGGER_USER_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional arguments: user list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "group_usage" ) )
    {
        p_trigger_item->type = TRIGGER_GROUP_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional argument: group list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "pool_usage" ) )
    {
        p_trigger_item->type = TRIGGER_POOL_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional arguments: user list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "external_command" ) )
    {
        p_trigger_item->type = TRIGGER_CUSTOM_CMD;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* single mandatory argument: command */
        if ( arg_count != 1 )
        {
            sprintf( msg_out,
                     "A single mandatory argument is expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }

        p_trigger_item->list = ( char ** ) malloc( sizeof( char * ) );
        p_trigger_item->list[0] = ( char * ) malloc( strlen( arg_tab[0] ) + 1 );
        strcpy( p_trigger_item->list[0], arg_tab[0] );
        p_trigger_item->list_size = 1;
    }
    else
    {
        sprintf( msg_out, "Unexpected value for 'trigger_on' parameter: %s.", tmpstr );
        return EINVAL;
    }


    /* retrieve all threshold params and check their compatibility */
    high_count = low_count = 0;

    rc_hp = GetFloatParam( config_blk, block_name, "high_threshold_pct",
                         FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &h_pct,
                         NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hp == ENOENT )
        rc_hp = GetFloatParam( config_blk, block_name, "high_watermark_pct",
                             FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &h_pct,
                             NULL, NULL, msg_out );

    if ( ( rc_hp != 0 ) && ( rc_hp != ENOENT ) )
        return rc_hp;
    else if ( rc_hp != ENOENT )
        high_count++;

    rc_hv = GetSizeParam( config_blk, block_name, "high_threshold_vol",
                        INT_PARAM_POSITIVE, &h_vol, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hv == ENOENT )
        rc_hv = GetSizeParam( config_blk, block_name, "high_watermark_vol",
                              INT_PARAM_POSITIVE, &h_vol, NULL, NULL, msg_out );

    if ( ( rc_hv != 0 ) && ( rc_hv != ENOENT ) )
        return rc_hv;
    else if ( rc_hv != ENOENT )
        high_count++;

    rc_hc = GetInt64Param( config_blk, block_name, "high_threshold_cnt",
                           INT_PARAM_POSITIVE, &h_cnt, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hc == ENOENT )
            rc_hc = GetInt64Param( config_blk, block_name, "high_watermark_cnt",
                                   INT_PARAM_POSITIVE, &h_cnt, NULL, NULL, msg_out );
    if ( ( rc_hc != 0 ) && ( rc_hc != ENOENT ) )
        return rc_hc;
    else if ( rc_hc != ENOENT )
        high_count++;

    rc_lp = GetFloatParam( config_blk, block_name, "low_threshold_pct",
                         FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &l_pct,
                         NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lp == ENOENT )
        rc_lp = GetFloatParam( config_blk, block_name, "low_watermark_pct",
                             FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &l_pct,
                             NULL, NULL, msg_out );

    if ( ( rc_lp != 0 ) && ( rc_lp != ENOENT ) )
        return rc_lp;
    else if ( rc_lp != ENOENT )
        low_count++;

    rc_lv = GetSizeParam( config_blk, block_name, "low_threshold_vol",
                        INT_PARAM_POSITIVE, &l_vol, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lv == ENOENT )
        rc_lv = GetSizeParam( config_blk, block_name, "low_watermark_vol",
                            INT_PARAM_POSITIVE, &l_vol, NULL, NULL, msg_out );
    if ( ( rc_lv != 0 ) && ( rc_lv != ENOENT ) )
        return rc_lv;
    else if ( rc_lv != ENOENT )
        low_count++;

    rc_lc = GetInt64Param( config_blk, block_name, "low_threshold_cnt",
                           INT_PARAM_POSITIVE, &l_cnt, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lc == ENOENT )
        rc_lc = GetInt64Param( config_blk, block_name, "low_watermark_cnt",
                               INT_PARAM_POSITIVE, &l_cnt, NULL, NULL, msg_out );
    if ( ( rc_lc != 0 ) && ( rc_lc != ENOENT ) )
        return rc_lc;
    else if ( rc_lc != ENOENT )
        low_count++;

    if ( p_trigger_item->type == TRIGGER_ALWAYS )
    {
        /* in case of 'periodic' trigger, no thresholds are expected */
        if ( (high_count > 0) || (low_count > 0) )
        {
            strcpy( msg_out,
                    "No high/low threshold expected for trigger type 'periodic'" );
            return EINVAL;
        }
    }
    else if ( p_trigger_item->type == TRIGGER_CUSTOM_CMD )
    {
        /* in case of an external command, no thresholds are expected */
        if ( (high_count > 0) || (low_count > 0) )
        {
            strcpy( msg_out,
                    "No high/low thresholds expected for trigger type 'external_command'" );
            return EINVAL;
        }
    }
    else if ( high_count > 1 )
    {
        strcpy( msg_out, "Multiple purge start conditions in trigger." );
        return EINVAL;
    }
    else if ( low_count > 1 )
    {
        strcpy( msg_out, "Multiple purge stop conditions in trigger." );
        return EINVAL;
    }
    else if ( high_count == 0 )
    {
        strcpy( msg_out, "No purge start condition found in trigger "
                         "(mandatory). 'high_threshold_pct', 'high_threshold_vol'"
                         "or 'high_threshold_cnt' expected" );
        return ENOENT;
    }
    else if ( low_count == 0 )
    {
        strcpy( msg_out, "No purge stop condition found in trigger "
                         "(mandatory). 'low_threshold_pct', 'low_threshold_vol'"
                         "or 'low_threshold_cnt' expected" );
        return ENOENT;
    }
    else if ( rc_hc != rc_lc ) /* both 0 or both ENOENT */
    {
        strcpy( msg_out, "Incompatible threshold types: 'high_threshold_cnt' "
                         "must be used with 'low_threshold_cnt'" );
        return ENOENT;
    }

    /* NOTE: count threshold for HSM systems only match online files (not released)*/

    /* count threshold is only on global usage */
    if ( (p_trigger_item->type != TRIGGER_GLOBAL_USAGE)
         && (p_trigger_item->type != TRIGGER_ALWAYS)
         && (p_trigger_item->type != TRIGGER_USER_USAGE)
         && (p_trigger_item->type != TRIGGER_GROUP_USAGE)
         && ( (rc_hc == 0) || (rc_lc == 0) ) )
    {
        strcpy( msg_out, "Threshold on entry count is only supported "
                         "for 'global_usage', 'user_usage', 'group_usage' and 'periodic' triggers" );
        return EINVAL;
    }

    if ( rc_hp == 0 )
    {
        p_trigger_item->hw_type = PCT_THRESHOLD;
        p_trigger_item->hw_percent = h_pct;
    }
    else if ( rc_hv == 0 )
    {
        p_trigger_item->hw_type = VOL_THRESHOLD;
        p_trigger_item->hw_volume = h_vol;
    }
    else if ( rc_hc == 0 )
    {
        p_trigger_item->hw_type = COUNT_THRESHOLD;
        p_trigger_item->hw_count = h_cnt;
    }

    if ( rc_lp == 0 )
    {
        p_trigger_item->lw_type = PCT_THRESHOLD;
        p_trigger_item->lw_percent = l_pct;
    }
    else if ( rc_lv == 0 )
    {
        p_trigger_item->lw_type = VOL_THRESHOLD;
        p_trigger_item->lw_volume = l_vol;
    }
    else if ( rc_lc == 0 )
    {
        p_trigger_item->lw_type = COUNT_THRESHOLD;
        p_trigger_item->lw_count = l_cnt;
    }

    /* retrieve check interval parameter */

    rc = GetDurationParam( config_blk, block_name, "check_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL
                           | PARAM_MANDATORY, &tmpval, NULL,
                           NULL, msg_out );
    if ( rc )
        return rc;
    p_trigger_item->check_interval = tmpval;

    rc = GetBoolParam( config_blk, block_name, "alert_high", 0,
                       &tmpval, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "notify_hw", 0,
                           &tmpval, NULL, NULL, msg_out );
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "notify", 0,
                           &tmpval, NULL, NULL, msg_out );

    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        p_trigger_item->alert_hw = tmpval;

    rc = GetBoolParam( config_blk, block_name, "alert_low", 0,
                       &tmpval, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "alert_lw", 0,
                           &tmpval, NULL, NULL, msg_out );

    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        p_trigger_item->alert_lw = tmpval;

    CheckUnknownParameters( config_blk, block_name, trigger_expect );

    return 0;

}
コード例 #5
0
ファイル: listmgr_config.c プロジェクト: cea-hpc/robinhood
static int lmgr_cfg_read(config_file_t config, void *module_config,
                         char *msg_out)
{
    int rc;
    bool bval;
    lmgr_config_t *conf = (lmgr_config_t *) module_config;
    char **options = NULL;
    unsigned int nb_options = 0;
    char tmpstr[1024];
    config_item_t lmgr_block;
    config_item_t db_block;

    static const char *lmgr_allowed[] = {
        "commit_behavior", "connect_retry_interval_min",
        "connect_retry_interval_max", "accounting",
        MYSQL_CONFIG_BLOCK, SQLITE_CONFIG_BLOCK,
        "user_acct", "group_acct",  /* deprecated => accounting */
        NULL
    };

    const cfg_param_t cfg_params[] = {
        {"connect_retry_interval_min", PT_DURATION, PFLG_POSITIVE |
         PFLG_NOT_NULL, &conf->connect_retry_min, 0},
        {"connect_retry_interval_max", PT_DURATION, PFLG_POSITIVE |
         PFLG_NOT_NULL, &conf->connect_retry_max, 0},
        {"accounting", PT_BOOL, 0, &conf->acct, 0},
        END_OF_PARAMS
    };

#ifdef _MYSQL
    static const char *db_allowed[] = {
        "server", "db", "user", "password", "password_file", "port", "socket",
        "engine", "tokudb_compression", NULL
    };

    const cfg_param_t db_params[] = {
        {"server", PT_STRING, PFLG_NO_WILDCARDS,
         conf->db_config.server, sizeof(conf->db_config.server)}
        ,
        {"db", PT_STRING, PFLG_MANDATORY | PFLG_NO_WILDCARDS,
         conf->db_config.db, sizeof(conf->db_config.db)}
        ,
        {"user", PT_STRING, PFLG_NO_WILDCARDS, conf->db_config.user,
         sizeof(conf->db_config.user)}
        ,
        {"port", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL,
         (int *)&conf->db_config.port, 0},
        {"socket", PT_STRING, PFLG_NO_WILDCARDS | PFLG_ABSOLUTE_PATH,
         conf->db_config.socket, sizeof(conf->db_config.socket)}
        ,
        {"engine", PT_STRING, PFLG_NO_WILDCARDS | PFLG_NOT_EMPTY,
         conf->db_config.engine, sizeof(conf->db_config.engine)}
        ,
        {"tokudb_compression", PT_STRING, PFLG_NO_WILDCARDS,
         conf->db_config.tokudb_compression,
         sizeof(conf->db_config.tokudb_compression)}
        ,
        END_OF_PARAMS
    };
#elif defined(_SQLITE)
    static const char *db_allowed[] = {
        "db_file", "retry_delay_microsec",
        NULL
    };
    const cfg_param_t db_params[] = {
        {"db_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS,
         conf->db_config.filepath, sizeof(conf->db_config.filepath)}
        ,
        {"retry_delay_microsec", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL,
         (int *)&conf->db_config.retry_delay_microsec, 0},
        END_OF_PARAMS
    };
#endif

    /* get ListManager block */
    rc = get_cfg_block(config, LMGR_CONFIG_BLOCK, &lmgr_block, msg_out);
    if (rc)
        return rc;

    /* retrieve std parameters */
    rc = read_scalar_params(lmgr_block, LMGR_CONFIG_BLOCK, cfg_params, msg_out);
    if (rc)
        return rc;

    /* commit_behavior */
    rc = GetStringParam(lmgr_block, LMGR_CONFIG_BLOCK, "commit_behavior",
                        PFLG_NO_WILDCARDS, tmpstr, sizeof(tmpstr), &options,
                        &nb_options, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc != ENOENT) {
        if (!strcasecmp(tmpstr, "autocommit"))
            conf->commit_behavior = 0;
        else if (!strcasecmp(tmpstr, "transaction"))
            conf->commit_behavior = 1;
        else if (!strcasecmp(tmpstr, "periodic")) {
            if ((nb_options != 1) || !options || !options[0]) {
                strcpy(msg_out,
                       "A single argument is expected for periodic commit behavior. Eg: commit_behavior = periodic(1000)");
                return EINVAL;
            }

            conf->commit_behavior = atoi(options[0]);
            if (conf->commit_behavior == 0) {
                strcpy(msg_out,
                       "The argument for \"" LMGR_CONFIG_BLOCK
                       "::commit_behavior = periodic\" must be a positive integer. Eg: commit_behavior = periodic(1000)");
                return EINVAL;
            }
        } else {
            sprintf(msg_out,
                    "Invalid commit behavior '%s' (expected: autocommit, "
                    "transaction, periodic(<count>))", tmpstr);
            return EINVAL;
        }
    }

    /* manage deprecated parameters */
    rc = GetBoolParam(lmgr_block, LMGR_CONFIG_BLOCK, "user_acct", 0, &bval,
                      NULL, NULL, msg_out);
    if (rc == 0) {
        DisplayLog(LVL_CRIT, TAG,
                   "WARNING: parameter %s::%s' is deprecated. Specify 'accounting = yes/no' instead.",
                   LMGR_CONFIG_BLOCK, "user_acct");
        DisplayLog(LVL_MAJOR, TAG,
                   "Setting 'accounting = %s' for compatibility.",
                   bool2str(bval));
        conf->acct = bval;
    }

    rc = GetBoolParam(lmgr_block, LMGR_CONFIG_BLOCK, "group_acct", 0, &bval,
                      NULL, NULL, msg_out);
    if (rc == 0) {
        DisplayLog(LVL_CRIT, TAG,
                   "WARNING: parameter %s::%s' is deprecated. Specify 'accounting = yes/no' instead.",
                   LMGR_CONFIG_BLOCK, "group_acct");
        DisplayLog(LVL_MAJOR, TAG,
                   "Setting 'accounting = %s' for compatibility.",
                   bool2str(bval));
        conf->acct = bval;
    }

    CheckUnknownParameters(lmgr_block, LMGR_CONFIG_BLOCK, lmgr_allowed);

    /* Database parameters */
#ifdef _MYSQL
    /* get MySQL block */
    rc = get_cfg_block(config, LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK,
                       &db_block, msg_out);
    if (rc)
        return rc;

    /* DB std params */
    rc = read_scalar_params(db_block, MYSQL_CONFIG_BLOCK, db_params, msg_out);
    if (rc)
        return rc;

    /* DB params with specific type */
    rc = GetStringParam(db_block, MYSQL_CONFIG_BLOCK, "password",
                        0, conf->db_config.password, 256, NULL, NULL, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc == ENOENT) {
        FILE *passfile;
        char errstr[1024];

        rc = GetStringParam(db_block, MYSQL_CONFIG_BLOCK,
                            "password_file",
                            PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS,
                            tmpstr, sizeof(tmpstr), NULL, NULL, msg_out);
        if ((rc != 0) && (rc != ENOENT))
            return rc;
        else if (rc == ENOENT) {
            strcpy(msg_out,
                   MYSQL_CONFIG_BLOCK "::password or "
                   MYSQL_CONFIG_BLOCK "::password_file must be provided");
            return ENOENT;
        }

        /* read password file and @TODO check its rights */
        passfile = fopen(tmpstr, "r");
        if (!passfile) {
            rc = errno;
            sprintf(msg_out, "Error opening password file %s : %s", tmpstr,
                    strerror(errno));
            return rc;
        }
        rc = fscanf(passfile, "%1023s", tmpstr);
        if (ferror(passfile) || rc < 1) {
            rc = errno;
            if (strerror_r(rc, errstr, sizeof(errstr))) {
                snprintf(errstr, sizeof(errstr), "%d", rc);
            }
            sprintf(msg_out, "Error reading password file %s : %s", tmpstr,
                    errstr);
            return rc;
        }
        fclose(passfile);
        rh_strncpy(conf->db_config.password, tmpstr, 256);
    }

    CheckUnknownParameters(db_block, MYSQL_CONFIG_BLOCK, db_allowed);

#elif defined(_SQLITE)
    /* get SQLite block */
    rc = get_cfg_block(config, LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK,
                       &db_block, msg_out);
    if (rc)
        return rc;

    rc = read_scalar_params(db_block, SQLITE_CONFIG_BLOCK, db_params, msg_out);
    if (rc)
        return rc;

    CheckUnknownParameters(db_block, SQLITE_CONFIG_BLOCK, db_allowed);
#endif

    return 0;
}
コード例 #6
0
ファイル: global_config.c プロジェクト: barzoj/robinhood
int ReadGlobalConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, tmpval;
    global_config_t *conf = ( global_config_t * ) module_config;

    static const char *allowed_params[] = {
        "fs_path", "fs_type", "lock_file", "stay_in_fs", "check_mounted",
        "direct_mds_stat", "fs_key",
NULL
    };

    /* get GENERAL block */
    config_item_t  general_block = rh_config_FindItemByName( config, GLOBAL_CONFIG_BLOCK );

    if ( general_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" GLOBAL_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( general_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" GLOBAL_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */

    rc = GetStringParam( general_block, GLOBAL_CONFIG_BLOCK, "fs_path",
                         PARAM_MANDATORY | STR_PARAM_ABSOLUTE_PATH |
                         STR_PARAM_REMOVE_FINAL_SLASH |
                         STR_PARAM_NO_WILDCARDS, conf->fs_path, RBH_PATH_MAX,
                         NULL, NULL, msg_out );
    if ( rc )
        return rc;

#ifdef _HAVE_FID
    rc = GetStringParam( general_block, GLOBAL_CONFIG_BLOCK, "fs_type",
                         PARAM_MANDATORY, conf->fs_type, RBH_NAME_MAX, NULL, NULL, msg_out );
    if ( ( rc != ENOENT ) && strcmp( conf->fs_type, "lustre" ) )
    {
#ifdef _LUSTRE_HSM
        strcpy( msg_out, "Only \"lustre\" filesystem type is allowed for Lustre-HSM purpose" );
#else
        strcpy( msg_out, "Robinhood is compiled for Lustre filesystem support only" );
#endif
        return EINVAL;
    }
#else
    rc = GetStringParam( general_block, GLOBAL_CONFIG_BLOCK, "fs_type",
                         PARAM_MANDATORY, conf->fs_type, RBH_NAME_MAX, NULL, NULL, msg_out );
    if ( rc )
        return rc;
#endif

    rc = GetStringParam( general_block, GLOBAL_CONFIG_BLOCK, "lock_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS,
                         conf->lock_file, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    /* /!\ stay_in_fs is a piece of bit field, it should not be passed directly: using tmpval instead */
    rc = GetBoolParam( general_block, GLOBAL_CONFIG_BLOCK, "stay_in_fs",
                       0, &tmpval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
        conf->stay_in_fs = tmpval;

    /* /!\ idem for check_mounted */
    rc = GetBoolParam( general_block, GLOBAL_CONFIG_BLOCK, "check_mounted",
                       0, &tmpval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
        conf->check_mounted = tmpval;

    /* fs_key param */
    char tmpstr[128];
    rc = GetStringParam( general_block, GLOBAL_CONFIG_BLOCK, "fs_key",
                         STR_PARAM_NO_WILDCARDS, tmpstr, 128, NULL, NULL,
                         msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if (rc == 0)
    {
        conf->fs_key = name2fskey(tmpstr);
        if (conf->fs_key == FSKEY_ERROR)
        {
            sprintf( msg_out, "Invalid type for fs_key: '%s' ('fsname', 'devid' or 'fsid' expected)", tmpstr );
            return EINVAL;
        }
    }

#if defined( _LUSTRE ) && defined( _MDS_STAT_SUPPORT )
    rc = GetBoolParam( general_block, GLOBAL_CONFIG_BLOCK,
                       "direct_mds_stat",0, &conf->direct_mds_stat,
                       NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
#endif

    /* check unknown parameters */
    CheckUnknownParameters( general_block, GLOBAL_CONFIG_BLOCK, allowed_params );


    return 0;
}
コード例 #7
0
static int log_cfg_read(config_file_t config, void *module_config,
                        char *msg_out)
{
    int rc, tmpval;
    char tmpstr[1024];
    log_config_t *conf = (log_config_t *) module_config;
    config_item_t log_block;

    /* all allowed parameters names */
    static const char * const allowed_params[] = {
        "debug_level", "log_file", "report_file",
        "alert_file", "alert_mail", "stats_interval", "batch_alert_max",
        "alert_show_attrs", "syslog_facility", "log_procname", "log_hostname",
#ifdef HAVE_CHANGELOGS
        "changelogs_file",
#endif
        NULL
    };

    /* std parameters */
    const cfg_param_t cfg_params[] = {
        {"log_file", PT_STRING,
         PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED,
         conf->log_file, sizeof(conf->log_file)}
        ,
        {"report_file", PT_STRING,
         PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED,
         conf->report_file, sizeof(conf->report_file)}
        ,
        {"alert_file", PT_STRING,
         PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED,
         conf->alert_file, sizeof(conf->alert_file)}
        ,
        {"alert_mail", PT_STRING, PFLG_MAIL,
         conf->alert_mail, sizeof(conf->alert_mail)}
        ,
#ifdef HAVE_CHANGELOGS
        {"changelogs_file", PT_STRING,
         PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED,
         conf->changelogs_file, sizeof(conf->changelogs_file)}
        ,
#endif
        /* TODO add cfg flag: clean if not found */
        {"stats_interval", PT_DURATION, PFLG_POSITIVE | PFLG_NOT_NULL,
         &conf->stats_interval, 0}
        ,
        {"batch_alert_max", PT_INT, PFLG_POSITIVE, &conf->batch_alert_max, 0}
        ,
        {"alert_show_attrs", PT_BOOL, 0, &conf->alert_show_attrs, 0}
        ,
        {"log_procname", PT_BOOL, 0, &conf->log_process, 0}
        ,
        {"log_hostname", PT_BOOL, 0, &conf->log_host, 0}
        ,

        {NULL, 0, 0, NULL, 0}
    };

    /* get Log block */
    rc = get_cfg_block(config, RBH_LOG_CONFIG_BLOCK, &log_block, msg_out);
    if (rc)
        return rc == ENOENT ? 0 : rc;   /* not mandatory */

    /* read std parameters */
    rc = read_scalar_params(log_block, RBH_LOG_CONFIG_BLOCK, cfg_params,
                            msg_out);
    if (rc)
        return rc;

    /* read specific parameters */
    rc = GetStringParam(log_block, RBH_LOG_CONFIG_BLOCK, "debug_level",
                        PFLG_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc != ENOENT) {
        tmpval = str2debuglevel(tmpstr);

        if (tmpval < 0) {
            sprintf(msg_out,
                    "Invalid value for " RBH_LOG_CONFIG_BLOCK
                    "::debug_level: '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected",
                    tmpstr);
            return EINVAL;
        } else
            conf->debug_level = tmpval;
    }

    rc = GetStringParam(log_block, RBH_LOG_CONFIG_BLOCK, "syslog_facility",
                        PFLG_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc == 0) {
        rc = check_syslog_facility(tmpstr, &conf->syslog_facility,
                                   &conf->syslog_priority);
        if (rc) {
            sprintf(msg_out,
                    "Invalid syslog channel '%s': expected syntax: <facility>[.<priority>]",
                    tmpstr);
            return rc;
        }
    }

    CheckUnknownParameters(log_block, RBH_LOG_CONFIG_BLOCK, allowed_params);

    return 0;
}
コード例 #8
0
int Read_EntryProc_Config( config_file_t config, void *module_config,
                           char *msg_out, int for_reload )
{
    int            rc, blc_index, i;
    int            tmpval;
    entry_proc_config_t *conf = ( entry_proc_config_t * ) module_config;

    char           pipeline_names[PIPELINE_STAGE_COUNT][256];
    char          *entry_proc_allowed[PIPELINE_STAGE_COUNT + 5];

    entry_proc_allowed[0] = "nb_threads";
    entry_proc_allowed[1] = "max_pending_operations";
    entry_proc_allowed[2] = "match_classes";
    entry_proc_allowed[3] = ALERT_BLOCK;

    entry_proc_allowed[PIPELINE_STAGE_COUNT + 4] = NULL;        /* PIPELINE_STAGE_COUNT+4 = last slot */

    /* get EntryProcessor block */

    config_item_t  entryproc_block = rh_config_FindItemByName( config, ENTRYPROC_CONFIG_BLOCK );

    if ( entryproc_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" ENTRYPROC_CONFIG_BLOCK "'" );
        /* No error because no parameter is mandatory  */
        return 0;
    }

    if ( rh_config_ItemType( entryproc_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" ENTRYPROC_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */

    rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "nb_threads",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      ( int * ) &conf->nb_thread, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "max_pending_operations",
                      INT_PARAM_POSITIVE,
                      ( int * ) &conf->max_pending_operations, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "match_classes",
                       0, &conf->match_classes, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;


    /* look for '<stage>_thread_max' parameters */
    for ( i = 0; i < PIPELINE_STAGE_COUNT; i++ )
    {
        char           varname[256];

        snprintf( varname, 256, "%s_threads_max", entry_proc_pipeline[i].stage_name );

        strncpy( pipeline_names[i], varname, 256 );
        entry_proc_allowed[i + 4] = pipeline_names[i];

        rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, varname,
                          INT_PARAM_POSITIVE, &tmpval, NULL, NULL, msg_out );

        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( ( rc != ENOENT ) && ( tmpval > 0 ) )  /* 0: keep default */
        {
            if ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_MAX_THREADS )
                entry_proc_pipeline[i].max_thread_count =
                    MIN2( entry_proc_pipeline[i].max_thread_count, tmpval );
            else if ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_PARALLEL )
            {
                /* the stqge is no more parallel, it has a limited number of threads */
                entry_proc_pipeline[i].stage_flags &= ~STAGE_FLAG_PARALLEL;
                entry_proc_pipeline[i].stage_flags |= STAGE_FLAG_MAX_THREADS;
                entry_proc_pipeline[i].max_thread_count = tmpval;
            }
            else if ( ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_SEQUENTIAL )
                      && ( tmpval != 1 ) )
            {
                sprintf( msg_out, "%s is sequential. Cannot use %u threads at this stage.",
                         entry_proc_pipeline[i].stage_name, tmpval );
                return EINVAL;
            }
        }

    }

    /* Find and parse "Alert" blocks */
    for ( blc_index = 0; blc_index < rh_config_GetNbItems( entryproc_block ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetItemByIndex( entryproc_block, blc_index );
        critical_err_check( curr_item, ENTRYPROC_CONFIG_BLOCK );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( curr_item, ENTRYPROC_CONFIG_BLOCK );

        if ( !strcasecmp( block_name, ALERT_BLOCK ) )
        {
            char * alert_title = NULL;

            if ( conf->alert_count == 0 )
                conf->alert_list = ( alert_item_t * ) malloc( sizeof( alert_item_t ) );
            else
                conf->alert_list =
                    ( alert_item_t * ) realloc( conf->alert_list,
                                                ( conf->alert_count + 1 )
                                                * sizeof( alert_item_t ) );

            conf->alert_count++;

            alert_title = rh_config_GetBlockId( curr_item );
            if ( alert_title != NULL )
                strncpy( conf->alert_list[conf->alert_count - 1].title,
                         alert_title, ALERT_TITLE_MAX );
            else
                conf->alert_list[conf->alert_count - 1].title[0] = '\0';

            /* analyze boolean expression */
            rc = GetBoolExpr( curr_item, block_name,
                              &conf->alert_list[conf->alert_count - 1].boolexpr,
                              &conf->alert_list[conf->alert_count - 1].attr_mask, msg_out );

            if ( rc )
                return rc;

            conf->alert_attr_mask |= conf->alert_list[conf->alert_count - 1].attr_mask;
        }
    }                           /* Loop on subblocks */

    CheckUnknownParameters( entryproc_block, ENTRYPROC_CONFIG_BLOCK,
                            ( const char ** ) entry_proc_allowed );

    return 0;
}
コード例 #9
0
ファイル: RobinhoodLogs.c プロジェクト: bringhurst/robinhood
int ReadLogConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, tmpval;
    char           tmpstr[1024];
    log_config_t  *conf = ( log_config_t * ) module_config;

    static const char *allowed_params[] = { "debug_level", "log_file", "report_file",
        "alert_file", "alert_mail", "stats_interval", "batch_alert_max",
        "alert_show_attrs", "syslog_facility",
        NULL
    };

    /* get Log block */

    config_item_t  log_block = rh_config_FindItemByName( config, RBH_LOG_CONFIG_BLOCK );

    if ( log_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" RBH_LOG_CONFIG_BLOCK "'" );
        /* no parameter is mandatory => Not an error */
        return 0;
    }

    if ( rh_config_ItemType( log_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out, "A block is expected for '" RBH_LOG_CONFIG_BLOCK "' item, line %d",
                 rh_config_GetItemLine( log_block ) );
        return EINVAL;
    }

    /* retrieve parameters */

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "debug_level",
                         STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
    {
        tmpval = str2debuglevel( tmpstr );

        if ( tmpval < 0 )
        {
            sprintf( msg_out,
                     "Invalid value for " RBH_LOG_CONFIG_BLOCK
                     "::debug_level: '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected",
                     tmpstr );
            return EINVAL;
        }
        else
            conf->debug_level = tmpval;
    }

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "log_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->log_file, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "report_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->report_file, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->alert_file, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
        conf->alert_file[0] = '\0';

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "syslog_facility",
                         STR_PARAM_NO_WILDCARDS,
                         tmpstr, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
    {
        rc = check_syslog_facility( tmpstr, &conf->syslog_facility,
                                    &conf->syslog_priority );
        if (rc)
        {
            sprintf( msg_out, "Invalid syslog channel '%s': expected syntax: <facility>[.<priority>]",
                     tmpstr );
            return rc;
        }
    }

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_mail",
                         STR_PARAM_MAIL, conf->alert_mail, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
        conf->alert_mail[0] = '\0';

    rc = GetDurationParam( log_block, RBH_LOG_CONFIG_BLOCK, "stats_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, &tmpval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
        conf->stats_interval = tmpval;

    rc = GetIntParam( log_block, RBH_LOG_CONFIG_BLOCK, "batch_alert_max",
                      INT_PARAM_POSITIVE, (int *)&conf->batch_alert_max,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_show_attrs",
                      INT_PARAM_POSITIVE, &conf->alert_show_attrs,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( log_block, RBH_LOG_CONFIG_BLOCK, allowed_params );

    return 0;
}
コード例 #10
0
ファイル: fs_scan_main.c プロジェクト: mjtrangoni/robinhood
int FSScan_ReadConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, blc_index;
    fs_scan_config_t *conf = ( fs_scan_config_t * ) module_config;
    int scan_intl_set = FALSE;
    int scan_intl = 0;

    static const char * fsscan_allowed[] =
    {
        "scan_interval", "min_scan_interval", "max_scan_interval",
        "scan_retry_delay", "nb_threads_scan", "scan_op_timeout",
        "exit_on_timeout", "spooler_check_interval", "nb_prealloc_tasks",
		"completion_command",
        IGNORE_BLOCK, NULL
    };

    /* get FS Scan block */

    config_item_t  fsscan_block = rh_config_FindItemByName( config, FSSCAN_CONFIG_BLOCK );

    if ( fsscan_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" FSSCAN_CONFIG_BLOCK "'" );
        /* No error because no parameter is mandatory  */
        return 0;
    }

    if ( rh_config_ItemType( fsscan_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" FSSCAN_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */
    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "min_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->min_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "max_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->max_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           &scan_intl, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
    {
        if (scan_intl_set)
        {
            strcpy( msg_out, "scan_interval parameter cannot be used with min/max_scan_interval" );
            return EINVAL;
        }
        conf->min_scan_interval = scan_intl;
        conf->max_scan_interval = scan_intl;
    }

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_retry_delay",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->scan_retry_delay, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                      "nb_threads_scan",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      ( int * ) &conf->nb_threads_scan, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "scan_op_timeout",
                            INT_PARAM_POSITIVE,    /* 0 is authorized => no timeout */
                           ( int * ) &conf->scan_op_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "exit_on_timeout", 0,
                       (int*)&conf->exit_on_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "spooler_check_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->spooler_check_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "nb_prealloc_tasks",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->nb_prealloc_tasks, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "completion_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {cfg} or {fspath} */
                         conf->completion_command, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;


    /* Find and parse "ignore" blocks */
    for ( blc_index = 0; blc_index < rh_config_GetNbItems( fsscan_block ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetItemByIndex( fsscan_block, blc_index );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( !strcasecmp( block_name, IGNORE_BLOCK ) )
        {
            if ( conf->ignore_count == 0 )
                conf->ignore_list = ( whitelist_item_t * ) malloc( sizeof( whitelist_item_t ) );
            else
                conf->ignore_list =
                    ( whitelist_item_t * ) realloc( conf->ignore_list,
                                                 ( conf->ignore_count + 1 )
                                                 * sizeof( whitelist_item_t ) );

            conf->ignore_count++;

            /* analyze boolean expression */
            rc = GetBoolExpr( curr_item, block_name,
                              &conf->ignore_list[conf->ignore_count - 1].bool_expr,
                              &conf->ignore_list[conf->ignore_count - 1].attr_mask, msg_out );

            if ( rc )
                return rc;

        }
    }                           /* Loop on subblocks */

    CheckUnknownParameters( fsscan_block, FSSCAN_CONFIG_BLOCK, fsscan_allowed );

    return 0;

}
コード例 #11
0
ファイル: policy_run_cfg.c プロジェクト: cea-hpc/robinhood
static int polrun_read_config(config_file_t config, const char *policy_name,
                              const struct sm_instance *smi,
                              policy_run_config_t *conf, char *msg_out)
{
    int rc;
    char block_name[1024];
    char tmp[1024];
    config_item_t param_block, action_params_block;
    char **extra = NULL;
    unsigned int extra_cnt = 0;

    /* parameter for CheckUnknownParams() */
    static const char *allowed[] = {
        "lru_sort_attr", "max_action_count",
        "max_action_volume", "nb_threads", "suspend_error_pct",
        "suspend_error_min", "report_interval", "action_timeout",
        "check_actions_interval", "check_actions_on_startup",
        "recheck_ignored_entries", "report_actions",
        "pre_maintenance_window", "maint_min_apply_delay", "queue_size",
        "db_result_size_max", "action_params", "action",
        "recheck_ignored_classes",  /* for compat */
        NULL
    };

    /* parameter for read_scalar_params() */
    const cfg_param_t cfg_params[] = {
        {   "max_action_count", PT_INT, PFLG_POSITIVE,
            &conf->max_action_nbr, 0
        },
        {   "max_action_volume", PT_SIZE, PFLG_POSITIVE,
            &conf->max_action_vol, 0
        },
        {   "nb_threads", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL,
            &conf->nb_threads, 0
        },
        {   "suspend_error_pct", PT_FLOAT, PFLG_POSITIVE | PFLG_ALLOW_PCT_SIGN,
            &conf->suspend_error_pct, 0
        },
        {   "suspend_error_min", PT_INT, PFLG_POSITIVE,
            &conf->suspend_error_min, 0
        },
        {   "report_interval", PT_DURATION, PFLG_POSITIVE | PFLG_NOT_NULL,
            &conf->report_interval, 0
        },
        {   "action_timeout", PT_DURATION, PFLG_POSITIVE,
            &conf->action_timeout, 0
        },
        {   "check_actions_interval", PT_DURATION, PFLG_POSITIVE,
            &conf->check_action_status_delay, 0
        },
        {   "check_actions_on_startup", PT_BOOL, 0,
            &conf->check_action_status_on_startup, 0
        },
        {   "recheck_ignored_entries", PT_BOOL, 0,
            &conf->recheck_ignored_entries, 0
        },
        {"report_actions", PT_BOOL, 0, &conf->report_actions, 0},
        {   "pre_maintenance_window", PT_DURATION, PFLG_POSITIVE,
            &conf->pre_maintenance_window, 0
        },
        {   "maint_min_apply_delay", PT_DURATION, PFLG_POSITIVE,
            &conf->maint_min_apply_delay, 0
        },
        {   "queue_size", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL,
            &conf->queue_size, 0
        },
        {   "db_result_size_max", PT_INT, PFLG_POSITIVE,
            &conf->db_request_limit, 0
        },

        {NULL, 0, 0, NULL, 0}
    };
    snprintf(block_name, sizeof(block_name), "%s" PARAM_SUFFIX, policy_name);

    /* get <policy>_parameters block */
    rc = get_cfg_block(config, block_name, &param_block, msg_out);
    if (rc)
        return rc == ENOENT ? 0 : rc;   /* not mandatory */

    /* check deprecated parameters */
    rc = GetBoolParam(param_block, block_name, "recheck_ignored_classes", 0,
                      &conf->recheck_ignored_entries, NULL, NULL, msg_out);
    if (rc == 0)
        DisplayLog(LVL_CRIT, TAG, "WARNING: parameter %s::%s' is deprecated. "
                   "Use 'recheck_ignored_entries' instead.",
                   block_name, "recheck_ignored_classes");

    /* read all scalar params */
    rc = read_scalar_params(param_block, block_name, cfg_params, msg_out);
    if (rc)
        return rc;

    /* read specific parameters */

    /* 'lru_sort_attr' overrides 'default_lru_sort_attr' from 'define_policy' */
    rc = GetStringParam(param_block, block_name, "lru_sort_attr",
                        PFLG_NO_WILDCARDS, tmp, sizeof(tmp), NULL, NULL,
                        msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc != ENOENT) {
        /* is it a time attribute? */
        rc = str2lru_attr(tmp, smi);
        if (rc == LRU_ATTR_INVAL) {
            strcpy(msg_out, "time attribute expected for 'lru_sort_attr': "
                   ALLOWED_LRU_ATTRS_STR "...");
            return EINVAL;
        } else
            conf->lru_sort_attr = rc;
    }

    /* 'action' overrides 'default_action' from 'define_policy' */
    rc = GetStringParam(param_block, block_name, "action",
                        0, tmp, sizeof(tmp), &extra, &extra_cnt, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;
    else if (rc != ENOENT) {
        rc = parse_policy_action("action", tmp, extra, extra_cnt,
                                 &conf->action, &conf->run_attr_mask, msg_out);
        if (rc)
            return rc;
    }

    /* get subblock */
    bool unique = true;
    action_params_block =
        rh_config_GetItemByName(param_block, "action_params", &unique);
    if (action_params_block != NULL) {
        if (!unique) {
            sprintf(msg_out, "Found duplicate block '%s' in '%s' line %d.",
                    "action_params", block_name,
                    rh_config_GetItemLine(action_params_block));
            return EEXIST;
        }
        if (rh_config_ItemType(action_params_block) != CONFIG_ITEM_BLOCK) {
            sprintf(msg_out,
                    "A block is expected for configuration item '%s::action_params', line %d.",
                    block_name, rh_config_GetItemLine(action_params_block));
            return EINVAL;
        }
#ifdef _DEBUG_POLICIES
        fprintf(stderr, "processing parameters in '%s'\n", block_name);
#endif
        rc = read_action_params(action_params_block, &conf->action_params,
                                &conf->run_attr_mask, msg_out);
        if (rc)
            return rc;
    }

    /* warn for unknown parameters */
    CheckUnknownParameters(param_block, block_name, allowed);

    return 0;
}
コード例 #12
0
ファイル: policy_run_cfg.c プロジェクト: cea-hpc/robinhood
/** parse a trigger block from configuration and fills a trigger item */
static int parse_trigger_block(config_item_t config_blk, const char *block_name,
                               trigger_item_t *p_trigger_item, char *msg_out)
{
    int rc;
    char tmpstr[1024];
    char **arg_tab;
    unsigned int arg_count;
    config_item_t params_block;

    const struct trig_target_def *def;

    static const char *trigger_expect[] = {
        "trigger_on", "check_interval",
        "high_threshold_pct", "low_threshold_pct",
        "high_threshold_vol", "low_threshold_vol",
        "high_threshold_cnt", "low_threshold_cnt",
        "alert_high", "alert_low", "post_trigger_wait",
        "action_params", "max_action_count", "max_action_volume",
        NULL
    };

    const cfg_param_t cfg_params[] = {
        {   "max_action_count", PT_INT, PFLG_POSITIVE,
            &p_trigger_item->max_action_nbr, 0
        },
        {   "max_action_volume", PT_SIZE, PFLG_POSITIVE,
            &p_trigger_item->max_action_vol, 0
        },
        {   "check_interval", PT_DURATION,
            PFLG_POSITIVE | PFLG_NOT_NULL | PFLG_MANDATORY,
            &p_trigger_item->check_interval, 0
        },
        {   "alert_high", PT_BOOL, 0,
            &p_trigger_item->alert_hw, 0
        },
        {   "alert_low", PT_BOOL, 0,
            &p_trigger_item->alert_lw, 0
        },
        {   "post_trigger_wait", PT_DURATION, 0,
            &p_trigger_item->post_trigger_wait, 0
        },
        END_OF_PARAMS
    };

    memset(p_trigger_item, 0, sizeof(*p_trigger_item));

    /* retrieve special parameters */
    rc = GetStringParam(config_blk, block_name, "trigger_on",
                        PFLG_MANDATORY | PFLG_NO_WILDCARDS, tmpstr,
                        sizeof(tmpstr), &arg_tab, &arg_count, msg_out);
    if (rc) /* even ENOENT retruns an error because trigger_on is mandatory */
        return rc;

    /* initialize list of optional args */
    p_trigger_item->list = NULL;
    p_trigger_item->list_size = 0;

    def = str2trigger_def(tmpstr);
    if (def == NULL) {
        sprintf(msg_out, "Unexpected value for 'trigger_on' parameter: %s.",
                tmpstr);
        return EINVAL;
    }
    rc = set_trigger_target(p_trigger_item, def, arg_tab, arg_count, msg_out);
    if (rc)
        return rc;

    /* retrieve high and low thresholds params and check their compatibility */
    rc = read_threshold_params(config_blk, block_name, "high", p_trigger_item,
                               &p_trigger_item->hw_type, &p_trigger_item->hw_u,
                               msg_out);
    if (rc)
        return rc;

    rc = read_threshold_params(config_blk, block_name, "low", p_trigger_item,
                               &p_trigger_item->lw_type, &p_trigger_item->lw_u,
                               msg_out);
    if (rc)
        return rc;

    if ((p_trigger_item->trigger_type != TRIG_ALWAYS)
            && (p_trigger_item->hw_type != p_trigger_item->lw_type)) {
        strcpy(msg_out, "Incompatible high/low threshold types");
        return EINVAL;
    }
    /** FIXME RBHv3 count threshold for HSM systems should only match online
     *  files (not released) */

    /* retrieve other scalar parameters */
    rc = read_scalar_params(config_blk, block_name, cfg_params, msg_out);
    if (rc)
        return rc;

    /* get action_params subblock */
    bool unique = true;
    params_block =
        rh_config_GetItemByName(config_blk, "action_params", &unique);

    if (params_block != NULL) {
        if (!unique) {
            sprintf(msg_out, "Found duplicate block '%s' in '%s' line %d.",
                    "action_params", block_name,
                    rh_config_GetItemLine(params_block));
            return EEXIST;
        }
        if (rh_config_ItemType(params_block) != CONFIG_ITEM_BLOCK) {
            sprintf(msg_out,
                    "A block is expected for configuration item '%s::action_params', line %d.",
                    block_name, rh_config_GetItemLine(params_block));
            return EINVAL;
        }
#ifdef _DEBUG_POLICIES
        fprintf(stderr, "processing parameters for trigger '%s'\n", block_name);
#endif
        rc = read_action_params(params_block, &p_trigger_item->action_params,
                                &p_trigger_item->params_mask, msg_out);
        if (rc)
            return rc;
    }

    CheckUnknownParameters(config_blk, block_name, trigger_expect);

    return 0;
}