/* * NAME: meta_raid_resync_all * DESCRIPTION: loop through the RAID devices synch'ing all * PARAMETERS: char *sp - the set to synch * daddr_t size - resync size * md_error_t *ep - return error info * */ int meta_raid_resync_all( mdsetname_t *sp, daddr_t size, md_error_t *ep ) { mdnamelist_t *nlp = NULL; mdnamelist_t *p; int rval = 0, fval; /* should have a set */ assert(sp != NULL); /* get raids */ if (meta_get_raid_names(sp, &nlp, 0, ep) < 0) return (-1); /* fork a process */ if ((fval = md_daemonize(sp, ep)) != 0) { /* * md_daemonize forks off a process to do the work. This * is the parent or errror. */ if (fval > 0) { if (nlp != NULL) metafreenamelist(nlp); return (0); } mdclrerror(ep); } assert((fval == 0) || (fval == -1)); /* resync each raid */ for (p = nlp; (p != NULL); p = p->next) { mdname_t *raidnp = p->namep; if (meta_raid_resync(sp, raidnp, size, ep) != 0) rval = -1; } /* cleanup, return success */ if (nlp != NULL) metafreenamelist(nlp); if (fval == 0) exit(0); return (rval); }
// program execution starts here! int main( int argc, char** argv ) { curl_global_init(CURL_GLOBAL_ALL); // start up protocol buffers GOOGLE_PROTOBUF_VERIFY_VERSION; g_config_file = strdup( METADATA_DEFAULT_CONFIG ); // process command-line options int c; int rc; bool make_daemon = true; bool good_input = true; char* mc_root = NULL; char* logfile = NULL; char* pidfile = NULL; int portnum = 0; int reload_pid = 0; while((c = getopt(argc, argv, "fc:m:p:u:l:P:k:")) != -1) { switch( c ) { case 'f': { make_daemon = false; break; } case '?': { usage( argv[0], 1 ); } case 'c': { g_config_file = realpath( optarg, NULL ); break; } case 'm': { mc_root = realpath( optarg, NULL ); break; } case 'P': { portnum = strtol( optarg, NULL, 10 ); if( portnum <= 0 ) good_input = false; break; } case 'u': { g_secrets_file = realpath( optarg, NULL ); break; } case 'l': { logfile = strdup( optarg ); break; } case 'p': { pidfile = realpath( optarg, NULL ); break; } case 'k': { reload_pid = strtol( optarg, NULL, 10 ); if( reload_pid <= 0 ) good_input = false; break; } default: { fprintf(stderr, "Ignoring unrecognized option %c\n", c); good_input = false; break; } } } if( !good_input ) { usage( argv[0], 1 ); } if( reload_pid > 0 ) { // all we're doing is telling a running metadata server to reload kill( reload_pid, SIGUSR1 ); exit(0); } // read the config struct md_syndicate_conf conf; g_conf = &conf; dbprintf("reading config %s\n", g_config_file); if( md_read_conf( g_config_file, &conf ) != 0 ) { errorf("Could not read config at %s\n", g_config_file); usage( argv[0], 1 ); } // user-given portnum? if( portnum > 0 ) { conf.portnum = portnum; } if( conf.portnum == 0 ) { errorf("Invalid port number %d. Specify PORTNUM in the config file or pass -p\n", conf.portnum); exit(1); } // master copy supplied in args? if( mc_root ) { if( conf.master_copy_root ) { free( conf.master_copy_root ); } conf.master_copy_root = mc_root; } // secrets file supplied in args? if( g_secrets_file ) { if( conf.secrets_file ) { free( conf.secrets_file ); } conf.secrets_file = g_secrets_file; } else if( conf.secrets_file ) { g_secrets_file = strdup( conf.secrets_file ); } // pidfile supplied in args? if( pidfile ) { if( conf.md_pidfile_path ) { free( conf.md_pidfile_path ); } conf.md_pidfile_path = pidfile; } dbprintf("%s", "initializing libsyndicate\n"); // set the config if( md_init( &conf, NULL ) != 0 ) exit(1); md_connect_timeout( conf.query_timeout ); md_signals( 0 ); // no signals dbprintf("reading users file %s\n", conf.secrets_file ); // read the users file struct md_user_entry **users = NULL; if( conf.secrets_file ) { users = md_parse_secrets_file( conf.secrets_file ); if( users == NULL ) { exit(1); } } else { errorf("No secrets file given. Pass -u or specify a value for %s in the config\n", SECRETS_FILE_KEY ); usage( argv[0], 1 ); } // need to daemonize? if( make_daemon ) { FILE* log = NULL; rc = md_daemonize( logfile, conf.md_pidfile_path, &log ); if( rc < 0 ) { errorf("md_daemonize rc = %d\n", rc ); exit(1); } if( log ) conf.md_logfile = log; } // setup the reload semaphore sem_init( &reload_sem, 0, 0 ); reload_thread = md_start_thread( reloader, NULL, true ); // start HTTP rc = http_init( &http, &conf, users ); if( rc != 0 ) { exit(1); } // start validator rc = validator_init( &conf ); if( rc != 0 ) { exit(1); } setup_signals(); while( 1 ) { sleep(1); } // we never reach this point--the signal handler cleans up return 0; }