+/**
+ * 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;
+}
+