]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/btape.c
Fix for reused thread ids by FreeBSD + qfill command
[bacula/bacula] / bacula / src / stored / btape.c
index c20fad8df7c582380fe290cf5452ad17ee910d67..868d66a93b99b3fb1311ce756e6e04ee23e846ce 100644 (file)
@@ -60,6 +60,7 @@ static void wrcmd();
 static void rrcmd();
 static void eodcmd();
 static void fillcmd();
+static void qfillcmd();
 static void statcmd();
 static void unfillcmd();
 static int flush_block(DEV_BLOCK *block, int dump);
@@ -424,15 +425,15 @@ static void weofcmd()
 static void eomcmd()
 {
    if (!eod_dev(dev)) {
-      Pmsg1(0, _("Bad status from eod. ERR=%s\n"), strerror_dev(dev));
+      Pmsg1(0, _("Bad status from MTEOD. ERR=%s\n"), strerror_dev(dev));
       return;
    } else {
-      Pmsg0(0, _("Moved to end of media\n"));
+      Pmsg0(0, _("Moved to end of medium.\n"));
    }
 }
 
 /*
- * Go to the end of the media (either hardware determined
+ * Go to the end of the medium (either hardware determined
  *  or defined by two eofs.
  */
 static void eodcmd()
@@ -695,7 +696,7 @@ static int append_test()
    wrcmd();
    weofcmd();    /* end file 2 */
    rewindcmd();
-   Pmsg0(0, _("Now moving to end of media.\n"));
+   Pmsg0(0, _("Now moving to end of medium.\n"));
    eodcmd();
    Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"), 
       dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
@@ -906,6 +907,7 @@ static void scancmd()
    int blocks, tot_blocks, tot_files;
    int block_size;
    uint64_t bytes;
+   char ec1[50];
 
 
    blocks = block_size = tot_blocks = 0;
@@ -961,7 +963,8 @@ static void scancmd()
    }
    update_pos_dev(dev);
    tot_files = dev->file - tot_files;
-   printf("Total files=%d, blocks=%d, bytes = %" lld "\n", tot_files, tot_blocks, bytes);
+   printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks, 
+      edit_uint64_with_commas(bytes, ec1));
 }
 
 
@@ -977,6 +980,7 @@ static void scan_blocks()
    uint32_t block_size;
    uint64_t bytes;
    DEV_BLOCK *block;
+   char ec1[50];
 
    block = new_block(dev);
    blocks = block_size = tot_blocks = 0;
@@ -1047,7 +1051,8 @@ static void scan_blocks()
 bail_out:
    free_block(block);
    tot_files = dev->file - tot_files;
-   printf("Total files=%d, blocks=%d, bytes = %" lld "\n", tot_files, tot_blocks, bytes);
+   printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks, 
+      edit_uint64_with_commas(bytes, ec1));
 }
 
 
@@ -1281,6 +1286,11 @@ static void unfillcmd()
 
    end_of_tape = 0;
 
+   /* Close device so user can use autochanger if desired */
+   if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
+      offline_dev(dev);
+   }
+   force_close_dev(dev);
    get_cmd(_("Mount first tape. Press enter when ready: ")); 
    
    free_vol_list(jcr);
@@ -1345,7 +1355,6 @@ bail_out:
    Pmsg0(000, _("Done with reread of fill data.\n"));
 }
 
-
 /* 
  * We are called here from "unfill" for each record on the tape.
  */
@@ -1529,6 +1538,65 @@ static int flush_block(DEV_BLOCK *block, int dump)
 }
 
 
+/* 
+ * First we label the tape, then we fill
+ *  it with data get a new tape and write a few blocks.
+ */                           
+static void qfillcmd()
+{
+   DEV_BLOCK *block;
+   DEV_RECORD *rec;
+   int i, count;
+
+   Pmsg0(0, "Test writing blocks of 64512 bytes to tape.\n");
+
+   get_cmd("How many blocks do you want to write? (1000): ");
+
+   count = atoi(cmd);
+   if (count <= 0) {
+      count = 1000;
+   }
+
+   sm_check(__FILE__, __LINE__, False);
+   block = new_block(dev);
+   rec = new_record();
+
+   i = block->buf_len - 100;
+   ASSERT (i > 0);
+   rec->data = check_pool_memory_size(rec->data, i);
+   memset(rec->data, i & 0xFF, i);
+   rec->data_len = i;
+   rewindcmd();
+   Pmsg1(0, "Begin writing %d blocks to tape ...\n", count);
+   for (i=0; i < count; i++) {
+      if (i % 100 == 0) {
+         printf("+");
+      }
+      if (!write_record_to_block(block, rec)) {
+         Pmsg0(0, _("Error writing record to block.\n")); 
+        goto bail_out;
+      }
+      if (!write_block_to_dev(jcr, dev, block)) {
+         Pmsg0(0, _("Error writing block to device.\n")); 
+        goto bail_out;
+      }
+   }
+   printf("\n");
+   weofcmd();
+   weofcmd();
+   rewindcmd();
+   scan_blocks();
+
+bail_out:
+   sm_check(__FILE__, __LINE__, False);
+   free_record(rec);
+   free_block(block);
+   sm_check(__FILE__, __LINE__, False);
+
+}
+
+
+
 struct cmdstruct { char *key; void (*func)(); char *help; }; 
 static struct cmdstruct commands[] = {
  {"bsf",        bsfcmd,       "backspace file"},
@@ -1554,6 +1622,7 @@ static struct cmdstruct commands[] = {
  {"weof",       weofcmd,      "write an EOF on the tape"},
  {"wr",         wrcmd,        "write a single Bacula block"}, 
  {"rr",         rrcmd,        "read a single record"},
+ {"qfill",      qfillcmd,     "quick fill command"},
             };
 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
 
@@ -1652,6 +1721,11 @@ int      dir_find_next_appendable_volume(JCR *jcr)
 
 int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
 {
+   /* Close device so user can use autochanger if desired */
+   if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
+      offline_dev(dev);
+   }
+   force_close_dev(dev);
    Pmsg1(-1, "%s", dev->errmsg);           /* print reason */
    fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
       jcr->VolumeName, dev_name(dev));
@@ -1661,6 +1735,11 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
 
 int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev)
 {
+   /* Close device so user can use autochanger if desired */
+   if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
+      offline_dev(dev);
+   }
+   force_close_dev(dev);
    fprintf(stderr, "Mount next Volume on device %s and press return when ready: ",
       dev_name(dev));
    getchar();