Skip to content

Commit

Permalink
XArray: Change xa_insert to return -EBUSY
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Matthew Wilcox committed Feb 6, 2019
1 parent 809ab93 commit fd9dc93
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Documentation/core-api/xarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ which was at that index; if it returns the same entry which was passed as

If you want to only store a new entry to an index if the current entry
at that index is ``NULL``, you can use :c:func:`xa_insert` which
returns ``-EEXIST`` if the entry is not empty.
returns ``-EBUSY`` if the entry is not empty.

You can enquire whether a mark is set on an entry by using
:c:func:`xa_get_mark`. If the entry is not ``NULL``, you can set a mark
Expand Down
2 changes: 1 addition & 1 deletion fs/nilfs2/btnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
*/
if (!err)
return 0;
else if (err != -EEXIST)
else if (err != -EBUSY)
goto failed_unlock;

err = invalidate_inode_pages2_range(btnc, newkey, newkey);
Expand Down
6 changes: 3 additions & 3 deletions include/linux/xarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index,
*
* Context: Any context. Takes and releases the xa_lock. May sleep if
* the @gfp flags permit.
* Return: 0 if the store succeeded. -EEXIST if another entry was present.
* Return: 0 if the store succeeded. -EBUSY if another entry was present.
* -ENOMEM if memory could not be allocated.
*/
static inline int xa_insert(struct xarray *xa, unsigned long index,
Expand Down Expand Up @@ -693,7 +693,7 @@ static inline int xa_insert(struct xarray *xa, unsigned long index,
*
* Context: Any context. Takes and releases the xa_lock while
* disabling softirqs. May sleep if the @gfp flags permit.
* Return: 0 if the store succeeded. -EEXIST if another entry was present.
* Return: 0 if the store succeeded. -EBUSY if another entry was present.
* -ENOMEM if memory could not be allocated.
*/
static inline int xa_insert_bh(struct xarray *xa, unsigned long index,
Expand Down Expand Up @@ -722,7 +722,7 @@ static inline int xa_insert_bh(struct xarray *xa, unsigned long index,
*
* Context: Process context. Takes and releases the xa_lock while
* disabling interrupts. May sleep if the @gfp flags permit.
* Return: 0 if the store succeeded. -EEXIST if another entry was present.
* Return: 0 if the store succeeded. -EBUSY if another entry was present.
* -ENOMEM if memory could not be allocated.
*/
static inline int xa_insert_irq(struct xarray *xa, unsigned long index,
Expand Down
4 changes: 2 additions & 2 deletions lib/test_xarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static noinline void check_cmpxchg(struct xarray *xa)

XA_BUG_ON(xa, !xa_empty(xa));
XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL);
XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EEXIST);
XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EBUSY);
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE);
Expand Down Expand Up @@ -388,7 +388,7 @@ static noinline void check_reserve(struct xarray *xa)
/* But xa_insert does not */
xa_reserve(xa, 12345678, GFP_KERNEL);
XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) !=
-EEXIST);
-EBUSY);
XA_BUG_ON(xa, xa_empty(xa));
XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL);
XA_BUG_ON(xa, !xa_empty(xa));
Expand Down
4 changes: 2 additions & 2 deletions lib/xarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ EXPORT_SYMBOL(__xa_cmpxchg);
*
* Context: Any context. Expects xa_lock to be held on entry. May
* release and reacquire xa_lock if @gfp flags permit.
* Return: 0 if the store succeeded. -EEXIST if another entry was present.
* Return: 0 if the store succeeded. -EBUSY if another entry was present.
* -ENOMEM if memory could not be allocated.
*/
int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
Expand All @@ -1471,7 +1471,7 @@ int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
if (xa_track_free(xa))
xas_clear_mark(&xas, XA_FREE_MARK);
} else {
xas_set_err(&xas, -EEXIST);
xas_set_err(&xas, -EBUSY);
}
} while (__xas_nomem(&xas, gfp));

Expand Down

0 comments on commit fd9dc93

Please sign in to comment.