/drivers/sh/superhyway/

rel='vcs-git' href='ssh://rtsrv.cs.unc.edu/public/litmus-rt-edfsc.git' title='litmus-rt-edfsc.git Git repository'/>
aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/target/target_core_pr.c
blob: d56f2aaba9af9a6bb4b89d5c1080d426cba84e63 (plain) (tree)
1
2
3
4
5
6
7





                                                                                
                                       


















                                                                                


                           
                       




                                    

                                       

                                        
                                 














                                                           
                                 



                                           
                                         
                              
 
                                                            

 










                                         
                                                                                       
                                                                                      
 

                                                  
 



                                               




                         
                      

         
                                                 

                         
                                                            
                                                


                                                                           
                                                        
         
 
                 

 



                                                                                   
                                                                      

                                                  
                                            
                                           
                                                       

                         

























                                                                                 
                                 





                                                                                
                                 






















                                                                             
                              

         
                 

 

                                                    


                                               
                                    
               
 
                                   
                         

                                                          
                         

                                                

                                              




                                                            
 


                                                         
                                          

                                                                           
                                          
                                                                               
         
                           
                                                                

                                                                               
                                                  
 


                                                

                                       

 

                                                    


                                               
                                    

                               
 

                                          
                                                                
                                                      
                                                   




                                                                                   
                                   
                         

                                                          
                         
 


                                                
                           


                                                               
                                                                     
                                                            
                                                        
                                                  
                                                                   
                                                                    
                                                                 

                                                          
                                               
                                


                                                       
                                                            

                                                            
                                                                              
         
                                                               

                                                                    
                                                  
 


                                                

                                               
                   

 








                                                                  

                        
                                             
                                     
                                                  





                                                                    
 
                                                                      

                                                                 
                                                                     




































                                                                                
                               
















































                                                                           
                                                                       
                                                                    
                                       



                        
                                                                            



                        
                                                                            

































                                                                         
                                                                     
                                                 
                                       





                                
                                  

                           
                                   






                                            
                                                                       

                     
                                 
                                                               

                                                              
 





                                                                     
                                      



                                                           
                                                                     














                                                                              
 
                                                
                                                                        



                                                                              
 







                                                                           
 
                                                                       

                                                                      
 


                                 
                                                                   







                                                                           

                                                     
























                                                                     
                                                


                 

                                                          
                
 









                                                                          
                                          




                                                








                                                                      


                                                                 

                                                                          


                            






















































                                                                                       
                    



                                                   
                       






                                                                                
                                                        






                                                                             
                                                                          

                                                                           
                                                  





















                                                                                 
                                                               








                                                                              
                                                                 
                                                                    

                                                                        











                                                                                
                                          

                                                                        










                                                                          
                                                        















                                                                         
                                        












                                           

                                                                      
                               


                                                                 

                                                                          
                               
         








































                                                                              
                                                                        










                                                                           

                                             
                                                                       




                                                
                                                                      
                                                                   
                                                   

                                                             
                                                      
                                                                            
                       


                                                                                   
                                                                                       









                                                        
                                                       










                                                                            

                                                           








                                                                              
 
                                                        








































                                                                               

                                 
 
                                                                  
 
                                                               










                                                                   
                                         


                                                      

                                                 
                                                                       
 
                                                                     

                                                                                               
                                                                     
                       
                                                                          

                                                                  
                                                                      

                                                              
                                      
                                                                   












                                                                          
                                         

                          

                                                                      
                                                       










                                                                                   
                                                     










                                                                              
                                                       



































                                                                              
                                         





                                                                       
                    
                              










                                                              
                                                       
















                                                                          
                                                   




                                                                             
                                                                              
                                                                     

                                                 
                                                               







                                                                                 
                          



                                                      
                                                       















                                                             
                                                              
                                                    
                                                                      








                                                                     
                                               

 
                                             








                                                       
                             




                                                        
                                                                       










                                                                               
                                                                           




                                                                           
                                                                  




                                                                      
                                                                


                                                                              
                             






                                                
                                                              








                                                                
                                                       
                                       

                                             
                                                                       


                                                   

                                               













                                                                             
                                                                      




                                                        
                                                                     

                                                        
                       
                                                                      

                                                              
                                      
                                                                   


                                                                        
                                      

                                           













                                                                               
                                                       
                                                                        
                              






                                                                    



                                                                                  




                                                                           


                                                                            













                                                                     
                                                       






                                                                             
                                                                       














                                                                              






                                                                  
                                                               




                                                                     
                                                          

                                                 
                                              








                                                                   
                                                               







                                                                      
                                                       


                       
                                                          

                                                  
                                               









                                                                      
                     




                                    
                                                               










                                                                         
                       
                                                      




                                    
                                                          

                                                        
                                              

 

                              






                                    
                                            

                                                          
                                                  



                                                                          
                                 

                                                                  
                           
                                                                        
                                                          
                           
                              
                             

                          
                                                                            






                                                                              

                                                        
                                                              





                                                       
                                                                   

                                                                            
                            
                                
                                                              








                                                                           
 


                                                                     
                                                 


                         
                                          




                                                             










                                                                          
                                                                    

                                                                      

                                                 














                                                                             
                                     
                                         
                                                         
                                        
                                         

                                                                       












                                                                                      
                                   

                                         
                                                                  

                                                        
                                                                  
                                                                      
                                                          
                                                                          

                                                                             

                          
                                                                                


                                                                              
                                                               

                                                                          

                                                                                
                                                                 
 
                                             




                                                                      
                                                                            
                                                                      
                                                                           
                                                                                
                                                                      

                                                                             


                                           
                                                                       
                                                       
                                                                        






                                                                         

                                                                     
                                                       

                                                         
                 
 
                                                                              
                                                     
                                                                                  
                                                         
 
                                     
                                                                     


                                                                            

                                                         







                                                                                  

                                                                 
                                                                
                                                                        



                                                                        

                                                         

                 
                                                                  
                                                                
                                                     
                                                                   

                                                                        

                                                                     
                 
 
                                                                  
                                                         
                                                                
                                                                                
 






















                                                                             

                                                                


                                                                        

                                                                     





















                                                                                
                                                                          

                                                                       
                                   



                                                                        

                                                         








                                                                    
 
                                      
 























                                                                                
                                                                                    
 
                                                                         

                                                           
                                                                
                                                                             
                                                                         
                                                                                       









                                                                
          
                                      
    
























                                                                                 











                                                                
                                       

                              
                             


                                    



                                             
                    
 

                                                  


                                       
                                                                   
























                                                                               
                                                                   








                                                                               
                                                                              




                                                                             
                                                              
                                                          
                                                     

                                        







                                                                             


                                                                    

                                                                              
                                                              
                                                          
                                                     

                                        



                                                   
 
                       

                                                                            

                                                    




                                                

                                            
                           
 
                                            
                          

                                               
                             

                

                             
                                                  
                                                                    
                                               
                                 



                                                                             
                           
                                                         
                                           
                                     

         
                                                                      
 
                                                           
 
                    
                                                                          
                   
 
                                    

 



                                                                      
                                                                                          
 

                           
 


                                                                      
                                                                     

                                                                  
 

                                                                      
 

                         
 





                                                                     
                           
                                            

         









                                                              

 

                                                                                
                                                                                             
 
                                                  
                                            
                                     
                                            
                                       
                                                                   
                                                       
                                                                  
                                          
                                
 

                                                                        
                                                              

                                 
                                                                      
 
                                                         
                                                         
                                                                                 





                                                                               

                                                                              
                              
                                                                    
                                                                          
                                                        



                                                     
                                
                                 
 
                                 




                                                                               
                                                                      

                                                                                
                                                            
                                                           
                                                                         
                                                                  














                                                                                
 
                                                                     

         









                                                                             


                        

                                                        
                                                 
                         





                                                              

                                                       


                                                                       
                         


          
                                                                        
           


















                                                                                                               


                                                                          
                                    
                                                       
                                 
                 

                                                       
                  

                                                                               
                   
















                                                                                 

                         
 
                  
                                                                   
                   
                                                                             
                              
 











                                                                        

                                                                 








                                                                        
                         
                 
 
                                                         
         
 
                                                            
 
    

                                              
                   























                                                                  

                                                                            
 
                                            
                                                  
                                            
                                                           
                                                       
                                       
                           


                                             

                                                                        
                                                              
         


                                                                      
                                                                            
                                         

                                                   
                                                                
                                                              










                                                                                
                                                                     

                                                                       

                                               











                                                                                
                                                                   

                                                 







                                                                                     
                            
                                                             









                                                                                


                                                                       
                                                                                     
                                                                 

                                                                              
                                                               
                                                                    
                                                                                   


                                                                           

                                                       










                                                                                     
                                                                 


                                                                               
                                                               
                                                                    
                                                                                   


                                                                           

                                                       











                                                                               

                                    








                                                                            
                                                                       
 
                                                                    
                                                               
                                                                              
                                                    
                                                      
                                                       
                                                            
                               

                                                

                                                                     
 

                
                                      
                   

 


                                                                       
 






                                              
                                                                         
                
                                                                       
                                           
                                             
         








                                                           

                     


                                                                         
                                              

                                             
                                                                       

                                                                  













                                                                    
 


























                                                                                 
                                                      
                                                               
                       





                                                                               


                                                                       

                                            

                                                  
                                                                      
                                                       

                               
 

                                                                        
                                                              




                                                                              

                                                   
                                                                
                                                              














                                                                                
                             



                                                                 
                                    











                                                                             
                                    
         
 














                                                                               
                                                                     


                                                                       

                                               









                                                                             
                                                               


                                                                         
                                                       
                                                            
                                                                           


                                                                   

                                               

















                                                                                
                                                        































                                                                          


                                                                     
               
                                      
                   

 

                                                             


                                            
                                                  
                                                       





                                                                                   
                                                        
                                                       

                                                   
                                                              
                                                              












                                                                                
                                                    



                                                                      
                                                








                                                                             
                                                                       




















                                                                              
                                      




                                                                              
                                                                  
                                                
 
                                                              













                                                           
                                       



                                                                      

                                             
                                                                       
          
                                                              


                                                            
                                                                                





                                        
                                                                      
                                                               
                                                                                                

                                                    
                                                             
                                                                                                
                                            






















                                                                            
                                                                     




                                           



                                                          

                                                                            
                                                               
 
                                            
                                        
                                                  
                                          
                                                                                   
                                                       
                                  

                                                    
                                        
 

                                                              
 
                                                                              
                                         

                                                   
                                                                 
                                                                                 
                                                


                                                
                                                

                                         
                                                                   
                                                
                                                  
         







                                                                             
                                      

                                                        
                                                  









                                                                              
                                                                          

























                                                                                
                                       

                                                                     
                                                             




                                                                                
                                                                                                       
                                                                        






                                                                               
                                                                             








                                                                            
                                                             







                                                                                
                                                                                                       
                                                         
                         
                                              

                                                                   
                                                                          








                                                                               
                                           

                                                                
                                                        







                                                                        

                                                                                                     
 
                                                              




                                                                           

                                                                             

                                                
                                                      

































                                                                     

                                                                                























                                                                       
                                                                                                     







                                                                            
                                                                  






                                                                        

                                                                                             






































                                                                           
                                                




                                                                             

                                                                     

                                        
                                              


                 

                                                                       
                                                                            
 






                                              
                                                                        
                                                                        
                
                                                                   
                                                                                                          
                                             
         


 


                                                                         
 
                                                  
                                            
                                                 
                                            




                                                                             
                                                       
                           
                                     
                                                          
                                 
                                                     
                           


                                  

                                                                        
                                                              
         
 

                                             
                                    





                                                                         
                                                                            
                                         

                                                                 
                                                            
                                                              





                                                                               
                                                              

                                                                                

                                               



                                                                  

                                                                   
                                         

                                                 
         
 




                                                                              
                                          




                                                             





                                          
                                      
                   

                                                 
                                                                       

                                                                         

                                                 






                                                                    
                                 
                                 
                                                      
                                 

                                 
                                                              

                                                
                                                              
                                                                    
                                                      
                                                                      

                                                                     






                                              

                                                                     

                                                                           

                                                 
         
 
                                          



                                                             
                                       
 
                                                                             
                                                  
 
                                                                              
                                                             



                                                                           
                                                 


                                                                 
                                                                    

                                                                         
                                                             



                                                                               

                                                                     
                                                              
                                                 


                         
                                      

                   
                                                                      













                                                                                
                            

                                       

                                                                    

                                                                              
                                                 

                         

                                                                       


                                                                             
                                                 





                                                                                   
                                                   

                                                                      

                                                                
                                                     
 

                                                              

                                                                           
                                                 

                         

                                                            
                                                             
                                            
                                                                
                                     
                                                 

                         
 
                                                                      

                                                                         
 




                                                                                  

                                                                    
                                                                         
                                                 


                         
                                                          
                                                                   
                                                           
                                    
                                                             

                         
 
                                                                     


                                                                             
 





                                                                         

                                                                    

                                                        
                                            








                                                                         
                                                                 

                                                              
                                               












                                                                                
                                                                    


                                                                             
                                               





























                                                                               
                           
                                                              
                                                                       
                                                              
                                                                
                                                         










                                                                               
                                                                        








                                                                               
                                                                       


                                                              
                     


                                                                          
                                                                  



                                                                               
                                                               

                                                                      
                                                      



















                                                                                
                                                              
 
                                      
 


                                           
                
                                              




                                                                

               
















                                                                                

                                               
 
                                            
                                                 
                           


                                                    
                           









                                                                             
                                                                         


                                                                     
                                                

         



                                                                                   

                                                              

                                    
                                                                
                                                                     
                                                  
         
 





                                                                         
 
                                          


                                                              
















                                                                          






                                                                            
                                      

                   


                                                                 

                                                           
 








                                                                            
                                                                       
                                       
                                                                   
                                                                
                                                  
         
 






                                                                       
                                                          
                                                                                    
                      
                         

                                                                                
                         

                                                                                
                       

                                                                 
                         
                                                                      
                                                                      
                      
                                   
                                                                      
                                                                                
                      
                                                  
                                                          
                                                                                                      
                      
                                   
                                                                            
                                                          
                      
                
                                                               
                                                            
                                             

         

                                               
                   






                                                            

                                            
 
                                            
                                           
                           


                                   
                                                               
                                                          
                                             

         
                                          


                                                              



                                                            
 

                                                                   


















                                                                        
                                                    





                                          
                                      
 







                                                                     

                                                   
 
                                            
                                           
                           



                                                                           
                                                                       
                                                          
                                             

         
                                          


                                                              



                                                            
 

                                              
                     







                                                      


                                          



































                                                                              

    
                                                
                                      








                                                           

                                                      
 
                                            
                                                       
                           


                                              
                                                                      
                                                             
                                             

         
                                          

                                                              
 
                                         




























                                                                              
                                      
 







                                                        

                                                   
 
                                            
                                    

                                                        
                                                       
                           

                                                                  

                                                               

                                   
                                                                      
                                                          
                                             

         
                                          

                                                              
 



                                                            
 












                                                                                







                                                                   
                                                       




                                                                    
                                                                               


                                                                       
                                                                 

                                                                          
                                                               
























                                                                       

                                                                    




                                                                    




                                                            
                                 
                 











                                                                              
                                                




                                                                                 
                                                                                 



                                                                            
                                                                              


                                                                            
                                                       



























                                                                         
                                      
 


                 

                                              
 
                           
 








                                                                             
                                                                         
                                                                     

                                                               
                                                

         

                                            

                                                    
                                  

                                                           
                                     

                                                              
                                  

                                                           


                                                                        
                                             

         

                                               
                   

 

                                            
 
                                            
                           
 





                                                                         
 





                                                               
 
                   
 
/*******************************************************************************
 * Filename:  target_core_pr.c
 *
 * This file contains SPC-3 compliant persistent reservations and
 * legacy SPC-2 reservations with compatible reservation handling (CRH=1)
 *
 * (c) Copyright 2009-2013 Datera, Inc.
 *
 * Nicholas A. Bellinger <nab@kernel.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ******************************************************************************/

#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/file.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <asm/unaligned.h>

#include <target/target_core_base.h>
#include <target/target_core_backend.h>
#include <target/target_core_fabric.h>
#include <target/target_core_configfs.h>

#include "target_core_internal.h"
#include "target_core_pr.h"
#include "target_core_ua.h"

/*
 * Used for Specify Initiator Ports Capable Bit (SPEC_I_PT)
 */
struct pr_transport_id_holder {
	int dest_local_nexus;
	struct t10_pr_registration *dest_pr_reg;
	struct se_portal_group *dest_tpg;
	struct se_node_acl *dest_node_acl;
	struct se_dev_entry *dest_se_deve;
	struct list_head dest_list;
};

void core_pr_dump_initiator_port(
	struct t10_pr_registration *pr_reg,
	char *buf,
	u32 size)
{
	if (!pr_reg->isid_present_at_reg)
		buf[0] = '\0';

	snprintf(buf, size, ",i,0x%s", pr_reg->pr_reg_isid);
}

