From 3cf96d45987ed03d6974ee3d4756464e0b30a2f7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 30 May 2008 15:01:03 +0000 Subject: [PATCH] Make DEVICE Slot private and access it via a method. Allows better control over when it is set and cleared. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7058 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/autochanger.c | 40 ++++++++++++++++----------------- bacula/src/stored/dev.c | 17 +++++++++++--- bacula/src/stored/dev.h | 11 ++++++--- bacula/src/stored/mount.c | 5 ++--- bacula/src/stored/status.c | 6 ++--- bacula/technotes-2.3 | 2 ++ 6 files changed, 49 insertions(+), 32 deletions(-) diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index e798d9fa68..e3afcf24d6 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -200,7 +200,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"), slot, drive); Dmsg2(100, "load slot %d, drive %d, status is OK.\n", slot, drive); - dev->Slot = slot; /* set currently loaded slot */ + dev->set_slot(slot); /* set currently loaded slot */ } else { berrno be; be.set_errno(status); @@ -210,13 +210,13 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) "ERR=%s.\nResults=%s\n"), slot, drive, be.bstrerror(), results.c_str()); rtn_stat = -1; /* hard error */ - dev->Slot = -1; /* mark unknown */ + dev->set_slot(-1); /* mark unknown */ } Dmsg2(100, "load slot %d status=%d\n", slot, status); unlock_changer(dcr); } else { status = 0; /* we got what we want */ - dev->Slot = slot; /* set currently loaded slot */ + dev->set_slot(slot); /* set currently loaded slot */ } Dmsg1(100, "After changer, status=%d\n", status); if (status == 0) { /* did we succeed? */ @@ -255,8 +255,8 @@ int get_autochanger_loaded_slot(DCR *dcr) // Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n")); return -1; } - if (dev->Slot > 0) { - return dev->Slot; + if (dev->get_slot() > 0) { + return dev->get_slot(); } /* Virtual disk autochanger */ if (dcr->device->changer_command[0] == 0) { @@ -277,11 +277,11 @@ int get_autochanger_loaded_slot(DCR *dcr) if (loaded > 0) { Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded? drive %d\", result is Slot %d.\n"), drive, loaded); - dev->Slot = loaded; + dev->set_slot(loaded); } else { Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded? drive %d\", result: nothing loaded.\n"), drive); - dev->Slot = -1; /* unknown */ + dev->clear_slot(); /* unknown */ } } else { berrno be; @@ -368,9 +368,9 @@ bool unload_autochanger(DCR *dcr, int loaded) "ERR=%s\nResults=%s\n"), loaded, dev->drive_index, be.bstrerror(), results.c_str()); ok = false; - dev->Slot = -1; /* unknown */ + dev->clear_slot(); /* unknown */ } else { - dev->Slot = 0; /* nothing loaded */ + dev->set_slot(0); /* nothing loaded */ } unlock_changer(dcr); @@ -400,7 +400,7 @@ static bool unload_other_drive(DCR *dcr, int slot) } foreach_alist(device, changer->device) { - if (device->dev && device->dev->Slot == slot) { + if (device->dev && device->dev->get_slot() == slot) { found = true; dev = device->dev; break; @@ -427,7 +427,7 @@ static bool unload_other_drive(DCR *dcr, int slot) Jmsg(dcr->jcr, M_WARNING, 0, _("Volume \"%s\" is in use by device %s\n"), dcr->VolumeName, dev->print_name()); Dmsg4(100, "Vol %s for dev=%s is busy dev=%s slot=%d\n", - dcr->VolumeName, dcr->dev->print_name(), dev->print_name(), dev->Slot); + dcr->VolumeName, dcr->dev->print_name(), dev->print_name(), dev->get_slot()); Dmsg2(100, "num_writ=%d reserv=%d\n", dev->num_writers, dev->num_reserved()); return false; } @@ -443,7 +443,7 @@ bool unload_dev(DCR *dcr, DEVICE *dev) DEVICE *save_dev; int save_slot; - if (!changer || dev->Slot <= 0) { + if (!changer || dev->get_slot() <= 0) { return false; } dev->dlock(); @@ -453,15 +453,15 @@ bool unload_dev(DCR *dcr, DEVICE *dev) lock_changer(dcr); Jmsg(jcr, M_INFO, 0, _("3307 Issuing autochanger \"unload slot %d, drive %d\" command.\n"), - dev->Slot, dev->drive_index); + dev->get_slot(), dev->drive_index); Dmsg2(100, "Issuing autochanger \"unload slot %d, drive %d\" command.\n", - dev->Slot, dev->drive_index); + dev->get_slot(), dev->drive_index); save_dev = dcr->dev; dcr->dev = dev; save_slot = dcr->VolCatInfo.Slot; - dcr->VolCatInfo.Slot = dev->Slot; + dcr->VolCatInfo.Slot = dev->get_slot(); changer_cmd = edit_device_codes(dcr, changer_cmd, dcr->device->changer_command, "unload"); dev->close(); @@ -475,15 +475,15 @@ bool unload_dev(DCR *dcr, DEVICE *dev) berrno be; be.set_errno(stat); Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"), - dev->Slot, dev->drive_index, be.bstrerror()); + dev->get_slot(), dev->drive_index, be.bstrerror()); Dmsg3(100, "Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n", - dev->Slot, dev->drive_index, be.bstrerror()); + dev->get_slot(), dev->drive_index, be.bstrerror()); ok = false; - dev->Slot = -1; /* unknown */ + dev->clear_slot(); /* unknown */ } else { - Dmsg2(100, "Slot %d unloaded %s\n", dev->Slot, dev->print_name()); - dev->Slot = 0; /* nothing loaded */ + Dmsg2(100, "Slot %d unloaded %s\n", dev->get_slot(), dev->print_name()); + dev->set_slot(0); /* nothing loaded */ } dev->clear_unload(); unlock_changer(dcr); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 5afe0e10f8..46c5bcce7f 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -139,7 +139,7 @@ init_dev(JCR *jcr, DEVRES *device) dev = (DEVICE *)malloc(sizeof(DEVICE)); memset(dev, 0, sizeof(DEVICE)); - dev->Slot = -1; /* unknown */ + dev->clear_slot(); /* unknown */ /* Copy user supplied device parameters from Resource */ dev->dev_name = get_memory(strlen(device->device_name)+1); @@ -302,7 +302,6 @@ DEVICE::open(DCR *dcr, int omode) Dmsg4(100, "open dev: type=%d dev_name=%s vol=%s mode=%s\n", dev_type, print_name(), VolCatInfo.VolCatName, mode_to_str(omode)); state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF); - Slot = -1; /* unknown slot */ label_type = B_BACULA_LABEL; if (is_tape() || is_fifo()) { open_tape_device(dcr, omode); @@ -1547,6 +1546,19 @@ void DEVICE::unlock_door() tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); #endif } + +void DEVICE::set_slot(int32_t slot) +{ + m_slot = slot; + if (vol) vol->clear_slot(); +} + +void DEVICE::clear_slot() +{ + m_slot = -1; + if (vol) vol->set_slot(-1); +} + /* @@ -1868,7 +1880,6 @@ void DEVICE::close() file_addr = 0; EndFile = EndBlock = 0; openmode = 0; - Slot = -1; /* unknown slot */ clear_volhdr(); memset(&VolCatInfo, 0, sizeof(VolCatInfo)); if (tid) { diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 3344ec49e9..fbfa735b68 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -197,11 +197,9 @@ struct VOLUME_CAT_INFO { class DEVRES; /* Device resource defined in stored_conf.h */ - class DCR; /* forward reference */ class VOLRES; /* forward reference */ - /* * Device structure definition. There is one of these for * each physical device. Everything here is "global" to @@ -216,6 +214,8 @@ private: bool m_unload; /* set when Volume must be unloaded */ bool m_load; /* set when Volume must be loaded */ int m_num_reserved; /* counter of device reservations */ + int32_t m_slot; /* slot loaded in drive or -1 if none */ + public: DEVICE * volatile swap_dev; /* Swap vol from this device */ dlist *attached_dcrs; /* attached DCR list */ @@ -237,7 +237,6 @@ public: bool initiated; /* set when init_dev() called */ int label_type; /* Bacula/ANSI/IBM label types */ uint32_t drive_index; /* Autochanger drive index (base 0) */ - int32_t Slot; /* Slot currently in drive (base 1) */ POOLMEM *dev_name; /* Physical device name */ POOLMEM *prt_name; /* Name used for display purposes */ char *errmsg; /* nicely edited error message */ @@ -385,6 +384,7 @@ public: void clear_load() { m_load = false; }; char *bstrerror(void) { return errmsg; }; char *print_errmsg() { return errmsg; }; + int32_t get_slot() const { return m_slot; }; void clear_volhdr(); /* in dev.c */ @@ -415,6 +415,10 @@ public: void clrerror(int func); /* in dev.c */ boffset_t lseek(DCR *dcr, boffset_t offset, int whence); /* in dev.c */ bool update_pos(DCR *dcr); /* in dev.c */ + void set_slot(int32_t slot); /* in dev.c */ + void clear_slot(); /* in dev.c */ + + bool update_freespace(); /* in dvd.c */ uint32_t get_file() const { return file; }; @@ -556,6 +560,7 @@ public: void set_in_use() { m_in_use = true; }; void clear_in_use() { m_in_use = false; }; void set_slot(int32_t slot) { m_slot = slot; }; + void clear_slot() { m_slot = -1; }; int32_t get_slot() const { return m_slot; }; }; diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 55075bcaca..98c3b80b3e 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -485,12 +485,11 @@ void DCR::do_swapping(bool is_writing) if (dev->swap_dev) { if (dev->swap_dev->must_unload()) { if (dev->vol) { - dev->swap_dev->Slot = dev->vol->get_slot(); + dev->swap_dev->set_slot(dev->vol->get_slot()); } - Dmsg2(100, "Swap unloading slot=%d %s\n", dev->swap_dev->Slot, + Dmsg2(100, "Swap unloading slot=%d %s\n", dev->swap_dev->get_slot(), dev->swap_dev->print_name()); unload_dev(this, dev->swap_dev); - dev->Slot = -1; } if (dev->vol) { dev->vol->clear_swapping(); diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index f91444e4e9..eb02eb2418 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -309,11 +309,11 @@ static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp) } /* Send autochanger slot status */ if (dev->is_autochanger()) { - if (dev->Slot > 0) { + if (dev->get_slot() > 0) { len = Mmsg(msg, _(" Slot %d is loaded in drive %d.\n"), - dev->Slot, dev->drive_index); + dev->get_slot(), dev->drive_index); sendit(msg, len, sp); - } else if (dev->Slot == 0) { + } else if (dev->get_slot() == 0) { len = Mmsg(msg, _(" Drive %d is not loaded.\n"), dev->drive_index); sendit(msg, len, sp); } else { diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index bdebafd548..b3d7641eea 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -25,6 +25,8 @@ Add long term statistics job table General: 30May08 +kes Make DEVICE Slot private and access it via a method. + Allows better control over when it is set and cleared. kes Fix possible seg fault if SQL error. 28May08 kes Add Martin's fixes to argument scanning for the estimate -- 2.39.5