/drivers/lguest/

tmus-rt-budgetable-locks.git/.git/blame/fs/quota/dquot.c?h=update_litmus_2019&id=39fa84e94a7df64a6ba27669ef98b51994fb6894'>blamecommitdiffstats
path: root/fs/quota/dquot.c
blob: 5b572c89e6c4bcbb028b5faf417c098503cc2991 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                                               

























































                                                                                     






                              
                             
                           
                                  


                        
  
                                                                               
                     

                                                                            
                                                                              


                                                                              
  

                                                                        





                                                                               






                                                                              
  
                                                                          








                                                                               

                                                                        





                                                                               
                                                            

   


                                                                 
                            
 
                                                            
                                        
 
                                 


                                     
                                    






                                                                     




                             
                                                                      
                                        
      



                                                                                
                                       








                                                        
                                     





                                                           


                                                             



                                           
                                       





                                                          


                                                                    




                                                         




                                                                    


                                         


                                                                            





































                                                                              
                       
 
                                                        
                                                              
 













                                                                              

                                                                               







                                                         

                                                                             





                                                                 

                                                               

                                     
                    




                                                      
                                                     
                                      






                                                         
                                      





                                                                       
                                                     
                                       



                                                    
                                       







                                              

                                      

 








                                                       
 
                                                                             

                                               





                                                                              
                                 
                                                            

                                                                     

                        
                                   
                   
 
                                      
 























                                                                       























                                                                       

                                       








                                                                         



                                                                              








                                               

                                         

                   
                             





                                     
                    

                                                          
                                       







                                                                         
                                                    
                                                                      

                           
        
                                         

                   
                            








                                                          
                                    


                                                                     
                                       


                                                                       



                                                                              



                                                 
                                         
           
                                      

                   
                             
 
                                       


                                             
                             





                                                        

                                                                             

                                                                           
                                                                   
   

                                                               
                                  
 
        
                                 
                                                                     



                                           



























                                                                              


                                         
                                        



                                   
















                                                                                
                                           
                                          














                                                                                
                                 
 
                                                                





                                                
                                          


                                               
                                                  



                                                         

                                                                     








                                                                           
                                                   
                                                  







                                                      

                                                                               
                                                       
                                
                                            
 


























                                                                              

                 
                                












                                                                
                                        








                                                        

                                                           
 

                                




                                           


                                                                                

 




                                           


                                                                                       
   
                               
 

                

                       
                         
                                             

                                                                               


                      
                                




                                                                 
                                                            
                                                                         

                                                        






                                                                            

                                                              


                                                                               







                                                                      









                                                                            
                         
                          
                                             



                                   
                     
 
                                                           


                                                         
                           
 



                                                                      
                                                 
                  
                            
 
                                    



                                         
                                                    








                                        




                                                                           
   
                                                                      

                                                    
                                                  
 
                                           
                            

                                 







                                             


                                                  
                                                   

                                                          



                                                                                 
                             




                                                      
                                           
                                          



                                                   
                                           

                                             
         

                                                                               
                             


                                                           
                             
                             
                         
         
                         
                                                                              
      


                                        


                     
                     







                                                       
                                             
                                             
                                         



                                 
                                                    

                                                           
                                               
                         
                         
      
 
                                       
                                                              




                                                                       
                                 
                 
                         

                                                             
      
                              
                                            
                                                 
 
                                
                                                








                                                                               
                                  
                                               
         
                                         
                        
 
                         
                       


                                                                             
         
      

 



                                                  






                                                   

                                                                           
                                         

                                                                      

                                                                


                                                   

                                    
                                          
                         
                                                               


                                                                             

                                                 


                                                                            








                                                                               




                                                                            





                                                         


                                                                    

                                                                             



                             



                                                              
                         
 
                                       
                                                              





                                                                              


                                                                     
                                                                         
                 
         
                                         






                                                                               

 




                                                            





                                                         

 
                                                                         








                                                                        




                                                                        


                             
                                                                           
 



                                                    






                                                                   





                                                     

 
                                                                  
 

                                                                   







                                                                        
                                                                 
 

                                                                   


                                                     
                                                                       



                                                     











                                                                       
                                 

                                   
                                                  





                                 
                                                               





                                                        
                                                
                                                                  

                         
                               
 



                                                                          

                       

                                
                       
                                                   
                                                                             
                                                      
            

                                                           
                           
                                        

                                                         
                                            

                                                                   
                                        

                                                          
                                        

                                                          
                                            

                                                                    
                                        


                                                           
                                    
                          
 

      




                                                                        
                                                                       
 
                         

              



                                                           
                                 
                                                       
      

                                                                          
                 
         

 
                                                



                                                                                

                                                              


                        
                                                                         
 

                                                                 
                                    

                                                                         
                         

                                           
                                                       
                                       
                                               
                               


                                           


                                                       
                                       
                                                   
                               


                                           
                                                       
                                           
                                               

                                                                            

         
                 




                                                                                      
                       
                                              
 
                                    
                                                               
                                                  
                         
 


                                                                        
                                           
                                                    

                                       
                                                       
                               


                                           
                                                    

                                                       

                                       
                                                           
                               


                                           
                                                    

                                           
                                                       

                                                                          





                                                                                             
                                       

         
                 

 
                                                             
 

                          
                                                    

                                                                          

                                       

                                                         

                                                                          
                                                     






                                                            
                                                                       

                                       
                                                                               
                                           

                                                                              


                                           
 








                                                                     
  






                                                                       
   
                                                             

                            
                
                                     
                                             
                    
 

                                                                       
                                 
                       


                                                               
                                













                                              




                                               


                                                  


                                                                             
                                           
                                                       
                                        






                                                                           


                 

                                           
                       




                                          
 
                                


                                              
   
                                             

                
                                     
 
                                                      
                                               
                                               
                                           

                                                    
                       

 






















                                                                    
 
  










                                                                            
                                                             




                                               
                                   
 
                                                               





                                               
                                     
 
                                                             




                                               
                                   



                                                       


                                                    























                                                                              






                                                                          




                                                                 
                                                                       
 
                         
                                 

                                                  
                                                
 



                                                                       
                                   




                                                         
                                             
                                                
 

                                               
                                         
                                 

                                                                   
                                     

                                                   
                 

                                               
                                         
                                 



                                                                      
         
                                                 
                                   
 

                                    
                                             

                                                 
                                                   


                   
                                   



                                                                 
                                                
 
                         

                                 

                                                                       
                                 
                         
                                             
                                                
                                                     

                                               
                                         
                                 

                                                                        



                                               
                                         
                                 
                                                          
         
 

                                   
                     
                                                     
                                                 


                                                   
                                 
 



                                                                  

                
 
                                   
                                                     
                         


                                                     


                                                       
                                        



                                                                       
                                             
                                   
                                             
                                                   
                 
 
                                         

  

                                                                 
                                                                       

                         
                                 
                                                  
 

                                                                       
                                   
                                                         
                       
         
 
                                                     

                                               
                                         
                                 
                                                                           



                                                                               
         
                                                 
                                   


                                
                                             
           
                                                 
                                                   
 
                                  

  

                                                                 
                                                

                         
                                 
 

                                                                       
                                 
                       
 
                                                     

                                               
                                         
                                 

                                                                      

                                   
                                             
                                                 
                                                   
 
                                


                                                                          


                                                                            


                                                                 
  
   
                                                                     
 

                                 
                                                    
                         
                                      

                                                                             
 

                                                                       
                              
                         
                                   
                                             
                                                   
                                                      

                                                                            
                         
         
                                 
                                           
                                               
                                      

                                                               


                                                                                 
                                      
                                 



                                                           
                                                         




                                                                               
                                        





                                                                                
                                   
                                 

                                                                                 



                                                                         
                                                                 


                                                                        


                                                       

                                                              


                                                       
                                   

                                                    

                                            


                                                            
                                         
                                             

                                                              
                 


                                                    

                                                 
 
                                
 


                                                                  
                                                            
 


                                                  
 
                                 
                         
 


                                                                           
                                                                           



                                                   
 
                              
 







                                                       
                                       
                                                          
                                         

                   
                                 



                                       
                                                  



                                                 


                                            
  
                                
 
  







                                                                   
                                        




                               

                                                                             
                                                                       
 
                         

                                                
 






                                                                            
                                                         
                                          





                                                                               
                                       


                                                    

                                               

                                              
                                                  
                                 

                                              
                                                  

                                                                       
                                                    
                        
                                                  





                                                                              
                                                            



                                                         
                                                    
                 


                                                                               
                                 




                                                         

                                                                              







                                                                 
                                                  
                                                 




                                                
                                            




                                                                      
                                                                             
                                                                   









                                                                         
                                                          

                                                                          
                                                            

                                                                            

                                                                           

                                                                              
                                                                        
                                                                       
                         
                                                            





                                             
                                                                              






                                                                              


                                                           
                 
                   
 
                             
 
                                                     
 

                                                                         
 
                               
 



                                  





                                                                             




















                                                                     




                                             
 
                                                     






                                                                             

                                            
                                          
                                            


                               




                                                                           
                                                                  

                                                                      
                                                                      
                                              



                                                                            
                                    
         










                                                     
                                                 
                                                          
                                       

                                                           
                                                 

                                   
                                         
                                  
                                                      
                                    

                                
                                            






                                  
                             
                                                                  



                                                                          
                                              
         
                                            





                              
                                   
                                                  


                                                
                         
                           
 
















                                                                             
                                                    
 




                                                                    


                   
                            
 

                                                                   







                                                    


                                                                             

                     
                              

  


                                                                

                                                              





                                                

                                        



















                                                            
                                          
                                                                     
                                            







                                                                   
                            

  


                                                                   
                                                               
                                        
 
                              

                  
                                                  
                                                                      
                                                    


                                       




                                
                                          
                   

                                                                              
 
    

                     
 
                                    
 









                                                                 
                                                                
                                                                       


                                              


                                                  
                                                       

                                
                                 







                                                           


                                   

                                                               


                            
                                    
                   
                              

                                
 

                 
                               
 




                                                     
                                                                
                                                                      


                                              

                                                                               










                                                           
                               

                                 

                                                                   
                               
                                                                      
         





                                                                
                               
                                                                        
         


                                                 
                               
                                                                       
         





                                                            
                               
                                                                        
         


                                             
                               
                                                                      
         


                                             
                               
                                                                      
         

                         

                                                            

                                                               
                                                             
                                                                               
                                                                        

                         

                                                             

                                                                 
                                                             
                                                                               
                                                                        
         

                                                                             




                                                       

                 

 
                                                               
                                           

                            
               
 



                                    
         
                                     
                     
    
                  
 
                               

                                                                       
                                                                            


                              
                                                 
                                             
                                                           








                                                 
                                                   

                 
                                

                                                                       
                                                                            

                              
                    
 
                                                 


                                             







                                                

                                                             



                                        
    
                                                   
                   
 
                                
 







                                                
  
                                  



                                                                     
                                                              



                                                                            


                                                               

                                       
                                            
                                                              

                                              
                                                  

          
                                          
                                                            

                                              
                                                  

          
                                          
                                                            

                                              
                                                  

          
                                           
                                                             

                                              
                                                  

          
                                               
                                                                 

                                              
                                                  

          
                                                     
                                                                   

                                              
                                                  

          
                                                
                                                                  

                                              
                                                  

          
                                          
                                                            

                                              
                                                  
          
                                 
         



                                                       
                                                
          
      
            



                               



                                                   
            



                                



                                           
            



                                  
                   



                                                                       
                                         
 
                                                 
                                                                        

                                                                 
                              





                                                                              




                                                                   
 















                                                                              
                                             



                        
/*
 * Implementation of the diskquota system for the LINUX operating system. QUOTA
 * is implemented using the BSD system call interface as the means of
 * communication with the user level. This file contains the generic routines
 * called by the different filesystems on allocation of an inode or block.
 * These routines take care of the administration needed to have a consistent
 * diskquota tracking system. The ideas of both user and group quotas are based
 * on the Melbourne quota system as used on BSD derived systems. The internal
 * implementation is based on one of the several variants of the LINUX
 * inode-subsystem with added complexity of the diskquota system.
 * 
 * Author:	Marco van Wieringen <mvw@planets.elm.net>
 *
 * Fixes:   Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96
 *
 *		Revised list management to avoid races
 *		-- Bill Hawes, <whawes@star.net>, 9/98
 *
 *		Fixed races in dquot_transfer(), dqget() and dquot_alloc_...().
 *		As the consequence the locking was moved from dquot_decr_...(),
 *		dquot_incr_...() to calling functions.
 *		invalidate_dquots() now writes modified dquots.
 *		Serialized quota_off() and quota_on() for mount point.
 *		Fixed a few bugs in grow_dquots().
 *		Fixed deadlock in write_dquot() - we no longer account quotas on
 *		quota files
 *		remove_dquot_ref() moved to inode.c - it now traverses through inodes
 *		add_dquot_ref() restarts after blocking
 *		Added check for bogus uid and fixed check for group in quotactl.
 *		Jan Kara, <jack@suse.cz>, sponsored by SuSE CR, 10-11/99
 *
 *		Used struct list_head instead of own list struct
 *		Invalidation of referenced dquots is no longer possible
 *		Improved free_dquots list management
 *		Quota and i_blocks are now updated in one place to avoid races
 *		Warnings are now delayed so we won't block in critical section
 *		Write updated not to require dquot lock
 *		Jan Kara, <jack@suse.cz>, 9/2000
 *
 *		Added dynamic quota structure allocation
 *		Jan Kara <jack@suse.cz> 12/2000
 *
 *		Rewritten quota interface. Implemented new quota format and
 *		formats registering.
 *		Jan Kara, <jack@suse.cz>, 2001,2002
 *
 *		New SMP locking.
 *		Jan Kara, <jack@suse.cz>, 10/2002
 *
 *		Added journalled quota support, fix lock inversion problems
 *		Jan Kara, <jack@suse.cz>, 2003,2004
 *
 * (C) Copyright 1994 - 1997 Marco van Wieringen 
 */

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/mm.h>
#include <linux/time.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <linux/tty.h>
#include <linux/file.h>
#include <linux/slab.h>
#include <linux/sysctl.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/security.h>
#include <linux/kmod.h>
#include <linux/namei.h>
#include <linux/buffer_head.h>
#include <linux/capability.h>
#include <linux/quotaops.h>
#include "../internal.h" /* ugh */

