]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
JAM: upgraded daq_disk to check if target partition is still accessible
authorhadaq <hadaq>
Tue, 14 Feb 2012 14:01:10 +0000 (14:01 +0000)
committerhadaq <hadaq>
Tue, 14 Feb 2012 14:01:10 +0000 (14:01 +0000)
First committed version, to be tested.

disks/daq_disks
disks/disks.c

index 2eeb2f34ea7c193e38eee04b25cf8dc34a28aa7c..b99e3b97b037e11a6796b803eff0c7d9e4232145 100755 (executable)
Binary files a/disks/daq_disks and b/disks/daq_disks differ
index a42578145343f90b08af469e9c8f877896dc6fc8..675c187952afd77cdf67bf45c6bb933f367faf0f 100644 (file)
@@ -5,16 +5,21 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <assert.h>
+#include <errno.h>
 
 #include "shmtrans.h"
 #include "worker.h" 
 
-#define BUFFSIZE = 10000
+#define BUFLEN  200
+#define NUMDISKS 22
+#define NUMEBS 16
+
+
 
 FILE *popen(const char *, const char *);
 char *strdup(const char *);
 
-const char data[22][8] = {"/data01", "/data02", "/data03", "/data04", "/data05",
+const char data[NUMDISKS][8] = {"/data01", "/data02", "/data03", "/data04", "/data05",
                          "/data06", "/data07", "/data08", "/data09", "/data10",
                          "/data11", "/data12", "/data13", "/data14", "/data15",
                          "/data16", "/data17", "/data18", "/data19", "/data20",
@@ -24,38 +29,45 @@ const char space[] = " ";
 
 char diskNum[] = "diskNum";
 
-int data_disks[22];                 /* Available disk space */
+int data_disks[NUMDISKS];                 /* Available disk space */
 
 char shmemBase[] = "daq_evtbuild";  /* Base name for shared memory segments */
-int shmem_nums[16];                 /* Numbers for found shared memory segments */
+int shmem_nums[NUMEBS];                 /* Numbers for found shared memory segments */
 int nrOfShmSegms;                   /* Total number of found shared memory segments */
 
 typedef struct TheArgsS {
-  int excludeDisks[22];
+  int excludeDisks[NUMDISKS];
   int excludeDisksCnt;
   int sleepTime;   /*seconds*/
+  int testPartition; 
   int debug;
 } TheArgs;
 
 static void usage(const char *progName)
 {
-        printf( "Usage: %s\n", progName);
-       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");
+  printf( "daq_disks V 1.1  14-Feb-2012 \n");
+  printf( "  authors: Sergei Yurevich\n");
+  printf( "           Joern Adamczewski-Musch (j.adamczewski@gsi.de)\n");
+  printf( "Eventbuilder disk load balancer for HADES\n");
+  printf( "Usage: %s\n", progName);
+  printf( "       [-h|--help]              : Print this help.\n");
+  printf( "       [-e|--exclude <diskNr>]  : Nr of disk to exclude.\n");
+  printf( "       [-a|--autoexclude]       : Automatically exclude broken partition.\n");
+  printf( "       [-s|--sleep <time>]      : Sleep time.\n");
+  printf( "       [-D|--debug]             : Debug output.\n");
 }
 
 static void argsDefault(TheArgs *my)
 {
   my->sleepTime = 10;
   my->debug     = 0; 
+  my->testPartition = 0;
 
   my->excludeDisksCnt = 0;
 
   /* Initialize the array with shared mem segment numbers */
   int i;
-  for(i=0; i<16; i++){
+  for(i=0; i<NUMEBS; i++){
     shmem_nums[i] = -1;
   }
 }
@@ -72,10 +84,11 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                        {"help", 0, 0, 'h'},
                        {"sleep", 1, 0, 's'},
                        {"exclude", 1, 0, 'e'},
+                       {"autoexclude", 0, 0, 'a'},
                        {"debug", 0, 0, 'D'},
                        {0, 0, 0, 0}
                };
-               i = getopt_long(argc, argv, "Dhs:e:", long_options,
+               i = getopt_long(argc, argv, "Dhas:e:", long_options,
                                &option_index);
                if (i == -1)
                        break;
@@ -89,10 +102,14 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                case 'e':
                        my->excludeDisks[my->excludeDisksCnt] = atoi(optarg);
                        my->excludeDisksCnt++;
-                       break;
+               case 'a':
+                       my->testPartition=1;
+                       break;
+               
                case 'D':
                        my->debug = 1;
                        break;
+                       
                default:
                        usage(argv[0]);
                        return -1;
@@ -117,11 +134,36 @@ static int excludeDisks(TheArgs *theArgs, int diskNr)
   return retval;
 }
 
+
+static int testPartition(TheArgs *theArgs, int diskIndex)
+{
+  /* return 1 if partition is writable, 0 otherwise*/
+  int err;
+  char fname[BUFLEN] = "";
+  
+  if((diskIndex<0) || (diskIndex>=NUMDISKS)) return 0;
+  if(theArgs->testPartition==0) return 1;
+  snprintf(fname,BUFLEN,"%s/data/daqDiskCheck",data[diskIndex]);
+  if(theArgs->debug)
+    printf("Debug: testPartition  %d with file %s\n", diskIndex, fname);
+  FILE* tfile = fopen(fname, "w+");
+  if(tfile==NULL) {
+    err=errno; /* save errno not to be modified by printf...*/
+    printf("Error: testPartition for %s  failed  with errno %d - %s\n",data[diskIndex], errno, strerror(err));    
+    return 0;
+  } 
+  if(theArgs->debug)
+    printf("Debug: testPartition for %s  OK\n",data[diskIndex]);
+  fclose(tfile);
+  return 1;
+}
+
+
 static void initDataDisks(int val)
 {
   int i;
 
-  for(i=0; i<22; i++){
+  for(i=0; i<NUMDISKS; i++){
     data_disks[i] = val;
   }
 }
@@ -131,18 +173,18 @@ static int checkDisks(TheArgs *theArgs)
   /* Read the available disk space with 'df' */
 
   int  count;
-  char buff[200] = "";
+  char buff[BUFLEN] = "";
   FILE* stream = popen("/bin/df -m", "r");
 
   char **array;
-  array = malloc( sizeof(char *) * 100 );
+  array = malloc( sizeof(char *) * BUFLEN );
   assert(array != NULL);
 
   count = 0;
 
   while (1)
   {
-    fgets( buff, 200, stream );
+    fgets( buff, BUFLEN, stream );
     if( feof(stream) )
       break;
 
@@ -160,7 +202,7 @@ static int checkDisks(TheArgs *theArgs)
   for( ; *array != NULL; array++ ){
 
     int k;
-    for(k=0; k<22; k++){
+    for(k=0; k<NUMDISKS; k++){
 
       /* Exclude disks */
       if(excludeDisks(theArgs, k+1))
@@ -171,6 +213,10 @@ static int checkDisks(TheArgs *theArgs)
       if(ptr == NULL)
        continue;
 
+      /* New: test if partition is writable*/
+      if(!testPartition(theArgs, k))
+       continue;
+
       /* Split string by spaces */
       strcpy(tmp,*array);
       token = strtok(tmp, space);     /* token => "Filesystem" */
@@ -188,7 +234,7 @@ static int checkDisks(TheArgs *theArgs)
 
   if(theArgs->debug){
     int i;
-    for(i=0; i<22; i++){
+    for(i=0; i<NUMDISKS; i++){
       printf("Debug: sizes[%2d] = %d\n", i, data_disks[i]);
     }
   }
@@ -213,7 +259,7 @@ static int findMaxElement( int tmp[] ){
   int maxElement = 0;
   int maxIndex = 0;
 
-  for( k=0; k<22; k++ ){
+  for( k=0; k<NUMDISKS; k++ ){
     if( tmp[k] > maxElement ){
       maxElement = tmp[k];
       maxIndex   = k;
@@ -232,18 +278,18 @@ static int writeShmem(TheArgs *theArgs)
 
   int i;
   char shmemName[20];
-  int tmp_data_disks[22];
+  int tmp_data_disks[NUMDISKS];
   int diskSpace;
   int diskIndex;
   unsigned long int iMax;
   unsigned long int freeDiskNr;
 
   /* Temp copy of array with free disk space */
-  for(i=0; i<22; i++){
+  for(i=0; i<NUMDISKS; i++){
     tmp_data_disks[i] = data_disks[i];
   }
 
-  for(i=0; i<16; i++){
+  for(i=0; i<NUMEBS; i++){
 
     /* The array contains endings (EB numbers) of shared memory names
      * which contain diskNum variable. 
@@ -271,18 +317,18 @@ static int writeShmem(TheArgs *theArgs)
 static int findShmem(TheArgs *theArgs)
 {
   /*
-   *  Loop over all EB numbers (1..16)
+   *  Loop over all EB numbers (1..NUMEBS)
    *  and find shared memory segments opened by daq_evtbuild.
    *  Save them in a shmem_nums array.
    */
 
-  char shmemName[100];
-  char shmemPathName[100];
+  char shmemName[BUFLEN];
+  char shmemPathName[BUFLEN];
   int i;
   int j = 0;
   unsigned long int tmp;
 
-  for(i=0; i<17; i++){
+  for(i=0; i<=NUMEBS; i++){
     sprintf( shmemName, "%s%d", shmemBase, i );
     sprintf( shmemPathName, "/dev/shm/%s%d.shm", shmemBase, i );