Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+9 -9
+1 -1
Documentation/core-api/xarray.rst
··· 85 85 86 86 If you want to only store a new entry to an index if the current entry 87 87 at that index is ``NULL``, you can use :c:func:`xa_insert` which 88 - returns ``-EEXIST`` if the entry is not empty. 88 + returns ``-EBUSY`` if the entry is not empty. 89 89 90 90 You can enquire whether a mark is set on an entry by using 91 91 :c:func:`xa_get_mark`. If the entry is not ``NULL``, you can set a mark
+1 -1
fs/nilfs2/btnode.c
··· 189 189 */ 190 190 if (!err) 191 191 return 0; 192 - else if (err != -EEXIST) 192 + else if (err != -EBUSY) 193 193 goto failed_unlock; 194 194 195 195 err = invalidate_inode_pages2_range(btnc, newkey, newkey);
+3 -3
include/linux/xarray.h
··· 664 664 * 665 665 * Context: Any context. Takes and releases the xa_lock. May sleep if 666 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 668 * -ENOMEM if memory could not be allocated. 669 669 */ 670 670 static inline int xa_insert(struct xarray *xa, unsigned long index, ··· 693 693 * 694 694 * Context: Any context. Takes and releases the xa_lock while 695 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 697 * -ENOMEM if memory could not be allocated. 698 698 */ 699 699 static inline int xa_insert_bh(struct xarray *xa, unsigned long index, ··· 722 722 * 723 723 * Context: Process context. Takes and releases the xa_lock while 724 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 726 * -ENOMEM if memory could not be allocated. 727 727 */ 728 728 static inline int xa_insert_irq(struct xarray *xa, unsigned long index,
+2 -2
lib/test_xarray.c
··· 346 346 347 347 XA_BUG_ON(xa, !xa_empty(xa)); 348 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 350 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS); 351 351 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS); 352 352 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE); ··· 388 388 /* But xa_insert does not */ 389 389 xa_reserve(xa, 12345678, GFP_KERNEL); 390 390 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != 391 - -EEXIST); 391 + -EBUSY); 392 392 XA_BUG_ON(xa, xa_empty(xa)); 393 393 XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL); 394 394 XA_BUG_ON(xa, !xa_empty(xa));
+2 -2
lib/xarray.c
··· 1451 1451 * 1452 1452 * Context: Any context. Expects xa_lock to be held on entry. May 1453 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 1455 * -ENOMEM if memory could not be allocated. 1456 1456 */ 1457 1457 int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) ··· 1471 1471 if (xa_track_free(xa)) 1472 1472 xas_clear_mark(&xas, XA_FREE_MARK); 1473 1473 } else { 1474 - xas_set_err(&xas, -EEXIST); 1474 + xas_set_err(&xas, -EBUSY); 1475 1475 } 1476 1476 } while (__xas_nomem(&xas, gfp)); 1477 1477