enum register_type {
	REGISTER,
	REGISTER_AND_IGNORE_EXISTING_KEY,
	REGISTER_AND_MOVE,
};

enum preempt_type {
	PREEMPT,
	PREEMPT_AND_ABORT,
};

static void __core_scsi3_complete_pro_release(struct se_device *, struct se_node_acl *,
					      struct t10_pr_registration *, int, int);

static sense_reason_t
target_scsi2_reservation_check(struct se_cmd *cmd)
{
	struct se_device *dev = cmd->se_dev;
	struct se_session *sess = cmd->se_sess;

	switch (cmd->t_task_cdb[0]) {
	case INQUIRY:
	case RELEASE:
	case RELEASE_10:
		return 0;
	default:
		break;
	}

	if (!dev->dev_reserved_node_acl || !sess)
		return 0;

	if (dev->dev_reserved_node_acl != sess->se_node_acl)
		return TCM_RESERVATION_CONFLICT;

	if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) {
		if (dev->dev_res_bin_isid != sess->sess_bin_isid)
			return TCM_RESERVATION_CONFLICT;
	}

	return 0;
}

static struct t10_pr_registration *core_scsi3_locate_pr_reg(struct se_device *,
					struct se_node_acl *, struct se_session *);
static void core_scsi3_put_pr_reg(struct t10_pr_registration *);