#include <asm/uaccess.h>

/*
 * There are three quota SMP locks. dq_list_lock protects all lists with quotas
 * and quota formats.
 * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and
 * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly
 * in inode_add_bytes() and inode_sub_bytes(). dq_state_lock protects
 * modifications of quota state (on quotaon and quotaoff) and readers who care
 * about latest values take it as well.
 *
 * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock,
 *   dq_list_lock > dq_state_lock
 *
 * Note that some things (eg. sb pointer, type, id) doesn't change during
 * the life of the dquot structure and so needn't to be protected by a lock
 *
 * Any operation working on dquots via inode pointers must hold dqptr_sem.  If
 * operation is just reading pointers from inode (or not using them at all) the
 * read lock is enough. If pointers are altered function must hold write lock.
 * Special care needs to be taken about S_NOQUOTA inode flag (marking that
 * inode is a quota file). Functions adding pointers from inode to dquots have
 * to check this flag under dqptr_sem and then (if S_NOQUOTA is not set) they
 * have to do all pointer modifications before dropping dqptr_sem. This makes
 * sure they cannot race with quotaon which first sets S_NOQUOTA flag and
 * then drops all pointers to dquots from an inode.
 *
 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
 * from inodes (dquot_alloc_space() and such don't check the dq_lock).
 * Currently dquot is locked only when it is being read to memory (or space for
 * it is being allocated) on the first dqget() and when it is being released on
 * the last dqput(). The allocation and release oparations are serialized by
 * the dq_lock and by checking the use count in dquot_release().  Write
 * operations on dquots don't hold dq_lock as they copy data under dq_data_lock
 * spinlock to internal buffers before writing.
 *
 * Lock ordering (including related VFS locks) is the following:
 *   i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
 *   dqio_mutex
 * The lock ordering of dqptr_sem imposed by quota code is only dqonoff_sem >
 * dqptr_sem. But filesystem has to count with the fact that functions such as
 * dquot_alloc_space() acquire dqptr_sem and they usually have to be called
 * from inside a transaction to keep filesystem consistency after a crash. Also
 * filesystems usually want to do some IO on dquot from ->mark_dirty which is
 * called with dqptr_sem held.
 * i_mutex on quota files is special (it's below dqio_mutex)
 */

