diff options
| author | Matthew Wilcox <willy@infradead.org> | 2018-10-30 09:45:55 -0400 |
|---|---|---|
| committer | Matthew Wilcox <willy@infradead.org> | 2018-11-05 16:38:08 -0500 |
| commit | 4c0608f4a0e76dfb82d3accd20081f4bf47ed143 (patch) | |
| tree | 54a22dbdebdd23830ea5c9f88c78cdc8567f2fef /include/linux/xarray.h | |
| parent | fe2b51145c9ffd5a49013fe180e42e92ef0e6df9 (diff) | |
XArray: Regularise xa_reserve
The xa_reserve() function was a little unusual in that it attempted to
be callable for all kinds of locking scenarios. Make it look like the
other APIs with __xa_reserve, xa_reserve_bh and xa_reserve_irq variants.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'include/linux/xarray.h')
| -rw-r--r-- | include/linux/xarray.h | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/include/linux/xarray.h b/include/linux/xarray.h index d9514928ddac..c2cb0426c60c 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h | |||
| @@ -291,7 +291,6 @@ void *xa_load(struct xarray *, unsigned long index); | |||
| 291 | void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); | 291 | void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); |
| 292 | void *xa_cmpxchg(struct xarray *, unsigned long index, | 292 | void *xa_cmpxchg(struct xarray *, unsigned long index, |
| 293 | void *old, void *entry, gfp_t); | 293 | void *old, void *entry, gfp_t); |
| 294 | int xa_reserve(struct xarray *, unsigned long index, gfp_t); | ||
| 295 | void *xa_store_range(struct xarray *, unsigned long first, unsigned long last, | 294 | void *xa_store_range(struct xarray *, unsigned long first, unsigned long last, |
| 296 | void *entry, gfp_t); | 295 | void *entry, gfp_t); |
| 297 | bool xa_get_mark(struct xarray *, unsigned long index, xa_mark_t); | 296 | bool xa_get_mark(struct xarray *, unsigned long index, xa_mark_t); |
| @@ -455,6 +454,7 @@ void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); | |||
| 455 | void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old, | 454 | void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old, |
| 456 | void *entry, gfp_t); | 455 | void *entry, gfp_t); |
| 457 | int __xa_alloc(struct xarray *, u32 *id, u32 max, void *entry, gfp_t); | 456 | int __xa_alloc(struct xarray *, u32 *id, u32 max, void *entry, gfp_t); |
| 457 | int __xa_reserve(struct xarray *, unsigned long index, gfp_t); | ||
| 458 | void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t); | 458 | void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t); |
| 459 | void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t); | 459 | void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t); |
| 460 | 460 | ||
| @@ -621,6 +621,84 @@ static inline int xa_alloc_irq(struct xarray *xa, u32 *id, u32 max, void *entry, | |||
| 621 | return err; | 621 | return err; |
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | /** | ||
| 625 | * xa_reserve() - Reserve this index in the XArray. | ||
| 626 | * @xa: XArray. | ||
| 627 | * @index: Index into array. | ||
| 628 | * @gfp: Memory allocation flags. | ||
| 629 | * | ||
| 630 | * Ensures there is somewhere to store an entry at @index in the array. | ||
| 631 | * If there is already something stored at @index, this function does | ||
| 632 | * nothing. If there was nothing there, the entry is marked as reserved. | ||
| 633 | * Loading from a reserved entry returns a %NULL pointer. | ||
| 634 | * | ||
| 635 | * If you do not use the entry that you have reserved, call xa_release() | ||
| 636 | * or xa_erase() to free any unnecessary memory. | ||
| 637 | * | ||
| 638 | * Context: Any context. Takes and releases the xa_lock. | ||
| 639 | * May sleep if the @gfp flags permit. | ||
| 640 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | ||
| 641 | */ | ||
| 642 | static inline | ||
| 643 | int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) | ||
| 644 | { | ||
| 645 | int ret; | ||
| 646 | |||
| 647 | xa_lock(xa); | ||
| 648 | ret = __xa_reserve(xa, index, gfp); | ||
| 649 | xa_unlock(xa); | ||
| 650 | |||
| 651 | return ret; | ||
| 652 | } | ||
| 653 | |||
| 654 | /** | ||
| 655 | * xa_reserve_bh() - Reserve this index in the XArray. | ||
| 656 | * @xa: XArray. | ||
| 657 | * @index: Index into array. | ||
| 658 | * @gfp: Memory allocation flags. | ||
| 659 | * | ||
| 660 | * A softirq-disabling version of xa_reserve(). | ||
| 661 | * | ||
| 662 | * Context: Any context. Takes and releases the xa_lock while | ||
| 663 | * disabling softirqs. | ||
| 664 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | ||
| 665 | */ | ||
| 666 | static inline | ||
| 667 | int xa_reserve_bh(struct xarray *xa, unsigned long index, gfp_t gfp) | ||
| 668 | { | ||
| 669 | int ret; | ||
| 670 | |||
| 671 | xa_lock_bh(xa); | ||
| 672 | ret = __xa_reserve(xa, index, gfp); | ||
| 673 | xa_unlock_bh(xa); | ||
| 674 | |||
| 675 | return ret; | ||
| 676 | } | ||
| 677 | |||
| 678 | /** | ||
| 679 | * xa_reserve_irq() - Reserve this index in the XArray. | ||
| 680 | * @xa: XArray. | ||
| 681 | * @index: Index into array. | ||
| 682 | * @gfp: Memory allocation flags. | ||
| 683 | * | ||
| 684 | * An interrupt-disabling version of xa_reserve(). | ||
| 685 | * | ||
| 686 | * Context: Process context. Takes and releases the xa_lock while | ||
| 687 | * disabling interrupts. | ||
| 688 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | ||
| 689 | */ | ||
| 690 | static inline | ||
| 691 | int xa_reserve_irq(struct xarray *xa, unsigned long index, gfp_t gfp) | ||
| 692 | { | ||
| 693 | int ret; | ||
| 694 | |||
| 695 | xa_lock_irq(xa); | ||
| 696 | ret = __xa_reserve(xa, index, gfp); | ||
| 697 | xa_unlock_irq(xa); | ||
| 698 | |||
| 699 | return ret; | ||
| 700 | } | ||
| 701 | |||
| 624 | /* Everything below here is the Advanced API. Proceed with caution. */ | 702 | /* Everything below here is the Advanced API. Proceed with caution. */ |
| 625 | 703 | ||
| 626 | /* | 704 | /* |
