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:
@@ -978,9 +978,11 @@ out_nolock:
|
||||
return num_written ? num_written : err;
|
||||
}
|
||||
|
||||
static int btrfs_release_file (struct inode * inode, struct file * filp)
|
||||
int btrfs_release_file(struct inode * inode, struct file * filp)
|
||||
{
|
||||
btrfs_del_ordered_inode(inode);
|
||||
if (filp->private_data)
|
||||
btrfs_ioctl_trans_end(filp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1011,6 +1013,9 @@ static int btrfs_sync_file(struct file *file,
|
||||
/*
|
||||
* ok we haven't committed the transaction yet, lets do a commit
|
||||
*/
|
||||
if (file->private_data)
|
||||
btrfs_ioctl_trans_end(file);
|
||||
|
||||
trans = btrfs_start_transaction(root, 1);
|
||||
if (!trans) {
|
||||
ret = -ENOMEM;
|
||||
|
Reference in New Issue
Block a user