Skip to content

Commit fd9dc93

Browse files
author
Matthew Wilcox
committed
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>
1 parent 809ab93 commit fd9dc93

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎Documentation/core-api/xarray.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ which was at that index; if it returns the same entry which was passed as
8585

8686
If you want to only store a new entry to an index if the current entry
8787
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.
8989

9090
You can enquire whether a mark is set on an entry by using
9191
:c:func:`xa_get_mark`. If the entry is not ``NULL``, you can set a mark

‎fs/nilfs2/btnode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
189189
*/
190190
if (!err)
191191
return 0;
192-
else if (err != -EEXIST)
192+
else if (err != -EBUSY)
193193
goto failed_unlock;
194194

195195
err = invalidate_inode_pages2_range(btnc, newkey, newkey);

‎include/linux/xarray.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index,
664664
*
665665
* Context: Any context. Takes and releases the xa_lock. May sleep if
666666
* 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.
668668
* -ENOMEM if memory could not be allocated.
669669
*/
670670
static 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,
693693
*
694694
* Context: Any context. Takes and releases the xa_lock while
695695
* 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.
697697
* -ENOMEM if memory could not be allocated.
698698
*/
699699
static 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,
722722
*
723723
* Context: Process context. Takes and releases the xa_lock while
724724
* 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.
726726
* -ENOMEM if memory could not be allocated.
727727
*/
728728
static inline int xa_insert_irq(struct xarray *xa, unsigned long index,

‎lib/test_xarray.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static noinline void check_cmpxchg(struct xarray *xa)
346346

347347
XA_BUG_ON(xa, !xa_empty(xa));
348348
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);
350350
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
351351
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
352352
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)
388388
/* But xa_insert does not */
389389
xa_reserve(xa, 12345678, GFP_KERNEL);
390390
XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) !=
391-
-EEXIST);
391+
-EBUSY);
392392
XA_BUG_ON(xa, xa_empty(xa));
393393
XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL);
394394
XA_BUG_ON(xa, !xa_empty(xa));

‎lib/xarray.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ EXPORT_SYMBOL(__xa_cmpxchg);
14511451
*
14521452
* Context: Any context. Expects xa_lock to be held on entry. May
14531453
* 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.
14551455
* -ENOMEM if memory could not be allocated.
14561456
*/
14571457
int __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)
14711471
if (xa_track_free(xa))
14721472
xas_clear_mark(&xas, XA_FREE_MARK);
14731473
} else {
1474-
xas_set_err(&xas, -EEXIST);
1474+
xas_set_err(&xas, -EBUSY);
14751475
}
14761476
} while (__xas_nomem(&xas, gfp));
14771477

0 commit comments

Comments
 (0)