| .. | .. |
|---|
| 41 | 41 | /* Work struct used for triggering events*/ |
|---|
| 42 | 42 | struct work_struct trigger_event; |
|---|
| 43 | 43 | |
|---|
| 44 | | - struct stripe stripe[0]; |
|---|
| 44 | + struct stripe stripe[]; |
|---|
| 45 | 45 | }; |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | /* |
|---|
| .. | .. |
|---|
| 53 | 53 | struct stripe_c *sc = container_of(work, struct stripe_c, |
|---|
| 54 | 54 | trigger_event); |
|---|
| 55 | 55 | 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); |
|---|
| 69 | 56 | } |
|---|
| 70 | 57 | |
|---|
| 71 | 58 | /* |
|---|
| .. | .. |
|---|
| 142 | 129 | return -EINVAL; |
|---|
| 143 | 130 | } |
|---|
| 144 | 131 | |
|---|
| 145 | | - sc = alloc_context(stripes); |
|---|
| 132 | + sc = kmalloc(struct_size(sc, stripe, stripes), GFP_KERNEL); |
|---|
| 146 | 133 | if (!sc) { |
|---|
| 147 | 134 | ti->error = "Memory allocation for striped context " |
|---|
| 148 | 135 | "failed"; |
|---|
| .. | .. |
|---|
| 373 | 360 | return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i); |
|---|
| 374 | 361 | } |
|---|
| 375 | 362 | |
|---|
| 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 | + |
|---|
| 376 | 384 | #else |
|---|
| 377 | 385 | #define stripe_dax_direct_access NULL |
|---|
| 378 | 386 | #define stripe_dax_copy_from_iter NULL |
|---|
| 379 | 387 | #define stripe_dax_copy_to_iter NULL |
|---|
| 388 | +#define stripe_dax_zero_page_range NULL |
|---|
| 380 | 389 | #endif |
|---|
| 381 | 390 | |
|---|
| 382 | 391 | /* |
|---|
| .. | .. |
|---|
| 499 | 508 | .direct_access = stripe_dax_direct_access, |
|---|
| 500 | 509 | .dax_copy_from_iter = stripe_dax_copy_from_iter, |
|---|
| 501 | 510 | .dax_copy_to_iter = stripe_dax_copy_to_iter, |
|---|
| 511 | + .dax_zero_page_range = stripe_dax_zero_page_range, |
|---|
| 502 | 512 | }; |
|---|
| 503 | 513 | |
|---|
| 504 | 514 | int __init dm_stripe_init(void) |
|---|