api2/config/{drive, changer}: prevent adding same device multiple times

this check is not perfect since there are often multiple device
nodes per drive/changer, but from the scan api we should return always
the same, so for an api user this should be enough

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-01-28 12:59:44 +01:00 committed by Dietmar Maurer
parent cef4654ff4
commit b03ec281bf
2 changed files with 19 additions and 4 deletions

View File

@ -59,8 +59,16 @@ pub fn create_changer(
check_drive_path(&linux_changers, &path)?; check_drive_path(&linux_changers, &path)?;
if config.sections.get(&name).is_some() { let existing: Vec<ScsiTapeChanger> = config.convert_to_typed_array("changer")?;
bail!("Entry '{}' already exists", name);
for changer in existing {
if changer.name == name {
bail!("Entry '{}' already exists", name);
}
if changer.path == path {
bail!("Path '{}' already in use by '{}'", path, changer.name);
}
} }
let item = ScsiTapeChanger { let item = ScsiTapeChanger {

View File

@ -56,8 +56,15 @@ pub fn create_drive(param: Value) -> Result<(), Error> {
check_drive_path(&linux_drives, &item.path)?; check_drive_path(&linux_drives, &item.path)?;
if config.sections.get(&item.name).is_some() { let existing: Vec<LinuxTapeDrive> = config.convert_to_typed_array("linux")?;
bail!("Entry '{}' already exists", item.name);
for drive in existing {
if drive.name == item.name {
bail!("Entry '{}' already exists", item.name);
}
if drive.path == item.path {
bail!("Path '{}' already used in drive '{}'", item.path, drive.name);
}
} }
config.set_data(&item.name, "linux", &item)?; config.set_data(&item.name, "linux", &item)?;