src/dird/next_vol.c
void check_if_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, const char **reason)
{
   int ok;

   *reason = NULL;

   /*  Check if a duration or limit has expired */
   if (has_volume_expired(jcr, mr)) {
      *reason = _("volume has expired");
      if (!mr->Recycle) {     /* cannot recycle */
         return;
      }
      /* Keep going because we may be able to recycle volume */
   }

   /*
    * Now see if we can use the volume as is
    */
   if (strcmp(mr->VolStatus, "Append") == 0 ||
       strcmp(mr->VolStatus, "Recycle") == 0) {
      *reason = NULL;
      return;
   }

   /*
    * Check if the Volume is already marked for recycling
    */
   if (strcmp(mr->VolStatus, "Purged") == 0) {
      if (recycle_volume(jcr, mr)) {
         Jmsg(jcr, M_INFO, 0, _("Recycled current volume \"%s\"\n"), mr->VolumeName);
         *reason = NULL;
         return;
      } else {
         /* In principle this shouldn't happen */
         *reason = _("and recycling of current volume failed");
         return;
      }
   }

   /* At this point, the volume is not valid for writing */
   *reason = _("but should be Append, Purged or Recycle");

   /*
    * What we're trying to do here is see if the current volume is
    * "recyclable" - ie. if we prune all expired jobs off it, is
    * it now possible to reuse it for the job that it is currently
    * needed for?
    */
   if (!mr->Recycle) {
      *reason = _("volume has recycling disabled");
      return;
   }
   /*
    * Check retention period from last written, but recycle to within
    *   a minute to try to catch close calls ...
    */
   if ((mr->LastWritten + mr->VolRetention - 60) < (utime_t)time(NULL)
         && jcr->pool->recycle_current_volume
         && (strcmp(mr->VolStatus, "Full") == 0 ||
            strcmp(mr->VolStatus, "Used") == 0)) {
      /*
       * Attempt prune of current volume to see if we can
       * recycle it for use.
       */
      UAContext *ua;

      ua = new_ua_context(jcr);
      ok = prune_volume(ua, mr);
      free_ua_context(ua);

      if (ok) {
         /* If fully purged, recycle current volume */
         if (recycle_volume(jcr, mr)) {
            Jmsg(jcr, M_INFO, 0, _("Recycled current volume \"%s\"\n"), mr->VolumeName);
            *reason = NULL;
         } else {
            *reason = _("but should be Append, Purged or Recycle (recycling of the "
               "current volume failed)");
         }
      } else {
         *reason = _("but should be Append, Purged or Recycle (cannot automatically "
            "recycle current volume, as it still contains unpruned data "
            "or the Volume Retention time has not expired.)");
      }
   }
}
/*
 * Try hard to recycle the current volume
 *
 *  Returns: on failure - reason = NULL
 *           on success - reason - pointer to reason
 */
Try hard to recycle the current volume
Returns: on failure - reason = NULL
on success - reason - pointer to reason
Try hard to recycle the current volume Returns : on failure - reason = NULL on success - reason - pointer to reason
void check_if_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, const char **reason)
{
   int ok;
   *reason = NULL;
   if (has_volume_expired(jcr, mr)) {
      *reason = _("volume has expired");
      if (!mr->Recycle) {     
         return;
      }
   }
   if (strcmp(mr->VolStatus, "Append") == 0 ||
       strcmp(mr->VolStatus, "Recycle") == 0) {
      *reason = NULL;
      return;
   }
   if (strcmp(mr->VolStatus, "Purged") == 0) {
      if (recycle_volume(jcr, mr)) {
         Jmsg(jcr, M_INFO, 0, _("Recycled current volume \"%s\"\n"), mr->VolumeName);
         *reason = NULL;
         return;
      } else {
         *reason = _("and recycling of current volume failed");
         return;
      }
   }
   *reason = _("but should be Append, Purged or Recycle");
   if (!mr->Recycle) {
      *reason = _("volume has recycling disabled");
      return;
   }
   if ((mr->LastWritten + mr->VolRetention - 60) < (utime_t)time(NULL)
         && jcr->pool->recycle_current_volume
         && (strcmp(mr->VolStatus, "Full") == 0 ||
            strcmp(mr->VolStatus, "Used") == 0)) {
      UAContext *ua;
      ua = new_ua_context(jcr);
      ok = prune_volume(ua, mr);
      free_ua_context(ua);
      if (ok) {
         if (recycle_volume(jcr, mr)) {
            Jmsg(jcr, M_INFO, 0, _("Recycled current volume \"%s\"\n"), mr->VolumeName);
            *reason = NULL;
         } else {
            *reason = _("but should be Append, Purged or Recycle (recycling of the "
               "current volume failed)");
         }
      } else {
         *reason = _("but should be Append, Purged or Recycle (cannot automatically "
            "recycle current volume, as it still contains unpruned data "
            "or the Volume Retention time has not expired.)");
      }
   }
}
void check_if_volume_valid_or_recyclable ( JCR * jcr , MEDIA_DBR * mr , const char * * reason ) { int ok ; * reason = NULL ; if ( has_volume_expired ( jcr , mr ) ) { * reason = _ ( " " ) ; if ( ! mr -> Recycle ) { return ; } } if ( strcmp ( mr -> VolStatus , " " ) == 0 || strcmp ( mr -> VolStatus , " " ) == 0 ) { * reason = NULL ; return ; } if ( strcmp ( mr -> VolStatus , " " ) == 0 ) { if ( recycle_volume ( jcr , mr ) ) { Jmsg ( jcr , M_INFO , 0 , _ ( " \" \" \n " ) , mr -> VolumeName ) ; * reason = NULL ; return ; } else { * reason = _ ( " " ) ; return ; } } * reason = _ ( " " ) ; if ( ! mr -> Recycle ) { * reason = _ ( " " ) ; return ; } if ( ( mr -> LastWritten + mr -> VolRetention - 60 ) < ( utime_t ) time ( NULL ) && jcr -> pool -> recycle_current_volume && ( strcmp ( mr -> VolStatus , " " ) == 0 || strcmp ( mr -> VolStatus , " " ) == 0 ) ) { UAContext * ua ; ua = new_ua_context ( jcr ) ; ok = prune_volume ( ua , mr ) ; free_ua_context ( ua ) ; if ( ok ) { if ( recycle_volume ( jcr , mr ) ) { Jmsg ( jcr , M_INFO , 0 , _ ( " \" \" \n " ) , mr -> VolumeName ) ; * reason = NULL ; } else { * reason = _ ( " " " " ) ; } } else { * reason = _ ( " " " " " " ) ; } } }
Try hard to recycle the current volume
  Returns: on failure - reason = NULL
           on success - reason - pointer to reason
Try hard to recycle the current volume Returns : on failure - reason = NULL on success - reason - pointer to reason
/*  Check if a duration or limit has expired */ /* cannot recycle */ /* Keep going because we may be able to recycle volume */ /*
    * Now see if we can use the volume as is
    */ /*
    * Check if the Volume is already marked for recycling
    */ /* In principle this shouldn't happen */ /* At this point, the volume is not valid for writing */ /*
    * What we're trying to do here is see if the current volume is
    * "recyclable" - ie. if we prune all expired jobs off it, is
    * it now possible to reuse it for the job that it is currently
    * needed for?
    */ /*
    * Check retention period from last written, but recycle to within
    *   a minute to try to catch close calls ...
    */ /*
       * Attempt prune of current volume to see if we can
       * recycle it for use.
       */ /* If fully purged, recycle current volume */