Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target: Add register_type and preempt_type enums to clarify code

core_scsi3_enulate_pro_register took an 'ignore_key' parameter that
really distinguished between REGISTER and REGISTER_AND_IGNORE_EXISTING_KEY
registration types, which was a little confusing. Same situation for
PREEMPT and PREEMPT_AND_ABORT. Use enums to add a little more
descriptiveness to the code.

Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Andy Grover and committed by
Nicholas Bellinger
33ce6a87 317ddd25

+44 -33
+44 -33
drivers/target/target_core_pr.c
··· 65 65 return 1; 66 66 } 67 67 68 + enum register_type { 69 + REGISTER, 70 + REGISTER_AND_IGNORE_EXISTING_KEY, 71 + REGISTER_AND_MOVE, 72 + }; 73 + 74 + enum preempt_type { 75 + PREEMPT, 76 + PREEMPT_AND_ABORT, 77 + }; 78 + 68 79 static void __core_scsi3_complete_pro_release(struct se_device *, struct se_node_acl *, 69 80 struct t10_pr_registration *, int); 70 81 ··· 880 869 } 881 870 882 871 static void __core_scsi3_add_registration(struct se_device *, struct se_node_acl *, 883 - struct t10_pr_registration *, int, int); 872 + struct t10_pr_registration *, enum register_type, int); 884 873 885 874 static int __core_scsi3_check_aptpl_registration( 886 875 struct se_device *dev, ··· 973 962 struct se_device *dev, 974 963 struct se_node_acl *nacl, 975 964 struct t10_pr_registration *pr_reg, 976 - int register_type) 965 + enum register_type register_type) 977 966 { 978 967 struct se_portal_group *se_tpg = nacl->se_tpg; 979 968 char i_buf[PR_REG_ISID_ID_LEN]; ··· 984 973 PR_REG_ISID_ID_LEN); 985 974 986 975 pr_debug("SPC-3 PR [%s] Service Action: REGISTER%s Initiator" 987 - " Node: %s%s\n", tfo->get_fabric_name(), (register_type == 2) ? 988 - "_AND_MOVE" : (register_type == 1) ? 976 + " Node: %s%s\n", tfo->get_fabric_name(), (register_type == REGISTER_AND_MOVE) ? 977 + "_AND_MOVE" : (register_type == REGISTER_AND_IGNORE_EXISTING_KEY) ? 989 978 "_AND_IGNORE_EXISTING_KEY" : "", nacl->initiatorname, 990 979 (prf_isid) ? i_buf : ""); 991 980 pr_debug("SPC-3 PR [%s] registration on Target Port: %s,0x%04x\n", ··· 1009 998 struct se_device *dev, 1010 999 struct se_node_acl *nacl, 1011 1000 struct t10_pr_registration *pr_reg, 1012 - int register_type, 1001 + enum register_type register_type, 1013 1002 int register_move) 1014 1003 { 1015 1004 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; ··· 1075 1064 u64 sa_res_key, 1076 1065 int all_tg_pt, 1077 1066 int aptpl, 1078 - int register_type, 1067 + enum register_type register_type, 1079 1068 int register_move) 1080 1069 { 1081 1070 struct t10_pr_registration *pr_reg; ··· 2041 2030 2042 2031 static sense_reason_t 2043 2032 core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, 2044 - int aptpl, int all_tg_pt, int spec_i_pt, int ignore_key) 2033 + int aptpl, int all_tg_pt, int spec_i_pt, enum register_type register_type) 2045 2034 { 2046 2035 struct se_session *se_sess = cmd->se_sess; 2047 2036 struct se_device *dev = cmd->se_dev; ··· 2094 2083 if (core_scsi3_alloc_registration(cmd->se_dev, 2095 2084 se_sess->se_node_acl, se_deve, isid_ptr, 2096 2085 sa_res_key, all_tg_pt, aptpl, 2097 - ignore_key, 0)) { 2086 + register_type, 0)) { 2098 2087 pr_err("Unable to allocate" 2099 2088 " struct t10_pr_registration\n"); 2100 2089 return TCM_INVALID_PARAMETER_LIST; ··· 2147 2136 pr_reg = pr_reg_e; 2148 2137 type = pr_reg->pr_res_type; 2149 2138 2150 - if (!ignore_key) { 2139 + if (register_type == REGISTER) { 2151 2140 if (res_key != pr_reg->pr_res_key) { 2152 2141 pr_err("SPC-3 PR REGISTER: Received" 2153 2142 " res_key: 0x%016Lx does not match" ··· 2291 2280 pr_debug("SPC-3 PR [%s] REGISTER%s: Changed Reservation" 2292 2281 " Key for %s to: 0x%016Lx PRgeneration:" 2293 2282 " 0x%08x\n", cmd->se_tfo->get_fabric_name(), 2294 - (ignore_key) ? "_AND_IGNORE_EXISTING_KEY" : "", 2283 + (register_type == REGISTER_AND_IGNORE_EXISTING_KEY) ? "_AND_IGNORE_EXISTING_KEY" : "", 2295 2284 pr_reg->pr_reg_nacl->initiatorname, 2296 2285 pr_reg->pr_res_key, pr_reg->pr_res_generation); 2297 2286 ··· 2821 2810 struct list_head *preempt_and_abort_list, 2822 2811 int type, 2823 2812 int scope, 2824 - int abort) 2813 + enum preempt_type preempt_type) 2825 2814 { 2826 2815 struct se_node_acl *nacl = pr_reg->pr_reg_nacl; 2827 2816 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; ··· 2845 2834 2846 2835 pr_debug("SPC-3 PR [%s] Service Action: PREEMPT%s created new" 2847 2836 " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2848 - tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "", 2837 + tfo->get_fabric_name(), (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : "", 2849 2838 core_scsi3_pr_dump_type(type), 2850 2839 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2851 2840 pr_debug("SPC-3 PR [%s] PREEMPT%s from Node: %s%s\n", 2852 - tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "", 2841 + tfo->get_fabric_name(), (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : "", 2853 2842 nacl->initiatorname, (prf_isid) ? &i_buf[0] : ""); 2854 2843 /* 2855 2844 * For PREEMPT_AND_ABORT, add the preempting reservation's ··· 2887 2876 2888 2877 static sense_reason_t 2889 2878 core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key, 2890 - u64 sa_res_key, int abort) 2879 + u64 sa_res_key, enum preempt_type preempt_type) 2891 2880 { 2892 2881 struct se_device *dev = cmd->se_dev; 2893 2882 struct se_node_acl *pr_reg_nacl; ··· 2907 2896 if (!pr_reg_n) { 2908 2897 pr_err("SPC-3 PR: Unable to locate" 2909 2898 " PR_REGISTERED *pr_reg for PREEMPT%s\n", 2910 - (abort) ? "_AND_ABORT" : ""); 2899 + (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : ""); 2911 2900 return TCM_RESERVATION_CONFLICT; 2912 2901 } 2913 2902 if (pr_reg_n->pr_res_key != res_key) { ··· 2976 2965 pr_reg_nacl = pr_reg->pr_reg_nacl; 2977 2966 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; 2978 2967 __core_scsi3_free_registration(dev, pr_reg, 2979 - (abort) ? &preempt_and_abort_list : 2968 + (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 2980 2969 NULL, calling_it_nexus); 2981 2970 released_regs++; 2982 2971 } else { ··· 3004 2993 pr_reg_nacl = pr_reg->pr_reg_nacl; 3005 2994 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; 3006 2995 __core_scsi3_free_registration(dev, pr_reg, 3007 - (abort) ? &preempt_and_abort_list : 2996 + (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 3008 2997 NULL, 0); 3009 2998 released_regs++; 3010 2999 } ··· 3033 3022 */ 3034 3023 if (pr_res_holder && all_reg && !(sa_res_key)) { 3035 3024 __core_scsi3_complete_pro_preempt(dev, pr_reg_n, 3036 - (abort) ? &preempt_and_abort_list : NULL, 3037 - type, scope, abort); 3025 + (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : NULL, 3026 + type, scope, preempt_type); 3038 3027 3039 - if (abort) 3028 + if (preempt_type == PREEMPT_AND_ABORT) 3040 3029 core_scsi3_release_preempt_and_abort( 3041 3030 &preempt_and_abort_list, pr_reg_n); 3042 3031 } ··· 3047 3036 &pr_reg_n->pr_aptpl_buf[0], 3048 3037 pr_tmpl->pr_aptpl_buf_len)) { 3049 3038 pr_debug("SPC-3 PR: Updated APTPL" 3050 - " metadata for PREEMPT%s\n", (abort) ? 3039 + " metadata for PREEMPT%s\n", (preempt_type == PREEMPT_AND_ABORT) ? 3051 3040 "_AND_ABORT" : ""); 3052 3041 } 3053 3042 } ··· 3114 3103 pr_reg_nacl = pr_reg->pr_reg_nacl; 3115 3104 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; 3116 3105 __core_scsi3_free_registration(dev, pr_reg, 3117 - (abort) ? &preempt_and_abort_list : NULL, 3106 + (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : NULL, 3118 3107 calling_it_nexus); 3119 3108 /* 3120 3109 * e) Establish a unit attention condition for the initiator ··· 3131 3120 * I_T nexus using the contents of the SCOPE and TYPE fields; 3132 3121 */ 3133 3122 __core_scsi3_complete_pro_preempt(dev, pr_reg_n, 3134 - (abort) ? &preempt_and_abort_list : NULL, 3135 - type, scope, abort); 3123 + (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : NULL, 3124 + type, scope, preempt_type); 3136 3125 /* 3137 3126 * d) Process tasks as defined in 5.7.1; 3138 3127 * e) See above.. ··· 3172 3161 * been removed from the primary pr_reg list), except the 3173 3162 * new persistent reservation holder, the calling Initiator Port. 3174 3163 */ 3175 - if (abort) { 3164 + if (preempt_type == PREEMPT_AND_ABORT) { 3176 3165 core_tmr_lun_reset(dev, NULL, &preempt_and_abort_list, cmd); 3177 3166 core_scsi3_release_preempt_and_abort(&preempt_and_abort_list, 3178 3167 pr_reg_n); ··· 3183 3172 &pr_reg_n->pr_aptpl_buf[0], 3184 3173 pr_tmpl->pr_aptpl_buf_len)) { 3185 3174 pr_debug("SPC-3 PR: Updated APTPL metadata for PREEMPT" 3186 - "%s\n", abort ? "_AND_ABORT" : ""); 3175 + "%s\n", (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : ""); 3187 3176 } 3188 3177 } 3189 3178 ··· 3194 3183 3195 3184 static sense_reason_t 3196 3185 core_scsi3_emulate_pro_preempt(struct se_cmd *cmd, int type, int scope, 3197 - u64 res_key, u64 sa_res_key, int abort) 3186 + u64 res_key, u64 sa_res_key, enum preempt_type preempt_type) 3198 3187 { 3199 3188 switch (type) { 3200 3189 case PR_TYPE_WRITE_EXCLUSIVE: ··· 3204 3193 case PR_TYPE_WRITE_EXCLUSIVE_ALLREG: 3205 3194 case PR_TYPE_EXCLUSIVE_ACCESS_ALLREG: 3206 3195 return core_scsi3_pro_preempt(cmd, type, scope, res_key, 3207 - sa_res_key, abort); 3196 + sa_res_key, preempt_type); 3208 3197 default: 3209 3198 pr_err("SPC-3 PR: Unknown Service Action PREEMPT%s" 3210 - " Type: 0x%02x\n", (abort) ? "_AND_ABORT" : "", type); 3199 + " Type: 0x%02x\n", (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : "", type); 3211 3200 return TCM_INVALID_CDB_FIELD; 3212 3201 } 3213 3202 } ··· 3763 3752 switch (sa) { 3764 3753 case PRO_REGISTER: 3765 3754 ret = core_scsi3_emulate_pro_register(cmd, 3766 - res_key, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 0); 3755 + res_key, sa_res_key, aptpl, all_tg_pt, spec_i_pt, REGISTER); 3767 3756 break; 3768 3757 case PRO_RESERVE: 3769 3758 ret = core_scsi3_emulate_pro_reserve(cmd, type, scope, res_key); ··· 3776 3765 break; 3777 3766 case PRO_PREEMPT: 3778 3767 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope, 3779 - res_key, sa_res_key, 0); 3768 + res_key, sa_res_key, PREEMPT); 3780 3769 break; 3781 3770 case PRO_PREEMPT_AND_ABORT: 3782 3771 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope, 3783 - res_key, sa_res_key, 1); 3772 + res_key, sa_res_key, PREEMPT_AND_ABORT); 3784 3773 break; 3785 3774 case PRO_REGISTER_AND_IGNORE_EXISTING_KEY: 3786 3775 ret = core_scsi3_emulate_pro_register(cmd, 3787 - 0, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 1); 3776 + 0, sa_res_key, aptpl, all_tg_pt, spec_i_pt, REGISTER_AND_IGNORE_EXISTING_KEY); 3788 3777 break; 3789 3778 case PRO_REGISTER_AND_MOVE: 3790 3779 ret = core_scsi3_emulate_pro_register_and_move(cmd, res_key,