hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/block/aoe/aoeblk.c
....@@ -6,7 +6,7 @@
66
77 #include <linux/kernel.h>
88 #include <linux/hdreg.h>
9
-#include <linux/blkdev.h>
9
+#include <linux/blk-mq.h>
1010 #include <linux/backing-dev.h>
1111 #include <linux/fs.h>
1212 #include <linux/ioctl.h>
....@@ -87,9 +87,9 @@
8787 if (*nd == NULL)
8888 return snprintf(page, PAGE_SIZE, "none\n");
8989 for (p = page; nd < ne; nd++)
90
- p += snprintf(p, PAGE_SIZE - (p-page), "%s%s",
90
+ p += scnprintf(p, PAGE_SIZE - (p-page), "%s%s",
9191 p == page ? "" : ",", (*nd)->name);
92
- p += snprintf(p, PAGE_SIZE - (p-page), "\n");
92
+ p += scnprintf(p, PAGE_SIZE - (p-page), "\n");
9393 return p-page;
9494 }
9595 /* firmware version */
....@@ -177,8 +177,13 @@
177177 NULL,
178178 };
179179
180
-static const struct attribute_group attr_group = {
180
+static const struct attribute_group aoe_attr_group = {
181181 .attrs = aoe_attrs,
182
+};
183
+
184
+static const struct attribute_group *aoe_attr_groups[] = {
185
+ &aoe_attr_group,
186
+ NULL,
182187 };
183188
184189 static const struct file_operations aoe_debugfs_fops = {
....@@ -191,7 +196,6 @@
191196 static void
192197 aoedisk_add_debugfs(struct aoedev *d)
193198 {
194
- struct dentry *entry;
195199 char *p;
196200
197201 if (aoe_debugfs_dir == NULL)
....@@ -202,32 +206,14 @@
202206 else
203207 p++;
204208 BUG_ON(*p == '\0');
205
- entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
206
- &aoe_debugfs_fops);
207
- if (IS_ERR_OR_NULL(entry)) {
208
- pr_info("aoe: cannot create debugfs file for %s\n",
209
- d->gd->disk_name);
210
- return;
211
- }
212
- BUG_ON(d->debugfs);
213
- d->debugfs = entry;
209
+ d->debugfs = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
210
+ &aoe_debugfs_fops);
214211 }
215212 void
216213 aoedisk_rm_debugfs(struct aoedev *d)
217214 {
218215 debugfs_remove(d->debugfs);
219216 d->debugfs = NULL;
220
-}
221
-
222
-static int
223
-aoedisk_add_sysfs(struct aoedev *d)
224
-{
225
- return sysfs_create_group(&disk_to_dev(d->gd)->kobj, &attr_group);
226
-}
227
-void
228
-aoedisk_rm_sysfs(struct aoedev *d)
229
-{
230
- sysfs_remove_group(&disk_to_dev(d->gd)->kobj, &attr_group);
231217 }
232218
233219 static int
....@@ -274,23 +260,25 @@
274260 spin_unlock_irqrestore(&d->lock, flags);
275261 }
276262
277
-static void
278
-aoeblk_request(struct request_queue *q)
263
+static blk_status_t aoeblk_queue_rq(struct blk_mq_hw_ctx *hctx,
264
+ const struct blk_mq_queue_data *bd)
279265 {
280
- struct aoedev *d;
281
- struct request *rq;
266
+ struct aoedev *d = hctx->queue->queuedata;
282267
283
- d = q->queuedata;
268
+ spin_lock_irq(&d->lock);
269
+
284270 if ((d->flags & DEVFL_UP) == 0) {
285271 pr_info_ratelimited("aoe: device %ld.%d is not up\n",
286272 d->aoemajor, d->aoeminor);
287
- while ((rq = blk_peek_request(q))) {
288
- blk_start_request(rq);
289
- aoe_end_request(d, rq, 1);
290
- }
291
- return;
273
+ spin_unlock_irq(&d->lock);
274
+ blk_mq_start_request(bd->rq);
275
+ return BLK_STS_IOERR;
292276 }
277
+
278
+ list_add_tail(&bd->rq->queuelist, &d->rq_list);
293279 aoecmd_work(d);
280
+ spin_unlock_irq(&d->lock);
281
+ return BLK_STS_OK;
294282 }
295283
296284 static int
....@@ -341,8 +329,13 @@
341329 .open = aoeblk_open,
342330 .release = aoeblk_release,
343331 .ioctl = aoeblk_ioctl,
332
+ .compat_ioctl = blkdev_compat_ptr_ioctl,
344333 .getgeo = aoeblk_getgeo,
345334 .owner = THIS_MODULE,
335
+};
336
+
337
+static const struct blk_mq_ops aoeblk_mq_ops = {
338
+ .queue_rq = aoeblk_queue_rq,
346339 };
347340
348341 /* alloc_disk and add_disk can sleep */
....@@ -353,9 +346,10 @@
353346 struct gendisk *gd;
354347 mempool_t *mp;
355348 struct request_queue *q;
356
- enum { KB = 1024, MB = KB * KB, READ_AHEAD = 2 * MB, };
349
+ struct blk_mq_tag_set *set;
357350 ulong flags;
358351 int late = 0;
352
+ int err;
359353
360354 spin_lock_irqsave(&d->lock, flags);
361355 if (d->flags & DEVFL_GDALLOC
....@@ -382,10 +376,26 @@
382376 d->aoemajor, d->aoeminor);
383377 goto err_disk;
384378 }
385
- q = blk_init_queue(aoeblk_request, &d->lock);
386
- if (q == NULL) {
379
+
380
+ set = &d->tag_set;
381
+ set->ops = &aoeblk_mq_ops;
382
+ set->cmd_size = sizeof(struct aoe_req);
383
+ set->nr_hw_queues = 1;
384
+ set->queue_depth = 128;
385
+ set->numa_node = NUMA_NO_NODE;
386
+ set->flags = BLK_MQ_F_SHOULD_MERGE;
387
+ err = blk_mq_alloc_tag_set(set);
388
+ if (err) {
389
+ pr_err("aoe: cannot allocate tag set for %ld.%d\n",
390
+ d->aoemajor, d->aoeminor);
391
+ goto err_mempool;
392
+ }
393
+
394
+ q = blk_mq_init_queue(set);
395
+ if (IS_ERR(q)) {
387396 pr_err("aoe: cannot allocate block queue for %ld.%d\n",
388397 d->aoemajor, d->aoeminor);
398
+ blk_mq_free_tag_set(set);
389399 goto err_mempool;
390400 }
391401
....@@ -396,8 +406,7 @@
396406 WARN_ON(d->gd);
397407 WARN_ON(d->flags & DEVFL_UP);
398408 blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
399
- q->backing_dev_info->name = "aoe";
400
- q->backing_dev_info->ra_pages = READ_AHEAD / PAGE_SIZE;
409
+ blk_queue_io_opt(q, SZ_2M);
401410 d->bufpool = mp;
402411 d->blkq = gd->queue = q;
403412 q->queuedata = d;
....@@ -417,8 +426,7 @@
417426
418427 spin_unlock_irqrestore(&d->lock, flags);
419428
420
- add_disk(gd);
421
- aoedisk_add_sysfs(d);
429
+ device_add_disk(NULL, gd, aoe_attr_groups);
422430 aoedisk_add_debugfs(d);
423431
424432 spin_lock_irqsave(&d->lock, flags);
....@@ -455,10 +463,6 @@
455463 if (buf_pool_cache == NULL)
456464 return -ENOMEM;
457465 aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
458
- if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
459
- pr_info("aoe: cannot create debugfs directory\n");
460
- aoe_debugfs_dir = NULL;
461
- }
462466 return 0;
463467 }
464468