aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ufs_fs_sb.h
blob: 8ff13c160f3d6a6bcba70055ccbec0d26d882317 (plain) (blame)
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
/* 
 *  linux/include/linux/ufs_fs_sb.h
 *
 * Copyright (C) 1996
 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
 * Laboratory for Computer Science Research Computing Facility
 * Rutgers, The State University of New Jersey
 *
 * $Id: ufs_fs_sb.h,v 1.8 1998/05/06 12:04:40 jj Exp $
 *
 * Write support by Daniel Pirkl <daniel.pirkl@email.cz>
 */

#ifndef __LINUX_UFS_FS_SB_H
#define __LINUX_UFS_FS_SB_H


#define UFS_MAX_GROUP_LOADED 8
#define UFS_CGNO_EMPTY ((unsigned)-1)

struct ufs_sb_private_info;
struct ufs_cg_private_info;
struct ufs_csum;
#define UFS_MAXCSBUFS 31

struct ufs_sb_info {
	struct ufs_sb_private_info * s_uspi;	
	struct ufs_csum	* s_csp;
	unsigned s_bytesex;
	unsigned s_flags;
	struct buffer_head ** s_ucg;
	struct ufs_cg_private_info * s_ucpi[UFS_MAX_GROUP_LOADED]; 
	unsigned s_cgno[UFS_MAX_GROUP_LOADED];
	unsigned short s_cg_loaded;
	unsigned s_mount_opt;
};

#endif
ah-Hartman <gregkh@suse.de> 2012-01-24 15:36:17 -0500 sysfs: Add s_hash to sysfs_dirent and order directory entries by hash' href='/cgit/cgit.cgi/litmus-rt.git/commit/fs/sysfs/dir.c?h=wip-shared-lib&id=4e4d6d860b9393c5395ba5920edb5b4c5d43a3a3'>4e4d6d860b93
1da177e4c3f4

3007e997de91
f7a75f0a4007
1da177e4c3f4
4e4d6d860b93

f7a75f0a4007
2b611bb7abdc

b6b4a4399c2a
4e4d6d860b93








































0c73f18b7d95

4e4d6d860b93
bc747f37a0f0
0c73f18b7d95

3007e997de91
4e4d6d860b93


0c73f18b7d95
4e4d6d860b93
0c73f18b7d95
4e4d6d860b93

4f72c0cab405
4e4d6d860b93












4f72c0cab405
4e4d6d860b93



0c73f18b7d95


4e4d6d860b93
0c73f18b7d95

4e4d6d860b93
bc747f37a0f0
0c73f18b7d95

3007e997de91
0c73f18b7d95
41fc1c27452e
0c73f18b7d95
4e4d6d860b93
0c73f18b7d95


b6b4a4399c2a








e72ceb8ccac5
b6b4a4399c2a
8619f9798983










846f99749ab6

8619f9798983
846f99749ab6
8619f9798983



b6b4a4399c2a
b6b4a4399c2a








e72ceb8ccac5
b6b4a4399c2a
8619f9798983




846f99749ab6
8619f9798983




58f2a4c7932d
8619f9798983
58f2a4c7932d
b6b4a4399c2a


b6b4a4399c2a


8619f9798983
b6b4a4399c2a
fb6896da37f1
b6b4a4399c2a
8619f9798983

b6b4a4399c2a
58f2a4c7932d
a2db6842873c



58f2a4c7932d
8619f9798983
846f99749ab6
8619f9798983
58f2a4c7932d
b6b4a4399c2a
8619f9798983

846f99749ab6

8619f9798983
846f99749ab6
8619f9798983
846f99749ab6

b6b4a4399c2a

cafa6b5dd7ce
2b611bb7abdc

















cafa6b5dd7ce
2b611bb7abdc





fa7f912ad4ae

13b3086d2ea4


3007e997de91


13b3086d2ea4

b402d72cf7b3
b1fc3d6144d5
b402d72cf7b3
0c096b507f15
4c3da2209b12


fa7f912ad4ae
2b611bb7abdc
fa7f912ad4ae
13b3086d2ea4



fa7f912ad4ae

fe15ce446beb
e8f077c88315






34286d666230
e8f077c88315

34286d666230



e8f077c88315





832b6af198ae







e8f077c88315






832b6af198ae





e8f077c88315















28a027cfc0d5
1da177e4c3f4


5a26b79c426f
1da177e4c3f4


ee1ec32903fc
e8f077c88315

28a027cfc0d5
1da177e4c3f4

3e5190380ebe
1da177e4c3f4
0c096b507f15
01da2425f327
0c096b507f15



01da2425f327
0c096b507f15
1da177e4c3f4
c376222960ae
1da177e4c3f4
01da2425f327
1da177e4c3f4
0c096b507f15
01da2425f327
2b611bb7abdc
1da177e4c3f4
8619f9798983
a26cd7226c24
0c096b507f15
a26cd7226c24
b402d72cf7b3
1da177e4c3f4

0c096b507f15
01da2425f327
0c096b507f15
01da2425f327

0c096b507f15
1da177e4c3f4

3007e997de91
fb6896da37f1


3007e997de91
fb6896da37f1

a16bbc3430ed
fb6896da37f1
3007e997de91

fb6896da37f1
a16bbc3430ed
3007e997de91
fb6896da37f1

b592fcfe7f06
fb6896da37f1


fb6896da37f1
fb6896da37f1


36ce6dad6e3c
fb6896da37f1



181b2e4be160

fb6896da37f1






23dc279950a0



fb6896da37f1
36ce6dad6e3c
fb6896da37f1
6b0bfe9383a5
4e4d6d860b93
6b0bfe9383a5
903e21e2eea0






4e4d6d860b93
fb6896da37f1

4e4d6d860b93


23dc279950a0
6b0bfe9383a5






23dc279950a0
fb6896da37f1


425cb02912d1



















36ce6dad6e3c























425cb02912d1









36ce6dad6e3c



fb6896da37f1

9fd5b1c906a9
fb6896da37f1

181b2e4be160
fb6896da37f1









6b0bfe9383a5

41fc1c27452e


fb6896da37f1
6b0bfe9383a5






fb6896da37f1
58f2a4c7932d
fb6896da37f1
a0edd7c84894


fb6896da37f1




a16bbc3430ed
fb6896da37f1

a16bbc3430ed
fb6896da37f1
990e53f880be
fb6896da37f1


fb6896da37f1




58f2a4c7932d
fb6896da37f1
fb6896da37f1
e0edd3c65aa5
fb6896da37f1
13b3086d2ea4
b592fcfe7f06

f0b0af4792d7





c516865cfbac
f0b0af4792d7
3007e997de91
c516865cfbac
f0b0af4792d7

c516865cfbac
f0b0af4792d7
3ff195b011d7
f0b0af4792d7
c516865cfbac
4e4d6d860b93

4f72c0cab405
903e21e2eea0






4e4d6d860b93












3ff195b011d7
4e4d6d860b93
f0b0af4792d7
c516865cfbac
f0b0af4792d7








3007e997de91
f0b0af4792d7




3ff195b011d7
f0b0af4792d7



3007e997de91
3ff195b011d7
f0b0af4792d7
3007e997de91
f0b0af4792d7

c516865cfbac
f1282c844e86
c516865cfbac
608e266a2d4e
3ff195b011d7

1da177e4c3f4
1da177e4c3f4
51225039f3cf
dfeb9fb03433
23dc279950a0
1da177e4c3f4
fc9f54b9982e
3e5190380ebe
a26cd7226c24
51225039f3cf
3ff195b011d7


b1fc3d6144d5
dfeb9fb03433
fc9f54b9982e
51225039f3cf
23dc279950a0

967e35dcc9ac
23dc279950a0


967e35dcc9ac
dfeb9fb03433
23dc279950a0
1da177e4c3f4

608e266a2d4e

1da177e4c3f4
3ff195b011d7



be867b194a3a







3ff195b011d7














1da177e4c3f4



1da177e4c3f4

90bc61359de0
1da177e4c3f4
3ff195b011d7
608e266a2d4e
3ff195b011d7
1da177e4c3f4



90bc61359de0
608e266a2d4e
1da177e4c3f4
7d0c7d676cc0
1da177e4c3f4
3ff195b011d7




1da177e4c3f4
608e266a2d4e
1da177e4c3f4


1da177e4c3f4


6cb52147b254
3ff195b011d7

a7a0475497f9
fc9f54b9982e
3ff195b011d7

1da177e4c3f4
6cb52147b254

3ff195b011d7



1da177e4c3f4
fc9f54b9982e
e49452c67703

