mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
Improve SCSI volume key generation
The SCSI volumes get a better 'key' field based on the fully qualified volume path. All SCSI volumes have a unique serial available in hardware which can be obtained by sending a suitable SCSI command. Call out to udev's 'scsi_id' command to fetch this value * src/storage/storage_backend_scsi.c: Improve volume key field value stability and uniqueness
This commit is contained in:
parent
ef264e82ee
commit
fdcd06ef71
@ -33,6 +33,7 @@
|
||||
#include "memory.h"
|
||||
#include "logging.h"
|
||||
#include "files.h"
|
||||
#include "command.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||
|
||||
@ -160,6 +161,45 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
virStorageBackendSCSISerial(const char *dev)
|
||||
{
|
||||
char *serial = NULL;
|
||||
#ifdef HAVE_UDEV
|
||||
virCommandPtr cmd = virCommandNewArgList(
|
||||
"/lib/udev/scsi_id",
|
||||
"--replace-whitespace",
|
||||
"--whitelisted",
|
||||
"--device", dev,
|
||||
NULL
|
||||
);
|
||||
|
||||
/* Run the program and capture its output */
|
||||
virCommandSetOutputBuffer(cmd, &serial);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
#endif
|
||||
|
||||
if (serial && STRNEQ(serial, "")) {
|
||||
char *nl = strchr(serial, '\n');
|
||||
if (nl)
|
||||
*nl = '\0';
|
||||
} else {
|
||||
VIR_FREE(serial);
|
||||
if (!(serial = strdup(dev)))
|
||||
virReportOOMError();
|
||||
}
|
||||
|
||||
#ifdef HAVE_UDEV
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
#endif
|
||||
|
||||
return serial;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
|
||||
uint32_t host ATTRIBUTE_UNUSED,
|
||||
@ -233,10 +273,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
|
||||
goto free_vol;
|
||||
}
|
||||
|
||||
/* XXX should use logical unit's UUID instead */
|
||||
vol->key = strdup(vol->target.path);
|
||||
if (vol->key == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(vol->key = virStorageBackendSCSISerial(vol->target.path))) {
|
||||
retval = -1;
|
||||
goto free_vol;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user