"WHERE MediaId=%d", dt, mr->MediaId);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
}
+ /*
+ * Make sure that if InChanger is non-zero any other identical slot
+ * has InChanger zero.
+ */
+ db_make_inchanger_unique(jcr, mdb, mr);
}
- /*
- * Make sure that if InChanger is non-zero any other identical slot
- * has InChanger zero.
- */
- db_make_inchanger_unique(jcr, mdb, mr);
-
db_unlock(mdb);
return stat;
}
db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
char ed1[50], ed2[50];
- if (mr->InChanger != 0 && mr->Slot != 0 && mr->StorageId != 0 &&
- mr->MediaId != 0) {
- Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE "
- "Slot=%d AND StorageId=%s AND MediaId!=%s",
- mr->Slot,
- edit_int64(mr->StorageId, ed1), edit_int64(mr->MediaId, ed2));
- Dmsg1(400, "%s\n", mdb->cmd);
- UPDATE_DB(jcr, mdb, mdb->cmd);
+ if (mr->InChanger != 0 && mr->Slot != 0 && mr->StorageId != 0) {
+
+ if (mr->MediaId != 0) {
+ Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE "
+ "Slot=%d AND StorageId=%s AND MediaId!=%s",
+ mr->Slot,
+ edit_int64(mr->StorageId, ed1), edit_int64(mr->MediaId, ed2));
+
+ } else if (*mr->VolumeName) {
+ Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE "
+ "Slot=%d AND StorageId=%s AND VolumeName!='%s'",
+ mr->Slot,
+ edit_int64(mr->StorageId, ed1), mr->VolumeName);
+
+ } else { /* used by ua_label to reset all volume with this slot */
+ Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE "
+ "Slot=%d AND StorageId=%s",
+ mr->Slot,
+ edit_int64(mr->StorageId, ed1), mr->VolumeName);
+ }
+ Dmsg1(100, "%s\n", mdb->cmd);
+ UPDATE_DB(jcr, mdb, mdb->cmd);
}
}