+}
+
+static int xsegbd_mapclose(struct xsegbd_device *xsegbd_dev)
+{
+ struct xseg_request *xreq;
+ char *target;
+ xqindex blkreq_idx;
+ struct xsegbd_pending *pending;
+ struct completion comp;
+ xport p;
+ int ret = -EBUSY;
+
+ xreq = xseg_get_request(xsegbd_dev->xseg, xsegbd_dev->src_portno,
+ xsegbd_dev->dst_portno, X_ALLOC);
+ if (!xreq)
+ goto out;
+
+ BUG_ON(xseg_prep_request(xsegbd_dev->xseg, xreq, xsegbd_dev->targetlen, 0));
+
+ init_completion(&comp);
+ blkreq_idx = xq_pop_head(&xsegbd_dev->blk_queue_pending, 1);
+ if (blkreq_idx == Noneidx)
+ goto out_put;
+
+ pending = &xsegbd_dev->blk_req_pending[blkreq_idx];
+ pending->dev = xsegbd_dev;
+ pending->request = NULL;
+ pending->comp = ∁
+
+
+ xreq->priv = (uint64_t) blkreq_idx;
+
+ target = xseg_get_target(xsegbd_dev->xseg, xreq);
+ strncpy(target, xsegbd_dev->target, xsegbd_dev->targetlen);
+ xreq->size = xreq->datalen;
+ xreq->offset = 0;
+ xreq->op = X_CLOSE;
+
+ xseg_prepare_wait(xsegbd_dev->xseg, xsegbd_dev->src_portno);
+ p = xseg_submit(xsegbd_dev->xseg, xreq,
+ xsegbd_dev->src_portno, X_ALLOC);
+ if ( p == NoPort) {
+ XSEGLOG("couldn't submit request");
+ BUG_ON(1);
+ goto out_queue;
+ }
+ WARN_ON(xseg_signal(xsegbd_dev->xseg, p) < 0);
+ wait_for_completion_interruptible(&comp);
+ ret = 0;
+ if (xreq->state & XS_FAILED)
+ XSEGLOG("Couldn't close disk on mapper");