mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
Btrfs: transaction ioctls
These ioctls let a user application hold a transaction open while it performs a series of operations. A final ioctl does a sync on the fs (closing the current transaction). This is the main requirement for Ceph's OSD to be able to keep the data it's storing in a btrfs volume consistent, and AFAICS it works just fine. The application would do something like fd = ::open("some/file", O_RDONLY); ::ioctl(fd, BTRFS_IOC_TRANS_START); /* do a bunch of stuff */ ::ioctl(fd, BTRFS_IOC_TRANS_END); or just ::close(fd); And to ensure it commits to disk, ::ioctl(fd, BTRFS_IOC_SYNC); When a transaction is held open, the trans_handle is attached to the struct file (via private_data) so that it will get cleaned up if the process dies unexpectedly. A held transaction is also ended on fsync() to avoid a deadlock. A misbehaving application could also deliberately hold a transaction open, effectively locking up the FS, so it may make sense to restrict something like this to root or something. Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
eba12c7bfc
commit
6bf13c0cc8
5 changed files with 83 additions and 2 deletions
|
@ -3336,6 +3336,61 @@ out_fput:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* there are many ways the trans_start and trans_end ioctls can lead
|
||||
* to deadlocks. They should only be used by applications that
|
||||
* basically own the machine, and have a very in depth understanding
|
||||
* of all the possible deadlocks and enospc problems.
|
||||
*/
|
||||
long btrfs_ioctl_trans_start(struct file *file)
|
||||
{
|
||||
struct inode *inode = fdentry(file)->d_inode;
|
||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||
struct btrfs_trans_handle *trans;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&root->fs_info->fs_mutex);
|
||||
if (file->private_data) {
|
||||
ret = -EINPROGRESS;
|
||||
goto out;
|
||||
}
|
||||
trans = btrfs_start_transaction(root, 0);
|
||||
if (trans)
|
||||
file->private_data = trans;
|
||||
else
|
||||
ret = -ENOMEM;
|
||||
/*printk(KERN_INFO "btrfs_ioctl_trans_start on %p\n", file);*/
|
||||
out:
|
||||
mutex_unlock(&root->fs_info->fs_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* there are many ways the trans_start and trans_end ioctls can lead
|
||||
* to deadlocks. They should only be used by applications that
|
||||
* basically own the machine, and have a very in depth understanding
|
||||
* of all the possible deadlocks and enospc problems.
|
||||
*/
|
||||
long btrfs_ioctl_trans_end(struct file *file)
|
||||
{
|
||||
struct inode *inode = fdentry(file)->d_inode;
|
||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||
struct btrfs_trans_handle *trans;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&root->fs_info->fs_mutex);
|
||||
trans = file->private_data;
|
||||
if (!trans) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
btrfs_end_transaction(trans, root);
|
||||
file->private_data = 0;
|
||||
out:
|
||||
mutex_unlock(&root->fs_info->fs_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long btrfs_ioctl(struct file *file, unsigned int
|
||||
cmd, unsigned long arg)
|
||||
{
|
||||
|
@ -3356,6 +3411,13 @@ long btrfs_ioctl(struct file *file, unsigned int
|
|||
return btrfs_balance(root->fs_info->dev_root);
|
||||
case BTRFS_IOC_CLONE:
|
||||
return btrfs_ioctl_clone(file, arg);
|
||||
case BTRFS_IOC_TRANS_START:
|
||||
return btrfs_ioctl_trans_start(file);
|
||||
case BTRFS_IOC_TRANS_END:
|
||||
return btrfs_ioctl_trans_end(file);
|
||||
case BTRFS_IOC_SYNC:
|
||||
btrfs_sync_fs(file->f_dentry->d_sb, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOTTY;
|
||||
|
@ -3679,6 +3741,7 @@ static struct file_operations btrfs_dir_file_operations = {
|
|||
#ifdef CONFIG_COMPAT
|
||||
.compat_ioctl = btrfs_ioctl,
|
||||
#endif
|
||||
.release = btrfs_release_file,
|
||||
};
|
||||
|
||||
static struct extent_io_ops btrfs_extent_io_ops = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue