- if (!(dev_state(dev, ST_OPENED))) {
- int mode;
- if (dev_cap(dev, CAP_STREAM)) {
- mode = OPEN_WRITE_ONLY;
- } else {
- mode = OPEN_READ_WRITE;
- }
- if (open_dev(dev, jcr->VolCatInfo.VolCatName, mode) < 0) {
- Jmsg2(jcr, M_FATAL, 0, _("Unable to open device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- return 0;
- }
+ if (!dev->is_open()) {
+ int mode;
+ if (dev_cap(dev, CAP_STREAM)) {
+ mode = OPEN_WRITE_ONLY;
+ } else {
+ mode = OPEN_READ_WRITE;
+ }
+ if (open_dev(dev, dcr->VolCatInfo.VolCatName, mode) < 0) {
+ /* If polling, ignore the error */
+ if (!dev->poll) {
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open archive %s: ERR=%s\n"),
+ dev->print_name(), strerror_dev(dev));
+ Pmsg2(000, "Unable to open archive %s: ERR=%s\n",
+ dev->print_name(), strerror_dev(dev));
+ }
+ return false;
+ }
+ }
+ return true;
+}
+
+void dev_lock(DEVICE *dev)
+{
+ int errstat;
+ if ((errstat=rwl_writelock(&dev->lock))) {
+ Emsg1(M_ABORT, 0, "Device write lock failure. ERR=%s\n", strerror(errstat));
+ }
+}
+
+void dev_unlock(DEVICE *dev)
+{
+ int errstat;
+ if ((errstat=rwl_writeunlock(&dev->lock))) {
+ Emsg1(M_ABORT, 0, "Device write unlock failure. ERR=%s\n", strerror(errstat));