* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
RETURN(0);
}
-struct page *osd_get_page(struct dt_object *dt, loff_t offset, int rw)
+static struct page *osd_get_page(struct dt_object *dt, loff_t offset, int rw)
{
struct inode *inode = osd_dt_obj(dt)->oo_inode;
struct osd_device *d = osd_obj2dev(osd_dt_obj(dt));
* journal_start
* i_mutex
* page lock
-
- * osd write path
- * lock page(s)
- * journal_start
- * truncate_sem
-
+ *
+ * osd write path:
+ * - lock page(s)
+ * - journal_start
+ * - truncate_sem
+ *
* ext4 vmtruncate:
- * lock pages, unlock
- * journal_start
- * lock partial page
- * i_data_sem
-
-*/
-int osd_bufs_get(const struct lu_env *env, struct dt_object *d, loff_t pos,
- ssize_t len, struct niobuf_local *lnb, int rw,
- struct lustre_capa *capa)
-{
- struct osd_object *obj = osd_dt_obj(d);
- int npages, i, rc = 0;
-
- LASSERT(obj->oo_inode);
-
- osd_map_remote_to_local(pos, len, &npages, lnb);
-
- for (i = 0; i < npages; i++, lnb++) {
- lnb->lnb_page = osd_get_page(d, lnb->lnb_file_offset, rw);
- if (lnb->lnb_page == NULL)
- GOTO(cleanup, rc = -ENOMEM);
-
- /* DLM locking protects us from write and truncate competing
- * for same region, but truncate can leave dirty page in the
- * cache. it's possible the writeout on a such a page is in
- * progress when we access it. it's also possible that during
- * this writeout we put new (partial) data, but then won't
- * be able to proceed in filter_commitrw_write(). thus let's
- * just wait for writeout completion, should be rare enough.
- * -bzzz */
- wait_on_page_writeback(lnb->lnb_page);
- BUG_ON(PageWriteback(lnb->lnb_page));
-
- lu_object_get(&d->do_lu);
- }
- rc = i;
-
-cleanup:
- RETURN(rc);
-}
+ * - lock pages, unlock
+ * - journal_start
+ * - lock partial page
+ * - i_data_sem
+ *
+ */
+/**
+ * Unlock and release pages loaded by osd_bufs_get()
+ *
+ * Unlock \a npages pages from \a lnb and drop the refcount on them.
+ *
+ * \param env thread execution environment
+ * \param dt dt object undergoing IO (OSD object + methods)
+ * \param lnb array of pages undergoing IO
+ * \param npages number of pages in \a lnb
+ *
+ * \retval 0 always
+ */
static int osd_bufs_put(const struct lu_env *env, struct dt_object *dt,
struct niobuf_local *lnb, int npages)
{
RETURN(0);
}
+/**
+ * Load and lock pages undergoing IO
+ *
+ * Pages as described in the \a lnb array are fetched (from disk or cache)
+ * and locked for IO by the caller.
+ *
+ * DLM locking protects us from write and truncate competing for same region,
+ * but partial-page truncate can leave dirty pages in the cache for ldiskfs.
+ * It's possible the writeout on a such a page is in progress when we access
+ * it. It's also possible that during this writeout we put new (partial) data
+ * into the page, but won't be able to proceed in filter_commitrw_write().
+ * Therefore, just wait for writeout completion as it should be rare enough.
+ *
+ * \param env thread execution environment
+ * \param dt dt object undergoing IO (OSD object + methods)
+ * \param pos byte offset of IO start
+ * \param len number of bytes of IO
+ * \param lnb array of extents undergoing IO
+ * \param rw read or write operation?
+ * \param capa capabilities
+ *
+ * \retval pages (zero or more) loaded successfully
+ * \retval -ENOMEM on memory/page allocation error
+ */
+static int osd_bufs_get(const struct lu_env *env, struct dt_object *dt,
+ loff_t pos, ssize_t len, struct niobuf_local *lnb,
+ int rw, struct lustre_capa *capa)
+{
+ struct osd_object *obj = osd_dt_obj(dt);
+ int npages, i, rc = 0;
+
+ LASSERT(obj->oo_inode);
+
+ osd_map_remote_to_local(pos, len, &npages, lnb);
+
+ for (i = 0; i < npages; i++, lnb++) {
+ lnb->lnb_page = osd_get_page(dt, lnb->lnb_file_offset, rw);
+ if (lnb->lnb_page == NULL)
+ GOTO(cleanup, rc = -ENOMEM);
+
+ wait_on_page_writeback(lnb->lnb_page);
+ BUG_ON(PageWriteback(lnb->lnb_page));
+
+ lu_object_get(&dt->do_lu);
+ }
+
+ RETURN(i);
+
+cleanup:
+ if (i > 0)
+ osd_bufs_put(env, dt, lnb - i, i);
+ return rc;
+}
+
#ifndef HAVE_LDISKFS_MAP_BLOCKS
#ifdef HAVE_EXT_PBLOCK /* Name changed to ext4_ext_pblock for kernel 2.6.35 */
return err;
}
-int osd_ldiskfs_map_nblocks(struct inode *inode, unsigned long block,
- unsigned long num, unsigned long *blocks,
- int create)
+static int osd_ldiskfs_map_nblocks(struct inode *inode, unsigned long block,
+ unsigned long num, unsigned long *blocks,
+ int create)
{
struct bpointers bp;
int err;
return err;
}
-int osd_ldiskfs_map_bm_inode_pages(struct inode *inode, struct page **page,
- int pages, unsigned long *blocks,
- int create)
+static int osd_ldiskfs_map_bm_inode_pages(struct inode *inode,
+ struct page **page, int pages,
+ unsigned long *blocks, int create)
{
int blocks_per_page = PAGE_CACHE_SIZE >> inode->i_blkbits;
+ pgoff_t bitmap_max_page_index;
unsigned long *b;
int rc = 0, i;
+ bitmap_max_page_index = LDISKFS_SB(inode->i_sb)->s_bitmap_maxbytes >>
+ PAGE_SHIFT;
for (i = 0, b = blocks; i < pages; i++, page++) {
+ if ((*page)->index + 1 >= bitmap_max_page_index) {
+ rc = -EFBIG;
+ break;
+ }
rc = ldiskfs_map_inode_page(inode, *page, b, create);
if (rc) {
CERROR("ino %lu, blk %lu create %d: rc %d\n",
return rc;
}
-int osd_ldiskfs_map_ext_inode_pages(struct inode *inode, struct page **page,
- int pages, unsigned long *blocks,
- int create)
+static int osd_ldiskfs_map_ext_inode_pages(struct inode *inode,
+ struct page **page,
+ int pages, unsigned long *blocks,
+ int create)
{
int blocks_per_page = PAGE_CACHE_SIZE >> inode->i_blkbits;
int rc = 0, i = 0;
struct page *fp = NULL;
int clen = 0;
+ pgoff_t extent_max_page_index;
+
+ extent_max_page_index = inode->i_sb->s_maxbytes >> PAGE_SHIFT;
CDEBUG(D_OTHER, "inode %lu: map %d pages from %lu\n",
inode->i_ino, pages, (*page)->index);
continue;
}
+ if (fp->index + i >= extent_max_page_index)
+ GOTO(cleanup, rc = -EFBIG);
+
/* process found extent */
rc = osd_ldiskfs_map_nblocks(inode, fp->index * blocks_per_page,
clen * blocks_per_page, blocks,
int rc = 0, i = 0;
struct page *fp = NULL;
int clen = 0;
+ pgoff_t max_page_index;
+
+ max_page_index = inode->i_sb->s_maxbytes >> PAGE_SHIFT;
CDEBUG(D_OTHER, "inode %lu: map %d pages from %lu\n",
inode->i_ino, pages, (*page)->index);
if (++i != pages)
continue;
}
+ if (fp->index + i >= max_page_index)
+ GOTO(cleanup, rc = -EFBIG);
/* process found extent */
map.m_lblk = fp->index * blocks_per_page;
map.m_len = blen = clen * blocks_per_page;
}
/* Check if a block is allocated or not */
-static int osd_is_mapped(struct inode *inode, obd_size offset)
+static int osd_is_mapped(struct inode *inode, u64 offset)
{
sector_t (*fs_bmap)(struct address_space *, sector_t);
struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
struct timeval start, end;
unsigned long timediff;
- int rc = 0, i, m = 0, cache = 0, cache_hits = 0, cache_misses = 0;
+ int rc = 0, i, cache = 0, cache_hits = 0, cache_misses = 0;
+ loff_t isize;
LASSERT(inode);
if (unlikely(rc != 0))
RETURN(rc);
+ isize = i_size_read(inode);
+
if (osd->od_read_cache)
cache = 1;
- if (i_size_read(inode) > osd->od_readcache_max_filesize)
+ if (isize > osd->od_readcache_max_filesize)
cache = 0;
do_gettimeofday(&start);
for (i = 0; i < npages; i++) {
- if (i_size_read(inode) <= lnb[i].lnb_file_offset)
+ if (isize <= lnb[i].lnb_file_offset)
/* If there's no more data, abort early.
* lnb->lnb_rc == 0, so it's easy to detect later. */
break;
- if (i_size_read(inode) <
- lnb[i].lnb_file_offset + lnb[i].lnb_len - 1)
- lnb[i].lnb_rc = i_size_read(inode) -
- lnb[i].lnb_file_offset;
+ if (isize < lnb[i].lnb_file_offset + lnb[i].lnb_len - 1)
+ lnb[i].lnb_rc = isize - lnb[i].lnb_file_offset;
else
lnb[i].lnb_rc = lnb[i].lnb_len;
- m += lnb[i].lnb_len;
if (PageUptodate(lnb[i].lnb_page)) {
cache_hits++;
boffs = *offs & (blocksize - 1);
csize = min(blocksize - boffs, size);
bh = ldiskfs_bread(NULL, inode, block, 0, &err);
- if (!bh) {
- CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n",
- LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
- csize, *offs, inode->i_ino, err);
- return err;
- }
+ if (err != 0) {
+ CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n",
+ LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
+ csize, *offs, inode->i_ino, err);
+ if (bh != NULL)
+ brelse(bh);
+ return err;
+ }
- memcpy(buf, bh->b_data + boffs, csize);
- brelse(bh);
+ if (bh != NULL) {
+ memcpy(buf, bh->b_data + boffs, csize);
+ brelse(bh);
+ } else {
+ memset(buf, 0, csize);
+ }
*offs += csize;
buf += csize;
"boffs %d size %d bh->b_size %lu\n",
boffs, size, (unsigned long)bh->b_size);
memcpy(bh->b_data + boffs, buf, size);
- err = ldiskfs_journal_dirty_metadata(handle, bh);
+ err = ldiskfs_handle_dirty_metadata(handle, NULL, bh);
if (err)
break;