mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
lib: Move lcm and gcd to lib/misc for wider use.
This commit is contained in:
parent
8c71fc1cc2
commit
c27963c566
@ -1,5 +1,6 @@
|
||||
Version 2.02.165 -
|
||||
===================================
|
||||
Move lcm and gcd to lib/misc.
|
||||
Suppress some unnecessary --stripesize parameter warnings.
|
||||
Fix 'pvmove -n name ...' to prohibit collocation of RAID SubLVs
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
@top_srcdir@/lib/misc/lvm-file.h
|
||||
@top_srcdir@/lib/misc/lvm-flock.h
|
||||
@top_srcdir@/lib/misc/lvm-globals.h
|
||||
@top_srcdir@/lib/misc/lvm-maths.h
|
||||
@top_srcdir@/lib/misc/lvm-percent.h
|
||||
@top_srcdir@/lib/misc/lvm-signal.h
|
||||
@top_srcdir@/lib/misc/lvm-string.h
|
||||
|
@ -112,6 +112,7 @@ SOURCES =\
|
||||
misc/lvm-file.c \
|
||||
misc/lvm-flock.c \
|
||||
misc/lvm-globals.c \
|
||||
misc/lvm-maths.c \
|
||||
misc/lvm-signal.c \
|
||||
misc/lvm-string.c \
|
||||
misc/lvm-wrappers.c \
|
||||
|
@ -430,28 +430,6 @@ int validate_pool_chunk_size(struct cmd_context *cmd,
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Greatest common divisor */
|
||||
static unsigned long _gcd(unsigned long n1, unsigned long n2)
|
||||
{
|
||||
unsigned long remainder;
|
||||
|
||||
do {
|
||||
remainder = n1 % n2;
|
||||
n1 = n2;
|
||||
n2 = remainder;
|
||||
} while (n2);
|
||||
|
||||
return n1;
|
||||
}
|
||||
|
||||
/* Least common multiple */
|
||||
static unsigned long _lcm(unsigned long n1, unsigned long n2)
|
||||
{
|
||||
if (!n1 || !n2)
|
||||
return 0;
|
||||
return (n1 * n2) / _gcd(n1, n2);
|
||||
}
|
||||
|
||||
int recalculate_pool_chunk_size_with_dev_hints(struct logical_volume *pool_lv,
|
||||
int passed_args,
|
||||
int chunk_size_calc_policy)
|
||||
@ -497,7 +475,7 @@ int recalculate_pool_chunk_size_with_dev_hints(struct logical_volume *pool_lv,
|
||||
continue;
|
||||
|
||||
if (previous_hint)
|
||||
hint = _lcm(previous_hint, hint);
|
||||
hint = lcm(previous_hint, hint);
|
||||
previous_hint = hint;
|
||||
break;
|
||||
case AREA_LV:
|
||||
|
@ -89,6 +89,7 @@
|
||||
# include "lvm-logging.h"
|
||||
# include "lvm-globals.h"
|
||||
# include "lvm-wrappers.h"
|
||||
# include "lvm-maths.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
38
lib/misc/lvm-maths.c
Normal file
38
lib/misc/lvm-maths.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License v.2.1.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
/* Greatest common divisor */
|
||||
unsigned long gcd(unsigned long n1, unsigned long n2)
|
||||
{
|
||||
unsigned long remainder;
|
||||
|
||||
do {
|
||||
remainder = n1 % n2;
|
||||
n1 = n2;
|
||||
n2 = remainder;
|
||||
} while (n2);
|
||||
|
||||
return n1;
|
||||
}
|
||||
|
||||
/* Least common multiple */
|
||||
unsigned long lcm(unsigned long n1, unsigned long n2)
|
||||
{
|
||||
if (!n1 || !n2)
|
||||
return 0;
|
||||
|
||||
return (n1 * n2) / gcd(n1, n2);
|
||||
}
|
24
lib/misc/lvm-maths.h
Normal file
24
lib/misc/lvm-maths.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use,
|
||||
* modify, copy, or redistribute it subject to the terms and conditions
|
||||
* of the GNU Lesser General Public License v.2.1.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _LVM_MATH_H
|
||||
#define _LVM_MATH_H
|
||||
|
||||
/* Greatest common divisor */
|
||||
unsigned long gcd(unsigned long n1, unsigned long n2);
|
||||
|
||||
/* Least common multiple */
|
||||
unsigned long lcm(unsigned long n1, unsigned long n2);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user