*
* Lustre Lite I/O Page Cache
*
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ * Copyright (C) 2002 Cluster File Systems, Inc.
*/
#include <linux/config.h>
/* SYNCHRONOUS I/O to object storage for an inode */
static int ll_brw(int rw, struct inode *inode, struct page *page, int create)
{
- struct ll_inode_info *lii = ll_i2info(inode);
- struct lov_stripe_md *md = lii->lli_smd;
- struct brw_page pg;
- int err;
+ struct ll_inode_info *lli = ll_i2info(inode);
+ struct lov_stripe_md *md = lli->lli_smd;
+ struct brw_page pg;
+ int err;
struct io_cb_data *cbd = ll_init_cb();
ENTRY;
- if (!cbd)
- RETURN(-ENOMEM);
+
+ if (!cbd)
+ RETURN(-ENOMEM);
pg.pg = page;
pg.count = PAGE_SIZE;
pg.flag = create ? OBD_BRW_CREATE : 0;
err = obd_brw(rw, ll_i2obdconn(inode), md, 1, &pg, ll_sync_io_cb, cbd);
+
RETURN(err);
} /* ll_brw */
static int ll_readpage(struct file *file, struct page *page)
{
struct inode *inode = page->mapping->host;
+ obd_off offset = ((obd_off)page->index) << PAGE_SHIFT;
int rc = 0;
ENTRY;
if (!PageLocked(page))
LBUG();
- if (((inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT) <= page->index) {
+ if (inode->i_size <= offset) {
memset(kmap(page), 0, PAGE_SIZE);
kunmap(page);
GOTO(readpage_out, rc);
unsigned to)
{
struct inode *inode = page->mapping->host;
- //obd_off offset = ((obd_off)page->index) << PAGE_SHIFT;
+ obd_off offset = ((obd_off)page->index) << PAGE_SHIFT;
int rc = 0;
char *addr;
- ENTRY;
-
+ ENTRY;
+
addr = kmap(page);
if (!PageLocked(page))
LBUG();
if (Page_Uptodate(page))
GOTO(prepare_done, rc);
- memset(addr, 0, PAGE_SIZE);
-
/* We're completely overwriting an existing page, so _don't_ set it up
* to date until commit_write */
if (from == 0 && to == PAGE_SIZE)
RETURN(0);
-
- /* prepare write should not read what lies beyond the end of
- the file */
+ /* We are writing to a new page, no need to read old data */
+ if (inode->i_size <= offset) {
+ memset(addr, 0, PAGE_SIZE);
+ goto prepare_done;
+ }
rc = ll_brw(OBD_BRW_READ, inode, page, 0);
} else {
CERROR("ll_brw failure %d\n", err);
}
- UnlockPage(page);
+ unlock_page(page);
RETURN(err);
}
{
int create = 1;
struct inode *inode = page->mapping->host;
- struct ll_inode_info *lii = ll_i2info(inode);
- struct lov_stripe_md *md = lii->lli_smd;
+ struct ll_inode_info *lli = ll_i2info(inode);
+ struct lov_stripe_md *md = lli->lli_smd;
struct brw_page pg;
int err;
- struct iattr iattr;
+ loff_t size;
struct io_cb_data *cbd = ll_init_cb();
pg.pg = page;
1, &pg, ll_sync_io_cb, cbd);
kunmap(page);
- if (err)
- GOTO(out, err);
+ size = pg.off + pg.count;
+ /* do NOT truncate when writing in the middle of a file */
+ if (size > inode->i_size)
+ inode->i_size = size;
- iattr.ia_size = pg.off + pg.count;
- if (iattr.ia_size > inode->i_size) {
- /* do NOT truncate when writing in the middle of a file */
- inode->i_size = iattr.ia_size;
- iattr.ia_valid = ATTR_SIZE;
-#if 0
- err = ll_inode_setattr(inode, &iattr, 0);
- if (err) {
- CERROR("failed - %d.\n", err);
- err = -EIO;
- }
-#endif
- }
-out:
RETURN(err);
} /* ll_commit_write */
{
struct obdo oa = {0};
struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
+ struct lustre_handle *lockhs = NULL;
int err;
ENTRY;
- if (!md) {
+ if (!md) {
/* object not yet allocated */
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
return;
}
+ oa.o_id = md->lmd_object_id;
+ oa.o_size = inode->i_size;
+
CDEBUG(D_INFO, "calling punch for %ld (all bytes after %Ld)\n",
(long)oa.o_id, (unsigned long long)oa.o_size);
- oa.o_id = md->lmd_object_id;
+ err = ll_size_lock(inode, md, oa.o_size, LCK_PW, &lockhs);
+ if (err) {
+ CERROR("ll_size_lock failed: %d\n", err);
+ /* FIXME: What to do here? It's too late to back out... */
+ LBUG();
+ }
+
oa.o_valid = OBD_MD_FLID;
/* truncate == punch to/from start from/to end:
set end to -1 for that. */
if (err)
CERROR("obd_truncate fails (%d)\n", err);
else
- /* This is done for us at the OST and MDS, but the
- * updated timestamps are not sent back to us.
- * Needed for POSIX.
- */
- inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+ obdo_to_inode(inode, &oa, oa.o_valid);
+
+ err = ll_size_unlock(inode, md, LCK_PW, lockhs);
+ if (err)
+ CERROR("ll_size_unlock failed: %d\n", err);
EXIT;
return;
unsigned long blocknr, int blocksize)
{
obd_count bufs_per_obdo = iobuf->nr_pages;
- struct ll_inode_info *lii = ll_i2info(inode);
- struct lov_stripe_md *md = lii->lli_smd;
+ struct ll_inode_info *lli = ll_i2info(inode);
+ struct lov_stripe_md *md = lli->lli_smd;
struct brw_page *pga;
int rc = 0;
int i;