-static
-struct llu_sysio_cookie* get_sysio_cookie(struct inode *inode, int maxpages)
-{
- struct llu_sysio_cookie *cookie;
- int rc;
-
- OBD_ALLOC(cookie, LLU_SYSIO_COOKIE_SIZE(maxpages));
- if (cookie == NULL)
- goto out;
-
- I_REF(inode);
- cookie->lsc_inode = inode;
- cookie->lsc_maxpages = maxpages;
- cookie->lsc_llap = (struct ll_async_page *)(cookie + 1);
- cookie->lsc_pages = (struct page *) (cookie->lsc_llap + maxpages);
-
- rc = oig_init(&cookie->lsc_oig);
- if (rc) {
- OBD_FREE(cookie, LLU_SYSIO_COOKIE_SIZE(maxpages));
- cookie = NULL;
- }
-
-out:
- return cookie;
-}
-
-static
-void put_sysio_cookie(struct llu_sysio_cookie *cookie)
-{
- struct lov_stripe_md *lsm = llu_i2info(cookie->lsc_inode)->lli_smd;
- struct obd_export *exp = llu_i2obdexp(cookie->lsc_inode);
- struct ll_async_page *llap = cookie->lsc_llap;
-#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
- struct page *pages = cookie->lsc_pages;
-#endif
- int i;
-
- for (i = 0; i< cookie->lsc_maxpages; i++) {
- if (llap[i].llap_cookie)
- obd_teardown_async_page(exp, lsm, NULL,
- llap[i].llap_cookie);
-#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
- if (pages[i]._managed) {
- free(pages[i].addr);
- pages[i]._managed = 0;
- }
-#endif
- }
-
- I_RELE(cookie->lsc_inode);
-
- oig_release(cookie->lsc_oig);
- OBD_FREE(cookie, LLU_SYSIO_COOKIE_SIZE(cookie->lsc_maxpages));
-}
-
-#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
-/* Note: these code should be removed finally, don't need
- * more cleanup
- */
-static
-int prepare_unaligned_write(struct llu_sysio_cookie *cookie)
-{
- struct inode *inode = cookie->lsc_inode;
- struct llu_inode_info *lli = llu_i2info(inode);
- struct lov_stripe_md *lsm = lli->lli_smd;
- struct obdo oa;
- struct page *pages = cookie->lsc_pages;
- int i, pgidx[2] = {0, cookie->lsc_npages-1};
- int rc;
- ENTRY;
-
- for (i = 0; i < 2; i++) {
- struct page *oldpage = &pages[pgidx[i]];
- struct page newpage;
- struct brw_page pg;
- char *newbuf;
-
- if (i == 0 && pgidx[0] == pgidx[1])
- continue;
-
- LASSERT(oldpage->_offset + oldpage->_count <= PAGE_CACHE_SIZE);
-
- if (oldpage->_count == PAGE_CACHE_SIZE)
- continue;
-
- if (oldpage->index << PAGE_CACHE_SHIFT >=
- lli->lli_st_size)
- continue;
-
- newbuf = malloc(PAGE_CACHE_SIZE);
- if (!newbuf)
- return -ENOMEM;
-
- newpage.index = oldpage->index;
- newpage.addr = newbuf;
-
- pg.pg = &newpage;
- pg.off = ((obd_off)newpage.index << PAGE_CACHE_SHIFT);
- if (pg.off + PAGE_CACHE_SIZE > lli->lli_st_size)
- pg.count = lli->lli_st_size % PAGE_CACHE_SIZE;
- else
- pg.count = PAGE_CACHE_SIZE;
- pg.flag = 0;
-
- oa.o_id = lsm->lsm_object_id;
- oa.o_mode = lli->lli_st_mode;
- oa.o_valid = OBD_MD_FLID | OBD_MD_FLMODE | OBD_MD_FLTYPE;
-
- /* issue read */
- rc = obd_brw(OBD_BRW_READ, llu_i2obdexp(inode), &oa, lsm, 1, &pg, NULL);
- if (rc) {
- free(newbuf);
- RETURN(rc);
- }
-
- /* copy page content, and reset page params */
- memcpy(newbuf + oldpage->_offset,
- (char*)oldpage->addr + oldpage->_offset,
- oldpage->_count);
-
- oldpage->addr = newbuf;
- if ((((obd_off)oldpage->index << PAGE_CACHE_SHIFT) +
- oldpage->_offset + oldpage->_count) > lli->lli_st_size)
- oldpage->_count += oldpage->_offset;
- else
- oldpage->_count = PAGE_CACHE_SIZE;
- oldpage->_offset = 0;
- oldpage->_managed = 1;
- }
-
- RETURN(0);
-}
-#endif
-
-static
-int llu_prep_async_io(struct llu_sysio_cookie *cookie, int cmd,
- char *buf, loff_t pos, size_t count)