Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f7c579c authored by Chris Mason's avatar Chris Mason
Browse files

Btrfs: move O_DIRECT space reservation to btrfs_direct_IO



This moves the delalloc space reservation done for O_DIRECT
into btrfs_direct_IO.  This way we don't leak reserved space
if the generic O_DIRECT write code errors out before it
calls into btrfs_direct_IO.

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 4845e44f
Loading
Loading
Loading
Loading
+0 −5
Original line number Original line Diff line number Diff line
@@ -888,14 +888,9 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
	BTRFS_I(inode)->sequence++;
	BTRFS_I(inode)->sequence++;


	if (unlikely(file->f_flags & O_DIRECT)) {
	if (unlikely(file->f_flags & O_DIRECT)) {
		ret = btrfs_delalloc_reserve_space(inode, count);
		if (ret)
			goto out;

		num_written = generic_file_direct_write(iocb, iov, &nr_segs,
		num_written = generic_file_direct_write(iocb, iov, &nr_segs,
							pos, ppos, count,
							pos, ppos, count,
							ocount);
							ocount);

		/*
		/*
		 * the generic O_DIRECT will update in-memory i_size after the
		 * the generic O_DIRECT will update in-memory i_size after the
		 * DIOs are done.  But our endio handlers that update the on
		 * DIOs are done.  But our endio handlers that update the on
+8 −1
Original line number Original line Diff line number Diff line
@@ -5602,9 +5602,16 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
	ssize_t ret;
	ssize_t ret;
	int writing = rw & WRITE;
	int writing = rw & WRITE;
	int write_bits = 0;
	int write_bits = 0;
	size_t count = iov_length(iov, nr_segs);


	lockstart = offset;
	lockstart = offset;
	lockend = offset + iov_length(iov, nr_segs) - 1;
	lockend = offset + count - 1;

	if (writing) {
		ret = btrfs_delalloc_reserve_space(inode, count);
		if (ret)
			goto out;
	}


	while (1) {
	while (1) {
		lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,
		lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,