#define CEPH_HOMELESS_OSD      -1
 
+/*
+ * A single extent in a SPARSE_READ reply.
+ *
+ * Note that these come from the OSD as little-endian values. On BE arches,
+ * we convert them in-place after receipt.
+ */
+struct ceph_sparse_extent {
+       u64     off;
+       u64     len;
+} __packed;
+
 /*
  * A given osd we're communicating with.
  *
                        u64 offset, length;
                        u64 truncate_size;
                        u32 truncate_seq;
+                       int sparse_ext_cnt;
+                       struct ceph_sparse_extent *sparse_ext;
                        struct ceph_osd_data osd_data;
                } extent;
                struct {
                                      u32 truncate_seq, u64 truncate_size,
                                      bool use_mempool);
 
+int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt);
+
+/*
+ * How big an extent array should we preallocate for a sparse read? This is
+ * just a starting value.  If we get more than this back from the OSD, the
+ * receiver will reallocate.
+ */
+#define CEPH_SPARSE_EXT_ARRAY_INITIAL  16
+
+static inline int ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op)
+{
+       return __ceph_alloc_sparse_ext_map(op, CEPH_SPARSE_EXT_ARRAY_INITIAL);
+}
+
 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
 
                            struct ceph_object_locator *oloc,
                            struct ceph_watch_item **watchers,
                            u32 *num_watchers);
-#endif
 
+/* Find offset into the buffer of the end of the extent map */
+static inline u64 ceph_sparse_ext_map_end(struct ceph_osd_req_op *op)
+{
+       struct ceph_sparse_extent *ext;
+
+       /* No extents? No data */
+       if (op->extent.sparse_ext_cnt == 0)
+               return 0;
+
+       ext = &op->extent.sparse_ext[op->extent.sparse_ext_cnt - 1];
+
+       return ext->off + ext->len - op->extent.offset;
+}
+
+#endif
 
        case CEPH_OSD_OP_READ:
        case CEPH_OSD_OP_WRITE:
        case CEPH_OSD_OP_WRITEFULL:
+               kfree(op->extent.sparse_ext);
                ceph_osd_data_release(&op->extent.osd_data);
                break;
        case CEPH_OSD_OP_CALL:
 }
 EXPORT_SYMBOL(ceph_osdc_new_request);
 
+int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt)
+{
+       op->extent.sparse_ext_cnt = cnt;
+       op->extent.sparse_ext = kmalloc_array(cnt,
+                                             sizeof(*op->extent.sparse_ext),
+                                             GFP_NOFS);
+       if (!op->extent.sparse_ext)
+               return -ENOMEM;
+       return 0;
+}
+EXPORT_SYMBOL(__ceph_alloc_sparse_ext_map);
+
 /*
  * We keep osd requests in an rbtree, sorted by ->r_tid.
  */