ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe()
@ 2020-10-02 22:34 Shuah Khan
  2020-10-02 23:44 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2020-10-02 22:34 UTC (permalink / raw)
  To: idryomov, dongsheng.yang, axboe
  Cc: ceph-devel, Linux Kernel Mailing List, Shuah Khan,
	Greg Kroah-Hartman, Kees Cook

All,

I came across these atomic_inc_return_safe() & atomic_dec_return_safe()
functions that hold the counters at safe values.

atomic_inc_return_safe()

If the counter is already 0 it will not be incremented.
If the counter is already at its maximum value returns
-EINVAL without updating it.

atomic_dec_return_safe()

Decrement the counter.  Return the resulting value, or -EINVAL

These two routines are static and only used in rbd.c.

Can these become part of atomic_t ops?

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe()
  2020-10-02 22:34 drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe() Shuah Khan
@ 2020-10-02 23:44 ` Jens Axboe
  2020-10-02 23:50   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2020-10-02 23:44 UTC (permalink / raw)
  To: Shuah Khan, idryomov, dongsheng.yang
  Cc: ceph-devel, Linux Kernel Mailing List, Greg Kroah-Hartman, Kees Cook

On 10/2/20 4:34 PM, Shuah Khan wrote:
> All,
> 
> I came across these atomic_inc_return_safe() & atomic_dec_return_safe()
> functions that hold the counters at safe values.
> 
> atomic_inc_return_safe()
> 
> If the counter is already 0 it will not be incremented.
> If the counter is already at its maximum value returns
> -EINVAL without updating it.
> 
> atomic_dec_return_safe()
> 
> Decrement the counter.  Return the resulting value, or -EINVAL
> 
> These two routines are static and only used in rbd.c.
> 
> Can these become part of atomic_t ops?

I think you just want to use refcount_t for this use case. They
have safe guards for under/overflow.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe()
  2020-10-02 23:44 ` Jens Axboe
@ 2020-10-02 23:50   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2020-10-02 23:50 UTC (permalink / raw)
  To: Jens Axboe, idryomov, dongsheng.yang
  Cc: ceph-devel, Linux Kernel Mailing List, Greg Kroah-Hartman,
	Kees Cook, Shuah Khan

On 10/2/20 5:44 PM, Jens Axboe wrote:
> On 10/2/20 4:34 PM, Shuah Khan wrote:
>> All,
>>
>> I came across these atomic_inc_return_safe() & atomic_dec_return_safe()
>> functions that hold the counters at safe values.
>>
>> atomic_inc_return_safe()
>>
>> If the counter is already 0 it will not be incremented.
>> If the counter is already at its maximum value returns
>> -EINVAL without updating it.
>>
>> atomic_dec_return_safe()
>>
>> Decrement the counter.  Return the resulting value, or -EINVAL
>>
>> These two routines are static and only used in rbd.c.
>>
>> Can these become part of atomic_t ops?
> 
> I think you just want to use refcount_t for this use case. They
> have safe guards for under/overflow.
> 

Makes sense. Guess these came before refcount_t.

I will track this for refcount_t conversion.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-02 23:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 22:34 drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe() Shuah Khan
2020-10-02 23:44 ` Jens Axboe
2020-10-02 23:50   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).