static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd)
{
	struct se_session *se_sess = cmd->se_sess;
	struct se_device *dev = cmd->se_dev;
	struct t10_pr_registration *pr_reg;
	struct t10_reservation *pr_tmpl = &dev->t10_pr;
	int conflict = 0;

	pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
			se_sess);
	if (pr_reg) {
		/*
		 * From spc4r17 5.7.3 Exceptions to SPC-2 RESERVE and RELEASE
		 * behavior
		 *
		 * A RESERVE(6) or RESERVE(10) command shall complete with GOOD
		 * status, but no reservation shall be established and the
		 * persistent reservation shall not be changed, if the command
		 * is received from a) and b) below.
		 *
		 * A RELEASE(6) or RELEASE(10) command shall complete with GOOD
		 * status, but the persistent reservation shall not be released,
		 * if the command is received from a) and b)
		 *
		 * a) An I_T nexus that is a persistent reservation holder; or
		 * b) An I_T nexus that is registered if a registrants only or
		 *    all registrants type persistent reservation is present.
		 *
		 * In all other cases, a RESERVE(6) command, RESERVE(10) command,
		 * RELEASE(6) command, or RELEASE(10) command shall be processed
		 * as defined in SPC-2.
		 */
		if (pr_reg->pr_res_holder) {
			core_scsi3_put_pr_reg(pr_reg);
			return 1;
		}
		if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) ||
		    (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) ||
		    (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) ||
		    (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) {
			core_scsi3_put_pr_reg(pr_reg);
			return 1;
		}
		core_scsi3_put_pr_reg(pr_reg);
		conflict = 1;
	} else {
		/*
		 * Following spc2r20 5.5.1 Reservations overview:
		 *
		 * If a logical unit has executed a PERSISTENT RESERVE OUT
		 * command with the REGISTER or the REGISTER AND IGNORE
		 * EXISTING KEY service action and is still registered by any
		 * initiator, all RESERVE commands and all RELEASE commands
		 * regardless of initiator shall conflict and shall terminate
		 * with a RESERVATION CONFLICT status.
		 */
		spin_lock(&pr_tmpl->registration_lock);
		conflict = (list_empty(&pr_tmpl->registration_list)) ? 0 : 1;
		spin_unlock(&pr_tmpl->registration_lock);
	}

	if (conflict) {
		pr_err("Received legacy SPC-2 RESERVE/RELEASE"
			" while active SPC-3 registrations exist,"
			" returning RESERVATION_CONFLICT\n");
		return -EBUSY;
	}

	return 0;
}

