src/dird/next_vol.c
bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr)
{
   bool expired = false;
   char ed1[50];
   /*
    * Check limits and expirations if "Append" and it has been used
    * i.e. mr->VolJobs > 0
    *
    */
   if (strcmp(mr->VolStatus, "Append") == 0 && mr->VolJobs > 0) {
      /* First handle Max Volume Bytes */
      if ((mr->MaxVolBytes > 0 && mr->VolBytes >= mr->MaxVolBytes)) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume bytes=%s exceeded. "
             "Marking Volume \"%s\" as Full.\n"),
             edit_uint64_with_commas(mr->MaxVolBytes, ed1), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Full", sizeof(mr->VolStatus));
         expired = true;

      /* Now see if Volume should only be used once */
      } else if (mr->VolBytes > 0 && jcr->pool->use_volume_once) {
         Jmsg(jcr, M_INFO, 0, _("Volume used once. "
             "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;

      /* Now see if Max Jobs written to volume */
      } else if (mr->MaxVolJobs > 0 && mr->MaxVolJobs <= mr->VolJobs) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume jobs=%s exceeded. "
             "Marking Volume \"%s\" as Used.\n"),
             edit_uint64_with_commas(mr->MaxVolJobs, ed1), mr->VolumeName);
         Dmsg3(dbglvl, "MaxVolJobs=%d JobId=%d Vol=%s\n", mr->MaxVolJobs,
               (uint32_t)jcr->JobId, mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;

      /* Now see if Max Files written to volume */
      } else if (mr->MaxVolFiles > 0 && mr->MaxVolFiles <= mr->VolFiles) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume files=%s exceeded. "
             "Marking Volume \"%s\" as Used.\n"),
             edit_uint64_with_commas(mr->MaxVolFiles, ed1), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;

      /* Finally, check Use duration expiration */
      } else if (mr->VolUseDuration > 0) {
         utime_t now = time(NULL);
         /* See if Vol Use has expired */
         if (mr->VolUseDuration <= (now - mr->FirstWritten)) {
            Jmsg(jcr, M_INFO, 0, _("Max configured use duration=%s sec. exceeded. "
               "Marking Volume \"%s\" as Used.\n"),
               edit_uint64_with_commas(mr->VolUseDuration, ed1), mr->VolumeName);
            bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
            expired = true;
         }
      }
   }
   if (expired) {
      /* Need to update media */
      Dmsg1(dbglvl, "Vol=%s has expired update media record\n", mr->VolumeName);
      set_storageid_in_mr(NULL, mr);
      if (!db_update_media_record(jcr, jcr->db, mr)) {
         Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
              mr->VolumeName, db_strerror(jcr->db));
      }
   }
   Dmsg2(dbglvl, "Vol=%s expired=%d\n", mr->VolumeName, expired);
   return expired;
}
/*
 * Check if any time limits or use limits have expired
 *   if so, set the VolStatus appropriately.
 */
