summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2019-02-06 13:07:11 -0500
committerMatthew Wilcox <willy@infradead.org>2019-02-06 13:12:15 -0500
commitfd9dc93e36231fb6d520e0edd467058fad4fd12d (patch)
treeaa7dc07e911ece5d69304e9e4bba1f9b937d8ce2
parent809ab9371ca0a96b44d9866ad82849410759a45b (diff)
XArray: Change xa_insert to return -EBUSY
Userspace translates EEXIST to "File exists" which isn't a very good error message for the problem. "Device or resource busy" is a better indication of what went wrong. Signed-off-by: Matthew Wilcox <willy@infradead.org>
-rw-r--r--Documentation/core-api/xarray.rst2
-rw-r--r--fs/nilfs2/btnode.c2
-rw-r--r--include/linux/xarray.h6
-rw-r--r--lib/test_xarray.c4
-rw-r--r--lib/xarray.c4
5 files changed, 9 insertions, 9 deletions
diff --git a/Documentation/core-api/xarray.rst b/Documentation/core-api/xarray.rst
index 5d54b27c6eba..42bb1a62650f 100644
--- a/Documentation/core-api/xarray.rst
+++ b/Documentation/core-api/xarray.rst
@@ -85,7 +85,7 @@ which was at that index; if it returns the same entry which was passed as
85 85
86If you want to only store a new entry to an index if the current entry 86If you want to only store a new entry to an index if the current entry
87at that index is ``NULL``, you can use :c:func:`xa_insert` which 87at that index is ``NULL``, you can use :c:func:`xa_insert` which
88returns ``-EEXIST`` if the entry is not empty. 88returns ``-EBUSY`` if the entry is not empty.
89 89
90You can enquire whether a mark is set on an entry by using 90You can enquire whether a mark is set on an entry by using
91:c:func:`xa_get_mark`. If the entry is not ``NULL``, you can set a mark 91:c:func:`xa_get_mark`. If the entry is not ``NULL``, you can set a mark
diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c
index f2129a5d9f23..4391fd3abd8f 100644
--- a/fs/nilfs2/btnode.c
+++ b/fs/nilfs2/btnode.c
@@ -189,7 +189,7 @@ retry:
189 */ 189 */
190 if (!err) 190 if (!err)
191 return 0; 191 return 0;
192 else if (err != -EEXIST) 192 else if (err != -EBUSY)
193 goto failed_unlock; 193 goto failed_unlock;
194 194
195 err = invalidate_inode_pages2_range(btnc, newkey, newkey); 195 err = invalidate_inode_pages2_range(btnc, newkey, newkey);
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index e11841537631..57cf35c4d094 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -664,7 +664,7 @@ static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index,
664 * 664 *
665 * Context: Any context. Takes and releases the xa_lock. May sleep if 665 * Context: Any context. Takes and releases the xa_lock. May sleep if
666 * the @gfp flags permit. 666 * the @gfp flags permit.
667 * Return: 0 if the store succeeded. -EEXIST if another entry was present. 667 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
668 * -ENOMEM if memory could not be allocated. 668 * -ENOMEM if memory could not be allocated.
669 */ 669 */
670static inline int xa_insert(struct xarray *xa, unsigned long index, 670static inline int xa_insert(struct xarray *xa, unsigned long index,
@@ -693,7 +693,7 @@ static inline int xa_insert(struct xarray *xa, unsigned long index,
693 * 693 *
694 * Context: Any context. Takes and releases the xa_lock while 694 * Context: Any context. Takes and releases the xa_lock while
695 * disabling softirqs. May sleep if the @gfp flags permit. 695 * disabling softirqs. May sleep if the @gfp flags permit.
696 * Return: 0 if the store succeeded. -EEXIST if another entry was present. 696 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
697 * -ENOMEM if memory could not be allocated. 697 * -ENOMEM if memory could not be allocated.
698 */ 698 */
699static inline int xa_insert_bh(struct xarray *xa, unsigned long index, 699static inline int xa_insert_bh(struct xarray *xa, unsigned long index,
@@ -722,7 +722,7 @@ static inline int xa_insert_bh(struct xarray *xa, unsigned long index,
722 * 722 *
723 * Context: Process context. Takes and releases the xa_lock while 723 * Context: Process context. Takes and releases the xa_lock while
724 * disabling interrupts. May sleep if the @gfp flags permit. 724 * disabling interrupts. May sleep if the @gfp flags permit.
725 * Return: 0 if the store succeeded. -EEXIST if another entry was present. 725 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
726 * -ENOMEM if memory could not be allocated. 726 * -ENOMEM if memory could not be allocated.
727 */ 727 */
728static inline int xa_insert_irq(struct xarray *xa, unsigned long index, 728static inline int xa_insert_irq(struct xarray *xa, unsigned long index,
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index 671a93ee09e6..9d894e93456c 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -346,7 +346,7 @@ static noinline void check_cmpxchg(struct xarray *xa)
346 346
347 XA_BUG_ON(xa, !xa_empty(xa)); 347 XA_BUG_ON(xa, !xa_empty(xa));
348 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL); 348 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL);
349 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EEXIST); 349 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EBUSY);
350 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS); 350 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
351 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS); 351 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
352 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE); 352 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE);
@@ -388,7 +388,7 @@ static noinline void check_reserve(struct xarray *xa)
388 /* But xa_insert does not */ 388 /* But xa_insert does not */
389 xa_reserve(xa, 12345678, GFP_KERNEL); 389 xa_reserve(xa, 12345678, GFP_KERNEL);
390 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != 390 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) !=
391 -EEXIST); 391 -EBUSY);
392 XA_BUG_ON(xa, xa_empty(xa)); 392 XA_BUG_ON(xa, xa_empty(xa));
393 XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL); 393 XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL);
394 XA_BUG_ON(xa, !xa_empty(xa)); 394 XA_BUG_ON(xa, !xa_empty(xa));
diff --git a/lib/xarray.c b/lib/xarray.c
index fb783bf2a441..1b97ca58bd15 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -1451,7 +1451,7 @@ EXPORT_SYMBOL(__xa_cmpxchg);
1451 * 1451 *
1452 * Context: Any context. Expects xa_lock to be held on entry. May 1452 * Context: Any context. Expects xa_lock to be held on entry. May
1453 * release and reacquire xa_lock if @gfp flags permit. 1453 * release and reacquire xa_lock if @gfp flags permit.
1454 * Return: 0 if the store succeeded. -EEXIST if another entry was present. 1454 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
1455 * -ENOMEM if memory could not be allocated. 1455 * -ENOMEM if memory could not be allocated.
1456 */ 1456 */
1457int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) 1457int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
@@ -1471,7 +1471,7 @@ int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
1471 if (xa_track_free(xa)) 1471 if (xa_track_free(xa))
1472 xas_clear_mark(&xas, XA_FREE_MARK); 1472 xas_clear_mark(&xas, XA_FREE_MARK);
1473 } else { 1473 } else {
1474 xas_set_err(&xas, -EEXIST); 1474 xas_set_err(&xas, -EBUSY);
1475 } 1475 }
1476 } while (__xas_nomem(&xas, gfp)); 1476 } while (__xas_nomem(&xas, gfp));
1477 1477