static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock);
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_state_lock);
__cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock);
EXPORT_SYMBOL(dq_data_lock);

void __quota_error(struct super_block *sb, const char *func,
		   const char *fmt, ...)
{
	if (printk_ratelimit()) {
		va_list args;
		struct va_format vaf;

		va_start(args, fmt);

		vaf.fmt = fmt;
		vaf.va = &args;

		printk(KERN_ERR "Quota error (device %s): %s: %pV\n",
		       sb->s_id, func, &vaf);

		va_end(args);
	}
}
EXPORT_SYMBOL(__quota_error);

#if defined(CONFIG_QUOTA_DEBUG) || defined(CONFIG_PRINT_QUOTA_WARNING)
static char *quotatypes[] = INITQFNAMES;
#endif
static struct quota_format_type *quota_formats;	/* List of registered formats */
static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES;

/* SLAB cache for dquot structures */
static struct kmem_cache *dquot_cachep;

int register_quota_format(struct quota_format_type *fmt)
{
	spin_lock(&dq_list_lock);
	fmt->qf_next = quota_formats;
	quota_formats = fmt;
	spin_unlock(&dq_list_lock);
	return 0;
}
EXPORT_SYMBOL(register_quota_format);

void unregister_quota_format(struct quota_format_type *fmt)
{
	struct quota_format_type **actqf;

	spin_lock(&dq_list_lock);
	for (actqf = &quota_formats; *actqf && *actqf != fmt;
	     actqf = &(*actqf)->qf_next)
		;
	if (*actqf)
		*actqf = (*actqf)->qf_next;
	spin_unlock(&dq_list_lock);
}
EXPORT_SYMBOL(unregister_quota_format);

static struct quota_format_type *find_quota_format(int id)
{
	struct quota_format_type *actqf;

	spin_lock(&dq_list_lock);