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 /lib | |
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 'lib')
-rw-r--r-- | lib/test_xarray.c | 6 | ||||
-rw-r--r-- | lib/xarray.c | 18 |
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 126127658b49..e5294b20b52f 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -373,6 +373,12 @@ static noinline void check_reserve(struct xarray *xa) | |||
373 | xa_erase_index(xa, 12345678); | 373 | xa_erase_index(xa, 12345678); |
374 | XA_BUG_ON(xa, !xa_empty(xa)); | 374 | XA_BUG_ON(xa, !xa_empty(xa)); |
375 | 375 | ||
376 | /* And so does xa_insert */ | ||
377 | xa_reserve(xa, 12345678, GFP_KERNEL); | ||
378 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != 0); | ||
379 | xa_erase_index(xa, 12345678); | ||
380 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
381 | |||
376 | /* Can iterate through a reserved entry */ | 382 | /* Can iterate through a reserved entry */ |
377 | xa_store_index(xa, 5, GFP_KERNEL); | 383 | xa_store_index(xa, 5, GFP_KERNEL); |
378 | xa_reserve(xa, 6, GFP_KERNEL); | 384 | xa_reserve(xa, 6, GFP_KERNEL); |
diff --git a/lib/xarray.c b/lib/xarray.c index e7be4e47c6a9..9cab8cfef8a8 100644 --- a/lib/xarray.c +++ b/lib/xarray.c | |||
@@ -1488,7 +1488,7 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index, | |||
1488 | EXPORT_SYMBOL(__xa_cmpxchg); | 1488 | EXPORT_SYMBOL(__xa_cmpxchg); |
1489 | 1489 | ||
1490 | /** | 1490 | /** |
1491 | * xa_reserve() - Reserve this index in the XArray. | 1491 | * __xa_reserve() - Reserve this index in the XArray. |
1492 | * @xa: XArray. | 1492 | * @xa: XArray. |
1493 | * @index: Index into array. | 1493 | * @index: Index into array. |
1494 | * @gfp: Memory allocation flags. | 1494 | * @gfp: Memory allocation flags. |
@@ -1496,33 +1496,29 @@ EXPORT_SYMBOL(__xa_cmpxchg); | |||
1496 | * Ensures there is somewhere to store an entry at @index in the array. | 1496 | * Ensures there is somewhere to store an entry at @index in the array. |
1497 | * If there is already something stored at @index, this function does | 1497 | * If there is already something stored at @index, this function does |
1498 | * nothing. If there was nothing there, the entry is marked as reserved. | 1498 | * nothing. If there was nothing there, the entry is marked as reserved. |
1499 | * Loads from @index will continue to see a %NULL pointer until a | 1499 | * Loading from a reserved entry returns a %NULL pointer. |
1500 | * subsequent store to @index. | ||
1501 | * | 1500 | * |
1502 | * If you do not use the entry that you have reserved, call xa_release() | 1501 | * If you do not use the entry that you have reserved, call xa_release() |
1503 | * or xa_erase() to free any unnecessary memory. | 1502 | * or xa_erase() to free any unnecessary memory. |
1504 | * | 1503 | * |
1505 | * Context: Process context. Takes and releases the xa_lock, IRQ or BH safe | 1504 | * Context: Any context. Expects the xa_lock to be held on entry. May |
1506 | * if specified in XArray flags. May sleep if the @gfp flags permit. | 1505 | * release the lock, sleep and reacquire the lock if the @gfp flags permit. |
1507 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. | 1506 | * Return: 0 if the reservation succeeded or -ENOMEM if it failed. |
1508 | */ | 1507 | */ |
1509 | int xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) | 1508 | int __xa_reserve(struct xarray *xa, unsigned long index, gfp_t gfp) |
1510 | { | 1509 | { |
1511 | XA_STATE(xas, xa, index); | 1510 | XA_STATE(xas, xa, index); |
1512 | unsigned int lock_type = xa_lock_type(xa); | ||
1513 | void *curr; | 1511 | void *curr; |
1514 | 1512 | ||
1515 | do { | 1513 | do { |
1516 | xas_lock_type(&xas, lock_type); | ||
1517 | curr = xas_load(&xas); | 1514 | curr = xas_load(&xas); |
1518 | if (!curr) | 1515 | if (!curr) |
1519 | xas_store(&xas, XA_ZERO_ENTRY); | 1516 | xas_store(&xas, XA_ZERO_ENTRY); |
1520 | xas_unlock_type(&xas, lock_type); | 1517 | } while (__xas_nomem(&xas, gfp)); |
1521 | } while (xas_nomem(&xas, gfp)); | ||
1522 | 1518 | ||
1523 | return xas_error(&xas); | 1519 | return xas_error(&xas); |
1524 | } | 1520 | } |
1525 | EXPORT_SYMBOL(xa_reserve); | 1521 | EXPORT_SYMBOL(__xa_reserve); |
1526 | 1522 | ||
1527 | #ifdef CONFIG_XARRAY_MULTI | 1523 | #ifdef CONFIG_XARRAY_MULTI |
1528 | static void xas_set_range(struct xa_state *xas, unsigned long first, | 1524 | static void xas_set_range(struct xa_state *xas, unsigned long first, |