Re: [PATCH] 2.6.14 patch for supporting madvise(MADV_REMOVE)

From: Andrew Morton
Date: Fri Nov 11 2005 - 19:34:18 EST


Badari Pulavarty <pbadari@xxxxxxxxxx> wrote:
>
> +int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end)
> +{
> + struct address_space *mapping = inode->i_mapping;
> +
> + /*
> + * If the underlying filesystem is not going to provide
> + * a way to truncate a range of blocks (punch a hole) -
> + * we should return failure right now.
> + */
> + if (!inode->i_op || !inode->i_op->truncate_range)
> + return -ENOSYS;
> +
> + /* XXX - Do we need both i_sem and i_allocsem all the way ? */
> + down(&inode->i_sem);
> + down_write(&inode->i_alloc_sem);
> + unmap_mapping_range(mapping, offset, (end - offset), 1);
> + truncate_inode_pages_range(mapping, offset, end);
> + inode->i_op->truncate_range(inode, offset, end);
> + up_write(&inode->i_alloc_sem);
> + up(&inode->i_sem);
> +
> + return 0;
> +}

Yes, we need to take i_alloc_sem for writing. To prevent concurrent
direct-io reads from coming in and instantiated by unwritten blocks.

tmpfs doesn't implements direct-io though.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/