sense_reason_t
target_scsi2_reservation_release(struct se_cmd *cmd)
{
	struct se_device *dev = cmd->se_dev;
	struct se_session *sess = cmd->se_sess;
	struct se_portal_group *tpg;
	int rc;

	if (!sess || !sess->se_tpg)
		goto out;
	rc = target_check_scsi2_reservation_conflict(cmd);
	if (rc == 1)
		goto out;
	if (rc < 0)
		return TCM_RESERVATION_CONFLICT;

	spin_lock(&dev->dev_reservation_lock);
	if (!dev->dev_reserved_node_acl || !sess)
		goto out_unlock;

	if (dev->dev_reserved_node_acl != sess->se_node_acl)
		goto out_unlock;

	if (dev->dev_res_bin_isid != sess->sess_bin_isid)
		goto out_unlock;

	dev->dev_reserved_node_acl = NULL;
	dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS;
	if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) {
		dev->dev_res_bin_isid = 0;
		dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS_WITH_ISID;
	}
	tpg = sess->se_tpg;
	pr_debug("SCSI-2 Released reservation for %s LUN: %u ->"
		" MAPPED LUN: %u for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
		cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
		sess->se_node_acl->initiatorname);

out_unlock:
	spin_unlock(&dev->dev_reservation_lock);
