+static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
+ struct niobuf_remote *nb, int *pages,
+ struct niobuf_local *lb, int cmd, int *left)
+{
+ int gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
+ GFP_HIGHUSER : GFP_IOFS;
+ int ispersistent = ostid_id(&obj->ioo_oid) == ECHO_PERSISTENT_OBJID;
+ int debug_setup = (!ispersistent &&
+ (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
+ (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
+ struct niobuf_local *res = lb;
+ obd_off offset = nb->offset;
+ int len = nb->len;
+
+ while (len > 0) {
+ int plen = PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1));
+ if (len < plen)
+ plen = len;
+
+ /* check for local buf overflow */
+ if (*left == 0)
+ return -EINVAL;
+
+ res->lnb_file_offset = offset;
+ res->lnb_len = plen;
+ LASSERT((res->lnb_file_offset & ~CFS_PAGE_MASK) +
+ res->lnb_len <= PAGE_CACHE_SIZE);
+
+ if (ispersistent &&
+ ((res->lnb_file_offset >> PAGE_CACHE_SHIFT) <
+ ECHO_PERSISTENT_PAGES)) {
+ res->lnb_page =
+ echo_persistent_pages[res->lnb_file_offset >>
+ PAGE_CACHE_SHIFT];
+ /* Take extra ref so __free_pages() can be called OK */
+ get_page(res->lnb_page);
+ } else {
+ OBD_PAGE_ALLOC(res->lnb_page, gfp_mask);
+ if (res->lnb_page == NULL) {
+ CERROR("can't get page for id " DOSTID"\n",
+ POSTID(&obj->ioo_oid));
+ return -ENOMEM;
+ }
+ }
+
+ CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
+ res->lnb_page, res->lnb_file_offset, res->lnb_len);
+
+ if (cmd & OBD_BRW_READ)
+ res->lnb_rc = res->lnb_len;
+
+ if (debug_setup)
+ echo_page_debug_setup(res->lnb_page, cmd,
+ ostid_id(&obj->ioo_oid),
+ res->lnb_file_offset,
+ res->lnb_len);
+
+ offset += plen;
+ len -= plen;
+ res++;
+
+ (*left)--;
+ (*pages)++;
+ }
+
+ return 0;
+}
+
+static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
+ struct niobuf_remote *rb, int *pgs,
+ struct niobuf_local *lb, int verify)
+{
+ struct niobuf_local *res = lb;
+ obd_off start = rb->offset >> PAGE_CACHE_SHIFT;
+ obd_off end = (rb->offset + rb->len + PAGE_CACHE_SIZE - 1) >>
+ PAGE_CACHE_SHIFT;
+ int count = (int)(end - start);
+ int rc = 0;
+ int i;
+
+ for (i = 0; i < count; i++, (*pgs) ++, res++) {
+ struct page *page = res->lnb_page;
+ void *addr;
+
+ if (page == NULL) {
+ CERROR("null page objid "LPU64":%p, buf %d/%d\n",
+ ostid_id(&obj->ioo_oid), page, i,
+ obj->ioo_bufcnt);
+ return -EFAULT;
+ }
+
+ addr = kmap(page);
+
+ CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
+ res->lnb_page, addr, res->lnb_file_offset);
+
+ if (verify) {
+ int vrc = echo_page_debug_check(page,
+ ostid_id(&obj->ioo_oid),
+ res->lnb_file_offset,
+ res->lnb_len);
+ /* check all the pages always */
+ if (vrc != 0 && rc == 0)
+ rc = vrc;
+ }
+
+ kunmap(page);
+ /* NB see comment above regarding persistent pages */
+ OBD_PAGE_FREE(page);
+ }
+
+ return rc;
+}
+
+static int echo_preprw(const struct lu_env *env, int cmd,
+ struct obd_export *export, struct obdo *oa,
+ int objcount, struct obd_ioobj *obj,
+ struct niobuf_remote *nb, int *pages,
+ struct niobuf_local *res, struct obd_trans_info *oti,
+ struct lustre_capa *unused)