hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/md/dm-stripe.c
....@@ -41,7 +41,7 @@
4141 /* Work struct used for triggering events*/
4242 struct work_struct trigger_event;
4343
44
- struct stripe stripe[0];
44
+ struct stripe stripe[];
4545 };
4646
4747 /*
....@@ -53,19 +53,6 @@
5353 struct stripe_c *sc = container_of(work, struct stripe_c,
5454 trigger_event);
5555 dm_table_event(sc->ti->table);
56
-}
57
-
58
-static inline struct stripe_c *alloc_context(unsigned int stripes)
59
-{
60
- size_t len;
61
-
62
- if (dm_array_too_big(sizeof(struct stripe_c), sizeof(struct stripe),
63
- stripes))
64
- return NULL;
65
-
66
- len = sizeof(struct stripe_c) + (sizeof(struct stripe) * stripes);
67
-
68
- return kmalloc(len, GFP_KERNEL);
6956 }
7057
7158 /*
....@@ -142,7 +129,7 @@
142129 return -EINVAL;
143130 }
144131
145
- sc = alloc_context(stripes);
132
+ sc = kmalloc(struct_size(sc, stripe, stripes), GFP_KERNEL);
146133 if (!sc) {
147134 ti->error = "Memory allocation for striped context "
148135 "failed";
....@@ -373,10 +360,32 @@
373360 return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
374361 }
375362
363
+static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
364
+ size_t nr_pages)
365
+{
366
+ int ret;
367
+ sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
368
+ struct stripe_c *sc = ti->private;
369
+ struct dax_device *dax_dev;
370
+ struct block_device *bdev;
371
+ uint32_t stripe;
372
+
373
+ stripe_map_sector(sc, sector, &stripe, &dev_sector);
374
+ dev_sector += sc->stripe[stripe].physical_start;
375
+ dax_dev = sc->stripe[stripe].dev->dax_dev;
376
+ bdev = sc->stripe[stripe].dev->bdev;
377
+
378
+ ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages << PAGE_SHIFT, &pgoff);
379
+ if (ret)
380
+ return ret;
381
+ return dax_zero_page_range(dax_dev, pgoff, nr_pages);
382
+}
383
+
376384 #else
377385 #define stripe_dax_direct_access NULL
378386 #define stripe_dax_copy_from_iter NULL
379387 #define stripe_dax_copy_to_iter NULL
388
+#define stripe_dax_zero_page_range NULL
380389 #endif
381390
382391 /*
....@@ -499,6 +508,7 @@
499508 .direct_access = stripe_dax_direct_access,
500509 .dax_copy_from_iter = stripe_dax_copy_from_iter,
501510 .dax_copy_to_iter = stripe_dax_copy_to_iter,
511
+ .dax_zero_page_range = stripe_dax_zero_page_range,
502512 };
503513
504514 int __init dm_stripe_init(void)