[PATCH v6 01/12] common/rc: Add _min() and _max() helpers

Ojaswin Mujoo posted 11 patches 3 weeks ago
There is a newer version of this series
[PATCH v6 01/12] common/rc: Add _min() and _max() helpers
Posted by Ojaswin Mujoo 3 weeks ago
Many programs open code these functionalities so add it as a generic helper
in common/rc

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 common/rc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/common/rc b/common/rc
index 81587dad..28fbbcbb 100644
--- a/common/rc
+++ b/common/rc
@@ -5978,6 +5978,28 @@ _require_inplace_writes()
 	fi
 }
 
+_min() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg < $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
+_max() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg > $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
 ################################################################################
 # make sure this script returns success
 /bin/true
-- 
2.49.0
Re: [PATCH v6 01/12] common/rc: Add _min() and _max() helpers
Posted by John Garry 2 weeks, 6 days ago
On 11/09/2025 18:13, Ojaswin Mujoo wrote:
> Many programs open code these functionalities so add it as a generic helper
> in common/rc
> 
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Reviewed-by: John Garry <john.g.gary@oracle.com>

I just sent a patch for something similar for blktests to linux-block. I 
wonder how much commonality there is for such helpers...

BTW, let me know if I should attribute some credit there. cheers
Re: [PATCH v6 01/12] common/rc: Add _min() and _max() helpers
Posted by Ojaswin Mujoo 2 weeks, 3 days ago
On Fri, Sep 12, 2025 at 05:53:47PM +0100, John Garry wrote:
> On 11/09/2025 18:13, Ojaswin Mujoo wrote:
> > Many programs open code these functionalities so add it as a generic helper
> > in common/rc
> > 
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> > Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> 
> Reviewed-by: John Garry <john.g.gary@oracle.com>
> 
> I just sent a patch for something similar for blktests to linux-block. I
> wonder how much commonality there is for such helpers...
> 
> BTW, let me know if I should attribute some credit there. cheers

Thanks for the review John!

I think the helpers are simple enough so credit is not needed :) 

Thanks,
Ojaswin