⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locking

📁 嵌入式系统设计与实例开发实验教材二源码 多线程应用程序设计 串行端口程序设计 AD接口实验 CAN总线通信实验 GPS通信实验 Linux内核移植与编译实验 IC卡读写实验 SD驱动使
💻
字号:
	The text below describes the locking rules for VFS-related methods.It is (believed to be) up-to-date. *Please*, if you change anything inprototypes or locking protocols - update this file. And update the relevantinstances in the tree, don't leave that to maintainers of filesystems/devices/etc. At the very least, put the list of dubious cases in the end of this file.Don't turn it into log - maintainers of out-of-the-tree code are supposed tobe able to use diff(1).	Thing currently missing here: socket operations. Alexey?--------------------------- dentry_operations --------------------------prototypes:	int (*d_revalidate)(struct dentry *, int);	int (*d_hash) (struct dentry *, struct qstr *);	int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);	int (*d_delete)(struct dentry *);	void (*d_release)(struct dentry *);	void (*d_iput)(struct dentry *, struct inode *);locking rules:	none have BKL		dcache_lock	may blockd_revalidate:	no		yesd_hash		no		yesd_compare:	yes		nod_delete:	yes		nod_release:	no		yesd_iput:		no		yes--------------------------- inode_operations --------------------------- prototypes:	int (*create) (struct inode *,struct dentry *,int);	struct dentry * (*lookup) (struct inode *,struct dentry *);	int (*link) (struct dentry *,struct inode *,struct dentry *);	int (*unlink) (struct inode *,struct dentry *);	int (*symlink) (struct inode *,struct dentry *,const char *);	int (*mkdir) (struct inode *,struct dentry *,int);	int (*rmdir) (struct inode *,struct dentry *);	int (*mknod) (struct inode *,struct dentry *,int,int);	int (*rename) (struct inode *, struct dentry *,			struct inode *, struct dentry *);	int (*readlink) (struct dentry *, char *,int);	int (*follow_link) (struct dentry *, struct nameidata *);	void (*truncate) (struct inode *);	int (*permission) (struct inode *, int);	int (*revalidate) (struct dentry *);	int (*setattr) (struct dentry *, struct iattr *);	int (*getattr) (struct dentry *, struct iattr *);locking rules:	all may block		BKL	i_sem(inode)	i_zombie(inode)lookup:		yes	yes		nocreate:		yes	yes		yeslink:		yes	yes		yesmknod:		yes	yes		yesmkdir:		yes	yes		yesunlink:		yes	yes		yesrmdir:		yes	yes		yes		(see below)rename:		yes	yes (both)	yes (both)	(see below)readlink:	no	no		nofollow_link:	no	no		notruncate:	yes	yes		no		(see below)setattr:	yes	if ATTR_SIZE	nopermssion:	yes	no		nogetattr:						(see below)revalidate:	no					(see below)	Additionally, ->rmdir() has i_zombie on victim and so does ->rename()in case when target exists and is a directory.	->rename() on directories has (per-superblock) ->s_vfs_rename_sem.	->revalidate(), it may be called both with and without the i_semon dentry->d_inode. VFS never calls it with i_zombie on dentry->d_inode,but watch for other methods directly calling this one...	->truncate() is never called directly - it's a callback, not amethod. It's called by vmtruncate() - library function normally used by->setattr(). Locking information above applies to that call (i.e. isinherited from ->setattr() - vmtruncate() is used when ATTR_SIZE had beenpassed).	->getattr() is currently unused.--------------------------- super_operations ---------------------------prototypes:	void (*read_inode) (struct inode *);	void (*write_inode) (struct inode *, int);	void (*put_inode) (struct inode *);	void (*delete_inode) (struct inode *);	void (*put_super) (struct super_block *);	void (*write_super) (struct super_block *);	int (*statfs) (struct super_block *, struct statfs *);	int (*remount_fs) (struct super_block *, int *, char *);	void (*clear_inode) (struct inode *);	void (*umount_begin) (struct super_block *);locking rules:	All may block.		BKL	s_lock	mount_semread_inode:	yes				(see below)write_inode:	no	put_inode:	no	delete_inode:	no	clear_inode:	no	put_super:	yes	yes	maybe		(see below)write_super:	yes	yes	maybe		(see below)statfs:		yes	no	noremount_fs:	yes	yes	maybe		(see below)umount_begin:	yes	no	maybe		(see below)->read_inode() is not a method - it's a callback used in iget()/iget4().rules for mount_sem are not too nice - it is going to die and be replacedby better scheme anyway.--------------------------- file_system_type ---------------------------prototypes:	struct super_block *(*read_super) (struct super_block *, void *, int);locking rules:may block	BKL	->s_lock	mount_semyes		yes	yes		maybe--------------------------- address_space_operations --------------------------prototypes:	int (*writepage)(struct page *);	int (*readpage)(struct file *, struct page *);	int (*sync_page)(struct page *);	int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);	int (*commit_write)(struct file *, struct page *, unsigned, unsigned);	int (*bmap)(struct address_space *, long);	int (*flushpage) (struct page *, unsigned long);	int (*releasepage) (struct page *, int);	int (*direct_IO)(int, struct inode *, struct kiobuf *, unsigned long, int);locking rules:	All may block		BKL	PageLocked(page)writepage:	no	yes, unlocksreadpage:	no	yes, unlockssync_page:	no	maybeprepare_write:	no	yescommit_write:	no	yesbmap:		yesflushpage:	no	yesreleasepage:	no	yes	->prepare_write(), ->commit_write(), ->sync_page() and ->readpage()may be called from the request handler (/dev/loop).	->readpage() and ->writepage() unlock the page.	->sync_page() locking rules are not well-defined - usually it is calledwith lock on page, but that is not guaranteed. Considering the currentlyexisting instances of this method ->sync_page() itself doesn't lookwell-defined...	->bmap() is currently used by legacy ioctl() (FIBMAP) provided by somefilesystems and by the swapper. The latter will eventually go away. Allinstances do not actually need the BKL. Please, keep it that way and don'tbreed new callers.	->flushpage() is called when the filesystem must attempt to dropsome or all of the buffers from the page when it is being truncated.  Itreturns zero on success.  If ->flushpage is zero, the kernel usesblock_flushpage() instead.	->releasepage() is called when the kernel is about to try to drop thebuffers from the page in preparation for freeing it.  It returns zero toindicate that the buffers are (or may be) freeable.  If ->flushpage is zero,the kernel assumes that the fs has no private interest in the buffers.	Note: currently almost all instances of address_space methods areusing BKL for internal serialization and that's one of the worst sourcesof contention. Normally they are calling library functions (in fs/buffer.c)and pass foo_get_block() as a callback (on local block-based filesystems,indeed). BKL is not needed for library stuff and is usually taken byfoo_get_block(). It's an overkill, since block bitmaps can be protected byinternal fs locking and real critical areas are much smaller than the areasfilesystems protect now.--------------------------- file_lock ------------------------------------prototypes:	void (*fl_notify)(struct file_lock *);	/* unblock callback */	void (*fl_insert)(struct file_lock *);	/* lock insertion callback */	void (*fl_remove)(struct file_lock *);	/* lock removal callback */locking rules:		BKL	may blockfl_notify:	yes	nofl_insert:	yes	maybefl_remove:	yes	maybe	Currently only NLM provides instances of this class. None of thethem block. If you have out-of-tree instances - please, show up. Lockingin that area will change.--------------------------- buffer_head -----------------------------------prototypes:	void (*b_end_io)(struct buffer_head *bh, int uptodate);locking rules:	called from interrupts. In other words, extreme care is needed here.bh is locked, but that's all warranties we have here. Currently only RAID1,highmem and fs/buffer.c are providing these. Block devices call this methodupon the IO completion.--------------------------- block_device_operations -----------------------prototypes:	int (*open) (struct inode *, struct file *);	int (*release) (struct inode *, struct file *);	int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);	int (*check_media_change) (kdev_t);	int (*revalidate) (kdev_t);locking rules:			BKL	bd_semopen:			yes	yesrelease:		yes	yesioctl:			yes	nocheck_media_change:	yes	norevalidate:		yes	noThe last two are called only from check_disk_change(). Prototypes are verybad - as soon as we'll get disk_struct they will change (and methods willbecome per-disk instead of per-partition).--------------------------- file_operations -------------------------------prototypes:	loff_t (*llseek) (struct file *, loff_t, int);	ssize_t (*read) (struct file *, char *, size_t, loff_t *);	ssize_t (*write) (struct file *, const char *, size_t, loff_t *);	int (*readdir) (struct file *, void *, filldir_t);	unsigned int (*poll) (struct file *, struct poll_table_struct *);	int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);	int (*mmap) (struct file *, struct vm_area_struct *);	int (*open) (struct inode *, struct file *);	int (*flush) (struct file *);	int (*release) (struct inode *, struct file *);	int (*fsync) (struct file *, struct dentry *, int datasync);	int (*fasync) (int, struct file *, int);	int (*lock) (struct file *, int, struct file_lock *);	ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);	ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);};locking rules:	All except ->poll() may block.		BKLllseek:		yesread:		nowrite:		noreaddir:	yes	(see below)poll:		noioctl:		yes	(see below)mmap:		noopen:		maybe	(see below)flush:		yesrelease:	nofsync:		yes	(see below)fasync:		yes	(see below)lock:		yesreadv:		nowritev:		no->open() locking is in-transit: big lock partially moved into the methods.The only exception is ->open() in the instances of file_operations that neverend up in ->i_fop/->proc_fops, i.e. ones that belong to character devices(chrdev_open() takes lock before replacing ->f_op and calling the secondarymethod. As soon as we fix the handling of module reference counters allinstances of ->open() will be called without the BKL.Note: ext2_release() was *the* source of contention on fs-intensiveloads and dropping BKL on ->release() helps to get rid of that (we stillgrab BKL for cases when we close a file that had been opened r/w, but thatcan and should be done using the internal locking with smaller critical areas).Current worst offender is ext2_get_block()...->fasync() is a mess. This area needs a big cleanup and that will probablyaffect locking.->readdir() and ->ioctl() on directories must be changed. Ideally we wouldmove ->readdir() to inode_operations and use a separate method for directory->ioctl() or kill the latter completely. One of the problems is that foranything that resembles union-mount we won't have a struct file for allcomponents. And there are other reasons why the current interface is a mess...->read on directories probably must go away - we should just enforce -EISDIRin sys_read() and friends.->fsync() has i_sem on inode.--------------------------- dquot_operations -------------------------------prototypes:	void (*initialize) (struct inode *, short);	void (*drop) (struct inode *);	int (*alloc_block) (const struct inode *, unsigned long, char);	int (*alloc_inode) (const struct inode *, unsigned long);	void (*free_block) (const struct inode *, unsigned long);	void (*free_inode) (const struct inode *, unsigned long);	int (*transfer) (struct dentry *, struct iattr *);locking rules:		BKLinitialize:	nodrop:		noalloc_block:	yesalloc_inode:	yesfree_block:	yesfree_inode:	yestransfer:	no--------------------------- vm_operations_struct -----------------------------prototypes:	void (*open)(struct vm_area_struct*);	void (*close)(struct vm_area_struct*);	struct page *(*nopage)(struct vm_area_struct*, unsigned long, int);locking rules:		BKL	mmap_semopen:		no	yesclose:		no	yesnopage:		no	yes================================================================================			Dubious stuff(if you break something or notice that it is broken and do not fix it yourself- at least put it here)ipc/shm.c::shm_delete() - may need BKL.->read() and ->write() in many drivers are (probably) missing BKL.drivers/sgi/char/graphics.c::sgi_graphics_nopage() - may need BKL.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -