CEPH-Devel archive on lore.kernel.org
 help / color / 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, back to index

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

CEPH-Devel archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/ceph-devel/0 ceph-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ceph-devel ceph-devel/ https://lore.kernel.org/ceph-devel \
		ceph-devel@vger.kernel.org
	public-inbox-index ceph-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.ceph-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git