git://git.onelab.eu
/
linux-2.6.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git]
/
fs
/
direct-io.c
diff --git
a/fs/direct-io.c
b/fs/direct-io.c
index
afc38f4
..
1d55e7e
100644
(file)
--- a/
fs/direct-io.c
+++ b/
fs/direct-io.c
@@
-66,6
+66,7
@@
struct dio {
struct bio *bio; /* bio under assembly */
struct inode *inode;
int rw;
struct bio *bio; /* bio under assembly */
struct inode *inode;
int rw;
+ loff_t i_size; /* i_size when submitted */
int lock_type; /* doesn't change */
unsigned blkbits; /* doesn't change */
unsigned blkfactor; /* When we're using an alignment which
int lock_type; /* doesn't change */
unsigned blkbits; /* doesn't change */
unsigned blkfactor; /* When we're using an alignment which
@@
-215,7
+216,7
@@
static void dio_complete(struct dio *dio, loff_t offset, ssize_t bytes)
{
if (dio->end_io && dio->result)
dio->end_io(dio->inode, offset, bytes, dio->map_bh.b_private);
{
if (dio->end_io && dio->result)
dio->end_io(dio->inode, offset, bytes, dio->map_bh.b_private);
- if (dio->lock_type
!= DIO_N
O_LOCKING)
+ if (dio->lock_type
== DI
O_LOCKING)
up_read(&dio->inode->i_alloc_sem);
}
up_read(&dio->inode->i_alloc_sem);
}
@@
-230,17
+231,29
@@
static void finished_one_bio(struct dio *dio)
spin_lock_irqsave(&dio->bio_lock, flags);
if (dio->bio_count == 1) {
if (dio->is_async) {
spin_lock_irqsave(&dio->bio_lock, flags);
if (dio->bio_count == 1) {
if (dio->is_async) {
+ ssize_t transferred;
+ loff_t offset;
+
/*
* Last reference to the dio is going away.
* Drop spinlock and complete the DIO.
*/
spin_unlock_irqrestore(&dio->bio_lock, flags);
/*
* Last reference to the dio is going away.
* Drop spinlock and complete the DIO.
*/
spin_unlock_irqrestore(&dio->bio_lock, flags);
- dio_complete(dio, dio->block_in_file << dio->blkbits,
- dio->result);
+
+ /* Check for short read case */
+ transferred = dio->result;
+ offset = dio->iocb->ki_pos;
+
+ if ((dio->rw == READ) &&
+ ((offset + transferred) > dio->i_size))
+ transferred = dio->i_size - offset;
+
+ dio_complete(dio, offset, transferred);
+
/* Complete AIO later if falling back to buffered i/o */
if (dio->result == dio->size ||
((dio->rw == READ) && dio->result)) {
/* Complete AIO later if falling back to buffered i/o */
if (dio->result == dio->size ||
((dio->rw == READ) && dio->result)) {
- aio_complete(dio->iocb,
dio->result
, 0);
+ aio_complete(dio->iocb,
transferred
, 0);
kfree(dio);
return;
} else {
kfree(dio);
return;
} else {
@@
-844,8
+857,10
@@
do_holes:
char *kaddr;
/* AKPM: eargh, -ENOTBLK is a hack */
char *kaddr;
/* AKPM: eargh, -ENOTBLK is a hack */
- if (dio->rw == WRITE)
+ if (dio->rw == WRITE) {
+ page_cache_release(page);
return -ENOTBLK;
return -ENOTBLK;
+ }
if (dio->block_in_file >=
i_size_read(dio->inode)>>blkbits) {
if (dio->block_in_file >=
i_size_read(dio->inode)>>blkbits) {
@@
-949,6
+964,7
@@
direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
dio->page_errors = 0;
dio->result = 0;
dio->iocb = iocb;
dio->page_errors = 0;
dio->result = 0;
dio->iocb = iocb;
+ dio->i_size = i_size_read(inode);
/*
* BIO completion state.
/*
* BIO completion state.
@@
-1124,11
+1140,23
@@
direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
/*
* This is a library function for use by filesystem drivers.
/*
* This is a library function for use by filesystem drivers.
+ * The locking rules are governed by the dio_lock_type parameter.
+ *
+ * DIO_NO_LOCKING (no locking, for raw block device access)
+ * For writes, i_sem is not held on entry; it is never taken.
*
*
- * For writes to S_ISREG files, we are called under i_sem and return with i_sem
- * held, even though it is internally dropped.
+ * DIO_LOCKING (simple locking for regular files)
+ * For writes we are called under i_sem and return with i_sem held, even though
+ * it is internally dropped.
+ * For reads, i_sem is not held on entry, but it is taken and dropped before
+ * returning.
*
*
- * For writes to S_ISBLK files, i_sem is not held on entry; it is never taken.
+ * DIO_OWN_LOCKING (filesystem provides synchronisation and handling of
+ * uninitialised data, allowing parallel direct readers and writers)
+ * For writes we are called without i_sem, return without it, never touch it.
+ * For reads, i_sem is held on entry and will be released before returning.
+ *
+ * Additional i_alloc_sem locking requirements described inline below.
*/
ssize_t
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
*/
ssize_t
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
@@
-1145,6
+1173,10
@@
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
ssize_t retval = -EINVAL;
loff_t end = offset;
struct dio *dio;
ssize_t retval = -EINVAL;
loff_t end = offset;
struct dio *dio;
+ int reader_with_isem = (rw == READ && dio_lock_type == DIO_OWN_LOCKING);
+
+ if (rw & WRITE)
+ current->flags |= PF_SYNCWRITE;
if (bdev)
bdev_blkbits = blksize_bits(bdev_hardsect_size(bdev));
if (bdev)
bdev_blkbits = blksize_bits(bdev_hardsect_size(bdev));
@@
-1177,33
+1209,44
@@
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
goto out;
/*
goto out;
/*
+ * For block device access DIO_NO_LOCKING is used,
+ * neither readers nor writers do any locking at all
* For regular files using DIO_LOCKING,
* readers need to grab i_sem and i_alloc_sem
* writers need to grab i_alloc_sem only (i_sem is already held)
* For regular files using DIO_OWN_LOCKING,
* For regular files using DIO_LOCKING,
* readers need to grab i_sem and i_alloc_sem
* writers need to grab i_alloc_sem only (i_sem is already held)
* For regular files using DIO_OWN_LOCKING,
- *
both readers and writers need to grab i_alloc_sem
- *
neither readers nor writers hold i_sem on entry (nor exit
)
+ *
neither readers nor writers take any locks here
+ *
(i_sem is already held and release for writers here
)
*/
dio->lock_type = dio_lock_type;
if (dio_lock_type != DIO_NO_LOCKING) {
*/
dio->lock_type = dio_lock_type;
if (dio_lock_type != DIO_NO_LOCKING) {
- if (rw == READ) {
+ /* watch out for a 0 len io from a tricksy fs */
+ if (rw == READ && end > offset) {
struct address_space *mapping;
mapping = iocb->ki_filp->f_mapping;
struct address_space *mapping;
mapping = iocb->ki_filp->f_mapping;
- down(&inode->i_sem);
- retval = filemap_write_and_wait(mapping);
+ if (dio_lock_type != DIO_OWN_LOCKING) {
+ down(&inode->i_sem);
+ reader_with_isem = 1;
+ }
+
+ retval = filemap_write_and_wait_range(mapping, offset,
+ end - 1);
if (retval) {
if (retval) {
- up(&inode->i_sem);
kfree(dio);
goto out;
}
kfree(dio);
goto out;
}
- down_read(&inode->i_alloc_sem);
- if (dio_lock_type == DIO_OWN_LOCKING)
+
+ if (dio_lock_type == DIO_OWN_LOCKING)
{
up(&inode->i_sem);
up(&inode->i_sem);
- } else {
- down_read(&inode->i_alloc_sem);
+ reader_with_isem = 0;
+ }
}
}
+
+ if (dio_lock_type == DIO_LOCKING)
+ down_read(&inode->i_alloc_sem);
}
}
+
/*
* For file extending writes updating i_size before data
* writeouts complete can expose uninitialized blocks. So
/*
* For file extending writes updating i_size before data
* writeouts complete can expose uninitialized blocks. So
@@
-1215,7
+1258,15
@@
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
retval = direct_io_worker(rw, iocb, inode, iov, offset,
nr_segs, blkbits, get_blocks, end_io, dio);
retval = direct_io_worker(rw, iocb, inode, iov, offset,
nr_segs, blkbits, get_blocks, end_io, dio);
+
+ if (rw == READ && dio_lock_type == DIO_LOCKING)
+ reader_with_isem = 0;
+
out:
out:
+ if (reader_with_isem)
+ up(&inode->i_sem);
+ if (rw & WRITE)
+ current->flags &= ~PF_SYNCWRITE;
return retval;
}
EXPORT_SYMBOL(__blockdev_direct_IO);
return retval;
}
EXPORT_SYMBOL(__blockdev_direct_IO);