4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (C) 2008-2010 Lawrence Livermore National Security, LLC.
23 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
24 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
33 #include <linux/blkdev.h>
34 #include <linux/elevator.h>
37 typedef unsigned __bitwise__ fmode_t;
38 #endif /* HAVE_FMODE_T */
40 #ifndef HAVE_BLK_FETCH_REQUEST
41 static inline struct request *
42 blk_fetch_request(struct request_queue *q)
46 req = elv_next_request(q);
48 blkdev_dequeue_request(req);
52 #endif /* HAVE_BLK_FETCH_REQUEST */
54 #ifndef HAVE_BLK_REQUEUE_REQUEST
56 blk_requeue_request(request_queue_t *q, struct request *req)
58 elv_requeue_request(q, req);
60 #endif /* HAVE_BLK_REQUEUE_REQUEST */
62 #ifndef HAVE_BLK_END_REQUEST
64 __blk_end_request(struct request *req, int error, unsigned int nr_bytes)
69 * Request has already been dequeued but 2.6.18 version of
70 * end_request() unconditionally dequeues the request so we
71 * add it to a local list to prevent hitting the BUG_ON.
73 list_add(&req->queuelist, &list);
76 * The old API required the driver to end each segment and not
77 * the entire request. In our case we always need to end the
78 * entire request partial requests are not supported.
80 req->hard_cur_sectors = nr_bytes >> 9;
81 end_request(req, ((error == 0) ? 1 : error));
87 blk_end_request(struct request *req, int error, unsigned int nr_bytes)
89 struct request_queue *q = req->q;
92 spin_lock_irq(q->queue_lock);
93 rc = __blk_end_request(req, error, nr_bytes);
94 spin_unlock_irq(q->queue_lock);
99 # ifdef HAVE_BLK_END_REQUEST_GPL_ONLY
101 * Define required to avoid conflicting 2.6.29 non-static prototype for a
102 * GPL-only version of the helper. As of 2.6.31 the helper is available
103 * to non-GPL modules and is not explicitly exported GPL-only.
105 # define __blk_end_request __blk_end_request_x
106 # define blk_end_request blk_end_request_x
109 __blk_end_request_x(struct request *req, int error, unsigned int nr_bytes)
112 * The old API required the driver to end each segment and not
113 * the entire request. In our case we always need to end the
114 * entire request partial requests are not supported.
116 req->hard_cur_sectors = nr_bytes >> 9;
117 end_request(req, ((error == 0) ? 1 : error));
122 blk_end_request_x(struct request *req, int error, unsigned int nr_bytes)
124 struct request_queue *q = req->q;
127 spin_lock_irq(q->queue_lock);
128 rc = __blk_end_request_x(req, error, nr_bytes);
129 spin_unlock_irq(q->queue_lock);
133 # endif /* HAVE_BLK_END_REQUEST_GPL_ONLY */
134 #endif /* HAVE_BLK_END_REQUEST */
136 #ifndef HAVE_BLK_RQ_POS
137 static inline sector_t
138 blk_rq_pos(struct request *req)
142 #endif /* HAVE_BLK_RQ_POS */
144 #ifndef HAVE_BLK_RQ_SECTORS
145 static inline unsigned int
146 blk_rq_sectors(struct request *req)
148 return req->nr_sectors;
150 #endif /* HAVE_BLK_RQ_SECTORS */
152 #if !defined(HAVE_BLK_RQ_BYTES) || defined(HAVE_BLK_RQ_BYTES_GPL_ONLY)
154 * Define required to avoid conflicting 2.6.29 non-static prototype for a
155 * GPL-only version of the helper. As of 2.6.31 the helper is available
156 * to non-GPL modules in the form of a static inline in the header.
158 #define blk_rq_bytes __blk_rq_bytes
159 static inline unsigned int
160 __blk_rq_bytes(struct request *req)
162 return blk_rq_sectors(req) << 9;
164 #endif /* !HAVE_BLK_RQ_BYTES || HAVE_BLK_RQ_BYTES_GPL_ONLY */
167 * Most of the blk_* macros were removed in 2.6.36. Ostensibly this was
168 * done to improve readability and allow easier grepping. However, from
169 * a portability stand point the macros are helpful. Therefore the needed
170 * macros are redefined here if they are missing from the kernel.
172 #ifndef blk_fs_request
173 #define blk_fs_request(rq) ((rq)->cmd_type == REQ_TYPE_FS)
176 #ifndef HAVE_GET_DISK_RO
178 get_disk_ro(struct gendisk *disk)
183 policy = disk->part[0]->policy;
187 #endif /* HAVE_GET_DISK_RO */
189 #ifndef HAVE_RQ_IS_SYNC
191 rq_is_sync(struct request *req)
193 return (req->flags & REQ_RW_SYNC);
195 #endif /* HAVE_RQ_IS_SYNC */
197 #ifndef HAVE_RQ_FOR_EACH_SEGMENT
198 struct req_iterator {
203 # define for_each_bio(_bio) \
204 for (; _bio; _bio = _bio->bi_next)
206 # define __rq_for_each_bio(_bio, rq) \
208 for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
210 # define rq_for_each_segment(bvl, _rq, _iter) \
211 __rq_for_each_bio(_iter.bio, _rq) \
212 bio_for_each_segment(bvl, _iter.bio, _iter.i)
213 #endif /* HAVE_RQ_FOR_EACH_SEGMENT */
216 bio_set_flags_failfast(struct block_device *bdev, int *flags)
220 * Disable FAILFAST for loopback devices because of the
221 * following incorrect BUG_ON() in loop_make_request().
222 * This support is also disabled for md devices because the
223 * test suite layers md devices on top of loopback devices.
224 * This may be removed when the loopback driver is fixed.
226 * BUG_ON(!lo || (rw != READ && rw != WRITE));
228 if ((MAJOR(bdev->bd_dev) == LOOP_MAJOR) ||
229 (MAJOR(bdev->bd_dev) == MD_MAJOR))
232 #ifdef BLOCK_EXT_MAJOR
233 if (MAJOR(bdev->bd_dev) == BLOCK_EXT_MAJOR)
235 #endif /* BLOCK_EXT_MAJOR */
236 #endif /* CONFIG_BUG */
238 #ifdef HAVE_BIO_RW_FAILFAST_DTD
239 /* BIO_RW_FAILFAST_* preferred interface from 2.6.28 - 2.6.35 */
241 ((1 << BIO_RW_FAILFAST_DEV) |
242 (1 << BIO_RW_FAILFAST_TRANSPORT) |
243 (1 << BIO_RW_FAILFAST_DRIVER));
245 # ifdef HAVE_BIO_RW_FAILFAST
246 /* BIO_RW_FAILFAST preferred interface from 2.6.12 - 2.6.27 */
247 *flags |= (1 << BIO_RW_FAILFAST);
249 # ifdef HAVE_REQ_FAILFAST_MASK
250 /* REQ_FAILFAST_* preferred interface from 2.6.36 - 2.6.xx,
251 * the BIO_* and REQ_* flags were unified under REQ_* flags. */
252 *flags |= REQ_FAILFAST_MASK;
253 # endif /* HAVE_REQ_FAILFAST_MASK */
254 # endif /* HAVE_BIO_RW_FAILFAST */
255 #endif /* HAVE_BIO_RW_FAILFAST_DTD */
258 #ifndef DISK_NAME_LEN
259 #define DISK_NAME_LEN 32
260 #endif /* DISK_NAME_LEN */
264 #endif /* _SYS_BLKDEV_H */