From: Kern Sibbald Date: Mon, 19 Aug 2002 21:42:16 +0000 (+0000) Subject: Create JobMedia for all Jobs using media X-Git-Tag: Release-1.25~35 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=80eb45e0ca629dc18f4faede11d2c883de899b77;p=bacula%2Fbacula Create JobMedia for all Jobs using media git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@108 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 834e6e017f..02dbf324bf 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -187,10 +187,12 @@ db_update_media_record(B_DB *mdb, MEDIA_DBR *mr) Dmsg1(100, "update_media: FirstWritten=%d\n", mr->FirstWritten); db_lock(mdb); - if (mr->VolMounts == 1) { + if (mr->VolMounts == 1 && mr->VolBlocks==1 && mr->VolWrites==1) { + Dmsg1(400, "Set FirstWritten Vol=%s\n", mr->VolumeName); Mmsg(&mdb->cmd, "UPDATE Media SET FirstWritten='%s'\ WHERE VolumeName='%s'", dt, mr->VolumeName); - UPDATE_DB(mdb, mdb->cmd); + stat = UPDATE_DB(mdb, mdb->cmd); + Dmsg1(400, "Firstwritten stat=%d\n", stat); } Mmsg(&mdb->cmd, "UPDATE Media SET VolJobs=%d,\ @@ -202,6 +204,8 @@ db_update_media_record(B_DB *mdb, MEDIA_DBR *mr) edit_uint64(mr->VolMaxBytes, ed2), dt, mr->VolStatus, mr->Slot, mr->VolumeName); + Dmsg1(400, "%s\n", mdb->cmd); + stat = UPDATE_DB(mdb, mdb->cmd); db_unlock(mdb); return stat; diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index f9b7960f71..621d23d45d 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -147,9 +147,9 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg) mr.VolFiles, mr.VolBlocks, mr.VolBytes, mr.VolMounts, mr.VolErrors, mr.VolWrites, mr.VolMaxBytes, mr.VolCapacityBytes, mr.VolStatus, mr.Slot); - } else { Dmsg4(100, "get_media_record PoolId=%d wanted %d, Status=%s, \ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); + } else { /* Not suitable volume */ bnet_fsend(bs, "1998 Volume not appropriate.\n"); } @@ -175,7 +175,8 @@ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); strcpy(mr.VolStatus, "Full"); } - Dmsg0(20, "db_update_media_record\n"); + Dmsg2(100, "db_update_media_record. Stat=%s Vol=%s\n", + mr.VolStatus, mr.VolumeName); if (db_update_media_record(jcr->db, &mr)) { bnet_fsend(bs, OK_update); Dmsg0(90, "send OK\n"); @@ -202,7 +203,7 @@ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); db_strerror(jcr->db)); bnet_fsend(bs, "1991 Update JobMedia error\n"); } else { - Dmsg0(20, "JobMedia record created\n"); + Dmsg0(100, "JobMedia record created\n"); bnet_fsend(bs, OK_update); } diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 4e49b90e71..9908cb215c 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -177,7 +177,7 @@ int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel) /* * After writing a Volume, create the JobMedia record. */ -int dir_create_job_media_record(JCR *jcr) +int dir_create_jobmedia_record(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; @@ -185,14 +185,14 @@ int dir_create_job_media_record(JCR *jcr) jcr->VolFirstFile, jcr->JobFiles, jcr->start_file, jcr->end_file, jcr->start_block, jcr->end_block); - Dmsg1(20, "create_job_media(): %s", dir->msg); + Dmsg1(100, "create_jobmedia(): %s", dir->msg); if (bnet_recv(dir) <= 0) { Dmsg0(90, "create_jobmedia error bnet_recv\n"); return 0; } - Dmsg1(20, "Create_jobmedia: %s", dir->msg); + Dmsg1(020, "Create_jobmedia: %s", dir->msg); if (strcmp(dir->msg, OK_update) != 0) { - Dmsg1(30, "Bad response from Dir: %s\n", dir->msg); + Dmsg1(030, "Bad response from Dir: %s\n", dir->msg); Jmsg(jcr, M_ERROR, 0, _("Error creating JobMedia record: %s\n"), dir->msg); return 0; } diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 886713392a..f286a7c62d 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -549,7 +549,7 @@ static void print_ls_output(char *fname, char *link, int type, struct stat *stat int dir_get_volume_info(JCR *jcr) { return 1;} int dir_find_next_appendable_volume(JCR *jcr) { return 1;} int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel) { return 1; } -int dir_create_job_media_record(JCR *jcr) { return 1; } +int dir_create_jobmedia_record(JCR *jcr) { return 1; } int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev) { return 1; } int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;} int dir_send_job_status(JCR *jcr) {return 1;} diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index ee73913dd3..c26634706c 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -544,7 +544,7 @@ static void print_ls_output(char *fname, char *link, int type, struct stat *stat int dir_get_volume_info(JCR *jcr) { return 1;} int dir_find_next_appendable_volume(JCR *jcr) { return 1;} int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel) { return 1; } -int dir_create_job_media_record(JCR *jcr) { return 1; } +int dir_create_jobmedia_record(JCR *jcr) { return 1; } int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev) { return 1; } int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;} int dir_send_job_status(JCR *jcr) {return 1;} diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index c8561dd333..0f9383063b 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1076,24 +1076,24 @@ term_dev(DEVICE *dev) } } + +/* To make following two functions more readable */ + #define attached_jcrs ((JCR *)(dev->attached_jcrs)) -void dev_attach_jcr(DEVICE *dev, JCR *jcr) +void attach_jcr_to_device(DEVICE *dev, JCR *jcr) { - - P(dev->mutex); jcr->prev_dev = NULL; jcr->next_dev = attached_jcrs; if (attached_jcrs) { attached_jcrs->prev_dev = jcr; } attached_jcrs = jcr; - V(dev->mutex); + Dmsg1(000, "Attached Job %s\n", jcr->Job); } -void dev_remove_jcr(DEVICE *dev, JCR *jcr) +void detach_jcr_from_device(DEVICE *dev, JCR *jcr) { - P(dev->mutex); if (!jcr->prev_dev) { attached_jcrs = jcr->next_dev; } else { @@ -1102,5 +1102,13 @@ void dev_remove_jcr(DEVICE *dev, JCR *jcr) if (jcr->next_dev) { jcr->next_dev->prev_dev = jcr->prev_dev; } - V(dev->mutex); + Dmsg1(000, "Detached Job %s\n", jcr->Job); +} + +JCR *next_attached_jcr(DEVICE *dev, JCR *jcr) +{ + if (jcr == NULL) { + return attached_jcrs; + } + return jcr->next_dev; } diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 7f20bef970..a14a78b59e 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -161,6 +161,7 @@ int acquire_device_for_append(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) if (jcr->NumVolumes == 0) { jcr->NumVolumes = 1; } + attach_jcr_to_device(dev, jcr); /* attach jcr to device */ unlock_device(dev); return 1; /* got it */ } @@ -173,7 +174,7 @@ int acquire_device_for_append(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) { P(dev->mutex); - Dmsg1(90, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk"); + Dmsg1(100, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk"); if (dev->state & ST_READ) { dev->state &= ~ST_READ; /* clear read bit */ if (!dev_is_tape(dev) || !(dev->capabilities & CAP_ALWAYSOPEN)) { @@ -189,9 +190,11 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) Dmsg1(90, "There are %d writers in release_device\n", dev->num_writers); if (dev->num_writers == 0) { weof_dev(dev, 1); - dir_create_job_media_record(jcr); + Dmsg0(100, "dir_create_jobmedia_record. Release\n"); + dir_create_jobmedia_record(jcr); dev->VolCatInfo.VolCatFiles++; /* increment number of files */ /* Note! do volume update before close, which zaps VolCatInfo */ + Dmsg0(100, "dir_update_vol_info. Release\n"); dir_update_volume_info(jcr, &dev->VolCatInfo, 0); /* send Volume info to Director */ if (!dev_is_tape(dev) || !(dev->capabilities & CAP_ALWAYSOPEN)) { @@ -201,12 +204,15 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) close_dev(dev); } } else { - dir_create_job_media_record(jcr); + Dmsg0(100, "dir_create_jobmedia_record. Release\n"); + dir_create_jobmedia_record(jcr); + Dmsg0(100, "dir_update_vol_info. Release\n"); dir_update_volume_info(jcr, &dev->VolCatInfo, 0); /* send Volume info to Director */ } } else { Jmsg1(jcr, M_ERROR, 0, _("BAD ERROR: release_device %s not in use.\n"), dev_name(dev)); } + detach_jcr_from_device(dev, jcr); V(dev->mutex); return 1; } @@ -298,7 +304,7 @@ mount_next_vol: dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF); - jcr->VolFirstFile = 0; /* first update of Vol FileIndex */ + jcr->VolFirstFile = jcr->JobFiles; /* first update of Vol FileIndex */ for ( ;; ) { int slot = jcr->VolCatInfo.Slot; @@ -492,6 +498,7 @@ read_volume: dev->VolCatInfo.VolCatReads = 1; } strcpy(dev->VolCatInfo.VolCatStatus, "Append"); + Dmsg0(100, "dir_update_vol_info. Set Append\n"); dir_update_volume_info(jcr, &dev->VolCatInfo, 1); /* indicate doing relabel */ if (recycle) { Jmsg(jcr, M_INFO, 0, _("Recycled volume %s on device %s, all previous data lost.\n"), @@ -516,6 +523,7 @@ read_volume: Jmsg(jcr, M_INFO, 0, _("Marking Volume %s in Error in Catalog.\n"), jcr->VolumeName); strcpy(dev->VolCatInfo.VolCatStatus, "Error"); + Dmsg0(100, "dir_update_vol_info. Set Error.\n"); dir_update_volume_info(jcr, &dev->VolCatInfo, 0); goto mount_next_vol; } @@ -623,17 +631,25 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) block_device(dev, BST_DOING_ACQUIRE); - strcpy(dev->VolCatInfo.VolCatStatus, "Full"); - Dmsg0(90, "Call update_vol_info\n"); - /* Update position counters */ - jcr->end_block = dev->block_num; - jcr->end_file = dev->file; - /* - * ****FIXME**** update JobMedia record of every job using - * this device + /* + * Walk through all attached jcrs creating a jobmedia_record() */ - if (!dir_create_job_media_record(jcr) || - !dir_update_volume_info(jcr, &dev->VolCatInfo, 0)) { /* send Volume info to Director */ + Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName); + for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { + Dmsg1(100, "create JobMedia for Job %s\n", mjcr->Job); + mjcr->end_block = dev->block_num; + mjcr->end_file = dev->file; + if (!dir_create_jobmedia_record(mjcr)) { + Jmsg(mjcr, M_ERROR, 0, _("Could not create JobMedia record for Volume=%s Job=%s\n"), + dev->VolCatInfo.VolCatName, mjcr->Job); + return 0; + } + } + + strcpy(dev->VolCatInfo.VolCatStatus, "Full"); + Dmsg2(100, "Call update_vol_info Stat=%s Vol=%s\n", + dev->VolCatInfo.VolCatStatus, dev->VolCatInfo.VolCatName); + if (!dir_update_volume_info(jcr, &dev->VolCatInfo, 0)) { /* send Volume info to Director */ Jmsg(jcr, M_ERROR, 0, _("Could not update Volume info Volume=%s Job=%s\n"), dev->VolCatInfo.VolCatName, jcr->Job); return 0; /* device locked */ @@ -691,11 +707,14 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) jcr->NumVolumes++; Dmsg0(90, "Wake up any waiting threads.\n"); free_block(label_blk); - /* Set new start/end positions */ - jcr->start_block = dev->block_num; - jcr->start_file = dev->file; + for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { + /* Set new start/end positions */ + mjcr->start_block = dev->block_num; + mjcr->start_file = dev->file; + mjcr->VolFirstFile = mjcr->JobFiles; + mjcr->run_time += time(NULL) - wait_time; /* correct run time */ + } unblock_device(dev); - jcr->run_time += time(NULL) - wait_time; /* correct run time */ return 1; /* device locked */ } if (label_blk) { diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 5e008231be..8cb2be8e80 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -35,7 +35,7 @@ int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev); int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev); int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec); int dir_send_job_status(JCR *jcr); -int dir_create_job_media_record(JCR *jcr); +int dir_create_jobmedia_record(JCR *jcr); /* authenticate.c */ int authenticate_director(JCR *jcr); @@ -77,8 +77,9 @@ int fsf_dev(DEVICE *dev, int num); int fsr_dev(DEVICE *dev, int num); int bsf_dev(DEVICE *dev, int num); int bsr_dev(DEVICE *dev, int num); -void dev_attach_jcr(DEVICE *dev, JCR *jcr); -void dev_remove_jcr(DEVICE *dev, JCR *jcr); +void attach_jcr_to_device(DEVICE *dev, JCR *jcr); +void detach_jcr_from_device(DEVICE *dev, JCR *jcr); +JCR *next_attached_jcr(DEVICE *dev, JCR *jcr); /* Get info about device */