aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 406adbc277a0..07a63114d938 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -5107,6 +5107,133 @@ static const struct file_operations rb_simple_fops = {
5107 .llseek = default_llseek, 5107 .llseek = default_llseek,
5108}; 5108};
5109 5109
5110struct dentry *trace_instance_dir;
5111
5112static void
5113init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
5114
5115static int new_instance_create(const char *name)
5116{
5117 enum ring_buffer_flags rb_flags;
5118 struct trace_array *tr;
5119 int ret;
5120 int i;
5121
5122 mutex_lock(&trace_types_lock);
5123
5124 ret = -EEXIST;
5125 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
5126 if (tr->name && strcmp(tr->name, name) == 0)
5127 goto out_unlock;
5128 }
5129
5130 ret = -ENOMEM;
5131 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
5132 if (!tr)
5133 goto out_unlock;
5134
5135 tr->name = kstrdup(name, GFP_KERNEL);
5136 if (!tr->name)
5137 goto out_free_tr;
5138
5139 raw_spin_lock_init(&tr->start_lock);
5140
5141 tr->current_trace = &nop_trace;
5142
5143 INIT_LIST_HEAD(&tr->systems);
5144 INIT_LIST_HEAD(&tr->events);
5145
5146 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
5147
5148 tr->buffer = ring_buffer_alloc(trace_buf_size, rb_flags);
5149 if (!tr->buffer)
5150 goto out_free_tr;
5151
5152 tr->data = alloc_percpu(struct trace_array_cpu);
5153 if (!tr->data)
5154 goto out_free_tr;
5155
5156 for_each_tracing_cpu(i) {
5157 memset(per_cpu_ptr(tr->data, i), 0, sizeof(struct trace_array_cpu));
5158 per_cpu_ptr(tr->data, i)->trace_cpu.cpu = i;
5159 per_cpu_ptr(tr->data, i)->trace_cpu.tr = tr;
5160 }
5161
5162 /* Holder for file callbacks */
5163 tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5164 tr->trace_cpu.tr = tr;
5165
5166 tr->dir = debugfs_create_dir(name, trace_instance_dir);
5167 if (!tr->dir)
5168 goto out_free_tr;
5169
5170 ret = event_trace_add_tracer(tr->dir, tr);
5171 if (ret)
5172 goto out_free_tr;
5173
5174 init_tracer_debugfs(tr, tr->dir);
5175
5176 list_add(&tr->list, &ftrace_trace_arrays);
5177
5178 mutex_unlock(&trace_types_lock);
5179
5180 return 0;
5181
5182 out_free_tr:
5183 if (tr->buffer)
5184 ring_buffer_free(tr->buffer);
5185 kfree(tr->name);
5186 kfree(tr);
5187
5188 out_unlock:
5189 mutex_unlock(&trace_types_lock);
5190
5191 return ret;
5192
5193}
5194
5195static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode)
5196{
5197 struct dentry *parent;
5198 int ret;
5199
5200 /* Paranoid: Make sure the parent is the "instances" directory */
5201 parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
5202 if (WARN_ON_ONCE(parent != trace_instance_dir))
5203 return -ENOENT;
5204
5205 /*
5206 * The inode mutex is locked, but debugfs_create_dir() will also
5207 * take the mutex. As the instances directory can not be destroyed
5208 * or changed in any other way, it is safe to unlock it, and
5209 * let the dentry try. If two users try to make the same dir at
5210 * the same time, then the new_instance_create() will determine the
5211 * winner.
5212 */
5213 mutex_unlock(&inode->i_mutex);
5214
5215 ret = new_instance_create(dentry->d_iname);
5216
5217 mutex_lock(&inode->i_mutex);
5218
5219 return ret;
5220}
5221
5222static const struct inode_operations instance_dir_inode_operations = {
5223 .lookup = simple_lookup,
5224 .mkdir = instance_mkdir,
5225};
5226
5227static __init void create_trace_instances(struct dentry *d_tracer)
5228{
5229 trace_instance_dir = debugfs_create_dir("instances", d_tracer);
5230 if (WARN_ON(!trace_instance_dir))
5231 return;
5232
5233 /* Hijack the dir inode operations, to allow mkdir */
5234 trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations;
5235}
5236
5110static void 5237static void
5111init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) 5238init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
5112{ 5239{
@@ -5183,6 +5310,8 @@ static __init int tracer_init_debugfs(void)
5183 (void *)&global_trace.trace_cpu, &snapshot_fops); 5310 (void *)&global_trace.trace_cpu, &snapshot_fops);
5184#endif 5311#endif
5185 5312
5313 create_trace_instances(d_tracer);
5314
5186 create_trace_options_dir(&global_trace); 5315 create_trace_options_dir(&global_trace);
5187 5316
5188 for_each_tracing_cpu(cpu) 5317 for_each_tracing_cpu(cpu)
able-locks.git/.git/commit/drivers/target/target_core_sbc.c?h=update_litmus_2019&id=db60df88ec39715fc3fb2a846cf35837e074c11d'>db60df88ec39
cf6d1f0964fa
68ff9b9b2752


