@@ -1,6 +1,8 @@
#ifndef SCSI_UTILS_H
#define SCSI_UTILS_H
+#include "block/block-common.h"
+#include "scsi/constants.h"
#ifdef CONFIG_LINUX
#include <scsi/sg.h>
#endif
@@ -135,6 +137,9 @@ uint32_t scsi_data_cdb_xfer(uint8_t *buf);
uint32_t scsi_cdb_xfer(uint8_t *buf);
int scsi_cdb_length(uint8_t *buf);
+BlockPrType scsi_pr_type_to_block(SCSIPrType type);
+SCSIPrType block_pr_type_to_scsi(BlockPrType type);
+
/* Linux SG_IO interface. */
#ifdef CONFIG_LINUX
#define SG_ERR_DRIVER_TIMEOUT 0x06
@@ -658,3 +658,43 @@ int scsi_sense_from_host_status(uint8_t host_status,
}
return GOOD;
}
+
+BlockPrType scsi_pr_type_to_block(SCSIPrType type)
+{
+ switch (type) {
+ case SCSI_PR_WRITE_EXCLUSIVE:
+ return BLK_PR_WRITE_EXCLUSIVE;
+ case SCSI_PR_EXCLUSIVE_ACCESS:
+ return BLK_PR_EXCLUSIVE_ACCESS;
+ case SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY:
+ return BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY;
+ case SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY:
+ return BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY;
+ case SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS:
+ return BLK_PR_WRITE_EXCLUSIVE_ALL_REGS;
+ case SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS:
+ return BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS;
+ }
+
+ return 0;
+}
+
+SCSIPrType block_pr_type_to_scsi(BlockPrType type)
+{
+ switch (type) {
+ case BLK_PR_WRITE_EXCLUSIVE:
+ return SCSI_PR_WRITE_EXCLUSIVE;
+ case BLK_PR_EXCLUSIVE_ACCESS:
+ return SCSI_PR_EXCLUSIVE_ACCESS;
+ case BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY:
+ return SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY;
+ case BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY:
+ return SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY;
+ case BLK_PR_WRITE_EXCLUSIVE_ALL_REGS:
+ return SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS;
+ case BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS:
+ return SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS;
+ }
+
+ return 0;
+}