===================================================================
@@ -122,6 +122,34 @@ void blk_set_default_limits(struct queue
EXPORT_SYMBOL(blk_set_default_limits);
/**
+ * blk_queue_copy_limits - copy limits to queue
+ * @q: the request queue whose limits as a copy destination
+ * @lim: the queue_limits structure as a copy source
+ *
+ * Description:
+ * Copies a queue_limit struct contents to @q with fix-ups to
+ * invalid values.
+ */
+void blk_queue_copy_limits(struct request_queue *q, struct queue_limits *lim)
+{
+ q->limits = *lim;
+
+ /*
+ * blk_set_default_limits() sets max_sectors/max_hw_sectors to 0
+ * so that blk_stack_limits() appropriately propagate the values
+ * of lower-stack by min_not_zero().
+ * However, if the default value 0 is unchanged (e.g. the stacking
+ * device is virtual and has no underlying device), it results
+ * in unusable device.
+ * Check if max_sectors/max_hw_sectors have non-zero values,
+ * and set SAFE_MAX_SECTORS if they do.
+ */
+ if (q->limits.max_sectors == 0 || q->limits.max_hw_sectors == 0)
+ blk_queue_max_sectors(q, SAFE_MAX_SECTORS);
+}
+EXPORT_SYMBOL(blk_queue_copy_limits);
+
+/**
* blk_queue_make_request - define an alternate make_request function for a device
* @q: the request queue for the device to be affected
* @mfn: the alternate make_request function
===================================================================
@@ -917,6 +917,7 @@ extern void blk_limits_io_min(struct que
extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
extern void blk_set_default_limits(struct queue_limits *lim);
+extern void blk_queue_copy_limits(struct request_queue *q, struct queue_limits *lim);
extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
sector_t offset);
extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,