a2890087499a

68ff9b9b2752



























































































































b7191253b302





68ff9b9b2752















de103c93aff0

d6e0175cf3f9
d6e0175cf3f9

1fd032ee10d2
d6e0175cf3f9
de103c93aff0
d6e0175cf3f9





a82a9538dd30

d6e0175cf3f9




a82a9538dd30

d6e0175cf3f9




a82a9538dd30

d6e0175cf3f9




a82a9538dd30

d6e0175cf3f9




a82a9538dd30

d6e0175cf3f9







a82a9538dd30

d6e0175cf3f9






a82a9538dd30

d6e0175cf3f9






a82a9538dd30

d6e0175cf3f9

de103c93aff0
d6e0175cf3f9
de103c93aff0
d6e0175cf3f9







a82a9538dd30

d6e0175cf3f9





















a82a9538dd30

d6e0175cf3f9








de103c93aff0
d6e0175cf3f9

1fd032ee10d2
d6e0175cf3f9

cd063bef414c
6b64e1fe2ba8
cd063bef414c
d6e0175cf3f9



de103c93aff0
d6e0175cf3f9


68ff9b9b2752





















d6e0175cf3f9
1fd032ee10d2

d6e0175cf3f9



1fd032ee10d2
d6e0175cf3f9



de103c93aff0
d6e0175cf3f9
1fd032ee10d2
d6e0175cf3f9



882e3f8e6966




ad67f0d9e63c
d6e0175cf3f9










1fd032ee10d2
d6e0175cf3f9






33633676df0d
d6e0175cf3f9
ad67f0d9e63c
d6e0175cf3f9

14150a6bbe9e
de103c93aff0
14150a6bbe9e
1fd032ee10d2
14150a6bbe9e
d6e0175cf3f9




de103c93aff0
d6e0175cf3f9

1fd032ee10d2
d6e0175cf3f9

cd063bef414c
6b64e1fe2ba8
cd063bef414c
d6e0175cf3f9




de103c93aff0
d6e0175cf3f9

1fd032ee10d2
d6e0175cf3f9





cd063bef414c
6b64e1fe2ba8
cd063bef414c
d6e0175cf3f9

1fd032ee10d2
1920ed61fbbb
d6e0175cf3f9
1a1ff38c4ceb











d6e0175cf3f9
1fd032ee10d2
d6e0175cf3f9





de103c93aff0
d6e0175cf3f9

1fd032ee10d2

0fd97ccf45be
d6e0175cf3f9


0fd97ccf45be
de103c93aff0
d6e0175cf3f9
0fd97ccf45be
d6e0175cf3f9


0fd97ccf45be
de103c93aff0
d6e0175cf3f9

1fd032ee10d2




09ceadc70383
1fd032ee10d2

68ff9b9b2752

d6e0175cf3f9

de103c93aff0
d6e0175cf3f9

6f23ac8a3941
6f23ac8a3941




