|
@@ -1766,3 +1766,104 @@ end_io:
|
|
|
|
|
|
/**
|
|
|
* generic_make_request - hand a buffer to its device driver for I/O
|
|
|
+ * @bio: The bio describing the location in memory and on the device.
|
|
|
+ *
|
|
|
+ * generic_make_request() is used to make I/O requests of block
|
|
|
+ * devices. It is passed a &struct bio, which describes the I/O that needs
|
|
|
+ * to be done.
|
|
|
+ *
|
|
|
+ * generic_make_request() does not return any status. The
|
|
|
+ * success/failure status of the request, along with notification of
|
|
|
+ * completion, is delivered asynchronously through the bio->bi_end_io
|
|
|
+ * function described (one day) else where.
|
|
|
+ *
|
|
|
+ * The caller of generic_make_request must make sure that bi_io_vec
|
|
|
+ * are set to describe the memory buffer, and that bi_dev and bi_sector are
|
|
|
+ * set to describe the device address, and the
|
|
|
+ * bi_end_io and optionally bi_private are set to describe how
|
|
|
+ * completion notification should be signaled.
|
|
|
+ *
|
|
|
+ * generic_make_request and the drivers it calls may use bi_next if this
|
|
|
+ * bio happens to be merged with someone else, and may resubmit the bio to
|
|
|
+ * a lower device by calling into generic_make_request recursively, which
|
|
|
+ * means the bio should NOT be touched after the call to ->make_request_fn.
|
|
|
+ */
|
|
|
+void generic_make_request(struct bio *bio)
|
|
|
+{
|
|
|
+ struct bio_list bio_list_on_stack;
|
|
|
+
|
|
|
+ if (!generic_make_request_checks(bio))
|
|
|
+ return;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * We only want one ->make_request_fn to be active at a time, else
|
|
|
+ * stack usage with stacked devices could be a problem. So use
|
|
|
+ * current->bio_list to keep a list of requests submited by a
|
|
|
+ * make_request_fn function. current->bio_list is also used as a
|
|
|
+ * flag to say if generic_make_request is currently active in this
|
|
|
+ * task or not. If it is NULL, then no make_request is active. If
|
|
|
+ * it is non-NULL, then a make_request is active, and new requests
|
|
|
+ * should be added at the tail
|
|
|
+ */
|
|
|
+ if (current->bio_list) {
|
|
|
+ bio_list_add(current->bio_list, bio);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* following loop may be a bit non-obvious, and so deserves some
|
|
|
+ * explanation.
|
|
|
+ * Before entering the loop, bio->bi_next is NULL (as all callers
|
|
|
+ * ensure that) so we have a list with a single bio.
|
|
|
+ * We pretend that we have just taken it off a longer list, so
|
|
|
+ * we assign bio_list to a pointer to the bio_list_on_stack,
|
|
|
+ * thus initialising the bio_list of new bios to be
|
|
|
+ * added. ->make_request() may indeed add some more bios
|
|
|
+ * through a recursive call to generic_make_request. If it
|
|
|
+ * did, we find a non-NULL value in bio_list and re-enter the loop
|
|
|
+ * from the top. In this case we really did just take the bio
|
|
|
+ * of the top of the list (no pretending) and so remove it from
|
|
|
+ * bio_list, and call into ->make_request() again.
|
|
|
+ */
|
|
|
+ BUG_ON(bio->bi_next);
|
|
|
+ bio_list_init(&bio_list_on_stack);
|
|
|
+ current->bio_list = &bio_list_on_stack;
|
|
|
+ do {
|
|
|
+ struct request_queue *q = bdev_get_queue(bio->bi_bdev);
|
|
|
+
|
|
|
+ q->make_request_fn(q, bio);
|
|
|
+
|
|
|
+ bio = bio_list_pop(current->bio_list);
|
|
|
+ } while (bio);
|
|
|
+ current->bio_list = NULL; /* deactivate */
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(generic_make_request);
|
|
|
+
|
|
|
+/**
|
|
|
+ * submit_bio - submit a bio to the block device layer for I/O
|
|
|
+ * @rw: whether to %READ or %WRITE, or maybe to %READA (read ahead)
|
|
|
+ * @bio: The &struct bio which describes the I/O
|
|
|
+ *
|
|
|
+ * submit_bio() is very similar in purpose to generic_make_request(), and
|
|
|
+ * uses that function to do most of the work. Both are fairly rough
|
|
|
+ * interfaces; @bio must be presetup and ready for I/O.
|
|
|
+ *
|
|
|
+ */
|
|
|
+void submit_bio(int rw, struct bio *bio)
|
|
|
+{
|
|
|
+ bio->bi_rw |= rw;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * If it's a regular read/write or a barrier with data attached,
|
|
|
+ * go through the normal accounting stuff before submission.
|
|
|
+ */
|
|
|
+ if (bio_has_data(bio)) {
|
|
|
+ unsigned int count;
|
|
|
+
|
|
|
+ if (unlikely(rw & REQ_WRITE_SAME))
|
|
|
+ count = bdev_logical_block_size(bio->bi_bdev) >> 9;
|
|
|
+ else
|
|
|
+ count = bio_sectors(bio);
|
|
|
+
|
|
|
+ if (rw & WRITE) {
|
|
|
+ count_vm_events(PGPGOUT, count);
|
|
|
+ } else {
|