6cb52147b254
e49452c67703
fc9f54b9982e

fac2622bbad4
6cb52147b254



3007e997de91
d6b4fd2faeb9
832b6af198ae

fb045adb99d9
832b6af198ae





fc9f54b9982e
6cb52147b254
3007e997de91
6cb52147b254
1da177e4c3f4

c5ef1c42c51b
1da177e4c3f4
e61ab4ae48fb
988d186de5b6
e61ab4ae48fb
ddd29ec65971
1da177e4c3f4

608e266a2d4e
1da177e4c3f4
fb6896da37f1
1da177e4c3f4
fb6896da37f1
fb6896da37f1

1da177e4c3f4

608e266a2d4e
1da177e4c3f4
608e266a2d4e
1da177e4c3f4


608e266a2d4e
1da177e4c3f4
fb6896da37f1
a406f75840e1
1da177e4c3f4
608e266a2d4e
1da177e4c3f4

608e266a2d4e
fb6896da37f1
4e4d6d860b93
a406f75840e1
4e4d6d860b93
a406f75840e1
3efa65b92d83
fb6896da37f1
1da177e4c3f4
fb6896da37f1
0ab66088c855
608e266a2d4e
b592fcfe7f06












608e266a2d4e
aecdcedaab49
5f9953237f68
608e266a2d4e
5f9953237f68
aecdcedaab49
608e266a2d4e
1da177e4c3f4

ca1bab38195d
3ff195b011d7

1da177e4c3f4
51225039f3cf
996b73764e9b
1da177e4c3f4
832b6af198ae
932ea2e374dd
9918f9a4817c
3ff195b011d7
ca1bab38195d
9918f9a4817c

9918f9a4817c
3ff195b011d7
832b6af198ae
996b73764e9b
0b4a4fea253e
ca1bab38195d








0c096b507f15
f6d90b4f9ce0



3ff195b011d7
f6d90b4f9ce0

0c096b507f15
996b73764e9b
832b6af198ae
9918f9a4817c
51225039f3cf
1da177e4c3f4


ca1bab38195d

3ff195b011d7






ca1bab38195d

51225039f3cf
8a82472f86bf
51225039f3cf

3ff195b011d7
8a82472f86bf
51225039f3cf
3ff195b011d7

ca1bab38195d
a6a8357788d6
51225039f3cf
3ff195b011d7
8a82472f86bf

1da177e4c3f4





1e5289c97bba





3ff195b011d7
4e4d6d860b93
1e5289c97bba



4e4d6d860b93
1e5289c97bba
3ff195b011d7

1e5289c97bba
4e4d6d860b93









a406f75840e1
a406f75840e1

4e4d6d860b93
b9e2780d576a
4e4d6d860b93

a406f75840e1

4e4d6d860b93
1e5289c97bba



3ff195b011d7

1e5289c97bba
3ff195b011d7
a406f75840e1
4e4d6d860b93

a406f75840e1

4e4d6d860b93
b9e2780d576a
1e5289c97bba


1da177e4c3f4

f427f5d5d6b0
1da177e4c3f4
1e5289c97bba
3ff195b011d7

1da177e4c3f4
1da177e4c3f4
3ff195b011d7


3efa65b92d83


1da177e4c3f4
3efa65b92d83






1da177e4c3f4
3efa65b92d83
1e5289c97bba
3ff195b011d7
1e5289c97bba
3ff195b011d7
1e5289c97bba







4e4d6d860b93
1e5289c97bba
1da177e4c3f4
3007e997de91
1e5289c97bba








1da177e4c3f4
3efa65b92d83
1da177e4c3f4

3efa65b92d83
4b6f5d20b04d
1da177e4c3f4