Check if any time limits or use limits have expired
if so, set the VolStatus appropriately.
Check if any time limits or use limits have expired if so set the VolStatus appropriately .
bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr)
{
   bool expired = false;
   char ed1[50];
   if (strcmp(mr->VolStatus, "Append") == 0 && mr->VolJobs > 0) {
      if ((mr->MaxVolBytes > 0 && mr->VolBytes >= mr->MaxVolBytes)) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume bytes=%s exceeded. "
             "Marking Volume \"%s\" as Full.\n"),
             edit_uint64_with_commas(mr->MaxVolBytes, ed1), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Full", sizeof(mr->VolStatus));
         expired = true;
      } else if (mr->VolBytes > 0 && jcr->pool->use_volume_once) {
         Jmsg(jcr, M_INFO, 0, _("Volume used once. "
             "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;
      } else if (mr->MaxVolJobs > 0 && mr->MaxVolJobs <= mr->VolJobs) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume jobs=%s exceeded. "
             "Marking Volume \"%s\" as Used.\n"),
             edit_uint64_with_commas(mr->MaxVolJobs, ed1), mr->VolumeName);
         Dmsg3(dbglvl, "MaxVolJobs=%d JobId=%d Vol=%s\n", mr->MaxVolJobs,
               (uint32_t)jcr->JobId, mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;
      } else if (mr->MaxVolFiles > 0 && mr->MaxVolFiles <= mr->VolFiles) {
         Jmsg(jcr, M_INFO, 0, _("Max Volume files=%s exceeded. "
             "Marking Volume \"%s\" as Used.\n"),
             edit_uint64_with_commas(mr->MaxVolFiles, ed1), mr->VolumeName);
         bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
         expired = true;
      } else if (mr->VolUseDuration > 0) {
         utime_t now = time(NULL);
         if (mr->VolUseDuration <= (now - mr->FirstWritten)) {
            Jmsg(jcr, M_INFO, 0, _("Max configured use duration=%s sec. exceeded. "
               "Marking Volume \"%s\" as Used.\n"),
               edit_uint64_with_commas(mr->VolUseDuration, ed1), mr->VolumeName);
            bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
            expired = true;
         }
      }
   }
   if (expired) {
      Dmsg1(dbglvl, "Vol=%s has expired update media record\n", mr->VolumeName);
      set_storageid_in_mr(NULL, mr);
      if (!db_update_media_record(jcr, jcr->db, mr)) {
         Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
              mr->VolumeName, db_strerror(jcr->db));
      }
   }
   Dmsg2(dbglvl, "Vol=%s expired=%d\n", mr->VolumeName, expired);
   return expired;
}
bool has_volume_expired ( JCR * jcr , MEDIA_DBR * mr ) { bool expired = false ; char ed1 [ 50 ] ; if ( strcmp ( mr -> VolStatus , " " ) == 0 && mr -> VolJobs > 0 ) { if ( ( mr -> MaxVolBytes > 0 && mr -> VolBytes >= mr -> MaxVolBytes ) ) { Jmsg ( jcr , M_INFO , 0 , _ ( " " " \" \" \n " ) , edit_uint64_with_commas ( mr -> MaxVolBytes , ed1 ) , mr -> VolumeName ) ; bstrncpy ( mr -> VolStatus , " " , sizeof ( mr -> VolStatus ) ) ; expired = true ; } else if ( mr -> VolBytes > 0 && jcr -> pool -> use_volume_once ) { Jmsg ( jcr , M_INFO , 0 , _ ( " " " \" \" \n " ) , mr -> VolumeName ) ; bstrncpy ( mr -> VolStatus , " " , sizeof ( mr -> VolStatus ) ) ; expired = true ; } else if ( mr -> MaxVolJobs > 0 && mr -> MaxVolJobs <= mr -> VolJobs ) { Jmsg ( jcr , M_INFO , 0 , _ ( " " " \" \" \n " ) , edit_uint64_with_commas ( mr -> MaxVolJobs , ed1 ) , mr -> VolumeName ) ; Dmsg3 ( dbglvl , " \n " , mr -> MaxVolJobs , ( uint32_t ) jcr -> JobId , mr -> VolumeName ) ; bstrncpy ( mr -> VolStatus , " " , sizeof ( mr -> VolStatus ) ) ; expired = true ; } else if ( mr -> MaxVolFiles > 0 && mr -> MaxVolFiles <= mr -> VolFiles ) { Jmsg ( jcr , M_INFO , 0 , _ ( " " " \" \" \n " ) , edit_uint64_with_commas ( mr -> MaxVolFiles , ed1 ) , mr -> VolumeName ) ; bstrncpy ( mr -> VolStatus , " " , sizeof ( mr -> VolStatus ) ) ; expired = true ; } else if ( mr -> VolUseDuration > 0 ) { utime_t now = time ( NULL ) ; if ( mr -> VolUseDuration <= ( now - mr -> FirstWritten ) ) { Jmsg ( jcr , M_INFO , 0 , _ ( " " " \" \" \n " ) , edit_uint64_with_commas ( mr -> VolUseDuration , ed1 ) , mr -> VolumeName ) ; bstrncpy ( mr -> VolStatus , " " , sizeof ( mr -> VolStatus ) ) ; expired = true ; } } } if ( expired ) { Dmsg1 ( dbglvl , " \n " , mr -> VolumeName ) ; set_storageid_in_mr ( NULL , mr ) ; if ( ! db_update_media_record ( jcr , jcr -> db , mr ) ) { Jmsg ( jcr , M_ERROR , 0 , _ ( " \" \" " ) , mr -> VolumeName , db_strerror ( jcr -> db ) ) ; } } Dmsg2 ( dbglvl , " \n " , mr -> VolumeName , expired ) ; return expired ; }
Check if any time limits or use limits have expired
   if so, set the VolStatus appropriately.
Check if any time limits or use limits have expired if so set the VolStatus appropriately .
/*
    * Check limits and expirations if "Append" and it has been used
    * i.e. mr->VolJobs > 0
    *
    */ /* First handle Max Volume Bytes */ /* Now see if Volume should only be used once */ /* Now see if Max Jobs written to volume */ /* Now see if Max Files written to volume */ /* Finally, check Use duration expiration */ /* See if Vol Use has expired */ /* Need to update media */