From: hadaq <hadaq> Date: Mon, 27 Sep 2010 15:54:10 +0000 (+0000) Subject: Option to exclude disks added. Sergey. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=0f1b6ef5a093637ae3908db91712ab3b164d3f85;p=daqdata.git Option to exclude disks added. Sergey. --- diff --git a/disks/disks.c b/disks/disks.c index 4d644c7..a425781 100644 --- a/disks/disks.c +++ b/disks/disks.c @@ -31,6 +31,8 @@ int shmem_nums[16]; /* Numbers for found shared memory segments int nrOfShmSegms; /* Total number of found shared memory segments */ typedef struct TheArgsS { + int excludeDisks[22]; + int excludeDisksCnt; int sleepTime; /*seconds*/ int debug; } TheArgs; @@ -38,9 +40,10 @@ typedef struct TheArgsS { static void usage(const char *progName) { printf( "Usage: %s\n", progName); - printf( " [-h|--help] : Print this help.\n"); - printf( " [-s|--sleep <time>] : Sleep time.\n"); - printf( " [-D|--debug] : Debug output.\n"); + printf( " [-h|--help] : Print this help.\n"); + printf( " [-e|--exclude <diskNr>] : Nr of disk to exclude.\n"); + printf( " [-s|--sleep <time>] : Sleep time.\n"); + printf( " [-D|--debug] : Debug output.\n"); } static void argsDefault(TheArgs *my) @@ -48,6 +51,8 @@ static void argsDefault(TheArgs *my) my->sleepTime = 10; my->debug = 0; + my->excludeDisksCnt = 0; + /* Initialize the array with shared mem segment numbers */ int i; for(i=0; i<16; i++){ @@ -66,10 +71,11 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[]) static struct option long_options[] = { {"help", 0, 0, 'h'}, {"sleep", 1, 0, 's'}, + {"exclude", 1, 0, 'e'}, {"debug", 0, 0, 'D'}, {0, 0, 0, 0} }; - i = getopt_long(argc, argv, "Dhs:", long_options, + i = getopt_long(argc, argv, "Dhs:e:", long_options, &option_index); if (i == -1) break; @@ -78,8 +84,12 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[]) return -1; break; case 's': - my->sleepTime = strtoul(optarg, NULL, 0); + my->sleepTime = atoi(optarg); break; + case 'e': + my->excludeDisks[my->excludeDisksCnt] = atoi(optarg); + my->excludeDisksCnt++; + break; case 'D': my->debug = 1; break; @@ -92,7 +102,31 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[]) return 0; } -int checkDisks(TheArgs *theArgs) +static int excludeDisks(TheArgs *theArgs, int diskNr) +{ + int retval = 0; + int i; + + for(i=0; i<theArgs->excludeDisksCnt; i++){ + if(theArgs->excludeDisks[i] == diskNr){ + retval = 1; + break; + } + } + + return retval; +} + +static void initDataDisks(int val) +{ + int i; + + for(i=0; i<22; i++){ + data_disks[i] = val; + } +} + +static int checkDisks(TheArgs *theArgs) { /* Read the available disk space with 'df' */ @@ -128,6 +162,10 @@ int checkDisks(TheArgs *theArgs) int k; for(k=0; k<22; k++){ + /* Exclude disks */ + if(excludeDisks(theArgs, k+1)) + continue; + /* Find string with info on the data disks */ ptr = strstr(*array, data[k]); if(ptr == NULL) @@ -158,7 +196,7 @@ int checkDisks(TheArgs *theArgs) return 0; } -int cleanup(TheArgs *theArgs) +static int cleanup(TheArgs *theArgs) { /* There is a Perl script which runs as a daemon and performs cleanup * (removes oldest files from disks) thus we do here nothing. @@ -167,7 +205,7 @@ int cleanup(TheArgs *theArgs) return 0; } -int findMaxElement( int tmp[] ){ +static int findMaxElement( int tmp[] ){ /* Function returns index of max element of the array */ @@ -185,7 +223,7 @@ int findMaxElement( int tmp[] ){ return maxIndex; } -int writeShmem(TheArgs *theArgs) +static int writeShmem(TheArgs *theArgs) { /* Loop over all found shared mem segments * and write there disk numbers which have @@ -230,7 +268,7 @@ int writeShmem(TheArgs *theArgs) return 0; } -int findShmem(TheArgs *theArgs) +static int findShmem(TheArgs *theArgs) { /* * Loop over all EB numbers (1..16) @@ -278,6 +316,7 @@ int main(int argc, char *argv[]) } while(1){ + initDataDisks(0); checkDisks(theArgs); findShmem(theArgs); writeShmem(theArgs);