1e5289c97bba
3222a3e55f40
1da177e4c3f4
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
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
  








                                                                       







                          
                        
                      
                             
                        
                       
                           
                       

                  
                          
                                  
 

                                                                    
                                       

                                 
   








































                                                                               

                                     
                                                          
                                     

                
                               


                                         
   
                                                      
 

                                                                      
 












                                                   
         



                                                                  


   
                                                                      

                                     
                                                            
                                     

                
                               
   
                                                         
 
                                                           


   








                                                                     
                                                              
 










                                                            

                                                                         
                                  
                 



                                    
         








                                                                     
                                              
 




                          
                                                 




                                                                      
                            
           
                                   


   


                                                  
                                                           
   
                                                     
 

                                         
 
                                                    



                                                 
                                         
 
                                                    
                                                                      
                                        
           

                                                                  

                                                       
                                           
         
 

                                                 

 
                                              

















                                                            
                                            





                                        

                                                   


                                       


                                                                  

                                 
                                              
                                                   
                                             
                                  


                                                                     
                           
                                  
                                              



                                                    

 
                                                           






                                                                               
                                

                   



                                   





                                               







                                                         






                                                                        





                                                                   















                                                                      
                                                                         


                                                    
                      


                    
                                                          

                                                  
                                            

  
                                                                               
 
                              
                                



                                                            
                                    
         
 
                                                             
                
                              
 
                                        
                              
 
                                    
                                     
 
                          
                          
                           

                  
 
          
                                              

                        
                    

 
   


                                                               
  

                                                                     
                                                               
                              

                
                                                                    
               
   

                                                      
 


                                       
                                 


   
                                                                    



                                                                     

                                                                     






                                                                  



                                                                  
   
                                                                          
 
                                           
                
 






                                                                              
                                                           

                                                  


                                     
 






                                                                         
                 


   



















                                                                     























                                                                        









                                                                               



                   

                                                          
                                       

                                                                   
                                                           









                                                                            

                                           


                                                 
 






                                                                         
                                          
                                           
                           


   




                                                                      
                   

                
                                
   
                                                     


                                                               




                                                        
                                                   
 
                                     
                                   
                              
         

 





                                                                 
  
                
                               
  

                                                      
   
                                                                      
                                                      
                                                                 
 

                                                                 
 






                                                                        












                                                                
         
                    
 
 








                                                                        
                                                              




                                                                     
                                                     



                                                                
                                 
                                                    
                      
                                   

                  
 
                                    
 
                                                                           

                                                                 
 
                                                            
                                    
                                
               
 
                      
                                                     
                
                               


                                                     
                              
 
                     
                                            

                                      
 


                           
                              
 
                  

 

                                                               
 



                                                               







                                                                   














                                                                 



                                                            

                                                             
                                           
 
                               
                                            
                              



                      
                         
                                             
            
                                        
 




                                                                               
                   
                              


                     


                                                                             
                                  

                                                          
                                
                            

                               
 

                                 



                                                                   
 
                           

                                       
                                
         

                                     
                                               



                                       
 
                                         

                                  
                                                      





                                                 
 
            
                                   
                   

 
                                                            
                                       
                                           
                                        
                                        
                                         

  
                                               
 
                                    
 
                                               

                                    

 
                                                 
 
                       


 
                                                           
 
                                    
                            
 
                    

                       
                                                             
                                         
                                                
                     
                                                               
                                   
                                                
                                                    
         
                                  
 
                           












                                                                           
                                           
 
                                     
                        
                                       
 
                               

 
                                         

                                                               
 
                                    
                  
 
                                 
 
                  
                                                                      
                                                

                                                       
                        
                                                               
                         
 
                                 








                                                                    
 



                                                                                  
                          

                                     
 
                  
     
                                   
                        


                     

                                                                






                                                                   

 
                                                                         
 

                                           
                                  
 
                              

                                                      
                                                                
                                                  
 
                                                                   

 





                                                            





                                                                    
                                                         
                                                                              



                                                                   
                                            
                               

                                   
         









                                                                         
                                      

                 
                                                      
                                        

                                                           

                                   
                                                    



                   

                                                                            
 
                                                     
                     

                                                           

                                   
                                                    
                                         


                   

                                                                              
                                                    
                                                           
                                                      

                               
                  
 


                                                


                                                                           
                                      






                                                                            
                                      
         
                                 
                                                                  
                 
                                                                         







                                    
                                          
                                                    
 
                                           








                                                                         
         
                 

 
 
                                                     

                                           
                                            
                                              
  
/*
 * fs/sysfs/dir.c - sysfs core and dir operation implementation
 *
 * Copyright (c) 2001-3 Patrick Mochel
 * Copyright (c) 2007 SUSE Linux Products GmbH
 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
 *
 * This file is released under the GPLv2.
 *
 * Please see Documentation/filesystems/sysfs.txt for more information.
 */

#undef DEBUG

#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/namei.h>
#include <linux/idr.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/security.h>
#include <linux/hash.h>
#include "sysfs.h"

