scsi: target: core: Parse APTPL res_type and res_scope as hex
Subsystems (3)
PATCH 1/1 scsi: target: core: Parse APTPL res_type and res_scope as hex
core_scsi3_update_aptpl_buf() saves the reservation holder's type and scope to the APTPL metadata file as zero-padded hex ("res_type=%02x", "res_scope=%02x"), but target_pr_res_aptpl_metadata_store() reads them back with "%d" tokens and match_int(), which parse with base 0. A leading zero selects octal, so match_token() parses only the "0" of "res_type=08", the trailing "8" makes the token not match, and the field is ignored as unknown. An Exclusive Access - All Registrants holder (type 0x8) is left with type 0 and the write fails with -EINVAL and
Illegal PR type: 0x00 for reservation holder
Userspace that restores APTPL state by writing the saved records back to pr/res_aptpl_metadata (rtslib-fb does this when it recreates a storage object) therefore loses every type 8 reservation across a target restart, and with rtslib the storage object creation fails. The other valid types (1, 3, 5, 6, 7) and scope 0 only work because their octal and decimal values coincide.
Keep the on-disk format and parse both fields as hex. The valid type and scope values have the same hex and decimal representation, so records written in decimal by hand keep working.
--- drivers/target/target_core_configfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/target/target_core_configfs.c +4 -4
@@ -2126,8 +2126,8 @@ static match_table_t tokens = { {Opt_initiator_sid, "initiator_sid=%s"}, {Opt_sa_res_key, "sa_res_key=%s"}, {Opt_res_holder, "res_holder=%d"}, - {Opt_res_type, "res_type=%d"}, - {Opt_res_scope, "res_scope=%d"}, + {Opt_res_type, "res_type=%x"}, + {Opt_res_scope, "res_scope=%x"}, {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, {Opt_mapped_lun, "mapped_lun=%u"}, {Opt_target_fabric, "target_fabric=%s"},
@@ -2229,13 +2229,13 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, res_holder = arg;break ;case Opt_res_type: - ret =match_int (args, &arg); + ret =match_hex (args, &arg);if (ret) goto out; type = (u8 )arg;break ;case Opt_res_scope: - ret =match_int (args, &arg); + ret =match_hex (args, &arg);if (ret) goto out;break ;
Signature · 1 line
2.55.0
Quoted 10 lines · Ciro Iriarte
core_scsi3_update_aptpl_buf()saves the reservation holder's type and scope to the APTPL metadata file as zero-padded hex ("res_type=%02x", "res_scope=%02x"), buttarget_pr_res_aptpl_metadata_store()reads them back with "%d" tokens andmatch_int(), which parse with base 0. A leading zero selects octal, somatch_token()parses only the "0" of "res_type=08", the trailing "8" makes the token not match, and the field is ignored as unknown. An Exclusive Access - All Registrants holder (type0x8) is left with type 0 and the write fails with-EINVALand[...]
Applied to 7.4/scsi-fixes, thanks!
[1/1] scsi: target: core: Parse APTPL res_type and res_scope as hex
https://git.kernel.org/mkp/scsi/c/08f08a6d49ef
Signature · 1 line
Martin K. Petersen