out:
	target_complete_cmd(cmd, GOOD);
	return 0;
}

sense_reason_t
target_scsi2_reservation_reserve(struct se_cmd *cmd)
{
	struct se_device *dev = cmd->se_dev;
	struct se_session *sess = cmd->se_sess;
	struct se_portal_group *tpg;
	sense_reason_t ret = 0;
	int rc;

	if ((cmd->t_task_cdb[1] & 0x01) &&
	    (cmd->t_task_cdb[1] & 0x02)) {
		pr_err("LongIO and Obselete Bits set, returning"
				" ILLEGAL_REQUEST\n");
		return TCM_UNSUPPORTED_SCSI_OPCODE;
	}
	/*
	 * This is currently the case for target_core_mod passthrough struct se_cmd
	 * ops
	 */
	if (!sess || !sess->se_tpg)
		goto out;
	rc = target_check_scsi2_reservation_conflict(cmd);
	if (rc == 1)
		goto out;

	if (rc < 0)
		return TCM_RESERVATION_CONFLICT;

	tpg = sess->se_tpg;
	spin_lock(&dev->dev_reservation_lock);
	if (dev->dev_reserved_node_acl &&
	   (dev->dev_reserved_node_acl != sess->se_node_acl)) {
		pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n",
			tpg->se_tpg_tfo->get_fabric_name());
		pr_err("Original reserver LUN: %u %s\n",
			cmd->se_lun->unpacked_lun,
			dev->dev_reserved_node_acl->initiatorname);
		pr_err("Current attempt - LUN: %u -> MAPPED LUN: %u"
			" from %s \n", cmd->se_lun->unpacked_lun,
			cmd->se_deve->mapped_lun,
			sess->se_node_acl->initiatorname);
		ret = TCM_RESERVATION_CONFLICT;
		goto out_unlock;
	}

	dev->dev_reserved_node_acl = sess->se_node_acl;
	dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS;
	if (sess->sess_bin_isid != 0) {
		dev->dev_res_bin_isid = sess->sess_bin_isid;
		dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS_WITH_ISID;
	}
	pr_debug("SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u"
		" for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
		cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
		sess->se_node_acl->initiatorname);

out_unlock:
	spin_unlock(&dev->dev_reservation_lock);
out:
	if (!ret)
		target_complete_cmd(cmd, GOOD);
	return ret;
}


/*
 * Begin SPC-3/SPC-4 Persistent Reservations emulation support
 *
 * This function is called by those initiator ports who are *NOT*
 * the active PR reservation holder when a reservation is present.
 */
static int core_scsi3_pr_seq_non_holder(
	struct se_cmd *cmd,
	u32 pr_reg_type)
{
	unsigned char *cdb = cmd->t_task_cdb;
	struct se_dev_entry *se_deve;
	struct se_session *se_sess = cmd->se_sess;
	int other_cdb = 0, ignore_reg;
	int registered_nexus = 0, ret = 1; /* Conflict by default */
	int all_reg = 0, reg_only = 0; /* ALL_REG, REG_ONLY */
	int we = 0; /* Write Exclusive */
	int legacy = 0; /* Act like a legacy device and return
			 * RESERVATION CONFLICT on some CDBs */

	se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun];
	/*
	 * Determine if the registration should be ignored due to
	 * non-matching ISIDs in target_scsi3_pr_reservation_check().
	 */
	ignore_reg = (pr_reg_type & 0x80000000);
	if (ignore_reg)
		pr_reg_type &= ~0x80000000;

	switch (pr_reg_type) {
	case PR_TYPE_WRITE_EXCLUSIVE:
		we = 1;
	case PR_TYPE_EXCLUSIVE_ACCESS:
		/*
		 * Some commands are only allowed for the persistent reservation
		 * holder.
		 */
		if ((se_deve->def_pr_registered) && !(ignore_reg))
			registered_nexus = 1;