DEFINE_MUTEX(sysfs_mutex);
DEFINE_SPINLOCK(sysfs_assoc_lock);

#define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb);

static DEFINE_SPINLOCK(sysfs_ino_lock);
static DEFINE_IDA(sysfs_ino_ida);

/**
 *	sysfs_name_hash
 *	@ns:   Namespace tag to hash
 *	@name: Null terminated string to hash
 *
 *	Returns 31 bit hash of ns + name (so it fits in an off_t )
 */
static unsigned int sysfs_name_hash(const void *ns, const char *name)
{
	unsigned long hash = init_name_hash();
	unsigned int len = strlen(name);
	while (len--)
		hash = partial_name_hash(*name++, hash);
	hash = ( end_name_hash(hash) ^ hash_ptr( (void *)ns, 31 ) );
	hash &= 0x7fffffffU;
	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
	if (hash < 1)
		hash += 2;
	if (hash >= INT_MAX)
		hash = INT_MAX - 1;
	return hash;
}

static int sysfs_name_compare(unsigned int hash, const void *ns,
	const char *name, const struct sysfs_dirent *sd)
{
	if (hash != sd->s_hash)
		return hash - sd->s_hash;
	if (ns != sd->s_ns)
		return ns - sd->s_ns;
	return strcmp(name, sd->s_name);
}

static int sysfs_sd_compare(const struct sysfs_dirent *left,
			    const struct sysfs_dirent *right)
{
	return sysfs_name_compare(left->s_hash, left->s_ns, left->s_name,
				  right);
}

/**
 *	sysfs_link_subling - link sysfs_dirent into sibling rbtree
 *	@sd: sysfs_dirent of interest
 *
 *	Link @sd into its sibling rbtree which starts from
 *	sd->s_parent->s_dir.children.
 *
 *	Locking:
 *	mutex_lock(sysfs_mutex)
 *
 *	RETURNS:
 *	0 on susccess -EEXIST on failure.
 */
static int sysfs_link_sibling(struct sysfs_dirent *sd)
{
	struct rb_node **node = &sd->s_parent->s_dir.children.rb_node;
	struct rb_node *parent = NULL;

	while (*node) {
		struct sysfs_dirent *pos;
		int result;

		pos = to_sysfs_dirent(*node);
		parent = *node;
		result = sysfs_sd_compare(sd, pos);
		if (result < 0)
			node = &pos->s_rb.rb_left;
		else if (result > 0)
			node = &pos->s_rb.rb_right;
		else
			return -EEXIST;
	}
	/* add new node and rebalance the tree */
	rb_link_node(&sd->s_rb, parent, node);
	rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children);
	return 0;
}

/**
 *	sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree
 *	@sd: sysfs_dirent of interest
 *
 *	Unlink @sd from its sibling rbtree which starts from
 *	sd->s_parent->s_dir.children.
 *
 *	Locking:
 *	mutex_lock(sysfs_mutex)
 */
static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
{
	rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children);
}

/**
 *	sysfs_get_active - get an active reference to sysfs_dirent
 *	@sd: sysfs_dirent to get an active reference to
 *
 *	Get an active reference of @sd.  This function is noop if @sd
 *	is NULL.
 *
 *	RETURNS:
 *	Pointer to @sd on success, NULL on failure.
 */
struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
{
	if (unlikely(!sd))
		return NULL;

	while (1) {
		int v, t;

		v = atomic_read(&sd->s_active);
		if (unlikely(v < 0))
			return NULL;

		t = atomic_cmpxchg(&sd->s_active, v, v + 1);
		if (likely(t == v)) {
			rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_);
			return sd;
		}
		if (t < 0)
			return NULL;

		cpu_relax();
	}
}

/**
 *	sysfs_put_active - put an active reference to sysfs_dirent
 *	@sd: sysfs_dirent to put an active reference to
 *
 *	Put an active reference to @sd.  This function is noop if @sd
 *	is NULL.
 */
void sysfs_put_active(struct sysfs_dirent *sd)
{
	int v;

	if (unlikely(!sd))
		return;

	rwsem_release(&sd->dep_map, 1, _RET_IP_);
	v = atomic_dec_return(&sd->s_active);
	if (likely(v != SD_DEACTIVATED_BIAS))
		return;

	/* atomic_dec_return() is a mb(), we'll always see the updated
	 * sd->u.completion.
	 */
	complete(sd->u.completion);
}

/**