86d7182985d2




















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946


                                                   
                                       






















                                                                             
                          








                                       

                                            

                                            
                                             
                                                                         

                             

                   














                                                                      




                                              



                                       



                                                           
 
                                           



                                                                             




                                       

                                               

                                            

                              

                                                                    
                                    







                                       



                                                           



                                                                                
                                                                        

                               
                                           



                                                                             




                                       
                                                       
 
                       











                                                                                

                                  
 

                                                                
 
                                          
 
                     
                                    




                                       

                                                               
                                                            







                                                      
                                                                


















































































                                                                             

                                                                                   
 
                                                               
 



                                                               
                                                   
         




                                                                                  
          

                                                                      
           





                                                                 
         

                                                   
 
                                                   


                 
                                                              



                                  

                                          













                                                                                  
                                            

















                                                                             

                                                   
                                 
                 









                                                                        
                   

 






                                                                      



                                                                









                                                                               












                                                                              
                                         







                                                             





                                                                       








                                                                          
 


                                                                     

                                           



























































































































                                                                              





                                                                          















                                                                               

                                                      
 

                                             
                          
                        
                           





                                                        

                                                  




                                                        

                                                  




                                                        

                                                  




                                                        

                                                  




                                                        

                                                  







                                                        

                                                  






                                                        

                                                  






                                                        

                                                  

                            
                                                           
                                                    
                                                     







                                                                          

                                                  





















                                                                             

                                                          








                                                                                 
                                                             

                         
                                                    

                                                                       
                                                                       
                                
                                           



                                                                           
                                                           


                      





















                                                                               
                           

                                                            



                                                    
                                                                       



                                                           
                                                     
                 
                                                          



                                                




                                                            
 










                                                                                     
                                                  






                                                                               
                                                                
                 
                                                           

                      
                                        
                                                           
 
                                                   
                                                      




                                                                                 
                                                     

                 
                                            

                                                              
                                                              
                        
                                   




                                                                                 
                                                     

                 
                                            





                                                                                 
                                                              
                        
                                   

                      
                         
                                                    
                      











                                                                               
                
                                                





                                                                          
                                                   

                                                    

                                           
                                                                   


                                                                             
                                                                    
                                                     
                 
                                                               


                                                                                 
                                                                
                                                     

                 




                                                                   
                                                        

                 

                                                                 

         
                                                

                             
 




                                              




















































































                                                                                        
/*
 * SCSI Block Commands (SBC) parsing and emulation.
 *
 * (c) Copyright 2002-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/kernel.h>
#include <linux/module.h>
#include <linux/ratelimit.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_tcq.h>

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

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


static sense_reason_t
sbc_emulate_readcapacity(struct se_cmd *cmd)
{
	struct se_device *dev = cmd->se_dev;
	unsigned char *cdb = cmd->t_task_cdb;
	unsigned long long blocks_long = dev->transport->get_blocks(dev);
	unsigned char *rbuf;
	unsigned char buf[8];
	u32 blocks;

	/*
	 * SBC-2 says:
	 *   If the PMI bit is set to zero and the LOGICAL BLOCK
	 *   ADDRESS field is not set to zero, the device server shall
	 *   terminate the command with CHECK CONDITION status with
	 *   the sense key set to ILLEGAL REQUEST and the additional
	 *   sense code set to INVALID FIELD IN CDB.
	 *
	 * In SBC-3, these fields are obsolete, but some SCSI
	 * compliance tests actually check this, so we might as well
	 * follow SBC-2.
	 */
	if (!(cdb[8] & 1) && !!(cdb[2] | cdb[3] | cdb[4] | cdb[5]))
		return TCM_INVALID_CDB_FIELD;

	if (blocks_long >= 0x00000000ffffffff)
		blocks = 0xffffffff;
	else
		blocks = (u32)blocks_long;

	buf[0] = (blocks >> 24) & 0xff;
	buf[1] = (blocks >> 16) & 0xff;
	buf[2] = (blocks >> 8) & 0xff;
	buf[3] = blocks & 0xff;
	buf[4] = (dev->dev_attrib.block_size >> 24) & 0xff;
	buf[5] = (dev->dev_attrib.block_size >> 16) & 0xff;
	buf[6] = (dev->dev_attrib.block_size >> 8) & 0xff;
	buf[7] = dev->dev_attrib.block_size & 0xff;

	rbuf = transport_kmap_data_sg(cmd);
	if (rbuf) {